Skip to main content

ScorePool Class

Container that accumulates scores by type within a pool. More...

Declaration

class helios::engine::mechanics::scoring::ScorePool { ... }

Public Constructors Index

ScorePool (const helios::engine::mechanics::scoring::types::ScorePoolId scorePoolId)

Constructs a ScorePool with the given ID. More...

Public Member Functions Index

helios::engine::mechanics::scoring::types::ScorePoolIdid () const noexcept

Returns the pool's unique identifier. More...

voidaddScore (const helios::engine::mechanics::scoring::types::ScoreValueContext &scoreContext)

Adds a score from the given context. More...

voidreset () noexcept

Resets all scores to zero. More...

doubletotalScore () const noexcept

Returns the running total of all scores. More...

helios::engine::mechanics::scoring::types::ScorePoolIdscorePoolId () const noexcept

Returns the pool's unique identifier. More...

helios::engine::mechanics::scoring::types::ScorePoolRevisionrevision () const noexcept

Returns the current revision number. More...

helios::engine::mechanics::scoring::ScorePoolSnapshotsnapshot () const noexcept

Returns a snapshot of the current pool state. More...

voidupdateMaxScore () noexcept

Recalculates the high score from the current total. More...

doublemaxScore () const noexcept

Returns the highest total score observed. More...

helios::engine::mechanics::scoring::types::ScorePoolRevisionmaxScoreRevision () const noexcept

Returns the revision counter for maxScore changes. More...

helios::engine::mechanics::scoring::MaxScorePoolSnapshotmaxScoreSnapshot () const noexcept

Returns a snapshot of the current high score state. More...

Private Member Functions Index

voidaddTotal (const double total) noexcept

Adds to the running total. More...

voidsetTotal (const double total) noexcept

Sets the running total directly. More...

Private Member Attributes Index

helios::engine::mechanics::scoring::types::ScorePoolIdscorePoolId_

Unique identifier for this score pool. More...

std::vector< double >scores_

Per-type score values indexed by ScoreTypeId. More...

doubletotalScore_ {}

Running total of all scores in this pool. More...

doublemaxScore_ {}

The highest total score observed so far. More...

helios::engine::mechanics::scoring::types::ScorePoolRevisionmaxScoreRevision_ {}

Revision counter for maxScore changes. More...

helios::engine::mechanics::scoring::types::ScorePoolRevisionrevision_ {}

The current revision of this ScorePool. More...

Description

Container that accumulates scores by type within a pool.

ScorePool maintains a collection of scores indexed by ScoreTypeId, along with a running total. It tracks changes via a revision number that is incremented whenever a score value changes, enabling efficient change detection by observers.

ScorePools are managed by ScorePoolManager, which handles command processing and pool lifecycle.

See Also

ScorePoolManager

See Also

ScorePoolSnapshot

See Also

ScoreValueContext

Definition at line 39 of file ScorePool.ixx.

Public Constructors

ScorePool()

helios::engine::mechanics::scoring::ScorePool::ScorePool (const helios::engine::mechanics::scoring::types::ScorePoolId scorePoolId)
inline explicit

Constructs a ScorePool with the given ID.

Parameters
scorePoolId

Unique identifier for this pool.

Definition at line 96 of file ScorePool.ixx.

Reference scorePoolId.

Public Member Functions

addScore()

void helios::engine::mechanics::scoring::ScorePool::addScore (const helios::engine::mechanics::scoring::types::ScoreValueContext & scoreContext)
inline

Adds a score from the given context.

Updates both the per-type score and the running total.

Parameters
scoreContext

Context containing type ID and value.

Definition at line 115 of file ScorePool.ixx.

116
117 auto id = scoreContext.scoreTypeId.value();
118
119 if (id >= scores_.size()) {
120 scores_.resize(id + 1, 0.0f);
121 }
122
123 const double oldScore = scores_[id];
124 scores_[id] += scoreContext.value;
125 if (oldScore != scores_[id]) {
126 revision_++;
127 }
128 addTotal(scoreContext.value);
130 }

References id, helios::engine::mechanics::scoring::types::ScoreValueContext::scoreTypeId, updateMaxScore, helios::engine::mechanics::scoring::types::ScoreTypeId::value and helios::engine::mechanics::scoring::types::ScoreValueContext::value.

id()

helios::engine::mechanics::scoring::types::ScorePoolId helios::engine::mechanics::scoring::ScorePool::id ()
inline nodiscard noexcept

Returns the pool's unique identifier.

Returns

The ScorePoolId.

Definition at line 104 of file ScorePool.ixx.

105 return scorePoolId_;
106 }

Referenced by addScore.

maxScore()

double helios::engine::mechanics::scoring::ScorePool::maxScore ()
inline nodiscard noexcept

Returns the highest total score observed.

Returns

The maximum score value.

Definition at line 204 of file ScorePool.ixx.

204 [[nodiscard]] double maxScore() const noexcept {
205 return maxScore_;
206 }

maxScoreRevision()

helios::engine::mechanics::scoring::types::ScorePoolRevision helios::engine::mechanics::scoring::ScorePool::maxScoreRevision ()
inline nodiscard noexcept

Returns the revision counter for maxScore changes.

Returns

The current max score revision.

Definition at line 213 of file ScorePool.ixx.

214 return maxScoreRevision_;
215 }

maxScoreSnapshot()

helios::engine::mechanics::scoring::MaxScorePoolSnapshot helios::engine::mechanics::scoring::ScorePool::maxScoreSnapshot ()
inline nodiscard noexcept

Returns a snapshot of the current high score state.

Returns

A MaxScorePoolSnapshot with current values.

See Also

MaxScorePoolSnapshot

Definition at line 224 of file ScorePool.ixx.

225 return {.scorePoolId = scorePoolId_, .maxScore = maxScore_, .revision = maxScoreRevision_};
226 }

reset()

void helios::engine::mechanics::scoring::ScorePool::reset ()
inline noexcept

Resets all scores to zero.

Definition at line 135 of file ScorePool.ixx.

135 void reset() noexcept {
136 std::fill(scores_.begin(), scores_.end(), 0.0f);
137 setTotal(0.0f);
138 revision_++;
139 }

revision()

helios::engine::mechanics::scoring::types::ScorePoolRevision helios::engine::mechanics::scoring::ScorePool::revision ()
inline nodiscard noexcept

Returns the current revision number.

The revision is incremented whenever a score value changes. Used by observers to detect changes without polling values.

Returns

The current ScorePoolRevision.

Definition at line 168 of file ScorePool.ixx.

169 return revision_;
170 }

scorePoolId()

helios::engine::mechanics::scoring::types::ScorePoolId helios::engine::mechanics::scoring::ScorePool::scorePoolId ()
inline nodiscard noexcept

Returns the pool's unique identifier.

Returns

The ScorePoolId.

Definition at line 156 of file ScorePool.ixx.

157 return scorePoolId_;
158 }

Referenced by ScorePool.

snapshot()

helios::engine::mechanics::scoring::ScorePoolSnapshot helios::engine::mechanics::scoring::ScorePool::snapshot ()
inline nodiscard noexcept

Returns a snapshot of the current pool state.

The snapshot contains the pool ID, total score, and current revision. Useful for observers and UI binding.

Returns

A ScorePoolSnapshot with current values.

Definition at line 180 of file ScorePool.ixx.

181 return {.scorePoolId = scorePoolId_, .totalScore = totalScore_, .revision = revision_};
182 }

totalScore()

double helios::engine::mechanics::scoring::ScorePool::totalScore ()
inline nodiscard noexcept

Returns the running total of all scores.

Returns

The total score value.

Definition at line 147 of file ScorePool.ixx.

147 [[nodiscard]] double totalScore() const noexcept {
148 return totalScore_;
149 }

updateMaxScore()

void helios::engine::mechanics::scoring::ScorePool::updateMaxScore ()
inline noexcept

Recalculates the high score from the current total.

Increments maxScoreRevision if the high score changes. Called automatically by addScore().

Definition at line 191 of file ScorePool.ixx.

191 void updateMaxScore() noexcept {
192 const auto tmpScore = std::max(totalScore_, maxScore_);
193 if (tmpScore != maxScore_) {
194 maxScoreRevision_++;
195 maxScore_ = tmpScore;
196 }
197 }

Referenced by addScore.

Private Member Functions

addTotal()

void helios::engine::mechanics::scoring::ScorePool::addTotal (const double total)
inline noexcept

Adds to the running total.

Parameters
total

Value to add.

Definition at line 71 of file ScorePool.ixx.

71 void addTotal(const double total) noexcept {
72 totalScore_ += total;
73 }

setTotal()

void helios::engine::mechanics::scoring::ScorePool::setTotal (const double total)
inline noexcept

Sets the running total directly.

Parameters
total

New total value.

Definition at line 80 of file ScorePool.ixx.

80 void setTotal(const double total) noexcept {
81 totalScore_ = total;
82 }

Private Member Attributes

maxScore_

double helios::engine::mechanics::scoring::ScorePool::maxScore_ {}

The highest total score observed so far.

Definition at line 59 of file ScorePool.ixx.

59 double maxScore_{};

maxScoreRevision_

helios::engine::mechanics::scoring::types::ScorePoolRevision helios::engine::mechanics::scoring::ScorePool::maxScoreRevision_ {}

Revision counter for maxScore changes.

Definition at line 64 of file ScorePool.ixx.

revision_

helios::engine::mechanics::scoring::types::ScorePoolRevision helios::engine::mechanics::scoring::ScorePool::revision_ {}

The current revision of this ScorePool.

Definition at line 87 of file ScorePool.ixx.

scorePoolId_

helios::engine::mechanics::scoring::types::ScorePoolId helios::engine::mechanics::scoring::ScorePool::scorePoolId_

Unique identifier for this score pool.

Definition at line 44 of file ScorePool.ixx.

scores_

std::vector<double> helios::engine::mechanics::scoring::ScorePool::scores_

Per-type score values indexed by ScoreTypeId.

Definition at line 49 of file ScorePool.ixx.

49 std::vector<double> scores_;

totalScore_

double helios::engine::mechanics::scoring::ScorePool::totalScore_ {}

Running total of all scores in this pool.

Definition at line 54 of file ScorePool.ixx.

54 double totalScore_{};

The documentation for this class was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.