Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.5 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: timer.hxx
  3. *
  4. * Copyright (c) 1996 Microsoft Corporation
  5. *
  6. \**************************************************************************/
  7. #ifndef __timer_hxx__
  8. #define __timer_hxx__
  9. #include <time.h>
  10. #define MillisToSeconds( dwMillis ) \
  11. ( (float) (dwMillis) / 1000.0f )
  12. #define SecondsToMillis( fSeconds ) \
  13. ( (DWORD) ((fSeconds) * 1000.0f) )
  14. // The basic timer is like a stopwatch
  15. class TIMER {
  16. public:
  17. TIMER();
  18. void Start();
  19. float Stop();
  20. void Reset();
  21. float Elapsed();
  22. protected:
  23. DWORD dwStartMillis;
  24. DWORD dwElapsedMillis;
  25. DWORD dwTotalMillis;
  26. BOOL bRunning;
  27. };
  28. class UPDATE_TIMER : public TIMER {
  29. public:
  30. UPDATE_TIMER( float fUpdateInterval );
  31. BOOL Update( int numItems, float *fRate );
  32. void Reset();
  33. protected:
  34. int nItems;
  35. int nTotalItems; // total # items drawn
  36. float fUpdateRate; // items per second
  37. DWORD updateInterval; // interval between timer updates in ms
  38. };
  39. #define MAX_RESULTS 10
  40. class AVG_UPDATE_TIMER : public UPDATE_TIMER {
  41. public:
  42. AVG_UPDATE_TIMER( float fUpdateInterval, int numResults );
  43. BOOL Update( int numItems, float *fRate );
  44. void Reset();
  45. private:
  46. float fResults[MAX_RESULTS];
  47. int nResults; // current # of results
  48. int nMaxResults; // max # of results for averaging
  49. int iOldestResult; // index of oldest result
  50. float fSummedResults; // current sum of results
  51. };
  52. #endif // __timer_hxx__