home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / SpriteWorld 2.2 / SpriteWorld files / Utils / SWFPSReport.c < prev    next >
Encoding:
Text File  |  1998-06-08  |  1.9 KB  |  64 lines  |  [TEXT/CWIE]

  1. ///--------------------------------------------------------------------------------------
  2. //    SWFPSReport.c
  3. //
  4. //    Requires ALRT and DITL resource ID 200 to be copied from SpriteTest and put in 
  5. //    your project. Remember to include the SWFPSReport.h file as well. It will 
  6. //    call SysBeep if for some reason it can't display the alert.
  7. //
  8. //    Make sure to set the Sprite's move time and the MaxFPS rate to 0; otherwise 
  9. //    the fps report will be innaccurate. (It still isn't terribly accurate, but should
  10. //    give you a pretty good idea of how fast the animation is going.)
  11. ///--------------------------------------------------------------------------------------
  12.  
  13.  
  14. #include "SWFPSReport.h"
  15.  
  16. #define    kNoteAlertID    200
  17.  
  18.  
  19. long            gOldTicks;
  20.  
  21.  
  22. ///--------------------------------------------------------------------------------------
  23. //    Call StartTimer right before you start the animation
  24. ///--------------------------------------------------------------------------------------
  25.  
  26. void    StartTimer( void )
  27. {
  28.         // Wait for ticks to roll over before starting
  29.     gOldTicks = TickCount();
  30.     while (gOldTicks == TickCount())
  31.         NULL;
  32.  
  33.     gOldTicks = TickCount();
  34. }
  35.  
  36.  
  37. ///--------------------------------------------------------------------------------------
  38. //    Call ShowResults as soon as your animation is done and pass to it the number of
  39. //    frames that have occured in the animation.
  40. ///--------------------------------------------------------------------------------------
  41.  
  42. void    ShowResults( long frames )
  43. {
  44.     Str255         framesString, secondsString, fpsString;
  45.     long         fps;
  46.     double        seconds;
  47.     
  48.     seconds = ((TickCount() - gOldTicks - 1) / 60.5);
  49.     fps = (double)frames / seconds;
  50.  
  51.     NumToString(frames, framesString);
  52.     NumToString(seconds, secondsString);
  53.     NumToString(fps, fpsString);
  54.  
  55.     ParamText(framesString, secondsString, fpsString, "\p");
  56.     
  57.     SetCursor(&qd.arrow);
  58.     ShowCursor();
  59.     
  60.     if (NoteAlert(kNoteAlertID, NULL) == -1)
  61.         SysBeep(10);
  62. }
  63.  
  64.