CG-Project2
|
This class manages the current State running in the application and also provides a simple cache system. More...
#include <State.hpp>
Public Member Functions | |
StateManager (StateManager &other)=delete | |
void | operator= (const StateManager &other)=delete |
bool | shouldExit () const |
Retrieves true if the current state should exit. | |
void | execUpdate () |
Execute State::onUpdate() method of the current state. | |
void | execRender () |
Execute State::onRender() method of the current state. | |
void | sync () |
This method works like a barrier: after calling StateManager::changeState(), detach the current state; clear the EventManager, attach the queued State, defines new event listeners. It needs to be called after every StateManager::changeState() or at the end of a loop before calling StateManager::shouldExit(). | |
void | clean () |
Cleans all the current state cache system. | |
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 while caching. | |
void | changeState (const Shared< State > &state) |
This method queue the given State and tells the StateManager that the current state needs to be changed. If the given State is not in the cache system, the StateManager will cache the State with the state's name. To make it work the method StateManager::sync() needs to be called (read StateManager::sync() for further informations). | |
void | changeState (const std::string &name) |
This method search in the cache the State with the given name. If the name is not found in the cache, the current state will not change. | |
bool | isCurrentStateDefined () const |
Retrieves if the current state is defined or not. | |
void | cacheState (const std::string &name, const Shared< State > &state) |
This method caches the State given with the given name. | |
void | cacheState (const Shared< State > &state) |
Caches the given State, his name will be used in the cached states. | |
void | uncacheState (const std::string &name) |
Removes the State with the given name if contained in the cache. | |
std::map< std::string, Shared< State > > | getCachedStates () |
Retrieves the current cache of the StateManager. |
Static Public Member Functions | |
static Shared< StateManager > | instance () |
Retrieves the instance of the StateManager if it's not created. This function is thread safe using a simple std::mutex. |
This class manages the current State running in the application and also provides a simple cache system.
It allow to change state while executing for one iteration or in a loop using a simple barrier system.
It's implemented with singleton so there only be one instance of this class.
|
inline |
Caches the given State, his name will be used in the cached states.
state | state to be cached |
void StateManager::cacheState | ( | const std::string & | name, |
const Shared< State > & | state ) |
|
inline |
This method queue the given State and tells the StateManager that the current state needs to be changed. If the given State is not in the cache system, the StateManager will cache the State with the state's name. To make it work the method StateManager::sync() needs to be called (read StateManager::sync() for further informations).
void StateManager::changeState | ( | const std::string & | name | ) |
This method search in the cache the State with the given name. If the name is not found in the cache, the current state will not change.
name | the state's name |
void StateManager::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 while caching.
|
inline |
Retrieves the current cache of the StateManager.
|
inlinestatic |
Retrieves the instance of the StateManager if it's not created. This function is thread safe using a simple std::mutex.
|
inline |
Retrieves if the current state is defined or not.
|
inline |
Retrieves true if the current state should exit.
void StateManager::sync | ( | ) |
This method works like a barrier: after calling StateManager::changeState(), detach the current state; clear the EventManager, attach the queued State, defines new event listeners. It needs to be called after every StateManager::changeState() or at the end of a loop before calling StateManager::shouldExit().
void StateManager::uncacheState | ( | const std::string & | name | ) |
Removes the State with the given name if contained in the cache.
name | state's name |