home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / DirectPlay / Maze / MazeClient / FrameRate.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-31  |  1.2 KB  |  56 lines

  1. //----------------------------------------------------------------------------
  2. // File: 
  3. //
  4. // Desc: 
  5. //
  6. // Copyright (c) 1999-2001 Microsoft Corp. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #ifndef    _FRAMERATE_H
  9. #define    _FRAMERATE_H
  10.  
  11.  
  12.  
  13.  
  14. //-----------------------------------------------------------------------------
  15. // Name: 
  16. // Desc: 
  17. //-----------------------------------------------------------------------------
  18. class    CFrameRate
  19. {
  20. public:
  21.     CFrameRate() { Reset(); };
  22.  
  23.     void    Reset()
  24.     {
  25.         m_dwCount = m_dwLastFrameCount = 0;
  26.         m_fLastAppTime = DXUtil_Timer( TIMER_GETAPPTIME );
  27.         m_fRate = 0;
  28.     };
  29.  
  30.     void    DoneFrame()
  31.     {
  32.         m_dwCount++;
  33.         FLOAT fCurTime = DXUtil_Timer( TIMER_GETAPPTIME );
  34.         if ( (fCurTime - m_fLastAppTime) >= 1.0f )
  35.         {
  36.             m_fRate = (float(m_dwCount - m_dwLastFrameCount) / (fCurTime - m_fLastAppTime));
  37.             m_fLastAppTime = fCurTime;
  38.             m_dwLastFrameCount = m_dwCount;
  39.         }
  40.     };
  41.  
  42.     float    GetRate() const { return m_fRate; };
  43.     DWORD    GetCount() const { return m_dwCount; };
  44.  
  45. protected:
  46.     DWORD    m_dwCount;
  47.     float    m_fRate;
  48.     FLOAT   m_fLastAppTime;
  49.     DWORD    m_dwLastFrameCount;
  50. };
  51.  
  52.  
  53.  
  54.  
  55. #endif
  56.