Skip to main content

GameObjectSpawnSystem Class

System that evaluates spawn conditions and enqueues spawn commands. More...

Declaration

class helios::engine::mechanics::spawn::systems::GameObjectSpawnSystem { ... }

Base class

classSystem

Abstract base class for game systems. More...

Public Constructors Index

GameObjectSpawnSystem (std::vector< std::unique_ptr< helios::engine::runtime::spawn::scheduling::SpawnScheduler > > spawnSchedulers)

Constructs a GameObjectSpawnSystem with the given schedulers. More...

Public Member Functions Index

voidupdate (helios::engine::runtime::world::UpdateContext &updateContext) noexcept override

Processes spawn scheduling and enqueues spawn commands. More...

Private Member Attributes Index

std::vector< std::unique_ptr< helios::engine::runtime::spawn::scheduling::SpawnScheduler > >spawnSchedulers_

Collection of schedulers that manage spawn rules and conditions. More...

Description

System that evaluates spawn conditions and enqueues spawn commands.

GameObjectSpawnSystem bridges the spawn scheduling logic with the command-based spawning pipeline. It manages multiple SpawnScheduler instances and performs the following each frame:

1. **Read Frame Events:** Consumes `SpawnPlanCommandExecutedEvent` from the previous frame to commit completed spawn operations to all schedulers.

2. **Evaluate Conditions:** Calls `SpawnScheduler::evaluate()` on each scheduler to check all registered spawn rules against their conditions.

3. **Drain Scheduled Plans:** Retrieves all plans that are ready to execute and enqueues them as `ScheduledSpawnPlanCommand` into the CommandBuffer.

The actual spawning is performed by the command dispatcher/manager layer, keeping this system focused on scheduling logic only.

Example setup: ```cpp std::vector<std::unique_ptr<SpawnScheduler>> schedulers;

auto enemyScheduler = std::make_unique<SpawnScheduler>(); enemyScheduler->addRule(enemyProfileId, std::move(enemyRule)); schedulers.push_back(std::move(enemyScheduler));

auto powerupScheduler = std::make_unique<SpawnScheduler>(); powerupScheduler->addRule(powerupProfileId, std::move(powerupRule)); schedulers.push_back(std::move(powerupScheduler));

auto spawnSystem = std::make_unique<GameObjectSpawnSystem>(schedulers); mainPhase.addPass().add(std::move(spawnSystem)); ```

info

This system reads frame-level events via `readFrame()`, meaning it processes spawn confirmations from the previous frame.

See Also

SpawnScheduler

See Also

ScheduledSpawnPlanCommand

See Also

SpawnPlanCommandExecutedEvent

Definition at line 64 of file GameObjectSpawnSystem.ixx.

Public Constructors

GameObjectSpawnSystem()

helios::engine::mechanics::spawn::systems::GameObjectSpawnSystem::GameObjectSpawnSystem (std::vector< std::unique_ptr< helios::engine::runtime::spawn::scheduling::SpawnScheduler > > spawnSchedulers)
inline explicit

Constructs a GameObjectSpawnSystem with the given schedulers.

Parameters
spawnSchedulers

Vector of schedulers managing spawn rules. Ownership of all schedulers is transferred to this system.

Definition at line 84 of file GameObjectSpawnSystem.ixx.

85 std::vector<std::unique_ptr<helios::engine::runtime::spawn::scheduling::SpawnScheduler>> spawnSchedulers
86 ) :
87 spawnSchedulers_(std::move(spawnSchedulers)) {}

Public Member Functions

update()

void helios::engine::mechanics::spawn::systems::GameObjectSpawnSystem::update (helios::engine::runtime::world::UpdateContext & updateContext)
inline noexcept virtual

Processes spawn scheduling and enqueues spawn commands.

Iterates through all schedulers and performs these steps for each: 1. Reads `SpawnPlanCommandExecutedEvent` from frame event bus 2. Commits completed spawns to the scheduler (for tracking/cooldowns) 3. Evaluates all spawn rules against current conditions 4. Drains ready spawn plans and enqueues them as commands

Parameters
updateContext

The current frame's update context.

Definition at line 100 of file GameObjectSpawnSystem.ixx.

100 void update(helios::engine::runtime::world::UpdateContext& updateContext) noexcept override {
101
102 const auto& events = updateContext.readFrame<
104 >();
105
106 for (const auto& spawnScheduler : spawnSchedulers_) {
107
108 /**
109 * @todo this should be processed before iterating over all schedulers: A scheduler owns the rule,
110 * hence a rule that triggered the event's can be associated with the owning Scheduler, making it
111 * unneccesary to iterate over already processed events
112 */
113 for (const auto& event : events) {
114 spawnScheduler->commit(event.spawnRuleId, event.spawnCount);
115 }
116
117 spawnScheduler->evaluate(updateContext);
118
119 auto scheduledPlans = spawnScheduler->drainScheduledPlans();
120
121 for (auto& plan : scheduledPlans) {
122 updateContext.commandBuffer().add<
124 >(
125 plan.spawnProfileId, plan.spawnPlan, plan.spawnContext
126 );
127 }
128 }
129
130 }

Private Member Attributes

spawnSchedulers_

std::vector<std::unique_ptr<helios::engine::runtime::spawn::scheduling::SpawnScheduler> > helios::engine::mechanics::spawn::systems::GameObjectSpawnSystem::spawnSchedulers_

Collection of schedulers that manage spawn rules and conditions.

Each scheduler owns and evaluates its registered spawn rules independently. When conditions are met, the scheduler produces ScheduledSpawnPlan instances for execution. Multiple schedulers allow grouping spawn rules by category (e.g., enemies, powerups, projectiles).

Definition at line 74 of file GameObjectSpawnSystem.ixx.

74 std::vector<std::unique_ptr<helios::engine::runtime::spawn::scheduling::SpawnScheduler>> spawnSchedulers_;

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.