Skip to main content

DelayedComponentEnablerInitializer.ixx File

Initializer that schedules delayed activation of specified components. More...

Included Headers

Namespaces Index

namespacehelios
namespaceengine

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

namespaceruntime

Runtime infrastructure for game execution and lifecycle orchestration. More...

namespacespawn

Entity spawning infrastructure for the helios engine. More...

namespacebehavior

Spawn behavior strategies for positioning and initializing entities. More...

namespaceinitializers

Concrete SpawnInitializer implementations. More...

Classes Index

classDelayedComponentEnablerInitializer<ComponentTypes>

Initializer that schedules delayed activation of arbitrary components. More...

Description

Initializer that schedules delayed activation of specified components.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file DelayedComponentEnablerInitializer.ixx
3 * @brief Initializer that schedules delayed activation of specified components.
4 */
5module;
6
7#include <cassert>
8#include <typeindex>
9#include <vector>
10
11export module helios.engine.runtime.spawn.behavior.initializers.DelayedComponentEnablerInitializer;
12
13
14import helios.engine.runtime.spawn.behavior.SpawnInitializer;
15import helios.engine.runtime.spawn.SpawnPlanCursor;
16import helios.engine.runtime.spawn.SpawnContext;
17import helios.engine.ecs.GameObject;
18
19import helios.engine.mechanics.lifecycle.components.DelayedComponentEnabler;
20import helios.engine.core.data.ComponentTypeId;
21
23
24 /**
25 * @brief Initializer that schedules delayed activation of arbitrary components.
26 *
27 * @details DelayedComponentEnablerInitializer defers the activation of specified
28 * components until a calculated delay has elapsed. This enables gameplay patterns
29 * such as:
30 * - **Collision immunity:** Newly spawned entities ignore collisions briefly
31 * - **Visibility fade-in:** Rendering components activate after spawn animation
32 * - **AI activation:** Behavior components enable after entity is fully placed
33 * - **Staggered waves:** Sequential spawns activate progressively
34 *
35 * The delay for each entity is calculated as:
36 * `delay = (batchPosition + 1) * baseDelay`
37 *
38 * An optional cycle length resets the batch position via modulo, useful for
39 * repeating spawn patterns where delay should not grow indefinitely.
40 *
41 * @tparam ComponentTypes The component types whose activation should be deferred.
42 *
43 * @note The entity must have a DelayedComponentEnabler component attached.
44 * The specified ComponentTypes must exist on the entity.
45 *
46 * @see SpawnInitializer
47 * @see DelayedComponentEnabler
48 */
49 template<typename... ComponentTypes>
51
52 /**
53 * @brief Base delay in seconds between activations.
54 */
55 const float delay_;
56
57 /**
58 * @brief Cycle length for repeating delay patterns.
59 *
60 * If non-zero, position indices wrap around after this many spawns.
61 * If zero, positions increase indefinitely.
62 */
63 const size_t cycleLength_;
64
65 /**
66 * @brief Type IDs of components whose activation should be deferred.
67 */
68 std::vector<helios::engine::core::data::ComponentTypeId> deferredComponents_;
69
70 public:
71
72 /**
73 * @brief Constructs the initializer with delay and optional cycle length.
74 *
75 * @param delay Base delay in seconds between each activation step.
76 * @param cycleLength Number of positions before the delay pattern repeats.
77 * Zero means no cycling (default).
78 */
79 DelayedComponentEnablerInitializer(const float delay, const size_t cycleLength = 0) :
80 delay_(delay),
81 cycleLength_(cycleLength),
82 deferredComponents_{helios::engine::core::data::ComponentTypeId::id<ComponentTypes>() ...}
83 {}
84
85 /**
86 * @brief Schedules delayed activation of the configured component types.
87 *
88 * @details Searches the entity's components for matches against the template
89 * ComponentTypes. Each matching component is registered with the entity's
90 * DelayedComponentEnabler for deferred activation. The delay duration depends
91 * on the spawn batch position and the configured base delay.
92 *
93 * @param gameObject The entity to initialize.
94 * @param cursor Provides batch position for delay calculation.
95 * @param spawnContext Context data (unused).
96 */
99 const SpawnPlanCursor& cursor,
100 const SpawnContext& spawnContext
101 ) override {
102
103 bool deferFound = false;
104
105 auto position = cycleLength_ != 0 ? cursor.position % cycleLength_ : cursor.position;
106
107 for (auto typeId : gameObject.componentTypeIds()) {
108
109 // Find the component that should be deferred.
110 const bool deferThisComponent = std::find(
111 deferredComponents_.begin(), deferredComponents_.end(), typeId
112 ) != deferredComponents_.end();
113
114 if (deferThisComponent) {
115 deferFound = true;
117 assert(dec && "Missing DelayedComponentEnabler");
118
119 dec->defer(gameObject, typeId, (position + 1) * delay_);
120 }
121 }
122
123 assert(deferFound && "Unexpected missing deferrable component");
124 }
125
126 };
127
128}
129
130

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.