I want to make a game state system that I can push into a static lib and use it for a bunch of different games.
My goals for this state system are
- not to have a switch/enum system
- be able to sleep a state (which is to say it wont unload its resources, aka main menu etc.)
My first game state system had an enum and switch
enum STATES { LOADING, MENU, GAME, GAME_OVER}switch (m_currentState) { // blah blah blah}
This works great but requires that I register each state in the state manager switch
My next attempt was a little more dynamic but equally flawed.
StateManagerInstance().switchState(new GameState())
This meant that only the current state would need to know what the next state was, which is close to what I want. But passing new everywhere worries me (I cant use boost btw), and also it does not check to see if the next state is already active.
What I want to be able to do is somthing along the lines of
StateManagerInstance().swtichState("main-menu");
This requires that the StateManager knows all the states again which is somthing I want to avoid, however I thought that during the game start up I could register all the game states in some sort of loading. then delete it, but this seems like a bit of overkill.
StateManagerInstance().registerState("main-menu", new MainMenu)
I've been mucking about with a map which works well, but still requiers the switch enum.
Would it be ok to load up all the states at the beginning of the game, but have them not load there resources(sounds images etc) and only load them when necessary? That still seems wrong, is it?
Thanks
Phil