Skip to main content

DefaultSpawnScheduler Class

Scheduler that evaluates spawn rules and produces spawn plans. More...

Declaration

class helios::engine::runtime::spawn::scheduling::DefaultSpawnScheduler { ... }

Base class

classSpawnScheduler

Abstract base class for spawn schedulers. More...

Public Constructors Index

DefaultSpawnScheduler (const size_t initialSpanPlanSize=20)

Constructs a DefaultSpawnScheduler with optional initial capacity. More...

Public Member Functions Index

voidevaluate (const GameWorld &gameWorld, const UpdateContext &updateContext, const SpawnContext &spawnContext) noexcept override

Evaluates all registered spawn rules. More...

DefaultSpawnScheduler &addRule (const helios::engine::runtime::spawn::types::SpawnProfileId spawnProfileId, std::unique_ptr< helios::engine::runtime::spawn::policy::SpawnRule > spawnRule)

Adds a spawn rule for a profile. More...

voidcommit (const helios::engine::runtime::spawn::types::SpawnRuleId spawnRuleId, const size_t spawnCount) noexcept override

Commits a completed spawn to update rule state. More...

voidreset () noexcept override

Resets all rule states to their initial values. More...

Protected Member Attributes Index

std::unordered_map< helios::engine::runtime::spawn::types::SpawnProfileId, std::unique_ptr< helios::engine::runtime::spawn::policy::SpawnRule > >spawnRules_

Map from spawn profile IDs to their spawn rules. More...

std::unordered_map< helios::engine::runtime::spawn::types::SpawnRuleId, helios::engine::runtime::spawn::policy::SpawnRuleState >spawnRuleStates_

Map from spawn rule IDs to their runtime state. More...

DefaultRuleProcessorruleProcessor_ {}

Processor for evaluating individual rules. More...

Description

Scheduler that evaluates spawn rules and produces spawn plans.

SpawnScheduler is the central coordinator for rule-based spawning. It maintains a collection of spawn rules, evaluates them each frame, and produces ScheduledSpawnPlan instances for rules whose conditions are met.

## Workflow

1. **Registration:** Rules are added via `addRule()` with their profile ID 2. **Evaluation:** `evaluate()` is called each frame by GameObjectSpawnSystem 3. **Scheduling:** Rules that pass conditions produce ScheduledSpawnPlans 4. **Draining:** `drainScheduledPlans()` returns and clears pending plans 5. **Commit:** `commit()` is called when spawns complete to update state

Example: ```cpp SpawnScheduler scheduler; scheduler.addRule(enemyProfileId, std::make_unique<TimerSpawnRule>( ruleId, 2.0f, 3 // Every 2s, spawn 3 ));

// In game loop scheduler.evaluate(updateContext); auto plans = scheduler.drainScheduledPlans(); ```

See Also

SpawnRule

See Also

ScheduledSpawnPlan

See Also

GameObjectSpawnSystem

Definition at line 67 of file DefaultSpawnScheduler.ixx.

Public Constructors

DefaultSpawnScheduler()

helios::engine::runtime::spawn::scheduling::DefaultSpawnScheduler::DefaultSpawnScheduler (const size_t initialSpanPlanSize=20)
inline

Constructs a DefaultSpawnScheduler with optional initial capacity.

Parameters
initialSpanPlanSize

Initial capacity for the spawn plan buffer.

Definition at line 98 of file DefaultSpawnScheduler.ixx.

98 DefaultSpawnScheduler(const size_t initialSpanPlanSize = 20) {
99 scheduledSpawnPlans_.reserve(initialSpanPlanSize);
100 }

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

Referenced by addRule.

Public Member Functions

addRule()

DefaultSpawnScheduler & helios::engine::runtime::spawn::scheduling::DefaultSpawnScheduler::addRule (const helios::engine::runtime::spawn::types::SpawnProfileId spawnProfileId, std::unique_ptr< helios::engine::runtime::spawn::policy::SpawnRule > spawnRule)
inline

Adds a spawn rule for a profile.

Parameters
spawnProfileId

The profile ID to associate with the rule.

spawnRule

The spawn rule to add. Ownership transferred.

Returns

Reference to this scheduler for chaining.

Precondition

No rule is already registered for this profile ID.

Definition at line 146 of file DefaultSpawnScheduler.ixx.

148 std::unique_ptr<helios::engine::runtime::spawn::policy::SpawnRule> spawnRule
149 ) {
150 assert(!spawnRules_.contains(spawnProfileId) && "Duplicate SpawnProfile entry");
151 assert(!spawnRuleStates_.contains(spawnRule->spawnRuleId()) && "Duplicate SpawnRuleId entry");
152
153 spawnRuleStates_.try_emplace(spawnRule->spawnRuleId());
154 spawnRules_.try_emplace(spawnProfileId, std::move(spawnRule));
155
156
157 return *this;
158 }

References DefaultSpawnScheduler, spawnRules_ and spawnRuleStates_.

commit()

void helios::engine::runtime::spawn::scheduling::DefaultSpawnScheduler::commit (const helios::engine::runtime::spawn::types::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, timer reset).

Parameters
spawnRuleId

The rule that triggered the spawn.

spawnCount

Number of entities actually spawned.

Definition at line 169 of file DefaultSpawnScheduler.ixx.

169 void commit(const helios::engine::runtime::spawn::types::SpawnRuleId spawnRuleId, const size_t spawnCount) noexcept override{
170
171 for (auto& spawnRule : spawnRules_ | std::views::values) {
172
173 if (spawnRule->spawnRuleId() == spawnRuleId) {
174
175 auto it = spawnRuleStates_.find(spawnRuleId);
176 assert(it != spawnRuleStates_.end() && "Unexpected missing spawnRuleState");
177
178 spawnRule->commit(it->second, spawnCount);
179 }
180 }
181 }

References spawnRules_ and spawnRuleStates_.

evaluate()

void helios::engine::runtime::spawn::scheduling::DefaultSpawnScheduler::evaluate (const GameWorld & gameWorld, const UpdateContext & updateContext, const SpawnContext & spawnContext)
inline noexcept virtual

Evaluates all registered spawn rules.

Iterates through all rules, processes each one, and collects spawn plans for rules whose conditions are met.

Parameters
gameWorld

The game world where evaluation takes place.

updateContext

Current frame context with delta time and world.

spawnContext

Context for spawn operations.

Definition at line 112 of file DefaultSpawnScheduler.ixx.

113 const GameWorld& gameWorld,
114 const UpdateContext& updateContext,
115 const SpawnContext& spawnContext) noexcept override{
116
118
119 for (auto& [spawnProfileId, rule] : spawnRules_) {
120
121 auto spawnPlan = ruleProcessor_.processRule(
122 gameWorld, updateContext, spawnContext, spawnProfileId, *rule,
123 spawnRuleStates_[rule->spawnRuleId()]
124 );
125
126 if (spawnPlan.amount > 0) {
127 scheduledSpawnPlans_.push_back({
128 spawnProfileId,
129 std::move(spawnPlan),
130 spawnContext
131 });
132 }
133 }
134 }

References ruleProcessor_, helios::engine::runtime::spawn::scheduling::SpawnScheduler::scheduledSpawnPlans_, spawnRules_ and spawnRuleStates_.

reset()

void helios::engine::runtime::spawn::scheduling::DefaultSpawnScheduler::reset ()
inline noexcept virtual

Resets all rule states to their initial values.

Iterates through all rules and resets their state.

Definition at line 188 of file DefaultSpawnScheduler.ixx.

188 void reset() noexcept override {
189 for (auto& spawnRule : spawnRules_ | std::views::values) {
190
191 auto it = spawnRuleStates_.find(spawnRule->spawnRuleId());
192 assert(it != spawnRuleStates_.end() && "Unexpected missing spawnRuleState");
193
194 spawnRule->reset(it->second);
195
196 }
197 }

References spawnRules_ and spawnRuleStates_.

Protected Member Attributes

ruleProcessor_

DefaultRuleProcessor helios::engine::runtime::spawn::scheduling::DefaultSpawnScheduler::ruleProcessor_ {}
protected

Processor for evaluating individual rules.

Definition at line 89 of file DefaultSpawnScheduler.ixx.

Referenced by evaluate.

spawnRules_

std::unordered_map<helios::engine::runtime::spawn::types::SpawnProfileId, std::unique_ptr<helios::engine::runtime::spawn::policy::SpawnRule> > helios::engine::runtime::spawn::scheduling::DefaultSpawnScheduler::spawnRules_
protected

Map from spawn profile IDs to their spawn rules.

Definition at line 76 of file DefaultSpawnScheduler.ixx.

Referenced by addRule, commit, evaluate and reset.

spawnRuleStates_

std::unordered_map< helios::engine::runtime::spawn::types::SpawnRuleId, helios::engine::runtime::spawn::policy::SpawnRuleState > helios::engine::runtime::spawn::scheduling::DefaultSpawnScheduler::spawnRuleStates_
protected

Map from spawn rule IDs to their runtime state.

Definition at line 84 of file DefaultSpawnScheduler.ixx.

Referenced by addRule, commit, evaluate and reset.


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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.