Entity Class Template
Lightweight facade for entity component manipulation. More...
Declaration
Public Member Typedefs Index
template <typename TEntityManager> | |
| using | Handle_type = TEntityManager::Handle_type |
template <typename TEntityManager> | |
| using | ComponentTypeId_type = ComponentTypeId< Handle_type > |
template <typename TEntityManager> | |
| using | ComponentOpsRegistry_type = ComponentOpsRegistry< Handle_type > |
template <typename TEntityManager> | |
| using | HierarchyComponent_type = components::HierarchyComponent< Handle_type > |
template <typename TEntityManager> | |
| using | ActiveComponent_type = components::Active< Handle_type > |
Public Constructors Index
template <typename TEntityManager> | |
| Entity (const Handle_type entityHandle, TEntityManager *entityManager) noexcept | |
Public Member Functions Index
template <typename TFunc> | |
| void | forEachComponentTypeId (TFunc &&func) const |
|
Returns a generator over all component type IDs attached to this entity. More... | |
template <typename TEntityManager> | |
| Handle_type | handle () noexcept |
|
Returns the underlying entity handle. More... | |
template <typename TEntityManager> | |
| Handle_type | handle () const noexcept |
|
Returns the underlying entity handle (const). More... | |
template <typename T, typename ... Args> | |
| T & | add (Args &&...args) |
|
Constructs and attaches a component to this entity. More... | |
template <typename T, typename ... Args> | |
| T & | getOrAdd (Args &&...args) |
|
Returns existing component or creates a new one. More... | |
template <typename T> | |
| bool | remove () |
|
Removes a component from this entity. More... | |
template <typename TEntityManager> | |
| void * | raw (const ComponentTypeId_type typeId) |
|
Returns raw pointer to component by type ID. More... | |
template <typename T> | |
| T * | get () |
|
Returns pointer to a component. More... | |
template <typename T> | |
| const T * | get () const |
|
Returns const pointer to a component. More... | |
template <typename T> | |
| bool | has () const noexcept |
|
Checks if this entity has a specific component type. More... | |
template <typename TEntityManager> | |
| bool | has (ComponentTypeId_type typeId) const noexcept |
|
Checks if this entity has a component by type ID. More... | |
template <typename TEntityManager> | |
| void | enableComponent (const ComponentTypeId_type typeId) |
|
Enables a specific component by type ID. More... | |
template <typename TEntityManager> | |
| void | disableComponent (const ComponentTypeId_type typeId) |
|
Disables a specific component by type ID. More... | |
template <typename TEntityManager> | |
| void | setActive (const bool active) |
template <typename TEntityManager> | |
| bool | isActive () const |
template <typename TEntityManager> | |
| void | onRelease () |
|
Notifies all components that the entity is being released to a pool. More... | |
template <typename TEntityManager> | |
| void | onAcquire () |
|
Notifies all components that the entity is being acquired from a pool. More... | |
Private Member Attributes Index
template <typename TEntityManager> | |
| TEntityManager::Handle_type | entityHandle_ {0,0} |
|
The underlying entity identifier. More... | |
template <typename TEntityManager> | |
| TEntityManager * | entityManager_ |
|
Non-owning pointer to the EntityManager. More... | |
Description
Lightweight facade for entity component manipulation.
Entity provides a type-safe, convenient interface for working with entities and their components. It wraps an EntityHandle and a pointer to the EntityManager, delegating all operations.
Definition at line 82 of file Entity.ixx.
Public Member Typedefs
ActiveComponent_type
|
Definition at line 101 of file Entity.ixx.
ComponentOpsRegistry_type
|
Definition at line 99 of file Entity.ixx.
ComponentTypeId_type
|
Definition at line 98 of file Entity.ixx.
Handle_type
|
Definition at line 97 of file Entity.ixx.
HierarchyComponent_type
|
Definition at line 100 of file Entity.ixx.
Public Constructors
Entity()
| inline explicit noexcept |
Constructs a Entity wrapper.
- Parameters
-
entityHandle The entity handle to wrap.
entityManager Pointer to the EntityManager. Must not be null.
Definition at line 109 of file Entity.ixx.
Public Member Functions
add()
| inline |
Constructs and attaches a component to this entity.
If the entity is active, calls onActivate() on the new component. If inactive, calls onDeactivate().
- Template Parameters
-
T The component type to add.
Args Constructor argument types.
- Parameters
-
args Arguments forwarded to the component constructor.
- Returns
Reference to the newly created component.
Definition at line 159 of file Entity.ixx.
References helios::ecs::ComponentOpsRegistry< THandle >::ops and helios::ecs::Entity< TEntityManager >::raw.
disableComponent()
| inline |
Disables a specific component by type ID.
- Parameters
-
typeId The component type identifier.
Definition at line 286 of file Entity.ixx.
enableComponent()
| inline |
Enables a specific component by type ID.
- Parameters
-
typeId The component type identifier.
Definition at line 277 of file Entity.ixx.
forEachComponentTypeId()
| inline |
Returns a generator over all component type IDs attached to this entity.
- Returns
Generator yielding ComponentTypeId for each attached component.
Definition at line 123 of file Entity.ixx.
Referenced by helios::ecs::Entity< TEntityManager >::onAcquire, helios::ecs::Entity< TEntityManager >::onRelease and helios::ecs::Entity< TEntityManager >::setActive.
get()
| inline |
Returns pointer to a component.
- Template Parameters
-
T The component type.
- Returns
Pointer to the component, or nullptr if not attached.
Definition at line 233 of file Entity.ixx.
get()
| inline |
Returns const pointer to a component.
- Template Parameters
-
T The component type.
- Returns
Const pointer to the component, or nullptr if not attached.
Definition at line 245 of file Entity.ixx.
getOrAdd()
| inline |
Returns existing component or creates a new one.
- Template Parameters
-
T The component type.
Args Constructor argument types.
- Parameters
-
args Arguments forwarded to the constructor if creating.
- Returns
Reference to the existing or newly created component.
Definition at line 195 of file Entity.ixx.
handle()
| inline noexcept |
Returns the underlying entity handle.
- Returns
The EntityHandle for this Entity.
Definition at line 132 of file Entity.ixx.
handle()
| inline noexcept |
Returns the underlying entity handle (const).
- Returns
The EntityHandle for this Entity.
Definition at line 141 of file Entity.ixx.
has()
| inline noexcept |
Checks if this entity has a specific component type.
- Template Parameters
-
T The component type to check.
- Returns
True if the component is attached, false otherwise.
Definition at line 257 of file Entity.ixx.
has()
| inline noexcept |
Checks if this entity has a component by type ID.
- Parameters
-
typeId The component type identifier.
- Returns
True if the component is attached, false otherwise.
Definition at line 268 of file Entity.ixx.
isActive()
| inline |
Returns whether this Entity is active.
- Returns
True if the entity has the Active tag component.
Definition at line 353 of file Entity.ixx.
Referenced by helios::ecs::Entity< TEntityManager >::setActive.
onAcquire()
| inline |
Notifies all components that the entity is being acquired from a pool.
Iterates through all attached components and calls onAcquire() on those that implement it.
Definition at line 385 of file Entity.ixx.
References helios::ecs::Entity< TEntityManager >::forEachComponentTypeId, helios::ecs::ComponentOpsRegistry< THandle >::ops and helios::ecs::Entity< TEntityManager >::raw.
onRelease()
| inline |
Notifies all components that the entity is being released to a pool.
Iterates through all attached components and calls onRelease() on those that implement it.
Definition at line 363 of file Entity.ixx.
References helios::ecs::Entity< TEntityManager >::forEachComponentTypeId, helios::ecs::ComponentOpsRegistry< THandle >::ops and helios::ecs::Entity< TEntityManager >::raw.
raw()
| inline |
Returns raw pointer to component by type ID.
- Parameters
-
typeId The component type identifier.
- Returns
Raw void pointer to the component, or nullptr if not found.
Definition at line 221 of file Entity.ixx.
Referenced by helios::ecs::Entity< TEntityManager >::add, helios::ecs::Entity< TEntityManager >::onAcquire, helios::ecs::Entity< TEntityManager >::onRelease and helios::ecs::Entity< TEntityManager >::setActive.
remove()
| inline |
Removes a component from this entity.
- Template Parameters
-
T The component type to remove.
- Returns
True if the component was removed, false if not present.
Definition at line 210 of file Entity.ixx.
setActive()
| inline |
Sets the activation state of this Entity.
When deactivated:
- The Active tag component is removed
- onDeactivate() is called on components that support it
- If a HierarchyComponent is present, it is marked dirty for propagation
When activated:
- The Inactive tag component is removed
- An Active tag component is added
- onActivate() is called on components that support it
- If a HierarchyComponent is present, it is marked dirty for propagation
Does not call enable()/disable() on components.
- Parameters
-
active True to activate, false to deactivate.
- See Also
- See Also
HierarchyPropagationSystem
Definition at line 311 of file Entity.ixx.
References helios::ecs::Entity< TEntityManager >::forEachComponentTypeId, helios::ecs::Entity< TEntityManager >::isActive, helios::ecs::ComponentOpsRegistry< THandle >::ops and helios::ecs::Entity< TEntityManager >::raw.
Private Member Attributes
entityHandle_
|
The underlying entity identifier.
Definition at line 87 of file Entity.ixx.
entityManager_
|
Non-owning pointer to the EntityManager.
Definition at line 92 of file Entity.ixx.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.