#ifndef __JABYENGINE_FRAME_TIMER_HPP__ #define __JABYENGINE_FRAME_TIMER_HPP__ #include "frame_time_helper.hpp" #include namespace JabyEngine { class MasterTime { __friends: static uint32_t value; public: static uint32_t read() { return reinterpret_cast(MasterTime::value); } template static T read_as() { return static_cast(MasterTime::read()); } }; template class SimpleTimer { protected: T value = 0; public: constexpr SimpleTimer() = default; bool is_expired_for(T time) const { return static_cast((MasterTime::read_as() - this->value)) >= time; } void reset() { this->value = MasterTime::read_as(); } }; template class IntervalTimer : public SimpleTimer { private: T interval = 0; public: constexpr IntervalTimer() = default; constexpr IntervalTimer(T interval) : SimpleTimer(), interval(interval) { } void set_interval(T interval) { this->interval = interval; } bool is_expired() const { return SimpleTimer::is_expired_for(this->interval); } }; } #endif //!__JABYENGINE_FRAME_TIMER_HPP__