Skip to main content

Traits.ixx File

Compile-time traits for ECS component lifecycle hooks. More...

Included Headers

#include <concepts>

Namespaces Index

namespacehelios
namespaceengine

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

namespaceecs

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

namespacetraits

Description

Compile-time traits for ECS component lifecycle hooks.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file Traits.ixx
3 * @brief Compile-time traits for ECS component lifecycle hooks.
4 */
5module;
6
7#include <concepts>
8
9export module helios.engine.ecs.Traits;
10
11
12export namespace helios::engine::ecs::traits {
13
14 /**
15 * @brief Trait for components that support removal interception.
16 *
17 * When a type `T` satisfies `HasOnRemove`, the `SparseSet` will invoke
18 * `onRemove()` before removing the element. If the method returns `false`,
19 * removal is cancelled.
20 *
21 * ## Usage
22 *
23 * ```cpp
24 * struct MyComponent {
25 * bool onRemove() {
26 * // Cleanup logic...
27 * return true; // Allow removal
28 * }
29 * };
30 *
31 * static_assert(traits::HasOnRemove<MyComponent>);
32 * ```
33 *
34 * @tparam T The type to check.
35 *
36 * @see SparseSet::remove
37 */
38 template<typename T>
39 concept HasOnRemove = requires(T t) {
40 {t.onRemove()} -> std::convertible_to<bool>;
41 };
42
43
44 /**
45 * @brief Called when this GameObject is acquired from a pool.
46 *
47 * @details Notifies all attached components by calling their `onAcquire()` method.
48 * Used by the pool system to reset or initialize component state before reuse.
49 *
50 * @see GameObjectPool
51 * @see Component::onAcquire
52 */
53 template<typename T>
54 concept HasOnAcquire = requires(T t) {
55 {t.onAcquire()} -> std::same_as<void>;
56 };
57
58
59 /**
60 * @brief Called when this GameObject is released back to a pool.
61 *
62 * @details Notifies all attached components by calling their `onRelease()` method.
63 * Used by the pool system to clean up component state before pooling.
64 *
65 * @see GameObjectPool
66 * @see Component::onRelease
67 */
68 template<typename T>
69 concept HasOnRelease = requires(T t) {
70 {t.onRelease()} -> std::same_as<void>;
71 };
72
73 /**
74 * @brief Trait for components that can be enabled/disabled.
75 *
76 * @details When a type `T` satisfies `HasToggleable`, the component can be
77 * toggled on/off via `enable()` and `disable()` methods. Both methods must
78 * be present for the trait to be satisfied.
79 *
80 * ## Usage
81 *
82 * ```cpp
83 * struct MyComponent {
84 * bool isEnabled_ = true;
85 *
86 * void enable() noexcept { isEnabled_ = true; }
87 * void disable() noexcept { isEnabled_ = false; }
88 * };
89 *
90 * static_assert(traits::HasToggleable<MyComponent>);
91 * ```
92 *
93 * @tparam T The type to check.
94 */
95 template<typename T>
96 concept HasToggleable = requires(T t) {
97 {t.disable()} -> std::same_as<void>;
98 {t.enable()} -> std::same_as<void>;
99 };
100
101 /**
102 * @brief Trait for components with post-copy initialization.
103 *
104 * @details When a type `T` satisfies `HasClone`, the `onClone()` method is
105 * called after copy construction during entity cloning. Use this for
106 * initialization that requires the copy to be complete.
107 *
108 * ## Usage
109 *
110 * ```cpp
111 * struct SceneNodeComponent {
112 * SceneNode* sceneNode_;
113 *
114 * void onClone(const SceneNodeComponent& source) {
115 * // Create a new SceneNode for this clone
116 * auto node = std::make_unique<SceneNode>(source.sceneNode_->shareRenderable());
117 * sceneNode_ = source.sceneNode_->parent()->addNode(std::move(node));
118 * }
119 * };
120 *
121 * static_assert(traits::HasClone<SceneNodeComponent>);
122 * ```
123 *
124 * @tparam T The type to check.
125 */
126 template<typename T>
127 concept HasClone = requires(T t, const T& source) {
128 {t.onClone(source)} -> std::same_as<void>;
129 };
130
131 /**
132 * @brief Trait for components responding to GameObject activation.
133 *
134 * @details When a type `T` satisfies `HasActivatable`, the `onActivate()`
135 * and `onDeactivate()` methods are called when the owning GameObject's
136 * active state changes via `setActive()`. Both methods must be present.
137 *
138 * ## Usage
139 *
140 * ```cpp
141 * struct AIComponent {
142 * void onActivate() { startBehaviorTree(); }
143 * void onDeactivate() { pauseBehaviorTree(); }
144 * };
145 *
146 * static_assert(traits::HasActivatable<AIComponent>);
147 * ```
148 *
149 * @tparam T The type to check.
150 */
151 template<typename T>
152 concept HasActivatable = requires(T t) {
153 {t.onActivate()} -> std::same_as<void>;
154 {t.onDeactivate()} -> std::same_as<void>;
155 };
156
157
158}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.