update pointers properly when flattening characters

This commit is contained in:
David Rose 2007-02-14 17:07:44 +00:00
parent 362484b473
commit 0d45017e81
4 changed files with 44 additions and 6 deletions

View File

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

View File

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

View File

@ -35,7 +35,7 @@ CharacterJointBundle(const string &name) : PartBundle(name) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: CharacterJointBundle::make_copy // Function: CharacterJointBundle::make_copy
// Access: Public, Virtual // Access: Protected, Virtual
// Description: Allocates and returns a new copy of the node. // Description: Allocates and returns a new copy of the node.
// Children are not copied, but see copy_subgraph(). // Children are not copied, but see copy_subgraph().
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -44,6 +44,41 @@ make_copy() const {
return new CharacterJointBundle(*this); 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 // Function: CharacterJointBundle::make_CharacterJointBundle
// Access: Protected // Access: Protected

View File

@ -42,9 +42,14 @@ public:
PUBLISHED: PUBLISHED:
INLINE Character *get_node() const; INLINE Character *get_node() const;
public: protected:
virtual PartGroup *make_copy() const; 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 void register_with_read_factory();
static TypedWritable *make_CharacterJointBundle(const FactoryParams &params); static TypedWritable *make_CharacterJointBundle(const FactoryParams &params);