Advertisement

Lesson 21

Started by May 22, 2008 08:26 PM
0 comments, last by lc_overlord 16 years, 6 months 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...
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