mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
get_ancestor
This commit is contained in:
parent
2a6a39dd4a
commit
d2c5866507
@ -98,6 +98,9 @@ get_num_nodes(Thread *current_thread) const {
|
||||
// return the same thing as get_node(0) (since the
|
||||
// bottom node is the most important node in the
|
||||
// NodePath, and is the one most frequently referenced).
|
||||
//
|
||||
// Note that this function returns the same thing as
|
||||
// get_ancestor(index).node().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PandaNode *NodePath::
|
||||
get_node(int index, Thread *current_thread) const {
|
||||
@ -120,6 +123,40 @@ get_node(int index, Thread *current_thread) const {
|
||||
return comp->get_node();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: NodePath::get_ancestor
|
||||
// Access: Published
|
||||
// Description: Returns the nth ancestor of the path, where 0 is the
|
||||
// NodePath itself and get_num_nodes() - 1 is get_top().
|
||||
// This requires iterating through the path.
|
||||
//
|
||||
// Also see get_node(), which returns the same thing as
|
||||
// a PandaNode pointer, not a NodePath.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
NodePath NodePath::
|
||||
get_ancestor(int index, Thread *current_thread) const {
|
||||
nassertr(index >= 0 && index < get_num_nodes(), NodePath::fail());
|
||||
|
||||
int pipeline_stage = current_thread->get_pipeline_stage();
|
||||
|
||||
NodePathComponent *comp = _head;
|
||||
while (index > 0) {
|
||||
// If this assertion fails, the index was out of range; the
|
||||
// component's length must have been invalid.
|
||||
nassertr(comp != (NodePathComponent *)NULL, NodePath::fail());
|
||||
comp = comp->get_next(pipeline_stage, current_thread);
|
||||
index--;
|
||||
}
|
||||
|
||||
// If this assertion fails, the index was out of range; the
|
||||
// component's length must have been invalid.
|
||||
nassertr(comp != (NodePathComponent *)NULL, NodePath::fail());
|
||||
|
||||
NodePath result;
|
||||
result._head = comp;
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: NodePath::get_top
|
||||
// Access: Published
|
||||
@ -137,7 +174,7 @@ get_top(Thread *current_thread) const {
|
||||
NodePathComponent *comp = _head;
|
||||
while (!comp->is_top_node(pipeline_stage, current_thread)) {
|
||||
comp = comp->get_next(pipeline_stage, current_thread);
|
||||
nassertr(comp != (NodePathComponent *)NULL, NULL);
|
||||
nassertr(comp != (NodePathComponent *)NULL, NodePath::fail());
|
||||
}
|
||||
|
||||
NodePath top;
|
||||
|
@ -180,6 +180,7 @@ PUBLISHED:
|
||||
INLINE bool is_singleton(Thread *current_thread = Thread::get_current_thread()) const;
|
||||
int get_num_nodes(Thread *current_thread = Thread::get_current_thread()) const;
|
||||
PandaNode *get_node(int index, Thread *current_thread = Thread::get_current_thread()) const;
|
||||
NodePath get_ancestor(int index, Thread *current_thread = Thread::get_current_thread()) const;
|
||||
|
||||
INLINE ErrorType get_error_type() const;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user