Clock.h 459 B

12345678910111213141516171819202122232425262728
  1. #ifndef CLOCK_H
  2. #define CLOCK_H
  3. #include "data/Array.h"
  4. #include "utils/Types.h"
  5. struct Clock final {
  6. typedef int64 Nanos;
  7. private:
  8. static constexpr int BITS = 7;
  9. static constexpr int LENGTH = 1 << BITS;
  10. int index;
  11. Nanos last;
  12. Nanos sum;
  13. Array<Nanos, LENGTH> time;
  14. public:
  15. Clock();
  16. Nanos update();
  17. float getUpdatesPerSecond() const;
  18. void wait(Nanos nanos) const;
  19. private:
  20. Nanos getNanos() const;
  21. };
  22. #endif