ge211
2021.5.1
A student game engine
|
|
3 #include "ge211_forward.hxx"
13 using Clock = std::conditional_t<
14 std::chrono::high_resolution_clock::is_steady,
44 std::chrono::duration_cast<std::chrono::duration<double>>(
53 std::chrono::duration_cast<std::chrono::duration<long, std::milli>>(
55 return millis.count();
64 return duration_ == other.duration_;
70 return duration_ != other.duration_;
76 return duration_ < other.duration_;
82 return duration_ <= other.duration_;
88 return duration_ > other.duration_;
94 return duration_ >= other.duration_;
105 return {duration_ + other.duration_};
111 return {duration_ - other.duration_};
117 return {duration_ * factor};
123 return {duration_ / factor};
129 return *
this = *
this + other;
135 return *
this = *
this - other;
141 return *
this = *
this * factor;
147 return *
this = *
this / factor;
154 friend class detail::Engine;
157 :
Duration{std::chrono::duration_cast<detail::Clock::duration>
160 Duration(detail::Clock::duration duration)
161 : duration_{duration} {}
163 void sleep_for()
const
168 detail::Clock::duration duration_;
189 return time_point_ == other.time_point_;
195 return time_point_ != other.time_point_;
201 return time_point_ < other.time_point_;
207 return time_point_ <= other.time_point_;
213 return time_point_ > other.time_point_;
219 return time_point_ >= other.time_point_;
230 return Duration{time_point_ - other.time_point_};
236 return Time_point{time_point_ + duration.duration_};
242 return Time_point{time_point_ - duration.duration_};
248 return *
this = *
this + duration;
254 return *
this = *
this - duration;
260 Time_point(detail::Clock::time_point time_point)
261 : time_point_{time_point} {}
263 detail::Clock::time_point time_point_;
281 result.start_time_ += duration;
289 start_time_ = now_();
290 return start_time_ - previous;
306 return now_() - start_time_;
323 is_paused_ = start_paused;
328 fake_start_time_ = now_();
343 return elapsed_time_;
345 return now_() - fake_start_time_;
356 elapsed_time_ = now_() - fake_start_time_;
360 return elapsed_time_;
367 fake_start_time_ = now_() - elapsed_time_;
377 auto result = elapsed_time_;
382 auto result = now - fake_start_time_;
383 fake_start_time_ = now;
bool operator>=(Time_point other) const
Is this Time_point later than or equal to that one?
Duration & operator/=(double factor)
Division for Duration.
Duration elapsed_time() const
Returns how much time has elapsed since this timer was started or most recently reset.
bool operator>(Time_point other) const
Is this Time_point later than that one?
void resume()
Unpauses the timer. If the timer is already running, has no effect.
Time_point & operator+=(Duration duration)
Offsets a Time_point by adding on a Duration.
bool operator==(Duration other) const
Does this Duration equal another one?
double seconds() const
Gets this duration in seconds.
static Timer future(Duration duration)
Creates a timer whose “start time” is some Duration in the future.
Duration reset()
Resets a timer, returning the time it was at before it was reset.
bool operator==(Time_point other) const
Equality for Time_point.
long milliseconds() const
Gets this duration, approximately, in milliseconds.
Duration operator-(Time_point other) const
Finds the Duration between one Time_point and another.
The game engine namespace.
bool operator<=(Duration other) const
Less-than-or-equal-to for Duration.
bool is_paused() const
Checks whether the timer is currently paused.
Duration pause()
Pauses the timer.
Duration & operator+=(Duration other)
Addition for Duration.
bool operator<(Duration other) const
Less-than for Duration.
Time_point operator-(Duration duration) const
Offsets a Time_point subtracting by a Duration.
bool operator>(Duration other) const
Greater-than for Duration.
Duration()
Constructs the zero duration.
Timer()
Creates a new timer, running from the time it was created.
Duration operator/(double factor) const
Division for Duration.
A class for timing intervals while supporting pausing.
A class for timing intervals. The result is a Duration.
bool operator<(Time_point other) const
Is this Time_point earlier than that one?
bool operator<=(Time_point other) const
Is this Time_point earlier than or equal to that one?
Duration operator*(double factor) const
Multiplication for Duration.
bool operator!=(Time_point other) const
Disequality for Time_point.
Time_point()
Constructs the zero time point (the epoch).
Duration elapsed_time() const
The elapsed time since the start or most recent reset, not counting paused times.
Duration reset()
Resets the timer, returning the elapsed time since starting or the most recent reset().
static Time_point now()
Returns the current time.
Time_point operator+(Duration duration) const
Offsets a Time_point by adding a Duration.
Time_point & operator-=(Duration duration)
Offsets a Time_point subtracting off a Duration.
Time_point start_time() const
Returns the actual time when this timer was started or most recently reset.
bool operator!=(Duration other) const
Does this Duration NOT equal another one?
Duration & operator*=(double factor)
Multiplication for Duration.
Duration operator-(Duration other) const
Subtraction for Duration.
Duration operator+(Duration other) const
Addition for Duration.
Pausable_timer(bool start_paused=false)
Constructs a new pausable timer.
Duration(double seconds)
Constructs the duration of the given number of seconds.
Duration & operator-=(Duration other)
Subtraction for Duration.
bool operator>=(Duration other) const
Greater-than-or-equal-to for Duration.