BsTime.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "Utility/BsTime.h"
  4. #include "Utility/BsTimer.h"
  5. namespace bs
  6. {
  7. const double Time::MICROSEC_TO_SEC = 1.0/1000000.0;
  8. Time::Time()
  9. :mFrameDelta(0.0f), mTimeSinceStart(0.0f), mTimeSinceStartMs(0), mAppStartTime(0), mLastFrameTime(0),
  10. mCurrentFrame(0UL)
  11. {
  12. mTimer = bs_new<Timer>();
  13. mAppStartTime = mTimer->getStartMs();
  14. mLastFrameTime = mTimer->getMicroseconds();
  15. }
  16. Time::~Time()
  17. {
  18. bs_delete(mTimer);
  19. }
  20. void Time::_update()
  21. {
  22. UINT64 currentFrameTime = mTimer->getMicroseconds();
  23. mFrameDelta = (float)((currentFrameTime - mLastFrameTime) * MICROSEC_TO_SEC);
  24. mTimeSinceStartMs = (UINT64)(currentFrameTime / 1000);
  25. mTimeSinceStart = mTimeSinceStartMs / 1000.0f;
  26. mLastFrameTime = currentFrameTime;
  27. mCurrentFrame.fetch_add(1, std::memory_order_relaxed);
  28. }
  29. UINT64 Time::getTimePrecise() const
  30. {
  31. return mTimer->getMicroseconds();
  32. }
  33. Time& gTime()
  34. {
  35. return Time::instance();
  36. }
  37. }