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 Typedefs Index

template <typename... TEntityManagers>
usingEntityManager_types = std::tuple< 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 (typename 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>
EntityManager_typesentityManagers_

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.

Definition at line 121 of file TypedHandleWorld.ixx.

Public Member Typedefs

EntityManager_types

template <typename... TEntityManagers>
using helios::ecs::TypedHandleWorld< TEntityManagers >::EntityManager_types = std::tuple<TEntityManagers...>

Definition at line 126 of file TypedHandleWorld.ixx.

126 using EntityManager_types = std::tuple<TEntityManagers...>;

Public Member Functions

addEntity()

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

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(typename THandle::StrongId_type strongId) {
172 auto& em = entityManager<THandle>();
173
174 auto handle = em.create(strongId);
175
176 return Entity{handle, &em};
177 }

addEntity()

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

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 }

cloneEntity()

template <typename THandle>
auto helios::ecs::TypedHandleWorld< TEntityManagers >::cloneEntity (THandle source)
inline 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 }

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 }

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 }

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

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 }

view()

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

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 }

Private Member Attributes

entityManagers_

template <typename... TEntityManagers>
EntityManager_types helios::ecs::TypedHandleWorld< TEntityManagers >::entityManagers_

Definition at line 286 of file TypedHandleWorld.ixx.

286 EntityManager_types entityManagers_;

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.