Thrive
entity.h
1 #pragma once
2 
3 #include "engine/component.h"
4 #include "engine/typedefs.h"
5 
6 #include <string>
7 #include <iostream>
8 namespace luabind {
9 class scope;
10 }
11 
12 namespace thrive {
13 
14 class GameState;
15 class EntityManager;
16 
28 class Entity {
29 
30 public:
31 
53  static luabind::scope
54  luaBindings();
55 
66  Entity(
67  GameState* gameState = nullptr
68  );
69 
83  Entity(
84  EntityId id,
85  GameState* gameState = nullptr
86  );
87 
103  Entity(
104  const std::string& name,
105  GameState* gameState = nullptr
106  );
107 
116  Entity(
117  const Entity& other
118  );
119 
123  ~Entity();
124 
132  Entity&
133  operator = (
134  const Entity& other
135  );
136 
144  bool
145  operator == (
146  const Entity& other
147  ) const;
148 
154  void
155  addComponent(
156  std::unique_ptr<Component> component
157  );
158 
162  void
163  destroy();
164 
170  bool
171  exists() const;
172 
183  Component*
184  getComponent(
185  ComponentTypeId typeId
186  );
187 
202  bool
203  hasComponent(
204  ComponentTypeId typeId
205  );
206 
210  EntityId
211  id() const;
212 
220  bool
221  isVolatile() const;
222 
232  void
233  addChild(
234  Entity& child
235  );
236 
242  bool
243  hasChildren() const;
244 
245 
257  void
258  stealName(
259  const std::string& name
260  );
261 
274  void
276  ComponentTypeId typeId
277  );
278 
288  Entity
289  transfer(
290  GameState* newGameState
291  );
292 
300  void
301  setVolatile(
302  bool isVolatile
303  );
304 
305 private:
306 
307  struct Implementation;
308  std::unique_ptr<Implementation> m_impl;
309 
310 };
311 
312 
313 }
void setVolatile(bool isVolatile)
Sets the volatile flag.
Definition: entity.cpp:217
void addChild(Entity &child)
Adds a child to the current entity.
Definition: entity.cpp:224
EntityId id() const
The entity's id.
Definition: entity.cpp:188
Component * getComponent(ComponentTypeId typeId)
Retrieves a component by type id.
Definition: entity.cpp:165
bool exists() const
Checks if the entity has any components.
Definition: entity.cpp:159
Entity & operator=(const Entity &other)
Copy assignment.
Definition: entity.cpp:130
bool hasChildren() const
Returns whether the entity has any children.
Definition: entity.cpp:231
Convenience class to handle an entity.
Definition: entity.h:28
void stealName(const std::string &name)
Rebinds the name to the new Id.
Definition: entity.cpp:236
void destroy()
Removes all components of this entity.
Definition: entity.cpp:153
Entity(GameState *gameState=nullptr)
Constructor.
Definition: entity.cpp:84
Base class for components.
Definition: component.h:31
~Entity()
Destructor.
Definition: entity.cpp:115
bool isVolatile() const
Returns the volatile flag.
Definition: entity.cpp:194
bool operator==(const Entity &other) const
Compares two entities.
Definition: entity.cpp:119
bool hasComponent(ComponentTypeId typeId)
Checks whether this entity has a component.
Definition: entity.cpp:176
Entity transfer(GameState *newGameState)
Transfers an entity to a different gameState.
Definition: entity.cpp:210
Definition: bullet_to_ogre_system.h:5
void addComponent(std::unique_ptr< Component > component)
Adds a component to this entity.
Definition: entity.cpp:142
Definition: bullet_ogre_conversion.h:6
static luabind::scope luaBindings()
Lua bindings.
Definition: entity.cpp:44
Represents a distinct set of active systems and entities.
Definition: game_state.h:41
void removeComponent(ComponentTypeId typeId)
Removes a component by type id.
Definition: entity.cpp:200