publish sort_descendants()

This commit is contained in:
David Rose 2011-05-03 16:52:13 +00:00
parent 337a09552f
commit d2f531211a
4 changed files with 89 additions and 90 deletions

View File

@ -69,7 +69,7 @@ AnimGroup(AnimGroup *parent, const AnimGroup &copy) :
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: AnimGroup::Constructor // Function: AnimGroup::Constructor
// Access: Public // Access: Published
// Description: Creates the AnimGroup, and adds it to the indicated // Description: Creates the AnimGroup, and adds it to the indicated
// parent. The only way to delete it subsequently is to // parent. The only way to delete it subsequently is to
// delete the entire hierarchy. // delete the entire hierarchy.
@ -87,7 +87,7 @@ AnimGroup(AnimGroup *parent, const string &name) :
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: AnimGroup::Destructor // Function: AnimGroup::Destructor
// Access: Public, Virtual // Access: Published, Virtual
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
AnimGroup:: AnimGroup::
@ -97,7 +97,7 @@ AnimGroup::
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: AnimGroup::get_num_children // Function: AnimGroup::get_num_children
// Access: Public // Access: Published
// Description: Returns the number of child nodes of the group. // Description: Returns the number of child nodes of the group.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
int AnimGroup:: int AnimGroup::
@ -108,7 +108,7 @@ get_num_children() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: AnimGroup::get_child // Function: AnimGroup::get_child
// Access: Public // Access: Published
// Description: Returns the nth child of the group. // Description: Returns the nth child of the group.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
AnimGroup *AnimGroup:: AnimGroup *AnimGroup::
@ -119,7 +119,7 @@ get_child(int n) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: AnimGroup::get_child_named // Function: AnimGroup::get_child_named
// Access: Public // Access: Published
// Description: Returns the first child found with the indicated // Description: Returns the first child found with the indicated
// name, or NULL if no such child exists. This method // name, or NULL if no such child exists. This method
// searches only the children of this particular // searches only the children of this particular
@ -141,7 +141,7 @@ get_child_named(const string &name) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: AnimGroup::find_child // Function: AnimGroup::find_child
// Access: Public // Access: Published
// Description: Returns the first descendant found with the indicated // Description: Returns the first descendant found with the indicated
// name, or NULL if no such descendant exists. This // name, or NULL if no such descendant exists. This
// method searches the entire graph beginning at this // method searches the entire graph beginning at this
@ -164,20 +164,6 @@ find_child(const string &name) const {
return (AnimGroup *)NULL; return (AnimGroup *)NULL;
} }
////////////////////////////////////////////////////////////////////
// Function: AnimGroup::get_value_type
// Access: Public, Virtual
// Description: Returns the TypeHandle associated with the ValueType
// we are concerned with. This is provided to allow a
// bit of run-time checking that joints and channels are
// matching properly in type.
////////////////////////////////////////////////////////////////////
TypeHandle AnimGroup::
get_value_type() const {
return TypeHandle::none();
}
// An STL object to sort a list of children into alphabetical order. // An STL object to sort a list of children into alphabetical order.
class AnimGroupAlphabeticalOrder { class AnimGroupAlphabeticalOrder {
public: public:
@ -188,7 +174,7 @@ public:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: AnimGroup::sort_descendants // Function: AnimGroup::sort_descendants
// Access: Public // Access: Published
// Description: Sorts the children nodes at each level of the // Description: Sorts the children nodes at each level of the
// hierarchy into alphabetical order. This should be // hierarchy into alphabetical order. This should be
// done after creating the hierarchy, to guarantee that // done after creating the hierarchy, to guarantee that
@ -207,8 +193,21 @@ sort_descendants() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: AnimGroup::output // Function: AnimGroup::get_value_type
// Access: Public, Virtual // Access: Public, Virtual
// Description: Returns the TypeHandle associated with the ValueType
// we are concerned with. This is provided to allow a
// bit of run-time checking that joints and channels are
// matching properly in type.
////////////////////////////////////////////////////////////////////
TypeHandle AnimGroup::
get_value_type() const {
return TypeHandle::none();
}
////////////////////////////////////////////////////////////////////
// Function: AnimGroup::output
// Access: Published, Virtual
// Description: Writes a one-line description of the group. // Description: Writes a one-line description of the group.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void AnimGroup:: void AnimGroup::
@ -218,7 +217,7 @@ output(ostream &out) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: AnimGroup::write // Function: AnimGroup::write
// Access: Public, Virtual // Access: Published, Virtual
// Description: Writes a brief description of the group and all of // Description: Writes a brief description of the group and all of
// its descendants. // its descendants.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////

View File

@ -49,10 +49,10 @@ PUBLISHED:
AnimGroup *get_child_named(const string &name) const; AnimGroup *get_child_named(const string &name) const;
AnimGroup *find_child(const string &name) const; AnimGroup *find_child(const string &name) const;
void sort_descendants();
public: public:
virtual TypeHandle get_value_type() const; virtual TypeHandle get_value_type() const;
void sort_descendants();
PUBLISHED: PUBLISHED:
virtual void output(ostream &out) const; virtual void output(ostream &out) const;

View File

@ -29,7 +29,7 @@ TypeHandle PartGroup::_type_handle;
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PartGroup::Constructor // Function: PartGroup::Constructor
// Access: Public // Access: Published
// Description: Creates the PartGroup, and adds it to the indicated // Description: Creates the PartGroup, and adds it to the indicated
// parent. The only way to delete it subsequently is to // parent. The only way to delete it subsequently is to
// delete the entire hierarchy. // delete the entire hierarchy.
@ -46,7 +46,7 @@ PartGroup(PartGroup *parent, const string &name) :
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PartGroup::Destructor // Function: PartGroup::Destructor
// Access: Public // Access: Published
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
PartGroup:: PartGroup::
@ -55,7 +55,7 @@ PartGroup::
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PartGroup::is_character_joint // Function: PartGroup::is_character_joint
// Access: Public, Virtual // Access: Published, Virtual
// Description: Returns true if this part is a CharacterJoint, false // Description: Returns true if this part is a CharacterJoint, false
// otherwise. This is a tiny optimization over // otherwise. This is a tiny optimization over
// is_of_type(CharacterType::get_class_type()). // is_of_type(CharacterType::get_class_type()).
@ -67,7 +67,7 @@ is_character_joint() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PartGroup::make_copy // Function: PartGroup::make_copy
// Access: Public, Virtual // Access: Published, 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().
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -78,7 +78,7 @@ make_copy() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PartGroup::copy_subgraph // Function: PartGroup::copy_subgraph
// Access: Public // Access: Published
// Description: Allocates and returns a new copy of this node and of // Description: Allocates and returns a new copy of this node and of
// all of its children. // all of its children.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -103,7 +103,7 @@ copy_subgraph() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PartGroup::get_num_children // Function: PartGroup::get_num_children
// Access: Public // Access: Published
// Description: Returns the number of child nodes of the group. // Description: Returns the number of child nodes of the group.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
int PartGroup:: int PartGroup::
@ -114,7 +114,7 @@ get_num_children() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PartGroup::get_child // Function: PartGroup::get_child
// Access: Public // Access: Published
// Description: Returns the nth child of the group. // Description: Returns the nth child of the group.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
PartGroup *PartGroup:: PartGroup *PartGroup::
@ -125,7 +125,7 @@ get_child(int n) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PartGroup::get_child_named // Function: PartGroup::get_child_named
// Access: Public // Access: Published
// Description: Returns the first child found with the indicated // Description: Returns the first child found with the indicated
// name, or NULL if no such child exists. This method // name, or NULL if no such child exists. This method
// searches only the children of this particular // searches only the children of this particular
@ -147,7 +147,7 @@ get_child_named(const string &name) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PartGroup::find_child // Function: PartGroup::find_child
// Access: Public // Access: Published
// Description: Returns the first descendant found with the indicated // Description: Returns the first descendant found with the indicated
// name, or NULL if no such descendant exists. This // name, or NULL if no such descendant exists. This
// method searches the entire graph beginning at this // method searches the entire graph beginning at this
@ -170,6 +170,33 @@ find_child(const string &name) const {
return (PartGroup *)NULL; return (PartGroup *)NULL;
} }
// An STL object to sort a list of children into alphabetical order.
class PartGroupAlphabeticalOrder {
public:
bool operator()(const PT(PartGroup) &a, const PT(PartGroup) &b) const {
return a->get_name() < b->get_name();
}
};
////////////////////////////////////////////////////////////////////
// Function: PartGroup::sort_descendants
// Access: Published
// Description: Sorts the children nodes at each level of the
// hierarchy into alphabetical order. This should be
// done after creating the hierarchy, to guarantee that
// the correct names will match up together when the
// AnimBundle is later bound to a PlayerRoot.
////////////////////////////////////////////////////////////////////
void PartGroup::
sort_descendants() {
stable_sort(_children.begin(), _children.end(), PartGroupAlphabeticalOrder());
Children::iterator ci;
for (ci = _children.begin(); ci != _children.end(); ++ci) {
(*ci)->sort_descendants();
}
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PartGroup::apply_freeze // Function: PartGroup::apply_freeze
// Access: Published // Access: Published
@ -265,6 +292,35 @@ get_forced_channel() const {
return NULL; return NULL;
} }
////////////////////////////////////////////////////////////////////
// Function: PartGroup::write
// Access: Published, Virtual
// Description: Writes a brief description of the group and all of
// its descendants.
////////////////////////////////////////////////////////////////////
void PartGroup::
write(ostream &out, int indent_level) const {
indent(out, indent_level)
<< get_type() << " " << get_name() << " {\n";
write_descendants(out, indent_level + 2);
indent(out, indent_level) << "}\n";
}
////////////////////////////////////////////////////////////////////
// Function: PartGroup::write_with_value
// Access: Published, Virtual
// Description: Writes a brief description of the group, showing its
// current value, and that of all of its descendants.
////////////////////////////////////////////////////////////////////
void PartGroup::
write_with_value(ostream &out, int indent_level) const {
indent(out, indent_level)
<< get_type() << " " << get_name() << " {\n";
write_descendants_with_value(out, indent_level + 2);
indent(out, indent_level) << "}\n";
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PartGroup::get_value_type // Function: PartGroup::get_value_type
// Access: Public, Virtual // Access: Public, Virtual
@ -278,34 +334,6 @@ get_value_type() const {
return TypeHandle::none(); return TypeHandle::none();
} }
// An STL object to sort a list of children into alphabetical order.
class PartGroupAlphabeticalOrder {
public:
bool operator()(const PT(PartGroup) &a, const PT(PartGroup) &b) const {
return a->get_name() < b->get_name();
}
};
////////////////////////////////////////////////////////////////////
// Function: PartGroup::sort_descendants
// Access: Public
// Description: Sorts the children nodes at each level of the
// hierarchy into alphabetical order. This should be
// done after creating the hierarchy, to guarantee that
// the correct names will match up together when the
// AnimBundle is later bound to a PlayerRoot.
////////////////////////////////////////////////////////////////////
void PartGroup::
sort_descendants() {
stable_sort(_children.begin(), _children.end(), PartGroupAlphabeticalOrder());
Children::iterator ci;
for (ci = _children.begin(); ci != _children.end(); ++ci) {
(*ci)->sort_descendants();
}
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PartGroup::check_hierarchy // Function: PartGroup::check_hierarchy
// Access: Public // Access: Public
@ -486,34 +514,6 @@ check_hierarchy(const AnimGroup *anim, const PartGroup *,
return true; return true;
} }
////////////////////////////////////////////////////////////////////
// Function: PartGroup::write
// Access: Public, Virtual
// Description: Writes a brief description of the group and all of
// its descendants.
////////////////////////////////////////////////////////////////////
void PartGroup::
write(ostream &out, int indent_level) const {
indent(out, indent_level)
<< get_type() << " " << get_name() << " {\n";
write_descendants(out, indent_level + 2);
indent(out, indent_level) << "}\n";
}
////////////////////////////////////////////////////////////////////
// Function: PartGroup::write_with_value
// Access: Public, Virtual
// Description: Writes a brief description of the group, showing its
// current value, and that of all of its descendants.
////////////////////////////////////////////////////////////////////
void PartGroup::
write_with_value(ostream &out, int indent_level) const {
indent(out, indent_level)
<< get_type() << " " << get_name() << " {\n";
write_descendants_with_value(out, indent_level + 2);
indent(out, indent_level) << "}\n";
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PartGroup::do_update // Function: PartGroup::do_update

View File

@ -77,6 +77,7 @@ PUBLISHED:
PartGroup *get_child_named(const string &name) const; PartGroup *get_child_named(const string &name) const;
PartGroup *find_child(const string &name) const; PartGroup *find_child(const string &name) const;
void sort_descendants();
bool apply_freeze(const TransformState *transform); bool apply_freeze(const TransformState *transform);
virtual bool apply_freeze_matrix(const LVecBase3f &pos, const LVecBase3f &hpr, const LVecBase3f &scale); virtual bool apply_freeze_matrix(const LVecBase3f &pos, const LVecBase3f &hpr, const LVecBase3f &scale);
@ -91,7 +92,6 @@ PUBLISHED:
public: public:
virtual TypeHandle get_value_type() const; virtual TypeHandle get_value_type() const;
void sort_descendants();
bool check_hierarchy(const AnimGroup *anim, bool check_hierarchy(const AnimGroup *anim,
const PartGroup *parent, const PartGroup *parent,
int hierarchy_match_flags = 0) const; int hierarchy_match_flags = 0) const;