Panda3D
|
00001 // Filename: workingNodePath.cxx 00002 // Created by: drose (16Mar02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "workingNodePath.h" 00016 00017 00018 //////////////////////////////////////////////////////////////////// 00019 // Function: WorkingNodePath::is_valid 00020 // Access: Public 00021 // Description: Returns true if the WorkingNodePath object appears to 00022 // be a valid NodePath reference, false otherwise. 00023 //////////////////////////////////////////////////////////////////// 00024 bool WorkingNodePath:: 00025 is_valid() const { 00026 if (_node == (PandaNode *)NULL) { 00027 return false; 00028 } 00029 if (_next == (WorkingNodePath *)NULL) { 00030 return (_start != (NodePathComponent *)NULL); 00031 } 00032 00033 nassertr(_node != _next->_node, false); 00034 return _next->is_valid(); 00035 } 00036 00037 //////////////////////////////////////////////////////////////////// 00038 // Function: WorkingNodePath::get_num_nodes 00039 // Access: Public 00040 // Description: Returns the number of nodes in the path from the root 00041 // to the current node. 00042 // 00043 // Since a WorkingNodePath always consists of, at 00044 // minimum, a nonempty parent NodePath and one child 00045 // node, this method will always return at least 2. 00046 //////////////////////////////////////////////////////////////////// 00047 int WorkingNodePath:: 00048 get_num_nodes() const { 00049 if (_next == (WorkingNodePath *)NULL) { 00050 Thread *current_thread = Thread::get_current_thread(); 00051 int pipeline_stage = current_thread->get_pipeline_stage(); 00052 return _start->get_length(pipeline_stage, current_thread); 00053 } 00054 00055 return _next->get_num_nodes() + 1; 00056 } 00057 00058 //////////////////////////////////////////////////////////////////// 00059 // Function: WorkingNodePath::get_node 00060 // Access: Public 00061 // Description: Returns the nth node of the path, where 0 is the 00062 // referenced (bottom) node and get_num_nodes() - 1 is 00063 // the top node. This requires iterating through the 00064 // path. 00065 //////////////////////////////////////////////////////////////////// 00066 PandaNode *WorkingNodePath:: 00067 get_node(int index) const { 00068 nassertr(index >= 0, NULL); 00069 if (index == 0) { 00070 return _node; 00071 } 00072 00073 if (_next == (WorkingNodePath *)NULL) { 00074 return get_node_path().get_node(index - 1); 00075 } 00076 00077 return _next->get_node(index - 1); 00078 } 00079 00080 //////////////////////////////////////////////////////////////////// 00081 // Function: WorkingNodePath::output 00082 // Access: Public 00083 // Description: 00084 //////////////////////////////////////////////////////////////////// 00085 void WorkingNodePath:: 00086 output(ostream &out) const { 00087 // Cheesy and slow, but when you're outputting the thing, presumably 00088 // you're not in a hurry. 00089 get_node_path().output(out); 00090 } 00091 00092 //////////////////////////////////////////////////////////////////// 00093 // Function: WorkingNodePath::r_get_node_path 00094 // Access: Private 00095 // Description: The private, recursive implementation of 00096 // get_node_path(), this returns the NodePathComponent 00097 // representing the NodePath. 00098 //////////////////////////////////////////////////////////////////// 00099 PT(NodePathComponent) WorkingNodePath:: 00100 r_get_node_path() const { 00101 if (_next == (WorkingNodePath *)NULL) { 00102 nassertr(_start != (NodePathComponent *)NULL, NULL); 00103 return _start; 00104 } 00105 00106 nassertr(_start == (NodePathComponent *)NULL, NULL); 00107 nassertr(_node != (PandaNode *)NULL, NULL); 00108 00109 PT(NodePathComponent) comp = _next->r_get_node_path(); 00110 nassertr(comp != (NodePathComponent *)NULL, NULL); 00111 00112 Thread *current_thread = Thread::get_current_thread(); 00113 int pipeline_stage = current_thread->get_pipeline_stage(); 00114 PT(NodePathComponent) result = 00115 PandaNode::get_component(comp, _node, pipeline_stage, current_thread); 00116 if (result == (NodePathComponent *)NULL) { 00117 // This means we found a disconnected chain in the 00118 // WorkingNodePath's ancestry: the node above this node isn't 00119 // connected. In this case, don't attempt to go higher; just 00120 // truncate the NodePath at the bottom of the disconnect. 00121 return PandaNode::get_top_component(_node, true, pipeline_stage, current_thread); 00122 } 00123 00124 return result; 00125 }