![]() |
nomlib
|
Finite State Machine manager class. More...
#include <StateMachine.hpp>
Public Member Functions | |
| StateMachine () | |
| Default constructor. | |
| ~StateMachine () | |
| Destructor. | |
| uint32 | count () const |
| Get the number of active states. | |
| bool | empty () const |
| Check if the state stack is empty. | |
| uint32 | current_state_id (void) const |
| Obtain the current state's identifier. | |
| uint32 | next_state_id (void) const |
| Obtain the next pending state's identifier. | |
| StateSymbol | current_state_symbol () const |
| Obtain the current active state symbol. | |
| void | register_state (const StateDescriptor &desc) |
| Register a state factory and optional parent relationship. | |
| void | add_transition (StateSymbol active, EventSymbol event, StateSymbol stack_top, const Transition &transition) |
| Add an exact event-driven transition to the machine's table. | |
| void | add_transition (StateSymbol active, EventSymbol event, const Transition &transition) |
| Add a wildcard event-driven transition to the machine's table. | |
| void | set_transition_fallback (const TransitionTable::Callback &callback) |
| Install a fallback transition resolver. | |
| void | set_input_mapper (InputStateMapper *mapper) |
| Install the input mapper used to auto-manage per-state input contexts during state transitions. | |
| InputStateMapper * | input_mapper () const |
| Obtain the installed input mapper, or nullptr. | |
| void | set_state (std::unique_ptr< IState > state, void_ptr data) |
| void | pop_state (void_ptr data) |
| void | push_state (StateSymbol symbol, void_ptr data=nullptr) |
| Push a registered state onto the stack by symbol. | |
| void | push (StateSymbol child, void_ptr data=nullptr) |
| Push a registered child state onto the active parent. | |
| void | pop (StateSymbol parent, void_ptr data=nullptr) |
| Pop states until the requested parent state is active. | |
| void | replace (StateSymbol symbol, void_ptr data=nullptr) |
| Replace the active state with a registered state by symbol. | |
| void | on_event (const Event &ev) |
| Event handling logic for the active state. | |
| void | on_event (EventSymbol event_symbol, const Event *ev) |
| Event handling logic with transition-table evaluation. | |
| void | update (float delta) |
| State logic handling. | |
| void | draw (RenderWindow &) |
| State rendering handling. | |
Private Member Functions | |
| void | set_deferred_state (std::unique_ptr< IState > state, void_ptr data) |
| Set the next state. | |
| void | activate_input_context (const IState &state) |
| void | disable_input_context (const IState &state) |
| void | erase_input_context (const IState &state) |
| IState::unique_ptr | make_state (StateSymbol symbol, void_ptr data=nullptr) const |
| Construct a registered state by symbol. | |
| bool | can_push (StateSymbol child, StateSymbol parent) const |
| Validate that child is declared as a child of the given parent. | |
Private Attributes | |
| priv::DeferredState | next_state_ |
| The pending state to be set on the next frame update. | |
| std::vector< std::unique_ptr< IState > > | states_ |
| Stack of states. | |
| std::map< StateSymbol, StateDescriptor > | registry_ |
| Registered state factories keyed by symbol. | |
| TransitionTable | transitions_ |
| Event-driven transition table. | |
| InputStateMapper * | input_mapper_ = nullptr |
Finite State Machine manager class.
Definition at line 171 of file StateMachine.hpp.
| void nom::StateMachine::add_transition | ( | StateSymbol | active, |
| EventSymbol | event, | ||
| const Transition & | transition ) |
Add a wildcard event-driven transition to the machine's table.
The stack top symbol is ignored when matching this transition.
| uint32 nom::StateMachine::count | ( | ) | const |
Get the number of active states.
| uint32 nom::StateMachine::current_state_id | ( | void | ) | const |
Obtain the current state's identifier.
| StateSymbol nom::StateMachine::current_state_symbol | ( | ) | const |
Obtain the current active state symbol.
|
private |
Construct a registered state by symbol.
| symbol | Registered symbol to construct. |
| data | User-defined data passed to the registered factory. |
| uint32 nom::StateMachine::next_state_id | ( | void | ) | const |
Obtain the next pending state's identifier.
| void nom::StateMachine::on_event | ( | const Event & | ev | ) |
Event handling logic for the active state.
Forwards the event to the active state's on_event. No transition-table lookup is performed; use on_event(EventSymbol, const Event&) to drive event-driven transitions.
| void nom::StateMachine::on_event | ( | EventSymbol | event_symbol, |
| const Event * | ev ) |
Event handling logic with transition-table evaluation.
Queries the transition table using the active state symbol, the provided event symbol, and the current stack-top symbol. If a transition matches, it is applied and the event is consumed. If no transition matches and ev is not nullptr, the event is forwarded to the active state's on_event.
| void nom::StateMachine::pop | ( | StateSymbol | parent, |
| void_ptr | data = nullptr ) |
Pop states until the requested parent state is active.
All intermediate states are exited. If the target parent is already active, this is a no-op.
| parent | Symbol of the parent state to make active. |
| data | User-defined data passed to lifecycle hooks. |
| void nom::StateMachine::pop_state | ( | void_ptr | data | ) |
| state | The nom::IState deriving object to be set as the current state. |
| data | User-defined data; used for passing data in between states. |
| void nom::StateMachine::push | ( | StateSymbol | child, |
| void_ptr | data = nullptr ) |
Push a registered child state onto the active parent.
The child must be registered with a parent matching the active state's symbol, or the request is rejected.
| child | Symbol of the child state to push. |
| data | User-defined data passed to on_init. |
| void nom::StateMachine::push_state | ( | StateSymbol | symbol, |
| void_ptr | data = nullptr ) |
Push a registered state onto the stack by symbol.
| symbol | Symbol registered with register_state(). |
| data | User-defined data passed to on_init. |
| void nom::StateMachine::register_state | ( | const StateDescriptor & | desc | ) |
Register a state factory and optional parent relationship.
Registered states can be pushed by symbol via push_state and can act as targets for event-driven transitions.
| desc | State descriptor containing the symbol, optional parent, and factory. |
| void nom::StateMachine::replace | ( | StateSymbol | symbol, |
| void_ptr | data = nullptr ) |
Replace the active state with a registered state by symbol.
| symbol | Symbol registered with register_state(). |
| data | User-defined data passed to lifecycle hooks. |
|
private |
Set the next state.
| state | The state to be put onto the stack. If NULL is passed, the current state exits and the next one after that is resumed. |
| void nom::StateMachine::set_input_mapper | ( | InputStateMapper * | mapper | ) |
Install the input mapper used to auto-manage per-state input contexts during state transitions.
| mapper | Non-owned pointer; it must outlive this machine or be reset via set_input_mapper(nullptr). May be nullptr (default). |
| void nom::StateMachine::set_state | ( | std::unique_ptr< IState > | state, |
| void_ptr | data ) |
| state | The nom::IState deriving object to be set as the current state. |
| data | User-defined data; used for passing data in between states. |
| void nom::StateMachine::set_transition_fallback | ( | const TransitionTable::Callback & | callback | ) |
Install a fallback transition resolver.
Called when no exact or wildcard transition exists.
| void nom::StateMachine::update | ( | float | delta | ) |
State logic handling.
|
private |
Definition at line 376 of file StateMachine.hpp.
|
private |
The pending state to be set on the next frame update.
Definition at line 365 of file StateMachine.hpp.
|
private |
Registered state factories keyed by symbol.
Definition at line 371 of file StateMachine.hpp.
|
private |
Stack of states.
Definition at line 368 of file StateMachine.hpp.
|
private |
Event-driven transition table.
Definition at line 374 of file StateMachine.hpp.