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