Skip to main content

EntityManager Class Template

Manages entities and their associated components. More...

Declaration

template <typename THandle, typename TEntityRegistry, size_t TCapacity> class helios::ecs::EntityManager<THandle, TEntityRegistry, TCapacity> { ... }

Public Member Typedefs Index

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
usingEntityRegistry_type = TEntityRegistry
template <typename THandle, typename TEntityRegistry, size_t TCapacity>
usingHandle_type = THandle
template <typename THandle, typename TEntityRegistry, size_t TCapacity>
usingStrongId_type = Handle_type::StrongId_type
template <typename THandle, typename TEntityRegistry, size_t TCapacity>
usingComponentTypeId_type = ComponentTypeId< Handle_type >
template <typename THandle, typename TEntityRegistry, size_t TCapacity>
usingComponentOpsRegistry_type = ComponentOpsRegistry< Handle_type >

Public Constructors Index

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
EntityManager (const size_t capacity=TCapacity)

Constructs an EntityManager with the given capacity. More...

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
EntityManager (EntityRegistry_type &registry, const size_t capacity=TCapacity)

Constructs an EntityManager with an external registry. More...

Public Member Functions Index

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
Handle_typecreate (StrongId_type strongId=StrongId_type{})

Creates a new entity. More...

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
boolisValid (const Handle_type handle) const noexcept

Checks if an entity handle is valid. More...

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
boolisValid (const EntityId entityId) const noexcept

Checks if an entity ID is valid. More...

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
booldestroy (const Handle_type handle)

Destroys an entity and invalidates its handle. More...

template <typename T>
T *get (const Handle_type handle) const

Retrieves a component for the given entity. More...

template <typename T>
auto getSparseSet () -> SparseSet< T > *

Returns the SparseSet for a component type. More...

template <typename T>
auto getSparseSet () const -> const SparseSet< T > *

Returns the SparseSet for a component type (const). More...

template <typename T>
boolhas (const Handle_type handle) const

Checks whether an entity has a specific component. More...

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
boolhas (const Handle_type handle, const ComponentTypeId_type typeId) const

Checks whether an entity has a component by type ID. More...

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
voidenable (const Handle_type handle, const ComponentTypeId_type typeId) const

Enables a component by type ID. More...

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
voiddisable (const Handle_type handle, const ComponentTypeId_type typeId) const

Disables a component by type ID. More...

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
voidenable (const Handle_type handle, const ComponentTypeId_type typeId, const bool enable) const

Enables or disables a component by type ID. More...

template <typename T, typename... Args>
T *emplace (const Handle_type handle, Args &&...args)

Constructs and attaches a component to an entity. More...

template <typename T, typename... Args>
T *emplaceOrGet (const Handle_type handle, Args &&...args)

Returns existing component or creates a new one. More...

template <typename T>
boolremove (const Handle_type &handle)

Removes a specific component from an entity. More...

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
auto componentTypeIds (const Handle_type handle) const -> std::generator< ComponentTypeId_type >

Returns a generator over all component type IDs attached to an entity. More...

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
voidclone (const Handle_type source, const Handle_type target)

Clones all components from source entity to target entity. More...

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
void *raw (const Handle_type handle, const ComponentTypeId_type typeId) const

Returns raw void pointer to a component. More...

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
Handle_typehandle (const EntityId entityId) const

Reconstructs an EntityHandle from an EntityId. More...

Private Member Attributes Index

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
std::vector< std::unique_ptr< SparseSetBase > >components_

Component storage indexed by type ID. More...

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
EntityRegistry_typeregistry_

Entity registry owned by this EntityManager. More...

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
const size_tcapacity_

Initial capacity for the underlying sparse sets. More...

Description

Manages entities and their associated components.

`EntityManager` provides a unified interface for creating entities and attaching/retrieving components. It delegates handle management to an `EntityRegistry` and stores component data in type-specific `SparseSet` containers.

## Responsibilities

  • **Entity Creation:** Delegates to `EntityRegistry` for handle allocation.
  • **Entity Destruction:** Removes all components and invalidates the handle.
  • **Component Storage:** Maintains a vector of `SparseSet` instances, one per component type, indexed by `TypeIndexer`.

## Usage

```cpp EntityManager<MyHandle, MyRegistry, 1024> manager;

auto entity = manager.create(); auto* transform = manager.emplace<TransformComponent>(entity, glm::vec3{0.0f});

if (manager.has<TransformComponent>(entity)) { auto* t = manager.get<TransformComponent>(entity); }

manager.remove<TransformComponent>(entity); // Remove single component manager.destroy(entity); // Destroy entity and all components ```

Template Parameters
THandle

Handle type used to identify entities (e.g. `EntityHandle<StrongId>`).

TEntityRegistry

Registry type that manages handle allocation and versioning.

TCapacity

Default initial capacity for the registry and sparse sets.

See Also

EntityRegistry

See Also

SparseSet

See Also

EntityHandle

See Also

TypedHandleWorld

Definition at line 72 of file EntityManager.ixx.

Public Member Typedefs

ComponentOpsRegistry_type

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
using helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::ComponentOpsRegistry_type = ComponentOpsRegistry<Handle_type>

ComponentTypeId_type

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
using helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::ComponentTypeId_type = ComponentTypeId<Handle_type>

EntityRegistry_type

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
using helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::EntityRegistry_type = TEntityRegistry

Definition at line 77 of file EntityManager.ixx.

77 using EntityRegistry_type = TEntityRegistry;

Handle_type

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
using helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::Handle_type = THandle

Definition at line 78 of file EntityManager.ixx.

78 using Handle_type = THandle;

StrongId_type

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
using helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::StrongId_type = Handle_type::StrongId_type

Definition at line 79 of file EntityManager.ixx.

79 using StrongId_type = Handle_type::StrongId_type;

Public Constructors

EntityManager()

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::EntityManager (const size_t capacity=TCapacity)
inline explicit

Constructs an EntityManager with the given capacity.

Creates an internally owned `EntityRegistry` initialized with the specified capacity.

Parameters
capacity

Initial capacity for the registry and sparse sets. Defaults to `TCapacity`.

Definition at line 92 of file EntityManager.ixx.

92 explicit EntityManager(const size_t capacity = TCapacity)
93 : registry_(EntityRegistry_type{capacity}), capacity_(capacity)
94 {}

EntityManager()

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::EntityManager (EntityRegistry_type & registry, const size_t capacity=TCapacity)
inline explicit

Constructs an EntityManager with an external registry.

Parameters
registry

External EntityRegistry to use for handle allocation.

capacity

Initial capacity for the sparse sets. Defaults to `TCapacity`.

Deprecated

Prefer the capacity-only constructor which creates its own registry internally.

Definition at line 106 of file EntityManager.ixx.

106 explicit EntityManager(
107 EntityRegistry_type& registry,
108 const size_t capacity = TCapacity)
109 : registry_(registry), capacity_(capacity)
110 {}

Public Member Functions

clone()

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
void helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::clone (const Handle_type source, const Handle_type target)
inline

Clones all components from source entity to target entity.

Iterates through all components on the source and copies them to the target using the registered clone function. Skips components that already exist on the target.

Parameters
source

The entity to clone from.

target

The entity to clone to.

Definition at line 485 of file EntityManager.ixx.

485 void clone(const Handle_type source, const Handle_type target) {
486
487 if (!registry_.isValid(source)) {
488 return;
489 }
490
491 for (auto typeId : componentTypeIds(source)) {
492
493 if (!has(target, typeId)) {
494
495 const auto& ops = ComponentOpsRegistry_type::ops(typeId);
496
497 const void* sourceCmp = raw(source, typeId);
498
499 if (sourceCmp && ops.clone) {
500 ops.clone(this, sourceCmp, &target);
501 }
502
503 }
504
505 }
506 }

References helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::componentTypeIds, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::has, helios::ecs::ComponentOpsRegistry< Handle_type >::ops and helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::raw.

componentTypeIds()

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
std::generator< ComponentTypeId_type > helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::componentTypeIds (const Handle_type handle)
inline

Returns a generator over all component type IDs attached to an entity.

Parameters
handle

The entity to query.

Returns

Generator yielding ComponentTypeId for each attached component.

Definition at line 463 of file EntityManager.ixx.

464 if (!registry_.isValid(handle)) {
465 co_return;
466 }
467
468 for (size_t i = 0; i < components_.size(); i++) {
469 if (components_[i] && components_[i]->contains(handle.entityId)) {
470 co_yield ComponentTypeId_type{i};
471 }
472 }
473 }

Reference helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::handle.

Referenced by helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::clone.

create()

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
Handle_type helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::create (StrongId_type strongId=StrongId_type{})
inline nodiscard

Creates a new entity.

Delegates to the underlying `EntityRegistry` to allocate a new handle.

Returns

A valid `EntityHandle` for the newly created entity.

See Also

EntityRegistry::create

Definition at line 121 of file EntityManager.ixx.

121 [[nodiscard]] Handle_type create(StrongId_type strongId = StrongId_type{}) {
122 return registry_.create(strongId);
123 }

destroy()

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
bool helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::destroy (const Handle_type handle)
inline nodiscard

Destroys an entity and invalidates its handle.

Increments the entity's version in the registry, making all existing handles to this entity stale. Does automatically remove its components from storage.

Parameters
handle

The handle of the entity to destroy.

Returns

`true` if the entity was destroyed, `false` if already invalid.

Definition at line 158 of file EntityManager.ixx.

158 [[nodiscard]] bool destroy(const Handle_type handle) {
159
160 if (!registry_.isValid(handle)) {
161 return false;
162 }
163
164 for (size_t i = 0; i < components_.size(); i++) {
165
166 if (!components_[i]) {
167 continue;
168 }
169 const auto typeId = ComponentTypeId_type{i};
170 if (void* rawCmp = raw(handle, typeId)) {
171 if (const auto& ops = ComponentOpsRegistry_type::ops(typeId); ops.onRemove) {
172 ops.onRemove(rawCmp);
173 }
174 }
175
176 components_[i]->remove(handle.entityId);
177 }
178
179 registry_.destroy(handle);
180
181 return true;
182 }

References helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::handle, helios::ecs::ComponentOpsRegistry< Handle_type >::ops and helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::raw.

disable()

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
void helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::disable (const Handle_type handle, const ComponentTypeId_type typeId)
inline

Disables a component by type ID.

Calls the component's `disable()` method if registered.

Parameters
handle

The entity whose component to disable.

typeId

The component type identifier.

Definition at line 314 of file EntityManager.ixx.

314 void disable(const Handle_type handle, const ComponentTypeId_type typeId) const {
315 enable(handle, typeId, false);
316 }

References helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::enable and helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::handle.

emplace()

template <typename T, typename... Args>
T * helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::emplace (const Handle_type handle, Args &&... args)
inline

Constructs and attaches a component to an entity.

If the component type has not been registered yet, a new `SparseSet` is created. The component is constructed in-place with the provided arguments. Returns `nullptr` if the component already exists or if the handle was invalid.

Template Parameters
T

The component type to emplace.

Args

Constructor argument types.

Parameters
handle

The entity to attach the component to.

args

Arguments forwarded to the component constructor.

Returns

Pointer to the newly created component, or `nullptr` if the handle is invalid.

Definition at line 362 of file EntityManager.ixx.

362 T* emplace(const Handle_type handle, Args&& ...args) {
363
364 if (!registry_.isValid(handle)) {
365 return nullptr;
366 }
367
368 const auto entityId = handle.entityId;
369
370 const auto typeId = ComponentTypeId_type::template id<T>().value();
371
372 if (typeId >= components_.size()) {
373 components_.resize(typeId + 1);
374 }
375
376 if (!components_[typeId]) {
377 components_[typeId] = std::make_unique<SparseSet<T>>(capacity_);
378 }
379
380 auto* sparseSet = static_cast<SparseSet<T>*>(components_[typeId].get());
381
382 if (sparseSet->contains(entityId)) {
383 return nullptr;
384 }
385
386 return sparseSet->emplace(entityId, std::forward<Args>(args)...);
387 }

Reference helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::handle.

Referenced by helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::emplaceOrGet.

emplaceOrGet()

template <typename T, typename... Args>
T * helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::emplaceOrGet (const Handle_type handle, Args &&... args)
inline

Returns existing component or creates a new one.

Template Parameters
T

The component type.

Args

Constructor argument types.

Parameters
handle

The entity.

args

Arguments forwarded to the constructor if creating.

Returns

Pointer to the existing or newly created component, or `nullptr` if the handle is invalid.

Definition at line 402 of file EntityManager.ixx.

402 T* emplaceOrGet(const Handle_type handle, Args&& ...args) {
403
404 if (!registry_.isValid(handle)) {
405 return nullptr;
406 }
407
408 auto* raw = emplace<T>(handle, std::forward<Args>(args)...);
409
410 if (!raw) {
411 return get<T>(handle);
412 }
413
414 return raw;
415 }

References helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::emplace, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::get, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::handle and helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::raw.

enable()

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
void helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::enable (const Handle_type handle, const ComponentTypeId_type typeId)
inline

Enables a component by type ID.

Calls the component's `enable()` method if registered.

Parameters
handle

The entity whose component to enable.

typeId

The component type identifier.

Definition at line 302 of file EntityManager.ixx.

302 void enable(const Handle_type handle, const ComponentTypeId_type typeId) const {
303 enable(handle, typeId, true);
304 }

References helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::enable and helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::handle.

Referenced by helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::disable, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::enable and helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::enable.

enable()

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
void helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::enable (const Handle_type handle, const ComponentTypeId_type typeId, const bool enable)
inline

Enables or disables a component by type ID.

Parameters
handle

The entity whose component to modify.

typeId

The component type identifier.

enable

`true` to enable, `false` to disable.

Definition at line 325 of file EntityManager.ixx.

325 void enable(const Handle_type handle, const ComponentTypeId_type typeId, const bool enable) const {
326
327 if (!has(handle, typeId)) {
328 return;
329 }
330
331 void* rawCmp = raw(handle, typeId);
332 if (!rawCmp) {
333 return;
334 }
335 const auto& ops = ComponentOpsRegistry_type::ops(typeId);
336
337 if (enable && ops.enable) {
338 ops.enable(rawCmp);
339 } else if (!enable && ops.disable) {
340 ops.disable(rawCmp);
341 }
342 }

References helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::enable, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::handle, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::has, helios::ecs::ComponentOpsRegistry< Handle_type >::ops and helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::raw.

get()

template <typename T>
T * helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::get (const Handle_type handle)
inline nodiscard

Retrieves a component for the given entity.

Template Parameters
T

The component type to retrieve.

Parameters
handle

The entity whose component to retrieve.

Returns

Pointer to the component, or `nullptr` if the entity is invalid or does not have the requested component.

Definition at line 195 of file EntityManager.ixx.

195 [[nodiscard]] T* get(const Handle_type handle) const {
196 if (!has<T>(handle)) {
197 return nullptr;
198 }
199
200 const auto entityId = handle.entityId;
201 const auto typeId = ComponentTypeId_type::template id<T>().value();
202
203 auto* sparseSet = static_cast<SparseSet<T>*>(components_[typeId].get());
204
205 return sparseSet->get(entityId);
206 }

References helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::handle and helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::has.

Referenced by helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::emplaceOrGet.

getSparseSet()

template <typename T>
SparseSet< T > * helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::getSparseSet ()
inline nodiscard

Returns the SparseSet for a component type.

Template Parameters
T

The component type.

Returns

Pointer to the SparseSet, or `nullptr` if the type has no storage.

Definition at line 216 of file EntityManager.ixx.

216 [[nodiscard]] SparseSet<T>* getSparseSet() {
217
218 const auto typeId = ComponentTypeId_type::template id<T>().value();
219
220 if (typeId >= components_.size()) {
221 return nullptr;
222 }
223
224 return static_cast<SparseSet<T>*>(components_[typeId].get());
225 }

getSparseSet()

template <typename T>
const SparseSet< T > * helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::getSparseSet ()
inline nodiscard

Returns the SparseSet for a component type (const).

Template Parameters
T

The component type.

Returns

Const pointer to the SparseSet, or `nullptr` if the type has no storage.

Definition at line 235 of file EntityManager.ixx.

235 [[nodiscard]] const SparseSet<T>* getSparseSet() const {
236
237 const auto typeId = ComponentTypeId_type::template id<T>().value();
238
239 if (typeId >= components_.size()) {
240 return nullptr;
241 }
242
243 return static_cast<SparseSet<T>*>(components_[typeId].get());
244 }

handle()

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
Handle_type helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::handle (const EntityId entityId)
inline nodiscard

has()

template <typename T>
bool helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::has (const Handle_type handle)
inline nodiscard

Checks whether an entity has a specific component.

Template Parameters
T

The component type to check for.

Parameters
handle

The entity to query.

Returns

`true` if the entity has the component, `false` if the handle is invalid or the component is not attached.

Definition at line 257 of file EntityManager.ixx.

257 [[nodiscard]] bool has(const Handle_type handle) const {
258 if (!registry_.isValid(handle)) {
259 return false;
260 }
261
262 const auto typeId = ComponentTypeId_type::template id<T>().value();
263
264 if (typeId < components_.size() && components_[typeId]) {
265 return components_[typeId]->contains(handle.entityId);
266 }
267
268 return false;
269 }

Reference helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::handle.

Referenced by helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::clone, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::enable, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::get, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::raw and helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::remove.

has()

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
bool helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::has (const Handle_type handle, const ComponentTypeId_type typeId)
inline nodiscard

Checks whether an entity has a component by type ID.

Parameters
handle

The entity to query.

typeId

The component type identifier.

Returns

`true` if the entity has the component, `false` otherwise.

Definition at line 279 of file EntityManager.ixx.

279 [[nodiscard]] bool has(const Handle_type handle,
280 const ComponentTypeId_type typeId) const {
281 if (!registry_.isValid(handle)) {
282 return false;
283 }
284
285 const auto tvalue = typeId.value();
286
287 if (tvalue < components_.size() && components_[tvalue]) {
288 return components_[tvalue]->contains(handle.entityId);
289 }
290
291 return false;
292 }

References helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::handle and helios::ecs::types::ComponentTypeId< THandle >::value.

isValid()

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
bool helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::isValid (const Handle_type handle)
inline nodiscard noexcept

Checks if an entity handle is valid.

Parameters
handle

The handle to validate.

Returns

`true` if the handle refers to a living entity.

Definition at line 132 of file EntityManager.ixx.

132 [[nodiscard]] bool isValid(const Handle_type handle) const noexcept {
133 return registry_.isValid(handle);
134 }

Reference helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::handle.

isValid()

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
bool helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::isValid (const EntityId entityId)
inline nodiscard noexcept

Checks if an entity ID is valid.

Parameters
entityId

The entity ID to validate.

Returns

`true` if the entity ID refers to a living entity.

Definition at line 143 of file EntityManager.ixx.

143 [[nodiscard]] bool isValid(const EntityId entityId) const noexcept {
144 return registry_.isValid(handle(entityId));
145 }

Reference helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::handle.

raw()

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
void * helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::raw (const Handle_type handle, const ComponentTypeId_type typeId)
inline nodiscard

remove()

template <typename T>
bool helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::remove (const Handle_type & handle)
inline

Removes a specific component from an entity.

Unlike `destroy()`, this only removes a single component type while keeping the entity and other components intact.

Template Parameters
T

The component type to remove.

Parameters
handle

The entity whose component to remove.

Returns

`true` if the component was removed, `false` if the handle was invalid, the component was not attached, or removal was blocked by `onRemove`.

See Also

destroy

See Also

SparseSet::remove

Definition at line 435 of file EntityManager.ixx.

435 bool remove(const Handle_type& handle) {
436
437 if (!has<T>(handle)) {
438 return false;
439 }
440
441 const auto typeId = ComponentTypeId_type::template id<T>();
442 void* rawCmp = raw(handle, typeId);
443 if (!rawCmp) {
444 return false;
445 }
446 const auto& ops = ComponentOpsRegistry_type::ops(typeId);
447
448 if (ops.onRemove && !ops.onRemove(rawCmp)) {
449 return false;
450 }
451
452 return components_[typeId.value()]->remove(handle.entityId);
453 }

References helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::handle, helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::has, helios::ecs::ComponentOpsRegistry< Handle_type >::ops and helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::raw.

Private Member Attributes

capacity_

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
const size_t helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::capacity_

Initial capacity for the underlying sparse sets.

Definition at line 551 of file EntityManager.ixx.

551 const size_t capacity_;

components_

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
std::vector<std::unique_ptr<SparseSetBase> > helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::components_

Component storage indexed by type ID.

Todo

sort after size()

Definition at line 541 of file EntityManager.ixx.

541 std::vector<std::unique_ptr<SparseSetBase>> components_;

registry_

template <typename THandle, typename TEntityRegistry, size_t TCapacity>
EntityRegistry_type helios::ecs::EntityManager< THandle, TEntityRegistry, TCapacity >::registry_

Entity registry owned by this EntityManager.

Definition at line 546 of file EntityManager.ixx.

546 EntityRegistry_type registry_;

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.