Skip to main content

MaxScoreObserverComponent.ixx File

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

classMaxScoreObserverClearSystem

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

classMaxScoreObserverComponent

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

Description

Component for observing score pool changes as high score.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file MaxScoreObserverComponent.ixx
3 * @brief Component for observing score pool changes as high score.
4 */
5module;
6
7
8export module helios.engine.mechanics.scoring.components.MaxScoreObserverComponent;
9
10import helios.engine.mechanics.scoring.MaxScorePoolSnapshot;
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 high score value from a ScorePool.
25 *
26 * Attached to UI entities to display high score values. The
27 * MaxScoreObserverUpdateSystem 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 MaxScoreObserverUpdateSystem
32 * @see MaxScoreObserverClearSystem
33 * @see MaxScorePoolSnapshot
34 */
36
37
39
40 private:
41
42 /**
43 * @brief ID of the score pool to observe.
44 */
46
47
48 /**
49 * @brief Flag indicating whether the value changed this frame.
50 *
51 * Cleared by MaxScoreObserverClearSystem at frame end.
52 */
53 bool hasUpdate_ = true;
54
55 /**
56 * @brief the current snapshot saved by this observer component.
57 */
58 MaxScorePoolSnapshot snapshot_;
59
60 /**
61 * @brief Whether this component is enabled.
62 */
63 bool isEnabled_ = true;
64
65 /**
66 * @brief Clears the update flag.
67 *
68 * Called by MaxScoreObserverClearSystem.
69 */
70 void clearUpdate() {
71 hasUpdate_ = false;
72 }
73
74 public:
75
76 /**
77 * @brief Checks whether this component is enabled.
78 *
79 * @return True if enabled, false otherwise.
80 */
81 [[nodiscard]] bool isEnabled() const noexcept {
82 return isEnabled_;
83 }
84
85 /**
86 * @brief Enables this component.
87 */
88 void enable() noexcept {
89 isEnabled_ = true;
90 }
91
92 /**
93 * @brief Disables this component.
94 */
95 void disable() noexcept {
96 isEnabled_ = false;
97 }
98
100
101 /**
102 * @brief Copy constructor.
103 *
104 * @param other The component to copy from.
105 */
107 scorePoolId_(other.scorePoolId_) {}
108
111 MaxScoreObserverComponent& operator=(MaxScoreObserverComponent&&) noexcept = default;
112
113 /**
114 * @brief Sets the score pool to observe.
115 *
116 * @param scorePoolId The ID of the pool to observe.
117 */
118 void setScorePoolId(const ScorePoolId scorePoolId) noexcept {
119 scorePoolId_ = scorePoolId;
120 }
121
122 /**
123 * @brief Returns the observed score pool ID.
124 *
125 * @return The ScorePoolId.
126 */
127 [[nodiscard]] ScorePoolId scorePoolId() const noexcept {
128 return scorePoolId_;
129 }
130
131 /**
132 * @brief Sets the cached snapshot value.
133 *
134 * Sets hasUpdate to true if the value changes.
135 *
136 * @param snapshot The snapshot to use for the next update.
137 */
139 if (snapshot_.revision == snapshot.revision) {
140 return;
141 }
142 snapshot_ = snapshot;
143 hasUpdate_ = true;
144 }
145
146 /**
147 * @brief Returns the cached score pool revision.
148 *
149 * @return The revision of the last observed snapshot.
150 */
151 [[nodiscard]] ScorePoolRevision scorePoolRevision() const noexcept {
152 return snapshot_.revision;
153 }
154
155 /**
156 * @brief Returns the cached max score.
157 *
158 * @return The current high score value.
159 */
160 [[nodiscard]] double maxScore() const noexcept {
161 return snapshot_.maxScore;
162 }
163
164 /**
165 * @brief Checks if the value changed since last clear.
166 *
167 * @return True if the value was updated this frame.
168 */
169 [[nodiscard]] bool hasUpdate() const noexcept {
170 return hasUpdate_;
171 }
172
173
174 };
175
176
177}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.