00001 // Filename: fltInstanceDefinition.cxx 00002 // Created by: drose (30Aug00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #include "fltInstanceDefinition.h" 00020 #include "fltRecordReader.h" 00021 #include "fltRecordWriter.h" 00022 00023 TypeHandle FltInstanceDefinition::_type_handle; 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Function: FltInstanceDefinition::Constructor 00027 // Access: Public 00028 // Description: 00029 //////////////////////////////////////////////////////////////////// 00030 FltInstanceDefinition:: 00031 FltInstanceDefinition(FltHeader *header) : FltBead(header) { 00032 _instance_index = 0; 00033 } 00034 00035 //////////////////////////////////////////////////////////////////// 00036 // Function: FltInstanceDefinition::extract_record 00037 // Access: Protected, Virtual 00038 // Description: Fills in the information in this bead based on the 00039 // information given in the indicated datagram, whose 00040 // opcode has already been read. Returns true on 00041 // success, false if the datagram is invalid. 00042 //////////////////////////////////////////////////////////////////// 00043 bool FltInstanceDefinition:: 00044 extract_record(FltRecordReader &reader) { 00045 if (!FltBead::extract_record(reader)) { 00046 return false; 00047 } 00048 00049 nassertr(reader.get_opcode() == FO_instance, false); 00050 DatagramIterator &iterator = reader.get_iterator(); 00051 00052 iterator.skip_bytes(2); 00053 _instance_index = iterator.get_be_int16(); 00054 00055 check_remaining_size(iterator); 00056 return true; 00057 } 00058 00059 //////////////////////////////////////////////////////////////////// 00060 // Function: FltInstanceDefinition::build_record 00061 // Access: Protected, Virtual 00062 // Description: Fills up the current record on the FltRecordWriter with 00063 // data for this record, but does not advance the 00064 // writer. Returns true on success, false if there is 00065 // some error. 00066 //////////////////////////////////////////////////////////////////// 00067 bool FltInstanceDefinition:: 00068 build_record(FltRecordWriter &writer) const { 00069 if (!FltBead::build_record(writer)) { 00070 return false; 00071 } 00072 00073 writer.set_opcode(FO_instance); 00074 Datagram &datagram = writer.update_datagram(); 00075 00076 datagram.pad_bytes(2); 00077 datagram.add_be_int16(_instance_index); 00078 00079 return true; 00080 }