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 | InactiveComponent_type = components::Inactive< 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 TEntityManager> | |
| auto | componentTypeIds () const -> std::generator< ComponentTypeId_type > |
|
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.
## Size and Copy Semantics
Entity is only 16 bytes (8 bytes EntityHandle + 8 bytes pointer) and should be **passed by value**, not by reference:
```cpp // Correct - pass by value void processEntity(Entity entity) { ... }
// Unnecessary - reference adds indirection void processEntity(Entity& entity); // Avoid void processEntity(const Entity& entity); // Avoid ```
## Hierarchy Integration
When a Entity has a `HierarchyComponent`, activation changes trigger hierarchy propagation. Calling `setActive()` marks the hierarchy as dirty, and `HierarchyPropagationSystem` propagates the state to all descendants.
## Usage
```cpp auto player = gameWorld.addEntity();
// Add components player.add<TransformComponent>(position); player.add<HealthComponent>(100.0f);
// Query and access if (player.has<HealthComponent>()) { player.get<HealthComponent>()->takeDamage(10.0f); }
// Activation state (propagates to children if HierarchyComponent present) player.setActive(false); // Calls onDeactivate() on components ```
- Template Parameters
-
TEntityManager The entity manager type providing handle and component storage. Must expose `Handle_type` and component operations.
- See Also
- See Also
- See Also
GameWorld
- See Also
HierarchyComponent
- See Also
HierarchyPropagationSystem
Definition at line 83 of file Entity.ixx.
Public Member Typedefs
ActiveComponent_type
|
Definition at line 103 of file Entity.ixx.
ComponentOpsRegistry_type
|
Definition at line 100 of file Entity.ixx.
ComponentTypeId_type
|
Definition at line 99 of file Entity.ixx.
Handle_type
|
Definition at line 98 of file Entity.ixx.
HierarchyComponent_type
|
Definition at line 101 of file Entity.ixx.
InactiveComponent_type
|
Definition at line 102 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 111 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 161 of file Entity.ixx.
References helios::ecs::Entity< TEntityManager >::has, helios::ecs::ComponentOpsRegistry< Handle_type >::ops and helios::ecs::Entity< TEntityManager >::raw.
Referenced by helios::ecs::Entity< TEntityManager >::getOrAdd.
componentTypeIds()
| inline nodiscard |
Returns a generator over all component type IDs attached to this entity.
- Returns
Generator yielding ComponentTypeId for each attached component.
Definition at line 125 of file Entity.ixx.
Referenced by helios::ecs::Entity< TEntityManager >::onAcquire, helios::ecs::Entity< TEntityManager >::onRelease and helios::ecs::Entity< TEntityManager >::setActive.
disableComponent()
| inline |
Disables a specific component by type ID.
- Parameters
-
typeId The component type identifier.
Definition at line 288 of file Entity.ixx.
enableComponent()
| inline |
Enables a specific component by type ID.
- Parameters
-
typeId The component type identifier.
Definition at line 279 of file Entity.ixx.
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 235 of file Entity.ixx.
Reference helios::ecs::Entity< TEntityManager >::get.
Referenced by helios::ecs::Entity< TEntityManager >::get, helios::ecs::Entity< TEntityManager >::get, helios::ecs::Entity< TEntityManager >::getOrAdd and helios::ecs::Entity< TEntityManager >::setActive.
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 247 of file Entity.ixx.
Reference helios::ecs::Entity< TEntityManager >::get.
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 197 of file Entity.ixx.
References helios::ecs::Entity< TEntityManager >::add, helios::ecs::Entity< TEntityManager >::get and helios::ecs::Entity< TEntityManager >::has.
handle()
| inline nodiscard noexcept |
Returns the underlying entity handle.
- Returns
The EntityHandle for this Entity.
Definition at line 134 of file Entity.ixx.
handle()
| inline nodiscard noexcept |
Returns the underlying entity handle (const).
- Returns
The EntityHandle for this Entity.
Definition at line 143 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 259 of file Entity.ixx.
Reference helios::ecs::Entity< TEntityManager >::has.
Referenced by helios::ecs::Entity< TEntityManager >::add, helios::ecs::Entity< TEntityManager >::getOrAdd, helios::ecs::Entity< TEntityManager >::has, helios::ecs::Entity< TEntityManager >::has, helios::ecs::Entity< TEntityManager >::isActive and helios::ecs::Entity< TEntityManager >::setActive.
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 270 of file Entity.ixx.
Reference helios::ecs::Entity< TEntityManager >::has.
isActive()
| inline nodiscard |
Returns whether this Entity is active.
- Returns
True if the entity has the Active tag component.
Definition at line 356 of file Entity.ixx.
Reference helios::ecs::Entity< TEntityManager >::has.
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 383 of file Entity.ixx.
References helios::ecs::Entity< TEntityManager >::componentTypeIds, helios::ecs::ComponentOpsRegistry< Handle_type >::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 366 of file Entity.ixx.
References helios::ecs::Entity< TEntityManager >::componentTypeIds, helios::ecs::ComponentOpsRegistry< Handle_type >::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 223 of file Entity.ixx.
Reference helios::ecs::Entity< TEntityManager >::raw.
Referenced by helios::ecs::Entity< TEntityManager >::add, helios::ecs::Entity< TEntityManager >::onAcquire, helios::ecs::Entity< TEntityManager >::onRelease, helios::ecs::Entity< TEntityManager >::raw 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 212 of file Entity.ixx.
Reference helios::ecs::Entity< TEntityManager >::remove.
Referenced by helios::ecs::Entity< TEntityManager >::remove and helios::ecs::Entity< TEntityManager >::setActive.
setActive()
| inline |
Sets the activation state of this Entity.
When deactivated:
- An `Inactive` tag component is added
- 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 314 of file Entity.ixx.
References helios::ecs::Entity< TEntityManager >::componentTypeIds, helios::ecs::Entity< TEntityManager >::get, helios::ecs::Entity< TEntityManager >::has, helios::ecs::Entity< TEntityManager >::isActive, helios::ecs::ComponentOpsRegistry< Handle_type >::ops, helios::ecs::Entity< TEntityManager >::raw and helios::ecs::Entity< TEntityManager >::remove.
Private Member Attributes
entityHandle_
|
The underlying entity identifier.
Definition at line 88 of file Entity.ixx.
entityManager_
|
Non-owning pointer to the EntityManager.
Definition at line 93 of file Entity.ixx.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.