switch(dwGameState)
{
case GAME_STATE_INIT:
{
// blah
}
case GAME_STATE_RUN:
{
// blah
}
case GAME_STATE_EXIT:
{
// blah
}
}
Handling game loops
Most of the authors of the books I read code their game loops like so:
OK, this works... But it's not optimal. Is there a more efficient method to do it?
Thanks.
Quote:Original post by DirectXFreak
Most of the authors of the books I read code their game loops like so:
*** Source Snippet Removed ***
OK, this works... But it's not optimal. Is there a more efficient method to do it?
Thanks.
maybe you want to go with a kernel and task approach as shown in the Enginuity articles, it will be much more flexible.
HTH
If you just want a simpler structure without getting as complicated as a kernel system, you can do this:
This eliminates a conditional for each iteration of the game loop - a minimal performance gain, but if you do such "hoisting" tricks as much as possible, you can get much better execution efficiency.
void IntroLoop(){ while(IntroRunning) DoIntroStuff();}void GameLoop(){ while(GameRunning) DoGameStuff();}void ExitLoop(){ while(ExitRunning) DoExitStuff();}void MainFunction(){ InitStuff(); IntroLoop(); GameLoop(); ExitLoop(); CleanUpStuff();}
This eliminates a conditional for each iteration of the game loop - a minimal performance gain, but if you do such "hoisting" tricks as much as possible, you can get much better execution efficiency.
Here is how I do it. works well enough for me
psudocode:
while not Endgame
select State
case MAIN_GUI
Setup_main_Gui()
Main_Gui_Loop() //loops forever until the 'State' val changes
End_Main_Gui()
case MAIN_GAME
Setup_Main_Game()
Main_Game_Loop() // loops until the state changes
End_Main_Game()
wend
psudocode:
while not Endgame
select State
case MAIN_GUI
Setup_main_Gui()
Main_Gui_Loop() //loops forever until the 'State' val changes
End_Main_Gui()
case MAIN_GAME
Setup_Main_Game()
Main_Game_Loop() // loops until the state changes
End_Main_Game()
wend
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement