00001 // Filename: dataNodeTransmit.cxx 00002 // Created by: drose (11Mar02) 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 "dataNodeTransmit.h" 00016 #include "bamReader.h" 00017 #include "bamWriter.h" 00018 00019 TypeHandle DataNodeTransmit::_type_handle; 00020 00021 //////////////////////////////////////////////////////////////////// 00022 // Function: DataNodeTransmit::Destructor 00023 // Access: Public, Virtual 00024 // Description: 00025 //////////////////////////////////////////////////////////////////// 00026 DataNodeTransmit:: 00027 ~DataNodeTransmit() { 00028 } 00029 00030 //////////////////////////////////////////////////////////////////// 00031 // Function: DataNodeTransmit::slot_data 00032 // Access: Private 00033 // Description: Ensures that the given index number exists in the 00034 // data array. 00035 //////////////////////////////////////////////////////////////////// 00036 void DataNodeTransmit:: 00037 slot_data(int index) { 00038 nassertv(index < 1000); 00039 while (index >= (int)_data.size()) { 00040 _data.push_back(EventParameter()); 00041 } 00042 } 00043 00044 //////////////////////////////////////////////////////////////////// 00045 // Function: DataNodeTransmit::register_with_read_factory 00046 // Access: Public, Static 00047 // Description: Tells the BamReader how to create objects of type 00048 // Lens. 00049 //////////////////////////////////////////////////////////////////// 00050 void DataNodeTransmit:: 00051 register_with_read_factory() { 00052 BamReader::get_factory()->register_factory(get_class_type(), make_from_bam); 00053 } 00054 00055 //////////////////////////////////////////////////////////////////// 00056 // Function: DataNodeTransmit::write_datagram 00057 // Access: Public, Virtual 00058 // Description: Writes the contents of this object to the datagram 00059 // for shipping out to a Bam file. 00060 //////////////////////////////////////////////////////////////////// 00061 void DataNodeTransmit:: 00062 write_datagram(BamWriter *manager, Datagram &dg) { 00063 TypedWritable::write_datagram(manager, dg); 00064 00065 dg.add_uint16(_data.size()); 00066 Data::const_iterator di; 00067 for (di = _data.begin(); di != _data.end(); ++di) { 00068 const EventParameter ¶m = (*di); 00069 TypedWritableReferenceCount *ptr = param.get_ptr(); 00070 manager->write_pointer(dg, ptr); 00071 } 00072 } 00073 00074 //////////////////////////////////////////////////////////////////// 00075 // Function: DataNodeTransmit::complete_pointers 00076 // Access: Public, Virtual 00077 // Description: Receives an array of pointers, one for each time 00078 // manager->read_pointer() was called in fillin(). 00079 // Returns the number of pointers processed. 00080 //////////////////////////////////////////////////////////////////// 00081 int DataNodeTransmit:: 00082 complete_pointers(TypedWritable **p_list, BamReader *manager) { 00083 int pi = TypedWritable::complete_pointers(p_list, manager); 00084 00085 Data::iterator di; 00086 for (di = _data.begin(); di != _data.end(); ++di) { 00087 (*di) = EventParameter(DCAST(TypedWritableReferenceCount, p_list[pi++])); 00088 } 00089 00090 return pi; 00091 } 00092 00093 //////////////////////////////////////////////////////////////////// 00094 // Function: DataNodeTransmit::make_from_bam 00095 // Access: Protected, Static 00096 // Description: This function is called by the BamReader's factory 00097 // when a new object of type Lens is encountered 00098 // in the Bam file. It should create the Lens 00099 // and extract its information from the file. 00100 //////////////////////////////////////////////////////////////////// 00101 TypedWritable *DataNodeTransmit:: 00102 make_from_bam(const FactoryParams ¶ms) { 00103 DataNodeTransmit *xmit = new DataNodeTransmit; 00104 DatagramIterator scan; 00105 BamReader *manager; 00106 00107 parse_params(params, scan, manager); 00108 xmit->fillin(scan, manager); 00109 00110 return xmit; 00111 } 00112 00113 //////////////////////////////////////////////////////////////////// 00114 // Function: DataNodeTransmit::fillin 00115 // Access: Protected 00116 // Description: This internal function is called by make_from_bam to 00117 // read in all of the relevant data from the BamFile for 00118 // the new Lens. 00119 //////////////////////////////////////////////////////////////////// 00120 void DataNodeTransmit:: 00121 fillin(DatagramIterator &scan, BamReader *manager) { 00122 TypedWritable::fillin(scan, manager); 00123 00124 int num_params = scan.get_uint16(); 00125 _data.reserve(num_params); 00126 for (int i = 0; i < num_params; i++) { 00127 manager->read_pointer(scan); 00128 _data.push_back(EventParameter()); 00129 } 00130 }