Clock.cpp 471 B

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