TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
tb_entity_manager.hpp
1 
9 #ifndef TurtleBrains_EntityManager_hpp
10 #define TurtleBrains_EntityManager_hpp
11 
12 #include <turtle_brains/game/tb_entity.hpp> //For EntityType definition.
13 #include <turtle_brains/core/tb_noncopyable.hpp>
14 
15 #include <map>
16 #include <set>
17 #include <list>
18 
19 namespace TurtleBrains
20 {
21  namespace Game
22  {
23 
24  class Entity;
25 
33  {
34  public:
38  typedef std::list<Entity*> EntityList;
39 
43  EntityManager(void);
44 
49  virtual ~EntityManager(void) = 0;
50 
54  void ClearEntities(void);
55 
62  //Entity& AddEntity(const EntityType& entityType);
63 
69  void AddEntity(Entity* entity);
70 
77  void AddEntity(Entity& entity);
78 
83  void RemoveEntity(Entity* entity);
84 
88  void RemoveEntities(const EntityType& byType = Entity::kInvalidType);
89 
94  void EntityTypeChanged(Entity& entity, const EntityTypeContainer& oldTypes);
95 
99  EntityList GetAllEntities(void);
100 
104  EntityList GetEntitiesByType(const EntityType& byType);
105 
119  EntityList GetEntitiesAt(const tbMath::Vector2& point, const EntityType& byType = Entity::kInvalidType, bool onlyCollidableEntities = false);
120 
124  EntityList GetEntitiesWithin(const tbMath::Vector2& center, const float radius, const EntityType& byType = Entity::kInvalidType, bool onlyCollidableEntities = false);
125 
129  EntityList GetEntitiesWithin(const tbMath::Vector2& center, const float width, const float height, const EntityType& byType = Entity::kInvalidType, bool onlyCollidableEntities = false);
130 
134  void Simulate(void);
135 
136  protected:
141  virtual void OnSimulate(void);
142 
146  virtual void OnUpdate(const float deltaTime) override;
147 
148  private:
149  void ReallyAddEntity(Entity* entity, bool managed);
150  void ReallyRemoveEntity(Entity* entityToRemove);
151  void ReallyRemoveMarkedEntities(void);
152 
153  typedef std::set<Entity*> EntitySet;
154  typedef std::map<EntityType, EntityList> EntityByTypeMap;
155 
156  EntityList mEntities;
157  EntityList mManagedEntities;
158  EntitySet mEntitiesToRemove;
159  EntityByTypeMap mEntitiesByType;
160  bool mIsSafeToRemove;
161  };
162 
163  }; /* namespace Game */
164 }; /* namespace TurtleBrains */
165 
166 namespace tbGame = TurtleBrains::Game;
167 
168 #endif /* TurtleBrains_EntityManager_hpp */
Definition: tb_vector.hpp:48
Definition: tb_entity.hpp:46
void AddEntity(Entity *entity)
Definition: tb_graphic_list.hpp:27
std::list< EntityType > EntityTypeContainer
Definition: tb_entity.hpp:35
std::list< Entity * > EntityList
Definition: tb_entity_manager.hpp:38
Here is some information about the primary namespace.
Definition: tb_application_dialog.hpp:21
virtual void OnUpdate(const float deltaTime) override
Definition: tb_entity_manager.hpp:32
void RemoveEntities(const EntityType &byType=Entity::kInvalidType)
tbCore::tbString EntityType
Definition: tb_entity.hpp:30
static const EntityType kInvalidType
Definition: tb_entity.hpp:53
EntityList GetEntitiesWithin(const tbMath::Vector2 &center, const float radius, const EntityType &byType=Entity::kInvalidType, bool onlyCollidableEntities=false)
EntityList GetEntitiesByType(const EntityType &byType)
void EntityTypeChanged(Entity &entity, const EntityTypeContainer &oldTypes)
EntityList GetEntitiesAt(const tbMath::Vector2 &point, const EntityType &byType=Entity::kInvalidType, bool onlyCollidableEntities=false)
void RemoveEntity(Entity *entity)
This is the heart of TurtleBrains for game developers to create GameScenes and Entities to interact w...