CmTimerImp.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #pragma once
  2. #include "../BsPrerequisitesUtil.h"
  3. #ifndef WIN32_LEAN_AND_MEAN
  4. # define WIN32_LEAN_AND_MEAN
  5. #endif
  6. #if !defined(NOMINMAX) && defined(_MSC_VER)
  7. # define NOMINMAX // Required to stop windows.h messing up std::min
  8. #endif
  9. #include "windows.h"
  10. namespace BansheeEngine
  11. {
  12. /**
  13. * @brief Timer class used for querying high precision timers.
  14. */
  15. class BS_UTILITY_EXPORT Timer
  16. {
  17. public:
  18. /**
  19. * @brief Construct the timer and start timing.
  20. */
  21. Timer();
  22. ~Timer();
  23. /**
  24. * @brief Reset the timer to zero.
  25. */
  26. void reset();
  27. /**
  28. * @brief Returns time in milliseconds since timer was initialized or
  29. * last reset.
  30. */
  31. unsigned long getMilliseconds();
  32. /**
  33. * @brief Returns time in microseconds since timer was initialized or
  34. * last reset.
  35. */
  36. unsigned long getMicroseconds();
  37. /**
  38. * @brief Returns time in milliseconds since timer was initialized or
  39. * last reset. Only CPU timer measured.
  40. */
  41. unsigned long getMillisecondsCPU();
  42. /**
  43. * @brief Returns time in microseconds since timer was initialized or
  44. * last reset. Only CPU timer measured.
  45. */
  46. unsigned long getMicrosecondsCPU();
  47. /**
  48. * @brief Returns the time at which the timer was initialized, in milliseconds.
  49. *
  50. * @return Time in milliseconds.
  51. */
  52. unsigned long getStartMs() const;
  53. private:
  54. clock_t mZeroClock;
  55. LARGE_INTEGER mStartTime;
  56. LARGE_INTEGER mFrequency;
  57. };
  58. }