Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
CFsm< Context > Class Template Reference

Manages states, events, actions and transitions between states. More...

#include <FSM.h>

Classes

struct  CallbackFunction
 
struct  Transition
 
struct  TransitionKey
 

Public Member Functions

void AddTransition (unsigned int state, unsigned int eventType, unsigned int nextState, Action *pAction=nullptr, Context *pContext=nullptr)
 Adds a new transistion to the state machine. More...
 
void SetFirstState (unsigned int firstState)
 Sets the initial state for FSM. More...
 
void SetCurrState (unsigned int state)
 Sets the current state and update the last state to the current state. More...
 
unsigned int GetCurrState () const
 
void SetNextState (unsigned int nextState)
 
unsigned int GetNextState () const
 
bool Update (unsigned int eventType, void *pEventData)
 Updates the FSM and retrieves next state. More...
 
bool IsDone () const
 Tests whether the state machine has finished its work. More...
 

Private Types

using Action = bool(Context *pContext, CFsmEvent *pEvent)
 
using TransitionMap = std::unordered_map< TransitionKey, const Transition, typename TransitionKey::Hash >
 

Private Member Functions

bool IsFirstTime () const
 Verifies whether state machine has already been updated. More...
 

Private Attributes

bool m_Done {false}
 
unsigned int m_FirstState {FSM_INVALID_STATE}
 
unsigned int m_CurrState {FSM_INVALID_STATE}
 
unsigned int m_NextState {FSM_INVALID_STATE}
 
TransitionMap m_Transitions
 

Detailed Description

template<typename Context>
class CFsm< Context >

Manages states, events, actions and transitions between states.

It provides an interface for advertising events and track the current state. The implementation is a Mealy state machine, so the system respond to events and execute some action.

A Mealy state machine has behaviour associated with state transitions; Mealy machines are event driven where an event triggers a state transition.

Member Typedef Documentation

◆ Action

template<typename Context >
using CFsm< Context >::Action = bool(Context* pContext, CFsmEvent* pEvent)
private

◆ TransitionMap

template<typename Context >
using CFsm< Context >::TransitionMap = std::unordered_map<TransitionKey, const Transition, typename TransitionKey::Hash>
private

Member Function Documentation

◆ AddTransition()

template<typename Context >
void CFsm< Context >::AddTransition ( unsigned int  state,
unsigned int  eventType,
unsigned int  nextState,
Action pAction = nullptr,
Context *  pContext = nullptr 
)
inline

Adds a new transistion to the state machine.

◆ GetCurrState()

template<typename Context >
unsigned int CFsm< Context >::GetCurrState ( ) const
inline

◆ GetNextState()

template<typename Context >
unsigned int CFsm< Context >::GetNextState ( ) const
inline

◆ IsDone()

template<typename Context >
bool CFsm< Context >::IsDone ( ) const
inline

Tests whether the state machine has finished its work.

◆ IsFirstTime()

template<typename Context >
bool CFsm< Context >::IsFirstTime ( ) const
inlineprivate

Verifies whether state machine has already been updated.

◆ SetCurrState()

template<typename Context >
void CFsm< Context >::SetCurrState ( unsigned int  state)
inline

Sets the current state and update the last state to the current state.

◆ SetFirstState()

template<typename Context >
void CFsm< Context >::SetFirstState ( unsigned int  firstState)
inline

Sets the initial state for FSM.

◆ SetNextState()

template<typename Context >
void CFsm< Context >::SetNextState ( unsigned int  nextState)
inline

◆ Update()

template<typename Context >
bool CFsm< Context >::Update ( unsigned int  eventType,
void *  pEventData 
)
inline

Updates the FSM and retrieves next state.

Returns
whether the state was changed.

Member Data Documentation

◆ m_CurrState

template<typename Context >
unsigned int CFsm< Context >::m_CurrState {FSM_INVALID_STATE}
private

◆ m_Done

template<typename Context >
bool CFsm< Context >::m_Done {false}
private

◆ m_FirstState

template<typename Context >
unsigned int CFsm< Context >::m_FirstState {FSM_INVALID_STATE}
private

◆ m_NextState

template<typename Context >
unsigned int CFsm< Context >::m_NextState {FSM_INVALID_STATE}
private

◆ m_Transitions

template<typename Context >
TransitionMap CFsm< Context >::m_Transitions
private

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