Class Engine::Registry¶
The core of the ECS. Manages entities, components, and systems. More...
#include <Registry.hpp>
Public Functions¶
| Type | Name |
|---|---|
| void | AddComponent (Entity entity, T component) Adds a component to an entity. |
| T & | AddResource (Args &&... args) Registers a global resource. |
| void | ClearEntities () Destroys every entity and restarts entity IDs at 1. |
| Entity | CreateEntity () Creates a new entity and gives it a default Position andRotation . |
| void | DestroyEntity (const Entity entity) Destroys an entity and its entire subtree (entities with Parent pointing here). |
| void | FlushQueues () Safely executes all deferred destructions. Call at the end of the frame. |
| std::optional< std::reference_wrapper< T > > | GetComponent (Entity entity) Retrieves a component for a specific entity. |
| std::shared_ptr< ComponentArray< T > > | GetComponentArray () Helper function to get the strongly-typed component array. |
| size_t | GetEntityCount () const Returns the total number of entities created (used by the Editor for iterating). |
| T & | GetResource () Retrieves a global resource. |
| std::shared_ptr< T > | GetSystem () Gets a registered system. |
| const std::vector< std::type_index > & | GetSystemRenderOrder () const Registration order for System::Render (stable across frames). |
| const std::vector< std::type_index > & | GetSystemUpdateOrder () const Registration order for System::Update (stable across frames). |
| const std::unordered_map< std::type_index, std::shared_ptr< System > > & | GetSystems () const Returns all registered systems. |
| bool | HasComponent (Entity entity) Checks if an entity has a specific component. |
| bool | HasComponentByType (const std::type_index & type, Entity entity) const Type-erased component existence check used by scripting glue. |
| bool | HasResource () const Checks if a resource exists. |
| bool | IsComponentRegistered () const Checks if a component type has been registered. |
| bool | IsEntityAlive (Entity entity) const Checks if an entity is alive (holds at least one component). |
| void | QueueDestroyEntity (Entity entity) Defers entity destruction to the end of the frame. Safe to call inside physics/collision callbacks! |
| Registry * | RegisterComponent () Registers a component type with the registry. |
| std::shared_ptr< T > | RegisterSystem () Registers a system type with the registry. |
| Registry () |
|
| void | RemoveComponent (Entity entity) Removes a component from an entity. |
| void | RemoveComponentByType (const std::type_index & type, Entity entity) Type-erased component removal used by scripting glue. |
| T & | RequireComponent (Entity entity) Retrieves a component that must already be on the entity. |
| void | Shutdown () Destroys every entity and every resource now. |
Detailed Description¶
The registry serves as the coordinator for the entire ECS architecture, providing methods to create entities, attach components, and register systems.
Public Functions Documentation¶
function AddComponent¶
Adds a component to an entity.
Template parameters:
TThe component type.
Parameters:
entityThe entity ID.componentThe component data.
function AddResource¶
Registers a global resource.
Template parameters:
TThe resource type.ArgsConstructor argument types.
Returns:
Reference to the created resource.
function ClearEntities¶
Destroys every entity and restarts entity IDs at 1.
Used when switching scenes. Component types, systems and resources stay registered: only entity data is removed. Each system's m_Entities set and the deferred destroy queue are emptied too, so nothing points at an old entity once IDs start being reused.
function CreateEntity¶
Creates a new entity and gives it a default Position andRotation .
Returns:
The ID of the newly created entity.
function DestroyEntity¶
Destroys an entity and its entire subtree (entities with Parent pointing here).
Parameters:
entityThe ID of the entity to destroy.
function FlushQueues¶
Safely executes all deferred destructions. Call at the end of the frame.
function GetComponent¶
Retrieves a component for a specific entity.
template<typename T>
inline std::optional< std::reference_wrapper< T > > Engine::Registry::GetComponent (
Entity entity
)
Missing components are empty results. Callers that require the component use RequireComponent.
Template parameters:
TThe component type.
Parameters:
entityThe entity ID.
Returns:
The component when the entity has it, otherwise std::nullopt. Also empty when T was never registered.
function GetComponentArray¶
Helper function to get the strongly-typed component array.
template<typename T>
inline std::shared_ptr< ComponentArray < T > > Engine::Registry::GetComponentArray ()
Template parameters:
TThe component type.
Returns:
Shared pointer to the ComponentArray.
function GetEntityCount¶
Returns the total number of entities created (used by the Editor for iterating).
function GetResource¶
Retrieves a global resource.
Template parameters:
TThe resource type.
Returns:
Reference to the resource.
function GetSystem¶
Gets a registered system.
Template parameters:
TThe system type.
Returns:
Shared pointer to the system.
function GetSystemRenderOrder¶
Registration order for System::Render (stable across frames).
function GetSystemUpdateOrder¶
Registration order for System::Update (stable across frames).
function GetSystems¶
Returns all registered systems.
inline const std::unordered_map< std::type_index, std::shared_ptr< System > > & Engine::Registry::GetSystems () const
function HasComponent¶
Checks if an entity has a specific component.
function HasComponentByType¶
Type-erased component existence check used by scripting glue.
inline bool Engine::Registry::HasComponentByType (
const std::type_index & type,
Entity entity
) const
Parameters:
typeThe component type index.entityThe entity ID.
Returns:
True if the component is registered and attached to the entity.
function HasResource¶
Checks if a resource exists.
Template parameters:
TThe resource type.
Returns:
True if the resource exists.
function IsComponentRegistered¶
Checks if a component type has been registered.
Template parameters:
TThe component type.
Returns:
True if RegisterComponent<T>() has been called.
function IsEntityAlive¶
Checks if an entity is alive (holds at least one component).
Entity IDs are not reused while a scene is running, so destroyed entities keep their ID but own no components. Editor panels use this to skip dead rows. Only ClearEntities restarts IDs at 1.
Parameters:
entityThe entity ID.
Returns:
True if any component is attached to the entity.
function QueueDestroyEntity¶
Defers entity destruction to the end of the frame. Safe to call inside physics/collision callbacks!
function RegisterComponent¶
Registers a component type with the registry.
Template parameters:
TThe component type.
function RegisterSystem¶
Registers a system type with the registry.
Template parameters:
TThe system type.
Returns:
Shared pointer to the registered system.
function Registry¶
function RemoveComponent¶
Removes a component from an entity.
Template parameters:
TThe component type.
Parameters:
entityThe entity ID.
function RemoveComponentByType¶
Type-erased component removal used by scripting glue.
Parameters:
typeThe component type index.entityThe entity ID.
function RequireComponent¶
Retrieves a component that must already be on the entity.
Template parameters:
TThe component type.
Parameters:
entityThe entity ID.
Returns:
Reference to the requested component.
Exception:
- ErrorEcs if
Tis not registered or the entity does not have it.
function Shutdown¶
Destroys every entity and every resource now.
Lets the application free GPU/audio-backed data (textures, sounds, fonts) while the window and audio device are still alive, instead of during member destruction after CloseWindow().
The documentation for this class was generated from the following file /home/runner/work/r-type/r-type/Engine/include/ECS/Registry.hpp