Skip to main content

CyclicSpawnScheduler Class Template

Scheduler that cycles through spawn rules in round-robin order. More...

Declaration

template <std::size_t N> class helios::engine::runtime::spawn::scheduling::CyclicSpawnScheduler<N> { ... }

Base class

classSpawnScheduler

Abstract base class for spawn schedulers. More...

Public Member Functions Index

template <std::size_t N>
voidevaluate (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>
voidcommit (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_tcursor_ = 0

Current position in the ring buffer. More...

template <std::size_t N>
size_tcount_ = 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>
DefaultRuleProcessorruleProcessor_

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

SpawnScheduler

See Also

DefaultSpawnScheduler

See Also

RuleConfig

Definition at line 92 of file CyclicSpawnScheduler.ixx.

Public Member Functions

addRule()

template <std::size_t N>
CyclicSpawnScheduler & helios::engine::runtime::spawn::scheduling::CyclicSpawnScheduler< N >::addRule (const helios::engine::core::data::SpawnProfileId spawnProfileId, std::unique_ptr< helios::engine::runtime::spawn::policy::SpawnRule > spawnRule)
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.

173 std::unique_ptr<helios::engine::runtime::spawn::policy::SpawnRule> spawnRule
174 ) {
175 assert(count_ < N);
176
177 assert(!spawnRuleStates_.contains(spawnRule->spawnRuleId()) && "Duplicate SpawnRuleId entry");
178
179 for (const auto& item : ringBuffer_) {
180 assert(item.spawnProfileId != spawnProfileId && "Duplicate SpawnProfile entry");
181 }
182
183 spawnRuleStates_.try_emplace(spawnRule->spawnRuleId());
184
185 ringBuffer_[count_++] = {
186 spawnProfileId, std::move(spawnRule)
187 };
188
189 return *this;
190 }

commit()

template <std::size_t N>
void helios::engine::runtime::spawn::scheduling::CyclicSpawnScheduler< N >::commit (const helios::engine::core::data::SpawnRuleId spawnRuleId, const size_t spawnCount)
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.

201 void commit(const helios::engine::core::data::SpawnRuleId spawnRuleId, const size_t spawnCount) noexcept override{
202
203 for (auto& ruleConfig : ringBuffer_) {
204
205 if (ruleConfig.spawnRule->spawnRuleId() == spawnRuleId) {
206
207 auto it = spawnRuleStates_.find(spawnRuleId);
208 assert(it != spawnRuleStates_.end() && "Unexpected missing spawnRuleState");
209
210 ruleConfig.spawnRule->commit(it->second, spawnCount);
211 }
212 }
213 }

evaluate()

template <std::size_t N>
void helios::engine::runtime::spawn::scheduling::CyclicSpawnScheduler< N >::evaluate (const helios::engine::runtime::world::UpdateContext & updateContext, const helios::engine::runtime::spawn::SpawnContext & spawnContext)
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.

136 const helios::engine::runtime::spawn::SpawnContext& spawnContext ) noexcept override {
137
139
140 // Process queue
141 auto& [spawnProfileId, spawnRule] = ringBuffer_[cursor_];
142 auto spawnPlan = ruleProcessor_.processRule(
143 updateContext, spawnContext, spawnProfileId, *spawnRule,
144 spawnRuleStates_[spawnRule->spawnRuleId()]);
145
146 if (spawnPlan.amount > 0) {
147 scheduledSpawnPlans_.push_back({
148 spawnProfileId,
149 std::move(spawnPlan),
150 spawnContext
151 });
152 cursor_ = (cursor_ + 1) % (count_);
153 }
154
155 }

Reference helios::engine::runtime::spawn::scheduling::SpawnScheduler::scheduledSpawnPlans_.

Private Member Attributes

count_

template <std::size_t N>
size_t helios::engine::runtime::spawn::scheduling::CyclicSpawnScheduler< N >::count_ = 0

Number of rules currently registered.

Definition at line 107 of file CyclicSpawnScheduler.ixx.

107 size_t count_ = 0;

cursor_

template <std::size_t N>
size_t helios::engine::runtime::spawn::scheduling::CyclicSpawnScheduler< N >::cursor_ = 0

Current position in the ring buffer.

Definition at line 102 of file CyclicSpawnScheduler.ixx.

102 size_t cursor_ = 0;

ringBuffer_

template <std::size_t N>
std::array<RuleConfig, N> helios::engine::runtime::spawn::scheduling::CyclicSpawnScheduler< N >::ringBuffer_ {}

Fixed-size ring buffer of rule configurations.

Definition at line 97 of file CyclicSpawnScheduler.ixx.

97 std::array<RuleConfig, N> ringBuffer_{};

ruleProcessor_

template <std::size_t N>
DefaultRuleProcessor helios::engine::runtime::spawn::scheduling::CyclicSpawnScheduler< N >::ruleProcessor_

Processor for evaluating individual rules.

Definition at line 120 of file CyclicSpawnScheduler.ixx.

120 DefaultRuleProcessor ruleProcessor_;

spawnRuleStates_

template <std::size_t N>
std::unordered_map< helios::engine::core::data::SpawnRuleId, helios::engine::runtime::spawn::policy::SpawnRuleState > helios::engine::runtime::spawn::scheduling::CyclicSpawnScheduler< N >::spawnRuleStates_

Map from spawn rule IDs to their runtime state.

Definition at line 115 of file CyclicSpawnScheduler.ixx.

115 > spawnRuleStates_;

The documentation for this class was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.