Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <SFML\Graphics.hpp>
- #include "BaseState.h"
- #include "SharedContext.h"
- using StateContainer = std::vector<std::pair<StateType, BaseState*>>;
- using TypeContainer = std::vector<StateType>;
- using StateFactory = std::unordered_map<StateType, std::function<BaseState*(void)>>;
- class StateManager
- {
- public:
- StateManager(SharedContext* context);
- ~StateManager();
- void Update(const sf::Time& time);
- void Draw();
- void ProcessRequests();
- SharedContext* GetContext();
- bool HasState(const StateType& type);
- void SwitchTo(const StateType& type);
- void Remove(const StateType type);
- private:
- void CreateState(const StateType& type);
- void RemoveState(const StateType& type);
- template<class T>
- void RegisterState(const StateType& type)
- {
- m_stateFactory[type] = [this]() -> BaseState*
- {
- return new T(this);
- }
- };
- SharedContext* m_context;
- StateContainer m_states;
- TypeContainer m_toRemove;
- StateFactory m_stateFactory;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement