Clock.h 488 B

12345678910111213141516171819202122232425262728
  1. #ifndef CLOCK_H
  2. #define CLOCK_H
  3. #include "gaming-core/utils/Types.h"
  4. #include "gaming-core/utils/Array.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. Nanos last;
  11. int index;
  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