00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "dataNode.h"
00016 #include "dataNodeTransmit.h"
00017 #include "config_dgraph.h"
00018 #include "dcast.h"
00019
00020 TypeHandle DataNode::_type_handle;
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 PandaNode *DataNode::
00031 make_copy() const {
00032 return new DataNode(*this);
00033 }
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 void DataNode::
00044 transmit_data(DataGraphTraverser *trav,
00045 const DataNodeTransmit inputs[],
00046 DataNodeTransmit &output) {
00047 DataNodeTransmit new_input;
00048 new_input.reserve(get_num_inputs());
00049
00050 DataConnections::const_iterator ci;
00051 for (ci = _data_connections.begin(); ci != _data_connections.end(); ++ci) {
00052 const DataConnection &connect = (*ci);
00053 const EventParameter &data =
00054 inputs[connect._parent_index].get_data(connect._output_index);
00055 if (!data.is_empty()) {
00056 new_input.set_data(connect._input_index, data);
00057 }
00058 }
00059
00060 #ifndef NDEBUG
00061 if (dgraph_cat.is_spam()) {
00062 bool any_data = false;
00063 Wires::const_iterator wi;
00064 for (wi = _input_wires.begin(); wi != _input_wires.end(); ++wi) {
00065 const string &name = (*wi).first;
00066 const WireDef &def = (*wi).second;
00067 if (new_input.has_data(def._index)) {
00068 if (!any_data) {
00069 dgraph_cat.spam()
00070 << *this << " receives:\n";
00071 any_data = true;
00072 }
00073 dgraph_cat.spam(false)
00074 << " " << name << " = " << new_input.get_data(def._index)
00075 << "\n";
00076 }
00077 }
00078 }
00079 #endif // NDEBUG
00080
00081 do_transmit_data(trav, new_input, output);
00082
00083 #ifndef NDEBUG
00084 if (dgraph_cat.is_spam()) {
00085 bool any_data = false;
00086 Wires::const_iterator wi;
00087 for (wi = _output_wires.begin(); wi != _output_wires.end(); ++wi) {
00088 const string &name = (*wi).first;
00089 const WireDef &def = (*wi).second;
00090 if (output.has_data(def._index)) {
00091 if (!any_data) {
00092 dgraph_cat.spam()
00093 << *this << " transmits:\n";
00094 any_data = true;
00095 }
00096 dgraph_cat.spam(false)
00097 << " " << name << " = " << output.get_data(def._index)
00098 << "\n";
00099 }
00100 }
00101 }
00102 #endif // NDEBUG
00103 }
00104
00105
00106
00107
00108
00109
00110
00111 void DataNode::
00112 write_inputs(ostream &out) const {
00113 Wires::const_iterator wi;
00114 for (wi = _input_wires.begin(); wi != _input_wires.end(); ++wi) {
00115 const string &name = (*wi).first;
00116 const WireDef &def = (*wi).second;
00117 out << name << " " << def._data_type << "\n";
00118 }
00119 }
00120
00121
00122
00123
00124
00125
00126
00127 void DataNode::
00128 write_outputs(ostream &out) const {
00129 Wires::const_iterator wi;
00130 for (wi = _output_wires.begin(); wi != _output_wires.end(); ++wi) {
00131 const string &name = (*wi).first;
00132 const WireDef &def = (*wi).second;
00133 out << name << " " << def._data_type << "\n";
00134 }
00135 }
00136
00137
00138
00139
00140
00141
00142
00143
00144 void DataNode::
00145 write_connections(ostream &out) const {
00146 DataConnections::const_iterator ci;
00147 for (ci = _data_connections.begin(); ci != _data_connections.end(); ++ci) {
00148 const DataConnection &connect = (*ci);
00149 nassertv(connect._parent_index >= 0 && connect._parent_index < get_num_parents());
00150
00151
00152
00153 Wires::const_iterator wi;
00154 bool found = false;
00155 for (wi = _input_wires.begin(); wi != _input_wires.end() && !found; ++wi) {
00156 const string &name = (*wi).first;
00157 const WireDef &def = (*wi).second;
00158 if (def._index == connect._input_index) {
00159 out << name << " " << def._data_type << " from "
00160 << *get_parent(connect._parent_index) << "\n";
00161 found = true;
00162 }
00163 }
00164 nassertv(found);
00165 }
00166 }
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185 int DataNode::
00186 define_input(const string &name, TypeHandle data_type) {
00187
00188 nassertr(_data_connections.empty(), 0);
00189
00190 Wires::iterator wi;
00191 wi = _input_wires.find(name);
00192 if (wi != _input_wires.end()) {
00193
00194
00195 WireDef &def = (*wi).second;
00196 def._data_type = data_type;
00197 return def._index;
00198 }
00199
00200
00201 WireDef &def = _input_wires[name];
00202 def._data_type = data_type;
00203 def._index = _input_wires.size() - 1;
00204 return def._index;
00205 }
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224 int DataNode::
00225 define_output(const string &name, TypeHandle data_type) {
00226
00227 nassertr(_data_connections.empty(), 0);
00228
00229 Wires::iterator wi;
00230 wi = _output_wires.find(name);
00231 if (wi != _output_wires.end()) {
00232
00233
00234 WireDef &def = (*wi).second;
00235 def._data_type = data_type;
00236 return def._index;
00237 }
00238
00239
00240 WireDef &def = _output_wires[name];
00241 def._data_type = data_type;
00242 def._index = _output_wires.size() - 1;
00243 return def._index;
00244 }
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255 void DataNode::
00256 parents_changed() {
00257 PandaNode::parents_changed();
00258 reconnect();
00259 }
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274 void DataNode::
00275 do_transmit_data(DataGraphTraverser *, const DataNodeTransmit &,
00276 DataNodeTransmit &) {
00277 }
00278
00279
00280
00281
00282
00283
00284
00285
00286 void DataNode::
00287 reconnect() {
00288 int num_parents = get_num_parents();
00289 _data_connections.clear();
00290
00291 int num_datanode_parents = 0;
00292
00293 Wires::const_iterator wi;
00294 for (wi = _input_wires.begin(); wi != _input_wires.end(); ++wi) {
00295 const string &name = (*wi).first;
00296 const WireDef &input_def = (*wi).second;
00297
00298 int num_found = 0;
00299 for (int i = 0; i < num_parents; i++) {
00300 PandaNode *parent_node = get_parent(i);
00301 if (parent_node->is_of_type(DataNode::get_class_type())) {
00302 DataNode *data_node = DCAST(DataNode, parent_node);
00303 num_datanode_parents++;
00304 Wires::const_iterator pi;
00305 pi = data_node->_output_wires.find(name);
00306 if (pi != data_node->_output_wires.end()) {
00307 const WireDef &output_def = (*pi).second;
00308 num_found++;
00309 if (output_def._data_type != input_def._data_type) {
00310 dgraph_cat.warning()
00311 << "Ignoring mismatched type for connection " << name
00312 << " between " << *data_node << " and " << *this << "\n";
00313 } else {
00314 DataConnection dc;
00315 dc._parent_index = i;
00316 dc._output_index = output_def._index;
00317 dc._input_index = input_def._index;
00318 _data_connections.push_back(dc);
00319 }
00320 }
00321 }
00322 }
00323
00324 if (num_found > 1) {
00325 if (dgraph_cat.is_debug()) {
00326 dgraph_cat.debug()
00327 << "Multiple connections found for " << name << " into " << *this
00328 << "\n";
00329 }
00330 }
00331 }
00332
00333 if (_data_connections.empty() && get_num_inputs() != 0 &&
00334 num_datanode_parents != 0) {
00335 dgraph_cat.warning()
00336 << "No data connected to " << *this << "\n";
00337 }
00338 }
00339
00340
00341
00342
00343
00344
00345
00346 void DataNode::
00347 write_datagram(BamWriter *manager, Datagram &dg) {
00348 PandaNode::write_datagram(manager, dg);
00349 }
00350
00351
00352
00353
00354
00355
00356
00357
00358 void DataNode::
00359 fillin(DatagramIterator &scan, BamReader *manager) {
00360 PandaNode::fillin(scan, manager);
00361 }