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
Private Attributes
Static Private Attributes
Static Private Member Functions
Private Member Functions
Public Member Functions
Allocates a new entity.
A fresh Entity, or an error if the registry has no more room.
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) noexceptDestroys an entity and strips it from every component pool.
Ok on success, or an error if inEntity is not currently alive.
void DestroyAllEntities() noexceptDestroys an entities and strips them from every component pool.
Logs error when it cannot remove a specific entity.
void DisableEntity(Entity inEntity) noexceptDisables 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 noexceptTrue 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.
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.
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 noexceptLooks up inEntity's component of type T (read-only).
A const reference to the component, or an error if T has never been used or inEntity has none.
Looks up inEntity's component of type T.
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 noexceptChecks whether inEntity currently has a component of type T.
template<typename T> std::reference_wrapper< T > GetOrAddComponent(Entity inEntity) noexceptGets 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() noexceptReturns 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.
Ts | Component types the returned view requires. |
A View<Ts...> yielding (Entity, Ts&...) for each match.
template<typename ... Ts> asge::ecs::View< Ts const ... > View() const noexceptRead-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).
Looks up the registry-wide instance of type T.
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