dataNode.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // Filename: dataNode.h
  2. // Created by: drose (11Mar02)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://etc.cmu.edu/panda3d/docs/license/ .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #ifndef DATANODE_H
  19. #define DATANODE_H
  20. ////////////////////////////////////////////////////////////////////
  21. //
  22. // The Data Graph.
  23. //
  24. // The data graph is intended to hook up devices and their inputs
  25. // and/or outputs in a clean interface. It uses the same graph
  26. // relationship that is used to construct the scene graph, with the
  27. // same sort of nodes and NodePaths.
  28. //
  29. // In a data graph, each node may potentially produce and/or consume
  30. // data, and the arcs transmit data downward, from the root of the
  31. // graph to its leaves. Thus, an input device such as a mouse might
  32. // be added to the graph near the root, and a tformer-style object
  33. // that interprets the mouse data as a trackball motion and outputs a
  34. // matrix might be the immediate child of the mouse, followed by an
  35. // object that accepts a matrix and sets it on some particular arc in
  36. // the scene graph.
  37. //
  38. // Each different kind of DataNode defines its own set of input values
  39. // and output values, identified by name. When a DataNode is attached
  40. // to another DataNode, the inputs of the child are automatically
  41. // connected up to the corresponding outputs of the parent, and an
  42. // error message is issued if there are no matching connections.
  43. //
  44. ////////////////////////////////////////////////////////////////////
  45. #include "pandabase.h"
  46. #include "pandaNode.h"
  47. #include "pointerTo.h"
  48. class DataNodeTransmit;
  49. ////////////////////////////////////////////////////////////////////
  50. // Class : DataNode
  51. // Description : The fundamental type of node for the data graph. The
  52. // DataNode class is itself primarily intended as an
  53. // abstract class; it defines no inputs and no outputs.
  54. // Most kinds of data nodes will derive from this to
  55. // specify the inputs and outputs in the constructor.
  56. //
  57. // DataNode does not attempt to cycle its data with a
  58. // PipelineCycler. The data graph is intended to be
  59. // used only within a single thread.
  60. ////////////////////////////////////////////////////////////////////
  61. class EXPCL_PANDA DataNode : public PandaNode {
  62. PUBLISHED:
  63. INLINE DataNode(const string &name);
  64. protected:
  65. INLINE DataNode(const DataNode &copy);
  66. public:
  67. virtual PandaNode *make_copy() const;
  68. void transmit_data(const DataNodeTransmit inputs[],
  69. DataNodeTransmit &output);
  70. INLINE int get_num_inputs() const;
  71. INLINE int get_num_outputs() const;
  72. PUBLISHED:
  73. void write_inputs(ostream &out) const;
  74. void write_outputs(ostream &out) const;
  75. void write_connections(ostream &out) const;
  76. protected:
  77. int define_input(const string &name, TypeHandle data_type);
  78. int define_output(const string &name, TypeHandle data_type);
  79. protected:
  80. // Inherited from PandaNode
  81. virtual void parents_changed();
  82. // Local to DataNode
  83. virtual void do_transmit_data(const DataNodeTransmit &input,
  84. DataNodeTransmit &output);
  85. private:
  86. void reconnect();
  87. class WireDef {
  88. public:
  89. TypeHandle _data_type;
  90. int _index;
  91. };
  92. typedef pmap<string, WireDef> Wires;
  93. Wires _input_wires;
  94. Wires _output_wires;
  95. class DataConnection {
  96. public:
  97. int _parent_index;
  98. int _output_index;
  99. int _input_index;
  100. };
  101. typedef pvector<DataConnection> DataConnections;
  102. DataConnections _data_connections;
  103. public:
  104. virtual void write_datagram(BamWriter *manager, Datagram &dg);
  105. protected:
  106. void fillin(DatagramIterator &scan, BamReader *manager);
  107. public:
  108. static TypeHandle get_class_type() {
  109. return _type_handle;
  110. }
  111. static void init_type() {
  112. PandaNode::init_type();
  113. register_type(_type_handle, "DataNode",
  114. PandaNode::get_class_type());
  115. }
  116. virtual TypeHandle get_type() const {
  117. return get_class_type();
  118. }
  119. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  120. private:
  121. static TypeHandle _type_handle;
  122. };
  123. #include "dataNode.I"
  124. #endif