Archived

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

Pexi

Game Loop?

Recommended Posts

Pexi    122
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
Kylotan    10008
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
thehurricane    122
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
FearedPixel    124
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