StateManager.ixx File
Generic state manager and transition orchestrator. More...
Included Headers
#include <memory>
#include <span>
#include <vector>
#include <helios.engine.state.TypedStateCommandHandler>
#include <helios.engine.state.StateTransitionListener>
#include <helios.engine.state.types>
#include <helios.engine.core.types>
#include <helios.engine.state.types.StateTransitionRule>
#include <helios.engine.state.components>
#include <helios.engine.util.Guid>
#include <helios.engine.state.commands>
#include <helios.engine.runtime.world.UpdateContext>
#include <helios.engine.runtime.messaging.command.CommandHandlerRegistry>
#include <helios.engine.runtime.world.Session>
#include <helios.engine.runtime.world.tags.ManagerRole>
#include <helios.engine.runtime.world.GameObject>
Namespaces Index
| namespace | helios |
| namespace | engine |
| namespace | state |
Classes Index
| class | StateManager<StateType> |
|
Manages state transitions using a rule-based system. More... | |
Description
Generic state manager and transition orchestrator.
File Listing
The file content with the documentation metadata removed is:
43export namespace helios::engine::state {
70 class StateManager {
98 const StateTransitionIdType<StateType> transitionId,
101 for (auto& listener : listeners_) {
102 listener->onStateExit(updateContext, from);
117 const StateTransitionIdType<StateType> transitionId,
120 for (auto& listener : listeners_) {
121 listener->onStateTransition(
122 updateContext,
123 StateTransitionContext<StateType>{from, to, transitionId}
139 const StateTransitionIdType<StateType> transitionId,
142 for (auto& listener : listeners_) {
143 listener->onStateEnter(updateContext, to);
157 explicit StateManager(std::span<const StateTransitionRule<StateType>> rules)
167 StateManager& addStateListener(std::unique_ptr<StateTransitionListener<StateType>> listener) noexcept {
168 listeners_.push_back(std::move(listener));
192 auto& session = updateContext.session();
193 auto currentFrom = session.state<StateType>();
198 if (currentFrom != from) {
204 for (auto& rule : rules_) {
207 if (rule.guard()) {
208 if (!rule.guard()(updateContext, transitionRequest)) {
213 signalExit(from, rule.to(), transitionId, updateContext);
214 signalTransition(from, rule.to(), transitionId, updateContext);
215 session.setStateFrom<StateType>(StateTransitionContext<StateType>{rule.from(), rule.to(), transitionId});
216 signalEnter(from, rule.to(), transitionId, updateContext);
231 const StateCommand<StateType> stateCommand
233 pending_.push_back(stateCommand);
251 const DelayedStateCommand<StateType> stateCommand
253 pending_.push_back(StateCommand<StateType>(stateCommand.transitionRequest()));
262 void init(helios::engine::runtime::messaging::command::CommandHandlerRegistry& commandHandlerRegistry) {
263 commandHandlerRegistry.registerHandler<StateCommand<StateType>>(*this);
264 commandHandlerRegistry.registerHandler<DelayedStateCommand<StateType>>(*this);
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.