Skip to main content

DefaultMatchStateTransitionGuards.ixx File

Default guard functions for match state transitions. 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...

namespacerules

Transition rules for the match state machine. More...

namespaceguards

Classes Index

classDefaultMatchStateTransitionGuards

Provides default guard functions for match state transitions. More...

Description

Default guard functions for match state transitions.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file DefaultMatchStateTransitionGuards.ixx
3 * @brief Default guard functions for match state transitions.
4 */
5module;
6
7export module helios.engine.mechanics.match.rules.guards.DefaultMatchStateTransitionGuards;
8
9import helios.engine.runtime.world.UpdateContext;
10import helios.engine.runtime.world.Session;
11import helios.engine.runtime.world.GameWorld;
12
13import helios.engine.state.Bindings;
14
15import helios.engine.mechanics.match.types;
16import helios.engine.state.types;
17
18import helios.engine.mechanics.match.components.LivesComponent;
19
21using namespace helios::engine::state::types;
23
25
26 /**
27 * @brief Provides default guard functions for match state transitions.
28 *
29 * @details Guard functions are predicates that determine whether a state
30 * transition is allowed. They are evaluated before a transition occurs and
31 * can block it by returning false.
32 *
33 * All guards are static functions that take an UpdateContext and a
34 * MatchStateTransitionRequest, returning true if the transition is allowed.
35 *
36 * @see MatchStateTransitionRequest
37 * @see MatchStateManager
38 */
40
41 public:
42
43 /**
44 * @brief Guard that allows transition only if the player is active.
45 *
46 * @param updateContext The current frame's update context.
47 * @param transitionRequest The requested state transition.
48 *
49 * @return True if the player entity exists and is active.
50 */
51 static bool isPlayerActive(
53 const StateTransitionRequest<MatchState> transitionRequest
54 ) {
55 auto playerOpt = updateContext.find(updateContext.session().playerEntityHandle());
56 return playerOpt.has_value() && playerOpt->isActive();
57
58 }
59
60 /**
61 * @brief Guard that allows transition only if the player is inactive.
62 *
63 * @param updateContext The current frame's update context.
64 * @param transitionRequest The requested state transition.
65 *
66 * @return True if the player entity exists and is inactive.
67 */
68 static bool isPlayerInactive(
70 const StateTransitionRequest<MatchState> transitionRequest
71 ) {
72 auto playerOpt = updateContext.find(updateContext.session().playerEntityHandle());
73 return playerOpt.has_value() && !playerOpt->isActive();
74
75 }
76
77 /**
78 * @brief Guard that allows transition only if the player has lives left.
79 *
80 * @param updateContext The current frame's update context.
81 * @param transitionRequest The requested state transition.
82 *
83 * @return True if the player entity has lives left.
84 */
85 static bool hasLifeLeft(
87 const StateTransitionRequest<MatchState> transitionRequest
88 ) {
89 auto playerOpt = updateContext.find(updateContext.session().playerEntityHandle());
90 if (!playerOpt) {
91 return false;
92 }
93 auto* lc = playerOpt->get<LivesComponent>();
94 return lc && lc->lives() > 0;
95
96 }
97
98 /**
99 * @brief Guard that allows transition only if the player has no lives left.
100 *
101 * @param updateContext The current frame's update context.
102 * @param transitionRequest The requested state transition.
103 *
104 * @return True if the player entity has no lives left.
105 *
106 * @see hasLifeLeft
107 */
108 static bool hasNoLifeLeft(
110 const StateTransitionRequest<MatchState> transitionRequest
111 ) {
112 return !hasLifeLeft(updateContext, transitionRequest);
113 }
114
115 };
116
117
118}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.