Skip to main content

LivesComponent.ixx File

Component tracking the remaining lives of an entity. 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...

namespacematch

Match state management for the helios engine. More...

namespacecomponents

Components for match rule tracking. More...

Classes Index

classLivesComponent

Tracks the remaining lives of an entity. More...

Description

Component tracking the remaining lives of an entity.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file LivesComponent.ixx
3 * @brief Component tracking the remaining lives of an entity.
4 */
5module;
6
7export module helios.engine.mechanics.match.components.LivesComponent;
8
9import helios.engine.mechanics.match.types;
10
12
14
15 /**
16 * @brief Tracks the remaining lives of an entity.
17 *
18 * Each modification increments an internal LivesRevision counter so
19 * that observer systems can detect changes without polling the value.
20 */
22
23 /**
24 * @brief Current number of remaining lives.
25 */
26 size_t lives_;
27
28 /**
29 * @brief Monotonically increasing revision counter.
30 */
31 LivesRevision livesRevision_{1};
32
33 /**
34 * @brief Number of default lives this component starts with.
35 */
36 size_t defaultLives_;
37
38 public:
39
40 /**
41 * @brief Constructs a LivesComponent with an initial life count.
42 *
43 * @details Constructs a LivesComponent with an initial life count.
44 * The default lives for this component will be initially set to this value.
45 *
46 * @param lives Initial number of lives.
47 */
48 explicit LivesComponent(const size_t lives) noexcept : lives_(lives), defaultLives_(lives) {};
49
50 /**
51 * @brief Resets this component to an initial state.
52 */
53 void reset() noexcept {
54 livesRevision_++;
55 lives_ = defaultLives_;
56 }
57
58 /**
59 * @brief Returns the current life count.
60 *
61 * @return Remaining lives.
62 */
63 [[nodiscard]] size_t lives() const noexcept {
64 return lives_;
65 }
66
67 /**
68 * @brief Decreases the life count by one and increments the revision.
69 *
70 * @return The new life count after decrement.
71 */
72 size_t decrease() noexcept {
73 if (lives_ == 0) {
74 return 0;
75 }
76 livesRevision_++;
77 return --lives_;
78 }
79
80 /**
81 * @brief Increases the life count by one and increments the revision.
82 *
83 * @return The new life count after increment.
84 */
85 size_t increase() noexcept {
86 livesRevision_++;
87 return ++lives_;
88 }
89
90 /**
91 * @brief Returns the current lives revision.
92 *
93 * @return The LivesRevision value.
94 */
95 [[nodiscard]] LivesRevision livesRevision() const noexcept {
96 return livesRevision_;
97 }
98
99 };
100
101}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.