add count_num_descendants()

This commit is contained in:
David Rose 2007-04-17 18:21:29 +00:00
parent 2144050758
commit 8566b388fb
4 changed files with 36 additions and 0 deletions

View File

@ -392,6 +392,19 @@ get_child(int n, Thread *current_thread) const {
return child; return child;
} }
////////////////////////////////////////////////////////////////////
// Function: NodePath::count_num_descendants
// Access: Published
// Description: Returns the number of nodes at and below this level.
////////////////////////////////////////////////////////////////////
INLINE int NodePath::
count_num_descendants() const {
if (is_empty()) {
return 0;
}
return _head->get_node()->count_num_descendants();
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: NodePath::has_parent // Function: NodePath::has_parent
// Access: Published // Access: Published

View File

@ -206,6 +206,8 @@ PUBLISHED:
INLINE NodePath get_child(int n, Thread *current_thread = Thread::get_current_thread()) const; INLINE NodePath get_child(int n, Thread *current_thread = Thread::get_current_thread()) const;
NodePathCollection get_stashed_children(Thread *current_thread = Thread::get_current_thread()) const; NodePathCollection get_stashed_children(Thread *current_thread = Thread::get_current_thread()) const;
INLINE int count_num_descendants() const;
INLINE bool has_parent(Thread *current_thread = Thread::get_current_thread()) const; INLINE bool has_parent(Thread *current_thread = Thread::get_current_thread()) const;
INLINE NodePath get_parent(Thread *current_thread = Thread::get_current_thread()) const; INLINE NodePath get_parent(Thread *current_thread = Thread::get_current_thread()) const;
int get_sort(Thread *current_thread = Thread::get_current_thread()) const; int get_sort(Thread *current_thread = Thread::get_current_thread()) const;

View File

@ -572,6 +572,25 @@ copy_subgraph(Thread *current_thread) const {
return r_copy_subgraph(inst_map, current_thread); return r_copy_subgraph(inst_map, current_thread);
} }
////////////////////////////////////////////////////////////////////
// Function: PandaNode::count_num_descendants
// Access: Published
// Description: Returns the number of nodes at and below this level.
////////////////////////////////////////////////////////////////////
int PandaNode::
count_num_descendants() const {
int count = 1;
Children children = get_children();
int num_children = children.get_num_children();
for (int i = 0; i < num_children; ++i) {
PandaNode *child = children.get_child(i);
count += child->count_num_descendants();
}
return count;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PandaNode::add_child // Function: PandaNode::add_child
// Access: Published // Access: Published

View File

@ -124,6 +124,8 @@ PUBLISHED:
INLINE int get_child_sort(int n, Thread *current_thread = Thread::get_current_thread()) const; INLINE int get_child_sort(int n, Thread *current_thread = Thread::get_current_thread()) const;
INLINE int find_child(PandaNode *node, Thread *current_thread = Thread::get_current_thread()) const; INLINE int find_child(PandaNode *node, Thread *current_thread = Thread::get_current_thread()) const;
int count_num_descendants() const;
void add_child(PandaNode *child_node, int sort = 0, void add_child(PandaNode *child_node, int sort = 0,
Thread *current_thread = Thread::get_current_thread()); Thread *current_thread = Thread::get_current_thread());
void remove_child(int child_index, Thread *current_thread = Thread::get_current_thread()); void remove_child(int child_index, Thread *current_thread = Thread::get_current_thread());