Yet Another Game Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
entity.h
Go to the documentation of this file.
1 
9 #pragma once
10 
11 #include <vector>
12 #include <memory>
13 
14 namespace yage
15 {
16 
17 class Space;
19 
20 typedef unsigned int Entity;
21 
25 {
26 public:
29  EntityManager() = default;
30 
36  EntityManager(Space *space);
37 
43  EntityManager(Space *space, std::size_t n);
44 
51 
54  void deleteEntity(Entity entity);
55 
56 private:
59  Entity next_entity_ = 0;
60 
63  Space *space_ = nullptr;
64 
67  std::vector<Entity> entities_;
68 
72  std::vector<std::unique_ptr<ComponentGroup>> components;
73 };
74 
81 public:
85  typedef unsigned Group;
86 
87 protected:
89 };
90 
96 template <typename Derived>
97 class Component : public BaseComponent {
98 private:
99  friend class EntityManager;
100 
101  BaseComponent::Group group();
102 };
103 
108 private:
109  friend class EntityManager;
110 
111  std::vector<BaseComponent *> components_;
112 };
113 
114 // Template definitions
115 
116 template <typename Derived>
118 {
119  static Group group_id = group_id_counter_++;
120  return group_id;
121 }
122 
123 } // namespace yage
Base component used to store components.
Definition: entity.h:80
Manages entities in a space.
Definition: entity.h:24
unsigned Group
Group used to register a specific component internally with the entity manager.
Definition: entity.h:85
Entity createEntity()
Creates an Entity and returns the handle to the entity, which can then be used by the user to do oper...
Definition: entity.cpp:25
unsigned int Entity
Definition: entity.h:18
EntityManager()=default
Default instance of an EntityManager.
Contains a list of all components that belong to a sepecific group, these are then stored in the main...
Definition: entity.h:107
static Group group_id_counter_
Definition: entity.h:88
void deleteEntity(Entity entity)
Delete an entity.
Definition: entity.cpp:32
The main component that is used to make a component from a defined struct.
Definition: entity.h:97
Space that keeps track of all the entities, componenets and runs the systems on the data to update th...
Definition: space.h:34