Game Loop?

Started by
2 comments, last by Pexi 21 years, 1 month ago
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/
Pekka Heikurapekka.heikura@mbnet.fi
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 ]
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.
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.

This topic is closed to new replies.

Advertisement