Clock.h 457 B

1234567891011121314151617181920212223242526
  1. #ifndef CLOCK_H
  2. #define CLOCK_H
  3. #include "common/utils/Types.h"
  4. #include "common/utils/Array.h"
  5. class Clock final {
  6. public:
  7. Clock();
  8. u64 update();
  9. u64 getLength() const;
  10. float getUpdatesPerSecond() const;
  11. void wait(u64 nanos) const;
  12. private:
  13. u64 getNanos() const;
  14. static constexpr u64 bits = 7;
  15. static constexpr u64 length = 1 << bits;
  16. u64 last;
  17. u64 index;
  18. s64 sum;
  19. Array<u64, length> time;
  20. };
  21. #endif