Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
TransformSystem.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
15#pragma once
16
17#include "System.hpp"
18#include "Registry.hpp"
19#include "TransformEpoch.hpp"
22#include "FlatGeometry.hpp"
23#include "../math/Math.hpp"
24
25#include <algorithm>
26
27namespace esengine::ecs {
28
29class TransformSystem : public System {
30public:
32 setPriority(-100);
33 }
34
35 void init(Registry& registry) override {
36 (void)registry;
37 }
38
39 void update(World& world) override { compose(world.registry); }
40
48 void ensureComposed(Registry& registry) {
49 if (registry.instanceId() == composedRegistry_
50 && transformMutationEpoch() == composedEpoch_) return;
51 compose(registry);
52 }
53
54 u32 composedEpoch() const { return composedEpoch_; }
55
61 u32 compositionSerial() const { return serial_; }
62
68 void setChangeTracking(bool on) {
69 tracking_ = on;
70 if (!on) takeChanges();
71 }
72 bool changeTracking() const { return tracking_; }
73
80 const std::vector<Entity>& pendingChanges() const { return changed_; }
81
89 bool changesOverflowed() const { return overflowed_; }
90
92 void takeChanges() { changed_.clear(); overflowed_ = false; }
93
95 u32 visited() const { return visited_; }
96
97private:
98 // Zero, while the epoch starts at one: nothing has been composed yet, so the
99 // first ensure runs rather than believing a world it has never looked at.
100 u32 composedEpoch_ = 0;
101 u64 composedRegistry_ = 0;
102
103 void markComposed(Registry& registry) {
104 composedEpoch_ = transformMutationEpoch();
105 composedRegistry_ = registry.instanceId();
106 }
107
108 std::vector<Entity> dirty_to_clear_;
109
110 // Off on the shipped path: composition answers "are they stale", and only a
111 // caller building an incremental structure pays for "which ones moved".
112 bool tracking_ = false;
113 std::vector<Entity>* changedOut_ = nullptr;
114 std::vector<Entity> changed_;
115 u32 visited_ = 0;
116 u32 serial_ = 0;
117 bool overflowed_ = false;
119 struct Slot {
120 const glm::mat4* matrix;
121 bool dirty;
122 bool flatCollapsed;
123 };
124 std::vector<Slot> slots_;
125 bool have_dirty_ = false;
126 bool have_static_ = false;
127 bool have_children_ = false;
128 bool have_collapsed_ = false;
129
130 void setFlatCollapsed(Registry& registry, Entity entity, bool collapsed) {
131 if (!collapsed && !have_collapsed_) return;
132 const bool present = have_collapsed_ && registry.has<FlatGeometryCollapsed>(entity);
133 if (collapsed && !present) {
134 registry.emplace<FlatGeometryCollapsed>(entity);
135 have_collapsed_ = true;
136 } else if (!collapsed && present) {
137 registry.remove<FlatGeometryCollapsed>(entity);
138 }
139 }
140
148 void compose(Registry& registry) {
149 visited_ = 0;
150 if (tracking_ && !overflowed_) changedOut_ = &changed_;
151 updateDirtyTransforms(registry);
152 changedOut_ = nullptr;
153 // Past the point where replaying the list beats re-reading the world: more entries than there are Transforms to read.
154 if (changed_.size() > registry.countOf<Transform>()) {
155 changed_.clear();
156 overflowed_ = true;
157 }
158 ++serial_;
159 markComposed(registry);
160 }
161
162 // What the last composition saw, to tell what has changed since: the registry, the tick it read up to (its own world-matrix
163 // stamps included), the Transform pool's version (a removal moves it) and whether it composed in full at all.
164 u64 seenRegistry_ = 0;
165 u32 seenTick_ = 0;
166 u32 seenTransformVersion_ = 0;
167 u32 seenUnstampedEpoch_ = 0;
168 std::vector<Entity> retargeted_;
169 std::vector<std::pair<u32, u32>> changedSlots_;
170
177 void updateDirtyTransforms(Registry& registry) {
178 dirty_to_clear_.clear();
179 have_dirty_ = !registry.entitiesWith<TransformDirty>().empty();
180 have_static_ = !registry.entitiesWith<TransformStatic>().empty();
181 auto& rel = registry.childOf();
182 have_children_ = rel.linkCount() != 0;
183 have_collapsed_ = !registry.entitiesWith<FlatGeometryCollapsed>().empty();
184
185 // A reparent is not a reason to compose everything: the entities that moved are listed, and their subtrees recompose.
186 const bool retargetsListed = rel.takeRetargeted(retargeted_);
187 const bool full = seenRegistry_ != registry.identity() || seenTick_ == 0 || !retargetsListed
188 || seenTransformVersion_ != registry.poolVersion<Transform>()
189 || seenUnstampedEpoch_ != transformUnstampedEpoch() || registry.changeAuditEnabled();
190 if (full) composeAll(registry);
191 else composeChanged(registry);
192
193 for (Entity e : dirty_to_clear_) {
194 if (registry.has<TransformDirty>(e)) {
195 registry.remove<TransformDirty>(e);
196 }
197 }
198 // After its own stamps: what this composition wrote is not a change the next one has to recompose.
199 seenRegistry_ = registry.identity();
200 seenTick_ = registry.beginChangeRead();
201 if (seenTick_ == 0) seenTick_ = registry.beginChangeRead();
202 seenTransformVersion_ = registry.poolVersion<Transform>();
203 seenUnstampedEpoch_ = transformUnstampedEpoch();
204 }
205
206 bool inTree(const ExclusiveRelation& rel, Entity entity) const {
207 return have_children_ && (rel.hasTarget(entity) || rel.hasSources(entity));
208 }
209
211 void composeAll(Registry& registry) {
212 const auto& rel = registry.childOf();
213 // eachLive (no per-frame snapshot copy of the entity list): the callback
214 // writes Transform fields and derived collapse tags, while deferring
215 // TransformDirty removal; the Transform pool itself stays stable.
216 if (plainRoots()) {
217 registry.eachLive<Transform>([&registry, &rel, this](Entity entity, Transform& transform) {
218 if (!inTree(rel, entity)) copyRoot(registry, entity, transform);
219 });
220 } else {
221 registry.eachLive<Transform>([&registry, &rel, this](Entity entity, Transform& transform) {
222 if (inTree(rel, entity)) return;
223 const bool isStatic = have_static_ && registry.has<TransformStatic>(entity);
224 const bool isDirty = have_dirty_ && registry.has<TransformDirty>(entity);
225 if (isStatic && !isDirty) return;
226 updateRootTransform(registry, entity, transform, isDirty);
227 });
228 }
229 if (!have_children_) return;
230 for (const auto& tree : rel.cascade()) {
231 if (!tree.alive) continue;
232 slots_.resize(tree.entries.size());
233 for (u32 i = 0, n = static_cast<u32>(tree.entries.size()); i < n; ++i) composeEntry(registry, tree.entries, i);
234 }
235 }
236
238 void composeChanged(Registry& registry) {
239 const auto& rel = registry.childOf();
240 const auto& trees = have_children_ ? rel.cascade() : emptyCascade();
241 changedSlots_.clear();
242
243 // A static entity is recomposed only when tagged dirty, as the full walk does: a write to it is not one.
244 const auto changed = [&](Entity entity, bool tagged, Transform* transform) {
245 if (!tagged && have_static_ && registry.has<TransformStatic>(entity)) return;
246 if (inTree(rel, entity)) {
247 const auto at = rel.cascadeAt(entity);
248 changedSlots_.emplace_back(at.tree, at.slot);
249 return;
250 }
251 if (!transform) {
252 if (tagged) dirty_to_clear_.push_back(entity);
253 return;
254 }
255 updateRootTransform(registry, entity, *transform, tagged);
256 };
257 // Down the pool's own arrays: the written Transform is in hand, with no lookup for it.
258 if (plainRoots()) {
259 registry.eachChangedSince<Transform>(seenTick_, [&](Entity entity, Transform& transform) {
260 if (!inTree(rel, entity)) { copyRoot(registry, entity, transform); return; }
261 const auto at = rel.cascadeAt(entity);
262 changedSlots_.emplace_back(at.tree, at.slot);
263 });
264 } else {
265 registry.eachChangedSince<Transform>(seenTick_, [&](Entity entity, Transform& transform) {
266 changed(entity, have_dirty_ && registry.has<TransformDirty>(entity), &transform);
267 });
268 }
269 // Moved under another parent, detached, or left a root by a destroyed parent: composed under a new matrix whatever its
270 // own stamp says, and a static one too.
271 for (const Entity entity : retargeted_) {
272 if (registry.valid(entity)) changed(entity, true, registry.tryGet<Transform>(entity));
273 }
274 if (have_dirty_) {
275 for (const Entity entity : registry.entitiesWith<TransformDirty>()) {
276 // Written and tagged was handled above, with its tag.
277 if (!registry.changedSince<Transform>(entity, seenTick_)) changed(entity, true, registry.tryGet<Transform>(entity));
278 }
279 }
280 if (changedSlots_.empty()) return;
281
282 // Ranges in cascade order, tree by tree: one inside a range already recomposed is part of it.
283 std::sort(changedSlots_.begin(), changedSlots_.end());
284 u32 tree = ExclusiveRelation::NONE, covered = 0;
285 for (const auto [t, start] : changedSlots_) {
286 const auto& order = trees[t].entries;
287 if (t != tree) { tree = t; covered = 0; slots_.resize(order.size()); }
288 if (start < covered) continue;
289 const u32 parent = order[start].parent;
290 if (parent != ExclusiveRelation::NONE) slots_[parent] = contextOf(registry, order, parent);
291 for (u32 i = start, end = order[start].end; i < end; ++i) composeEntry(registry, order, i);
292 covered = order[start].end;
293 }
294 }
295
296 static const std::vector<ExclusiveRelation::CascadeTree>& emptyCascade() {
297 static const std::vector<ExclusiveRelation::CascadeTree> none;
298 return none;
299 }
300
307 Slot contextOf(Registry& registry, const std::vector<ExclusiveRelation::CascadeEntry>& order, u32 slot) {
308 static const glm::mat4 identity{1.0f};
309 chain_.clear();
310 for (u32 at = slot; at != ExclusiveRelation::NONE; at = order[at].parent) chain_.push_back(at);
311 Slot context{&identity, true, false};
312 for (usize k = chain_.size(); k-- > 0;) {
313 const Entity entity = order[chain_[k]].entity;
314 auto* transform = registry.tryGet<Transform>(entity);
315 const bool localDirty = have_dirty_ && registry.has<TransformDirty>(entity);
316 const bool collapsedTag = have_collapsed_ && registry.has<FlatGeometryCollapsed>(entity);
317 if (k + 1 == chain_.size()) {
318 // The root of the tree.
319 if (!transform) context = {&identity, true, false};
320 else if (have_static_ && !localDirty && registry.has<TransformStatic>(entity)) context = {&transform->cachedMatrix_, false, collapsedTag};
321 else {
322 // A root that just took its first child has never built the matrix (a childless root does not need one).
323 transform->cachedMatrix_ = math::compose(transform->position, transform->rotation, transform->scale);
324 context = {&transform->cachedMatrix_, true, transform->scale.x == 0 || transform->scale.y == 0};
325 }
326 continue;
327 }
328 const bool dirty = context.dirty || localDirty;
329 const bool keepStatic = transform && have_static_ && !dirty && registry.has<TransformStatic>(entity);
330 // Its collapse tag is what composeEntry derived for it last time, from inputs that have not changed since.
331 context = {transform ? &transform->cachedMatrix_ : context.matrix, keepStatic ? false : dirty, collapsedTag};
332 }
333 return context;
334 }
335 std::vector<u32> chain_;
336
341 bool plainRoots() const { return !have_static_ && !have_dirty_ && !changedOut_; }
342
344 void copyRoot(Registry& registry, Entity entity, Transform& transform) {
345 transform.worldPosition = transform.position;
346 transform.worldRotation = transform.rotation;
347 transform.worldScale = transform.scale;
348 transform.decomposed_ = true;
349 const bool collapsed = transform.scale.x == 0 || transform.scale.y == 0;
350 if (collapsed || have_collapsed_) setFlatCollapsed(registry, entity, collapsed);
351 }
352
354 void updateRootTransform(Registry& registry, Entity entity, Transform& transform, bool localDirty) {
355 if (changedOut_) {
356 ++visited_;
357 if (!transform.decomposed_
358 || transform.worldPosition != transform.position
359 || transform.worldRotation != transform.rotation
360 || transform.worldScale != transform.scale) {
361 changedOut_->push_back(entity);
362 }
363 }
364 transform.worldPosition = transform.position;
365 transform.worldRotation = transform.rotation;
366 transform.worldScale = transform.scale;
367 transform.decomposed_ = true;
368 setFlatCollapsed(registry, entity, transform.scale.x == 0 || transform.scale.y == 0);
369 if (localDirty) dirty_to_clear_.push_back(entity);
370 }
371
373 void composeEntry(Registry& registry, const std::vector<ExclusiveRelation::CascadeEntry>& order, u32 i) {
374 static const glm::mat4 identity{1.0f};
375 const Entity entity = order[i].entity;
376 auto* transform = registry.tryGet<Transform>(entity);
377 const bool localDirty = have_dirty_ && registry.has<TransformDirty>(entity);
378
379 if (order[i].parent == ExclusiveRelation::NONE) {
380 // The root of a tree.
381 if (!transform) {
382 // A parent with no Transform of its own (a folder of entities): its children compose against identity.
383 if (localDirty) dirty_to_clear_.push_back(entity);
384 setFlatCollapsed(registry, entity, false);
385 slots_[i] = {&identity, true, false};
386 } else if (have_static_ && !localDirty && registry.has<TransformStatic>(entity)) {
387 // A static root keeps the matrix it had; its children are recomposed only where they are dirty.
388 slots_[i] = {&transform->cachedMatrix_, false, registry.has<FlatGeometryCollapsed>(entity)};
389 } else {
390 updateRootTransform(registry, entity, *transform, localDirty);
391 // A root's cachedMatrix_ is only read to transform its children, so only a root with children builds it.
392 transform->cachedMatrix_ = math::compose(transform->worldPosition, transform->worldRotation, transform->worldScale);
393 slots_[i] = {&transform->cachedMatrix_, true, transform->scale.x == 0 || transform->scale.y == 0};
394 }
395 return;
396 }
397
398 const Slot parent = slots_[order[i].parent];
399 const bool dirty = parent.dirty || localDirty;
400 const bool keepStatic = transform && have_static_ && !dirty && registry.has<TransformStatic>(entity);
401 bool flatCollapsed = parent.flatCollapsed;
402 if (transform && !keepStatic) {
403 flatCollapsed = transform->scale.x == 0 || transform->scale.y == 0
404 || (parent.flatCollapsed && transform->rotation.x == 0 && transform->rotation.y == 0);
405 const auto matrix = *parent.matrix * math::compose(transform->position, transform->rotation, transform->scale);
406 if (changedOut_) ++visited_;
407 // Only a matrix that changed is decomposed again: the same matrix decomposes to the same world fields, and
408 // a still child of a model (most of a scene's meshes) was decomposed afresh by every view of every frame.
409 if (matrix != transform->cachedMatrix_) {
410 if (changedOut_) changedOut_->push_back(entity);
411 transform->cachedMatrix_ = matrix;
412 transform->decomposed_ = false;
413 // Where it stands in the world changed (its own move or a parent's): a reader of Transform changes sees it.
414 registry.markChanged<Transform>(entity);
415 }
416 } else if (keepStatic) {
417 flatCollapsed = registry.has<FlatGeometryCollapsed>(entity);
418 }
419 setFlatCollapsed(registry, entity, flatCollapsed);
420 if (localDirty) dirty_to_clear_.push_back(entity);
421 // An entity with no Transform passes its parent's matrix through to its children. Transform storage is stable
422 // throughout composition, so a slot borrows the cached matrix rather than copying it.
423 slots_[i] = {transform ? &transform->cachedMatrix_ : parent.matrix, keepStatic ? false : dirty, flatCollapsed};
424 }
425};
426
427inline bool isDescendantOf(Registry& registry, Entity entity, Entity ancestor) {
428 return registry.childOf().isDescendantOf(entity, ancestor);
429}
430
437inline void syncHierarchyComponents(Registry& registry, Entity entity, Entity oldParent, Entity newParent) {
438 const auto& rel = registry.childOf();
439 if (!entity.isValid()) {
440 } else if (newParent.isValid()) {
441 if (auto* parent = registry.tryGet<Parent>(entity)) {
442 if (parent->entity != newParent) registry.patch<Parent>(entity).entity = newParent;
443 } else {
444 registry.emplace<Parent>(entity, newParent);
445 }
446 } else if (registry.has<Parent>(entity)) {
447 registry.remove<Parent>(entity);
448 }
449 for (const Entity owner : {oldParent, newParent}) {
450 if (!owner.isValid() || !registry.valid(owner)) continue;
451 if (!registry.has<Children>(owner)) {
452 if (!rel.hasSources(owner)) continue;
453 registry.emplace<Children>(owner);
454 }
455 auto list = rel.sources(owner);
456 if (registry.get<Children>(owner).entities != list) registry.patch<Children>(owner).entities = std::move(list);
457 }
458}
459
460inline bool setParent(Registry& registry, Entity child, Entity newParent) {
461 // SDK/scene documents use 0 for no entity; C++ uses UINT32_MAX. Index 0
462 // is never allocated, so both null representations mean detachment.
463 if (newParent.id() == 0) newParent = INVALID_ENTITY;
464 if (registry.destructionPending(child) || registry.destructionPending(newParent)) return false;
465 // Validate the entire proposed link BEFORE touching either half of the old
466 // one. A rejected edit is a transaction with no observable changes.
467 if (!registry.valid(child)) return false;
468 auto& rel = registry.childOf();
469 if (newParent != INVALID_ENTITY &&
470 (!registry.valid(newParent) || child == newParent || rel.isDescendantOf(newParent, child))) {
471 return false;
472 }
473 const Entity oldParent = rel.target(child);
474 // The components can disagree with the relation only where the parent was destroyed under the child: the relation made
475 // the child a root, while its Parent still names the dead entity. Detaching such a child is still an edit, of the component.
476 const bool stale = !newParent.isValid() && !oldParent.isValid() && registry.has<Parent>(child);
477 if (oldParent == newParent && !stale) return true;
478
479 if (newParent.isValid()) rel.link(child, newParent); else rel.unlink(child);
480 syncHierarchyComponents(registry, child, oldParent, newParent);
481
482 if (newParent.isValid()) {
483 // A childless root does not build a matrix. Its first child makes that
484 // cache live, even when the parent has since been marked static.
485 if (rel.count(newParent) == 1 && registry.has<TransformStatic>(newParent)
486 && !registry.has<TransformDirty>(newParent)) {
487 registry.emplace<TransformDirty>(newParent);
488 }
489 }
490
491 if (!registry.has<TransformDirty>(child)) {
492 registry.emplace<TransformDirty>(child);
493 }
495 registry.invalidateActivityHierarchy(child);
496 return true;
497}
498
506inline void applySceneEntityOrder(Registry& registry, const Entity* order, usize count) {
507 if (!order || count == 0) return;
508 const std::vector<u32> rank = registry.buildEntityRank(order, count);
509 registry.applyEntityRank(rank);
510
511 auto& rel = registry.childOf();
512 std::vector<Entity> parents;
513 registry.eachLive<Children>([&parents](Entity entity, Children&) { parents.push_back(entity); });
514 for (const Entity parent : parents) {
515 if (rel.sortSources(parent, rank)) syncHierarchyComponents(registry, INVALID_ENTITY, INVALID_ENTITY, parent);
516 }
518}
519
520inline Entity getRoot(Registry& registry, Entity entity) {
521 return registry.childOf().root(entity);
522}
523
524inline void destroyWithChildren(Registry& registry, Entity entity) {
525 if (!registry.valid(entity) || registry.destructionPending(entity)) return;
526 const auto& rel = registry.childOf();
527 std::vector<Entity> owned, postorder;
528 struct Reservations {
529 Registry& registry;
530 std::vector<Entity>& owned;
531 ~Reservations() { for (Entity e : owned) registry.releaseDestruction(e); }
532 } reservations{registry, owned};
533 // Reserve the whole subtree before destroying any of it, in postorder (children before their parent, in child order):
534 // an onDestroy callback that destroys part of it again joins the reservation rather than recursing.
535 struct Frame { Entity entity; Entity next; };
536 std::vector<Frame> stack;
537 const auto enter = [&](Entity e) {
538 if (!registry.valid(e) || registry.destructionPending(e)) return;
539 owned.push_back(e);
540 if (!registry.reserveDestruction(e)) { owned.pop_back(); return; }
541 stack.push_back({e, rel.first(e)});
542 };
543 enter(entity);
544 while (!stack.empty()) {
545 auto& frame = stack.back();
546 if (frame.next.isValid()) {
547 const Entity child = frame.next;
548 frame.next = rel.next(child);
549 enter(child);
550 } else {
551 postorder.push_back(frame.entity);
552 stack.pop_back();
553 }
554 }
555 for (Entity e : postorder) {
556 if (!registry.valid(e)) continue;
557 const Entity parent = rel.target(e);
558 registry.destroy(e);
559 if (parent.isValid() && registry.valid(parent) && registry.has<Children>(parent)) {
560 auto& children = registry.get<Children>(parent).entities;
561 const auto it = std::find(children.begin(), children.end(), e);
562 if (it != children.end()) children.erase(it);
563 }
564 }
565}
566
567} // namespace esengine::ecs
Hierarchy components for parent-child relationships.
Math utilities and GLM configuration for ESEngine.
Central ECS registry for entity and component management.
ECS System base class and execution group.
The words that say composed world transforms are stale, apart from the composer so the registry can s...
Unified Transform component with local and world-space data.
static constexpr u32 NONE
Definition Relation.hpp:40
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.
Definition Relation.hpp:78
Entity root(Entity entity) const
The top of entity's tree (itself when it has no target).
Definition Relation.hpp:86
Central container for all entities and components.
Definition Registry.hpp:73
bool reserveDestruction(Entity entity)
Definition Registry.hpp:423
void releaseDestruction(Entity entity)
Definition Registry.hpp:428
void eachLive(Func &&func)
each() without the per-call snapshot copy, for read-only passes.
Definition Registry.hpp:890
T & get(Entity entity)
Gets a component from an entity (must exist).
Definition Registry.hpp:649
void invalidateActivityHierarchy(Entity root=INVALID_ENTITY)
Definition Registry.hpp:123
const ExclusiveRelation & childOf() const
The (ChildOf, parent) relation: each entity's parent, and each parent's children in order.
Definition Registry.hpp:534
std::vector< u32 > buildEntityRank(const Entity *order, usize count) const
Rank table (by Entity::index()) for an ordered entity list.
Definition Registry.hpp:829
bool has(Entity entity) const
Checks if an entity has a specific component.
Definition Registry.hpp:711
bool valid(Entity entity) const
Checks if an entity is currently valid.
Definition Registry.hpp:518
void remove(Entity entity)
Removes a component from an entity.
Definition Registry.hpp:625
void destroy(Entity entity)
Destroys an entity and removes all its components.
Definition Registry.hpp:449
void applyEntityRank(const std::vector< u32 > &rank)
Reorders every component pool by a rank table from buildEntityRank.
Definition Registry.hpp:862
u64 instanceId() const
Which registry this is — unique for the process, never reused.
Definition Registry.hpp:96
T & patch(Entity entity)
Mutable access that says it writes: entity's T, stamped. Fatal where it has none, as get<T>() is.
Definition Registry.hpp:186
T * tryGet(Entity entity)
Tries to get a component from an entity.
Definition Registry.hpp:670
T & emplace(Entity entity, Args &&... args)
Adds a component to an entity with in-place construction.
Definition Registry.hpp:576
bool destructionPending(Entity entity) const
Definition Registry.hpp:436
Base class for all ECS systems.
Definition System.hpp:59
void setPriority(i32 priority)
Sets the system's execution priority.
Definition System.hpp:119
u32 visited() const
How many entities the last composition wrote, changed or not.
const std::vector< Entity > & pendingChanges() const
What every composition since the last acknowledgement changed.
bool changesOverflowed() const
Whether the pending set was dropped for being bigger than a rebuild.
u32 compositionSerial() const
How many compositions have RUN.
void update(World &world) override
Called every frame to execute system logic.
void takeChanges()
Acknowledge the pending set: it is applied, and starts again.
void ensureComposed(Registry &registry)
Compose if anything changed since the last one; O(1) if not.
void setChangeTracking(bool on)
Collect which entities' composed OUTPUT changed, from now on.
void init(Registry &registry) override
Called once when the system is added to a group.
u32 & transformMutationEpoch()
Entity getRoot(Registry &registry, Entity entity)
bool setParent(Registry &registry, Entity child, Entity newParent)
void destroyWithChildren(Registry &registry, Entity entity)
bool isDescendantOf(Registry &registry, Entity entity, Entity ancestor)
void syncHierarchyComponents(Registry &registry, Entity entity, Entity oldParent, Entity newParent)
Writes the Parent and Children components from the ChildOf relation, for entity and the parents it le...
u32 & transformUnstampedEpoch()
How many times a producer has written a local transform WITHOUT stamping it.
void applySceneEntityOrder(Registry &registry, const Entity *order, usize count)
Applies a scene's authored entity order to the whole world.
void invalidateTransformComposition()
Say that composed world transforms are stale.
glm::mat4 compose(const glm::vec3 &position, const glm::quat &rotation, const glm::vec3 &scale)
Constructs a transformation matrix from TRS components.
Definition Math.hpp:395
std::uint64_t u64
Unsigned 64-bit integer.
Definition Types.hpp:47
std::size_t usize
Size type for indexing and sizes.
Definition Types.hpp:64
constexpr Entity INVALID_ENTITY
Invalid entity sentinel value.
Definition Types.hpp:174
std::uint32_t u32
Unsigned 32-bit integer.
Definition Types.hpp:45
Entity identifier with packed index + generation.
Definition Types.hpp:135
constexpr u32 id() const
Returns the raw packed value for FFI serialization.
Definition Types.hpp:159
constexpr bool isValid() const
Checks if this is not the invalid sentinel.
Definition Types.hpp:156
Context passed to every System::update call.
Definition World.hpp:40
Children list component.
Definition Hierarchy.hpp:66
std::vector< Entity > entities
List of child entity IDs.
Definition Hierarchy.hpp:69
Parent reference component.
Definition Hierarchy.hpp:46