Clock.hpp 620 B

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