Skip to main content

HierarchyPropagationSystem.ixx File

System for propagating activation state through entity hierarchies. More...

Included Headers

Namespaces Index

namespacehelios
namespaceengine

Main engine module aggregating core infrastructure and game systems. More...

namespaceecs

Core Entity-Component-System architecture. More...

namespacesystems

Core ECS systems for entity management. More...

Classes Index

classHierarchyPropagationSystem

Propagates activation state from parent to child entities. More...

Description

System for propagating activation state through entity hierarchies.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file HierarchyPropagationSystem.ixx
3 * @brief System for propagating activation state through entity hierarchies.
4 */
5module;
6
7#include <cassert>
8#include <utility>
9#include <vector>
10
11export module helios.engine.ecs.systems.HierarchyPropagationSystem;
12
13
14import helios.engine.ecs.EntityHandle;
15import helios.engine.ecs.GameObject;
16
17import helios.engine.ecs.components.HierarchyComponent;
18
19import helios.engine.runtime.world.UpdateContext;
20import helios.engine.runtime.world.GameWorld;
21
22
23import helios.engine.mechanics.lifecycle.components.Active;
24import helios.engine.mechanics.lifecycle.components.Inactive;
25
26
27
28import helios.engine.common.tags.SystemRole;
29
31
32
33 using namespace helios::engine::ecs;
34
35 /**
36 * @brief Propagates activation state from parent to child entities.
37 *
38 * @details This system processes entities with HierarchyComponent and
39 * propagates their active/inactive state to all descendants. Only root
40 * entities (those without a parent) that are marked dirty trigger
41 * propagation.
42 *
43 * The system runs in two passes:
44 * - Active roots: propagate active state to children
45 * - Inactive roots: propagate inactive state to children
46 */
48
49 /**
50 * @brief Recursively updates activation state for an entity and its children.
51 *
52 * @param go The entity to update.
53 * @param active The activation state to apply.
54 */
55 void updateEntityHierarchy(GameObject go, helios::engine::runtime::world::UpdateContext& updateContext, bool active) {
56
58 if (!hc) {
59 return;
60 }
61 hc->clearDirty();
62 for (auto child : hc->children()) {
63 if (auto ent = updateContext.find(child)) {
64 ent->setActive(active);
65 updateEntityHierarchy(ent.value(), updateContext, active);
66 }
67 }
68 }
69
70 /**
71 * @brief Temporary storage for root entities pending propagation.
72 */
73 std::vector<GameObject> roots_;
74
75
76 public:
77
79 /**
80 * @brief Processes hierarchy propagation for dirty root entities.
81 *
82 * @param updateContext The current frame's update context.
83 */
85
86 for (auto [entity, hc, active] : updateContext.view<
89 >().whereEnabled()) {
90 if (hc->parent() || !hc->isDirty()) {
91 continue;
92 }
93 roots_.push_back(entity);
94 }
95
96 for (auto& entity : roots_) {
97 updateEntityHierarchy(entity, updateContext, true);
98 }
99 roots_.clear();
100
101 for (auto [entity, hc, active] : updateContext.view<
104 >().whereEnabled()) {
105 if (hc->parent() || !hc->isDirty()) {
106 continue;
107 }
108 roots_.push_back(entity);
109 }
110
111 for (auto& entity : roots_) {
112 updateEntityHierarchy(entity, updateContext, false);
113 }
114 roots_.clear();
115 }
116 };
117}
118
119

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.