Panda3D
Loading...
Searching...
No Matches
workingNodePath.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file workingNodePath.cxx
10 * @author drose
11 * @date 2002-03-16
12 */
13
14#include "workingNodePath.h"
15
16
17/**
18 * Returns true if the WorkingNodePath object appears to be a valid NodePath
19 * reference, false otherwise.
20 */
22is_valid() const {
23 if (_node == nullptr) {
24 return false;
25 }
26 if (_next == nullptr) {
27 return (_start != nullptr);
28 }
29
30 nassertr(_node != _next->_node, false);
31 return _next->is_valid();
32}
33
34/**
35 * Returns the number of nodes in the path from the root to the current node.
36 *
37 * Since a WorkingNodePath always consists of, at minimum, a nonempty parent
38 * NodePath and one child node, this method will always return at least 2.
39 */
41get_num_nodes() const {
42 if (_next == nullptr) {
43 Thread *current_thread = Thread::get_current_thread();
44 int pipeline_stage = current_thread->get_pipeline_stage();
45 return _start->get_length(pipeline_stage, current_thread);
46 }
47
48 return _next->get_num_nodes() + 1;
49}
50
51/**
52 * Returns the nth node of the path, where 0 is the referenced (bottom) node
53 * and get_num_nodes() - 1 is the top node. This requires iterating through
54 * the path.
55 */
57get_node(int index) const {
58 nassertr(index >= 0, nullptr);
59 if (index == 0) {
60 return _node;
61 }
62
63 if (_next == nullptr) {
64 return get_node_path().get_node(index - 1);
65 }
66
67 return _next->get_node(index - 1);
68}
69
70/**
71 *
72 */
73void WorkingNodePath::
74output(std::ostream &out) const {
75 // Cheesy and slow, but when you're outputting the thing, presumably you're
76 // not in a hurry.
77 get_node_path().output(out);
78}
79
80/**
81 * The private, recursive implementation of get_node_path(), this returns the
82 * NodePathComponent representing the NodePath.
83 */
84PT(NodePathComponent) WorkingNodePath::
85r_get_node_path() const {
86 if (_next == nullptr) {
87 nassertr(_start != nullptr, nullptr);
88 return _start;
89 }
90
91 nassertr(_start == nullptr, nullptr);
92 nassertr(_node != nullptr, nullptr);
93
94 PT(NodePathComponent) comp = _next->r_get_node_path();
95 nassertr(comp != nullptr, nullptr);
96
97 Thread *current_thread = Thread::get_current_thread();
98 int pipeline_stage = current_thread->get_pipeline_stage();
99 PT(NodePathComponent) result =
100 PandaNode::get_component(comp, _node, pipeline_stage, current_thread);
101 if (result == nullptr) {
102 // This means we found a disconnected chain in the WorkingNodePath's
103 // ancestry: the node above this node isn't connected. In this case,
104 // don't attempt to go higher; just truncate the NodePath at the bottom of
105 // the disconnect.
106 return PandaNode::get_top_component(_node, true, pipeline_stage, current_thread);
107 }
108
109 return result;
110}
This is one component of a NodePath.
A basic node of the scene graph or data graph.
Definition pandaNode.h:65
A thread; that is, a lightweight process.
Definition thread.h:46
get_pipeline_stage
Returns the Pipeline stage number associated with this thread.
Definition thread.h:105
get_current_thread
Returns a pointer to the currently-executing Thread object.
Definition thread.h:109
get_node_path
Constructs and returns an actual NodePath that represents the same path we have just traversed.
PandaNode * get_node(int index) const
Returns the nth node of the path, where 0 is the referenced (bottom) node and get_num_nodes() - 1 is ...
int get_num_nodes() const
Returns the number of nodes in the path from the root to the current node.
is_valid
Returns true if the WorkingNodePath object appears to be a valid NodePath reference,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.