Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
Relation.hpp File Reference

A relationship between entities, stored as one: (Relation, target) pairs in the manner of Flecs. More...

#include "../core/Types.hpp"
#include <algorithm>
#include <vector>
Include dependency graph for Relation.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

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

Namespaces

namespace  esengine
namespace  esengine::ecs

Detailed Description

A relationship between entities, stored as one: (Relation, target) pairs in the manner of Flecs.

An exclusive relation gives an entity at most one target (ChildOf: one parent). It is kept in flat arrays indexed by entity index, struct of arrays, rather than as a component holding a list:

target the entity's one target, or none first the first entity that names this one as its target (its first child) last the last such entity next the next entity with the same target (the next sibling) prev the previous one count how many entities name this one depth how many links lie between the entity and the root of its tree

Every edit is O(1) and allocates nothing once the arrays have grown to the entity count: linking, unlinking, and moving an entity within its siblings touch a constant number of slots. A walk over an entity's sources (its children) follows next through one array. The arrays are plain u32 in linear memory, so a script can read them where they lie instead of asking for a copy.

Flecs stores a pair as part of an archetype's type, which suits its table storage; this engine stores components in sparse sets, where the answer to "the sources of this target, in order" is an intrusive list, and the answer to "this entity's target" is one array read.

A slot belongs to whichever entity holds that index now: the registry clears an entity's slots when it destroys the entity (onDestroy), so no slot outlives its entity and none needs a generation check on read.

Definition in file Relation.hpp.