Panda3D
|
00001 // Filename: bamReader.I 00002 // Created by: jason (12Jun00) 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 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: BamReaderAuxData::Constructor 00018 // Access: Published 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE BamReaderAuxData:: 00022 BamReaderAuxData() { 00023 } 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Function: BamReader::get_source 00027 // Access: Published 00028 // Description: Returns the current source of the BamReader as set by 00029 // set_source() or the constructor. 00030 //////////////////////////////////////////////////////////////////// 00031 INLINE DatagramGenerator *BamReader:: 00032 get_source() { 00033 return _source; 00034 } 00035 00036 //////////////////////////////////////////////////////////////////// 00037 // Function: BamReader::get_filename 00038 // Access: Published 00039 // Description: If a BAM is a file, then the BamReader should 00040 // contain the name of the file. This enables the 00041 // reader to interpret pathnames in the BAM as relative 00042 // to the directory containing the BAM. 00043 //////////////////////////////////////////////////////////////////// 00044 INLINE const Filename &BamReader:: 00045 get_filename() const { 00046 if (_source != (DatagramGenerator *)NULL) { 00047 return _source->get_filename(); 00048 } 00049 static const Filename empty_filename; 00050 return empty_filename; 00051 } 00052 00053 //////////////////////////////////////////////////////////////////// 00054 // Function: BamReader::get_loader_options 00055 // Access: Published 00056 // Description: Returns the LoaderOptions passed to the loader when 00057 // the model was requested, if any. 00058 //////////////////////////////////////////////////////////////////// 00059 INLINE const LoaderOptions &BamReader:: 00060 get_loader_options() const { 00061 return _loader_options; 00062 } 00063 00064 //////////////////////////////////////////////////////////////////// 00065 // Function: BamReader::set_loader_options 00066 // Access: Published 00067 // Description: Specifies the LoaderOptions for this BamReader. 00068 //////////////////////////////////////////////////////////////////// 00069 INLINE void BamReader:: 00070 set_loader_options(const LoaderOptions &options) { 00071 _loader_options = options; 00072 } 00073 00074 //////////////////////////////////////////////////////////////////// 00075 // Function: BamReader::is_eof 00076 // Access: Published 00077 // Description: Returns true if the reader has reached end-of-file, 00078 // false otherwise. This call is only valid after a 00079 // call to read_object(). 00080 //////////////////////////////////////////////////////////////////// 00081 INLINE bool BamReader:: 00082 is_eof() const { 00083 nassertr(_source != NULL, true); 00084 return _source->is_eof(); 00085 } 00086 00087 //////////////////////////////////////////////////////////////////// 00088 // Function: BamReader::get_file_major_ver 00089 // Access: Published 00090 // Description: Returns the major version number of the Bam file 00091 // currently being read. 00092 //////////////////////////////////////////////////////////////////// 00093 INLINE int BamReader:: 00094 get_file_major_ver() const { 00095 return _file_major; 00096 } 00097 00098 //////////////////////////////////////////////////////////////////// 00099 // Function: BamReader::get_file_minor_ver 00100 // Access: Published 00101 // Description: Returns the minor version number of the Bam file 00102 // currently being read. 00103 //////////////////////////////////////////////////////////////////// 00104 INLINE int BamReader:: 00105 get_file_minor_ver() const { 00106 return _file_minor; 00107 } 00108 00109 //////////////////////////////////////////////////////////////////// 00110 // Function: BamReader::get_file_endian 00111 // Access: Published 00112 // Description: Returns the endian preference indicated by the Bam 00113 // file currently being read. This does not imply that 00114 // every number is stored using the indicated 00115 // convention, but individual objects may choose to 00116 // respect this flag when recording data. 00117 //////////////////////////////////////////////////////////////////// 00118 INLINE BamReader::BamEndian BamReader:: 00119 get_file_endian() const { 00120 return _file_endian; 00121 } 00122 00123 //////////////////////////////////////////////////////////////////// 00124 // Function: BamReader::get_file_stdfloat_double 00125 // Access: Published 00126 // Description: Returns true if the file stores all "standard" 00127 // floats as 64-bit doubles, or false if they are 32-bit 00128 // floats. This is determined by the compilation flags 00129 // of the version of Panda that generated this file. 00130 //////////////////////////////////////////////////////////////////// 00131 INLINE bool BamReader:: 00132 get_file_stdfloat_double() const { 00133 return _file_stdfloat_double; 00134 } 00135 00136 //////////////////////////////////////////////////////////////////// 00137 // Function: BamReader::get_current_major_ver 00138 // Access: Published 00139 // Description: Returns the major version number of Bam files 00140 // supported by the current code base. This must match 00141 // get_file_major_ver() in order to successfully read a 00142 // file. 00143 //////////////////////////////////////////////////////////////////// 00144 INLINE int BamReader:: 00145 get_current_major_ver() const { 00146 return _cur_major; 00147 } 00148 00149 //////////////////////////////////////////////////////////////////// 00150 // Function: BamReader::get_current_minor_ver 00151 // Access: Published 00152 // Description: Returns the minor version number of Bam files 00153 // supported by the current code base. This must match 00154 // or exceed get_file_minor_ver() in order to 00155 // successfully read a file. 00156 //////////////////////////////////////////////////////////////////// 00157 INLINE int BamReader:: 00158 get_current_minor_ver() const { 00159 return _cur_minor; 00160 } 00161 00162 //////////////////////////////////////////////////////////////////// 00163 // Function: BamReader::get_file 00164 // Access: Public 00165 // Description: Returns the FileReference that provides the source for 00166 // these datagrams, if any, or NULL if the datagrams do 00167 // not originate from a file on disk. 00168 //////////////////////////////////////////////////////////////////// 00169 INLINE const FileReference *BamReader:: 00170 get_file() { 00171 nassertr(_source != NULL, NULL); 00172 return _source->get_file(); 00173 } 00174 00175 //////////////////////////////////////////////////////////////////// 00176 // Function: BamReader::get_vfile 00177 // Access: Public 00178 // Description: Returns the VirtualFile that provides the source for 00179 // these datagrams, if any, or NULL if the datagrams do 00180 // not originate from a VirtualFile. 00181 //////////////////////////////////////////////////////////////////// 00182 INLINE VirtualFile *BamReader:: 00183 get_vfile() { 00184 nassertr(_source != NULL, NULL); 00185 return _source->get_vfile(); 00186 } 00187 00188 //////////////////////////////////////////////////////////////////// 00189 // Function: BamReader::get_file_pos 00190 // Access: Public 00191 // Description: Returns the current file position within the data 00192 // stream, if any, or 0 if the file position is not 00193 // meaningful or cannot be determined. 00194 // 00195 // For BamReaders that return a meaningful file 00196 // position, this will be pointing to the first byte 00197 // following the datagram returned after a call to 00198 // get_datagram(). 00199 //////////////////////////////////////////////////////////////////// 00200 INLINE streampos BamReader:: 00201 get_file_pos() { 00202 nassertr(_source != NULL, 0); 00203 return _source->get_file_pos(); 00204 } 00205 00206 //////////////////////////////////////////////////////////////////// 00207 // Function: BamReader::get_factory 00208 // Access: Public, Static 00209 // Description: Returns the global WritableFactory for generating 00210 // TypedWritable objects 00211 //////////////////////////////////////////////////////////////////// 00212 INLINE WritableFactory *BamReader:: 00213 get_factory() { 00214 if (_factory == (WritableFactory *)NULL) { 00215 create_factory(); 00216 } 00217 return _factory; 00218 } 00219 00220 //////////////////////////////////////////////////////////////////// 00221 // Function: BamReader::create_factory 00222 // Access: Private, Static 00223 // Description: Creates a new WritableFactory for generating 00224 // TypedWritable objects 00225 //////////////////////////////////////////////////////////////////// 00226 INLINE void BamReader:: 00227 create_factory() { 00228 _factory = new WritableFactory; 00229 } 00230 00231 //////////////////////////////////////////////////////////////////// 00232 // Function: BamReader::get_datagram 00233 // Access: Private 00234 // Description: Reads a single datagram from the stream. Returns 00235 // true on success, false on failure. 00236 //////////////////////////////////////////////////////////////////// 00237 INLINE bool BamReader:: 00238 get_datagram(Datagram &datagram) { 00239 nassertr(_source != NULL, false); 00240 if (_source->is_error()) { 00241 return false; 00242 } 00243 00244 if (!_source->get_datagram(datagram)) { 00245 return false; 00246 } 00247 00248 datagram.set_stdfloat_double(_file_stdfloat_double); 00249 return true; 00250 } 00251 00252 //////////////////////////////////////////////////////////////////// 00253 // Function: BamReader::AuxData::Constructor 00254 // Access: Public 00255 // Description: 00256 //////////////////////////////////////////////////////////////////// 00257 INLINE BamReader::AuxData:: 00258 AuxData() { 00259 } 00260 00261 //////////////////////////////////////////////////////////////////// 00262 // Function: BamReader::CreatedObj::Constructor 00263 // Access: Public 00264 // Description: 00265 //////////////////////////////////////////////////////////////////// 00266 INLINE BamReader::CreatedObj:: 00267 CreatedObj() : 00268 _created(false), 00269 _ptr(NULL), 00270 _ref_ptr(NULL), 00271 _change_this(NULL), 00272 _change_this_ref(NULL) 00273 { 00274 } 00275 00276 //////////////////////////////////////////////////////////////////// 00277 // Function: BamReader::CreatedObj::Destructor 00278 // Access: Public 00279 // Description: 00280 //////////////////////////////////////////////////////////////////// 00281 INLINE BamReader::CreatedObj:: 00282 ~CreatedObj() { 00283 set_ptr(NULL, NULL); 00284 } 00285 00286 //////////////////////////////////////////////////////////////////// 00287 // Function: BamReader::CreatedObj::set_ptr 00288 // Access: Public 00289 // Description: Replaces the pointer to the created object. There 00290 // are actually two pointers to the same object in 00291 // different forms: a generic TypedWritable pointer, and 00292 // an untyped ReferenceCount pointer. We need both 00293 // pointers because some objects (like PandaNode) 00294 // inherit from TypedWritable and ReferenceCount 00295 // independently. 00296 // 00297 // Managing a typed pointer and an untyped 00298 // ReferenceCount pointer to the same object takes just 00299 // a bit of extra care. 00300 //////////////////////////////////////////////////////////////////// 00301 INLINE void BamReader::CreatedObj:: 00302 set_ptr(TypedWritable *ptr, ReferenceCount *ref_ptr) { 00303 if (_ptr != ptr) { 00304 if (_ref_ptr != NULL) { 00305 nassertv(_ref_ptr != ref_ptr); 00306 unref_delete(_ref_ptr); 00307 } 00308 00309 _ptr = ptr; 00310 _ref_ptr = ref_ptr; 00311 00312 if (_ref_ptr != NULL) { 00313 _ref_ptr->ref(); 00314 } 00315 } else { 00316 nassertv(_ref_ptr == ref_ptr); 00317 } 00318 } 00319 00320 //////////////////////////////////////////////////////////////////// 00321 // Function: parse_params 00322 // Access: Private, Static 00323 // Description: Takes in a FactoryParams, passed from a WritableFactory 00324 // into any TypedWritable's make function, and parses 00325 // out the datagram that contatins the data it needs to 00326 // construct itself, and parses out the pointer to the 00327 // managing BamReader object 00328 //////////////////////////////////////////////////////////////////// 00329 INLINE void 00330 parse_params(const FactoryParams ¶ms, 00331 DatagramIterator &scan, BamReader *&manager) { 00332 BamReaderParam *param = DCAST(BamReaderParam, params.get_param(0)); 00333 00334 scan = param->get_iterator(); 00335 manager = param->get_manager(); 00336 } 00337