Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Input System


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 DeafTV   Members   -  Reputation: 1229

Like
0Likes
Like

Posted 22 February 2013 - 05:52 PM

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


Sponsor:

#2 ApochPiQ   Moderators   -  Reputation: 16079

Like
0Likes
Like

Posted 22 February 2013 - 06:06 PM

My standard response :-)

#3 DeafTV   Members   -  Reputation: 1229

Like
0Likes
Like

Posted 22 February 2013 - 07:50 PM

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


Fly Safe 7o





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS