Skip to main content

TypedHandleWorld Class Template

A multi-domain entity world that dispatches operations to the correct `EntityManager` based on the handle type. More...

Declaration

template <typename... TEntityManagers> class helios::ecs::TypedHandleWorld<TEntityManagers> { ... }

Public Member Functions Index

template <typename THandle>
auto &entityManager ()

Returns a reference to the EntityManager that owns handles of type `THandle`. More...

template <typename THandle>
const auto &entityManager () const

Returns a const reference to the EntityManager that owns handles of type `THandle`. More...

template <typename THandle>
autoaddEntity (THandle::StrongId_type strongId)

Creates a new entity in the domain identified by `THandle`. More...

template <typename THandle>
autoaddEntity ()

Creates a new entity with an auto-generated id. More...

template <typename THandle>
booldestroy (THandle handle)

Destroys an entity identified by its handle. More...

template <typename THandle>
autofindEntity (THandle handle)

Looks up an existing entity by its handle. More...

template <typename THandle>
autocloneEntity (THandle source) noexcept

Clones all components from a source entity into a new entity. More...

template <typename THandle, typename ... TComponents>
autoview ()

Creates a `View` for iterating entities with specific components. More...

Private Member Attributes Index

template <typename... TEntityManagers>
std::tuple< TEntityManagers... >entityManagers_

Description

A multi-domain entity world that dispatches operations to the correct `EntityManager` based on the handle type.

`TypedHandleWorld` holds a tuple of `EntityManager` instances, each responsible for a different entity domain (identified by its handle type). All public methods accept a handle-type template argument and resolve the matching manager at **compile time** via `HandleToManager`.

This enables a single world object to manage entities from multiple independent registries — for example game entities, UI entities, and audio entities — without runtime dispatch overhead.

## Domain-Specific Entity Managers

Each `TEntityManagers` template argument is a fully configured `EntityManager<THandle, TEntityRegistry, TCapacity>` specialisation. The handle type (`THandle`) serves as the **domain key**: calling `addEntity<MyHandle>()` automatically selects the manager whose `Handle_type` is `MyHandle`.

## Usage

```cpp // Define domain-specific handle types using GameHandle = EntityHandle<GameStrongId>; using UiHandle = EntityHandle<UiStrongId>;

// Configure managers using GameEM = EntityManager<GameHandle, GameRegistry, 4096>; using UiEM = EntityManager<UiHandle, UiRegistry, 512>;

// Create the world TypedHandleWorld<GameEM, UiEM> world;

// Add entities — handle type selects the manager auto player = world.addEntity<GameHandle>(); auto button = world.addEntity<UiHandle>();

// Query a specific domain for (auto [entity, transform, velocity] : world.view<GameHandle, TransformComponent, VelocityComponent>()) { // ... } ```

## Template Parameters

Template Parameters
TEntityManagers

One or more `EntityManager` specialisations. Each must expose a unique `Handle_type` typedef.

See Also

Entity

See Also

EntityManager

See Also

View

See Also

HandleToManager

Definition at line 121 of file TypedHandleWorld.ixx.

Public Member Functions

addEntity()

template <typename THandle>
auto helios::ecs::TypedHandleWorld< TEntityManagers >::addEntity (THandle::StrongId_type strongId)
inline nodiscard

Creates a new entity in the domain identified by `THandle`.

Delegates to the matching `EntityManager::create()` and wraps the result in an `Entity` facade.

Template Parameters
THandle

The handle type identifying the target domain.

Returns

An `Entity` wrapping the newly created handle.

Definition at line 171 of file TypedHandleWorld.ixx.

171 [[nodiscard]] auto addEntity(THandle::StrongId_type strongId) {
172 auto& em = entityManager<THandle>();
173
174 auto handle = em.create(strongId);
175
176 return Entity{handle, &em};
177 }

Reference helios::ecs::TypedHandleWorld< TEntityManagers >::entityManager.

addEntity()

template <typename THandle>
auto helios::ecs::TypedHandleWorld< TEntityManagers >::addEntity ()
inline nodiscard

Creates a new entity with an auto-generated id.

Template Parameters
THandle

The handle type identifying the target domain.

Returns

An `Entity` wrapping the newly created handle.

Definition at line 187 of file TypedHandleWorld.ixx.

187 [[nodiscard]] auto addEntity() {
188 auto& em = entityManager<THandle>();
189
190 auto handle = em.create();
191
192 return Entity{handle, &em};
193 }

Reference helios::ecs::TypedHandleWorld< TEntityManagers >::entityManager.

Referenced by helios::ecs::TypedHandleWorld< TEntityManagers >::cloneEntity.

cloneEntity()

template <typename THandle>
auto helios::ecs::TypedHandleWorld< TEntityManagers >::cloneEntity (THandle source)
inline nodiscard noexcept

Clones all components from a source entity into a new entity.

Creates a new entity in the same domain and copies every component attached to `source` into it via `EntityManager::clone()`.

Template Parameters
THandle

The handle type identifying the target domain.

Parameters
source

The handle of the entity to clone.

Returns

An `Entity` wrapping the newly created clone.

Definition at line 253 of file TypedHandleWorld.ixx.

253 [[nodiscard]] auto cloneEntity(THandle source) noexcept {
254 auto& em = entityManager<THandle>();
255
256 auto entity = addEntity<THandle>();
257
258 em.clone(source, entity.handle());
259
260 return entity;
261 }

References helios::ecs::TypedHandleWorld< TEntityManagers >::addEntity and helios::ecs::TypedHandleWorld< TEntityManagers >::entityManager.

destroy()

template <typename THandle>
bool helios::ecs::TypedHandleWorld< TEntityManagers >::destroy (THandle handle)
inline

Destroys an entity identified by its handle.

Delegates to the owning `EntityManager::destroy()`. The handle's version is incremented, making all existing copies stale.

Template Parameters
THandle

The handle type identifying the target domain.

Parameters
handle

The handle of the entity to destroy.

Returns

True if the entity was valid and successfully destroyed.

Definition at line 208 of file TypedHandleWorld.ixx.

208 bool destroy(THandle handle) {
209 auto& em = entityManager<THandle>();
210
211 return em.destroy(handle);
212 }

Reference helios::ecs::TypedHandleWorld< TEntityManagers >::entityManager.

entityManager()

template <typename THandle>
auto & helios::ecs::TypedHandleWorld< TEntityManagers >::entityManager ()
inline

Returns a reference to the EntityManager that owns handles of type `THandle`.

Uses `HandleToManager` to resolve the tuple index at compile time. A `static_assert` fires if no manager matches.

Template Parameters
THandle

The handle type identifying the target domain.

Returns

Mutable reference to the matching EntityManager.

Definition at line 140 of file TypedHandleWorld.ixx.

140 auto& entityManager() {
141 constexpr size_t idx = HandleToManager<THandle, TEntityManagers...>::value;
142 return std::get<idx>(entityManagers_);
143 }

Referenced by helios::ecs::TypedHandleWorld< TEntityManagers >::addEntity, helios::ecs::TypedHandleWorld< TEntityManagers >::addEntity, helios::ecs::TypedHandleWorld< TEntityManagers >::cloneEntity, helios::ecs::TypedHandleWorld< TEntityManagers >::destroy, helios::ecs::TypedHandleWorld< TEntityManagers >::findEntity and helios::ecs::TypedHandleWorld< TEntityManagers >::view.

entityManager()

template <typename THandle>
const auto & helios::ecs::TypedHandleWorld< TEntityManagers >::entityManager ()
inline

Returns a const reference to the EntityManager that owns handles of type `THandle`.

Template Parameters
THandle

The handle type identifying the target domain.

Returns

Const reference to the matching EntityManager.

Definition at line 154 of file TypedHandleWorld.ixx.

154 const auto& entityManager() const {
155 constexpr size_t idx = HandleToManager<THandle, TEntityManagers...>::value;
156 return std::get<idx>(entityManagers_);
157 }

findEntity()

template <typename THandle>
auto helios::ecs::TypedHandleWorld< TEntityManagers >::findEntity (THandle handle)
inline nodiscard

Looks up an existing entity by its handle.

Validates the handle via the owning `EntityManager`. If valid, returns an `Entity` facade; otherwise returns `std::nullopt`.

Template Parameters
THandle

The handle type (and thus the domain) to search.

Parameters
handle

The entity handle to resolve.

Returns

`std::optional<Entity>` — engaged if the handle is valid.

Definition at line 227 of file TypedHandleWorld.ixx.

227 [[nodiscard]] auto findEntity(THandle handle) {
228 auto& em = entityManager<THandle>();
229
230 using EM = std::remove_reference_t<decltype(em)>;
231 using Entity_type = Entity<EM>;
232
233 if (!em.isValid(handle)) {
234 return std::optional<Entity_type>{std::nullopt};
235 }
236
237 return std::optional<Entity_type>{std::in_place, handle, &em};
238 }

Reference helios::ecs::TypedHandleWorld< TEntityManagers >::entityManager.

view()

template <typename THandle, typename ... TComponents>
auto helios::ecs::TypedHandleWorld< TEntityManagers >::view ()
inline nodiscard

Creates a `View` for iterating entities with specific components.

The view operates on the `EntityManager` identified by `THandle`. The first component type in `TComponents` serves as the lead set for iteration.

Template Parameters
THandle

The handle type selecting the domain.

TComponents

The component types to include in the view.

Returns

A `View` over the matching EntityManager.

See Also

View

Definition at line 278 of file TypedHandleWorld.ixx.

278 [[nodiscard]] auto view() {
279 auto& em = entityManager<THandle>();
280 using EM = std::remove_reference_t<decltype(em)>;
281 return View<EM, TComponents...>(&em);
282 }

Reference helios::ecs::TypedHandleWorld< TEntityManagers >::entityManager.

Private Member Attributes

entityManagers_

template <typename... TEntityManagers>
std::tuple<TEntityManagers...> helios::ecs::TypedHandleWorld< TEntityManagers >::entityManagers_

Definition at line 123 of file TypedHandleWorld.ixx.

123 std::tuple<TEntityManagers...> entityManagers_;

The documentation for this class was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.