Skip to main content

TimerSpawnCondition.ixx File

Time-based spawn condition for interval-controlled spawning. 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...

namespacepolicy

Spawn rules, conditions, and amount providers. More...

namespaceconditions

Spawn conditions for controlling spawn timing. More...

Classes Index

classTimerSpawnCondition

A SpawnCondition that triggers spawning at fixed time intervals. More...

Description

Time-based spawn condition for interval-controlled spawning.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file TimerSpawnCondition.ixx
3 * @brief Time-based spawn condition for interval-controlled spawning.
4 */
5module;
6
7#include <cassert>
8
9export module helios.engine.runtime.spawn.policy.conditions.TimerSpawnCondition;
10
11import helios.engine.runtime.spawn.policy.SpawnCondition;
12import helios.engine.runtime.spawn.policy.SpawnRuleState;
13import helios.engine.runtime.pooling.GameObjectPoolSnapshot;
14import helios.engine.runtime.world.UpdateContext;
15
17
18 /**
19 * @brief A SpawnCondition that triggers spawning at fixed time intervals.
20 *
21 * @details TimerSpawnCondition checks if enough time has elapsed since the
22 * last spawn to satisfy the interval requirement.
23 *
24 * ## Behavior
25 *
26 * - **isSatisfied():** Returns true when `sinceLastSpawn >= interval`.
27 * - **onCommit():** Resets the `sinceLastSpawn` timer to 0
28 *
29 * Example:
30 * ```cpp
31 * // Spawn every 2 seconds
32 * auto condition = std::make_unique<TimerSpawnCondition>(2.0f);
33 *
34 * auto rule = std::make_unique<SpawnRule>(
35 * std::move(condition),
36 * std::make_unique<FixedSpawnAmount>(3),
37 * SpawnRuleId{1}
38 * );
39 * ```
40 *
41 * @see SpawnCondition
42 * @see SpawnRule
43 * @see SpawnRuleState
44 */
46
47 private:
48
49 /**
50 * @brief The time interval between spawns in seconds.
51 */
52 float interval_ = 0.0f;
53
54 public:
55
56 /**
57 * @brief Constructs a TimerSpawnCondition with the specified interval.
58 *
59 * @details The first spawn will occur after the interval has elapsed,
60 * not immediately.
61 *
62 * @param interval The time in seconds between spawn events.
63 *
64 * @pre interval > 0.0f
65 */
66 explicit TimerSpawnCondition(const float interval)
67 : interval_(interval) {
68 assert(interval > 0.0f && "Interval must be > 0");
69 }
70
71 /**
72 * @brief Checks if the timer interval has elapsed.
73 *
74 * @param requestedAmount The number of entities requested to spawn.
75 * @param spawnState The rule's runtime state containing time since last spawn.
76 * @param poolSnapshot Snapshot of the pool's current capacity.
77 * @param updateContext The current frame's context.
78 *
79 * @return true if interval elapsed AND pool has enough inactive entities.
80 */
81 [[nodiscard]] bool isSatisfied(
82 const size_t requestedAmount,
83 const SpawnRuleState& spawnState,
86 ) const noexcept override {
87 return spawnState.sinceLastSpawn() >= interval_;
88 }
89
90 /**
91 * @brief Resets the spawn timer after a successful spawn.
92 *
93 * @param spawnRuleState The rule's runtime state to update.
94 * @param spawnAmount The number of entities that were spawned (unused).
95 */
96 void onCommit(
97 SpawnRuleState& spawnRuleState,
98 const size_t spawnAmount
99 ) const override {
100 spawnRuleState.setSinceLastSpawn(0.0f);
101 }
102
103 };
104
105}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.