Browse Source

*** empty log message ***

David Rose 24 years ago
parent
commit
c275aa7e17

+ 20 - 3
panda/src/chan/auto_bind.cxx

@@ -14,6 +14,7 @@
 #include <nullAttributeWrapper.h>
 #include <nullAttributeWrapper.h>
 #include <nullLevelState.h>
 #include <nullLevelState.h>
 #include <renderRelation.h>
 #include <renderRelation.h>
+#include <string_utils.h>
 
 
 typedef set<AnimBundleNode *> AnimNodes;
 typedef set<AnimBundleNode *> AnimNodes;
 typedef map<string, AnimNodes> Anims;
 typedef map<string, AnimNodes> Anims;
@@ -78,8 +79,20 @@ bind_anims(const PartNodes &parts, const AnimNodes &anims,
 
 
       PT(AnimControl) control = 
       PT(AnimControl) control = 
 	part->bind_anim(anim, hierarchy_match_flags);
 	part->bind_anim(anim, hierarchy_match_flags);
+      string name = anim->get_name();
       if (control != (AnimControl *)NULL) {
       if (control != (AnimControl *)NULL) {
-	controls.store_anim(control, anim->get_name());
+	if (controls.find_anim(name) != (AnimControl *)NULL) {
+	  // That name's already used; synthesize another one.
+	  int index = 0;
+	  string new_name;
+	  do {
+	    index++;
+	    new_name = name + '.' + format_string(index);
+	  } while (controls.find_anim(new_name) != (AnimControl *)NULL);
+	  name = new_name;
+	}
+
+	controls.store_anim(control, name);
       }
       }
 
 
       if (chan_cat.is_info()) {
       if (chan_cat.is_info()) {
@@ -89,7 +102,8 @@ bind_anims(const PartNodes &parts, const AnimNodes &anims,
 	} else {
 	} else {
 	  chan_cat.info()
 	  chan_cat.info()
 	    << "Bind succeeded, index "
 	    << "Bind succeeded, index "
-	    << control->get_channel_index() << "\n";
+	    << control->get_channel_index() << "; accessible as " 
+	    << name << "\n";
 	}
 	}
       }
       }
     }
     }
@@ -132,8 +146,11 @@ void auto_bind(Node *root_node, AnimControlCollection &controls,
       // But here we have (at least one) match!
       // But here we have (at least one) match!
       bind_anims((*pi).second, (*ai).second, controls, 
       bind_anims((*pi).second, (*ai).second, controls, 
 		 hierarchy_match_flags);
 		 hierarchy_match_flags);
-      ++ai;
       ++pi;
       ++pi;
+
+      // We don't increment the anim counter yet.  That way, the same
+      // anim may bind to multiple parts, if they all share the same
+      // name.
     }
     }
   }
   }
 }
 }

+ 26 - 0
panda/src/sgattrib/colorProperty.cxx

@@ -4,6 +4,8 @@
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 
 
 #include "colorProperty.h"
 #include "colorProperty.h"
+#include <datagram.h>
+#include <datagramIterator.h>
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: ColorProperty::output
 //     Function: ColorProperty::output
@@ -18,3 +20,27 @@ output(ostream &out) const {
     out << "uncolor";
     out << "uncolor";
   }
   }
 }
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: ColorProperty::write_datagram
+//       Access: Public
+//  Description: Function to write the important information in
+//               this object to a Datagram
+////////////////////////////////////////////////////////////////////
+void ColorProperty::
+write_datagram(Datagram &destination) {
+  _color.write_datagram(destination);
+  destination.add_bool(_real);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: ColorProperty::read_datagram
+//       Access: Public
+//  Description: Function to write the important information into
+//               this object out of a Datagram
+////////////////////////////////////////////////////////////////////
+void ColorProperty::
+read_datagram(DatagramIterator &source) {
+  _color.read_datagram(source);
+  _real = source.get_bool();
+}

+ 7 - 0
panda/src/sgattrib/colorProperty.h

@@ -10,6 +10,9 @@
 
 
 #include <luse.h>
 #include <luse.h>
 
 
+class Datagram;
+class DatagramIterator;
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 // 	 Class : ColorProperty
 // 	 Class : ColorProperty
 // Description : This class defines the scene graph color property
 // Description : This class defines the scene graph color property
@@ -33,6 +36,10 @@ public:
   INLINE int compare_to(const ColorProperty &other) const;
   INLINE int compare_to(const ColorProperty &other) const;
   void output(ostream &out) const;
   void output(ostream &out) const;
 
 
+public:
+  void write_datagram(Datagram &destination);
+  void read_datagram(DatagramIterator &source);
+
 private:
 private:
   Colorf _color;
   Colorf _color;
   bool _real;
   bool _real;

+ 56 - 0
panda/src/sgattrib/colorTransition.cxx

@@ -7,6 +7,10 @@
 #include "colorAttribute.h"
 #include "colorAttribute.h"
 
 
 #include <indent.h>
 #include <indent.h>
+#include <datagram.h>
+#include <datagramIterator.h>
+#include <bamReader.h>
+#include <bamWriter.h>
 
 
 TypeHandle ColorTransition::_type_handle;
 TypeHandle ColorTransition::_type_handle;
 
 
@@ -78,3 +82,55 @@ void ColorTransition::
 write_value(ostream &out, int indent_level) const {
 write_value(ostream &out, int indent_level) const {
   indent(out, indent_level) << _value << "\n";
   indent(out, indent_level) << _value << "\n";
 }
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: ColorTransition::register_with_read_factory
+//       Access: Public, Static
+//  Description: Factory method to generate a ColorTransition object
+////////////////////////////////////////////////////////////////////
+void ColorTransition::
+register_with_read_factory() {
+  BamReader::get_factory()->register_factory(get_class_type(), make_ColorTransition);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: ColorTransition::write_datagram
+//       Access: Public
+//  Description: Function to write the important information in
+//               the particular object to a Datagram
+////////////////////////////////////////////////////////////////////
+void ColorTransition::
+write_datagram(BamWriter *manager, Datagram &me) {
+  OnOffTransition::write_datagram(manager, me);
+  _value.write_datagram(me);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: ColorTransition::make_ColorTransition
+//       Access: Protected
+//  Description: Factory method to generate a ColorTransition object
+////////////////////////////////////////////////////////////////////
+TypedWritable *ColorTransition::
+make_ColorTransition(const FactoryParams &params) {
+  ColorTransition *me = new ColorTransition;
+  DatagramIterator scan;
+  BamReader *manager;
+
+  parse_params(params, scan, manager);
+  me->fillin(scan, manager);
+  return me;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: ColorTransition::fillin
+//       Access: Protected
+//  Description: Function that reads out of the datagram (or asks
+//               manager to read) all of the data that is needed to
+//               re-create this object and stores it in the appropiate
+//               place
+////////////////////////////////////////////////////////////////////
+void ColorTransition::
+fillin(DatagramIterator& scan, BamReader* manager) {
+  OnOffTransition::fillin(scan, manager);
+  _value.read_datagram(scan);
+}

+ 8 - 0
panda/src/sgattrib/colorTransition.h

@@ -49,6 +49,14 @@ protected:
 
 
   ColorProperty _value;
   ColorProperty _value;
 
 
+public:
+  static void register_with_read_factory();
+  virtual void write_datagram(BamWriter *manager, Datagram &me);  
+
+protected:
+  static TypedWritable *make_ColorTransition(const FactoryParams &params);
+  void fillin(DatagramIterator& scan, BamReader* manager);
+
 public:
 public:
   virtual TypeHandle get_type() const {
   virtual TypeHandle get_type() const {
     return get_class_type();
     return get_class_type();

+ 1 - 0
panda/src/sgattrib/config_sgattrib.cxx

@@ -188,6 +188,7 @@ ConfigureFn(config_sgattrib) {
   //functions with BamReader's factory
   //functions with BamReader's factory
   BillboardTransition::register_with_read_factory();
   BillboardTransition::register_with_read_factory();
   ColorMatrixTransition::register_with_read_factory();
   ColorMatrixTransition::register_with_read_factory();
+  ColorTransition::register_with_read_factory();
   CullFaceTransition::register_with_read_factory();
   CullFaceTransition::register_with_read_factory();
   DecalTransition::register_with_read_factory();
   DecalTransition::register_with_read_factory();
   DepthTestTransition::register_with_read_factory();
   DepthTestTransition::register_with_read_factory();