CyclicSpawnScheduler Class Template
Scheduler that cycles through spawn rules in round-robin order. More...
Declaration
Base class
| class | SpawnScheduler |
|
Abstract base class for spawn schedulers. More... | |
Public Member Functions Index
template <std::size_t N> | |
| void | evaluate (const helios::engine::runtime::world::UpdateContext &updateContext, const helios::engine::runtime::spawn::SpawnContext &spawnContext) noexcept override |
|
Evaluates the current rule in the cycle. More... | |
template <std::size_t N> | |
| CyclicSpawnScheduler & | addRule (const helios::engine::core::data::SpawnProfileId spawnProfileId, std::unique_ptr< helios::engine::runtime::spawn::policy::SpawnRule > spawnRule) |
|
Adds a spawn rule to the cycle. More... | |
template <std::size_t N> | |
| void | commit (const helios::engine::core::data::SpawnRuleId spawnRuleId, const size_t spawnCount) noexcept override |
|
Commits a completed spawn to update rule state. More... | |
Private Member Attributes Index
template <std::size_t N> | |
| std::array< RuleConfig, N > | ringBuffer_ {} |
|
Fixed-size ring buffer of rule configurations. More... | |
template <std::size_t N> | |
| size_t | cursor_ = 0 |
|
Current position in the ring buffer. More... | |
template <std::size_t N> | |
| size_t | count_ = 0 |
|
Number of rules currently registered. More... | |
template <std::size_t N> | |
| std::unordered_map< helios::engine::core::data::SpawnRuleId, helios::engine::runtime::spawn::policy::SpawnRuleState > | spawnRuleStates_ |
|
Map from spawn rule IDs to their runtime state. More... | |
template <std::size_t N> | |
| DefaultRuleProcessor | ruleProcessor_ |
|
Processor for evaluating individual rules. More... | |
Description
Scheduler that cycles through spawn rules in round-robin order.
CyclicSpawnScheduler evaluates one rule per frame in a fixed-size ring buffer, advancing only when a spawn successfully occurs. This creates predictable, sequential spawn patterns ideal for wave-based gameplay.
## Behavior
- Evaluates the current rule each `evaluate()` call
- Advances cursor only when a spawn plan is successfully produced
- Rules that don't trigger are re-evaluated on subsequent frames
- Uses compile-time fixed capacity via template parameter
## Use Cases
- **Wave spawning:** Sequential enemy types, each wave completes before next
- **Boss patterns:** Predictable attack phase cycling
- **Resource spawning:** Alternating pickup types
## Usage
```cpp CyclicSpawnScheduler<3> scheduler; scheduler .addRule(enemyAProfileId, std::make_unique<TimerSpawnRule>(ruleA, 2.0f, 1)) .addRule(enemyBProfileId, std::make_unique<TimerSpawnRule>(ruleB, 2.0f, 1)) .addRule(bossProfileId, std::make_unique<TimerSpawnRule>(ruleC, 5.0f, 1));
// Evaluates ruleA until spawn occurs, then advances to ruleB, etc. // Cycle: A → B → Boss → A → B → Boss → ... ```
- Template Parameters
-
N Maximum number of rules the scheduler can hold.
- See Also
- See Also
- See Also
Definition at line 92 of file CyclicSpawnScheduler.ixx.
Public Member Functions
addRule()
| inline |
Adds a spawn rule to the cycle.
Appends the rule to the ring buffer. Rules are evaluated in the order they are added.
- Parameters
-
spawnProfileId Profile ID for the spawned entities.
spawnRule The spawn rule. Ownership transferred.
- Returns
Reference to this scheduler for chaining.
- Precondition
The scheduler has capacity (count_ < N).
- Precondition
No duplicate profile IDs or rule IDs.
Definition at line 171 of file CyclicSpawnScheduler.ixx.
commit()
| inline noexcept virtual |
Commits a completed spawn to update rule state.
Called after entities are spawned to update the rule's internal state (e.g., spawn count tracking).
- Parameters
-
spawnRuleId The rule that triggered the spawn.
spawnCount Number of entities actually spawned.
Definition at line 201 of file CyclicSpawnScheduler.ixx.
evaluate()
| inline noexcept virtual |
Evaluates the current rule in the cycle.
Processes only the rule at the current cursor position. If the rule produces a spawn plan, the cursor advances to the next rule. Otherwise, the same rule is evaluated again next frame.
- Parameters
-
updateContext Current frame context.
spawnContext Context for spawn operations.
Definition at line 134 of file CyclicSpawnScheduler.ixx.
Reference helios::engine::runtime::spawn::scheduling::SpawnScheduler::scheduledSpawnPlans_.
Private Member Attributes
count_
|
Number of rules currently registered.
Definition at line 107 of file CyclicSpawnScheduler.ixx.
cursor_
|
Current position in the ring buffer.
Definition at line 102 of file CyclicSpawnScheduler.ixx.
ringBuffer_
|
Fixed-size ring buffer of rule configurations.
Definition at line 97 of file CyclicSpawnScheduler.ixx.
ruleProcessor_
|
Processor for evaluating individual rules.
Definition at line 120 of file CyclicSpawnScheduler.ixx.
spawnRuleStates_
|
Map from spawn rule IDs to their runtime state.
Definition at line 115 of file CyclicSpawnScheduler.ixx.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.