← API Reference Class

template<std::size_t N> asge::ecs::EntityAllocator

Fixed-capacity issuer and validator of generational Entity handles.

#include <EntityAllocator.hpp>

Wraps a mem::FreeList<N> of slot indices with a per-slot generation counter. Create() claims a free index and pairs it with that slot's current generation; Destroy() returns the index to the free-list and then bumps the slot's generation, which invalidates every Entity handle previously issued for that slot. IsAlive() is the source of truth for handle validity: a handle is alive only while its slot is currently claimed and its generation matches the slot's current one — so a handle built for a never-allocated slot is correctly rejected too.

A slot whose generation reaches its maximum value is retired rather than recycled, so a still-held stale handle can never alias a future allocation once the counter would otherwise wrap back to a reused value.

Template Parameters
N

Number of concurrently allocatable entities; fixed at compile time.

Private Attributes

#mem::FreeList< N > m_EntityFreeIdsprivate
#std::array< EntityGeneration, N > m_Generations {}private

Public Member Functions

#EntityAllocator()
#EntityAllocator(EntityAllocator const &)=delete
#EntityAllocator(EntityAllocator &&)=default
#EntityAllocator & operator=(EntityAllocator const &)=delete
#EntityAllocator & operator=(EntityAllocator &&)=default
#Result< Entity > Create() noexcept

Claims a free slot and returns a live handle for it.

The returned Entity pairs the slot's index with its current generation.

Returns

A fresh Entity, or an error if all N slots are in use.

#BoolResult Destroy(Entity inEntity) noexcept

Invalidates a live handle and returns its slot to the free-list.

Bumps the slot's generation, so every Entity previously issued for it (including inEntity) subsequently fails IsAlive().

Returns

Ok on success, or an error if inEntity is not currently alive.

#bool IsAlive(Entity inEntity) const noexcept

Checks whether a handle still refers to the slot it was issued for.

True only when the slot is currently claimed (i.e. was returned by Create() and not since destroyed) and its generation matches.

#std::vector< Entity > AllEntities() const

Lists every currently-alive entity, in no particular order.

A full O(N) scan over every slot — fine for an occasional operation like scene saving, not meant to be called every frame.