Open 3D Engine AzCore API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AZ::HSM Class Reference

#include <HSM.h>

Classes

struct  Event
 
struct  State
 

Public Types

enum  ReservedEventIds { EnterEventId = -1 , ExitEventId = -2 }
 
typedef unsigned char StateId
 
typedef AZStd::delegate< bool(HSM &sm, const Event &e)> StateHandler
 

Public Member Functions

 HSM (const char *name="HSM no name")
 
const char * GetName () const
 
void Start ()
 Starts the state machine.
 
bool Dispatch (const Event &e)
 Dispatches an event, return true if the event was processed, otherwise false.
 
bool IsDispatching () const
 Return true if the state machine is currently dispatching an event.
 
void Transition (StateId target)
 Transitions the state machine. This function can not be called from Enter / Exit events in the state handler.
 
StateId GetCurrentState () const
 
StateId GetSourceState () const
 
void SetStateHandler (StateId id, const char *name, const StateHandler &handler, StateId superId=InvalidStateId, StateId subId=InvalidStateId)
 
void ClearStateHandler (StateId id)
 Resets the state to invalid mode.
 
const char * GetStateName (StateId id) const
 Event handing.
 
StateId GetSuperState (StateId id) const
 
bool IsValidState (StateId id) const
 
bool IsInState (StateId id) const
 

Static Public Attributes

static const unsigned char MaxNumberOfStates = 254
 
static const unsigned char InvalidStateId = 255
 
static const int InvalidEventId = -4
 

Protected Member Functions

int StepsToCommonRoot (StateId source, StateId target)
 
void OnEnterSubState ()
 

Protected Attributes

const char * m_name
 
StateId m_curState
 
StateId m_nextState
 Pointer to next state. Valid only when a transition is taken.
 
StateId m_sourceState
 Pointer to source state during last transition.
 
StateId m_curSourceState
 Current transition source state. It may not actually complete.
 
StateId m_topState
 
bool m_disallowTransition
 
AZStd::array< State, MaxNumberOfStates > m_states
 

Detailed Description

Hierarchical state machine.

Note
This implementation have the standard restriction for HSM:
  1. You can not call Transition from HSM::EnterEventId and HSM::ExitEventId! These event are provided to execute your construction/destruction. Use custom events for that.
  2. You are not allowed to dispatch an event from within an event dispatch. You should queue events if you want such behavior. This restriction is imposed only to prevent the user from creating extremely complicated to trace state machines (which is what we are trying to avoid).

Member Function Documentation

◆ SetStateHandler()

void AZ::HSM::SetStateHandler ( StateId  id,
const char *  name,
const StateHandler handler,
StateId  superId = InvalidStateId,
StateId  subId = InvalidStateId 
)

Set a handler for a state ID. This function will overwrite the current state handler.

Parameters
idstate id from 0 to MaxNumberOfStates
namestate debug name.
handlerdelegate to the state function.
superIdid of the super state, if InvalidStateId this is a top state. Only one state can be a top state.
subIdif != InvalidStateId this sub state (child state) will be entered after the state Enter event is executed.

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