123456789101112131415161718 |
- #include "client/utils/Clock.h"
- Clock::Clock() : index(0), last(GLFWWrapper::getTimeNanos()), sum(0), time(0) {
- }
- GLFWWrapper::Nanos Clock::update() {
- index = (index + 1) & (LENGTH - 1);
- GLFWWrapper::Nanos current = GLFWWrapper::getTimeNanos();
- sum -= time[index];
- time[index] = current - last;
- sum += time[index];
- last = current;
- return time[index];
- }
- float Clock::getUpdatesPerSecond() const {
- return LENGTH * (1000000000.0f / sum);
- }
|