I am trying to implement a game state system in my engine. I have read around a bit and think I am able to tackle a stack of gamestates. In order to prototype I am aiming to have first a splash screen, then a main menu, and then the "playing" state.
I am wondering the best way to transition from one state to another?
Right now, I have a GameState class,
class GameState
{
public:
GameState();
~GameState();
virtual void update(const float deltaTime) = 0;
};
and my Game class (of which my actual game inherits from), with a vector of states
std::vector<std::shared_ptr<GameState>> m_states;
So right now, I can add the first state (the SplashScreenState, Inherited from GameState) using
game.pushState(std::make_shared<SplashScreenState>());
and in my game update loop I call
for (std::vector<std::shared_ptr<GameState>>::reverse_iterator i = m_states.rbegin(); i != m_states.rend(); ++i)
{
(*i)->update(frameTime);
}
to update each State. So right now my SplashScreenState is getting updated, and a timer transitions it. Once the timer runs out I want the MainMenuState to activate.
The question is, given my current design, how do I best go about this?
Should I have something inside SplashScreenState::update() that lets me push on the next state directly?
Should My GameState class handle all transitions internally?
Where do I go about actually explicitly stating which state I want to go from where and to (Splash Screen to Main Menu, Main Menu to Playing, Playing to Paused...).
Thanks for any insight.