|
Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
|
#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 |
Definition at line 38 of file Relation.hpp.
|
inline |
Definition at line 258 of file Relation.hpp.
|
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.
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.
|
inline |
Definition at line 188 of file Relation.hpp.
How many entities name target.
Definition at line 52 of file Relation.hpp.
References target().
Referenced by hasSources(), sortSources(), and sources().
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().
|
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().
|
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.
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().
|
inline |
Definition at line 256 of file Relation.hpp.
|
inline |
Definition at line 53 of file Relation.hpp.
|
inline |
|
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().
Definition at line 47 of file Relation.hpp.
References esengine::Entity::fromRaw(), and target().
|
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().
|
inline |
How many entities have a target: the size of (Relation, *).
Definition at line 57 of file Relation.hpp.
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().
|
inline |
Definition at line 257 of file Relation.hpp.
|
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.
Definition at line 50 of file Relation.hpp.
References esengine::Entity::fromRaw().
Referenced by sortSources().
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().
|
inline |
Puts target's sources in the order of rank (per entity index, lower first; stable; past the end last).
Definition at line 139 of file Relation.hpp.
References count(), esengine::Entity::fromRaw(), esengine::Entity::index(), NONE, prev(), sources(), and target().
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().
|
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.
Definition at line 203 of file Relation.hpp.
References esengine::Entity::fromRaw().
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().
|
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.
|
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.
|
staticconstexpr |
Definition at line 40 of file Relation.hpp.
Referenced by cascadeAt(), eachSource(), hasTarget(), isDescendantOf(), link(), onDestroy(), and sortSources().