Panda3D
dataNode.h
1 // Filename: dataNode.h
2 // Created by: drose (11Mar02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef DATANODE_H
16 #define DATANODE_H
17 
18 ////////////////////////////////////////////////////////////////////
19 //
20 // The Data Graph.
21 //
22 // The data graph is intended to hook up devices and their inputs
23 // and/or outputs in a clean interface. It uses the same graph
24 // relationship that is used to construct the scene graph, with the
25 // same sort of nodes and NodePaths.
26 //
27 // In a data graph, each node may potentially produce and/or consume
28 // data, and the arcs transmit data downward, from the root of the
29 // graph to its leaves. Thus, an input device such as a mouse might
30 // be added to the graph near the root, and a tformer-style object
31 // that interprets the mouse data as a trackball motion and outputs a
32 // matrix might be the immediate child of the mouse, followed by an
33 // object that accepts a matrix and sets it on some particular arc in
34 // the scene graph.
35 //
36 // Each different kind of DataNode defines its own set of input values
37 // and output values, identified by name. When a DataNode is attached
38 // to another DataNode, the inputs of the child are automatically
39 // connected up to the corresponding outputs of the parent, and an
40 // error message is issued if there are no matching connections.
41 //
42 ////////////////////////////////////////////////////////////////////
43 
44 #include "pandabase.h"
45 
46 #include "pandaNode.h"
47 #include "pointerTo.h"
48 
49 class DataGraphTraverser;
50 class DataNodeTransmit;
51 
52 ////////////////////////////////////////////////////////////////////
53 // Class : DataNode
54 // Description : The fundamental type of node for the data graph. The
55 // DataNode class is itself primarily intended as an
56 // abstract class; it defines no inputs and no outputs.
57 // Most kinds of data nodes will derive from this to
58 // specify the inputs and outputs in the constructor.
59 //
60 // DataNode does not attempt to cycle its data with a
61 // PipelineCycler. The data graph is intended to be
62 // used only within a single thread.
63 ////////////////////////////////////////////////////////////////////
64 class EXPCL_PANDA_DGRAPH DataNode : public PandaNode {
65 PUBLISHED:
66  INLINE DataNode(const string &name);
67 
68 protected:
69  INLINE DataNode(const DataNode &copy);
70 public:
71  virtual PandaNode *make_copy() const;
72 
73  void transmit_data(DataGraphTraverser *trav,
74  const DataNodeTransmit inputs[],
75  DataNodeTransmit &output);
76 
77  INLINE int get_num_inputs() const;
78  INLINE int get_num_outputs() const;
79 
80 PUBLISHED:
81  void write_inputs(ostream &out) const;
82  void write_outputs(ostream &out) const;
83  void write_connections(ostream &out) const;
84 
85 protected:
86  int define_input(const string &name, TypeHandle data_type);
87  int define_output(const string &name, TypeHandle data_type);
88 
89 protected:
90  // Inherited from PandaNode
91  virtual void parents_changed();
92 
93  // Local to DataNode
94  virtual void do_transmit_data(DataGraphTraverser *trav,
95  const DataNodeTransmit &input,
96  DataNodeTransmit &output);
97 
98 private:
99  void reconnect();
100 
101  class WireDef {
102  public:
103  TypeHandle _data_type;
104  int _index;
105  };
106 
108 
109  Wires _input_wires;
110  Wires _output_wires;
111 
112  class DataConnection {
113  public:
114  int _parent_index;
115  int _output_index;
116  int _input_index;
117  };
119  DataConnections _data_connections;
120 
121 public:
122  virtual void write_datagram(BamWriter *manager, Datagram &dg);
123 
124 protected:
125  void fillin(DatagramIterator &scan, BamReader *manager);
126 
127 public:
128  static TypeHandle get_class_type() {
129  return _type_handle;
130  }
131  static void init_type() {
132  PandaNode::init_type();
133  register_type(_type_handle, "DataNode",
134  PandaNode::get_class_type());
135  }
136  virtual TypeHandle get_type() const {
137  return get_class_type();
138  }
139  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
140 
141 private:
142  static TypeHandle _type_handle;
143 };
144 
145 #include "dataNode.I"
146 
147 #endif
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
The fundamental type of node for the data graph.
Definition: dataNode.h:64
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
Definition: pandaNode.cxx:604
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
Encapsulates the data generated from (or sent into) any particular DataNode.
This object supervises the traversal of the data graph and the moving of data from one DataNode to it...