🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Lesson 21

Started by
0 comments, last by lc_overlord 16 years, 1 month ago
I was looking at the program flow of lesson 21 and was wondering if this was a good alteration.
if ((active && !GameSwitch(currentGameState)) || keys[VK_ESCAPE])	// Active?  Was There A Quit Received?
			{
				done=TRUE;										// ESC or DrawGLScene Signalled A Quit
			}
			else												// Not Time To Quit, Update Screen
			{
				SwapBuffers(hDC);								// Swap Buffers (Double Buffering)
			}

int GameSwitch(currentGameState)
{
     switch(currentGameState)
     {
          case GAMESTATE_MAINMENU:
          {
               UpdateMainMenu();
               RenderMainMenu();
          }break;

          case GAMESTATE_GAME:
          {
               UpdateGame();
               RenderGame();
          }break;

          case GAMESTATE_CREDITS:
          {
               UpdateCredits();
               RenderCredits();
          }break;

          default:break;
     }
return 0;
}


My other idea was to split the function gameswitch into gamerender and gameupdate. (Not 100% sure how I will get user input and use it in gameupdate yet...)
if ((active && !GameRender(currentGameState)) || keys[VK_ESCAPE])	// Active?  Was There A Quit Received?
			{
				done=TRUE;										// ESC or DrawGLScene Signalled A Quit
			}
			else												// Not Time To Quit, Update Screen
			{
				SwapBuffers(hDC);								// Swap Buffers (Double Buffering)
			}

int GameRender(currentGameState)
{
     switch(currentGameState)
     {
          case GAMESTATE_MAINMENU:
          {
               RenderMainMenu();
          }break;

          case GAMESTATE_GAME:
          {
               RenderGame();
          }break;

          case GAMESTATE_CREDITS:
          {
               RenderCredits();
          }break;

          default:break;
     }
return 0;
}

int GameUpdate(currentGameState)
{
     switch(currentGameState)
     {
          case GAMESTATE_MAINMENU:
          {
               RenderMainMenu(/*Keys pressed?*/);
          }break;

          case GAMESTATE_GAME:
          {
               RenderGame();
          }break;

          case GAMESTATE_CREDITS:
          {
               RenderCredits();
          }break;

          default:break;
     }
return 0;
}


Any suggestions? Edit: I was thinking about it and I only need the arrow keys and space and enter for the gameupdate function...
Advertisement
Ok a few things.

1. you really only want one update function, and one that preferably only updates input and time at regular intervals, game updates are done just before rendering using that data, unless of course you want to try your hands at multi threading.

2. menu, game and credits should not be separate from each other as they should all be done by the rendering mechanisms in the game engine.

This topic is closed to new replies.

Advertisement