template<typename T, std::size_t Nc = asge::ecs::kMaxEntities, std::size_t Ne = asge::ecs::kMaxEntities> asge::ecs::ComponentPool final
Fixed-capacity sparse-set storage of one component type per Entity.
#include <ComponentPool.hpp>Inherits from asge::ecs::IComponentPool.
Inheritance
classDiagram
class N1["asge::ecs::ComponentPool"]
class N2["asge::ecs::IComponentPool"]
N2 <|-- N1
click N1 href "classasge_1_1ecs_1_1ComponentPool.html"
click N2 href "classasge_1_1ecs_1_1IComponentPool.html"
Collaboration
classDiagram
class N1["asge::ecs::ComponentPool"]
class N2["asge::ecs::IComponentPool"]
N2 <|-- N1
click N1 href "classasge_1_1ecs_1_1ComponentPool.html"
click N2 href "classasge_1_1ecs_1_1IComponentPool.html"
Maps each entity index to a densely-packed component array, so Insert, Get, Remove and Contains are all O(1) and iteration only ever touches live components. Removal is swap-and-pop, so iteration order can change after a Remove() call.
Components are tracked by entity index alone, not generation: this pool is never notified when an entity is destroyed, so a recycled index will alias its previous occupant's component unless the caller removes it first.
T | Component type; must be default-constructible and move-assignable. |
Ne | Number of distinct entity indices this pool can address. |
Nc | Maximum number of components concurrently stored. |
Public Types
using iterator = _Iteratorusing component_ref = std::reference_wrapper< T >using const_component_ref = std::reference_wrapper< T const >Private Attributes
Public Member Functions
ComponentPool()ComponentPool(ComponentPool const &)=deleteComponentPool(ComponentPool &&)=defaultComponentPool & operator=(ComponentPool const &)=deleteComponentPool & operator=(ComponentPool &&)=defaultResult< component_ref > Insert(Entity inEntity, T inComponent)Attaches inEntity's component, replacing it if one already exists.
Reuses the entity's existing slot if it already has a component here, otherwise claims a fresh one.
A reference to the stored component, or an error if inEntity's index is out of range or the pool is full.
virtual bool Contains(Entity inEntity) const noexcept overrideChecks whether inEntity currently has a component in this pool.
Result< const_component_ref > Get(Entity inEntity) const noexceptLooks up inEntity's component (read-only).
A const reference to the component, or an error if inEntity has none.
Result< component_ref > Get(Entity inEntity) noexceptLooks up inEntity's component.
Implemented in terms of the const overload above (then const_cast-ing the result back to mutable) rather than duplicating the lookup logic — safe here because *this is genuinely non-const at the call site.
A reference to the component, or an error if inEntity has none.
virtual BoolResult Remove(Entity inEntity) noexcept overrideDetaches inEntity's component, if any.
Swaps the removed slot with the last dense component to keep storage packed, so iteration order may change after this call.
Ok on success, or an error if inEntity has no component here.
virtual std::size_t Size() const noexcept overrideReturns the total number of components associated with entities.
Returns a view over all entities in the pool.