Panda3D

eggCharacterDb.cxx

00001 // Filename: eggCharacterDb.cxx
00002 // Created by:  drose (05Oct06)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "eggCharacterDb.h"
00016 #include "eggCharacterData.h"
00017 
00018 ////////////////////////////////////////////////////////////////////
00019 //     Function: EggCharacterDb::Constructor
00020 //       Access: Public
00021 //  Description: Constructs a database for storing the interim work
00022 //               for the indicated EggCharacterData.  The parameter
00023 //               max_ram_mb indicates the maximum amount of RAM (in
00024 //               MB) that the database should consume; if it the
00025 //               database would roughly fit within this limit, it will
00026 //               be stored in RAM; otherwise, it will be written to
00027 //               disk (if Berkeley DB is available).
00028 ////////////////////////////////////////////////////////////////////
00029 EggCharacterDb::
00030 EggCharacterDb() {
00031   /*
00032 #ifdef HAVE_BDB
00033   _db = NULL;
00034 
00035   _db = new Db(NULL, 0);
00036   _db_filename = Filename::temporary("", "eggc_", ".db");
00037 
00038   string os_db_filename = _db_filename.to_os_specific();
00039   _db->open(NULL, os_db_filename.c_str(), NULL,
00040             DB_BTREE, DB_CREATE | DB_EXCL, 0);
00041 
00042   nout << "Using " << os_db_filename << " for rebuild database.\n";
00043 #endif  // HAVE_BDB
00044   */
00045 }
00046 
00047 ////////////////////////////////////////////////////////////////////
00048 //     Function: EggCharacterDb::Destructor
00049 //       Access: Public
00050 //  Description:
00051 ////////////////////////////////////////////////////////////////////
00052 EggCharacterDb::
00053 ~EggCharacterDb() {
00054   /*
00055 #ifdef HAVE_BDB
00056   if (_db != (Db *)NULL){ 
00057     _db->close(0);
00058     delete _db;
00059     _db = NULL;
00060 
00061     string os_db_filename = _db_filename.to_os_specific();
00062     Db rmdb(NULL, 0);
00063     rmdb.remove(os_db_filename.c_str(), NULL, 0);
00064   }
00065 #endif  // HAVE_BDB
00066   */
00067 }
00068 
00069 ////////////////////////////////////////////////////////////////////
00070 //     Function: EggCharacterDb::get_matrix
00071 //       Access: Public
00072 //  Description: Looks up the data for the indicated joint, type, and
00073 //               frame, and fills it in result (and returns true) if
00074 //               it is found.  Returns false if this data has not been
00075 //               stored in the database.
00076 ////////////////////////////////////////////////////////////////////
00077 bool EggCharacterDb::
00078 get_matrix(const EggJointPointer *joint, TableType type,
00079            int frame, LMatrix4d &mat) const {
00080   Key key(joint, type, frame);
00081 
00082   /*
00083 #ifdef HAVE_BDB
00084   if (_db != (Db *)NULL){ 
00085     Dbt db_key(&key, sizeof(Key));
00086     Dbt db_data(&mat, sizeof(LMatrix4d));
00087     db_data.set_ulen(sizeof(LMatrix4d));
00088     db_data.set_flags(DB_DBT_USERMEM);
00089 
00090     int result = _db->get(NULL, &db_key, &db_data, 0);
00091     if (result == DB_NOTFOUND) {
00092       return false;
00093     }
00094     nassertr(result == 0, false);
00095     return true;
00096   }
00097 #endif  // HAVE_BDB
00098   */
00099 
00100   Table::const_iterator ti;
00101   ti = _table.find(key);
00102   if (ti == _table.end()) {
00103     return false;
00104   }
00105 
00106   mat = (*ti).second;
00107   return true;
00108 }
00109 
00110 ////////////////////////////////////////////////////////////////////
00111 //     Function: EggCharacterDb::set_matrix
00112 //       Access: Public
00113 //  Description: Stores the matrix for the indicated joint, type, and
00114 //               frame in the database.  It is an error to call this
00115 //               more than once for any given key combination (not for
00116 //               any technical reason, but because we don't expect
00117 //               this to happen).
00118 ////////////////////////////////////////////////////////////////////
00119 void EggCharacterDb::
00120 set_matrix(const EggJointPointer *joint, TableType type,
00121            int frame, const LMatrix4d &mat) {
00122   Key key(joint, type, frame);
00123 
00124   /*
00125 #ifdef HAVE_BDB
00126   if (_db != (Db *)NULL){ 
00127     Dbt db_key(&key, sizeof(Key));
00128     Dbt db_data((void *)&mat, sizeof(LMatrix4d));
00129     int result = _db->put(NULL, &db_key, &db_data, DB_NOOVERWRITE);
00130     nassertv(result != DB_KEYEXIST);
00131     nassertv(result == 0);
00132     return;
00133   }
00134 #endif  // HAVE_BDB
00135   */
00136 
00137   bool inserted = _table.insert(Table::value_type(key, mat)).second;
00138   nassertv(inserted);
00139 }
 All Classes Functions Variables Enumerations