Main driver to work with entities, components and systems. More...
#include <ECSEngine.h>
Public Member Functions | |
| Entity * | addEntity () |
| Adds a new entity to the collection and returns a pointer to it. | |
| void | addEntity (Entity &entity) |
| Adds an existing entity to the collection. More... | |
| Entity * | getEntity (Identifier entityId) |
| Gets a pointer to the entity from the collection with the given ID, or a nullptr if an entity with such ID does not exist in the collection. | |
| template<typename... Types> | |
| std::vector< Entity * > | entitiesWithComponents (bool includeDeleted=false) |
| Returns a vector with the entities that have the specified components. More... | |
| template<typename... Types> | |
| void | applyToEach (typename std::common_type< std::function< void(Entity *, Types *...)>>::type &&func, bool includeDeleted=false) |
| Applies a function to each of the entities from the collection that have the specified component types. More... | |
| template<typename EventType > | |
| void | subscribe (EventListener< EventType > *eventListener) |
| Subscribes the event listener to the list of listeners of that event type. More... | |
| template<typename EventType > | |
| void | unsubscribe (EventListener< EventType > *eventListener) |
| Unsubscribes the event listener from the list of listeners of that event type. | |
| template<typename EventType > | |
| void | emit (const EventType &event) |
| Emit an event to all listeners of that type of event. | |
| void | registerUpdateable (Updateable *updateable) |
| Adds an updateable object to the engine. More... | |
| virtual void | update () |
| Updates all the updateable objects in the engine. More... | |
Main driver to work with entities, components and systems.
The ECSEngine class manages and puts together all the pieces of the ECS model. It holds the entities and systems, and acts as a controller for the creation, deletion and modification of these objects.
It also acts as an observer for the classes that implement the EventListener interface, and is able to emit events of any type to these listeners, allowing communication between systems.
| void ECSEngine::addEntity | ( | Entity & | entity | ) |
Adds an existing entity to the collection.
If the entity already exists in the collection, that is, the ID of the entity is found in the collection, it does nothing.
| void lz::ECSEngine::applyToEach | ( | typename std::common_type< std::function< void(Entity *, Types *...)>>::type && | func, |
| bool | includeDeleted = false |
||
| ) |
Applies a function to each of the entities from the collection that have the specified component types.
The function passed can be a reference to an existing function, a lambda, or an std::function.
If includeDeleted is set to true, the function will also be applied to entities that are marked for deletion.
| std::vector< Entity * > lz::ECSEngine::entitiesWithComponents | ( | bool | includeDeleted = false | ) |
Returns a vector with the entities that have the specified components.
If includeDeleted is set to true, entities that are marked for deletion will also be included.
| void ECSEngine::registerUpdateable | ( | Updateable * | updateable | ) |
Adds an updateable object to the engine.
The update method on this object will be called when the engine is updated.
| void lz::ECSEngine::subscribe | ( | EventListener< EventType > * | eventListener | ) |
Subscribes the event listener to the list of listeners of that event type.
When an event of type EventType is emitted, it will be passed to all the event listeners subscribed to this event type, by calling their receive method.
|
virtual |
Updates all the updateable objects in the engine.
Will also garbage collect deleted entities.
1.8.6