Clock.h 841 B

12345678910111213141516171819202122232425262728293031323334
  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. // returns true on error and calls the error callback
  18. // the first invocation will always return 0 nanos
  19. check_return bool update(Nanos& n);
  20. float getUpdatesPerSecond() const;
  21. // returns true on error and calls the error callback
  22. check_return bool wait(Nanos nanos) const;
  23. // returns true on error and calls the error callback
  24. check_return static bool getNanos(Nanos& n);
  25. };
  26. }
  27. #endif