Panda3D
eggCharacterDb.cxx
1 // Filename: eggCharacterDb.cxx
2 // Created by: drose (05Oct06)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "eggCharacterDb.h"
16 #include "eggCharacterData.h"
17 
18 ////////////////////////////////////////////////////////////////////
19 // Function: EggCharacterDb::Constructor
20 // Access: Public
21 // Description: Constructs a database for storing the interim work
22 // for the indicated EggCharacterData. The parameter
23 // max_ram_mb indicates the maximum amount of RAM (in
24 // MB) that the database should consume; if it the
25 // database would roughly fit within this limit, it will
26 // be stored in RAM; otherwise, it will be written to
27 // disk (if Berkeley DB is available).
28 ////////////////////////////////////////////////////////////////////
31  /*
32 #ifdef HAVE_BDB
33  _db = NULL;
34 
35  _db = new Db(NULL, 0);
36  _db_filename = Filename::temporary("", "eggc_", ".db");
37 
38  string os_db_filename = _db_filename.to_os_specific();
39  _db->open(NULL, os_db_filename.c_str(), NULL,
40  DB_BTREE, DB_CREATE | DB_EXCL, 0);
41 
42  nout << "Using " << os_db_filename << " for rebuild database.\n";
43 #endif // HAVE_BDB
44  */
45 }
46 
47 ////////////////////////////////////////////////////////////////////
48 // Function: EggCharacterDb::Destructor
49 // Access: Public
50 // Description:
51 ////////////////////////////////////////////////////////////////////
52 EggCharacterDb::
53 ~EggCharacterDb() {
54  /*
55 #ifdef HAVE_BDB
56  if (_db != (Db *)NULL){
57  _db->close(0);
58  delete _db;
59  _db = NULL;
60 
61  string os_db_filename = _db_filename.to_os_specific();
62  Db rmdb(NULL, 0);
63  rmdb.remove(os_db_filename.c_str(), NULL, 0);
64  }
65 #endif // HAVE_BDB
66  */
67 }
68 
69 ////////////////////////////////////////////////////////////////////
70 // Function: EggCharacterDb::get_matrix
71 // Access: Public
72 // Description: Looks up the data for the indicated joint, type, and
73 // frame, and fills it in result (and returns true) if
74 // it is found. Returns false if this data has not been
75 // stored in the database.
76 ////////////////////////////////////////////////////////////////////
78 get_matrix(const EggJointPointer *joint, TableType type,
79  int frame, LMatrix4d &mat) const {
80  Key key(joint, type, frame);
81 
82  /*
83 #ifdef HAVE_BDB
84  if (_db != (Db *)NULL){
85  Dbt db_key(&key, sizeof(Key));
86  Dbt db_data(&mat, sizeof(LMatrix4d));
87  db_data.set_ulen(sizeof(LMatrix4d));
88  db_data.set_flags(DB_DBT_USERMEM);
89 
90  int result = _db->get(NULL, &db_key, &db_data, 0);
91  if (result == DB_NOTFOUND) {
92  return false;
93  }
94  nassertr(result == 0, false);
95  return true;
96  }
97 #endif // HAVE_BDB
98  */
99 
100  Table::const_iterator ti;
101  ti = _table.find(key);
102  if (ti == _table.end()) {
103  return false;
104  }
105 
106  mat = (*ti).second;
107  return true;
108 }
109 
110 ////////////////////////////////////////////////////////////////////
111 // Function: EggCharacterDb::set_matrix
112 // Access: Public
113 // Description: Stores the matrix for the indicated joint, type, and
114 // frame in the database. It is an error to call this
115 // more than once for any given key combination (not for
116 // any technical reason, but because we don't expect
117 // this to happen).
118 ////////////////////////////////////////////////////////////////////
119 void EggCharacterDb::
120 set_matrix(const EggJointPointer *joint, TableType type,
121  int frame, const LMatrix4d &mat) {
122  Key key(joint, type, frame);
123 
124  /*
125 #ifdef HAVE_BDB
126  if (_db != (Db *)NULL){
127  Dbt db_key(&key, sizeof(Key));
128  Dbt db_data((void *)&mat, sizeof(LMatrix4d));
129  int result = _db->put(NULL, &db_key, &db_data, DB_NOOVERWRITE);
130  nassertv(result != DB_KEYEXIST);
131  nassertv(result == 0);
132  return;
133  }
134 #endif // HAVE_BDB
135  */
136 
137  bool inserted = _table.insert(Table::value_type(key, mat)).second;
138  nassertv(inserted);
139 }
EggCharacterDb()
Constructs a database for storing the interim work for the indicated EggCharacterData.
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:4716
void set_matrix(const EggJointPointer *joint, TableType type, int frame, const LMatrix4d &mat)
Stores the matrix for the indicated joint, type, and frame in the database.
This is a base class for EggJointNodePointer and EggMatrixTablePointer.
bool get_matrix(const EggJointPointer *joint, TableType type, int frame, LMatrix4d &mat) const
Looks up the data for the indicated joint, type, and frame, and fills it in result (and returns true)...