![]() |
galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
|
A finite state machine. More...
#include <StateMachine.hpp>
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. | |
A finite state machine.
https://gameprogrammingpatterns.com/state.html
Definition at line 25 of file StateMachine.hpp.
|
private |
Ensure stack is using a vector over slower data structures.
Definition at line 30 of file StateMachine.hpp.
galaxy::state::StateMachine::StateMachine | ( | ) |
Constructor.
Definition at line 16 of file StateMachine.cpp.
galaxy::state::StateMachine::~StateMachine | ( | ) |
Destructor.
Definition at line 20 of file StateMachine.cpp.
|
inline |
Add a new state.
Type | Child state type. |
Args | Variable argument types. |
key | Key to assign to this state. |
args | Variable arguments for state constructor. |
Definition at line 85 of file StateMachine.hpp.
void galaxy::state::StateMachine::push | ( | const std::string & | key | ) |
Push a new state onto the stack.
key | Key of state to push. |
Definition at line 30 of file StateMachine.cpp.
void galaxy::state::StateMachine::pop | ( | ) |
Pop the topmost state off the top of the stack.
Definition at line 45 of file StateMachine.cpp.
void galaxy::state::StateMachine::update | ( | ) |
Update topmost state.
Definition at line 55 of file StateMachine.cpp.
|
private |
State stack.
Definition at line 76 of file StateMachine.hpp.
|
private |
State cache.
Definition at line 81 of file StateMachine.hpp.