← API Reference Class

asge::ecs::Registry

Owns entities, their components, and registry-wide resources; the ECS's single entry point.

#include <Registry.hpp>

Wraps an EntityAllocator<kMaxEntities> for entity lifecycle and one ComponentPool<T> per component type used so far (created lazily on the first AddComponent<T>) and ties them together: DestroyEntity() strips the entity from every pool, and View<Ts...>() iterates entities that have every one of Ts across their pools. SetResource<T>/GetResource<T> hold at most one T not tied to any Entity — e.g. shared/global state a system needs but that isn't itself part of the world.

Private Types

#using pool_t = ComponentPool< T, component_cap_v< T > >private

Private Attributes

#EntityAllocator< kMaxEntities > m_Allocator {}private
#std::vector< std::unique_ptr< IComponentPool > > m_Pools {}private
#std::vector< std::unique_ptr< IResourceHolder > > m_Resources {}private

Static Private Attributes

#static std::size_t s_NextResourceId = 0private

Static Private Member Functions

#template<typename T> static std::size_t ResourceId() noexceptprivate

Private Member Functions

#template<typename T> pool_t< T > const * FindPool() const noexceptprivate
#template<typename T> pool_t< T > * FindPool() noexceptprivate
#template<typename T> pool_t< T > & GetOrCreatePool()private

Public Member Functions

#Result< Entity > CreateEntity() noexcept

Allocates a new entity.

Returns

A fresh Entity, or an error if the registry has no more room.

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

Lists every currently-alive entity, regardless of which components (if any) it has.

Unlike View<Ts...>, which only sees entities present in a specific set of component pools, this walks the allocator directly — the only way to reach an entity with no components yet, or to visit every entity for something like scene serialization.

#BoolResult DestroyEntity(Entity inEntity) noexcept

Destroys an entity and strips it from every component pool.

Returns

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

#void DestroyAllEntities() noexcept

Destroys an entities and strips them from every component pool.

Logs error when it cannot remove a specific entity.

#void DisableEntity(Entity inEntity) noexcept

Disables an entity by adding the Disable marker to it alone.

No effect on its children IsDisabled() derives their disabled state by walking up to this entity, so nothing needs writing to them.

#bool IsDisabled(Entity inEntity) const noexcept

True if inEntity carries the Disable marker itself, or any ancestor in its Hierarchy chain does.

Walks up via components::Hierarchy::m_Parent, so cost is O(depth).

#template<typename T> Result< std::reference_wrapper< T > > AddComponent(Entity inEntity, T inComponent)

Attaches inComponent to inEntity, creating T's pool on first use.

Returns

A reference to the stored component, or an error if inEntity's index is out of range or T's pool is full.

#template<typename T> BoolResult RemoveComponent(Entity inEntity)

Detaches inEntity's component of type T, if any.

Returns

Ok on success, or an error if T has never been used or inEntity has no component of this type.

#template<typename T> Result< std::reference_wrapper< T const > > GetComponent(Entity inEntity) const noexcept

Looks up inEntity's component of type T (read-only).

Returns

A const reference to the component, or an error if T has never been used or inEntity has none.

#template<typename T> Result< std::reference_wrapper< T > > GetComponent(Entity inEntity) noexcept

Looks up inEntity's component of type T.

Returns

A reference to the component, or an error if T has never been used or inEntity has none.

#template<typename T> bool HasComponent(Entity inEntity) const noexcept

Checks whether inEntity currently has a component of type T.

#template<typename T> std::reference_wrapper< T > GetOrAddComponent(Entity inEntity) noexcept

Gets inEntity's existing component of type T, or default- constructs and attaches one first if it doesn't have one yet.

#template<typename ... Ts> asge::ecs::View< Ts... > View() noexcept

Returns a lazy view over entities that have every component in Ts.

Looks up each type's pool via FindPool — no pool is created for a type that has never been used — so the result may be empty if any of Ts has never been added to an entity yet. Entities IsDisabled() considers disabled are skipped unless Ts includes markers::Disable or the caller chains View::IncludeDisabled() onto the result.

Template Parameters
Ts

Component types the returned view requires.

Returns

A View<Ts...> yielding (Entity, Ts&...) for each match.

#template<typename ... Ts> asge::ecs::View< Ts const ... > View() const noexcept

Read-only counterpart to View() — same lookup (including the IsDisabled() skip), but returns View<Ts const...>, so iterating yields (Entity, Ts const&...) instead of mutable references.

The only overload callable through a Registry const&.

#template<typename T> void SetResource(T inValue)

Stores inValue as the registry-wide instance of type T, replacing any previous one.

Unlike components, a resource is not attached to any Entity — there is at most one T per Registry, found by its type alone. Not noexcept: both growing m_Resources and constructing T's ResourceHolder may allocate (or, for the latter, throw from T's own move constructor).

#template<typename T> Result< std::reference_wrapper< T > > GetResource() noexcept

Looks up the registry-wide instance of type T.

Returns

A reference to the resource, or an error if SetResource<T>() has never been called on this registry.

#void ForEachEntity(std::function< void(Entity const &)> m_Callback) const