Skip to main content

SpawnScheduler.ixx File

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

Included Headers

Namespaces Index

namespacehelios
namespaceengine

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

namespaceruntime

Runtime infrastructure for game execution and lifecycle orchestration. More...

namespacespawn

Entity spawning infrastructure for the helios engine. More...

namespacescheduling

Spawn scheduling and plan management. More...

Classes Index

classSpawnScheduler

Abstract base class for spawn schedulers. More...

Description

Scheduler that evaluates spawn rules and produces spawn plans.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file SpawnScheduler.ixx
3 * @brief Scheduler that evaluates spawn rules and produces spawn plans.
4 */
5module;
6
7#include <span>
8#include <vector>
9#include <algorithm>
10
11export module helios.engine.runtime.spawn.scheduling.SpawnScheduler;
12
13import helios.engine.runtime.world.UpdateContext;
14import helios.engine.runtime.spawn.types.SpawnContext;
15import helios.engine.runtime.world.GameWorld;
16import helios.engine.runtime.spawn.scheduling.SpawnPlan;
17import helios.engine.runtime.spawn.scheduling.ScheduledSpawnPlan;
18import helios.engine.runtime.spawn.types.SpawnProfileId;
19import helios.engine.runtime.spawn.types.SpawnRuleId;
20import helios.engine.runtime.spawn.policy.SpawnRule;
21import helios.engine.runtime.spawn.policy.SpawnRuleState;
22import helios.engine.runtime.pooling.GameObjectPoolManager;
23
24
28
29 /**
30 * @brief Abstract base class for spawn schedulers.
31 *
32 * @details SpawnScheduler defines the interface for evaluating spawn rules
33 * and producing scheduled spawn plans. Concrete implementations determine
34 * the evaluation strategy (all rules vs. cyclic, priority-based, etc.).
35 *
36 * ## Responsibilities
37 *
38 * - Maintain a buffer of scheduled spawn plans
39 * - Provide `evaluate()` for rule processing
40 * - Provide `drainScheduledPlans()` for retrieving pending spawns
41 * - Provide `commit()` for post-spawn state updates
42 *
43 * ## Implementations
44 *
45 * | Class | Strategy |
46 * |-------|----------|
47 * | `DefaultSpawnScheduler` | Evaluates all rules each frame |
48 * | `CyclicSpawnScheduler` | Round-robin evaluation, advances on successful spawn |
49 *
50 * @see DefaultSpawnScheduler
51 * @see CyclicSpawnScheduler
52 * @see ScheduledSpawnPlan
53 */
55
56 protected:
57
58 /**
59 * @brief Buffer for scheduled spawn plans awaiting processing.
60 */
61 std::vector<ScheduledSpawnPlan> scheduledSpawnPlans_;
62
63 public:
64
65 /**
66 * @brief Virtual destructor for proper cleanup.
67 */
68 virtual ~SpawnScheduler() = default;
69
70 /**
71 * @brief Default constructor.
72 */
73 SpawnScheduler() = default;
74
75 /**
76 * @brief Evaluates spawn rules and schedules spawn plans.
77 *
78 * @details Processes registered spawn rules according to the scheduler's
79 * strategy. Produces ScheduledSpawnPlan instances for rules whose
80 * conditions are met.
81 *
82 * @param gameWorld The game world where evaluation takes place.
83 * @param updateContext Current frame context with delta time and world.
84 * @param spawnContext Optional spawn context for the operation.
85 */
86 virtual void evaluate(
87 const GameWorld& gameWorld,
88 const UpdateContext& updateContext,
89 const SpawnContext& spawnContext = {}) noexcept = 0;
90
91
92 /**
93 * @brief Returns a read-only view of scheduled spawn plans.
94 *
95 * @return Span of currently scheduled plans.
96 */
97 [[nodiscard]] std::span<const ScheduledSpawnPlan> scheduledPlans() {
99 }
100
101 /**
102 * @brief Drains and returns all scheduled spawn plans.
103 *
104 * @details Moves all pending plans out of the scheduler and returns them.
105 * The internal buffer is left empty.
106 *
107 * @return Vector of scheduled spawn plans.
108 */
109 [[nodiscard]] std::vector<ScheduledSpawnPlan> drainScheduledPlans() {
110 std::vector<ScheduledSpawnPlan> plans{};
111 plans.swap(scheduledSpawnPlans_);
112 return plans;
113 }
114
115
116 /**
117 * @brief Commits a completed spawn operation to update rule state.
118 *
119 * @details Called when a spawn request has been executed to update
120 * the associated rule's state (e.g., reset timers, update counts).
121 *
122 * @param spawnRuleId The rule that triggered the spawn.
123 * @param spawnCount The number of entities actually spawned.
124 */
125 virtual void commit(SpawnRuleId spawnRuleId, const size_t spawnCount) noexcept = 0;
126
127 /**
128 * @brief Resets all rule states to their initial values.
129 *
130 * @details Called during level transitions or game restarts.
131 */
132 virtual void reset() noexcept = 0;
133 };
134
135}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.