Clock.cpp 471 B

123456789101112131415161718
  1. #include "client/utils/Clock.h"
  2. Clock::Clock() : index(0), last(GLFWWrapper::getTimeNanos()), sum(0), time(0) {
  3. }
  4. GLFWWrapper::Nanos Clock::update() {
  5. index = (index + 1) & (LENGTH - 1);
  6. GLFWWrapper::Nanos current = GLFWWrapper::getTimeNanos();
  7. sum -= time[index];
  8. time[index] = current - last;
  9. sum += time[index];
  10. last = current;
  11. return time[index];
  12. }
  13. float Clock::getUpdatesPerSecond() const {
  14. return LENGTH * (1000000000.0f / sum);
  15. }