15 #include "dataGraphTraverser.h" 17 #include "config_dgraph.h" 27 void DataGraphTraverser::CollectedData::
29 if ((
int)_data.size() <= parent_index) {
30 _data.reserve(parent_index + 1);
31 while ((
int)_data.size() <= parent_index) {
36 nassertv(parent_index >= 0 && parent_index < (
int)_data.size());
37 _data[parent_index] = data;
46 DataGraphTraverser(
Thread *current_thread) : _current_thread(current_thread) {
55 ~DataGraphTraverser() {
66 if (node->
is_of_type(DataNode::get_class_type())) {
92 for (
int i = 0; i < num_children; i++) {
94 if (child_node->
is_of_type(DataNode::get_class_type())) {
100 if (num_parents == 1) {
104 r_transmit(data_node, &output);
109 CollectedData &collected_data = _multipass_data[data_node];
110 int parent_index = data_node->
find_parent(node, _current_thread);
111 nassertv(parent_index != -1);
113 collected_data.set_data(parent_index, output);
114 collected_data._num_parents++;
115 nassertv(collected_data._num_parents <= num_parents);
116 if (collected_data._num_parents == num_parents) {
118 r_transmit(data_node, &collected_data._data[0]);
119 _multipass_data.erase(data_node);
144 while (!_multipass_data.empty()) {
145 MultipassData::iterator mi = _multipass_data.begin();
147 const CollectedData &collected_data = (*mi).second;
150 << *data_node <<
" improperly parented partly outside of data graph.\n";
152 r_transmit(data_node, &collected_data._data[0]);
153 _multipass_data.erase(mi);
165 void DataGraphTraverser::
int get_num_children() const
Returns the number of children of the node.
A basic node of the scene graph or data graph.
int get_num_outputs() const
Returns the number of different outputs that have been defined for this node using define_output()...
The fundamental type of node for the data graph.
void collect_leftovers()
Pick up any nodes that didn't get completely traversed.
void traverse_below(PandaNode *node, const DataNodeTransmit &output)
Continues the traversal to all the children of the indicated node, passing in the given data...
void reserve(int num_wires)
Tells the DataNodeTransmit object how many wires it is expected to store data for.
int find_parent(PandaNode *node, Thread *current_thread=Thread::get_current_thread()) const
Returns the index of the indicated parent node, if it is a parent, or -1 if it is not...
int get_num_parents(Thread *current_thread=Thread::get_current_thread()) const
Returns the number of parent nodes this node has.
Children get_children(Thread *current_thread=Thread::get_current_thread()) const
Returns an object that can be used to walk through the list of children of the node.
A thread; that is, a lightweight process.
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
PandaNode * get_child(int n) const
Returns the nth child of the node.
void transmit_data(DataGraphTraverser *trav, const DataNodeTransmit inputs[], DataNodeTransmit &output)
Collects the data from all of the parent nodes and puts it into one DataNodeTransmit object...
Encapsulates the data generated from (or sent into) any particular DataNode.
void traverse(PandaNode *node)
Starts the traversal of the data graph at the indicated root node.