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
StateMachine.hpp
Go to the documentation of this file.
1
7
8#ifndef GALAXY_STATE_STATEMACHINE_HPP_
9#define GALAXY_STATE_STATEMACHINE_HPP_
10
11#include <ankerl/unordered_dense.h>
12
13#include "galaxy/meta/Memory.hpp"
15
16namespace galaxy
17{
18 namespace state
19 {
25 class StateMachine final
26 {
30 using Stack = meta::stack<State*, meta::vector<State*>>;
31
32 public:
37
42
52 template<std::derived_from<State> Type, typename... Args>
53 void add(const std::string& key, Args&&... args);
54
60 void push(const std::string& key);
61
65 void pop();
66
70 void update();
71
72 private:
77
81 ankerl::unordered_dense::map<std::string, std::unique_ptr<State>> m_states;
82 };
83
84 template<std::derived_from<State> Type, typename... Args>
85 inline void StateMachine::add(const std::string& key, Args&&... args)
86 {
87 m_states[key] = std::make_unique<Type>(std::forward<Args>(args)...);
88 }
89 } // namespace state
90} // namespace galaxy
91
92#endif
A finite state machine.
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.
meta::stack< State *, meta::vector< State * > > Stack
Ensure stack is using a vector over slower data structures.
ankerl::unordered_dense::map< std::string, std::unique_ptr< State > > m_states
State cache.
void add(const std::string &key, Args &&... args)
Add a new state.
Timer.hpp galaxy.
Definition Async.hpp:17