1234567891011121314151617181920212223242526272829303132 |
- #ifndef CORE_CLOCK_HPP
- #define CORE_CLOCK_HPP
- #include "data/Array.hpp"
- #include "utils/Check.hpp"
- #include "utils/Types.hpp"
- namespace Core {
- struct Clock final {
- using Nanos = i64;
- private:
- static constexpr int BITS = 7;
- static constexpr int LENGTH = 1 << BITS;
- int index;
- Nanos last;
- Nanos sum;
- Array<Nanos, LENGTH> time;
- public:
- Clock();
- // the first invocation will always return 0 nanos
- check_return Error update(Nanos& n);
- float getUpdatesPerSecond() const;
- check_return Error wait(Nanos nanos) const;
- check_return static Error getNanos(Nanos& n);
- };
- }
- #endif
|