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.cpp
Go to the documentation of this file.
1
7
8#include "galaxy/error/Log.hpp"
9
10#include "StateMachine.hpp"
11
12namespace galaxy
13{
14 namespace state
15 {
19
21 {
22 while (!m_stack.empty())
23 {
24 m_stack.pop();
25 }
26
27 m_states.clear();
28 }
29
30 void StateMachine::push(const std::string& key)
31 {
32 if (m_states.contains(key))
33 {
34 auto ptr = m_states[key].get();
35 ptr->on_push();
36
37 m_stack.push(ptr);
38 }
39 else
40 {
41 GALAXY_LOG(GALAXY_WARNING, "Tried to push a state that doesnt exist.");
42 }
43 }
44
46 {
47 if (m_stack.top() != nullptr)
48 {
49 m_stack.top()->on_pop();
50 }
51
52 m_stack.pop();
53 }
54
56 {
57 if (m_stack.top() != nullptr)
58 {
59 m_stack.top()->update();
60 }
61 }
62 } // namespace state
63} // namespace galaxy
#define GALAXY_WARNING
Definition Log.hpp:24
#define GALAXY_LOG(level, msg,...)
Definition Log.hpp:29
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.
ankerl::unordered_dense::map< std::string, std::unique_ptr< State > > m_states
State cache.
Timer.hpp galaxy.
Definition Async.hpp:17