galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
galaxy::state::StateMachine Class Referencefinal

A finite state machine. More...

#include <StateMachine.hpp>

+ Collaboration diagram for galaxy::state::StateMachine:

Public Member Functions

 StateMachine ()
 Constructor.
 
 ~StateMachine ()
 Destructor.
 
template<std::derived_from< State > Type, typename... Args>
void add (const std::string &key, Args &&... args)
 Add a new state.
 
void push (const std::string &key)
 Push a new state onto the stack.
 
void pop ()
 Pop the topmost state off the top of the stack.
 
void update ()
 Update topmost state.
 

Private Types

using Stack = meta::stack<State*, meta::vector<State*>>
 Ensure stack is using a vector over slower data structures.
 

Private Attributes

Stack m_stack
 State stack.
 
ankerl::unordered_dense::map< std::string, std::unique_ptr< State > > m_states
 State cache.
 

Detailed Description

A finite state machine.

https://gameprogrammingpatterns.com/state.html

Definition at line 25 of file StateMachine.hpp.

Member Typedef Documentation

◆ Stack

using galaxy::state::StateMachine::Stack = meta::stack<State*, meta::vector<State*>>
private

Ensure stack is using a vector over slower data structures.

Definition at line 30 of file StateMachine.hpp.

Constructor & Destructor Documentation

◆ StateMachine()

galaxy::state::StateMachine::StateMachine ( )

Constructor.

Definition at line 16 of file StateMachine.cpp.

◆ ~StateMachine()

galaxy::state::StateMachine::~StateMachine ( )

Destructor.

Definition at line 20 of file StateMachine.cpp.

Member Function Documentation

◆ add()

template<std::derived_from< State > Type, typename... Args>
void galaxy::state::StateMachine::add ( const std::string & key,
Args &&... args )
inline

Add a new state.

Template Parameters
TypeChild state type.
ArgsVariable argument types.
Parameters
keyKey to assign to this state.
argsVariable arguments for state constructor.

Definition at line 85 of file StateMachine.hpp.

◆ push()

void galaxy::state::StateMachine::push ( const std::string & key)

Push a new state onto the stack.

Parameters
keyKey of state to push.

Definition at line 30 of file StateMachine.cpp.

+ Here is the caller graph for this function:

◆ pop()

void galaxy::state::StateMachine::pop ( )

Pop the topmost state off the top of the stack.

Definition at line 45 of file StateMachine.cpp.

+ Here is the caller graph for this function:

◆ update()

void galaxy::state::StateMachine::update ( )

Update topmost state.

Definition at line 55 of file StateMachine.cpp.

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_stack

Stack galaxy::state::StateMachine::m_stack
private

State stack.

Definition at line 76 of file StateMachine.hpp.

◆ m_states

ankerl::unordered_dense::map<std::string, std::unique_ptr<State> > galaxy::state::StateMachine::m_states
private

State cache.

Definition at line 81 of file StateMachine.hpp.


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