>This is what I have from that thread:
>>OK, I'll talk about menus too, since it's another misunderstood area.
Well, that's another good thread about menus.  But it doesn't mention
updating the screen only when your window isn't obscured.  Here's the code
from Reptoids.c.  There's lot's of other goodies in there too.


-Roger Flores


          // Wait until the next game period.
          EvtGetEvent (&event, TimeUntillNextPeriod());

          // Detect exiting the game's window.  This must be checked for.
At this
          // point there probably exists another window which may cover
part of
          // the MainView window.  Suppress drawing.  Otherwise drawing may
 draw
          // to part of the window covered by the new window.
          if (event.eType == winExitEvent)
               {
               if (event.data.winExit.exitWindow == (WinHandle)
FrmGetFormPtr(MainView))
                    {
                    GameStatus.paused = true;
                    GameStatus.pausedTime = TimGetTicks();
                    }
               }

          // Detect entering the game's window.  Resume drawing to our
window.
          else if (event.eType == winEnterEvent)
               {
               // In the current code, the menu doesn't remove itself when
it receives
               // a winExitEvent.
               if (event.data.winEnter.enterWindow == (WinHandle)
FrmGetFormPtr(MainView) &&
                    event.data.winEnter.enterWindow == (WinHandle)
FrmGetFirstForm ())
                    {
                    // Sometimes we can enter the game's window without
knowing it was
                    // ever left.  In that case the pause time will not
have been recorded.
                    // Set the current period back to it's beginning
                    if (!GameStatus.paused)
                         {
                         GameStatus.nextPeriodTime = TimGetTicks() +
advanceTimeInterval;
                         }
                    else
                         {
                         // Unpause the game.  Account for time lost during
 pause
                         GameStatus.paused = false;
                         GameStatus.nextPeriodTime += (TimGetTicks() -
GameStatus.pausedTime);

                         // Fixup the time spent playing the game by
changing the startTime.
                         GameStatus.startTime += (TimGetTicks() -
GameStatus.pausedTime);
                         }


                    // Redraw the game window.  This is normally triggered
when the launcher
                    // is activate during a low heap memory condition to
work around a launcher
                    // bug which causes it to fail to send a frmUpdateEvent
 when it doesn't
                    // restore the bits underneath it.
                    if (redrawWhenReturningToGameWindow)
                         {
                         GameStateDrawEverything();
                         redrawWhenReturningToGameWindow = false;
                         }
                    }
               }


          // If it's time, go to the next time period
          else if (event.eType == nilEvent && TimeUntillNextPeriod() == 0)
               {
               GameStateDraw();                    // Draw the state
renedered in the screen buffer




Reply via email to