Nui Engine
A game engine framework
|
The ECS context class manages entities, systems, and events in the ECS framework. More...
#include <Context.h>
Public Types | |
using | SubscriberMap = std::unordered_map<TypeIndex, std::vector<Internal::EventSubscriberBase*>, std::hash<TypeIndex>, std::equal_to<TypeIndex>> |
Unordered map of subscribers to array of events subscriber base pointers. | |
Public Member Functions | |
Context () | |
Constructs a new ECS context. | |
virtual | ~Context () |
Destroys the ECS context. | |
U64 | GetEntityCount () const noexcept |
Gets the total count of entities in the ECS context. | |
Entity * | GetEntityById (U64 id) |
Retrieves an entity by its unique identifier. | |
Entity * | GetEntityByIndex (U64 index) |
Retrieves an entity by its index. | |
Entity * | CreateEntity () |
Creates a new entity in the ECS context. | |
void | DestroyEntity (Entity *e, bool immediate=false) |
Destroys an entity in the ECS context. | |
bool | ClearPending () |
Clears all entities pending destruction in the ECS context. | |
void | Reset () |
Resets the ECS context, clearing all entities but keeping the systems. | |
template<typename T , typename... Args> requires IsSystem<T> | |
T * | RegisterSystem (Args &&... args) |
Registers a new system in the ECS context. | |
template<typename T > requires IsSystem<T> | |
void | UnregisterSystem () |
Unregisters a system from the ECS context. | |
void | UnregisterAllSystems () |
Un-registers all systems from the ECS context. | |
template<typename T > requires IsSystem<T> | |
T * | GetSystem () |
Gets a system from the ECS context. | |
template<typename T > requires IsSystem<T> | |
void | EnableSystem () |
Enables a system in the ECS context. | |
template<typename T > requires IsSystem<T> | |
void | DisableSystem () |
Disables a system in the ECS context. | |
template<typename T > requires IsSystem<T> | |
bool | IsSystmEnabled () |
Checks if a system is enabled in the ECS context. | |
template<typename T > | |
void | SubscribeEvent (EventSubscriber< T > *subscriber) |
Subscribes to an event in the ECS context. | |
template<typename T > | |
void | UnsubscribeEvent (EventSubscriber< T > *subscriber) |
Unsubscribes from an event in the ECS context. | |
void | UnsubscribeAll (void *subscriber) |
Un-subscribes from all events in the ECS context (usually called in the system destructor) | |
template<typename T > | |
void | EmitEvent (const T &event) |
Emits an event in the ECS context to all subscribers. | |
template<typename... Types> | |
Internal::EntityComponentView< Types... > | Each (bool includePendingDestroy=false) |
Iterates over all entities in the ECS context (used in ranged loops) | |
template<typename... Types> | |
void | Each (typename std::common_type< std::function< void(Entity *, ComponentHandle< Types >...)> >::type viewFunc, bool includePendingDestroy=false) |
Iterates over all entities in the ECS context (using a lambda/function) | |
Internal::EntityView | All (bool includePendingDestroy=false) |
Iterates over all entities in the ECS context (used in ranged loops) | |
void | All (std::function< void(Entity *)> viewFunc, bool includePendingDestroy=false) |
Iterates over all entities in the ECS context (using a lambda/function) | |
void | Tick (const F64 dt) |
Updates the ECS context (updates all the systems) | |
The ECS context class manages entities, systems, and events in the ECS framework.
|
inline |
Iterates over all entities in the ECS context (used in ranged loops)
includePendingDestroy | Flag indicating whether to include entities pending destruction |
|
inline |
Iterates over all entities in the ECS context (using a lambda/function)
viewFunc | Function to call for each entity |
includePendingDestroy | Flag indicating whether to include entities pending destruction |
|
inline |
Clears all entities pending destruction in the ECS context.
|
inline |
Creates a new entity in the ECS context.
|
inline |
Destroys an entity in the ECS context.
e | Pointer to the entity to destroy. |
immediate | Flag indicating whether to destroy the entity immediately. |
|
inline |
Disables a system in the ECS context.
T | Class derived from SystemBase to disable |
|
inline |
Iterates over all entities in the ECS context (used in ranged loops)
...Types | Types of components |
includePendingDestroy | Flag indicating whether to include entities pending destruction |
|
inline |
Iterates over all entities in the ECS context (using a lambda/function)
...Types | Types of components |
viewFunc | Function to call for each entity |
includePendingDestroy | Flag indicating whether to include entities pending destruction |
|
inline |
Emits an event in the ECS context to all subscribers.
T | Type of event |
event | Event data |
|
inline |
Enables a system in the ECS context.
T | Class derived from SystemBase to enable |
|
inline |
Retrieves an entity by its unique identifier.
id | The unique identifier of the entity. |
|
inline |
Retrieves an entity by its index.
index | The index of the entity. |
|
inlinenoexcept |
Gets the total count of entities in the ECS context.
|
inline |
Gets a system from the ECS context.
T | Class derived from SystemBase |
|
inline |
Checks if a system is enabled in the ECS context.
T | Class derived from SystemBase to check |
|
inline |
Registers a new system in the ECS context.
T | Class derived from SystemBase to register as a system |
...Args | Arguments to pass to the constructor |
...args | Arguments to pass to the constructor |
|
inline |
Subscribes to an event in the ECS context.
T | Type of event to subscribe to |
subscriber | A pointer to the subscriber (usually the system itself) |
|
inline |
Updates the ECS context (updates all the systems)
dt | Delta time |
|
inline |
Unregisters a system from the ECS context.
T | Class derived from SystemBase to unregister |
|
inline |
Un-subscribes from all events in the ECS context (usually called in the system destructor)
subscriber | A pointer to the subscriber (usually the system itself) |
|
inline |
Unsubscribes from an event in the ECS context.
T | Type of event to unsubscribe from |
subscriber | A pointer to the subscriber (usually the system itself) |