Jump to content


SDL C++ drawing problem


7 replies to this topic

#1 gardon

    Valued Member

  • Members
  • PipPipPip
  • 282 posts

Posted 16 March 2006 - 11:26 PM

I'm having a problem drawing to the screen based on gameStates. I'm not a noob, and this is a serious problem that I can't spend any more time slaving over.

The program runs like this:

while (menu->IsRunning()) // which returns true until the prog exits
{
Poll for input;

switch (g_globalState) // initially set to MENU above
{
case Menu:
g_globalState = Menu->Run() // which returns the global state
// after updating Menu
case GAMELOOP;
g_globalState = Engine->Run() // which does the same thing
}
}


-- end sample


So each frame it updates itself and checks for the globalState, which in turns either goes through Menu or Engine->Run(). once I Set the globalSTate to GAMELOOP through Menu options (I.e I click on the new game button) it goes to engine.

The problem I'm having is trying to get back to menu. I set the escape key to revert me back (setting globalSTate to MENU), which should run the MENU function and update it, however, it brings it back to menu but consistently draws and updates GAMELOOP as well.

It's like the switch statement doesn't matter, and it's still updating engine, which causes a double overlap of time and animation..,

I'm using double buffering, but that shouldn't make a difference.

Thanks,

Jason


And if you guys have visual studio and wanna check it out, go here: <a href="http://massive-war.com/Demo.rar">Here</a>

#2 .oisyn

    DevMaster Staff

  • Moderators
  • 1822 posts

Posted 17 March 2006 - 12:41 AM

You forgot the break statement at the end of the MENU case. Read the C++ documentation about how to use the switch statement.
C++ addict
-
Currently working on: the 3D engine for Tomb Raider.

#3 gardon

    Valued Member

  • Members
  • PipPipPip
  • 282 posts

Posted 17 March 2006 - 03:44 AM

which MENU case? in maiN? there's a break statement there

#4 gardon

    Valued Member

  • Members
  • PipPipPip
  • 282 posts

Posted 17 March 2006 - 03:47 AM

and that documentation looks fine to me:

switch(variable)
{
case whatever: break;
case whatever2: break;
case whatever4: break;
default: break;
}

#5 Reedbeta

    DevMaster Staff

  • Administrators
  • 4979 posts
  • LocationBellevue, WA

Posted 17 March 2006 - 07:41 AM

Well, the code in your original post doesn't have the break statement.
reedbeta.com - developer blog, OpenGL demos, and other projects

#6 gardon

    Valued Member

  • Members
  • PipPipPip
  • 282 posts

Posted 17 March 2006 - 08:21 PM

But it's fixed now, and the problem still arises.

Ugh

#7 Reedbeta

    DevMaster Staff

  • Administrators
  • 4979 posts
  • LocationBellevue, WA

Posted 17 March 2006 - 10:40 PM

Have you tried stepping through with a debugger to see exactly what happens when the game is in the menu state?
reedbeta.com - developer blog, OpenGL demos, and other projects

#8 gardon

    Valued Member

  • Members
  • PipPipPip
  • 282 posts

Posted 18 March 2006 - 12:44 AM

Yes, and I still can't figure it out.

God, I don't know what the problem is, but Im' sure I"ll figure it out sooner or later

Jason Otto





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users