Panda3D

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