00001 // Filename: fltInstanceDefinition.cxx 00002 // Created by: drose (30Aug00) 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 "fltInstanceDefinition.h" 00016 #include "fltRecordReader.h" 00017 #include "fltRecordWriter.h" 00018 00019 TypeHandle FltInstanceDefinition::_type_handle; 00020 00021 //////////////////////////////////////////////////////////////////// 00022 // Function: FltInstanceDefinition::Constructor 00023 // Access: Public 00024 // Description: 00025 //////////////////////////////////////////////////////////////////// 00026 FltInstanceDefinition:: 00027 FltInstanceDefinition(FltHeader *header) : FltBead(header) { 00028 _instance_index = 0; 00029 } 00030 00031 //////////////////////////////////////////////////////////////////// 00032 // Function: FltInstanceDefinition::extract_record 00033 // Access: Protected, Virtual 00034 // Description: Fills in the information in this bead based on the 00035 // information given in the indicated datagram, whose 00036 // opcode has already been read. Returns true on 00037 // success, false if the datagram is invalid. 00038 //////////////////////////////////////////////////////////////////// 00039 bool FltInstanceDefinition:: 00040 extract_record(FltRecordReader &reader) { 00041 if (!FltBead::extract_record(reader)) { 00042 return false; 00043 } 00044 00045 nassertr(reader.get_opcode() == FO_instance, false); 00046 DatagramIterator &iterator = reader.get_iterator(); 00047 00048 iterator.skip_bytes(2); 00049 _instance_index = iterator.get_be_int16(); 00050 00051 check_remaining_size(iterator); 00052 return true; 00053 } 00054 00055 //////////////////////////////////////////////////////////////////// 00056 // Function: FltInstanceDefinition::build_record 00057 // Access: Protected, Virtual 00058 // Description: Fills up the current record on the FltRecordWriter with 00059 // data for this record, but does not advance the 00060 // writer. Returns true on success, false if there is 00061 // some error. 00062 //////////////////////////////////////////////////////////////////// 00063 bool FltInstanceDefinition:: 00064 build_record(FltRecordWriter &writer) const { 00065 if (!FltBead::build_record(writer)) { 00066 return false; 00067 } 00068 00069 writer.set_opcode(FO_instance); 00070 Datagram &datagram = writer.update_datagram(); 00071 00072 datagram.pad_bytes(2); 00073 datagram.add_be_int16(_instance_index); 00074 00075 return true; 00076 }