Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
esengine::ecs::SparseSetBase Class Referenceabstract

Type-erased base class for sparse set operations. More...

#include <SparseSet.hpp>

Inheritance diagram for esengine::ecs::SparseSetBase:

Classes

struct  AuditCopy
 What the audit kept of a pool: its entities and their components' bytes, as they were at tick. More...

Public Member Functions

virtual ~SparseSetBase ()=default
 Virtual destructor for proper cleanup.
virtual bool contains (Entity entity) const =0
 Checks if an entity exists in the set.
virtual void remove (Entity entity)=0
 Removes an entity's component from the set.
virtual usize size () const =0
 Gets the number of components in the set.
virtual bool empty () const =0
 Checks if the set is empty.
virtual void clear ()=0
 Removes all components from the set.
virtual const std::vector< Entity > & entities () const =0
 Gets the dense entity array for iteration.
virtual u32 version () const =0
 Monotonic version, bumped whenever stored components may have moved in memory (buffer reallocation on growth, or swap-and-pop relocation on removal).
virtual void reorderBy (const std::vector< u32 > &rank)=0
 Permutes storage so iteration follows rank.
virtual u32 changedTickOf (Entity entity) const =0
 The tick of entity's last write here, 0 where it has no component: the type-erased changedTick.
virtual void markChanged (Entity entity, u32 tick)=0
 Stamps entity's component as written at tick (no-op where it has none): the type-erased markChanged.
virtual u32 lastChangedTick () const =0
 The tick of the last write to any component of this pool, or of the last add or remove: "anything since?" in O(1).
virtual void noteStructural (u32 tick)=0
 Notes an add or a remove at tick, which no stamp of a component that is still there records.
virtual void clampStamps (u32 floor)=0
 Lifts every stamp older than floor to it, so a stamp never reads as newer after the tick wraps.
virtual std::string_view typeName () const =0
 The component type's name, for what the audit says.
virtual bool auditable () const =0
 Whether this pool's components can be audited (see above).
virtual void auditKeep (AuditCopy &copy, u32 tick) const =0
 Keeps the pool's state as it is at tick.
virtual u32 auditCompare (const AuditCopy &copy, void(*report)(void *user, Entity entity), void *user) const =0
 Calls report for each entity whose component changed since copy without a stamp after copy.tick.

Static Public Member Functions

static std::vector< usize > stablePermutation (const std::vector< Entity > &dense, const std::vector< u32 > &rank)
 Which current slot belongs at each position when dense is put in rank order (stable).

Static Public Attributes

static constexpr u32 UNRANKED = 0xFFFFFFFFu
 Rank for an entity the caller did not order — sorts last, stably.

Detailed Description

Type-erased base class for sparse set operations.

Provides a common interface for type-erased operations on component pools. Used by Registry to manage pools of different component types uniformly.

Definition at line 51 of file SparseSet.hpp.

Constructor & Destructor Documentation

◆ ~SparseSetBase()

virtual esengine::ecs::SparseSetBase::~SparseSetBase ( )
virtualdefault

Virtual destructor for proper cleanup.

Member Function Documentation

◆ auditable()

virtual bool esengine::ecs::SparseSetBase::auditable ( ) const
pure virtual

Whether this pool's components can be audited (see above).

Implemented in esengine::ecs::SparseSet< T >.

◆ auditCompare()

virtual u32 esengine::ecs::SparseSetBase::auditCompare ( const AuditCopy & copy,
void(* report )(void *user, Entity entity),
void * user ) const
pure virtual

Calls report for each entity whose component changed since copy without a stamp after copy.tick.

Returns
How many did.

Implemented in esengine::ecs::SparseSet< T >.

◆ auditKeep()

virtual void esengine::ecs::SparseSetBase::auditKeep ( AuditCopy & copy,
u32 tick ) const
pure virtual

Keeps the pool's state as it is at tick.

Implemented in esengine::ecs::SparseSet< T >.

◆ changedTickOf()

virtual u32 esengine::ecs::SparseSetBase::changedTickOf ( Entity entity) const
pure virtual

The tick of entity's last write here, 0 where it has no component: the type-erased changedTick.

Implemented in esengine::ecs::SparseSet< T >.

◆ clampStamps()

virtual void esengine::ecs::SparseSetBase::clampStamps ( u32 floor)
pure virtual

Lifts every stamp older than floor to it, so a stamp never reads as newer after the tick wraps.

Implemented in esengine::ecs::SparseSet< T >.

◆ clear()

virtual void esengine::ecs::SparseSetBase::clear ( )
pure virtual

Removes all components from the set.

Implemented in esengine::ecs::SparseSet< T >.

◆ contains()

virtual bool esengine::ecs::SparseSetBase::contains ( Entity entity) const
pure virtual

Checks if an entity exists in the set.

Parameters
entityThe entity to check
Returns
True if the entity has a component in this pool

Implemented in esengine::ecs::SparseSet< T >.

◆ empty()

virtual bool esengine::ecs::SparseSetBase::empty ( ) const
pure virtual

Checks if the set is empty.

Returns
True if no components are stored

Implemented in esengine::ecs::SparseSet< T >.

◆ entities()

virtual const std::vector< Entity > & esengine::ecs::SparseSetBase::entities ( ) const
pure virtual

Gets the dense entity array for iteration.

Returns
Const reference to the entity vector

Implemented in esengine::ecs::SparseSet< T >.

◆ lastChangedTick()

virtual u32 esengine::ecs::SparseSetBase::lastChangedTick ( ) const
pure virtual

The tick of the last write to any component of this pool, or of the last add or remove: "anything since?" in O(1).

Implemented in esengine::ecs::SparseSet< T >.

◆ markChanged()

virtual void esengine::ecs::SparseSetBase::markChanged ( Entity entity,
u32 tick )
pure virtual

Stamps entity's component as written at tick (no-op where it has none): the type-erased markChanged.

Implemented in esengine::ecs::SparseSet< T >.

◆ noteStructural()

virtual void esengine::ecs::SparseSetBase::noteStructural ( u32 tick)
pure virtual

Notes an add or a remove at tick, which no stamp of a component that is still there records.

Implemented in esengine::ecs::SparseSet< T >.

◆ remove()

virtual void esengine::ecs::SparseSetBase::remove ( Entity entity)
pure virtual

Removes an entity's component from the set.

Parameters
entityThe entity whose component to remove

Implemented in esengine::ecs::SparseSet< T >.

◆ reorderBy()

virtual void esengine::ecs::SparseSetBase::reorderBy ( const std::vector< u32 > & rank)
pure virtual

Permutes storage so iteration follows rank.

Parameters
rankRank per ENTITY INDEX (Entity::index()); lower ranks iterate first

Storage order is iteration order, and iteration order is the renderer's within-layer painter order, so this is how a scene's authored entity order reaches the draw list without respawning anything. Entities with no rank (index past the end, or the UNRANKED sentinel) keep their relative order after the ranked ones — the sort is stable. A no-op reorder leaves storage (and therefore every handed-out component pointer) untouched.

Implemented in esengine::ecs::SparseSet< T >.

◆ size()

virtual usize esengine::ecs::SparseSetBase::size ( ) const
pure virtual

Gets the number of components in the set.

Returns
Number of stored components

Implemented in esengine::ecs::SparseSet< T >.

◆ stablePermutation()

std::vector< usize > esengine::ecs::SparseSetBase::stablePermutation ( const std::vector< Entity > & dense,
const std::vector< u32 > & rank )
inlinestatic

Which current slot belongs at each position when dense is put in rank order (stable).

Not a member of the template: the sort does not depend on the component type, and a copy of std::stable_sort and its merge helpers for each of the hundred-odd component types was 227KB of the engine's wasm — over a tenth of its code. Entities with no rank sort after the ranked ones, in their present order.

Definition at line 166 of file SparseSet.hpp.

References UNRANKED.

Referenced by esengine::ecs::SparseSet< T >::reorderBy().

◆ typeName()

virtual std::string_view esengine::ecs::SparseSetBase::typeName ( ) const
pure virtual

The component type's name, for what the audit says.

Implemented in esengine::ecs::SparseSet< T >.

◆ version()

virtual u32 esengine::ecs::SparseSetBase::version ( ) const
pure virtual

Monotonic version, bumped whenever stored components may have moved in memory (buffer reallocation on growth, or swap-and-pop relocation on removal).

Single source of truth for the cross-boundary pointer-staleness guard: a raw component pointer handed to JS (e.g. getTransformPtr) is only valid while this value is unchanged. Replaces the old SchemaComponentPool::poolVersion (which lived in a now-deleted parallel store and, notably, was not bumped on remove).

Implemented in esengine::ecs::SparseSet< T >.

Member Data Documentation

◆ UNRANKED

u32 esengine::ecs::SparseSetBase::UNRANKED = 0xFFFFFFFFu
staticconstexpr

Rank for an entity the caller did not order — sorts last, stably.

Definition at line 119 of file SparseSet.hpp.

Referenced by esengine::ecs::Registry::buildEntityRank(), and stablePermutation().


The documentation for this class was generated from the following file:
  • /home/runner/work/estella/estella/src/esengine/ecs/SparseSet.hpp