nomlib
Loading...
Searching...
No Matches
nom::StateMachine Class Reference

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.
uint32 current_state_id (void) const
 Obtain the current state's identifier.
uint32 next_state_id (void) const
 Obtain the next state's identifier.
void set_state (std::unique_ptr< IState > state, void_ptr data)
void pop_state (void_ptr data)
void on_event (const Event &ev)
 Event handling logic for the active state.
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.

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.

Detailed Description

Finite State Machine manager class.

Definition at line 60 of file StateMachine.hpp.

Member Function Documentation

◆ count()

uint32 nom::StateMachine::count ( ) const

Get the number of active states.

Returns
Total number of states in the stack.

◆ current_state_id()

uint32 nom::StateMachine::current_state_id ( void ) const

Obtain the current state's identifier.

Returns
The identifier of the state, or an assertion on failure, such as if the the states stack is empty.
Remarks
The state identifier is user-defined.

◆ next_state_id()

uint32 nom::StateMachine::next_state_id ( void ) const

Obtain the next state's identifier.

Returns
The identifier of the next state (in the stack), or an assertion on failure, such as if the the states stack is empty.
Remarks
The state identifier is user-defined.

◆ on_event()

void nom::StateMachine::on_event ( const Event & ev)

Event handling logic for the active state.

See also
nom::IState::on_event.

◆ pop_state()

void nom::StateMachine::pop_state ( void_ptr data)
Parameters
stateThe nom::IState deriving object to be set as the current state.
dataUser-defined data; used for passing data in between states.
See also
StateMachine::set_deferred_state

◆ set_deferred_state()

void nom::StateMachine::set_deferred_state ( std::unique_ptr< IState > state,
void_ptr data )
private

Set the next state.

Parameters
stateThe state to be put onto the stack. If NULL is passed, the current state exits and the next one after that is resumed.
Note
Where on the stack the state is put is dependent upon the type of state defined (see also: nom::IState::Type enumeration).
Remarks
The transition of the state must be deferred until the next frame update in order for engine callback systems, i.e.: nom::InputMapper and nom::UIWidget, to be used within application-level code that expects to be able to change its state from within said callback system. If not deferred, the result is invalid memory access (a crash if you are lucky!) due to the deletion of the state before the callback is completed.

◆ set_state()

void nom::StateMachine::set_state ( std::unique_ptr< IState > state,
void_ptr data )
Parameters
stateThe nom::IState deriving object to be set as the current state.
dataUser-defined data; used for passing data in between states.
See also
StateMachine::set_deferred_state

◆ update()

void nom::StateMachine::update ( float delta)

State logic handling.

Remarks
Deferred state transition logic is handled here.

Member Data Documentation

◆ next_state_

priv::DeferredState nom::StateMachine::next_state_
private

The pending state to be set on the next frame update.

Definition at line 140 of file StateMachine.hpp.

◆ states_

std::vector<std::unique_ptr<IState> > nom::StateMachine::states_
private

Stack of states.

Definition at line 143 of file StateMachine.hpp.


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