00001 // Filename: dataNode.h 00002 // Created by: drose (11Mar02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #ifndef DATANODE_H 00020 #define DATANODE_H 00021 00022 //////////////////////////////////////////////////////////////////// 00023 // 00024 // The Data Graph. 00025 // 00026 // The data graph is intended to hook up devices and their inputs 00027 // and/or outputs in a clean interface. It uses the same graph 00028 // relationship that is used to construct the scene graph, with the 00029 // same sort of nodes and NodePaths. 00030 // 00031 // In a data graph, each node may potentially produce and/or consume 00032 // data, and the arcs transmit data downward, from the root of the 00033 // graph to its leaves. Thus, an input device such as a mouse might 00034 // be added to the graph near the root, and a tformer-style object 00035 // that interprets the mouse data as a trackball motion and outputs a 00036 // matrix might be the immediate child of the mouse, followed by an 00037 // object that accepts a matrix and sets it on some particular arc in 00038 // the scene graph. 00039 // 00040 // Each different kind of DataNode defines its own set of input values 00041 // and output values, identified by name. When a DataNode is attached 00042 // to another DataNode, the inputs of the child are automatically 00043 // connected up to the corresponding outputs of the parent, and an 00044 // error message is issued if there are no matching connections. 00045 // 00046 //////////////////////////////////////////////////////////////////// 00047 00048 #include "pandabase.h" 00049 00050 #include "pandaNode.h" 00051 #include "pointerTo.h" 00052 00053 class DataNodeTransmit; 00054 00055 //////////////////////////////////////////////////////////////////// 00056 // Class : DataNode 00057 // Description : The fundamental type of node for the data graph. The 00058 // DataNode class is itself primarily intended as an 00059 // abstract class; it defines no inputs and no outputs. 00060 // Most kinds of data nodes will derive from this to 00061 // specify the inputs and outputs in the constructor. 00062 // 00063 // DataNode does not attempt to cycle its data with a 00064 // PipelineCycler. The data graph is intended to be 00065 // used only within a single thread. 00066 //////////////////////////////////////////////////////////////////// 00067 class EXPCL_PANDA DataNode : public PandaNode { 00068 PUBLISHED: 00069 INLINE DataNode(const string &name); 00070 00071 protected: 00072 INLINE DataNode(const DataNode ©); 00073 public: 00074 virtual PandaNode *make_copy() const; 00075 00076 void transmit_data(const DataNodeTransmit inputs[], 00077 DataNodeTransmit &output); 00078 00079 INLINE int get_num_inputs() const; 00080 INLINE int get_num_outputs() const; 00081 00082 PUBLISHED: 00083 void write_inputs(ostream &out) const; 00084 void write_outputs(ostream &out) const; 00085 void write_connections(ostream &out) const; 00086 00087 protected: 00088 int define_input(const string &name, TypeHandle data_type); 00089 int define_output(const string &name, TypeHandle data_type); 00090 00091 protected: 00092 // Inherited from PandaNode 00093 virtual void parents_changed(); 00094 00095 // Local to DataNode 00096 virtual void do_transmit_data(const DataNodeTransmit &input, 00097 DataNodeTransmit &output); 00098 00099 private: 00100 void reconnect(); 00101 00102 class WireDef { 00103 public: 00104 TypeHandle _data_type; 00105 int _index; 00106 }; 00107 00108 typedef pmap<string, WireDef> Wires; 00109 00110 Wires _input_wires; 00111 Wires _output_wires; 00112 00113 class DataConnection { 00114 public: 00115 int _parent_index; 00116 int _output_index; 00117 int _input_index; 00118 }; 00119 typedef pvector<DataConnection> DataConnections; 00120 DataConnections _data_connections; 00121 00122 public: 00123 static TypeHandle get_class_type() { 00124 return _type_handle; 00125 } 00126 static void init_type() { 00127 PandaNode::init_type(); 00128 register_type(_type_handle, "DataNode", 00129 PandaNode::get_class_type()); 00130 } 00131 virtual TypeHandle get_type() const { 00132 return get_class_type(); 00133 } 00134 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00135 00136 private: 00137 static TypeHandle _type_handle; 00138 }; 00139 00140 #include "dataNode.I" 00141 00142 #endif