hx3d  1
2D/3D Simple Game Framework
scene_graph.hpp
1 /*
2  Entity Component System: Base Scene Graph.
3  Copyright (C) 2015 Denis BOURGE
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
21 #ifndef HX3D_ECS_SCENEGRAPH
22 #define HX3D_ECS_SCENEGRAPH
23 
24 #include "hx3d/utils/ptr.hpp"
25 #include "hx3d/graphics/base_batch.hpp"
26 #include "hx3d/ecs/engine.hpp"
27 
28 #include <string>
29 #include <set>
30 #include <map>
31 
32 namespace hx3d {
33 namespace ecs {
34 
35 class Node;
36 
43 class SceneGraph {
44 public:
45  SceneGraph();
46  ~SceneGraph();
47 
55  template <class T, class... Args>
56  Ptr<T> createAtRoot(Args... args);
57 
66  template <class T, class... Args>
67  Ptr<T> create(const std::string path, Args... args);
68 
74  void remove(const std::string path);
75 
83  template <class T>
84  Ptr<T> fetch(const std::string path);
85 
92 
98  unsigned int getNodeCount();
99 
103  void showIndices();
104 
110  void draw(graphics::BaseBatch& batch);
111 
117  void update(const float delta);
118 
124  void setEntityMode(bool enabled);
125 
126 protected:
130  std::map<std::string, Ptr<Node>> _indices;
135 
141  void addIndex(const Ptr<Node>& object);
142 
150  Ptr<Node> pathExists(const std::string path);
151 
157  void internalRemove(const Ptr<Node>& node);
158 
167  template <class T, class... Args>
168  Ptr<T> createNodeChild(const Ptr<Node>& container, Args... args);
169 };
170 
171 } /* ecs */
172 } /* hx3d */
173 
174 #include "hx3d/ecs/_inline/scene_graph.inl.hpp"
175 
176 #endif
void showIndices()
Show the graph indices.
Definition: scene_graph.cpp:61
void setEntityMode(bool enabled)
Activate/Deactivate the entity management mode.
Definition: scene_graph.cpp:37
Ptr< T > createNodeChild(const Ptr< Node > &container, Args...args)
Create a child for a container Node.
Manages entity in a world.
Definition: engine.hpp:41
Ptr< T > create(const std::string path, Args...args)
Create a game object at a path.
std::map< std::string, Ptr< Node > > _indices
Node indices.
hx3d framework namespace
Definition: audio.hpp:26
Ptr< Node > _root
Graph root.
void addIndex(const Ptr< Node > &object)
Add an index to the graph.
Definition: scene_graph.cpp:49
void internalRemove(const Ptr< Node > &node)
Remove a node.
Node management in hierarchy.
Definition: scene_graph.hpp:43
Ptr< Node > pathExists(const std::string path)
Test if the path exists and returns the node.
Ptr< Node > getRoot()
Get the root.
Definition: scene_graph.cpp:41
bool _entityEnabled
Is entity management enabled ?
Ptr< T > fetch(const std::string path)
Fetch a game object from a path.
void draw(graphics::BaseBatch &batch)
Draw the nodes.
Definition: scene_graph.cpp:68
unsigned int getNodeCount()
Get the number of nodes.
Definition: scene_graph.cpp:45
Draw meshes and texts on screen.
Definition: base_batch.hpp:41
Ptr< T > createAtRoot(Args...args)
Create a game object at the root.
Engine _engine
Engine for entity management.
void update(const float delta)
Update the nodes.
Definition: scene_graph.cpp:84
std::shared_ptr< T > Ptr
Quick-typing shared ptr.
Definition: ptr.hpp:34