Skip to main content

ScorePoolManager.ixx File

Manager for score pools and score command handling. 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...

namespacescoring

Score management and tracking system for game mechanics. More...

Classes Index

classScorePoolManager

Manages score pools and processes score commands. More...

Description

Manager for score pools and score command handling.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file ScorePoolManager.ixx
3 * @brief Manager for score pools and score command handling.
4 */
5module;
6
7#include <cassert>
8#include <memory>
9#include <stdexcept>
10#include <unordered_map>
11
12export module helios.engine.mechanics.scoring.ScorePoolManager;
13
14import helios.engine.mechanics.scoring.ScorePool;
15import helios.engine.mechanics.scoring.types.ScoreValueContext;
16
17import helios.engine.mechanics.scoring.commands;
18
19import helios.engine.mechanics.scoring.types.ScorePoolId;
20
21import helios.engine.ecs.GameObject;
22import helios.engine.runtime.world.UpdateContext;
23
24import helios.engine.runtime.world.GameWorld;
25import helios.engine.runtime.pooling.GameObjectPool;
26
27import helios.core.types;
28import helios.util.Guid;
29import helios.engine.common;
30
33
35
36 /**
37 * @brief Manages score pools and processes score commands.
38 *
39 * @details ScorePoolManager is responsible for creating and managing score pools,
40 * and for handling score update commands. It implements both the Manager
41 * interface (for lifecycle management) and ScoreCommandHandler (for
42 * receiving score commands from the command system).
43 *
44 * Score updates are batched: commands submitted via `submit()` are queued
45 * and processed during `flush()`, ensuring deterministic ordering.
46 *
47 * @see ScorePool
48 * @see ScoreCommandHandler
49 * @see Manager
50 */
52
53 /**
54 * @brief Collection of score pools managed by this manager.
55 */
56 std::vector<ScorePool> pools_;
57
58 /**
59 * @brief Pending score contexts to be processed on flush.
60 */
61 std::vector<helios::engine::mechanics::scoring::types::ScoreValueContext> scores_;
62
63
64 public:
65
67
68 /**
69 * @brief Creates and registers a new score pool.
70 *
71 * @param scorePoolId Unique identifier for the new pool.
72 *
73 * @return Reference to the newly created ScorePool.
74 */
76
77 assert(!scorePool(scorePoolId) && "Score with scorePoolId already registered");
78
79 pools_.emplace_back(scorePoolId);
80
81 return pools_.back();
82 }
83
84
85 /**
86 * @brief Retrieves a score pool by ID.
87 *
88 * @param scorePoolId The ID of the pool to find.
89 *
90 * @return Pointer to the ScorePool, or nullptr if not found.
91 */
93
94 const auto it = std::ranges::find_if(pools_, [&scorePoolId](const auto& scorePool) -> bool {
95 return scorePool.scorePoolId() == scorePoolId;
96 });
97
98 if (it == pools_.end()) {
99 return nullptr;
100 }
101
102 return &*it;
103 }
104
105
106 /**
107 * @brief Flushes pending score updates to their respective pools.
108 *
109 * Processes all pending ScoreValueContext entries and adds them to
110 * the appropriate score pools based on their scorePoolId.
111 *
112 * @param gameWorld Reference to the game world.
113 * @param update_context Reference to the update context.
114 */
115 void flush(
117 ) noexcept {
118
119 for (const auto& scoreContext : scores_) {
120
121 for (auto& pool : pools_) {
122 if (const auto scorePoolId = pool.scorePoolId(); scorePoolId == scoreContext.scorePoolId) {
123 pool.addScore(scoreContext);
124 break;
125 }
126 }
127 }
128
129
130 scores_.clear();
131 }
132
133
134 /**
135 * @brief Submits a score update command for processing.
136 *
137 * @param updateScoreCommand The command containing score context.
138 *
139 * @return True if the command was accepted.
140 */
141 bool submit(
142 UpdateScoreCommand updateScoreCommand
143 ) noexcept {
144 scores_.push_back(std::move(updateScoreCommand).scoreContext());
145
146 return true;
147 };
148
149 /**
150 * @brief Initializes the manager and registers it as the score command handler.
151 *
152 * @param gameWorld Reference to the game world.
153 */
156 }
157
158
159 /**
160 * @brief Resets all managed score pools to zero.
161 *
162 * @details Iterates through all registered pools and calls their reset()
163 * method, clearing all scores and resetting totals.
164 */
165 void reset() {
166 for (auto& pool : pools_) {
167 pool.reset();
168 }
169 }
170 };
171
172}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.