DefaultSpawnScheduler Class
Scheduler that evaluates spawn rules and produces spawn plans. More...
Declaration
Base class
| class | SpawnScheduler |
|
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
| void | evaluate (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... | |
| void | commit (const helios::engine::runtime::spawn::types::SpawnRuleId spawnRuleId, const size_t spawnCount) noexcept override |
|
Commits a completed spawn to update rule state. More... | |
| void | reset () 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... | |
| DefaultRuleProcessor | ruleProcessor_ {} |
|
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
- See Also
GameObjectSpawnSystem
Definition at line 67 of file DefaultSpawnScheduler.ixx.
Public Constructors
DefaultSpawnScheduler()
| 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.
Reference helios::engine::runtime::spawn::scheduling::SpawnScheduler::scheduledSpawnPlans_.
Referenced by addRule.
Public Member Functions
addRule()
| 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.
References DefaultSpawnScheduler, spawnRules_ and spawnRuleStates_.
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, timer reset).
- Parameters
-
spawnRuleId The rule that triggered the spawn.
spawnCount Number of entities actually spawned.
Definition at line 169 of file DefaultSpawnScheduler.ixx.
References spawnRules_ and spawnRuleStates_.
evaluate()
| 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.
References ruleProcessor_, helios::engine::runtime::spawn::scheduling::SpawnScheduler::scheduledSpawnPlans_, spawnRules_ and spawnRuleStates_.
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.
References spawnRules_ and spawnRuleStates_.
Protected Member Attributes
ruleProcessor_
| protected |
Processor for evaluating individual rules.
Definition at line 89 of file DefaultSpawnScheduler.ixx.
Referenced by evaluate.
spawnRules_
| protected |
Map from spawn profile IDs to their spawn rules.
Definition at line 76 of file DefaultSpawnScheduler.ixx.
spawnRuleStates_
| protected |
Map from spawn rule IDs to their runtime state.
Definition at line 84 of file DefaultSpawnScheduler.ixx.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.