EntityManager Class Template
Manages entities and their associated components. More...
Declaration
Public Member Typedefs Index
template <typename THandle, typename TEntityRegistry, size_t TCapacity> | |
| using | EntityRegistry_type = TEntityRegistry |
template <typename THandle, typename TEntityRegistry, size_t TCapacity> | |
| using | Handle_type = THandle |
template <typename THandle, typename TEntityRegistry, size_t TCapacity> | |
| using | StrongId_type = Handle_type::StrongId_type |
template <typename THandle, typename TEntityRegistry, size_t TCapacity> | |
| using | ComponentTypeId_type = ComponentTypeId< Handle_type > |
template <typename THandle, typename TEntityRegistry, size_t TCapacity> | |
| using | ComponentOpsRegistry_type = ComponentOpsRegistry< Handle_type > |
Public Constructors Index
template <typename THandle, typename TEntityRegistry, size_t TCapacity> | |
| EntityManager (const EntityManager &)=delete | |
|
Non-copyable: copying an EntityManager is explicitly disabled. More... | |
template <typename THandle, typename TEntityRegistry, size_t TCapacity> | |
| EntityManager (EntityManager &&) noexcept=default | |
template <typename THandle, typename TEntityRegistry, size_t TCapacity> | |
| EntityManager (const size_t capacity=TCapacity) | |
|
Constructs an EntityManager with the given capacity. More... | |
template <typename THandle, typename TEntityRegistry, size_t TCapacity> | |
| EntityManager (EntityRegistry_type ®istry, const size_t capacity=TCapacity) | |
|
Constructs an EntityManager with an external registry. More... | |
Public Operators Index
template <typename THandle, typename TEntityRegistry, size_t TCapacity> | |
| EntityManager & | operator= (const EntityManager &)=delete |
template <typename THandle, typename TEntityRegistry, size_t TCapacity> | |
| EntityManager & | operator= (EntityManager &&) noexcept=default |
Public Member Functions Index
template <typename THandle, typename TEntityRegistry, size_t TCapacity> | |
| Handle_type | create (StrongId_type strongId=StrongId_type{}) |
|
Creates a new entity. More... | |
template <typename THandle, typename TEntityRegistry, size_t TCapacity> | |
| bool | isValid (const Handle_type handle) const noexcept |
|
Checks if an entity handle is valid. More... | |
template <typename THandle, typename TEntityRegistry, size_t TCapacity> | |
| bool | isValid (const EntityId entityId) const noexcept |
|
Checks if an entity ID is valid. More... | |
template <typename THandle, typename TEntityRegistry, size_t TCapacity> | |
| bool | destroy (const Handle_type handle) |
|
Destroys an entity and invalidates its handle. More... | |
template <typename T> | |
| T * | get (const Handle_type handle) const |
|
Retrieves a component for the given entity. More... | |
template <typename T> | |
| auto | getSparseSet () -> SparseSet< T > * |
template <typename T> | |
| auto | getSparseSet () const -> const SparseSet< T > * |
template <typename T> | |
| bool | has (const Handle_type handle) const |
|
Checks whether an entity has a specific component. More... | |
template <typename THandle, typename TEntityRegistry, size_t TCapacity> | |
| bool | has (const Handle_type handle, const ComponentTypeId_type typeId) const |
|
Checks whether an entity has a component by type ID. More... | |
template <typename THandle, typename TEntityRegistry, size_t TCapacity> | |
| void | enable (const Handle_type handle, const ComponentTypeId_type typeId) const |
|
Enables a component by type ID. More... | |
template <typename THandle, typename TEntityRegistry, size_t TCapacity> | |
| void | disable (const Handle_type handle, const ComponentTypeId_type typeId) const |
|
Disables a component by type ID. More... | |
template <typename THandle, typename TEntityRegistry, size_t TCapacity> | |
| void | enable (const Handle_type handle, const ComponentTypeId_type typeId, const bool enable) const |
|
Enables or disables a component by type ID. More... | |
template <typename T, typename... Args> | |
| T * | emplace (const Handle_type handle, Args &&...args) |
|
Constructs and attaches a component to an entity. More... | |
template <typename T, typename... Args> | |
| T * | emplaceOrGet (const Handle_type handle, Args &&...args) |
|
Returns existing component or creates a new one. More... | |
template <typename T> | |
| bool | remove (const Handle_type &handle) |
|
Removes a specific component from an entity. More... | |
template <typename TFunc> | |
| void | forEachComponentTypeId (const Handle_type handle, TFunc &&func) const |
|
Returns a span over all component type IDs attached to an entity. More... | |
template <typename THandle, typename TEntityRegistry, size_t TCapacity> | |
| void | clone (const Handle_type source, const Handle_type target) |
|
Clones all components from source entity to target entity. More... | |
template <typename THandle, typename TEntityRegistry, size_t TCapacity> | |
| void * | raw (const Handle_type handle, const ComponentTypeId_type typeId) const |
|
Returns raw void pointer to a component. More... | |
template <typename THandle, typename TEntityRegistry, size_t TCapacity> | |
| Handle_type | handle (const EntityId entityId) const |
|
Reconstructs an EntityHandle from an EntityId. More... | |
Private Member Attributes Index
template <typename THandle, typename TEntityRegistry, size_t TCapacity> | |
| std::vector< std::unique_ptr< SparseSetBase > > | components_ |
|
Component storage indexed by type ID. More... | |
template <typename THandle, typename TEntityRegistry, size_t TCapacity> | |
| EntityRegistry_type | registry_ |
|
Entity registry owned by this EntityManager. More... | |
template <typename THandle, typename TEntityRegistry, size_t TCapacity> | |
| const size_t | capacity_ |
|
Initial capacity for the underlying sparse sets. More... | |
Description
Manages entities and their associated components.
EntityManager provides a unified interface for creating entities and attaching/retrieving components. It delegates handle management to an EntityRegistry and stores component data in type-specific SparseSet containers.
Definition at line 73 of file EntityManager.ixx.
Public Member Typedefs
ComponentOpsRegistry_type
|
Definition at line 82 of file EntityManager.ixx.
ComponentTypeId_type
|
Definition at line 81 of file EntityManager.ixx.
EntityRegistry_type
|
Definition at line 78 of file EntityManager.ixx.
Handle_type
|
Definition at line 79 of file EntityManager.ixx.
StrongId_type
|
Definition at line 80 of file EntityManager.ixx.
Public Constructors
EntityManager()
| delete |
Non-copyable: copying an EntityManager is explicitly disabled.
Definition at line 87 of file EntityManager.ixx.
EntityManager()
| noexcept default |
Definition at line 90 of file EntityManager.ixx.
EntityManager()
| inline explicit |
Constructs an EntityManager with the given capacity.
Creates an internally owned EntityRegistry initialized with the specified capacity.
- Parameters
-
capacity Initial capacity for the registry and sparse sets. Defaults to TCapacity.
Definition at line 102 of file EntityManager.ixx.
EntityManager()
| inline explicit |
Constructs an EntityManager with an external registry.
- Parameters
-
registry External EntityRegistry to use for handle allocation.
capacity Initial capacity for the sparse sets. Defaults to TCapacity.
Definition at line 116 of file EntityManager.ixx.
Public Operators
operator=()
| delete |
Definition at line 88 of file EntityManager.ixx.
operator=()
| noexcept default |
Definition at line 91 of file EntityManager.ixx.
Public Member Functions
clone()
| inline |
Clones all components from source entity to target entity.
Iterates through all components on the source and copies them to the target using the registered clone function. Skips components that already exist on the target.
- Parameters
-
source The entity to clone from.
target The entity to clone to.
Definition at line 493 of file EntityManager.ixx.
References helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::forEachComponentTypeId, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::has, helios::ecs::ComponentOpsRegistry< THandle >::ops and helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::raw.
create()
| inline |
Creates a new entity.
Delegates to the underlying EntityRegistry to allocate a new handle.
- Returns
A valid EntityHandle for the newly created entity.
- See Also
Definition at line 131 of file EntityManager.ixx.
destroy()
| inline |
Destroys an entity and invalidates its handle.
Increments the entity's version in the registry, making all existing handles to this entity stale. Does automatically remove its components from storage.
- Parameters
-
handle The handle of the entity to destroy.
- Returns
true if the entity was destroyed, false if already invalid.
Definition at line 168 of file EntityManager.ixx.
References helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::handle, helios::ecs::types::ComponentOps::onRemove, helios::ecs::ComponentOpsRegistry< THandle >::ops and helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::raw.
disable()
| inline |
Disables a component by type ID.
Calls the component's disable() method if registered.
- Parameters
-
handle The entity whose component to disable.
typeId The component type identifier.
Definition at line 324 of file EntityManager.ixx.
References helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::enable and helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::handle.
emplace()
| inline |
Constructs and attaches a component to an entity.
If the component type has not been registered yet, a new SparseSet is created. The component is constructed in-place with the provided arguments. Returns nullptr if the component already exists or if the handle was invalid.
- Template Parameters
-
T The component type to emplace.
Args Constructor argument types.
- Parameters
-
handle The entity to attach the component to.
args Arguments forwarded to the component constructor.
- Returns
Pointer to the newly created component, or nullptr if the handle is invalid.
Definition at line 372 of file EntityManager.ixx.
References helios::ecs::SparseSet< T >::emplace and helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::handle.
emplaceOrGet()
| inline |
Returns existing component or creates a new one.
- Template Parameters
-
T The component type.
Args Constructor argument types.
- Parameters
-
handle The entity.
args Arguments forwarded to the constructor if creating.
- Returns
Pointer to the existing or newly created component, or nullptr if the handle is invalid.
Definition at line 412 of file EntityManager.ixx.
References helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::handle and helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::raw.
enable()
| inline |
Enables a component by type ID.
Calls the component's enable() method if registered.
- Parameters
-
handle The entity whose component to enable.
typeId The component type identifier.
Definition at line 312 of file EntityManager.ixx.
References helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::enable and helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::handle.
Referenced by helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::disable, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::enable and helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::enable.
enable()
| inline |
Enables or disables a component by type ID.
- Parameters
-
handle The entity whose component to modify.
typeId The component type identifier.
enable true to enable, false to disable.
Definition at line 335 of file EntityManager.ixx.
References helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::enable, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::handle, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::has, helios::ecs::ComponentOpsRegistry< THandle >::ops and helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::raw.
forEachComponentTypeId()
| inline |
Returns a span over all component type IDs attached to an entity.
- Parameters
-
handle The entity to query.
Definition at line 471 of file EntityManager.ixx.
Reference helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::handle.
Referenced by helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::clone.
get()
| inline |
Retrieves a component for the given entity.
- Template Parameters
-
T The component type to retrieve.
- Parameters
-
handle The entity whose component to retrieve.
- Returns
Pointer to the component, or nullptr if the entity is invalid or does not have the requested component.
Definition at line 205 of file EntityManager.ixx.
References helios::ecs::SparseSet< T >::get and helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::handle.
getSparseSet()
| inline |
Returns the SparseSet for a component type.
- Template Parameters
-
T The component type.
- Returns
Pointer to the SparseSet, or nullptr if the type has no storage.
Definition at line 226 of file EntityManager.ixx.
getSparseSet()
| inline |
Returns the SparseSet for a component type (const).
- Template Parameters
-
T The component type.
- Returns
Const pointer to the SparseSet, or nullptr if the type has no storage.
Definition at line 245 of file EntityManager.ixx.
handle()
| inline |
Reconstructs an EntityHandle from an EntityId.
- Parameters
-
entityId The entity ID.
- Returns
EntityHandle with current version from the registry.
Definition at line 538 of file EntityManager.ixx.
Referenced by helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::destroy, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::disable, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::emplace, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::emplaceOrGet, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::enable, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::enable, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::forEachComponentTypeId, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::get, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::has, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::has, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::isValid, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::isValid, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::raw and helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::remove.
has()
| inline |
Checks whether an entity has a specific component.
- Template Parameters
-
T The component type to check for.
- Parameters
-
handle The entity to query.
- Returns
true if the entity has the component, false if the handle is invalid or the component is not attached.
Definition at line 267 of file EntityManager.ixx.
Reference helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::handle.
Referenced by helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::clone, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::enable and helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::raw.
has()
| inline |
Checks whether an entity has a component by type ID.
- Parameters
-
handle The entity to query.
typeId The component type identifier.
- Returns
true if the entity has the component, false otherwise.
Definition at line 289 of file EntityManager.ixx.
References helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::handle and helios::ecs::types::ComponentTypeId< THandle >::value.
isValid()
| inline noexcept |
Checks if an entity handle is valid.
- Parameters
-
handle The handle to validate.
- Returns
true if the handle refers to a living entity.
Definition at line 142 of file EntityManager.ixx.
Reference helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::handle.
isValid()
| inline noexcept |
Checks if an entity ID is valid.
- Parameters
-
entityId The entity ID to validate.
- Returns
true if the entity ID refers to a living entity.
Definition at line 153 of file EntityManager.ixx.
Reference helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::handle.
raw()
| inline |
Returns raw void pointer to a component.
- Parameters
-
handle The entity.
typeId The component type identifier.
- Returns
Raw pointer to the component, or nullptr if not found.
Definition at line 523 of file EntityManager.ixx.
References helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::handle, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::has and helios::ecs::types::ComponentTypeId< THandle >::value.
Referenced by helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::clone, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::destroy, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::emplaceOrGet, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::enable and helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::remove.
remove()
| inline |
Removes a specific component from an entity.
Unlike destroy(), this only removes a single component type while keeping the entity and other components intact.
- Template Parameters
-
T The component type to remove.
- Parameters
-
handle The entity whose component to remove.
- Returns
true if the component was removed, false if the handle was invalid, the component was not attached, or removal was blocked by onRemove.
- See Also
- See Also
Definition at line 445 of file EntityManager.ixx.
References helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::handle, helios::ecs::ComponentOpsRegistry< THandle >::ops and helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::raw.
Private Member Attributes
capacity_
|
Initial capacity for the underlying sparse sets.
Definition at line 558 of file EntityManager.ixx.
components_
|
Component storage indexed by type ID.
Definition at line 548 of file EntityManager.ixx.
registry_
|
Entity registry owned by this EntityManager.
Definition at line 553 of file EntityManager.ixx.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.