3 #include "ge211_forward.h" 13 using Clock = std::conditional_t<
14 std::chrono::high_resolution_clock::is_steady,
15 std::chrono::high_resolution_clock,
16 std::chrono::steady_clock>;
44 std::chrono::duration_cast<std::chrono::duration<double>>(
53 std::chrono::duration_cast<std::chrono::duration<long, std::milli>>(
55 return millis.count();
61 bool operator==(
Duration other)
const 63 return duration_ == other.duration_;
66 bool operator!=(
Duration other)
const 68 return duration_ != other.duration_;
73 return duration_ < other.duration_;
76 bool operator<=(
Duration other)
const 78 return duration_ <= other.duration_;
83 return duration_ > other.duration_;
86 bool operator>=(
Duration other)
const 88 return duration_ >= other.duration_;
98 return {duration_ + other.duration_};
103 return {duration_ - other.duration_};
106 Duration operator*(
double factor)
const 108 return {duration_ * factor};
111 Duration operator/(
double factor)
const 113 return {duration_ / factor};
118 return *
this = *
this + other;
123 return *
this = *
this - other;
128 return *
this = *
this * factor;
133 return *
this = *
this / factor;
140 friend detail::Engine;
142 Duration(std::chrono::duration<double> duration)
143 :
Duration{std::chrono::duration_cast<detail::Clock::duration>
146 Duration(detail::Clock::duration duration)
147 : duration_{duration} {}
149 void sleep_for()
const 151 std::this_thread::sleep_for(duration_);
154 detail::Clock::duration duration_;
174 return time_point_ == other.time_point_;
179 return time_point_ != other.time_point_;
184 return time_point_ < other.time_point_;
189 return time_point_ <= other.time_point_;
194 return time_point_ > other.time_point_;
199 return time_point_ >= other.time_point_;
209 return Duration{time_point_ - other.time_point_};
214 return Time_point{time_point_ + duration.duration_};
219 return Time_point{time_point_ - duration.duration_};
224 return *
this = *
this + duration;
229 return *
this = *
this - duration;
235 Time_point(detail::Clock::time_point time_point)
236 : time_point_{time_point} {}
238 detail::Clock::time_point time_point_;
256 result.start_time_ += duration;
264 start_time_ = now_();
265 return start_time_ - previous;
281 return now_() - start_time_;
298 is_paused_ = start_paused;
303 fake_start_time_ = now_();
318 return elapsed_time_;
320 return now_() - fake_start_time_;
331 elapsed_time_ = now_() - fake_start_time_;
335 return elapsed_time_;
342 fake_start_time_ = now_() - elapsed_time_;
352 auto result = elapsed_time_;
357 auto result = now - fake_start_time_;
358 fake_start_time_ = now;
Duration reset()
Resets the timer, returning the elapsed time since starting or the most recent reset().
A class for timing intervals. The result is a Duration.
Duration elapsed_time() const
Returns how much time has elapsed since this timer was started or most recently reset.
The game engine namespace.
static Timer future(Duration duration)
Creates a timer whose “start time” is some Duration in the future.
bool is_paused() const
Checks whether the timer is currently paused.
Duration()
Constructs the zero duration.
Duration reset()
Resets a timer, returning the time it was at before it was reset.
double seconds() const
Gets this duration in seconds.
Duration elapsed_time() const
The elapsed time since the start or most recent reset, not counting paused times. ...
void resume()
Unpauses the timer. If the timer is already running, has no effect.
Duration(double seconds)
Constructs the duration of the given number of seconds.
A class for timing intervals while supporting pausing.
Time_point()
Constructs the zero time point (the epoch).
Duration pause()
Pauses the timer.
Timer()
Creates a new timer, running from the time it was created.
long milliseconds() const
Gets this duration, approximately, in milliseconds.
Time_point start_time() const
Returns the actual time when this timer was started or most recently reset.
static Time_point now()
Returns the current time.
Pausable_timer(bool start_paused=false)
Constructs a new pausable timer.