CG-Project2
|
This class manages all the entities and the components instanced. More...
#include <EntityManager.hpp>
Public Types | |
using | Index = unsigned int |
Public Member Functions | |
Index | createEntity () |
Create an entity and increment the current index. | |
void | resetIndex () |
Reset the ECS id, it is usually used when entities are cleaned. | |
std::vector< Index > | getEntities () const |
Retrieves a vector containing all entities in the ECS. | |
std::string | getEntityName (const Index &id) const |
Retrieves the entity name. | |
void | setEntityName (const Index &id, const std::string &name) |
Sets the name of the entity given. | |
bool | removeEntity (const Index &id) |
Removes the entity given from the ECS. | |
bool | isEntityValid (const Index &id) |
Checks if the entity given has components. | |
unsigned int | getEntitiesCount () const |
Retrieves the number of entities in the ECS. | |
template<typename T, typename... Args> | |
Shared< T > | addComponent (const Index &id, Args &&...args) |
Adds a component to the given entity. It instances a shared pointer of that component and calls the component constructor with the arguments given. | |
template<typename T> | |
bool | removeComponent (const Index &id) |
Removes a component from the given entity. | |
template<typename T> | |
bool | entityHasComponent (const Index &id) |
Checks if the given entity has the component. | |
template<typename T> | |
std::vector< Index > | getEntitiesFromComponent () const |
Retrieves all the entities that have the given component. | |
template<typename T> | |
Shared< T > | getComponentFromId (const Index &id) |
Retrieves a shared pointer to the component of an entity. | |
EntityManager (EntityManager &other)=delete | |
void | operator= (const EntityManager &other)=delete |
Static Public Member Functions | |
static Shared< EntityManager > | instance () |
Retrieves the instance of the EntityManager. If it's not instanced, it will be instanced automatically. |
This class manages all the entities and the components instanced.
It allows to add entities, add and remove components from entitites, query all entities with a specific component, etc.
It's implemented with singleton so there only be one instance of this class.
|
inline |
Adds a component to the given entity. It instances a shared pointer of that component and calls the component constructor with the arguments given.
T | class of the component |
Args | list of arguments |
id | entity id |
args | arguments list |
|
inline |
Create an entity and increment the current index.
|
inline |
Checks if the given entity has the component.
T | class of the component |
id | entity id |
|
inline |
Retrieves a shared pointer to the component of an entity.
T | class of the component |
id | entity id |
|
inline |
Retrieves a vector containing all entities in the ECS.
|
inline |
Retrieves the number of entities in the ECS.
|
inline |
Retrieves all the entities that have the given component.
T | class of the component |
|
inline |
Retrieves the entity name.
id | entity id |
|
inlinestatic |
Retrieves the instance of the EntityManager. If it's not instanced, it will be instanced automatically.
|
inline |
Checks if the entity given has components.
id | entity id |
|
inline |
Removes a component from the given entity.
T | class of the component that will be removed |
id | entity id |
|
inline |
Removes the entity given from the ECS.
If the entity is present in the ECS, his component will be cleared.
id | entity id |
|
inline |
Sets the name of the entity given.
id | entity id |