hx3d  1
2D/3D Simple Game Framework
node.hpp
1 /*
2  Entity Component System: Node without entity information.
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_NODE
22 #define HX3D_ECS_NODE
23 
24 #include "hx3d/ecs/entity.hpp"
25 #include "hx3d/utils/ptr.hpp"
26 
27 #include "hx3d/graphics/transform.hpp"
28 #include "hx3d/graphics/base_batch.hpp"
29 
30 namespace hx3d {
31 
35 namespace ecs {
36 
37 class SceneGraph;
38 
42 class Node: public Entity, public EnableSharedThis<Node> {
43 public:
55  Node(const std::string name);
56 
66  template <class T, class... Args>
67  Ptr<T> createChild(SceneGraph& sg, const std::string name, Args... args);
68 
76  template <class T>
77  Ptr<T> getChild(const std::string name);
78 
85  void removeChild(SceneGraph& sg, const std::string name);
86 
93 
99  std::string getPath();
100 
106  void destroy(SceneGraph& sg);
107 
113  unsigned int getChildCount();
114 
120  std::string getName();
121 
127  virtual void draw(graphics::BaseBatch& batch);
128 
134  virtual void update(const float delta);
135 
137 
140 
141  friend class SceneGraph;
142 
143 protected:
145  std::string _name;
149  std::vector<Ptr<Node>> _children;
150 
158  bool childNameExists(const std::string name);
159 };
160 
161 } /* ecs */
162 } /* hx3d */
163 
164 #include "hx3d/ecs/_inline/node.inl.hpp"
165 
166 #endif
std::string getPath()
Get the game object full path from the root.
Definition: node.cpp:48
std::string getName()
Get the node name.
Definition: node.cpp:68
void removeChild(SceneGraph &sg, const std::string name)
Remove a child, using the SceneGraph.
Definition: node.cpp:38
2D/3D transform.
Definition: transform.hpp:35
Ptr< Node > _parent
Parent node.
Definition: node.hpp:147
Node(const std::string name)
Create a named Node. Should not be used directly.
Definition: node.cpp:26
std::string _name
Current name.
Definition: node.hpp:145
unsigned int getChildCount()
Get the recursive child count.
Definition: node.cpp:80
virtual void update(const float delta)
Update the node.
Definition: node.cpp:74
virtual void draw(graphics::BaseBatch &batch)
Draw the node.
Definition: node.cpp:72
hx3d framework namespace
Definition: audio.hpp:26
void destroy(SceneGraph &sg)
Destroy the node.
Definition: node.cpp:76
graphics::Transform transform
Current transform.
Definition: node.hpp:139
std::vector< Ptr< Node > > _children
Children nodes.
Definition: node.hpp:149
Node management in hierarchy.
Definition: scene_graph.hpp:43
bool childNameExists(const std::string name)
Test if the object have a child.
Definition: node.cpp:92
std::enable_shared_from_this< T > EnableSharedThis
Quick-typing enable shared from this.
Definition: ptr.hpp:46
Base element, attachable with components.
Definition: entity.hpp:31
graphics::Transform getFullTransform()
Get the game object full transform.
Definition: node.cpp:30
Ptr< T > createChild(SceneGraph &sg, const std::string name, Args...args)
Create a new child Node, using the SceneGraph.
Definition: node.inl.hpp:27
Base node to use in a SceneGraph or an Engine.
Definition: node.hpp:42
Draw meshes and texts on screen.
Definition: base_batch.hpp:41
Ptr< T > getChild(const std::string name)
Get one child.
Definition: node.inl.hpp:33
std::shared_ptr< T > Ptr
Quick-typing shared ptr.
Definition: ptr.hpp:34