Central registry for managing entities and their components in the ECS system.
More...
#include <Registry.hpp>
|
| template<typename T> |
| ComponentStorage< T > * | try_get_storage_internal () |
| | Attempts to retrieve the storage for component type T without creating it.
|
| Entity | create () |
| | Creates a new entity.
|
| void | destroy (Entity entity) |
| | Destroys an entity and all its associated components.
|
| template<typename T, typename... Args> |
| T & | add_or_replace (Entity entity, Args &&... args) |
| | Adds or replaces a component for an entity.
|
| template<typename T> |
| void | remove (Entity entity) |
| | Removes a component from an entity.
|
| template<typename T> |
| T & | get (Entity entity) |
| | Retrieves a component from an entity.
|
| template<typename T> |
| T * | try_get (Entity entity) |
| | Safely retrieves a component from an entity if it exists.
|
| template<typename T> |
| bool | has (Entity entity) |
| | Checks if an entity has a component of type T.
|
| template<typename T> |
| void | on_create (std::function< void(Entity, T &)> cb) |
| | Registers a callback to be invoked when a component of type T is created.
|
| template<typename T> |
| void | on_destroy (std::function< void(Entity, T &)> cb) |
| | Registers a callback to be invoked when a component of type T is destroyed.
|
Central registry for managing entities and their components in the ECS system.
The Registry handles entity creation and destruction, component storage management, and provides a unified interface for component access. It maintains a pool of available entity IDs for reuse and dynamically creates storage for each component type as needed.
- Examples
- /home/devu/Documents/Projects/VEX/Engine/Core/include/components/ECS/ECS.hpp.
Definition at line 29 of file Registry.hpp.
◆ add_or_replace()
template<typename T, typename... Args>
| T & vex::Registry::add_or_replace |
( |
Entity | entity, |
|
|
Args &&... | args ) |
|
inline |
◆ create()
| Entity vex::Registry::create |
( |
| ) |
|
|
inline |
◆ destroy()
| void vex::Registry::destroy |
( |
Entity | entity | ) |
|
|
inline |
◆ get()
template<typename T>
| T & vex::Registry::get |
( |
Entity | entity | ) |
|
|
inline |
Retrieves a component from an entity.
- Template Parameters
-
- Parameters
-
| entity | The entity to get the component from. |
- Returns
- Mutable reference to the component.
- Precondition
- The entity must have the component.
Definition at line 118 of file Registry.hpp.
◆ get_storage()
Retrieves or creates the storage for component type T.
- Template Parameters
-
- Returns
- Pointer to the ComponentStorage for type T.
Lazily initializes storage on first access and resizes the storage array as needed to accommodate new component types.
Definition at line 44 of file Registry.hpp.
◆ has()
template<typename T>
| bool vex::Registry::has |
( |
Entity | entity | ) |
|
|
inline |
Checks if an entity has a component of type T.
- Template Parameters
-
| T | The component type to check for. |
- Parameters
-
| entity | The entity to check. |
- Returns
- True if the entity has the component, false otherwise.
Definition at line 137 of file Registry.hpp.
◆ on_create()
template<typename T>
| void vex::Registry::on_create |
( |
std::function< void(Entity, T &)> | cb | ) |
|
|
inline |
◆ on_destroy()
template<typename T>
| void vex::Registry::on_destroy |
( |
std::function< void(Entity, T &)> | cb | ) |
|
|
inline |
Registers a callback to be invoked when a component of type T is destroyed.
- Template Parameters
-
- Parameters
-
| cb | The callback function to register. |
Definition at line 152 of file Registry.hpp.
◆ remove()
template<typename T>
| void vex::Registry::remove |
( |
Entity | entity | ) |
|
|
inline |
Removes a component from an entity.
- Template Parameters
-
| T | The component type to remove. |
- Parameters
-
| entity | The entity to remove the component from. |
Definition at line 108 of file Registry.hpp.
◆ try_get()
template<typename T>
| T * vex::Registry::try_get |
( |
Entity | entity | ) |
|
|
inline |
Safely retrieves a component from an entity if it exists.
- Template Parameters
-
- Parameters
-
| entity | The entity to get the component from. |
- Returns
- Pointer to the component if it exists, nullptr otherwise.
Definition at line 127 of file Registry.hpp.
◆ try_get_storage_internal()
Attempts to retrieve the storage for component type T without creating it.
- Template Parameters
-
- Returns
- Pointer to the ComponentStorage if it exists, nullptr otherwise.
Used internally to check if a component type has been stored before.
Definition at line 61 of file Registry.hpp.
◆ m_availableEntities
| std::vector<Entity> vex::Registry::m_availableEntities |
|
private |
Pool of reusable entity IDs from destroyed entities.
Definition at line 32 of file Registry.hpp.
◆ m_componentStorages
Array of component storages indexed by component type ID.
Definition at line 36 of file Registry.hpp.
◆ m_nextEntity
| Entity vex::Registry::m_nextEntity = 0 |
|
private |
Counter for generating new entity IDs when the pool is empty.
Definition at line 34 of file Registry.hpp.
The documentation for this class was generated from the following file: