18template <
typename... AllComponentTypes>
29 availableEntityIds_.push(entity);
39 ECS(
const std::set<Entity>& oldEntities)
46 if (oldEntities.contains(entity))
47 entities_.insert(entity);
49 availableEntityIds_.push(entity);
62 Entity e = availableEntityIds_.front();
63 availableEntityIds_.pop();
69 throw std::runtime_error(
"MAX NUMBER OF ENTITIES REACHED!");
84 availableEntityIds_.push(e);
98 inline const std::set<Entity>&
getEntities()
const {
return entities_; }
105 template <
typename T>
108 return registry_.template getEntitiesByComponent<T>();
117 template <
typename... Ts>
136 template <
typename T>
147 template <
typename T>
150 registry_.template removeComponent<T>(e);
167 template <
typename... T>
179 template <
typename T>
182 return registry_.template getComponent<T>(e);
191 template <
typename T>
194 return registry_.template getComponent<T>(e);
203 template <
typename T>
206 return registry_.template hasComponent<T>(e);
215 template <
typename... Ts>
218 return registry_.template size<Ts...>();
238 template <
typename... Ts>
241 registry_.template
clear<Ts...>();
247 std::queue<Entity> availableEntityIds_;
248 std::set<Entity> entities_;
249 Registry<AllComponentTypes...> registry_;
255 std::queue<Entity> empty;
256 std::swap(availableEntityIds_, empty);
258 for (
Entity entity = 0; entity <
MAX_ENTITIES; entity++) availableEntityIds_.push(entity);
Manages entities and components in an Entity-Component-System architecture.
Definition ecs.hpp:19
void addComponent(const Entity e, T component)
Adds a component of type T to an entity.
Definition ecs.hpp:137
Entity addEntity()
Adds a new entity to the ECS.
Definition ecs.hpp:58
void clearComponents()
Definition ecs.hpp:244
const T & getComponent(const Entity e) const
Retrieves a reference to a component of type T from an entity.
Definition ecs.hpp:192
size_t getEntityCount() const
Returns the total number of active entities in the ECS.
Definition ecs.hpp:127
size_t getComponentCount() const
Returns the total count of components of the specified types within the ECS.
Definition ecs.hpp:216
void removeEntity(const Entity e)
Removes an entity and all its associated components from the ECS.
Definition ecs.hpp:77
const std::set< Entity > & getEntities() const
Returns a reference to the set of all entities.
Definition ecs.hpp:98
void clear()
Clears all entities and components from the ECS.
Definition ecs.hpp:227
T & getComponent(const Entity e)
Retrieves a reference to a component of type T from an entity.
Definition ecs.hpp:180
std::vector< Entity > getEntitiesByComponents() const
Returns a vector of entities that have all of the specified component types. Use smaller components f...
Definition ecs.hpp:118
size_t getComponentCount() const
Definition ecs.hpp:221
ECS(const std::set< Entity > &oldEntities)
Initializes the ECS with a specific set of entities.
Definition ecs.hpp:39
bool hasEntity(const Entity e) const
Checks if an entity exists within the ECS.
Definition ecs.hpp:92
void clearComponents()
Removes components of specific types from all entities within the ECS.
Definition ecs.hpp:239
ECS()
Initializes the ECS with a predefined maximum number of entities (MAX_ENTITIES).
Definition ecs.hpp:25
void removeComponents(const Entity e)
Removes all components from an entity.
Definition ecs.hpp:157
void removeComponent(const Entity e)
Removes a component of type T from an entity.
Definition ecs.hpp:148
bool hasComponent(const Entity e) const
Checks if an entity has a component of type T.
Definition ecs.hpp:204
const std::vector< Entity > & getEntitiesByComponent() const
Returns a vector of entities that have a component of a specific type.
Definition ecs.hpp:106
void removeComponents(const Entity e)
Removes all components of types T from an entity.
Definition ecs.hpp:168
Definition registry.hpp:15
size_t size() const
Definition registry.hpp:117
void addComponent(const Entity entity, const ComponentType &component)
Definition registry.hpp:21
void clear()
Definition registry.hpp:144
void removeComponents(const Entity entity)
Definition registry.hpp:34
const Entity MAX_ENTITIES
Definition entity.hpp:12
EASYS_ENTITY_TYPE Entity
Definition entity.hpp:11