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 > |
|
Concrete ComponentTypeId bound to this entity's handle type. More... | |
template <typename TEntityManager> | |
| using | ComponentOpsRegistry_type = ComponentOpsRegistry< Handle_type > |
|
Concrete ComponentOpsRegistry bound to this entity's handle type. More... | |
template <typename TEntityManager> | |
| using | HierarchyComponent_type = HierarchyComponent< Handle_type > |
|
HierarchyComponent specialisation for this entity's handle type. More... | |
template <typename TEntityManager> | |
| using | ActiveComponent_type = Active< Handle_type > |
|
Active tag component specialisation for this entity's handle type. More... | |
template <typename TEntityManager> | |
| using | InactiveComponent_type = Inactive< Handle_type > |
|
Inactive tag component specialisation for this entity's handle type. More... | |
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 TComponent, typename TBuffer, typename ... Args> | |
| void | deferAdd (TBuffer &buffer, Args &&...args) |
|
Enqueues a deferred add-component command into buffer. More... | |
template <typename TComponent, typename TBuffer> | |
| void | deferRemove (TBuffer &buffer) |
|
Enqueues a deferred remove-component command into buffer. More... | |
template <typename TBuffer> | |
| void | deferSetActive (TBuffer &buffer) |
|
Enqueues a deferred activate-entity command into buffer. More... | |
template <typename TBuffer> | |
| void | deferSetInactive (TBuffer &buffer) |
|
Enqueues a deferred deactivate-entity command into buffer. More... | |
template <typename T, typename ... Args> | |
| T & | getOrAdd (Args &&...args) |
|
Returns existing component or creates a new one. More... | |
template <typename T, typename ... Args> | |
| T & | trackDirty (Args &&...args) |
|
Tracks the specified component which will be added if not already existing. More... | |
template <typename TComponent, typename TValue> | |
| void | setTrackedValue (TComponent *component, TValue value) |
|
Updates the component's value and marks the component type dirty. More... | |
template <typename TComponent, typename TValue> | |
| void | setTrackedValue (TComponent *component, const TValue &value) |
|
Updates the component's value and marks the component type dirty. 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 Functions Index
template <typename T> | |
| void | markDirty () |
|
Marks the specified component as dirty and registers the dirty set with the EntityManager. 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 86 of file Entity.ixx.
Public Member Typedefs
ActiveComponent_type
|
Active tag component specialisation for this entity's handle type.
Definition at line 123 of file Entity.ixx.
ComponentOpsRegistry_type
|
Concrete ComponentOpsRegistry bound to this entity's handle type.
Definition at line 119 of file Entity.ixx.
ComponentTypeId_type
|
Concrete ComponentTypeId bound to this entity's handle type.
Definition at line 117 of file Entity.ixx.
Handle_type
|
Definition at line 115 of file Entity.ixx.
HierarchyComponent_type
|
HierarchyComponent specialisation for this entity's handle type.
Definition at line 121 of file Entity.ixx.
InactiveComponent_type
|
Inactive tag component specialisation for this entity's handle type.
Definition at line 125 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 133 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 183 of file Entity.ixx.
References helios::ecs::ComponentOpsRegistry< THandle >::ops and helios::ecs::Entity< TEntityManager >::raw.
deferAdd()
| inline |
Enqueues a deferred add-component command into buffer.
The component is not attached immediately; the command is applied when the buffer is flushed by the EntityMutationManager.
- Template Parameters
-
TComponent Component type to add.
TBuffer Command buffer type. Its Handle_type must match this entity's.
Args Constructor argument types for TComponent.
- Parameters
-
buffer Target command buffer to enqueue into.
args Arguments forwarded to the TComponent constructor.
Definition at line 222 of file Entity.ixx.
deferRemove()
| inline |
Enqueues a deferred remove-component command into buffer.
The component is not detached immediately; the command is applied when the buffer is flushed by the EntityMutationManager.
- Template Parameters
-
TComponent Component type to remove.
TBuffer Command buffer type. Its Handle_type must match this entity's.
- Parameters
-
buffer Target command buffer to enqueue into.
Definition at line 238 of file Entity.ixx.
deferSetActive()
| inline |
Enqueues a deferred activate-entity command into buffer.
Activation is not applied immediately; the command is processed when the buffer is flushed by the EntityMutationManager.
- Template Parameters
-
TBuffer Command buffer type. Its Handle_type must match this entity's.
- Parameters
-
buffer Target command buffer to enqueue into.
Definition at line 253 of file Entity.ixx.
deferSetInactive()
| inline |
Enqueues a deferred deactivate-entity command into buffer.
Deactivation is not applied immediately; the command is processed when the buffer is flushed by the EntityMutationManager.
- Template Parameters
-
TBuffer Command buffer type. Its Handle_type must match this entity's.
- Parameters
-
buffer Target command buffer to enqueue into.
Definition at line 268 of file Entity.ixx.
disableComponent()
| inline |
Disables a specific component by type ID.
- Parameters
-
typeId The component type identifier.
Definition at line 428 of file Entity.ixx.
enableComponent()
| inline |
Enables a specific component by type ID.
- Parameters
-
typeId The component type identifier.
Definition at line 419 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 147 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 375 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 387 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 283 of file Entity.ixx.
handle()
| inline noexcept |
Returns the underlying entity handle.
- Returns
The EntityHandle for this Entity.
Definition at line 156 of file Entity.ixx.
handle()
| inline noexcept |
Returns the underlying entity handle (const).
- Returns
The EntityHandle for this Entity.
Definition at line 165 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 399 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 410 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 495 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 527 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 505 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 363 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 352 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
- Inactive will be marked as dirty component to indicate state change.
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
- Active will be marked as dirty component to indicate state change.
Does not call enable()/disable() on components.
- Parameters
-
active True to activate, false to deactivate.
- See Also
- See Also
HierarchyPropagationSystem
Definition at line 455 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.
setTrackedValue()
| inline |
Updates the component's value and marks the component type dirty.
- Template Parameters
-
TComponent The component type to update. Must be existing for this entity.
TValue The value type to set. Must be compatible with TComponent::Value_type.
- Parameters
-
component Pointer to the TComponent
value The value to update the component with.
Definition at line 319 of file Entity.ixx.
setTrackedValue()
| inline |
Updates the component's value and marks the component type dirty.
- Template Parameters
-
TComponent The component type to update. Must be existing for this entity.
TValue The value type to set. Must be compatible with TComponent::Value_type.
- Parameters
-
component Pointer to the TComponent
value The value to update the component with.
Definition at line 337 of file Entity.ixx.
trackDirty()
| inline |
Tracks the specified component which will be added if not already existing.
- Template Parameters
-
T The component type to track.
Args Constructor argument types.
- Parameters
-
args Arguments forwarded to the component constructor.
- Returns
Reference to the tracked component.
- See Also
markDirty
Definition at line 301 of file Entity.ixx.
Private Member Functions
markDirty()
| inline |
Marks the specified component as dirty and registers the dirty set with the EntityManager.
- Template Parameters
-
T The component type to mark as dirty.
Definition at line 104 of file Entity.ixx.
Private Member Attributes
entityHandle_
|
The underlying entity identifier.
Definition at line 91 of file Entity.ixx.
entityManager_
|
Non-owning pointer to the EntityManager.
Definition at line 96 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.