Easys
A minimalist, header-only C++ ECS library for efficient and fuss-free entity and component management.
Loading...
Searching...
No Matches
Public Member Functions | List of all members
Easys::ECS< AllComponentTypes > Class Template Reference

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< EntitygetEntitiesByComponents () 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 ()
 

Detailed Description

template<typename... AllComponentTypes>
class Easys::ECS< AllComponentTypes >

Manages entities and components in an Entity-Component-System architecture.

Template Parameters
AllComponentTypesA list of all possible component types that can be used in this ECS instance.

Constructor & Destructor Documentation

◆ ECS() [1/2]

template<typename... AllComponentTypes>
Easys::ECS< AllComponentTypes >::ECS ( )
inline

Initializes the ECS with a predefined maximum number of entities (MAX_ENTITIES).

All entity IDs are initially available for assignment.

◆ ECS() [2/2]

template<typename... AllComponentTypes>
Easys::ECS< AllComponentTypes >::ECS ( const std::set< Entity > &  oldEntities)
inline

Initializes the ECS with a specific set of entities.

This constructor is useful for creating a new ECS instance based on a subset of entities from another instance or a predefined list.

Parameters
entitiesA set of entities to initialize the ECS with.

Member Function Documentation

◆ addComponent()

template<typename... AllComponentTypes>
template<typename T >
void Easys::ECS< AllComponentTypes >::addComponent ( const Entity  e,
component 
)
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.

Template Parameters
TThe type of the component to add.
Parameters
eThe entity to which the component will be added.
cThe component data to add.

◆ addEntity()

template<typename... AllComponentTypes>
Entity Easys::ECS< AllComponentTypes >::addEntity ( )
inline

Adds a new entity to the ECS.

Returns
The ID of the newly created entity.
Exceptions
std::runtime_errorif the maximum number of entities (MAX_ENTITIES) is reached.

◆ clear()

template<typename... AllComponentTypes>
void Easys::ECS< AllComponentTypes >::clear ( )
inline

Clears all entities and components from the ECS.

Resets the ECS to its initial state, making all entity IDs available again.

◆ clearComponents() [1/2]

template<typename... AllComponentTypes>
template<typename... Ts>
void Easys::ECS< AllComponentTypes >::clearComponents ( )
inline

Removes components of specific types from all entities within the ECS.

Template Parameters
TsA variadic list of component types to clear. If template parameters are omitted, all types of components are cleared from all entities.

◆ clearComponents() [2/2]

template<typename... AllComponentTypes>
void Easys::ECS< AllComponentTypes >::clearComponents ( )
inline

◆ getComponent() [1/2]

template<typename... AllComponentTypes>
template<typename T >
T & Easys::ECS< AllComponentTypes >::getComponent ( const Entity  e)
inline

Retrieves a reference to a component of type T from an entity.

Template Parameters
TThe type of the component to retrieve.
Parameters
eThe entity whose component is to be retrieved.
Returns
A mutable reference to the component.

◆ getComponent() [2/2]

template<typename... AllComponentTypes>
template<typename T >
const T & Easys::ECS< AllComponentTypes >::getComponent ( const Entity  e) const
inline

Retrieves a reference to a component of type T from an entity.

Template Parameters
TThe type of the component to retrieve.
Parameters
eThe entity whose component is to be retrieved.
Returns
A immutable reference to the component.

◆ getComponentCount() [1/2]

template<typename... AllComponentTypes>
template<typename... Ts>
size_t Easys::ECS< AllComponentTypes >::getComponentCount ( ) const
inline

Returns the total count of components of the specified types within the ECS.

Template Parameters
TsA variadic list of component types. If template parameters are omitted, it returns the total count of all component types.
Returns
The total number of components of the specified types.

◆ getComponentCount() [2/2]

template<typename... AllComponentTypes>
size_t Easys::ECS< AllComponentTypes >::getComponentCount ( ) const
inline

◆ getEntities()

template<typename... AllComponentTypes>
const std::set< Entity > & Easys::ECS< AllComponentTypes >::getEntities ( ) const
inline

Returns a reference to the set of all entities.

Returns
A constant reference to the set of all entities currently in the ECS.

◆ getEntitiesByComponent()

template<typename... AllComponentTypes>
template<typename T >
const std::vector< Entity > & Easys::ECS< AllComponentTypes >::getEntitiesByComponent ( ) const
inline

Returns a vector of entities that have a component of a specific type.

Template Parameters
TThe component type to query for.
Returns
A constant reference to a vector of entities possessing the component.

◆ getEntitiesByComponents()

template<typename... AllComponentTypes>
template<typename... Ts>
std::vector< Entity > Easys::ECS< AllComponentTypes >::getEntitiesByComponents ( ) const
inline

Returns a vector of entities that have all of the specified component types. Use smaller components first for optimal performance.

Template Parameters
TsA variadic list of component types to query for.
Returns
A vector of entities that possess all specified components.

◆ getEntityCount()

template<typename... AllComponentTypes>
size_t Easys::ECS< AllComponentTypes >::getEntityCount ( ) const
inline

Returns the total number of active entities in the ECS.

Returns
The number of entities.

◆ hasComponent()

template<typename... AllComponentTypes>
template<typename T >
bool Easys::ECS< AllComponentTypes >::hasComponent ( const Entity  e) const
inline

Checks if an entity has a component of type T.

Template Parameters
TThe type of the component to check for.
Parameters
eThe entity to check.
Returns
True if the entity has the component, false otherwise.

◆ hasEntity()

template<typename... AllComponentTypes>
bool Easys::ECS< AllComponentTypes >::hasEntity ( const Entity  e) const
inline

Checks if an entity exists within the ECS.

Parameters
eThe entity to check for.
Returns
True if the entity exists, false otherwise.

◆ removeComponent()

template<typename... AllComponentTypes>
template<typename T >
void Easys::ECS< AllComponentTypes >::removeComponent ( const Entity  e)
inline

Removes a component of type T from an entity.

Template Parameters
TThe type of the component to remove.
Parameters
eThe entity from which to remove the component.

◆ removeComponents() [1/2]

template<typename... AllComponentTypes>
void Easys::ECS< AllComponentTypes >::removeComponents ( const Entity  e)
inline

Removes all components from an entity.

Parameters
eThe entity from which to remove all components.

◆ removeComponents() [2/2]

template<typename... AllComponentTypes>
template<typename... T>
void Easys::ECS< AllComponentTypes >::removeComponents ( const Entity  e)
inline

Removes all components of types T from an entity.

Template Parameters
TThe types of the components to remove.
Parameters
eThe entity from which to remove the components.

◆ removeEntity()

template<typename... AllComponentTypes>
void Easys::ECS< AllComponentTypes >::removeEntity ( const Entity  e)
inline

Removes an entity and all its associated components from the ECS.

The removed entity's ID is made available for reuse.

Parameters
eThe entity to remove.

The documentation for this class was generated from the following file: