Panda3D

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