00001 // Filename: lwoHeader.cxx 00002 // Created by: drose (24Apr01) 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 "lwoHeader.h" 00016 #include "lwoInputFile.h" 00017 00018 #include "dcast.h" 00019 #include "indent.h" 00020 00021 TypeHandle LwoHeader::_type_handle; 00022 00023 //////////////////////////////////////////////////////////////////// 00024 // Function: LwoHeader::Constructor 00025 // Access: Public 00026 // Description: 00027 //////////////////////////////////////////////////////////////////// 00028 LwoHeader:: 00029 LwoHeader() { 00030 _valid = false; 00031 _version = 0.0; 00032 } 00033 00034 //////////////////////////////////////////////////////////////////// 00035 // Function: LwoHeader::read_iff 00036 // Access: Public, Virtual 00037 // Description: Reads the data of the chunk in from the given input 00038 // file, if possible. The ID and length of the chunk 00039 // have already been read. stop_at is the byte position 00040 // of the file to stop at (based on the current position 00041 // at in->get_bytes_read()). Returns true on success, 00042 // false otherwise. 00043 //////////////////////////////////////////////////////////////////// 00044 bool LwoHeader:: 00045 read_iff(IffInputFile *in, size_t stop_at) { 00046 LwoInputFile *lin = DCAST(LwoInputFile, in); 00047 00048 _lwid = lin->get_id(); 00049 00050 if (_lwid == IffId("LWO2")) { 00051 _valid = true; 00052 _version = 6.0; 00053 } else if (_lwid == IffId("LWOB")) { 00054 _valid = true; 00055 _version = 5.0; 00056 } 00057 00058 if (_valid) { 00059 lin->set_lwo_version(_version); 00060 } 00061 00062 read_chunks_iff(lin, stop_at); 00063 00064 return true; 00065 } 00066 00067 //////////////////////////////////////////////////////////////////// 00068 // Function: LwoHeader::write 00069 // Access: Public, Virtual 00070 // Description: 00071 //////////////////////////////////////////////////////////////////// 00072 void LwoHeader:: 00073 write(ostream &out, int indent_level) const { 00074 indent(out, indent_level) 00075 << get_id() << " {\n"; 00076 indent(out, indent_level + 2) 00077 << "id = " << _lwid << "\n"; 00078 write_chunks(out, indent_level + 2); 00079 indent(out, indent_level) 00080 << "}\n"; 00081 }