|
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. | |
| View | getEntities () const |
| Returns a reference to the set of all entities. | |
| template<typename... Ts> | |
| View | getEntities () 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 , typename Func > | |
| void | modifyComponent (const Entity e, Func &&fn) |
| Modifies a component of type T for a given entity. | |
| template<typename T > | |
| void | modifyComponent (const Entity e, T c) |
| Modifies a component of type T for a given entity. | |
| template<typename T > | |
| void | removeComponent (const Entity e) |
| Removes a component of type T from an entity. | |
| template<typename... Ts> | |
| void | removeComponents (const Entity e) |
| Removes all components of types Ts from an entity. | |
| void | removeComponents (const Entity e) |
| Removes all components 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 > | |
| T & | getComponentOr (const Entity e, T &c) |
| Retrieves a reference to a component of type T from an entity. If the entity does not exist or does not have a component T, return c. | |
| template<typename T > | |
| const T & | getComponentOr (const Entity e, const T &c) const |
| Retrieves a reference to a component of type T from an entity. If the entity does not exist or does not have a component T, return c. | |
| 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 |
| template<typename T > | |
| void | clearComponent () |
| Removes component of specific type from all entities within the ECS. | |
| template<typename... Ts> | |
| void | clearComponents () |
| Removes components of specific types from all entities within the ECS. | |
| void | clearComponents () |
| void | clear () |
| Clears all entities and components from the ECS. | |
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 component of specific type from all entities within the ECS.
| T | A component type to clear. |
|
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 |
Retrieves a reference to a component of type T from an entity. If the entity does not exist or does not have a component T, return c.
| T | The type of the component to retrieve. |
| e | The entity whose component is to be retrieved. |
| c | The default component value to return, if the entity does not have the component T. |
|
inline |
Retrieves a reference to a component of type T from an entity. If the entity does not exist or does not have a component T, return c.
| T | The type of the component to retrieve. |
| e | The entity whose component is to be retrieved. |
| c | The default component value to return, if the entity does not have the component T. |
|
inline |
Returns a reference to the set of all entities.
|
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 |
Modifies a component of type T for a given entity.
This function retrieves the component of type T associated with the specified entity and invokes the provided callable function with a reference to that component. The callable can be a lambda, function pointer, or any other callable type. The component can be modified directly through the callable.
| T | The type of the component to modify. |
| e | The entity whose component will be modified. |
| fn | The callable that will be used to modify the component. It should accept a reference to the component of type T. |
|
inline |
Modifies a component of type T for a given entity.
This function retrieves the component of type T associated with the specified entity and replaces it with the new component provided as the argument c.
| T | The type of the component to modify. |
| e | The entity whose component will be modified. |
| c | The new component of type T that will replace the existing component. |
|
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 of types Ts from an entity.
| T | The types of the components to remove. |
| e | The entity from which to remove the components. |
|
inline |
Removes all components from an entity.
| e | The entity from which to remove all 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. |