Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Ndk::StateMachine Class Reference

NDK class that represents a state machine, to represent the multiple states of your program as a stack. More...

Public Member Functions

 StateMachine (std::shared_ptr< State > originalState)
 Constructs a StateMachine object with an original state. More...
 
 StateMachine (const StateMachine &)=delete
 
 StateMachine (StateMachine &&fsm)=default
 
 ~StateMachine ()
 Destructs the object. More...
 
void ChangeState (std::shared_ptr< State > state)
 Replaces the current state on the top of the machine. More...
 
const std::shared_ptr< State > & GetCurrentState () const
 Gets the current state on the top of the machine. More...
 
bool IsTopState (const State *state) const
 Checks whether the state is on the top of the machine. More...
 
std::shared_ptr< StatePopState ()
 Pops the state on the top of the machine. More...
 
bool PopStatesUntil (std::shared_ptr< State > state)
 Pops all the states of the machine until a specific one is reached. More...
 
void PushState (std::shared_ptr< State > state)
 Pushes a new state on the top of the machine. More...
 
void SetState (std::shared_ptr< State > state)
 Pops every states of the machine to put a new one. More...
 
bool Update (float elapsedTime)
 Updates all the states. More...
 
StateMachineoperator= (StateMachine &&fsm)=default
 
StateMachineoperator= (const StateMachine &)=delete
 

Detailed Description

NDK class that represents a state machine, to represent the multiple states of your program as a stack.

Constructor & Destructor Documentation

◆ StateMachine()

Ndk::StateMachine::StateMachine ( std::shared_ptr< State originalState)
inline

Constructs a StateMachine object with an original state.

Parameters
originalStateState which is the entry point of the application
Remarks
Calls "Enter" on the state
Produces a NazaraAssert if nullptr is given

◆ ~StateMachine()

Ndk::StateMachine::~StateMachine ( )
inline

Destructs the object.

Remarks
Calls "Leave" on all the states

Member Function Documentation

◆ ChangeState()

void Ndk::StateMachine::ChangeState ( std::shared_ptr< State state)
inline

Replaces the current state on the top of the machine.

Parameters
stateState to replace the top one if it is nullptr, no action is performed

◆ GetCurrentState()

const std::shared_ptr< State > & Ndk::StateMachine::GetCurrentState ( ) const
inline

Gets the current state on the top of the machine.

Returns
A constant reference to the state
Remarks
The stack is supposed to be non empty, otherwise it is undefined behaviour
See also
PopStatesUntil

◆ IsTopState()

bool Ndk::StateMachine::IsTopState ( const State state) const
inline

Checks whether the state is on the top of the machine.

Returns
true If it is the case
Parameters
stateState to compare the top with

◆ PopState()

std::shared_ptr< State > Ndk::StateMachine::PopState ( )
inline

Pops the state on the top of the machine.

Returns
Old state on the top, nullptr if stack was empty
Remarks
This method can completely empty the stack

◆ PopStatesUntil()

bool Ndk::StateMachine::PopStatesUntil ( std::shared_ptr< State state)
inline

Pops all the states of the machine until a specific one is reached.

Returns
true If that specific state is on top, false if stack is empty
Parameters
stateState to find on the stack if it is nullptr, no action is performed
Remarks
This method can completely empty the stack

◆ PushState()

void Ndk::StateMachine::PushState ( std::shared_ptr< State state)
inline

Pushes a new state on the top of the machine.

Parameters
stateNext state to represent if it is nullptr, it performs no action
Remarks
Produces a NazaraAssert if the same state is pushed two times on the stack

◆ SetState()

void Ndk::StateMachine::SetState ( std::shared_ptr< State state)
inline

Pops every states of the machine to put a new one.

Parameters
stateState to reset the stack with if it is nullptr, no action is performed

◆ Update()

bool Ndk::StateMachine::Update ( float  elapsedTime)
inline

Updates all the states.

Returns
true If update is successful for everyone of them
Parameters
elapsedTimeDelta time used for the update

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