Skip to main content

LivesComponent Class

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

Declaration

class helios::engine::mechanics::match::components::LivesComponent { ... }

Public Constructors Index

LivesComponent (const size_t lives) noexcept

Constructs a LivesComponent with an initial life count. More...

Public Member Functions Index

voidreset () noexcept

Resets this component to an initial state. More...

size_tlives () const noexcept

Returns the current life count. More...

size_tdecrease () noexcept

Decreases the life count by one and increments the revision. More...

size_tincrease () noexcept

Increases the life count by one and increments the revision. More...

LivesRevisionlivesRevision () const noexcept

Returns the current lives revision. More...

Private Member Attributes Index

size_tlives_

Current number of remaining lives. More...

LivesRevisionlivesRevision_ {1}

Monotonically increasing revision counter. More...

size_tdefaultLives_

Number of default lives this component starts with. More...

Description

Tracks the remaining lives of an entity.

Each modification increments an internal LivesRevision counter so that observer systems can detect changes without polling the value.

Definition at line 21 of file LivesComponent.ixx.

Public Constructors

LivesComponent()

helios::engine::mechanics::match::components::LivesComponent::LivesComponent (const size_t lives)
inline explicit noexcept

Constructs a LivesComponent with an initial life count.

Constructs a LivesComponent with an initial life count. The default lives for this component will be initially set to this value.

Parameters
lives

Initial number of lives.

Definition at line 48 of file LivesComponent.ixx.

48 explicit LivesComponent(const size_t lives) noexcept : lives_(lives), defaultLives_(lives) {};

Reference lives.

Public Member Functions

decrease()

size_t helios::engine::mechanics::match::components::LivesComponent::decrease ()
inline noexcept

Decreases the life count by one and increments the revision.

Returns

The new life count after decrement.

Definition at line 72 of file LivesComponent.ixx.

72 size_t decrease() noexcept {
73 if (lives_ == 0) {
74 return 0;
75 }
76 livesRevision_++;
77 return --lives_;
78 }

increase()

size_t helios::engine::mechanics::match::components::LivesComponent::increase ()
inline noexcept

Increases the life count by one and increments the revision.

Returns

The new life count after increment.

Definition at line 85 of file LivesComponent.ixx.

85 size_t increase() noexcept {
86 livesRevision_++;
87 return ++lives_;
88 }

lives()

size_t helios::engine::mechanics::match::components::LivesComponent::lives ()
inline nodiscard noexcept

Returns the current life count.

Returns

Remaining lives.

Definition at line 63 of file LivesComponent.ixx.

63 [[nodiscard]] size_t lives() const noexcept {
64 return lives_;
65 }

Referenced by helios::engine::mechanics::match::rules::guards::DefaultMatchStateTransitionGuards::hasLifeLeft and LivesComponent.

livesRevision()

LivesRevision helios::engine::mechanics::match::components::LivesComponent::livesRevision ()
inline nodiscard noexcept

Returns the current lives revision.

Returns

The LivesRevision value.

Definition at line 95 of file LivesComponent.ixx.

95 [[nodiscard]] LivesRevision livesRevision() const noexcept {
96 return livesRevision_;
97 }

reset()

void helios::engine::mechanics::match::components::LivesComponent::reset ()
inline noexcept

Resets this component to an initial state.

Definition at line 53 of file LivesComponent.ixx.

53 void reset() noexcept {
54 livesRevision_++;
55 lives_ = defaultLives_;
56 }

Private Member Attributes

defaultLives_

size_t helios::engine::mechanics::match::components::LivesComponent::defaultLives_

Number of default lives this component starts with.

Definition at line 36 of file LivesComponent.ixx.

36 size_t defaultLives_;

lives_

size_t helios::engine::mechanics::match::components::LivesComponent::lives_

Current number of remaining lives.

Definition at line 26 of file LivesComponent.ixx.

26 size_t lives_;

livesRevision_

LivesRevision helios::engine::mechanics::match::components::LivesComponent::livesRevision_ {1}

Monotonically increasing revision counter.

Definition at line 31 of file LivesComponent.ixx.

31 LivesRevision livesRevision_{1};

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.