Clock.hpp 693 B

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