Debian Codegraph @

include/iscenegraph.h

raw
1 #pragma once
2
3 #include <cstddef>
4 #include "imodule.h"
5 #include "inode.h"
6 #include "ipath.h"
7 #include "imap.h"
8 #include <sigc++/signal.h>
9
10 /**
11 * \defgroup scenegraph Scenegraph
12 *
13 * \namespace scene
14 * \ingroup scenegraph
15 * Interfaces and types relating to the scene-graph.
16 */
17
18 // String identifier for the registry module
19 const char* const MODULE_SCENEGRAPH("SceneGraph");
20
21 class VolumeTest;
22
23 namespace scene
24 {
25
26 class ISpacePartitionSystem;
27 typedef std::shared_ptr<ISpacePartitionSystem> ISpacePartitionSystemPtr;
28
29 /**
30 * A scene-graph - a Directed Acyclic Graph (DAG).
31 *
32 * Each node may refer to zero or more 'child' nodes (directed).
33 * A node may never have itself as one of its ancestors (acyclic).
34 */
35 class Graph
36 {
37 public:
38
39 /* greebo: Derive from this class to get notified on scene changes
40 */
41 class Observer
42 {
43 public:
44 // destructor
45 virtual ~Observer() {}
46
47 // Gets called when anything in the scenegraph changes
48 virtual void onSceneGraphChange() {}
49
50 // Gets called when a new <node> is inserted into the scenegraph
51 virtual void onSceneNodeInsert(const INodePtr& node) {}
52
53 // Gets called when <node> is removed from the scenegraph
54 virtual void onSceneNodeErase(const INodePtr& node) {}
55 };
56
57 // Returns the root-node of the graph.
58 virtual const IMapRootNodePtr& root() const = 0;
59
60 // Sets the root-node of the graph to be 'newRoot'.
61 virtual void setRoot(const IMapRootNodePtr& newRoot) = 0;
62
63 // greebo: Adds a node to the scenegraph
64 virtual void insert(const scene::INodePtr& node) = 0;
65 // Removes a node from the scenegraph
66 virtual void erase(const scene::INodePtr& node) = 0;
67
68 /// \brief Invokes all scene-changed callbacks. Called when any part of the scene changes the way it will appear when the scene is rendered.
69 /// \todo Move to a separate class.
70 virtual void sceneChanged() = 0;
71 /// \brief Add a \p callback to be invoked when the scene changes.
72 /// \todo Move to a separate class.
73 virtual void addSceneObserver(Observer* observer) = 0;
74 // greebo: Remove the scene observer from the list
75 virtual void removeSceneObserver(Observer* observer) = 0;
76
77 /// Accessor for the signal emitted when bounds are changed
78 virtual sigc::signal<void> signal_boundsChanged() const = 0;
79
80 /// \brief Invokes all bounds-changed callbacks. Called when the bounds of any instance in the scene change.
81 /// \todo Move to a separate class.
82 virtual void boundsChanged() = 0;
83
84 // A specific node has changed its bounds
85 virtual void nodeBoundsChanged(const scene::INodePtr& node) = 0;
86
87 // A walker class to be used in "foreachNodeInVolume"
88 class Walker
89 {
90 public:
91 virtual ~Walker() {}
92
93 // Called for each visited node, returns TRUE if traversal should continue
94 virtual bool visit(const INodePtr& node) = 0;
95 };
96
97 // Visit each scene node in the given volume using the given walker class, even hidden ones
98 virtual void foreachNodeInVolume(const VolumeTest& volume, Walker& walker) = 0;
99
100 // Same as above, but culls any hidden nodes
101 virtual void foreachVisibleNodeInVolume(const VolumeTest& volume, Walker& walker) = 0;
102
103 // Call the functor on each scene node in the entire scenegraph, including hidden ones
104 virtual void foreachNode(const INode::VisitorFunc& functor) = 0;
105
106 // Call the functor on each scene node in the entire scenegraph, excluding hidden ones
107 virtual void foreachVisibleNode(const INode::VisitorFunc& functor) = 0;
108
109 // Call the functor on each scene node in the given volume, even hidden ones
110 virtual void foreachNodeInVolume(const VolumeTest& volume, const INode::VisitorFunc& functor) = 0;
111
112 // Same as above, but culls any hidden nodes
113 virtual void foreachVisibleNodeInVolume(const VolumeTest& volume, const INode::VisitorFunc& functor) = 0;
114
115 // Returns the associated spacepartition
116 virtual ISpacePartitionSystemPtr getSpacePartition() = 0;
117 };
118 typedef std::shared_ptr<Graph> GraphPtr;
119 typedef std::weak_ptr<Graph> GraphWeakPtr;
120
121 class Cloneable
122 {
123 public:
124 /// \brief destructor
125 virtual ~Cloneable() {}
126
127 /// \brief Returns a copy of itself.
128 virtual scene::INodePtr clone() const = 0;
129 };
130 typedef std::shared_ptr<Cloneable> CloneablePtr;
131
132 } // namespace
133
134 // Accessor to the singleton scenegraph, used for the main map
135 inline scene::Graph& GlobalSceneGraph()
136 {
137 static module::InstanceReference<scene::Graph> _reference(MODULE_SCENEGRAPH);
138 return _reference;
139 }
140
141 inline void SceneChangeNotify()
142 {
143 GlobalSceneGraph().sceneChanged();
144 }