Browse Source

update pointers properly when flattening characters

David Rose 19 years ago
parent
commit
0d45017e81

+ 1 - 4
panda/src/char/character.cxx

@@ -806,10 +806,7 @@ r_clear_joint_characters(PartGroup *part) {
   if (part->is_of_type(CharacterJoint::get_class_type())) {
     CharacterJoint *joint = DCAST(CharacterJoint, part);
 
-    // Whoops!  We are not properly assigning the joint->_character
-    // node when we flatten characters!  TODO: fix this.
-    //    nassertv(joint->get_character() == this || joint->get_character() == NULL);
-
+    nassertv(joint->get_character() == this || joint->get_character() == NULL);
     joint->set_character(NULL);
   }
 

+ 1 - 0
panda/src/char/characterJoint.h

@@ -126,6 +126,7 @@ private:
   static TypeHandle _type_handle;
 
   friend class Character;
+  friend class CharacterJointBundle;
   friend class JointVertexTransform;
 };
 

+ 36 - 1
panda/src/char/characterJointBundle.cxx

@@ -35,7 +35,7 @@ CharacterJointBundle(const string &name) : PartBundle(name) {
 
 ////////////////////////////////////////////////////////////////////
 //     Function: CharacterJointBundle::make_copy
-//       Access: Public, Virtual
+//       Access: Protected, Virtual
 //  Description: Allocates and returns a new copy of the node.
 //               Children are not copied, but see copy_subgraph().
 ////////////////////////////////////////////////////////////////////
@@ -44,6 +44,41 @@ make_copy() const {
   return new CharacterJointBundle(*this);
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: CharacterJointBundle::set_node
+//       Access: Protected, Virtual
+//  Description: Changes the PartBundleNode pointer associated with
+//               the PartBundle.  Normally called only by the
+//               PartBundleNode itself, for instance when the bundle
+//               is flattened with another node.
+////////////////////////////////////////////////////////////////////
+void CharacterJointBundle::
+set_node(PartBundleNode *node) {
+  PartBundle::set_node(node);
+  if (node->is_of_type(Character::get_class_type())) {
+    Character *character = DCAST(Character, node);
+    r_set_character(this, character);
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: CharacterJointBundle::r_set_character
+//       Access: Private
+//  Description: Recursively sets the Character on each joint in the
+//               hierarchy.
+////////////////////////////////////////////////////////////////////
+void CharacterJointBundle::
+r_set_character(PartGroup *group, Character *character) {
+  if (group->is_of_type(CharacterJoint::get_class_type())) {
+    DCAST(CharacterJoint, group)->set_character(character);
+  }
+
+  Children::const_iterator ci;
+  for (ci = group->_children.begin(); ci != group->_children.end(); ++ci) {
+    r_set_character((*ci), character);
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: CharacterJointBundle::make_CharacterJointBundle
 //       Access: Protected

+ 6 - 1
panda/src/char/characterJointBundle.h

@@ -42,9 +42,14 @@ public:
 PUBLISHED:
   INLINE Character *get_node() const;
 
-public:
+protected:
   virtual PartGroup *make_copy() const;
+  virtual void set_node(PartBundleNode *node);
 
+private:
+  void r_set_character(PartGroup *group, Character *character);
+
+public:
   static void register_with_read_factory();
 
   static TypedWritable *make_CharacterJointBundle(const FactoryParams &params);