I'm currently working on project using sdl which uses a gamestate system.
Here's some psuedo code of how it works right now:
GameEngine::Update(){
//SDL event loop ...
case SDLK_m:
changeState(STATE_MENU); //Changes the state which updates in manageState()
}
GameEngine::manageState(){
//Makes sure we can delete the state, if so - delete it
...
delete currentState;
switch(state){
case STATE_MENU:
currentState = new Menu();
}
...
}
GameEngine::Render(){
currentState->Render();
}
What I am looking to do is for each state, which is represented by a class that inherits from the abstract base class of GameState, is for it to have its own event loop. I was going to do it this way because the menu could have a totally different use for a key than the game itself.
The problem I'm running into is that I can't make a call to change the state from within that event loop. I need to be able to change the state and destroy the object in GameEngine and create it again so the GameEngine render and update functions can call the currentState->Render and update functions.
There may be a simple solution for this but its been driving me nuts lately. It is kind of difficult to explain so if you need further clarification I would be happy to do so. Thanks for the help