• Advertisement

Archived

This topic is now archived and is closed to further replies.

Game Loop?

This topic is 5424 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Could someone give me an example of games main loop... where the logig is updated and thing drawn. How do join it with state based game logic.
GameMain()
{
  switch (GameState)
  GS_MENU: MenuLoop;
  GS_MAIN: GameLoop;
  GS_IDLE: IdleLoop;
}

MenuLoop()
{
  UpdateMenu;
  DrawMenu;
}

GameLoop()
{
  UpdateGameLogic();
  DrawStuff();
}

IdleLoop()
{
  PlayDemo();
}
 
this is how currently have thought doing it. How you do it? Pekka H http://koti.mbnet.fi/pekkath/

Share this post


Link to post
Share on other sites
Advertisement
Looks fine to me. I''ve used that in a few places. Sometimes a more complex design might have a stack of states, where you execute the one at the top of the stack and pop it off the stack when you''re done.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]

Share this post


Link to post
Share on other sites
You can also create an abstract GameState base class and then derive states like PlayState and EditState from it and override the Draw and Process functions, so in effect each frame involves a virtual function call.

Share this post


Link to post
Share on other sites
Looks fine, just make sure that the MenuLoop, GameLoop etc have their own while loop inside, rather than a while loop in GameMain. Although im sure that is how you done it.

Share this post


Link to post
Share on other sites

  • Advertisement