Browse Source

Add MovingPartBase::_forced_channel to bam stream

David Rose 16 years ago
parent
commit
aee550231c

+ 63 - 1
panda/src/chan/animChannelMatrixFixed.cxx

@@ -138,7 +138,7 @@ get_shear(int, LVecBase3f &shear) {
 }
 
 ////////////////////////////////////////////////////////////////////
-//     Function: AnimChannelFixed::output
+//     Function: AnimChannelMatrixFixed::output
 //       Access: Public, Virtual
 //  Description:
 ////////////////////////////////////////////////////////////////////
@@ -147,3 +147,65 @@ output(ostream &out) const {
   AnimChannel<ACMatrixSwitchType>::output(out);
   out << ": pos " << _pos << " hpr " << _hpr << " scale " << _scale;
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: AnimChannelMatrixFixed::register_with_read_factory
+//       Access: Public, Static
+//  Description: Tells the BamReader how to create objects of type
+//               AnimChannelMatrixFixed.
+////////////////////////////////////////////////////////////////////
+void AnimChannelMatrixFixed::
+register_with_read_factory() {
+  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: AnimChannelMatrixFixed::write_datagram
+//       Access: Public, Virtual
+//  Description: Writes the contents of this object to the datagram
+//               for shipping out to a Bam file.
+////////////////////////////////////////////////////////////////////
+void AnimChannelMatrixFixed::
+write_datagram(BamWriter *manager, Datagram &dg) {
+  AnimChannel<ACMatrixSwitchType>::write_datagram(manager, dg);
+
+  _pos.write_datagram(dg);
+  _hpr.write_datagram(dg);
+  _scale.write_datagram(dg);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: AnimChannelMatrixFixed::make_from_bam
+//       Access: Protected, Static
+//  Description: This function is called by the BamReader's factory
+//               when a new object of type AnimChannelMatrixFixed is encountered
+//               in the Bam file.  It should create the AnimChannelMatrixFixed
+//               and extract its information from the file.
+////////////////////////////////////////////////////////////////////
+TypedWritable *AnimChannelMatrixFixed::
+make_from_bam(const FactoryParams &params) {
+  AnimChannelMatrixFixed *chan = new AnimChannelMatrixFixed("", LVecBase3f::zero(), LVecBase3f::zero(), LVecBase3f::zero());
+  DatagramIterator scan;
+  BamReader *manager;
+
+  parse_params(params, scan, manager);
+  chan->fillin(scan, manager);
+
+  return chan;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: AnimChannelMatrixFixed::fillin
+//       Access: Protected
+//  Description: This internal function is called by make_from_bam to
+//               read in all of the relevant data from the BamFile for
+//               the new AnimChannelMatrixFixed.
+////////////////////////////////////////////////////////////////////
+void AnimChannelMatrixFixed::
+fillin(DatagramIterator &scan, BamReader *manager) {
+  AnimChannel<ACMatrixSwitchType>::fillin(scan, manager);
+
+  _pos.read_datagram(scan);
+  _hpr.read_datagram(scan);
+  _scale.read_datagram(scan);
+}

+ 8 - 0
panda/src/chan/animChannelMatrixFixed.h

@@ -49,6 +49,14 @@ public:
 private:
   LVecBase3f _pos, _hpr, _scale;
 
+public:
+  static void register_with_read_factory();
+  virtual void write_datagram(BamWriter *manager, Datagram &dg);
+
+protected:
+  static TypedWritable *make_from_bam(const FactoryParams &params);
+  void fillin(DatagramIterator &scan, BamReader *manager);
+
 public:
   virtual TypeHandle get_type() const {
     return get_class_type();

+ 3 - 3
panda/src/chan/animGroup.cxx

@@ -41,7 +41,8 @@ TypeHandle AnimGroup::_type_handle;
 AnimGroup::
 AnimGroup(const string &name) : 
   Namable(name),
-  _children(get_class_type())
+  _children(get_class_type()),
+  _root(NULL)
 {
 }
 
@@ -301,9 +302,8 @@ fillin(DatagramIterator &scan, BamReader *manager) {
 ////////////////////////////////////////////////////////////////////
 int AnimGroup::
 complete_pointers(TypedWritable **p_list, BamReader *) {
-  nassertr(p_list[0] != TypedWritable::Null, 0);
   _root = DCAST(AnimBundle, p_list[0]);
-  for(int i = 1; i < _num_children+1; i++) {
+  for (int i = 1; i < _num_children+1; i++) {
     if (p_list[i] == TypedWritable::Null) {
       chan_cat->warning() << get_type().get_name()
                           << " Ignoring null child" << endl;

+ 1 - 0
panda/src/chan/config_chan.cxx

@@ -142,6 +142,7 @@ ConfigureFn(config_chan) {
   AnimBundleNode::register_with_read_factory();
   AnimChannelMatrixXfmTable::register_with_read_factory();
   AnimChannelMatrixDynamic::register_with_read_factory();
+  AnimChannelMatrixFixed::register_with_read_factory();
   AnimChannelScalarTable::register_with_read_factory();
   AnimChannelScalarDynamic::register_with_read_factory();
   AnimPreloadTable::register_with_read_factory();

+ 62 - 0
panda/src/chan/movingPartBase.cxx

@@ -367,3 +367,65 @@ determine_effective_channels(const CycleData *root_cdata) {
 
   PartGroup::determine_effective_channels(root_cdata);
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: MovingPartBase::write_datagram
+//       Access: Public, Virtual
+//  Description: Writes the contents of this object to the datagram
+//               for shipping out to a Bam file.
+////////////////////////////////////////////////////////////////////
+void MovingPartBase::
+write_datagram(BamWriter *manager, Datagram &dg) {
+  PartGroup::write_datagram(manager, dg);
+
+  manager->write_pointer(dg, _forced_channel);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MovingPartBase::complete_pointers
+//       Access: Public, Virtual
+//  Description: Receives an array of pointers, one for each time
+//               manager->read_pointer() was called in fillin().
+//               Returns the number of pointers processed.
+//
+//               This is the callback function that is made by the
+//               BamReader at some later point, after all of the
+//               required pointers have been filled in.  It is
+//               necessary because there might be forward references
+//               in a bam file; when we call read_pointer() in
+//               fillin(), the object may not have been read from the
+//               file yet, so we do not have a pointer available at
+//               that time.  Thus, instead of returning a pointer,
+//               read_pointer() simply reserves a later callback.
+//               This function provides that callback.  The calling
+//               object is responsible for keeping track of the number
+//               of times it called read_pointer() and extracting the
+//               same number of pointers out of the supplied vector,
+//               and storing them appropriately within the object.
+////////////////////////////////////////////////////////////////////
+int MovingPartBase::
+complete_pointers(TypedWritable **p_list, BamReader *manager) {
+  int pi = PartGroup::complete_pointers(p_list, manager);
+
+  if (manager->get_file_minor_ver() >= 20) {
+    _forced_channel = DCAST(AnimChannelBase, p_list[pi++]);
+  }
+
+  return pi;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MovingPartBase::fillin
+//       Access: Protected
+//  Description: This internal function is called by make_from_bam to
+//               read in all of the relevant data from the BamFile for
+//               the new MovingPartBase.
+////////////////////////////////////////////////////////////////////
+void MovingPartBase::
+fillin(DatagramIterator &scan, BamReader *manager) {
+  PartGroup::fillin(scan, manager);
+
+  if (manager->get_file_minor_ver() >= 20) {
+    manager->read_pointer(scan);
+  }
+}

+ 7 - 0
panda/src/chan/movingPartBase.h

@@ -97,6 +97,13 @@ protected:
   // via set_forced_channel().  It overrides all of the above if set.
   PT(AnimChannelBase) _forced_channel;
 
+public:
+  virtual void write_datagram(BamWriter *manager, Datagram &dg);
+  virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
+
+protected:
+  void fillin(DatagramIterator &scan, BamReader *manager);
+
 public:
   virtual TypeHandle get_type() const {
     return get_class_type();

+ 2 - 1
panda/src/putil/bam.h

@@ -33,13 +33,14 @@ static const unsigned short _bam_major_ver = 6;
 // Bumped to major version 6 on 2/11/06 to factor out PandaNode::CData.
 
 static const unsigned short _bam_first_minor_ver = 14;
-static const unsigned short _bam_minor_ver = 19;
+static const unsigned short _bam_minor_ver = 20;
 // Bumped to minor version 14 on 12/19/07 to change default ColorAttrib.
 // Bumped to minor version 15 on 4/9/08 to add TextureAttrib::_implicit_sort.
 // Bumped to minor version 16 on 5/13/08 to add Texture::_quality_level.
 // Bumped to minor version 17 on 8/6/08 to add PartBundle::_anim_preload.
 // Bumped to minor version 18 on 8/14/08 to add Texture::_simple_ram_image.
 // Bumped to minor version 19 on 8/14/08 to add PandaNode::_bounds_type.
+// Bumped to minor version 20 on 4/21/09 to add MovingPartBase::_forced_channel.
 
 
 #endif