Clock.h 658 B

12345678910111213141516171819202122232425262728293031
  1. #ifndef CORE_CLOCK_H
  2. #define CORE_CLOCK_H
  3. #include "data/Array.h"
  4. #include "utils/Check.h"
  5. namespace Core {
  6. struct Clock final {
  7. using Nanos = i64;
  8. private:
  9. static constexpr int BITS = 7;
  10. static constexpr int LENGTH = 1 << BITS;
  11. int index;
  12. Nanos last;
  13. Nanos sum;
  14. Array<Nanos, LENGTH> time;
  15. public:
  16. Clock();
  17. // the first invocation will always return 0 nanos
  18. check_return Error update(Nanos& n);
  19. float getUpdatesPerSecond() const;
  20. check_return Error wait(Nanos nanos) const;
  21. check_return static Error getNanos(Nanos& n);
  22. };
  23. }
  24. #endif