HighRezTimer.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "anki/util/HighRezTimer.h"
  2. #include "anki/util/Assert.h"
  3. #include <boost/date_time/posix_time/posix_time.hpp>
  4. namespace anki {
  5. //==============================================================================
  6. void HighRezTimer::start()
  7. {
  8. ANKI_ASSERT(startTime == 0);
  9. ANKI_ASSERT(stopTime == 0);
  10. startTime = getCurrentTime();
  11. stopTime = 0.0;
  12. }
  13. //==============================================================================
  14. void HighRezTimer::stop()
  15. {
  16. ANKI_ASSERT(startTime != 0.0);
  17. ANKI_ASSERT(stopTime == 0.0);
  18. stopTime = getCurrentTime();
  19. }
  20. //==============================================================================
  21. HighRezTimer::Scalar HighRezTimer::getElapsedTime() const
  22. {
  23. if(stopTime == 0)
  24. {
  25. return getCurrentTime() - startTime;
  26. }
  27. else
  28. {
  29. return stopTime - startTime;
  30. }
  31. }
  32. //==============================================================================
  33. HighRezTimer::Scalar HighRezTimer::getCurrentTime()
  34. {
  35. /// XXX Remove the boost
  36. using namespace boost::posix_time;
  37. uint64_t ms = ptime(microsec_clock::local_time()).time_of_day().
  38. total_milliseconds();
  39. return Scalar(ms) / 1000.0;
  40. }
  41. } // end namespace