GameObject Class
Lightweight facade for entity component manipulation. More...
Declaration
Public Constructors Index
| GameObject (const helios::engine::ecs::EntityHandle entityHandle, helios::engine::ecs::EntityManager *entityManager) noexcept | |
|
Constructs a GameObject wrapper. More... | |
Public Member Functions Index
| std::generator< helios::engine::core::data::ComponentTypeId > | componentTypeIds () const |
|
Returns a generator over all component type IDs attached to this entity. More... | |
| helios::engine::ecs::EntityHandle | entityHandle () noexcept |
|
Returns the underlying entity handle. More... | |
| helios::engine::ecs::EntityHandle | entityHandle () 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... | |
| void * | raw (const helios::engine::core::data::ComponentTypeId 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 () |
|
Checks if this entity has a specific component type. More... | |
| bool | has (helios::engine::core::data::ComponentTypeId typeId) |
|
Checks if this entity has a component by type ID. More... | |
| void | enableComponent (const helios::engine::core::data::ComponentTypeId typeId) |
|
Enables a specific component by type ID. More... | |
| void | disableComponent (const helios::engine::core::data::ComponentTypeId typeId) |
|
Disables a specific component by type ID. More... | |
| void | setActive (const bool active) |
|
Sets the activation state of this GameObject. More... | |
| bool | isActive () const |
|
Returns whether this GameObject is active. More... | |
| void | onRelease () |
|
Notifies all components that the entity is being released to a pool. More... | |
| void | onAcquire () |
|
Notifies all components that the entity is being acquired from a pool. More... | |
Private Member Attributes Index
| helios::engine::ecs::EntityHandle | entityHandle_ {0,0} |
|
The underlying entity identifier. More... | |
| helios::engine::ecs::EntityManager * | entityManager_ |
|
Non-owning pointer to the EntityManager. More... | |
Description
Lightweight facade for entity component manipulation.
`GameObject` 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
GameObject 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(GameObject entity) { ... }
// Unnecessary - reference adds indirection void processEntity(GameObject& entity); // Avoid void processEntity(const GameObject& entity); // Avoid ```
## Hierarchy Integration
When a GameObject 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.addGameObject();
// 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 ```
- See Also
- See Also
- See Also
GameWorld
- See Also
HierarchyComponent
- See Also
HierarchyPropagationSystem
Definition at line 85 of file GameObject.ixx.
Public Constructors
GameObject()
| inline explicit noexcept |
Constructs a GameObject wrapper.
- Parameters
-
entityHandle The entity handle to wrap.
entityManager Pointer to the EntityManager. Must not be null.
Definition at line 106 of file GameObject.ixx.
Reference entityHandle.
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 156 of file GameObject.ixx.
References helios::engine::core::data::ComponentTypeId::id, helios::engine::ecs::ComponentOpsRegistry::ops and raw.
Referenced by 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 120 of file GameObject.ixx.
Referenced by helios::engine::runtime::spawn::behavior::initializers::DelayedComponentEnablerInitializer< ComponentTypes >::initialize, onAcquire, onRelease and setActive.
disableComponent()
| inline |
Disables a specific component by type ID.
- Parameters
-
typeId The component type identifier.
Definition at line 283 of file GameObject.ixx.
Referenced by helios::engine::mechanics::lifecycle::components::DelayedComponentEnabler::defer.
enableComponent()
| inline |
Enables a specific component by type ID.
- Parameters
-
typeId The component type identifier.
Definition at line 274 of file GameObject.ixx.
entityHandle()
| inline nodiscard noexcept |
Returns the underlying entity handle.
- Returns
The EntityHandle for this GameObject.
Definition at line 129 of file GameObject.ixx.
Referenced by helios::engine::modules::ui::widgets::components::MenuComponent::addMenuItem, helios::engine::runtime::world::GameWorld::clone, GameObject, helios::engine::modules::ui::widgets::components::MenuComponent::insert and helios::engine::modules::physics::collision::systems::GridCollisionDetectionSystem::solveCell.
entityHandle()
| inline nodiscard noexcept |
Returns the underlying entity handle (const).
- Returns
The EntityHandle for this GameObject.
Definition at line 138 of file GameObject.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 230 of file GameObject.ixx.
Referenced by helios::engine::runtime::spawn::behavior::initializers::DelayedComponentEnablerInitializer< ComponentTypes >::initialize, helios::engine::runtime::spawn::behavior::initializers::EmitterInitializer::initialize and helios::engine::runtime::spawn::behavior::initializers::RandomDirectionInitializer::initialize.
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 242 of file GameObject.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 192 of file GameObject.ixx.
Reference add.
has()
| inline |
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 254 of file GameObject.ixx.
Referenced by helios::engine::mechanics::lifecycle::components::DelayedComponentEnabler::defer.
has()
| inline |
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 265 of file GameObject.ixx.
isActive()
| inline nodiscard |
Returns whether this GameObject is active.
- Returns
True if the entity has the Active tag component.
Definition at line 351 of file GameObject.ixx.
Referenced by 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 378 of file GameObject.ixx.
References componentTypeIds, helios::engine::ecs::ComponentOpsRegistry::ops and 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 361 of file GameObject.ixx.
References componentTypeIds, helios::engine::ecs::ComponentOpsRegistry::ops and 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 218 of file GameObject.ixx.
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 207 of file GameObject.ixx.
setActive()
| inline |
Sets the activation state of this GameObject.
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
HierarchyComponent
- See Also
HierarchyPropagationSystem
Definition at line 309 of file GameObject.ixx.
References componentTypeIds, isActive, helios::engine::ecs::ComponentOpsRegistry::ops and raw.
Private Member Attributes
entityHandle_
|
The underlying entity identifier.
Definition at line 90 of file GameObject.ixx.
entityManager_
|
Non-owning pointer to the EntityManager.
Definition at line 95 of file GameObject.ixx.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.