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