libes
0.5.3
an Entity System library for C++
|
The manager. More...
#include <es/Manager.h>
Public Member Functions | |
Manager () | |
Create a manager. More... | |
~Manager () | |
Entity | createEntity () |
Create a new entity. More... | |
bool | destroyEntity (Entity e) |
Destroy an entity. More... | |
std::set< Entity > | getEntities () const |
Get all the entities. More... | |
Store * | getStore (ComponentType ct) |
Get the store associated to a component type. More... | |
bool | createStoreFor (ComponentType ct) |
Create a store for a component type. More... | |
template<typename C > | |
bool | createStoreFor () |
Create a store for a component type. More... | |
Component * | getComponent (Entity e, ComponentType ct) |
Get the component associated to an entity. More... | |
template<typename C > | |
C * | getComponent (Entity e) |
Get the component associated to an entity. More... | |
bool | addComponent (Entity e, ComponentType ct, Component *c) |
Add a component to an entity. More... | |
template<typename C > | |
bool | addComponent (Entity e, C *c) |
Add a component to an entity. More... | |
Component * | extractComponent (Entity e, ComponentType ct) |
Extract the component associated to an entity. More... | |
template<typename C > | |
C * | extractComponent (Entity e) |
Extract the component associated to an entity. More... | |
int | subscribeEntityToSystems (Entity e, std::set< ComponentType > components) |
Subscribe and entity to the systems. More... | |
int | subscribeEntityToSystems (Entity e) |
Subscribe and entity to the systems. More... | |
bool | addSystem (std::shared_ptr< System > sys) |
Add a system to the manager. More... | |
template<typename S , typename... Args> | |
bool | addSystem (Args &&...args) |
Add a system to the manager. More... | |
void | initSystems () |
Initialize all systems. More... | |
void | updateSystems (float delta) |
Update all systems. More... | |
void | registerHandler (EventType type, EventHandler handler) |
Register an event handler to an event type. More... | |
template<typename E > | |
void | registerHandler (EventHandler handler) |
Register an event handler to an event type. More... | |
template<typename E , typename R , typename T > | |
void | registerHandler (R T::*pm, T *obj) |
Register an event handler to an event type. More... | |
void | triggerEvent (Entity origin, EventType type, Event *event) |
Trigger an event. More... | |
template<typename E > | |
void | triggerEvent (Entity origin, E *event) |
Trigger an event. More... | |
The manager.
The role of the manager is to manage entities, stores, components and systems. It can also create entities.
|
inline |
Create a manager.
es::Manager::~Manager | ( | ) |
bool es::Manager::addComponent | ( | Entity | e, |
ComponentType | ct, | ||
Component * | c | ||
) |
Add a component to an entity.
e | the entity |
ct | the component type |
c | the component to be added |
|
inline |
Add a component to an entity.
e | the entity |
c | the component to be added |
bool es::Manager::addSystem | ( | std::shared_ptr< System > | sys | ) |
Add a system to the manager.
sys | the system |
|
inline |
Add a system to the manager.
args | the arguments to pass to the system's constructor |
Entity es::Manager::createEntity | ( | ) |
Create a new entity.
bool es::Manager::createStoreFor | ( | ComponentType | ct | ) |
Create a store for a component type.
ct | a component type |
|
inline |
Create a store for a component type.
bool es::Manager::destroyEntity | ( | Entity | e | ) |
Destroy an entity.
e | the entity to destroy |
Component* es::Manager::extractComponent | ( | Entity | e, |
ComponentType | ct | ||
) |
Extract the component associated to an entity.
The component is removed from the associated store and returned.
e | the entity |
ct | the component type |
|
inline |
Extract the component associated to an entity.
The component is removed from the associated store and returned.
e | the entity |
Component* es::Manager::getComponent | ( | Entity | e, |
ComponentType | ct | ||
) |
Get the component associated to an entity.
e | the entity |
ct | the component type |
|
inline |
Get the component associated to an entity.
e | the entity |
std::set<Entity> es::Manager::getEntities | ( | ) | const |
Get all the entities.
Store* es::Manager::getStore | ( | ComponentType | ct | ) |
Get the store associated to a component type.
ct | a component type |
void es::Manager::initSystems | ( | ) |
Initialize all systems.
void es::Manager::registerHandler | ( | EventType | type, |
EventHandler | handler | ||
) |
Register an event handler to an event type.
type | an event type |
handler | the event handler |
|
inline |
Register an event handler to an event type.
handler | the event handler |
|
inline |
Register an event handler to an event type.
This version of registerHandler works when the handler is defined in the method of a class (with the same signature as an EventHandler). Then, instead of calling std::bind directly, you can call this function and bind will be called automatically.
pm | a pointer to member function |
obj | the object on which to apply the function |
int es::Manager::subscribeEntityToSystems | ( | Entity | e, |
std::set< ComponentType > | components | ||
) |
Subscribe and entity to the systems.
e | the entity |
components | the set of component types that the entity has |
int es::Manager::subscribeEntityToSystems | ( | Entity | e | ) |
Subscribe and entity to the systems.
The manager uses the component types of the components that have been added to the entity.
e | the entity |
Trigger an event.
The event is dispatched to registered handlers.
origin | the entity that triggers the event |
type | the event type |
event | the event parameters |
|
inline |
Trigger an event.
The event is dispatched to registered handlers.
origin | the entity that triggers the event |
event | the event parameters |
void es::Manager::updateSystems | ( | float | delta | ) |
Update all systems.
delta | the time (in second) since the last update |