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