forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataNodeTransmit.cxx
More file actions
110 lines (95 loc) · 2.76 KB
/
dataNodeTransmit.cxx
File metadata and controls
110 lines (95 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file dataNodeTransmit.cxx
* @author drose
* @date 2002-03-11
*/
#include "dataNodeTransmit.h"
#include "bamReader.h"
#include "bamWriter.h"
TypeHandle DataNodeTransmit::_type_handle;
/**
*
*/
DataNodeTransmit::
~DataNodeTransmit() {
}
/**
* Ensures that the given index number exists in the data array.
*/
void DataNodeTransmit::
slot_data(int index) {
nassertv(index < 1000);
while (index >= (int)_data.size()) {
_data.push_back(EventParameter());
}
}
/**
* Tells the BamReader how to create objects of type Lens.
*/
void DataNodeTransmit::
register_with_read_factory() {
BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
}
/**
* Writes the contents of this object to the datagram for shipping out to a
* Bam file.
*/
void DataNodeTransmit::
write_datagram(BamWriter *manager, Datagram &dg) {
TypedWritable::write_datagram(manager, dg);
dg.add_uint16(_data.size());
Data::const_iterator di;
for (di = _data.begin(); di != _data.end(); ++di) {
const EventParameter ¶m = (*di);
TypedWritableReferenceCount *ptr = param.get_ptr();
manager->write_pointer(dg, ptr);
}
}
/**
* Receives an array of pointers, one for each time manager->read_pointer()
* was called in fillin(). Returns the number of pointers processed.
*/
int DataNodeTransmit::
complete_pointers(TypedWritable **p_list, BamReader *manager) {
int pi = TypedWritable::complete_pointers(p_list, manager);
Data::iterator di;
for (di = _data.begin(); di != _data.end(); ++di) {
(*di) = EventParameter(DCAST(TypedWritableReferenceCount, p_list[pi++]));
}
return pi;
}
/**
* This function is called by the BamReader's factory when a new object of
* type Lens is encountered in the Bam file. It should create the Lens and
* extract its information from the file.
*/
TypedWritable *DataNodeTransmit::
make_from_bam(const FactoryParams ¶ms) {
DataNodeTransmit *xmit = new DataNodeTransmit;
DatagramIterator scan;
BamReader *manager;
parse_params(params, scan, manager);
xmit->fillin(scan, manager);
return xmit;
}
/**
* This internal function is called by make_from_bam to read in all of the
* relevant data from the BamFile for the new Lens.
*/
void DataNodeTransmit::
fillin(DatagramIterator &scan, BamReader *manager) {
TypedWritable::fillin(scan, manager);
int num_params = scan.get_uint16();
_data.reserve(num_params);
for (int i = 0; i < num_params; i++) {
manager->read_pointer(scan);
_data.push_back(EventParameter());
}
}