Clock.cpp 568 B

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