jubilant-funicular
|
#include <ECS.h>
Classes | |
struct | ComponentInfo |
Info directly attached to a ComponentID. More... | |
Public Member Functions | |
ECS (const ComponentRegistry ®istry) | |
Entity | gen_entity () |
Generates a new Entity, returning its ID. | |
void | gen_entities (std::size_t num, Entity *ids) |
Generates several entities, storing their IDs in ids. | |
bool | delete_entity (Entity id) |
bool | delete_owner (ComponentID cmpn) |
std::size_t | num_entities () const |
Returns the number of entities in the system. | |
template<typename T > | |
std::size_t | num_components () const |
Returns the number of components of the given type. | |
std::size_t | num_components () const |
template<typename T , typename... Args> | |
utils::Option< ComponentID > | add_component (Entity entity, Args &&... args) |
template<typename T , typename... Args> | |
utils::Option< ComponentID > | add_sibling (ComponentID cmpn, Args &&... args) |
bool | delete_component (ComponentID cmpn) |
template<typename T > | |
bool | delete_component (Entity entity) |
template<typename T > | |
bool | has_component (Entity entity) const |
Returns true if the given Entity has a Component of type T. | |
template<typename T > | |
bool | has_sibling (ComponentID cmpn) const |
bool | does_entity_exist (Entity entity) const |
Returns true if the given Entity exists. | |
utils::Option< Entity > | get_owner (ComponentID cmpn) const |
Returns the Entity associated to this Component. | |
template<typename T > | |
ComponentList< T > & | get_component_list () const |
Returns a list of all components of the given type. | |
template<typename T > | |
utils::Option< T & > | get_component (Entity entity) const |
Returns the Component of the given type associated to the given Entity. | |
utils::Option< Component & > | get_component (ComponentID id) const |
Returns the Component with the given id. | |
template<typename T > | |
utils::Option< T & > | get_sibling (ComponentID cmpn) const |
Returns the Component of the given type with the same owner as cmpn. | |
template<typename T > | |
void | for_each (std::function< void(T &)> func) const |
Runs a function of each Component of a given type. | |
template<typename T , typename Event > | |
void | enact_on (const Event &event, Entity entity) const |
Enacts the event on the Component of the given type owned by the given Entity. | |
template<typename T , typename Event , typename Event::enum_type e> | |
void | enact_on (const Event &event, Entity entity) const |
template<typename T , typename Event > | |
void | enact_on (const Event &event, typename Event::enum_type e, Entity entity) const |
template<typename T , typename Event > | |
void | enact_on_sibling (const Event &event, ComponentID cmpn) const |
Enacts the event on the Component of the given type owned by the same entity. | |
template<typename T , typename Event , typename Event::enum_type e> | |
void | enact_on_sibling (const Event &event, ComponentID cmpn) const |
template<typename T , typename Event > | |
void | enact_on_sibling (const Event &event, typename Event::enum_type e, ComponentID cmpn) const |
template<typename T , typename Event > | |
void | enact_on_all (const Event &event, typename Event::enum_type e) const |
Enacts the event on all the Components of the given type. | |
template<typename T , typename Event , typename Event::enum_type e> | |
void | enact_on_all (const Event &event) const |
void | clear () |
Removes all entities and components from this system. | |
Private Attributes | |
utils::TypeMap | m_components |
utils::SlotMap< ComponentInfo > | m_component_info |
utils::IDFactory< Entity > | m_entity_gen |
Responsible for creating unique IDs for the Entities. | |
utils::IDFactory< ComponentID > | m_cmpn_gen |
Responsible for creating unique IDs for the Components. | |
const ComponentRegistry | m_registry |
Container class representing a complete Entity-Component System
Manages creation of Entities and grouping of Components.
Assumes each entity can only have one Component of a given type.
The Event template parameter used in some functions should usually be an instantiation of EventTemplate. It is used for passing around events/signals/commands, i.e. it should be invokable on components
If you don't need events, leave this parameter unspecified.
struct nta::ECS::ComponentInfo |
utils::Option< ComponentID > nta::ECS::add_component | ( | Entity | entity, |
Args &&... | args | ||
) |
bool nta::ECS::delete_component | ( | ComponentID | cmpn | ) |
bool nta::ECS::delete_entity | ( | Entity | id | ) |
|
private |
A map from ComponentID to relevant information about that Component
Since ComponentIDs are unique, I could get rid of this and just always loop over all records instead.
Definition at line 153 of file ECS.h.
Referenced by add_component(), clear(), delete_component(), delete_entity(), get_component(), and get_owner().
|
private |
All the components in this system
Only stores types of the form ComponentList<T> where T inherits Component. Each vector has size m_entity_gen.get_last_id().
Definition at line 148 of file ECS.h.
Referenced by add_component(), clear(), delete_component(), delete_entity(), get_component(), get_component_list(), and has_component().
|
private |
The various Component types in use
This registry should not change after it's associated to an ECS
Definition at line 161 of file ECS.h.
Referenced by clear(), delete_component(), delete_entity(), and get_component().