StateManager Class Template
Manages state transitions using a rule-based system. More...
Declaration
Base classes
| class | Manager |
|
Abstract base class for managers that process deferred operations. More... | |
| class | TypedStateCommandHandler<StateType> |
|
Typed interface for handling state commands. More... | |
Public Constructors Index
template <typename StateType> | |
| StateManager (std::span< const StateTransitionRule< StateType > > rules) | |
|
Constructs a state manager with transition rules. More... | |
Public Member Functions Index
template <typename StateType> | |
| StateManager & | addStateListener (std::unique_ptr< StateTransitionListener< StateType > > listener) noexcept |
|
Registers a state transition listener. More... | |
template <typename StateType> | |
| void | flush (helios::engine::runtime::world::GameWorld &gameWorld, helios::engine::runtime::world::UpdateContext &updateContext) noexcept override |
|
Processes pending state commands. More... | |
template <typename StateType> | |
| bool | submit (const StateCommand< StateType > &stateCommand) noexcept override |
|
Submits a state command for processing. More... | |
template <typename StateType> | |
| void | init (helios::engine::runtime::world::GameWorld &gameWorld) override |
|
Initializes the manager and registers with GameWorld. More... | |
template <typename StateType> | |
| void | reset () override |
|
Clears all pending commands. More... | |
Private Member Functions Index
template <typename StateType> | |
| void | signalExit (const StateType from, const StateType to, const StateTransitionIdType< StateType > transitionId, helios::engine::runtime::world::UpdateContext &updateContext) |
|
Notifies listeners of state exit. More... | |
template <typename StateType> | |
| void | signalTransition (const StateType from, const StateType to, const StateTransitionIdType< StateType > transitionId, helios::engine::runtime::world::UpdateContext &updateContext) |
|
Notifies listeners of the transition. More... | |
template <typename StateType> | |
| void | signalEnter (const StateType from, const StateType to, const StateTransitionIdType< StateType > transitionId, helios::engine::runtime::world::UpdateContext &updateContext) |
|
Notifies listeners of state entry. More... | |
Private Member Attributes Index
template <typename StateType> | |
| std::vector< StateCommand< StateType > > | pending_ |
|
Queue of pending state commands. More... | |
template <typename StateType> | |
| std::vector< std::unique_ptr< StateTransitionListener< StateType > > > | listeners_ |
|
Registered transition listeners. More... | |
template <typename StateType> | |
| std::vector< StateTransitionRule< StateType > > | rules_ |
|
Transition rules defining valid state changes. More... | |
Description
Manages state transitions using a rule-based system.
Implements both Manager and TypedStateCommandHandler interfaces. Processes state transition commands by matching against registered rules, executing guards, and notifying listeners.
## Transition Flow
1. Commands are submitted via submit() and queued 2. During flush(), the last pending command is processed 3. Rules are checked to find a matching transition 4. If a guard is present, it must return true 5. Listeners are notified: onStateExit -> onStateTransition -> onStateEnter 6. Session state is updated
- Template Parameters
-
StateType The state enum type.
- See Also
- See Also
- See Also
Definition at line 64 of file StateManager.ixx.
Public Constructors
StateManager()
| inline explicit |
Constructs a state manager with transition rules.
- Parameters
-
rules Span of valid transition rules.
Definition at line 151 of file StateManager.ixx.
Public Member Functions
addStateListener()
| inline noexcept |
Registers a state transition listener.
- Parameters
-
listener The listener to add.
- Returns
Reference to this manager for chaining.
Definition at line 161 of file StateManager.ixx.
flush()
| inline noexcept virtual |
Processes pending state commands.
Processes the last pending command, finds matching rules, executes guards, and triggers the transition if valid.
- Parameters
-
gameWorld The game world.
updateContext The current frame's update context.
Definition at line 175 of file StateManager.ixx.
init()
| inline virtual |
Initializes the manager and registers with GameWorld.
- Parameters
-
gameWorld The game world to register with.
Definition at line 238 of file StateManager.ixx.
reset()
| inline virtual |
Clears all pending commands.
Definition at line 245 of file StateManager.ixx.
submit()
| inline noexcept virtual |
Submits a state command for processing.
- Parameters
-
stateCommand The command to queue.
- Returns
True (always accepts commands).
Definition at line 226 of file StateManager.ixx.
Private Member Functions
signalEnter()
| inline |
Notifies listeners of state entry.
- Parameters
-
from The source state.
to The state being entered.
transitionId The transition identifier.
updateContext The current frame's update context.
Definition at line 131 of file StateManager.ixx.
signalExit()
| inline |
Notifies listeners of state exit.
- Parameters
-
from The state being exited.
to The target state.
transitionId The transition identifier.
updateContext The current frame's update context.
Definition at line 90 of file StateManager.ixx.
signalTransition()
| inline |
Notifies listeners of the transition.
- Parameters
-
from The source state.
to The target state.
transitionId The transition identifier.
updateContext The current frame's update context.
Definition at line 109 of file StateManager.ixx.
Private Member Attributes
listeners_
|
Registered transition listeners.
Definition at line 75 of file StateManager.ixx.
pending_
|
Queue of pending state commands.
Definition at line 70 of file StateManager.ixx.
rules_
|
Transition rules defining valid state changes.
Definition at line 80 of file StateManager.ixx.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.