12345678910111213141516171819202122 |
- #include "utils/Clock.h"
- Clock::Clock() : index(0), last(GLFW::getNanos()), sum(0), time(0) {
- }
- Nanos Clock::update() {
- index = (index + 1) & (length - 1);
- Nanos current = GLFW::getNanos();
- sum -= time[index];
- time[index] = current - last;
- sum += time[index];
- last = current;
- return time[index];
- }
- Nanos Clock::getLength() const {
- return length;
- }
- float Clock::getUpdatesPerSecond() const {
- return length * (1000000000.0f / sum);
- }
|