libes  0.5.3
an Entity System library for C++
Public Member Functions | List of all members
es::Manager Class Reference

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< EntitygetEntities () const
 Get all the entities. More...
 
StoregetStore (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...
 
ComponentgetComponent (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...
 
ComponentextractComponent (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...
 

Detailed Description

The manager.

The role of the manager is to manage entities, stores, components and systems. It can also create entities.

Constructor & Destructor Documentation

es::Manager::Manager ( )
inline

Create a manager.

es::Manager::~Manager ( )

Member Function Documentation

bool es::Manager::addComponent ( Entity  e,
ComponentType  ct,
Component c 
)

Add a component to an entity.

Parameters
ethe entity
ctthe component type
cthe component to be added
Returns
true if the component was actually added
template<typename C >
bool es::Manager::addComponent ( Entity  e,
C *  c 
)
inline

Add a component to an entity.

Parameters
ethe entity
cthe component to be added
Returns
true if the component was actually added
bool es::Manager::addSystem ( std::shared_ptr< System sys)

Add a system to the manager.

Parameters
systhe system
Returns
true if the system was actually added
template<typename S , typename... Args>
bool es::Manager::addSystem ( Args &&...  args)
inline

Add a system to the manager.

Parameters
argsthe arguments to pass to the system's constructor
Returns
true if the system was actually added
Entity es::Manager::createEntity ( )

Create a new entity.

Returns
a new entity
bool es::Manager::createStoreFor ( ComponentType  ct)

Create a store for a component type.

Parameters
cta component type
Returns
true if the store was created
template<typename C >
bool es::Manager::createStoreFor ( )
inline

Create a store for a component type.

Returns
true if the store was createds
bool es::Manager::destroyEntity ( Entity  e)

Destroy an entity.

Parameters
ethe entity to destroy
Returns
true if the entity was actually present and destroyed
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.

Parameters
ethe entity
ctthe component type
Returns
the component or null if the entity is not valid, or if the store does not exist or if the entity has no component of this type
template<typename C >
C* es::Manager::extractComponent ( Entity  e)
inline

Extract the component associated to an entity.

The component is removed from the associated store and returned.

Parameters
ethe entity
Returns
the component or null if the entity is not valid, or if the store does not exist or if the entity has no component of this type
Component* es::Manager::getComponent ( Entity  e,
ComponentType  ct 
)

Get the component associated to an entity.

Parameters
ethe entity
ctthe component type
Returns
the component or null if the entity is not valid, or if the store does not exist or if the entity has no component of this type
template<typename C >
C* es::Manager::getComponent ( Entity  e)
inline

Get the component associated to an entity.

Parameters
ethe entity
Returns
the component or null if the entity is not valid, or if the store does not exist or if the entity has no component of this type
std::set<Entity> es::Manager::getEntities ( ) const

Get all the entities.

Returns
a copy of the set of entities
Store* es::Manager::getStore ( ComponentType  ct)

Get the store associated to a component type.

Parameters
cta component type
Returns
the store or nullptr if the store does not exist
void es::Manager::initSystems ( )

Initialize all systems.

void es::Manager::registerHandler ( EventType  type,
EventHandler  handler 
)

Register an event handler to an event type.

Parameters
typean event type
handlerthe event handler
template<typename E >
void es::Manager::registerHandler ( EventHandler  handler)
inline

Register an event handler to an event type.

Parameters
handlerthe event handler
template<typename E , typename R , typename T >
void es::Manager::registerHandler ( R T::*  pm,
T *  obj 
)
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.

Parameters
pma pointer to member function
objthe object on which to apply the function
int es::Manager::subscribeEntityToSystems ( Entity  e,
std::set< ComponentType components 
)

Subscribe and entity to the systems.

Parameters
ethe entity
componentsthe set of component types that the entity has
Returns
the number of systems the entity was subscribed
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.

Parameters
ethe entity
Returns
the number of systems the entity was subscribed
void es::Manager::triggerEvent ( Entity  origin,
EventType  type,
Event event 
)

Trigger an event.

The event is dispatched to registered handlers.

Parameters
originthe entity that triggers the event
typethe event type
eventthe event parameters
template<typename E >
void es::Manager::triggerEvent ( Entity  origin,
E *  event 
)
inline

Trigger an event.

The event is dispatched to registered handlers.

Parameters
originthe entity that triggers the event
eventthe event parameters
void es::Manager::updateSystems ( float  delta)

Update all systems.

Parameters
deltathe time (in second) since the last update