Skip to main content
GameDev.net gamedev.net
🔒 Locked

Game Loop?

Started by Pexi Mar 16, 2003 at 8:41 AM 2 replies 750+ views
Original Post
Pexi
Pexi
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
thehurricane
thehurricane
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.
FearedPixel
FearedPixel
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.