Easys
A minimalist, header-only C++ ECS library for efficient and fuss-free entity and component management.
|
Manages entities and components in an Entity-Component-System architecture. More...
#include <ecs.hpp>
Public Member Functions | |
ECS () | |
Initializes the ECS with a predefined maximum number of entities (MAX_ENTITIES). | |
ECS (const std::set< Entity > &oldEntities) | |
Initializes the ECS with a specific set of entities. | |
Entity | addEntity () |
Adds a new entity to the ECS. | |
void | removeEntity (const Entity e) |
Removes an entity and all its associated components from the ECS. | |
bool | hasEntity (const Entity e) const |
Checks if an entity exists within the ECS. | |
const std::set< Entity > & | getEntities () const |
Returns a reference to the set of all entities. | |
template<typename T > | |
const std::vector< Entity > & | getEntitiesByComponent () const |
Returns a vector of entities that have a component of a specific type. | |
template<typename... Ts> | |
std::vector< Entity > | getEntitiesByComponents () const |
Returns a vector of entities that have all of the specified component types. Use smaller components first for optimal performance. | |
size_t | getEntityCount () const |
Returns the total number of active entities in the ECS. | |
template<typename T > | |
void | addComponent (const Entity e, T component) |
Adds a component of type T to an entity. | |
template<typename T > | |
void | removeComponent (const Entity e) |
Removes a component of type T from an entity. | |
void | removeComponents (const Entity e) |
Removes all components from an entity. | |
template<typename... T> | |
void | removeComponents (const Entity e) |
Removes all components of types T from an entity. | |
template<typename T > | |
T & | getComponent (const Entity e) |
Retrieves a reference to a component of type T from an entity. | |
template<typename T > | |
const T & | getComponent (const Entity e) const |
Retrieves a reference to a component of type T from an entity. | |
template<typename T > | |
bool | hasComponent (const Entity e) const |
Checks if an entity has a component of type T. | |
template<typename... Ts> | |
size_t | getComponentCount () const |
Returns the total count of components of the specified types within the ECS. | |
size_t | getComponentCount () const |
void | clear () |
Clears all entities and components from the ECS. | |
template<typename... Ts> | |
void | clearComponents () |
Removes components of specific types from all entities within the ECS. | |
void | clearComponents () |
Manages entities and components in an Entity-Component-System architecture.
AllComponentTypes | A list of all possible component types that can be used in this ECS instance. |
|
inline |
Initializes the ECS with a predefined maximum number of entities (MAX_ENTITIES).
All entity IDs are initially available for assignment.
|
inline |
|
inline |
Adds a component of type T to an entity.
If the entity already has a component of type T, it will be updated with the new value.
T | The type of the component to add. |
e | The entity to which the component will be added. |
c | The component data to add. |
|
inline |
Adds a new entity to the ECS.
std::runtime_error | if the maximum number of entities (MAX_ENTITIES) is reached. |
|
inline |
|
inline |
Removes components of specific types from all entities within the ECS.
Ts | A variadic list of component types to clear. If template parameters are omitted, all types of components are cleared from all entities. |
|
inline |
|
inline |
Retrieves a reference to a component of type T from an entity.
T | The type of the component to retrieve. |
e | The entity whose component is to be retrieved. |
|
inline |
Retrieves a reference to a component of type T from an entity.
T | The type of the component to retrieve. |
e | The entity whose component is to be retrieved. |
|
inline |
Returns the total count of components of the specified types within the ECS.
Ts | A variadic list of component types. If template parameters are omitted, it returns the total count of all component types. |
|
inline |
|
inline |
Returns a reference to the set of all entities.
|
inline |
Returns a vector of entities that have a component of a specific type.
T | The component type to query for. |
|
inline |
Returns a vector of entities that have all of the specified component types. Use smaller components first for optimal performance.
Ts | A variadic list of component types to query for. |
|
inline |
Returns the total number of active entities in the ECS.
|
inline |
Checks if an entity has a component of type T.
T | The type of the component to check for. |
e | The entity to check. |
|
inline |
Checks if an entity exists within the ECS.
e | The entity to check for. |
|
inline |
Removes a component of type T from an entity.
T | The type of the component to remove. |
e | The entity from which to remove the component. |
|
inline |
Removes all components from an entity.
e | The entity from which to remove all components. |
|
inline |
Removes all components of types T from an entity.
T | The types of the components to remove. |
e | The entity from which to remove the components. |
|
inline |
Removes an entity and all its associated components from the ECS.
The removed entity's ID is made available for reuse.
e | The entity to remove. |