Skip to main content

HierarchyComponent.ixx File

Component for parent-child entity relationships. More...

Included Headers

#include <optional> #include <span> #include <vector> #include <helios.engine.ecs.EntityHandle>

Namespaces Index

namespacehelios
namespaceengine

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

namespaceecs

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

namespacecomponents

ECS core components for entity relationships. More...

Classes Index

classHierarchyComponent

Stores parent-child relationships for hierarchical entity graphs. More...

Description

Component for parent-child entity relationships.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file HierarchyComponent.ixx
3 * @brief Component for parent-child entity relationships.
4 */
5module;
6
7#include <optional>
8#include <span>
9#include <vector>
10
11export module helios.engine.ecs.components.HierarchyComponent;
12
13import helios.engine.ecs.EntityHandle;
14
16
17 /**
18 * @brief Stores parent-child relationships for hierarchical entity graphs.
19 *
20 * @details HierarchyComponent enables entities to form tree structures
21 * where state changes (e.g., activation, transformation) can propagate
22 * from parent to child entities. The dirty flag signals that the
23 * hierarchy has changed and needs propagation.
24 */
26
27 /**
28 * @brief Child entity handles.
29 */
30 std::vector<helios::engine::ecs::EntityHandle> children_;
31
32 /**
33 * @brief Optional parent entity handle.
34 */
35 std::optional<helios::engine::ecs::EntityHandle> parent_;
36
37 /**
38 * @brief Dirty flag indicating pending hierarchy updates.
39 */
40 bool isDirty_ = false;
41
42 /**
43 * @brief Whether this component is enabled.
44 */
45 bool isEnabled_ = true;
46
47 public:
48
49 /**
50 * @brief Adds a child entity to this hierarchy node.
51 *
52 * @param child Handle of the child entity to add.
53 */
55 children_.push_back(child);
56 }
57
58 /**
59 * @brief Sets the parent entity for this hierarchy node.
60 *
61 * @param parent Handle of the parent entity.
62 */
64 parent_ = parent;
65 }
66
67 /**
68 * @brief Returns the parent entity handle if set.
69 *
70 * @return Optional containing the parent handle, or std::nullopt.
71 */
72 [[nodiscard]] std::optional<helios::engine::ecs::EntityHandle> parent() const noexcept {
73 return parent_;
74 }
75
76 /**
77 * @brief Returns a span over all child entity handles.
78 *
79 * @return Read-only span of child handles.
80 */
81 [[nodiscard]] std::span<const helios::engine::ecs::EntityHandle> children() noexcept {
82 return children_;
83 }
84
85 /**
86 * @brief Marks the hierarchy as requiring propagation.
87 */
88 void markDirty() {
89 isDirty_ = true;
90 }
91
92 /**
93 * @brief Clears the dirty flag after propagation.
94 */
95 void clearDirty() {
96 isDirty_ = false;
97 }
98
99 /**
100 * @brief Checks whether the hierarchy needs propagation.
101 *
102 * @return True if dirty, false otherwise.
103 */
104 [[nodiscard]] bool isDirty() const noexcept {
105 return isDirty_;
106 }
107
108 };
109
110
111}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.