Skip to content

Commit aee5502

Browse files
committed
Add MovingPartBase::_forced_channel to bam stream
1 parent 6a87426 commit aee5502

File tree

7 files changed

+146
-5
lines changed

7 files changed

+146
-5
lines changed

panda/src/chan/animChannelMatrixFixed.cxx

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ get_shear(int, LVecBase3f &shear) {
138138
}
139139

140140
////////////////////////////////////////////////////////////////////
141-
// Function: AnimChannelFixed::output
141+
// Function: AnimChannelMatrixFixed::output
142142
// Access: Public, Virtual
143143
// Description:
144144
////////////////////////////////////////////////////////////////////
@@ -147,3 +147,65 @@ output(ostream &out) const {
147147
AnimChannel<ACMatrixSwitchType>::output(out);
148148
out << ": pos " << _pos << " hpr " << _hpr << " scale " << _scale;
149149
}
150+
151+
////////////////////////////////////////////////////////////////////
152+
// Function: AnimChannelMatrixFixed::register_with_read_factory
153+
// Access: Public, Static
154+
// Description: Tells the BamReader how to create objects of type
155+
// AnimChannelMatrixFixed.
156+
////////////////////////////////////////////////////////////////////
157+
void AnimChannelMatrixFixed::
158+
register_with_read_factory() {
159+
BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
160+
}
161+
162+
////////////////////////////////////////////////////////////////////
163+
// Function: AnimChannelMatrixFixed::write_datagram
164+
// Access: Public, Virtual
165+
// Description: Writes the contents of this object to the datagram
166+
// for shipping out to a Bam file.
167+
////////////////////////////////////////////////////////////////////
168+
void AnimChannelMatrixFixed::
169+
write_datagram(BamWriter *manager, Datagram &dg) {
170+
AnimChannel<ACMatrixSwitchType>::write_datagram(manager, dg);
171+
172+
_pos.write_datagram(dg);
173+
_hpr.write_datagram(dg);
174+
_scale.write_datagram(dg);
175+
}
176+
177+
////////////////////////////////////////////////////////////////////
178+
// Function: AnimChannelMatrixFixed::make_from_bam
179+
// Access: Protected, Static
180+
// Description: This function is called by the BamReader's factory
181+
// when a new object of type AnimChannelMatrixFixed is encountered
182+
// in the Bam file. It should create the AnimChannelMatrixFixed
183+
// and extract its information from the file.
184+
////////////////////////////////////////////////////////////////////
185+
TypedWritable *AnimChannelMatrixFixed::
186+
make_from_bam(const FactoryParams &params) {
187+
AnimChannelMatrixFixed *chan = new AnimChannelMatrixFixed("", LVecBase3f::zero(), LVecBase3f::zero(), LVecBase3f::zero());
188+
DatagramIterator scan;
189+
BamReader *manager;
190+
191+
parse_params(params, scan, manager);
192+
chan->fillin(scan, manager);
193+
194+
return chan;
195+
}
196+
197+
////////////////////////////////////////////////////////////////////
198+
// Function: AnimChannelMatrixFixed::fillin
199+
// Access: Protected
200+
// Description: This internal function is called by make_from_bam to
201+
// read in all of the relevant data from the BamFile for
202+
// the new AnimChannelMatrixFixed.
203+
////////////////////////////////////////////////////////////////////
204+
void AnimChannelMatrixFixed::
205+
fillin(DatagramIterator &scan, BamReader *manager) {
206+
AnimChannel<ACMatrixSwitchType>::fillin(scan, manager);
207+
208+
_pos.read_datagram(scan);
209+
_hpr.read_datagram(scan);
210+
_scale.read_datagram(scan);
211+
}

panda/src/chan/animChannelMatrixFixed.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ class EXPCL_PANDA_CHAN AnimChannelMatrixFixed : public AnimChannel<ACMatrixSwitc
4949
private:
5050
LVecBase3f _pos, _hpr, _scale;
5151

52+
public:
53+
static void register_with_read_factory();
54+
virtual void write_datagram(BamWriter *manager, Datagram &dg);
55+
56+
protected:
57+
static TypedWritable *make_from_bam(const FactoryParams &params);
58+
void fillin(DatagramIterator &scan, BamReader *manager);
59+
5260
public:
5361
virtual TypeHandle get_type() const {
5462
return get_class_type();

panda/src/chan/animGroup.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ TypeHandle AnimGroup::_type_handle;
4141
AnimGroup::
4242
AnimGroup(const string &name) :
4343
Namable(name),
44-
_children(get_class_type())
44+
_children(get_class_type()),
45+
_root(NULL)
4546
{
4647
}
4748

@@ -301,9 +302,8 @@ fillin(DatagramIterator &scan, BamReader *manager) {
301302
////////////////////////////////////////////////////////////////////
302303
int AnimGroup::
303304
complete_pointers(TypedWritable **p_list, BamReader *) {
304-
nassertr(p_list[0] != TypedWritable::Null, 0);
305305
_root = DCAST(AnimBundle, p_list[0]);
306-
for(int i = 1; i < _num_children+1; i++) {
306+
for (int i = 1; i < _num_children+1; i++) {
307307
if (p_list[i] == TypedWritable::Null) {
308308
chan_cat->warning() << get_type().get_name()
309309
<< " Ignoring null child" << endl;

panda/src/chan/config_chan.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ ConfigureFn(config_chan) {
142142
AnimBundleNode::register_with_read_factory();
143143
AnimChannelMatrixXfmTable::register_with_read_factory();
144144
AnimChannelMatrixDynamic::register_with_read_factory();
145+
AnimChannelMatrixFixed::register_with_read_factory();
145146
AnimChannelScalarTable::register_with_read_factory();
146147
AnimChannelScalarDynamic::register_with_read_factory();
147148
AnimPreloadTable::register_with_read_factory();

panda/src/chan/movingPartBase.cxx

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,3 +367,65 @@ determine_effective_channels(const CycleData *root_cdata) {
367367

368368
PartGroup::determine_effective_channels(root_cdata);
369369
}
370+
371+
////////////////////////////////////////////////////////////////////
372+
// Function: MovingPartBase::write_datagram
373+
// Access: Public, Virtual
374+
// Description: Writes the contents of this object to the datagram
375+
// for shipping out to a Bam file.
376+
////////////////////////////////////////////////////////////////////
377+
void MovingPartBase::
378+
write_datagram(BamWriter *manager, Datagram &dg) {
379+
PartGroup::write_datagram(manager, dg);
380+
381+
manager->write_pointer(dg, _forced_channel);
382+
}
383+
384+
////////////////////////////////////////////////////////////////////
385+
// Function: MovingPartBase::complete_pointers
386+
// Access: Public, Virtual
387+
// Description: Receives an array of pointers, one for each time
388+
// manager->read_pointer() was called in fillin().
389+
// Returns the number of pointers processed.
390+
//
391+
// This is the callback function that is made by the
392+
// BamReader at some later point, after all of the
393+
// required pointers have been filled in. It is
394+
// necessary because there might be forward references
395+
// in a bam file; when we call read_pointer() in
396+
// fillin(), the object may not have been read from the
397+
// file yet, so we do not have a pointer available at
398+
// that time. Thus, instead of returning a pointer,
399+
// read_pointer() simply reserves a later callback.
400+
// This function provides that callback. The calling
401+
// object is responsible for keeping track of the number
402+
// of times it called read_pointer() and extracting the
403+
// same number of pointers out of the supplied vector,
404+
// and storing them appropriately within the object.
405+
////////////////////////////////////////////////////////////////////
406+
int MovingPartBase::
407+
complete_pointers(TypedWritable **p_list, BamReader *manager) {
408+
int pi = PartGroup::complete_pointers(p_list, manager);
409+
410+
if (manager->get_file_minor_ver() >= 20) {
411+
_forced_channel = DCAST(AnimChannelBase, p_list[pi++]);
412+
}
413+
414+
return pi;
415+
}
416+
417+
////////////////////////////////////////////////////////////////////
418+
// Function: MovingPartBase::fillin
419+
// Access: Protected
420+
// Description: This internal function is called by make_from_bam to
421+
// read in all of the relevant data from the BamFile for
422+
// the new MovingPartBase.
423+
////////////////////////////////////////////////////////////////////
424+
void MovingPartBase::
425+
fillin(DatagramIterator &scan, BamReader *manager) {
426+
PartGroup::fillin(scan, manager);
427+
428+
if (manager->get_file_minor_ver() >= 20) {
429+
manager->read_pointer(scan);
430+
}
431+
}

panda/src/chan/movingPartBase.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ class EXPCL_PANDA_CHAN MovingPartBase : public PartGroup {
9797
// via set_forced_channel(). It overrides all of the above if set.
9898
PT(AnimChannelBase) _forced_channel;
9999

100+
public:
101+
virtual void write_datagram(BamWriter *manager, Datagram &dg);
102+
virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
103+
104+
protected:
105+
void fillin(DatagramIterator &scan, BamReader *manager);
106+
100107
public:
101108
virtual TypeHandle get_type() const {
102109
return get_class_type();

panda/src/putil/bam.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ static const unsigned short _bam_major_ver = 6;
3333
// Bumped to major version 6 on 2/11/06 to factor out PandaNode::CData.
3434

3535
static const unsigned short _bam_first_minor_ver = 14;
36-
static const unsigned short _bam_minor_ver = 19;
36+
static const unsigned short _bam_minor_ver = 20;
3737
// Bumped to minor version 14 on 12/19/07 to change default ColorAttrib.
3838
// Bumped to minor version 15 on 4/9/08 to add TextureAttrib::_implicit_sort.
3939
// Bumped to minor version 16 on 5/13/08 to add Texture::_quality_level.
4040
// Bumped to minor version 17 on 8/6/08 to add PartBundle::_anim_preload.
4141
// Bumped to minor version 18 on 8/14/08 to add Texture::_simple_ram_image.
4242
// Bumped to minor version 19 on 8/14/08 to add PandaNode::_bounds_type.
43+
// Bumped to minor version 20 on 4/21/09 to add MovingPartBase::_forced_channel.
4344

4445

4546
#endif

0 commit comments

Comments
 (0)