CmTime.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #pragma once
  2. #include "CmPrerequisitesUtil.h"
  3. #include "CmModule.h"
  4. namespace CamelotEngine
  5. {
  6. /**
  7. * @brief Manages all time related functionality
  8. */
  9. class CM_UTILITY_EXPORT Time : public Module<Time>
  10. {
  11. public:
  12. Time();
  13. ~Time();
  14. /**
  15. * @brief Gets the time elapsed since application start.
  16. *
  17. * @return The time since application start, in seconds.
  18. */
  19. float getTime() { return mTimeSinceStart; }
  20. /**
  21. * @brief Gets the time elapsed since application start.
  22. *
  23. * @return The time since application start, in miliseconds.
  24. */
  25. UINT64 getTimeMs() { return mTimeSinceStartMs; }
  26. /**
  27. * @brief Gets the time since last frame was executed.
  28. *
  29. * @return Time since last frame was executed, in seconds.
  30. */
  31. float getFrameDelta() { return mFrameDelta; }
  32. /**
  33. * @brief Returns the number of the current frame. First frame is 0.
  34. *
  35. * @return The current frame.
  36. */
  37. unsigned long getCurrentFrameNumber() { return mCurrentFrame; }
  38. /**
  39. * @brief Called when the application is first started. Should only be called by Application.
  40. */
  41. void init();
  42. /**
  43. * @brief Called every frame. Should only be called by Application.
  44. */
  45. void update();
  46. private:
  47. float mFrameDelta; // Frame delta in seconds
  48. float mTimeSinceStart; // Time since start in seconds
  49. UINT64 mTimeSinceStartMs;
  50. unsigned long mAppStartTime; // Time the application started, in microseconds
  51. unsigned long mLastFrameTime; // Time since last runOneFrame call, In microseconds
  52. unsigned long mCurrentFrame;
  53. Timer* mTimer;
  54. static const double MICROSEC_TO_SEC;
  55. };
  56. CM_UTILITY_EXPORT Time& gTime();
  57. }