Clock.cpp 562 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include "client/engine/Clock.h"
  2. Clock::Clock()
  3. {
  4. for(int i = 0; i < SIZE; i++)
  5. {
  6. time[i] = 0;
  7. }
  8. }
  9. Clock::Clock(const Clock& orig)
  10. {
  11. }
  12. Clock::~Clock()
  13. {
  14. }
  15. void Clock::update()
  16. {
  17. uint64_t t = glfwGetTimerValue();
  18. time[index] = t - oldTime;
  19. oldTime = t;
  20. sum += time[index];
  21. index = (index + 1) & (SIZE - 1);
  22. sum -= time[index];
  23. }
  24. double Clock::getUpdatesPerSecond() const
  25. {
  26. return (1000000000.0 * (SIZE - 1)) / sum;
  27. }
  28. uint64_t Clock::getCurrentTime() const
  29. {
  30. return time[(index - 1) & (SIZE - 1)];
  31. }