Panda3D
 All Classes Functions Variables Enumerations
dataNode.h
00001 // Filename: dataNode.h
00002 // Created by:  drose (11Mar02)
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 #ifndef DATANODE_H
00016 #define DATANODE_H
00017 
00018 ////////////////////////////////////////////////////////////////////
00019 //
00020 // The Data Graph.
00021 //
00022 // The data graph is intended to hook up devices and their inputs
00023 // and/or outputs in a clean interface.  It uses the same graph
00024 // relationship that is used to construct the scene graph, with the
00025 // same sort of nodes and NodePaths.
00026 //
00027 // In a data graph, each node may potentially produce and/or consume
00028 // data, and the arcs transmit data downward, from the root of the
00029 // graph to its leaves.  Thus, an input device such as a mouse might
00030 // be added to the graph near the root, and a tformer-style object
00031 // that interprets the mouse data as a trackball motion and outputs a
00032 // matrix might be the immediate child of the mouse, followed by an
00033 // object that accepts a matrix and sets it on some particular arc in
00034 // the scene graph.
00035 //
00036 // Each different kind of DataNode defines its own set of input values
00037 // and output values, identified by name.  When a DataNode is attached
00038 // to another DataNode, the inputs of the child are automatically
00039 // connected up to the corresponding outputs of the parent, and an
00040 // error message is issued if there are no matching connections.
00041 //
00042 ////////////////////////////////////////////////////////////////////
00043 
00044 #include "pandabase.h"
00045 
00046 #include "pandaNode.h"
00047 #include "pointerTo.h"
00048 
00049 class DataGraphTraverser;
00050 class DataNodeTransmit;
00051 
00052 ////////////////////////////////////////////////////////////////////
00053 //       Class : DataNode
00054 // Description : The fundamental type of node for the data graph.  The
00055 //               DataNode class is itself primarily intended as an
00056 //               abstract class; it defines no inputs and no outputs.
00057 //               Most kinds of data nodes will derive from this to
00058 //               specify the inputs and outputs in the constructor.
00059 //
00060 //               DataNode does not attempt to cycle its data with a
00061 //               PipelineCycler.  The data graph is intended to be
00062 //               used only within a single thread.
00063 ////////////////////////////////////////////////////////////////////
00064 class EXPCL_PANDA_DGRAPH DataNode : public PandaNode {
00065 PUBLISHED:
00066   INLINE DataNode(const string &name);
00067 
00068 protected:
00069   INLINE DataNode(const DataNode &copy);
00070 public:
00071   virtual PandaNode *make_copy() const;
00072 
00073   void transmit_data(DataGraphTraverser *trav,
00074                      const DataNodeTransmit inputs[],
00075                      DataNodeTransmit &output);
00076 
00077   INLINE int get_num_inputs() const;
00078   INLINE int get_num_outputs() const;
00079 
00080 PUBLISHED:
00081   void write_inputs(ostream &out) const;
00082   void write_outputs(ostream &out) const;
00083   void write_connections(ostream &out) const;
00084 
00085 protected:
00086   int define_input(const string &name, TypeHandle data_type);
00087   int define_output(const string &name, TypeHandle data_type);
00088 
00089 protected:
00090   // Inherited from PandaNode
00091   virtual void parents_changed();
00092 
00093   // Local to DataNode
00094   virtual void do_transmit_data(DataGraphTraverser *trav,
00095                                 const DataNodeTransmit &input,
00096                                 DataNodeTransmit &output);
00097 
00098 private:
00099   void reconnect();
00100 
00101   class WireDef {
00102   public:
00103     TypeHandle _data_type;
00104     int _index;
00105   };
00106 
00107   typedef pmap<string, WireDef> Wires;
00108 
00109   Wires _input_wires;
00110   Wires _output_wires;
00111 
00112   class DataConnection {
00113   public:
00114     int _parent_index;
00115     int _output_index;
00116     int _input_index;
00117   };
00118   typedef pvector<DataConnection> DataConnections;
00119   DataConnections _data_connections;
00120 
00121 public:
00122   virtual void write_datagram(BamWriter *manager, Datagram &dg);
00123 
00124 protected:
00125   void fillin(DatagramIterator &scan, BamReader *manager);
00126 
00127 public:
00128   static TypeHandle get_class_type() {
00129     return _type_handle;
00130   }
00131   static void init_type() {
00132     PandaNode::init_type();
00133     register_type(_type_handle, "DataNode",
00134                   PandaNode::get_class_type());
00135   }
00136   virtual TypeHandle get_type() const {
00137     return get_class_type();
00138   }
00139   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00140 
00141 private:
00142   static TypeHandle _type_handle;
00143 };
00144 
00145 #include "dataNode.I"
00146 
00147 #endif
 All Classes Functions Variables Enumerations