Skip to main content

ScoreObserverSystem.ixx File

System that synchronizes ScoreObserverComponent with ScorePools. 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...

Classes Index

classScoreObserverSystem

System that propagates score snapshots to ScoreObserverComponents. More...

Description

System that synchronizes ScoreObserverComponent with ScorePools.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file ScoreObserverSystem.ixx
3 * @brief System that synchronizes ScoreObserverComponent with ScorePools.
4 */
5module;
6
7
8#include <format>
9
10
11export module helios.engine.mechanics.scoring.systems.ScoreObserverSystem;
12
13import helios.engine.mechanics.scoring.ScorePoolManager;
14import helios.engine.mechanics.scoring.commands;
15import helios.engine.mechanics.scoring.components;
16import helios.engine.mechanics.scoring.types;
17
18import helios.engine.runtime.world.GameWorld;
19import helios.engine.runtime.world.UpdateContext;
20
21
22import helios.engine.modules.physics.collision.events;
23
24import helios.engine.mechanics.lifecycle.components.Active;
25
26
27import helios.util.log;
28
29
30import helios.engine.common.tags.SystemRole;
31
33
34 /**
35 * @brief System that propagates score snapshots to ScoreObserverComponents.
36 *
37 * Each frame, queries all active entities with a ScoreObserverComponent
38 * and updates them with the current ScorePoolSnapshot from the
39 * ScorePoolManager. The component's revision-based change detection
40 * ensures that downstream consumers (e.g. UI bindings) are only notified
41 * when the score actually changes.
42 *
43 * @see ScoreObserverClearSystem
44 * @see ScoreObserverComponent
45 * @see ScorePoolManager
46 */
48
49 /**
50 * @brief Reference to the ScorePoolManager that owns the score pools.
51 */
52 ScorePoolManager& scorePoolManager_;
53
54
55 public:
56
58 /**
59 * @brief Constructs the system with a reference to the ScorePoolManager.
60 *
61 * @param scorePoolManager The ScorePoolManager providing score pool state.
62 */
63 explicit ScoreObserverSystem(ScorePoolManager& scorePoolManager)
64 : scorePoolManager_(scorePoolManager) {}
65
66 /**
67 * @brief Updates all active ScoreObserverComponents with current score data.
68 *
69 * Compares each observer's cached revision against the pool's current
70 * revision. On mismatch, propagates the pool's snapshot to the component.
71 *
72 * @param updateContext The current frame's update context.
73 */
75
76 for (auto [entity, soc, active] : updateContext.view<
79 >().whereEnabled()) {
80
81 const auto scorePoolId = soc->scorePoolId();
82 auto* scorePool = scorePoolManager_.scorePool(scorePoolId);
83
84 if (!scorePool) {
85 continue;
86 }
87
88 if (soc->scorePoolRevision() != scorePool->revision()) {
89 soc->setScorePoolSnapshot(scorePool->snapshot());
90 }
91
92 }
93
94 }
95
96 };
97
98}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.