Skip to main content

GameObjectSpawnSystem.ixx File

System for processing spawn schedules and enqueuing spawn commands. More...

Included Headers

Namespaces Index

namespacehelios
namespaceengine

Main engine module aggregating core infrastructure and game systems. More...

namespacemechanics

High-level gameplay systems and components for game logic. More...

namespacespawn

Entity spawning and lifecycle management. More...

namespacesystems

Systems for spawn lifecycle management. More...

Classes Index

classGameObjectSpawnSystem

Description

System for processing spawn schedules and enqueuing spawn commands.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file GameObjectSpawnSystem.ixx
3 * @brief System for processing spawn schedules and enqueuing spawn commands.
4 */
5module;
6
7#include <cassert>
8#include <memory>
9#include <vector>
10
11export module helios.engine.mechanics.spawn.systems.GameObjectSpawnSystem;
12
13
14
15import helios.engine.state.Bindings;
16import helios.engine.runtime.messaging.command.EngineCommandBuffer;
17
18import helios.engine.runtime.world.UpdateContext;
19import helios.engine.runtime.world.GameWorld;
20import helios.engine.runtime.spawn.commands.ScheduledSpawnPlanCommand;
21import helios.engine.runtime.spawn.SpawnManager;
22import helios.engine.runtime.spawn.scheduling.SpawnScheduler;
23import helios.engine.runtime.spawn.events.SpawnPlanCommandExecutedEvent;
24import helios.engine.common.tags.SystemRole;
25
26
29
30
32
33
35
36 GameWorld* gameWorld_ = nullptr;
37
38 public:
39
40
42
44 : spawnManager_{spawnManager} {}
45
46
47 void init(GameWorld& gameWorld) noexcept {
48 gameWorld_ = &gameWorld;
49 }
50
51 /**
52 * @brief Processes spawn scheduling and enqueues spawn commands.
53 *
54 * @details Iterates through all schedulers and performs these steps for each:
55 * 1 Reads `SpawnPlanCommandExecutedEvent` from frame event bus
56 * 2 Commits completed spawns to the scheduler (for tracking/cooldowns)
57 * 3 Evaluates all spawn rules against current conditions
58 * 4 Drains ready spawn plans and enqueues them as commands
59 *
60 * @param updateContext The current frame's update context.
61 */
63
64 const auto& events = updateContext.readFrame<
66 >();
67
68 for (const auto& spawnScheduler : spawnManager_.spawnSchedulers()) {
69
70 /**
71 * @todo this should be processed before iterating over all schedulers: A scheduler owns the rule,
72 * hence a rule that triggered the event's can be associated with the owning Scheduler, making it
73 * unneccesary to iterate over already processed events
74 */
75 for (const auto& event : events) {
76 spawnScheduler->commit(event.spawnRuleId, event.spawnCount);
77 }
78
79 spawnScheduler->evaluate(*gameWorld_, updateContext);
80
81 auto scheduledPlans = spawnScheduler->drainScheduledPlans();
82
83 for (auto& plan : scheduledPlans) {
84 updateContext.queueCommand<
86 >(
87 plan.spawnProfileId, plan.spawnPlan, plan.spawnContext
88 );
89 }
90 }
91
92 }
93
94 };
95
96}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.