4#include "../../../Opengl-Core/include/Core.hpp"
31 std::cout <<
"Attaching state: " << this->
m_name <<
" to StateManager\n";
43 std::cout <<
"Detaching state: " << this->
m_name <<
" from StateManager\n";
85 State(
const std::string &name =
"State") :
87 virtual ~State() =
default;
107 StateManager(StateManager &other) =
delete;
109 void operator=(
const StateManager &other) =
delete;
118 if (s_pointer ==
nullptr) {
119 Shared<StateManager> copy(
new StateManager());
120 copy.swap(s_pointer);
131 ASSERT(this->m_currentState !=
nullptr);
132 return this->m_currentState->isCurrentStateEnd();
170 void changeState(
const std::string &name,
const Shared<State> &state);
204 void cacheState(
const std::string &name,
const Shared<State> &state);
225 inline std::map<std::string, Shared<State>>
getCachedStates() {
return this->m_cacheStates; }
231 inline static Shared<StateManager> s_pointer =
nullptr;
234 Shared<State> m_currentState =
nullptr;
236 Shared<State> m_queueState =
nullptr;
238 std::map<std::string, Shared<State>> m_cacheStates{};
241 bool m_stateChanged =
false;
243 StateManager() =
default;
This class manages the current State running in the application and also provides a simple cache syst...
Definition State.hpp:105
std::map< std::string, Shared< State > > getCachedStates()
Retrieves the current cache of the StateManager.
Definition State.hpp:225
void changeState(const Shared< State > &state)
This method queue the given State and tells the StateManager that the current state needs to be chang...
Definition State.hpp:182
void clean()
Cleans all the current state cache system.
Definition State.cpp:5
bool isCurrentStateDefined() const
Retrieves if the current state is defined or not.
Definition State.hpp:196
void cacheState(const std::string &name, const Shared< State > &state)
This method caches the State given with the given name.
Definition State.cpp:67
static Shared< StateManager > instance()
Retrieves the instance of the StateManager if it's not created. This function is thread safe using a ...
Definition State.hpp:117
void uncacheState(const std::string &name)
Removes the State with the given name if contained in the cache.
Definition State.cpp:75
bool shouldExit() const
Retrieves true if the current state should exit.
Definition State.hpp:130
void execRender()
Execute State::onRender() method of the current state.
Definition State.hpp:143
void changeState(const std::string &name, const Shared< State > &state)
Works as the other StateManager::changeState(const Shared<State>&) but this will use the given name w...
Definition State.cpp:55
void cacheState(const Shared< State > &state)
Caches the given State, his name will be used in the cached states.
Definition State.hpp:211
void execUpdate()
Execute State::onUpdate() method of the current state.
Definition State.hpp:138
void sync()
This method works like a barrier: after calling StateManager::changeState(), detach the current state...
Definition State.cpp:27
This class allow to create a state to be attached to the StateManager. A State works like a scene: de...
Definition State.hpp:21
State(const std::string &name="State")
Instances a state with the given name.
Definition State.hpp:85
bool m_attached
true if the state is attached
Definition State.hpp:93
virtual void onDetach()
This method is called while using sync() (read sync() documentation for more info)....
Definition State.hpp:42
virtual void onRender()
This methods contains all the operations executed at every event::loop::LOOP_RENDER if there are any.
Definition State.hpp:57
virtual bool isCurrentStateEnd()
Retrieves the current binary state of the current State
Definition State.hpp:64
std::string getName() const
Retrieves the State name.
Definition State.hpp:70
bool isAttached() const
Retrieves if the state is attached.
Definition State.hpp:76
virtual void onAttach()
This method is called after using StateManager::sync() (read StateMnaager::sync() documentation for m...
Definition State.hpp:30
const std::string m_name
state's name
Definition State.hpp:91
virtual void onUpdate()
This methods contains all the operations executed at every event::loop::LOOP_UPDATE if there are any.
Definition State.hpp:51