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

Entity identifier with packed index + generation. More...

#include <Types.hpp>

Public Types

using Layout = PackedId<22, 10>

Public Member Functions

constexpr Entity ()
constexpr Entity (u32 r)
constexpr operator u32 () const
constexpr u32 index () const
 Gets the entity index.
constexpr u32 generation () const
 Gets the generation number.
constexpr bool isValid () const
 Checks if this is not the invalid sentinel.
constexpr u32 id () const
 Returns the raw packed value for FFI serialization.
constexpr bool operator== (Entity other) const
constexpr bool operator!= (Entity other) const

Static Public Member Functions

static constexpr Entity fromRaw (u32 v)
 Reconstructs an Entity from a raw packed value.
static constexpr Entity make (u32 idx, u32 gen)
 Creates an Entity from index and generation.

Public Attributes

u32 raw

Static Public Attributes

static constexpr u32 INDEX_BITS = Layout::INDEX_BITS
static constexpr u32 GEN_BITS = Layout::GEN_BITS
static constexpr u32 INDEX_MASK = Layout::INDEX_MASK
static constexpr u32 GEN_MASK = Layout::GEN_MASK
static constexpr u32 INVALID_RAW = 0xFFFFFFFF

Detailed Description

Entity identifier with packed index + generation.

Entities pack a 22-bit index and 10-bit generation into a single u32. The generation detects stale references after an entity is destroyed and its index recycled (ABA problem). The bit-packing math lives once in PackedId; this just wires Entity to it.

Layout: [generation(10) | index(22)]

  • Max entities: 4,194,303 (2^22 - 1)
  • Max generations: 1,023 (2^10 - 1) before wrap

The split is u32 (4 bytes) on purpose — see PackedId.hpp for why (FFI as a plain JS number, box2d 32-bit user-data, dense-array cache behaviour). PackedId's static_assert enforces it.

Definition at line 135 of file Types.hpp.

Member Typedef Documentation

◆ Layout

Definition at line 138 of file Types.hpp.

Constructor & Destructor Documentation

◆ Entity() [1/2]

esengine::Entity::Entity ( )
inlineconstexpr

Definition at line 145 of file Types.hpp.

References INVALID_RAW, and raw.

Referenced by fromRaw(), make(), operator!=(), and operator==().

◆ Entity() [2/2]

esengine::Entity::Entity ( u32 r)
inlineexplicitconstexpr

Definition at line 146 of file Types.hpp.

References raw.

Member Function Documentation

◆ fromRaw()

constexpr Entity esengine::Entity::fromRaw ( u32 v)
inlinestaticconstexpr

Reconstructs an Entity from a raw packed value.

Definition at line 162 of file Types.hpp.

References Entity().

Referenced by esengine::anim_cancelAllTweens(), esengine::anim_cancelTween(), esengine::anim_createTween(), esengine::anim_getTweenState(), esengine::anim_pauseTween(), esengine::anim_resumeTween(), esengine::anim_setSequenceNext(), esengine::anim_setTweenBezier(), esengine::aot::applyCommands(), esengine::ecs::ExclusiveRelation::eachSource(), esengine::aot::engineComponentAt(), esengine::ecs::ExclusiveRelation::first(), esengine::getUINodeAlphaInTree(), esengine::getUINodeComputedHeight(), esengine::getUINodeComputedWidth(), esengine::getUINodeHiddenInTree(), esengine::ecs::ExclusiveRelation::isDescendantOf(), esengine::ecs::UISystem::isScreenDomain(), esengine::ecs::ExclusiveRelation::last(), esengine::ecs::ExclusiveRelation::link(), esengine::meshInstances_set(), esengine::meshRenderer_setGeometry(), esengine::ecs::ExclusiveRelation::next(), esengine::ecs::ExclusiveRelation::onDestroy(), esengine::ecs::ExclusiveRelation::prev(), esengine::registry_batchSyncPhysicsTransforms(), esengine::registry_getGeneration(), esengine::registry_markComponentsChanged(), esengine::registry_readWorldPoses2D(), esengine::renderer_clusterInspect(), esengine::renderer_entityVisibleToCamera(), esengine::renderer_lightStatus(), esengine::renderer_lodInspect(), esengine::renderer_retainedTextStale(), esengine::renderer_setEntityDrawOrder(), esengine::renderer_setImpostorAtlas(), esengine::renderer_setLodPreview(), esengine::renderer_setViewSkinWeights(), esengine::renderer_shadowStatus(), esengine::renderer_submitSkeletalBatchByEntityEx(), esengine::renderer_submitTextBatch(), esengine::particle::ParticleSystem::resolveCollisions(), esengine::ecs::UISystem::screenRootOf(), esengine::ecs::ExclusiveRelation::sortSources(), esengine::springbone_release(), esengine::springbone_reset(), esengine::springbone_snapshot(), esengine::RenderFrame::submitRetainedText(), esengine::ecs::ExclusiveRelation::takeRetargeted(), esengine::ecs::ExclusiveRelation::target(), esengine::trail_clear(), esengine::transform_copyFlatRenderMatrix(), esengine::ui_getCullBit(), esengine::ui_getRenderOrder(), esengine::uiNode_computedHeight(), esengine::uiNode_computedWidth(), and esengine::particle::ParticleSystem::update().

◆ generation()

u32 esengine::Entity::generation ( ) const
inlineconstexpr

◆ id()

◆ index()

◆ isValid()

bool esengine::Entity::isValid ( ) const
inlineconstexpr

Checks if this is not the invalid sentinel.

Definition at line 156 of file Types.hpp.

References INVALID_RAW, and raw.

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

◆ make()

constexpr Entity esengine::Entity::make ( u32 idx,
u32 gen )
inlinestaticconstexpr

Creates an Entity from index and generation.

Definition at line 165 of file Types.hpp.

References Entity(), and esengine::PackedId< 22, 10 >::pack().

Referenced by esengine::ecs::Registry::forEachEntity().

◆ operator u32()

esengine::Entity::operator u32 ( ) const
inlineexplicitconstexpr

Definition at line 147 of file Types.hpp.

References raw.

◆ operator!=()

bool esengine::Entity::operator!= ( Entity other) const
inlineconstexpr

Definition at line 168 of file Types.hpp.

References Entity(), and raw.

◆ operator==()

bool esengine::Entity::operator== ( Entity other) const
inlineconstexpr

Definition at line 167 of file Types.hpp.

References Entity(), and raw.

Member Data Documentation

◆ GEN_BITS

u32 esengine::Entity::GEN_BITS = Layout::GEN_BITS
staticconstexpr

Definition at line 140 of file Types.hpp.

◆ GEN_MASK

u32 esengine::Entity::GEN_MASK = Layout::GEN_MASK
staticconstexpr

Definition at line 142 of file Types.hpp.

Referenced by esengine::ecs::Registry::destroy().

◆ INDEX_BITS

u32 esengine::Entity::INDEX_BITS = Layout::INDEX_BITS
staticconstexpr

Definition at line 139 of file Types.hpp.

◆ INDEX_MASK

u32 esengine::Entity::INDEX_MASK = Layout::INDEX_MASK
staticconstexpr

Definition at line 141 of file Types.hpp.

Referenced by esengine::ecs::Registry::restore().

◆ INVALID_RAW

u32 esengine::Entity::INVALID_RAW = 0xFFFFFFFF
staticconstexpr

Definition at line 143 of file Types.hpp.

Referenced by Entity(), and isValid().

◆ raw


The documentation for this struct was generated from the following file:
  • /home/runner/work/estella/estella/src/esengine/core/Types.hpp