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
// Access: Public
// Access: Published
// Description: Creates the AnimGroup, and adds it to the indicated
// parent. The only way to delete it subsequently is to
// delete the entire hierarchy.
@ -87,7 +87,7 @@ AnimGroup(AnimGroup *parent, const string &name) :
////////////////////////////////////////////////////////////////////
// Function: AnimGroup::Destructor
// Access: Public, Virtual
// Access: Published, Virtual
// Description:
////////////////////////////////////////////////////////////////////
AnimGroup::
@ -97,7 +97,7 @@ AnimGroup::
////////////////////////////////////////////////////////////////////
// Function: AnimGroup::get_num_children
// Access: Public
// Access: Published
// Description: Returns the number of child nodes of the group.
////////////////////////////////////////////////////////////////////
int AnimGroup::
@ -108,7 +108,7 @@ get_num_children() const {
////////////////////////////////////////////////////////////////////
// Function: AnimGroup::get_child
// Access: Public
// Access: Published
// Description: Returns the nth child of the group.
////////////////////////////////////////////////////////////////////
AnimGroup *AnimGroup::
@ -119,7 +119,7 @@ get_child(int n) const {
////////////////////////////////////////////////////////////////////
// Function: AnimGroup::get_child_named
// Access: Public
// Access: Published
// Description: Returns the first child found with the indicated
// name, or NULL if no such child exists. This method
// searches only the children of this particular
@ -141,7 +141,7 @@ get_child_named(const string &name) const {
////////////////////////////////////////////////////////////////////
// Function: AnimGroup::find_child
// Access: Public
// Access: Published
// Description: Returns the first descendant found with the indicated
// name, or NULL if no such descendant exists. This
// method searches the entire graph beginning at this
@ -164,20 +164,6 @@ find_child(const string &name) const {
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.
class AnimGroupAlphabeticalOrder {
public:
@ -188,7 +174,7 @@ public:
////////////////////////////////////////////////////////////////////
// Function: AnimGroup::sort_descendants
// Access: Public
// 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
@ -207,8 +193,21 @@ sort_descendants() {
////////////////////////////////////////////////////////////////////
// Function: AnimGroup::output
// 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();
}
////////////////////////////////////////////////////////////////////
// Function: AnimGroup::output
// Access: Published, Virtual
// Description: Writes a one-line description of the group.
////////////////////////////////////////////////////////////////////
void AnimGroup::
@ -218,7 +217,7 @@ output(ostream &out) const {
////////////////////////////////////////////////////////////////////
// Function: AnimGroup::write
// Access: Public, Virtual
// Access: Published, Virtual
// Description: Writes a brief description of the group and all of
// its descendants.
////////////////////////////////////////////////////////////////////

View File

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

View File

@ -29,7 +29,7 @@ TypeHandle PartGroup::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: PartGroup::Constructor
// Access: Public
// Access: Published
// Description: Creates the PartGroup, and adds it to the indicated
// parent. The only way to delete it subsequently is to
// delete the entire hierarchy.
@ -46,7 +46,7 @@ PartGroup(PartGroup *parent, const string &name) :
////////////////////////////////////////////////////////////////////
// Function: PartGroup::Destructor
// Access: Public
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
PartGroup::
@ -55,7 +55,7 @@ PartGroup::
////////////////////////////////////////////////////////////////////
// Function: PartGroup::is_character_joint
// Access: Public, Virtual
// Access: Published, Virtual
// Description: Returns true if this part is a CharacterJoint, false
// otherwise. This is a tiny optimization over
// is_of_type(CharacterType::get_class_type()).
@ -67,7 +67,7 @@ is_character_joint() const {
////////////////////////////////////////////////////////////////////
// Function: PartGroup::make_copy
// Access: Public, Virtual
// Access: Published, Virtual
// Description: Allocates and returns a new copy of the node.
// Children are not copied, but see copy_subgraph().
////////////////////////////////////////////////////////////////////
@ -78,7 +78,7 @@ make_copy() const {
////////////////////////////////////////////////////////////////////
// Function: PartGroup::copy_subgraph
// Access: Public
// Access: Published
// Description: Allocates and returns a new copy of this node and of
// all of its children.
////////////////////////////////////////////////////////////////////
@ -103,7 +103,7 @@ copy_subgraph() const {
////////////////////////////////////////////////////////////////////
// Function: PartGroup::get_num_children
// Access: Public
// Access: Published
// Description: Returns the number of child nodes of the group.
////////////////////////////////////////////////////////////////////
int PartGroup::
@ -114,7 +114,7 @@ get_num_children() const {
////////////////////////////////////////////////////////////////////
// Function: PartGroup::get_child
// Access: Public
// Access: Published
// Description: Returns the nth child of the group.
////////////////////////////////////////////////////////////////////
PartGroup *PartGroup::
@ -125,7 +125,7 @@ get_child(int n) const {
////////////////////////////////////////////////////////////////////
// Function: PartGroup::get_child_named
// Access: Public
// Access: Published
// Description: Returns the first child found with the indicated
// name, or NULL if no such child exists. This method
// searches only the children of this particular
@ -147,7 +147,7 @@ get_child_named(const string &name) const {
////////////////////////////////////////////////////////////////////
// Function: PartGroup::find_child
// Access: Public
// Access: Published
// Description: Returns the first descendant found with the indicated
// name, or NULL if no such descendant exists. This
// method searches the entire graph beginning at this
@ -170,6 +170,33 @@ find_child(const string &name) const {
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
// Access: Published
@ -265,6 +292,35 @@ get_forced_channel() const {
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
// Access: Public, Virtual
@ -278,34 +334,6 @@ get_value_type() const {
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
// Access: Public
@ -486,34 +514,6 @@ check_hierarchy(const AnimGroup *anim, const PartGroup *,
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

View File

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