Skip to main content

ScoreObserverComponent.ixx File

Component for observing score pool changes. 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...

namespacesystems

Systems for score processing and observation. More...

namespacecomponents

Score-related ECS components. More...

Classes Index

classScoreObserverClearSystem

System that resets the hasUpdate flag on all ScoreObserverComponents. More...

classScoreObserverComponent

Component that observes and caches the score value from a ScorePool. More...

Description

Component for observing score pool changes.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file ScoreObserverComponent.ixx
3 * @brief Component for observing score pool changes.
4 */
5module;
6
7
8export module helios.engine.mechanics.scoring.components.ScoreObserverComponent;
9
10import helios.engine.mechanics.scoring.ScorePoolSnapshot;
11import helios.engine.mechanics.scoring.types;
12
13import helios.core.types;
14
17}
18
20
22
23 /**
24 * @brief Component that observes and caches the score value from a ScorePool.
25 *
26 * Attached to UI entities to display score values. The
27 * ScoreObserverUpdateSystem updates this component's snapshot from the
28 * referenced ScorePool each frame. The hasUpdate flag indicates when the
29 * value has changed.
30 *
31 * @see ScoreObserverUpdateSystem
32 * @see ScoreObserverClearSystem
33 * @see ScorePoolSnapshot
34 */
36
38
39 private:
40
41 /**
42 * @brief ID of the score pool to observe.
43 */
45
46
47 /**
48 * @brief Flag indicating whether the value changed this frame.
49 *
50 * Cleared by ScoreObserverClearSystem at frame end.
51 */
52 bool hasUpdate_ = true;
53
54 /**
55 * @brief the current snapshot saved by this observer component.
56 */
58
59 /**
60 * @brief Whether this component is enabled.
61 */
62 bool isEnabled_ = true;
63
64 /**
65 * @brief Clears the update flag.
66 *
67 * Called by ScoreObserverClearSystem.
68 */
69 void clearUpdate() {
70 hasUpdate_ = false;
71 }
72
73 public:
74
75 /**
76 * @brief Checks whether this component is enabled.
77 *
78 * @return True if enabled, false otherwise.
79 */
80 [[nodiscard]] bool isEnabled() const noexcept {
81 return isEnabled_;
82 }
83
84 /**
85 * @brief Enables this component.
86 */
87 void enable() noexcept {
88 isEnabled_ = true;
89 }
90
91 /**
92 * @brief Disables this component.
93 */
94 void disable() noexcept {
95 isEnabled_ = false;
96 }
97
99
100 /**
101 * @brief Copy constructor.
102 *
103 * @param other The component to copy from.
104 */
106 scorePoolId_(other.scorePoolId_) {}
107
110 ScoreObserverComponent& operator=(ScoreObserverComponent&&) noexcept = default;
111
112 /**
113 * @brief Sets the score pool to observe.
114 *
115 * @param scorePoolId The ID of the pool to observe.
116 */
118 scorePoolId_ = scorePoolId;
119 }
120
121 /**
122 * @brief Returns the observed score pool ID.
123 *
124 * @return The ScorePoolId.
125 */
127 return scorePoolId_;
128 }
129
130 /**
131 * @brief Sets the cached snapshot value.
132 *
133 * Sets hasUpdate to true if the value changes.
134 *
135 * @param snapshot The snapshot to use for the next update.
136 */
138 if (snapshot_.revision == snapshot.revision) {
139 return;
140 }
141 snapshot_ = snapshot;
142 hasUpdate_ = true;
143 }
144
145 /**
146 * @brief Returns the cached score pool revision.
147 *
148 * @return The revision of the last observed snapshot.
149 */
150 [[nodiscard]] ScorePoolRevision scorePoolRevision() const noexcept {
151 return snapshot_.revision;
152 }
153
154 /**
155 * @brief Returns the cached total score.
156 *
157 * @return The current score value.
158 */
159 [[nodiscard]] double totalScore() const noexcept {
160 return snapshot_.totalScore;
161 }
162
163 /**
164 * @brief Checks if the value changed since last clear.
165 *
166 * @return True if the value was updated this frame.
167 */
168 [[nodiscard]] bool hasUpdate() const noexcept {
169 return hasUpdate_;
170 }
171
172 /**
173 * @brief Called when this entity is acquired from a pool.
174 *
175 * @details Clears the update flag and resets the cached snapshot.
176 */
177 void onAcquire() noexcept {
178 clearUpdate();
179 snapshot_ = {};
180 }
181
182 /**
183 * @brief Called when this entity is released back to a pool.
184 *
185 * @details Clears the update flag and resets the cached snapshot.
186 */
187 void onRelease() noexcept {
188 clearUpdate();
189 snapshot_ = {};
190 }
191 };
192
193
194}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.