Clock.cpp 530 B

1234567891011121314151617181920212223
  1. #include "utils/Clock.h"
  2. #include "rendering/wrapper/GLFWWrapper.h"
  3. Clock::Clock() : last(GLFWWrapper::getTimeNanos()), index(0), sum(0), time(0) {
  4. }
  5. u64 Clock::update() {
  6. index = (index + 1) & (length - 1);
  7. u64 current = GLFWWrapper::getTimeNanos();
  8. sum -= time[index];
  9. time[index] = current - last;
  10. sum += time[index];
  11. last = current;
  12. return time[index];
  13. }
  14. u64 Clock::getLength() const {
  15. return length;
  16. }
  17. float Clock::getUpdatesPerSecond() const {
  18. return length * (1000000000.0f / sum);
  19. }