Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

Input System

Started by DeafTV Feb 22, 2013 at 11:52 PM 1 replies 1.4k views
Original Post
DeafTV
DeafTV

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 smile.png

Fly Safe 7o
DeafTV
DeafTV

Thanks! That looks like a good way to handle things and I'll look into implementing a system like that soon.

Fly Safe 7o

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.