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

#include <Relation.hpp>

Classes

struct  CascadeEntry
 One entity of a tree, in cascade order. More...
struct  CascadeTree
 One tree, root first, every entity after its target and in its siblings' order (preorder). More...
struct  CascadeAt
 Where an entity sits in the cascade: which tree, and where in it. More...

Public Member Functions

Entity target (Entity source) const
 The entity's target (its parent), or INVALID_ENTITY.
bool hasTarget (Entity source) const
Entity first (Entity target) const
 The first / last entity naming target (first and last child), or INVALID_ENTITY.
Entity last (Entity target) const
Entity next (Entity source) const
 The entity after / before source among those naming the same target (siblings), or INVALID_ENTITY.
Entity prev (Entity source) const
u32 count (Entity target) const
 How many entities name target.
bool hasSources (Entity target) const
u32 depth (Entity entity) const
 Links between entity and the root of its tree: 0 for a root.
u32 linkCount () const
 How many entities have a target: the size of (Relation, *).
u32 epoch () const
 Bumped by every edit to the relation's shape, so a cache built from it can tell it is stale.
template<typename Visit>
void eachSource (Entity target, Visit &&visit) const
 Calls visit(source) for each entity naming target, in order. visit must not edit the relation.
std::vector< Entity > sources (Entity target) const
 The entities naming target, in order: for a caller that edits the relation while it walks them.
bool isDescendantOf (Entity entity, Entity ancestor) const
 Whether ancestor is entity's target, or its target's, and so on up. Bounded: no cycle can form here.
Entity root (Entity entity) const
 The top of entity's tree (itself when it has no target).
void link (Entity source, Entity target, Entity before=INVALID_ENTITY)
 Gives source the target target, placed before before among its sources (last when before is none).
void unlink (Entity source)
 Takes source's target away; its own sources stay with it.
bool sortSources (Entity target, const std::vector< u32 > &rank)
 Puts target's sources in the order of rank (per entity index, lower first; stable; past the end last).
void onDestroy (Entity entity)
 Forgets entity, which is being destroyed: it leaves its target, and its sources become roots.
void clear ()
bool takeRetargeted (std::vector< Entity > &out)
 Hands over the entities whose target changed since the last call (moved, detached, orphaned by a destroyed target), and empties the list. One reader: whoever takes it, takes it for everyone.
const std::vector< CascadeTree > & cascade () const
 Every tree of the relation, each in cascade order: Flecs' cascade, one array per tree.
CascadeAt cascadeAt (Entity entity) const
 Where entity sits in cascade(), or tree NONE when it is in no tree. Current as of the last cascade() call.
const u32 * targets () const
 The arrays themselves, for a reader across the wasm boundary; valid until the next edit that grows them.
const u32 * firsts () const
const u32 * nexts () const
usize capacity () const

Static Public Attributes

static constexpr u32 NONE = Entity::INVALID_RAW

Detailed Description

Definition at line 38 of file Relation.hpp.

Member Function Documentation

◆ capacity()

usize esengine::ecs::ExclusiveRelation::capacity ( ) const
inline

Definition at line 258 of file Relation.hpp.

◆ cascade()

const std::vector< CascadeTree > & esengine::ecs::ExclusiveRelation::cascade ( ) const
inline

Every tree of the relation, each in cascade order: Flecs' cascade, one array per tree.

A walk from the front of a tree sees a parent before any of its children, so a caller that needs the parent's result reads it by parent from what it wrote earlier in the same walk. Kept per tree so an edit rebuilds only the trees it touched (the one an entity left and the one it joined), in O(their size), not every tree. Skip the entries whose tree is not alive. Only entities in a tree are listed: a root with no sources is not.

Definition at line 242 of file Relation.hpp.

◆ cascadeAt()

CascadeAt esengine::ecs::ExclusiveRelation::cascadeAt ( Entity entity) const
inline

Where entity sits in cascade(), or tree NONE when it is in no tree. Current as of the last cascade() call.

Definition at line 248 of file Relation.hpp.

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

◆ clear()

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

Definition at line 188 of file Relation.hpp.

◆ count()

u32 esengine::ecs::ExclusiveRelation::count ( Entity target) const
inline

How many entities name target.

Definition at line 52 of file Relation.hpp.

References target().

Referenced by hasSources(), sortSources(), and sources().

◆ depth()

u32 esengine::ecs::ExclusiveRelation::depth ( Entity entity) const
inline

Links between entity and the root of its tree: 0 for a root.

Definition at line 55 of file Relation.hpp.

References esengine::Entity::index().

◆ eachSource()

template<typename Visit>
void esengine::ecs::ExclusiveRelation::eachSource ( Entity target,
Visit && visit ) const
inline

Calls visit(source) for each entity naming target, in order. visit must not edit the relation.

Definition at line 63 of file Relation.hpp.

References esengine::Entity::fromRaw(), esengine::Entity::index(), NONE, and target().

Referenced by sources().

◆ epoch()

u32 esengine::ecs::ExclusiveRelation::epoch ( ) const
inline

Bumped by every edit to the relation's shape, so a cache built from it can tell it is stale.

Definition at line 59 of file Relation.hpp.

◆ first()

Entity esengine::ecs::ExclusiveRelation::first ( Entity target) const
inline

The first / last entity naming target (first and last child), or INVALID_ENTITY.

Definition at line 46 of file Relation.hpp.

References esengine::Entity::fromRaw(), and target().

◆ firsts()

const u32 * esengine::ecs::ExclusiveRelation::firsts ( ) const
inline

Definition at line 256 of file Relation.hpp.

◆ hasSources()

bool esengine::ecs::ExclusiveRelation::hasSources ( Entity target) const
inline

Definition at line 53 of file Relation.hpp.

References count(), and target().

◆ hasTarget()

bool esengine::ecs::ExclusiveRelation::hasTarget ( Entity source) const
inline

Definition at line 44 of file Relation.hpp.

References NONE.

Referenced by link(), root(), and unlink().

◆ isDescendantOf()

bool esengine::ecs::ExclusiveRelation::isDescendantOf ( Entity entity,
Entity ancestor ) const
inline

Whether ancestor is entity's target, or its target's, and so on up. Bounded: no cycle can form here.

Definition at line 78 of file Relation.hpp.

References esengine::Entity::fromRaw(), NONE, and esengine::Entity::raw.

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

◆ last()

Entity esengine::ecs::ExclusiveRelation::last ( Entity target) const
inline

Definition at line 47 of file Relation.hpp.

References esengine::Entity::fromRaw(), and target().

◆ link()

void esengine::ecs::ExclusiveRelation::link ( Entity source,
Entity target,
Entity before = INVALID_ENTITY )
inline

Gives source the target target, placed before before among its sources (last when before is none).

The caller has checked the edit: both are live, source is not target or one of its ancestors. A source with a target already is moved, keeping nothing of where it was. Depth follows for the whole moved subtree.

Definition at line 96 of file Relation.hpp.

References esengine::Entity::fromRaw(), hasTarget(), esengine::Entity::index(), esengine::INVALID_ENTITY, NONE, esengine::Entity::raw, and target().

◆ linkCount()

u32 esengine::ecs::ExclusiveRelation::linkCount ( ) const
inline

How many entities have a target: the size of (Relation, *).

Definition at line 57 of file Relation.hpp.

◆ next()

Entity esengine::ecs::ExclusiveRelation::next ( Entity source) const
inline

The entity after / before source among those naming the same target (siblings), or INVALID_ENTITY.

Definition at line 49 of file Relation.hpp.

References esengine::Entity::fromRaw().

◆ nexts()

const u32 * esengine::ecs::ExclusiveRelation::nexts ( ) const
inline

Definition at line 257 of file Relation.hpp.

◆ onDestroy()

void esengine::ecs::ExclusiveRelation::onDestroy ( Entity entity)
inline

Forgets entity, which is being destroyed: it leaves its target, and its sources become roots.

Called by the registry for every destroyed entity, so a slot never outlives the entity that owned it. Removing the sources is this relation's policy for a destroyed target; a caller that wants them gone as well (destroyWithChildren) destroys them first.

Definition at line 165 of file Relation.hpp.

References esengine::Entity::fromRaw(), esengine::Entity::index(), and NONE.

◆ prev()

Entity esengine::ecs::ExclusiveRelation::prev ( Entity source) const
inline

Definition at line 50 of file Relation.hpp.

References esengine::Entity::fromRaw().

Referenced by sortSources().

◆ root()

Entity esengine::ecs::ExclusiveRelation::root ( Entity entity) const
inline

The top of entity's tree (itself when it has no target).

Definition at line 86 of file Relation.hpp.

References hasTarget(), and target().

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

◆ sortSources()

bool esengine::ecs::ExclusiveRelation::sortSources ( Entity target,
const std::vector< u32 > & rank )
inline

Puts target's sources in the order of rank (per entity index, lower first; stable; past the end last).

Returns
Whether the order changed.

Definition at line 139 of file Relation.hpp.

References count(), esengine::Entity::fromRaw(), esengine::Entity::index(), NONE, prev(), sources(), and target().

◆ sources()

std::vector< Entity > esengine::ecs::ExclusiveRelation::sources ( Entity target) const
inline

The entities naming target, in order: for a caller that edits the relation while it walks them.

Definition at line 70 of file Relation.hpp.

References count(), eachSource(), and target().

Referenced by sortSources().

◆ takeRetargeted()

bool esengine::ecs::ExclusiveRelation::takeRetargeted ( std::vector< Entity > & out)
inline

Hands over the entities whose target changed since the last call (moved, detached, orphaned by a destroyed target), and empties the list. One reader: whoever takes it, takes it for everyone.

Returns
false when the list overflowed (or the relation was cleared): too many to list, so the reader treats all as moved.

Definition at line 203 of file Relation.hpp.

References esengine::Entity::fromRaw().

◆ target()

Entity esengine::ecs::ExclusiveRelation::target ( Entity source) const
inline

The entity's target (its parent), or INVALID_ENTITY.

Definition at line 43 of file Relation.hpp.

References esengine::Entity::fromRaw().

Referenced by count(), eachSource(), first(), hasSources(), last(), link(), root(), sortSources(), and sources().

◆ targets()

const u32 * esengine::ecs::ExclusiveRelation::targets ( ) const
inline

The arrays themselves, for a reader across the wasm boundary; valid until the next edit that grows them.

Definition at line 255 of file Relation.hpp.

◆ unlink()

void esengine::ecs::ExclusiveRelation::unlink ( Entity source)
inline

Takes source's target away; its own sources stay with it.

Definition at line 125 of file Relation.hpp.

References hasTarget(), and esengine::Entity::raw.

Member Data Documentation

◆ NONE

u32 esengine::ecs::ExclusiveRelation::NONE = Entity::INVALID_RAW
staticconstexpr

Definition at line 40 of file Relation.hpp.

Referenced by cascadeAt(), eachSource(), hasTarget(), isDescendantOf(), link(), onDestroy(), and sortSources().


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