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

Central container for all entities and components. More...

#include <Registry.hpp>

Public Types

using DestroyCallback = std::function<void(Entity)>

Public Member Functions

 Registry ()=default
 ~Registry ()=default
 Registry (const Registry &)=delete
Registry & operator= (const Registry &)=delete
 Registry (Registry &&) noexcept=default
Registry & operator= (Registry &&) noexcept=default
u64 instanceId () const
 Which registry this is — unique for the process, never reused.
bool setEntityEnabled (Entity e, bool enabled)
bool isEntityEnabled (Entity e) const
bool isEntityActive (Entity e) const
bool hasInactiveEntities () const
u32 activityEpoch () const
void invalidateActivityHierarchy (Entity root=INVALID_ENTITY)
u32 watchEntityChanges ()
void unwatchEntityChanges (u32 reader)
double entityChangeSequence () const
double entityChangeResetEpoch () const
double componentMutationRevision (u32 component, bool topology) const
i32 readEntityChanges (double after, std::span< EntityChangeRow > output) const
void recordEntityChange (Entity entity, u32 flags=0, u32 component=ENTITY_CHANGE_NO_COMPONENT)
u32 changeTick () const
 The tick a write made now is stamped with.
u64 identity () const
 Which registry this is, never shared with another made in this process (a registry assigned over this one brings its own). Ticks and entities are each registry's own, so a reader that keeps what it derived from one asks this before trusting a tick or an entity it kept.
u32 beginChangeRead ()
 For a reader about to look: the tick it is looking at, after which the clock moves on.
template<typename T>
T & patch (Entity entity)
 Mutable access that says it writes: entity's T, stamped. Fatal where it has none, as get<T>() is.
template<typename T>
void markChanged (Entity entity)
 Says entity's T was written, through a reference held from before.
void markChangedById (u32 typeId, Entity entity)
 markChanged by a component type id (componentTypeId): for a writer that names the type at run time, a script.
template<typename T>
bool changedSince (Entity entity, u32 tick) const
 Whether entity's T was written, added or replaced after tick (an answer of beginChangeRead).
bool changedSinceById (u32 typeId, Entity entity, u32 tick) const
 changedSince by a component type id (componentTypeId), for a reader that names the type at run time.
template<typename T>
bool anyChangedSince (u32 tick) const
 Whether any T was written, added or removed after tick: the question a frame that may skip its walk asks first.
template<typename T, typename Visit>
bool anyChangedSinceWhere (u32 tick, Visit &&visit) const
 Calls visit(entity) for each T written or added after tick, until it returns true; returns whether one did.
template<typename Visit>
bool anyComponentChangedSinceWhere (u32 tick, Visit &&visit) const
 anyChangedSinceWhere over every component type: calls visit(entity) for each component written or added after tick, whatever its type, until it returns true. A removal leaves nothing to visit; the entity change journal has it.
template<typename T>
u32 poolVersion () const
 T's pool version: moves when a T is removed or the pool's storage moves (SparseSetBase::version). 0 with no pool.
template<typename T, typename Visit>
void eachChangedSince (u32 tick, Visit &&visit)
 Calls visit(entity, component) for each T written, added or replaced after tick, in storage order.
template<typename T>
usize countOf () const
 How many entities have a T.
template<typename T>
u32 lastChangedTick () const
 The tick of the latest write, addition or removal of any T; 0 when there has been none.
void setChangeAudit (bool enabled)
 Turns the change audit on or off. On, auditChanges() compares every auditable component with the copy it kept and reports each one whose bytes changed with no stamp to say so — a write some consumer will never see.
bool changeAuditEnabled () const
u32 auditChanges ()
 Compares, reports, and keeps a new copy.
u32 changeAuditTotal () const
 Unstamped writes the audit has found since it was turned on.
template<class... C>
auto activeView ()
Entity create ()
 Creates a new entity.
std::vector< Entity > create (usize count)
 Creates multiple entities at once.
Entity restore (u32 index)
 Restores an entity at a specific index.
bool reserveDestruction (Entity entity)
void releaseDestruction (Entity entity)
bool destructionPending (Entity entity) const
void destroy (Entity entity)
 Destroys an entity and removes all its components.
Connection onDestroy (DestroyCallback callback)
 Subscribe to entity destruction.
bool valid (Entity entity) const
 Checks if an entity is currently valid.
usize entityCount () const
const ExclusiveRelation & childOf () const
 The (ChildOf, parent) relation: each entity's parent, and each parent's children in order.
ExclusiveRelation & childOf ()
u32 retiredSlots () const
 Slots permanently out of circulation, their generation spent.
template<typename Func>
void forEachEntity (Func &&func) const
 Executes a function for each valid entity.
template<typename T, typename... Args>
T & emplace (Entity entity, Args &&... args)
 Adds a component to an entity with in-place construction.
template<typename T, typename... Args>
T & emplaceOrReplace (Entity entity, Args &&... args)
 Adds or replaces a component on an entity.
template<typename T>
void remove (Entity entity)
 Removes a component from an entity.
template<typename T>
T & get (Entity entity)
 Gets a component from an entity (must exist).
template<typename T>
const T & get (Entity entity) const
 Gets a component from an entity (must exist).
template<typename T>
T * tryGet (Entity entity)
 Tries to get a component from an entity.
template<typename T>
const T * tryGet (Entity entity) const
 Tries to get a component from an entity.
template<typename T, typename... Args>
T & getOrEmplace (Entity entity, Args &&... args)
 Gets an existing component or creates a new one.
template<typename T>
bool has (Entity entity) const
 Checks if an entity has a specific component.
template<typename... Ts>
bool hasAll (Entity entity) const
 Checks if an entity has all specified components.
template<typename... Ts>
bool hasAny (Entity entity) const
 Checks if an entity has any of the specified components.
template<typename... Components>
View< Components... > view ()
 Creates a view for iterating entities with specific components.
void clear ()
 Clears all entities and components.
void applyEntityOrder (const Entity *order, usize count)
 Reorders every component pool to follow the given entity order.
std::vector< u32 > buildEntityRank (const Entity *order, usize count) const
 Rank table (by Entity::index()) for an ordered entity list.
double layoutEpoch () const
 Sum of every pool's version — one number for "did anything move".
void applyEntityRank (const std::vector< u32 > &rank)
 Reorders every component pool by a rank table from buildEntityRank.
template<typename... Components, typename Func>
void each (Func &&func)
 Executes a function for each entity with specified components.
template<typename... Components, typename Func>
void eachLive (Func &&func)
 each() without the per-call snapshot copy, for read-only passes.
template<typename T, typename Compare>
void sort (Compare compare)
 Sorts components by a comparison function.
template<typename T>
std::span< const Entity > entitiesWith () const
 The entities that carry T, densely.

Detailed Description

Central container for all entities and components.

The Registry provides:

  • Entity lifecycle management (create, destroy, recycle)
  • Component storage with O(1) access via SparseSet pools
  • View-based queries for iterating entities with specific components
Registry registry;
// Create entities and add components
Entity player = registry.create();
registry.emplace<Position>(player, 0.0f, 0.0f);
registry.emplace<Velocity>(player, 1.0f, 0.0f);
// Query and iterate
registry.each<Position, Velocity>([&](Entity e, Position& pos, Velocity& vel) {
pos.x += vel.x * deltaTime;
});
void each(Func &&func)
Executes a function for each entity with specified components.
Definition Registry.hpp:881
Entity create()
Creates a new entity.
Definition Registry.hpp:371
T & emplace(Entity entity, Args &&... args)
Adds a component to an entity with in-place construction.
Definition Registry.hpp:576
Entity identifier with packed index + generation.
Definition Types.hpp:135
Velocity component for simple kinematic motion.
Definition Velocity.hpp:41

Definition at line 73 of file Registry.hpp.

Member Typedef Documentation

◆ DestroyCallback

using esengine::ecs::Registry::DestroyCallback = std::function<void(Entity)>

Definition at line 499 of file Registry.hpp.

Constructor & Destructor Documentation

◆ Registry() [1/3]

esengine::ecs::Registry::Registry ( )
default

◆ ~Registry()

esengine::ecs::Registry::~Registry ( )
default

◆ Registry() [2/3]

esengine::ecs::Registry::Registry ( const Registry & )
delete

References Registry().

◆ Registry() [3/3]

esengine::ecs::Registry::Registry ( Registry && )
defaultnoexcept

References Registry().

Member Function Documentation

◆ activeView()

◆ activityEpoch()

u32 esengine::ecs::Registry::activityEpoch ( ) const
inline

◆ anyChangedSince()

template<typename T>
bool esengine::ecs::Registry::anyChangedSince ( u32 tick) const
inline

Whether any T was written, added or removed after tick: the question a frame that may skip its walk asks first.

Definition at line 220 of file Registry.hpp.

References esengine::ecs::tickAfter().

Referenced by esengine::MeshPlugin::castInputs(), and esengine::ecs::UISystem::hitInputsChanged().

◆ anyChangedSinceWhere()

template<typename T, typename Visit>
bool esengine::ecs::Registry::anyChangedSinceWhere ( u32 tick,
Visit && visit ) const
inline

Calls visit(entity) for each T written or added after tick, until it returns true; returns whether one did.

A pass over the stamps alone, which sit in one array beside the components: the answer to "did any of the many that changed matter to me" without a lookup per component. A removal leaves nothing to visit (anyChangedSince sees it).

Definition at line 232 of file Registry.hpp.

References esengine::ecs::tickAfter().

Referenced by esengine::MeshPlugin::castInputs().

◆ anyComponentChangedSinceWhere()

template<typename Visit>
bool esengine::ecs::Registry::anyComponentChangedSinceWhere ( u32 tick,
Visit && visit ) const
inline

anyChangedSinceWhere over every component type: calls visit(entity) for each component written or added after tick, whatever its type, until it returns true. A removal leaves nothing to visit; the entity change journal has it.

Definition at line 248 of file Registry.hpp.

References esengine::ecs::tickAfter().

◆ applyEntityOrder()

void esengine::ecs::Registry::applyEntityOrder ( const Entity * order,
usize count )
inline

Reorders every component pool to follow the given entity order.

Parameters
orderEntities in the desired iteration order (first iterates first)
countHow many entries order holds

Component storage order IS iteration order, and iteration order is the renderer's painter order within a sorting layer — so a scene's authored entity order only reaches the draw list because a load happens to spawn in that order. This applies an order to a registry that is already populated: the same picture, without respawning anything (entity ids, component values, and every subsystem keyed on them survive untouched).

Entities absent from order keep their relative order after the listed ones. Pools already in the requested order are left alone, so a redundant call costs a scan and bumps no pool version.

Definition at line 818 of file Registry.hpp.

References applyEntityRank(), and buildEntityRank().

◆ applyEntityRank()

void esengine::ecs::Registry::applyEntityRank ( const std::vector< u32 > & rank)
inline

Reorders every component pool by a rank table from buildEntityRank.

Definition at line 862 of file Registry.hpp.

Referenced by applyEntityOrder(), and esengine::ecs::applySceneEntityOrder().

◆ auditChanges()

u32 esengine::ecs::Registry::auditChanges ( )
inline

Compares, reports, and keeps a new copy.

Returns
The unstamped writes found since the last call (0 while off).

Each component type is named in the log the first time one of its writes goes unstamped, with the entity; every one is counted. A type that can be neither copied as bytes nor compared is named once, at the first audit, as unchecked.

Definition at line 314 of file Registry.hpp.

References Registry(), beginChangeRead(), ES_LOG_INFO, ES_LOG_WARN, esengine::INVALID_ENTITY, and esengine::sink().

Referenced by EMSCRIPTEN_BINDINGS(), and setChangeAudit().

◆ beginChangeRead()

u32 esengine::ecs::Registry::beginChangeRead ( )
inline

For a reader about to look: the tick it is looking at, after which the clock moves on.

Keep the answer; next time, changedSince(it) is what was written since this look. Stamps older than half the counter's range are lifted on the way, so an untouched component never reads as newer once the tick wraps.

Definition at line 173 of file Registry.hpp.

Referenced by auditChanges(), esengine::MeshPlugin::castInputs(), EMSCRIPTEN_BINDINGS(), esengine::ecs::UISystem::hitInputsChanged(), esengine::RenderFrame::keepScreenOverlay(), and esengine::RenderFrame::submitScreenOverlay().

◆ buildEntityRank()

std::vector< u32 > esengine::ecs::Registry::buildEntityRank ( const Entity * order,
usize count ) const
inline

Rank table (by Entity::index()) for an ordered entity list.

Split out of applyEntityOrder so a caller that ranks other entity lists too — child lists, in applySceneEntityOrder — builds it once. Unlisted entities read SparseSetBase::UNRANKED.

Definition at line 829 of file Registry.hpp.

References esengine::Entity::index(), and esengine::ecs::SparseSetBase::UNRANKED.

Referenced by applyEntityOrder(), and esengine::ecs::applySceneEntityOrder().

◆ changeAuditEnabled()

bool esengine::ecs::Registry::changeAuditEnabled ( ) const
inline

Definition at line 307 of file Registry.hpp.

Referenced by esengine::RenderFrame::keepScreenOverlay().

◆ changeAuditTotal()

u32 esengine::ecs::Registry::changeAuditTotal ( ) const
inline

Unstamped writes the audit has found since it was turned on.

Definition at line 353 of file Registry.hpp.

Referenced by EMSCRIPTEN_BINDINGS().

◆ changedSince()

template<typename T>
bool esengine::ecs::Registry::changedSince ( Entity entity,
u32 tick ) const
inline

Whether entity's T was written, added or replaced after tick (an answer of beginChangeRead).

Definition at line 207 of file Registry.hpp.

References esengine::ecs::tickAfter().

Referenced by esengine::ecs::UISystem::hitInputsChanged().

◆ changedSinceById()

bool esengine::ecs::Registry::changedSinceById ( u32 typeId,
Entity entity,
u32 tick ) const
inline

changedSince by a component type id (componentTypeId), for a reader that names the type at run time.

Definition at line 213 of file Registry.hpp.

References esengine::ecs::tickAfter().

Referenced by EMSCRIPTEN_BINDINGS().

◆ changeTick()

u32 esengine::ecs::Registry::changeTick ( ) const
inline

The tick a write made now is stamped with.

Definition at line 159 of file Registry.hpp.

Referenced by EMSCRIPTEN_BINDINGS().

◆ childOf() [1/2]

ExclusiveRelation & esengine::ecs::Registry::childOf ( )
inline

Definition at line 535 of file Registry.hpp.

◆ childOf() [2/2]

const ExclusiveRelation & esengine::ecs::Registry::childOf ( ) const
inline

The (ChildOf, parent) relation: each entity's parent, and each parent's children in order.

The authority on the hierarchy. Edit it through setParent / destroyWithChildren / applySceneEntityOrder, which also keep the Parent and Children components that scripts and scene files read.

Definition at line 534 of file Registry.hpp.

Referenced by esengine::ecs::applySceneEntityOrder(), esengine::ecs::destroyWithChildren(), esengine::ecs::getRoot(), esengine::ecs::isDescendantOf(), esengine::ecs::setParent(), and esengine::ecs::syncHierarchyComponents().

◆ clear()

void esengine::ecs::Registry::clear ( )
inline

Clears all entities and components.

Resets the registry to its initial empty state.

Definition at line 778 of file Registry.hpp.

References esengine::ecs::ENTITY_CHANGE_RESET, esengine::INVALID_ENTITY, and recordEntityChange().

◆ componentMutationRevision()

double esengine::ecs::Registry::componentMutationRevision ( u32 component,
bool topology ) const
inline

Definition at line 134 of file Registry.hpp.

Referenced by esengine::registry_componentMutationRevision().

◆ countOf()

template<typename T>
usize esengine::ecs::Registry::countOf ( ) const
inline

How many entities have a T.

Definition at line 284 of file Registry.hpp.

Referenced by esengine::MeshPlugin::castInputs().

◆ create() [1/2]

Entity esengine::ecs::Registry::create ( )
inline

Creates a new entity.

Returns
A valid entity ID

Recycles previously destroyed entities when available. New entities are allocated sequentially when no recycled entities exist.

Definition at line 371 of file Registry.hpp.

Referenced by create(), esengine::animation::TweenSystem::createTween(), EMSCRIPTEN_BINDINGS(), esengine::renderer_renderMaterialPreview(), and esengine::renderer_renderMeshPreview().

◆ create() [2/2]

std::vector< Entity > esengine::ecs::Registry::create ( usize count)
inline

Creates multiple entities at once.

Parameters
countNumber of entities to create
Returns
Vector containing all created entity IDs

Definition at line 390 of file Registry.hpp.

References create().

◆ destroy()

void esengine::ecs::Registry::destroy ( Entity entity)
inline

Destroys an entity and removes all its components.

Parameters
entityThe entity to destroy

The entity ID is recycled for future use. All components attached to the entity are removed.

Definition at line 449 of file Registry.hpp.

References esengine::ecs::ENTITY_CHANGE_SUBTREE, ES_LOG_TRACE, esengine::Entity::GEN_MASK, esengine::Entity::index(), esengine::ecs::invalidateTransformComposition(), esengine::Entity::raw, recordEntityChange(), and valid().

Referenced by esengine::aot::applyCommands(), esengine::ecs::destroyWithChildren(), EMSCRIPTEN_BINDINGS(), and esengine::animation::TweenSystem::update().

◆ destructionPending()

bool esengine::ecs::Registry::destructionPending ( Entity entity) const
inline

◆ each()

template<typename... Components, typename Func>
void esengine::ecs::Registry::each ( Func && func)
inline

Executes a function for each entity with specified components.

Template Parameters
ComponentsThe required component types
FuncThe callback type
Parameters
funcCallback receiving (Entity, Component&...)
registry.each<Position, Velocity>([](Entity e, Position& p, Velocity& v) {
p.x += v.x;
});

Definition at line 881 of file Registry.hpp.

References each(), and view().

Referenced by esengine::ecs::canvasRoots(), each(), and esengine::RenderFrame::keepScreenOverlay().

◆ eachChangedSince()

template<typename T, typename Visit>
void esengine::ecs::Registry::eachChangedSince ( u32 tick,
Visit && visit )
inline

Calls visit(entity, component) for each T written, added or replaced after tick, in storage order.

One pass down the pool's dense arrays (entities, components, stamps side by side), so a visit is handed its component without a lookup. visit must not add or remove a T.

Definition at line 271 of file Registry.hpp.

References esengine::ecs::tickAfter().

◆ eachLive()

template<typename... Components, typename Func>
void esengine::ecs::Registry::eachLive ( Func && func)
inline

each() without the per-call snapshot copy, for read-only passes.

Warning
The callback must not emplace/remove the iterated component(s).

Definition at line 890 of file Registry.hpp.

References eachLive(), and view().

Referenced by esengine::ecs::applySceneEntityOrder(), eachLive(), and esengine::ecs::UISystem::hitInputsChanged().

◆ emplace()

template<typename T, typename... Args>
T & esengine::ecs::Registry::emplace ( Entity entity,
Args &&... args )
inline

Adds a component to an entity with in-place construction.

Template Parameters
TThe component type
ArgsConstructor argument types
Parameters
entityThe target entity
argsArguments forwarded to T's constructor
Returns
Reference to the newly created component
Note
An invalid entity is fatal in every build; the component already being there degrades to the existing one (see SparseSet::emplace).

Definition at line 576 of file Registry.hpp.

References esengine::componentTypeId(), ES_VERIFY_FATAL, esengine::Entity::index(), and valid().

Referenced by esengine::animation::TweenSystem::createTween(), esengine::renderer_renderMaterialPreview(), esengine::renderer_renderMeshPreview(), esengine::ecs::setParent(), and esengine::ecs::syncHierarchyComponents().

◆ emplaceOrReplace()

template<typename T, typename... Args>
T & esengine::ecs::Registry::emplaceOrReplace ( Entity entity,
Args &&... args )
inline

Adds or replaces a component on an entity.

Template Parameters
TThe component type
ArgsConstructor argument types
Parameters
entityThe target entity
argsArguments forwarded to T's constructor
Returns
Reference to the component

If the entity already has the component, it is replaced.

Definition at line 599 of file Registry.hpp.

References esengine::componentTypeId(), esengine::ecs::ENTITY_CHANGE_REPLACED, ES_VERIFY_FATAL, esengine::Entity::index(), and valid().

Referenced by EMSCRIPTEN_BINDINGS().

◆ entitiesWith()

template<typename T>
std::span< const Entity > esengine::ecs::Registry::entitiesWith ( ) const
inline

The entities that carry T, densely.

Returns
The pool's dense entity array, or an empty span where no pool exists

What View narrows to internally, opened for a caller that assembles its query at run time from NAMES, as the AOT host does. Empty means nobody has it — never "ask everybody".

Definition at line 931 of file Registry.hpp.

Referenced by esengine::aot::engineComponentCandidates().

◆ entityChangeResetEpoch()

double esengine::ecs::Registry::entityChangeResetEpoch ( ) const
inline

Definition at line 131 of file Registry.hpp.

Referenced by esengine::registry_entityChangeResetEpoch().

◆ entityChangeSequence()

double esengine::ecs::Registry::entityChangeSequence ( ) const
inline

◆ entityCount()

usize esengine::ecs::Registry::entityCount ( ) const
inline

Definition at line 525 of file Registry.hpp.

Referenced by EMSCRIPTEN_BINDINGS().

◆ forEachEntity()

template<typename Func>
void esengine::ecs::Registry::forEachEntity ( Func && func) const
inline

Executes a function for each valid entity.

Template Parameters
FuncThe callback type
Parameters
funcCallback receiving Entity

Definition at line 552 of file Registry.hpp.

References esengine::Entity::make().

◆ get() [1/2]

◆ get() [2/2]

template<typename T>
const T & esengine::ecs::Registry::get ( Entity entity) const
inline

Gets a component from an entity (must exist).

Template Parameters
TThe component type
Parameters
entityThe target entity
Returns
Reference to the component
Note
A missing component is fatal in every build — the contract is that the caller knows it is there. Use tryGet() where absence is expected and getOrEmplace() where the component should be created.

Definition at line 657 of file Registry.hpp.

References ES_VERIFY_FATAL.

◆ getOrEmplace()

template<typename T, typename... Args>
T & esengine::ecs::Registry::getOrEmplace ( Entity entity,
Args &&... args )
inline

Gets an existing component or creates a new one.

Template Parameters
TThe component type
ArgsConstructor argument types (for new component)
Parameters
entityThe target entity
argsArguments forwarded to T's constructor if creating
Returns
Reference to the component

Definition at line 691 of file Registry.hpp.

References esengine::componentTypeId(), ES_VERIFY_FATAL, esengine::Entity::index(), and valid().

◆ has()

◆ hasAll()

template<typename... Ts>
bool esengine::ecs::Registry::hasAll ( Entity entity) const
inline

Checks if an entity has all specified components.

Template Parameters
TsThe component types to check
Parameters
entityThe entity to check
Returns
True if the entity has all components

Definition at line 723 of file Registry.hpp.

References has().

◆ hasAny()

template<typename... Ts>
bool esengine::ecs::Registry::hasAny ( Entity entity) const
inline

Checks if an entity has any of the specified components.

Template Parameters
TsThe component types to check
Parameters
entityThe entity to check
Returns
True if the entity has at least one component

Definition at line 734 of file Registry.hpp.

References has().

◆ hasInactiveEntities()

bool esengine::ecs::Registry::hasInactiveEntities ( ) const
inline

Definition at line 121 of file Registry.hpp.

Referenced by EMSCRIPTEN_BINDINGS().

◆ identity()

u64 esengine::ecs::Registry::identity ( ) const
inline

Which registry this is, never shared with another made in this process (a registry assigned over this one brings its own). Ticks and entities are each registry's own, so a reader that keeps what it derived from one asks this before trusting a tick or an entity it kept.

Definition at line 166 of file Registry.hpp.

Referenced by esengine::MeshPlugin::castInputs(), esengine::ecs::UISystem::hitInputsChanged(), and esengine::RenderFrame::keepScreenOverlay().

◆ instanceId()

u64 esengine::ecs::Registry::instanceId ( ) const
inline

Which registry this is — unique for the process, never reused.

Entity ids are only meaningful WITHIN a registry: a fresh one hands out 1, 2, 3 again, so anything caching per entity across registries (a scene reload, an editor play/stop) would silently serve the previous world's data for the new world's entities. Comparing addresses cannot answer this — a destroyed registry's storage is routinely reused by the next one. Systems that keep per-entity state hold this alongside it and drop the lot when it changes; see UISystem's retained Yoga nodes.

Definition at line 96 of file Registry.hpp.

References instanceId().

Referenced by esengine::ecs::TransformSystem::ensureComposed(), instanceId(), esengine::ecs::UISystem::isScreenDomain(), and esengine::ecs::UISystem::layoutUpdate().

◆ invalidateActivityHierarchy()

void esengine::ecs::Registry::invalidateActivityHierarchy ( Entity root = INVALID_ENTITY)
inline

◆ isEntityActive()

◆ isEntityEnabled()

bool esengine::ecs::Registry::isEntityEnabled ( Entity e) const
inline

Definition at line 111 of file Registry.hpp.

References esengine::Entity::index(), and valid().

Referenced by EMSCRIPTEN_BINDINGS().

◆ lastChangedTick()

template<typename T>
u32 esengine::ecs::Registry::lastChangedTick ( ) const
inline

The tick of the latest write, addition or removal of any T; 0 when there has been none.

Definition at line 291 of file Registry.hpp.

◆ layoutEpoch()

double esengine::ecs::Registry::layoutEpoch ( ) const
inline

Sum of every pool's version — one number for "did anything move".

Returns
Equal across two reads ⇒ no stored component changed address

A holder of RAW ADDRESSES (the AOT row table) needs one cheap question, and one that covers pools it never asked about: a C++ insert moves that pool with no JS call in it. u64 so it cannot wrap onto a value already seen; double because JS takes that.

Definition at line 853 of file Registry.hpp.

Referenced by esengine::registryLayoutEpoch().

◆ markChanged()

◆ markChangedById()

void esengine::ecs::Registry::markChangedById ( u32 typeId,
Entity entity )
inline

markChanged by a component type id (componentTypeId): for a writer that names the type at run time, a script.

Definition at line 201 of file Registry.hpp.

Referenced by EMSCRIPTEN_BINDINGS(), and esengine::registry_markComponentsChanged().

◆ onDestroy()

Connection esengine::ecs::Registry::onDestroy ( DestroyCallback callback)
inlinenodiscard

Subscribe to entity destruction.

Returns
An RAII Connection. The callback stays registered for as long as the returned Connection is alive; on its destruction the callback is removed. The Connection is also safe to outlive the Registry — it no-ops against a destroyed signal — so subscribers and the Registry can tear down in either order without a dangling callback.

Definition at line 509 of file Registry.hpp.

References esengine::sink().

Referenced by esengine::particle::ParticleSystem::update(), esengine::springbone::SpringBoneSystem::update(), and esengine::trail::TrailSystem::update().

◆ operator=() [1/2]

Registry & esengine::ecs::Registry::operator= ( const Registry & )
delete

References Registry().

◆ operator=() [2/2]

Registry & esengine::ecs::Registry::operator= ( Registry && )
defaultnoexcept

References Registry().

◆ patch()

template<typename T>
T & esengine::ecs::Registry::patch ( Entity entity)
inline

Mutable access that says it writes: entity's T, stamped. Fatal where it has none, as get<T>() is.

Definition at line 186 of file Registry.hpp.

References ES_VERIFY_FATAL.

Referenced by esengine::ecs::syncHierarchyComponents().

◆ poolVersion()

template<typename T>
u32 esengine::ecs::Registry::poolVersion ( ) const
inline

T's pool version: moves when a T is removed or the pool's storage moves (SparseSetBase::version). 0 with no pool.

Definition at line 260 of file Registry.hpp.

◆ readEntityChanges()

i32 esengine::ecs::Registry::readEntityChanges ( double after,
std::span< EntityChangeRow > output ) const
inline

Definition at line 137 of file Registry.hpp.

Referenced by esengine::registry_readEntityChanges().

◆ recordEntityChange()

void esengine::ecs::Registry::recordEntityChange ( Entity entity,
u32 flags = 0,
u32 component = ENTITY_CHANGE_NO_COMPONENT )
inline

◆ releaseDestruction()

void esengine::ecs::Registry::releaseDestruction ( Entity entity)
inline

◆ remove()

template<typename T>
void esengine::ecs::Registry::remove ( Entity entity)
inline

Removes a component from an entity.

Template Parameters
TThe component type to remove
Parameters
entityThe target entity

No-op if the entity doesn't have the component.

Definition at line 625 of file Registry.hpp.

References esengine::componentTypeId(), and esengine::Entity::index().

Referenced by EMSCRIPTEN_BINDINGS(), and esengine::ecs::syncHierarchyComponents().

◆ reserveDestruction()

bool esengine::ecs::Registry::reserveDestruction ( Entity entity)
inline

Internal subtree ownership. Components remain readable for callbacks, but a pending entity cannot receive links or be reserved a second time.

Definition at line 423 of file Registry.hpp.

References esengine::Entity::index(), and valid().

Referenced by esengine::ecs::destroyWithChildren(), and EMSCRIPTEN_BINDINGS().

◆ restore()

Entity esengine::ecs::Registry::restore ( u32 index)
inline

Restores an entity at a specific index.

Parameters
indexThe entity index to restore
Returns
The newly created Entity, or INVALID_ENTITY if index is already alive

Definition at line 404 of file Registry.hpp.

References ES_VERIFY, esengine::Entity::INDEX_MASK, and esengine::INVALID_ENTITY.

◆ retiredSlots()

u32 esengine::ecs::Registry::retiredSlots ( ) const
inline

Slots permanently out of circulation, their generation spent.

Zero for anything but sustained create/destroy on the same indices. Rising steadily is the signal that churn is eating index space — the price paid so a destroyed entity's handle can never come back as a live one.

Definition at line 544 of file Registry.hpp.

◆ setChangeAudit()

void esengine::ecs::Registry::setChangeAudit ( bool enabled)
inline

Turns the change audit on or off. On, auditChanges() compares every auditable component with the copy it kept and reports each one whose bytes changed with no stamp to say so — a write some consumer will never see.

A check for tests and gates: it copies every component once per audit.

Definition at line 301 of file Registry.hpp.

References auditChanges().

Referenced by EMSCRIPTEN_BINDINGS().

◆ setEntityEnabled()

bool esengine::ecs::Registry::setEntityEnabled ( Entity e,
bool enabled )
inline

◆ sort()

template<typename T, typename Compare>
void esengine::ecs::Registry::sort ( Compare compare)
inline

Sorts components by a comparison function.

Template Parameters
TThe component type to sort
CompareThe comparison function type
Parameters
compareComparison function returning true if first < second

Sorts the component pool so iteration order matches the comparison result.

Definition at line 904 of file Registry.hpp.

◆ tryGet() [1/2]

template<typename T>
T * esengine::ecs::Registry::tryGet ( Entity entity)
inline

Tries to get a component from an entity.

Template Parameters
TThe component type
Parameters
entityThe target entity
Returns
Pointer to the component, or nullptr if not found

Definition at line 670 of file Registry.hpp.

Referenced by esengine::anim_getTweenState(), esengine::anim_setSequenceNext(), esengine::anim_setTweenBezier(), esengine::animation::applyTweenValue(), esengine::ecs::assignRenderOrder(), esengine::animation::TweenSystem::cancelTween(), esengine::ecs::canvasRoots(), esengine::ecs::copyFlatRenderMatrix(), EMSCRIPTEN_BINDINGS(), EMSCRIPTEN_BINDINGS(), esengine::aot::engineComponentAt(), esengine::getUINodeAlphaInTree(), esengine::getUINodeComputedHeight(), esengine::getUINodeComputedWidth(), esengine::getUINodeHiddenInTree(), esengine::ecs::UISystem::hitTestUpdate(), esengine::ecs::isClippedByMask(), esengine::animation::markUIAnimOverride(), esengine::meshInstances_set(), esengine::meshRenderer_makeAllResident(), esengine::meshRenderer_setGeometry(), esengine::meshRenderer_setMaterialAll(), esengine::meshRenderer_setMeshAll(), esengine::animation::TweenSystem::pauseTween(), esengine::ecs::UISystem::pickAll(), esengine::MeshPlugin::prewarm(), esengine::renderer_retainedTextStale(), esengine::renderer_submitSkeletalBatchByEntityEx(), esengine::animation::TweenSystem::resumeTween(), esengine::RenderFrame::submitRetainedText(), esengine::ecs::syncHierarchyComponents(), esengine::ui_getCullBit(), esengine::ui_getRenderOrder(), esengine::uiNode_computedHeight(), esengine::uiNode_computedWidth(), esengine::animation::TweenSystem::update(), and esengine::springbone::SpringBoneSystem::update().

◆ tryGet() [2/2]

template<typename T>
const T * esengine::ecs::Registry::tryGet ( Entity entity) const
inline

Tries to get a component from an entity.

Template Parameters
TThe component type
Parameters
entityThe target entity
Returns
Pointer to the component, or nullptr if not found

Definition at line 677 of file Registry.hpp.

◆ unwatchEntityChanges()

void esengine::ecs::Registry::unwatchEntityChanges ( u32 reader)
inline

Definition at line 129 of file Registry.hpp.

Referenced by esengine::registry_unwatchEntityChanges().

◆ valid()

◆ view()

template<typename... Components>
View< Components... > esengine::ecs::Registry::view ( )
inline

Creates a view for iterating entities with specific components.

Template Parameters
ComponentsThe component types to query
Returns
A View for iterating matching entities
// Single component view
for (auto entity : registry.view<Position>()) {
auto& pos = registry.get<Position>(entity);
}
// Multi-component view: range-for yields the entities that have them all
auto view = registry.view<Position, Velocity>();
for (Entity e : view) {
view.get<Position>(e).x += view.get<Velocity>(e).x * dt;
}
View< Components... > view()
Creates a view for iterating entities with specific components.
Definition Registry.hpp:761

Definition at line 761 of file Registry.hpp.

Referenced by esengine::ecs::GroupOpacityLookup::GroupOpacityLookup(), activeView(), esengine::animation::TweenSystem::cancelAllTweens(), each(), eachLive(), esengine::ecs::UISystem::layoutUpdate(), esengine::meshRenderer_makeAllResident(), esengine::meshRenderer_setMaterialAll(), esengine::meshRenderer_setMeshAll(), and esengine::animation::TweenSystem::update().

◆ watchEntityChanges()

u32 esengine::ecs::Registry::watchEntityChanges ( )
inline

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