aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/LoopTimer.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-15 20:39:07 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-15 20:39:07 +0100
commite8cd950b8ebd152d76d588d4fedc7f4c239b0835 (patch)
tree7919d13a79d52f1365bc19bf1b435a6264ee5512 /src/crepe/api/LoopTimer.cpp
parent5bee4515c1089ce3499bc3b74780db94f0c02306 (diff)
parent9f6475e7b0698c414138e2a8140b47f01ce9c5d1 (diff)
merge `master` into `loek/cleanup`
Diffstat (limited to 'src/crepe/api/LoopTimer.cpp')
-rw-r--r--src/crepe/api/LoopTimer.cpp25
1 files changed, 9 insertions, 16 deletions
diff --git a/src/crepe/api/LoopTimer.cpp b/src/crepe/api/LoopTimer.cpp
index b3aec22..a9800b7 100644
--- a/src/crepe/api/LoopTimer.cpp
+++ b/src/crepe/api/LoopTimer.cpp
@@ -24,9 +24,8 @@ void LoopTimer::start() {
void LoopTimer::update() {
auto current_frame_time = std::chrono::steady_clock::now();
// Convert to duration in seconds for delta time
- this->delta_time
- = std::chrono::duration_cast<std::chrono::duration<double>>(
- current_frame_time - last_frame_time);
+ this->delta_time = std::chrono::duration_cast<std::chrono::duration<double>>(
+ current_frame_time - last_frame_time);
if (this->delta_time > this->maximum_delta_time) {
this->delta_time = this->maximum_delta_time;
@@ -39,17 +38,11 @@ void LoopTimer::update() {
double LoopTimer::get_delta_time() const { return this->delta_time.count(); }
-double LoopTimer::get_current_time() const {
- return this->elapsed_time.count();
-}
+double LoopTimer::get_current_time() const { return this->elapsed_time.count(); }
-void LoopTimer::advance_fixed_update() {
- this->elapsed_fixed_time += this->fixed_delta_time;
-}
+void LoopTimer::advance_fixed_update() { this->elapsed_fixed_time += this->fixed_delta_time; }
-double LoopTimer::get_fixed_delta_time() const {
- return this->fixed_delta_time.count();
-}
+double LoopTimer::get_fixed_delta_time() const { return this->fixed_delta_time.count(); }
void LoopTimer::set_fps(int fps) {
this->fps = fps;
@@ -66,13 +59,13 @@ void LoopTimer::enforce_frame_rate() {
std::chrono::steady_clock::time_point current_frame_time
= std::chrono::steady_clock::now();
std::chrono::milliseconds frame_duration
- = std::chrono::duration_cast<std::chrono::milliseconds>(
- current_frame_time - this->last_frame_time);
+ = std::chrono::duration_cast<std::chrono::milliseconds>(current_frame_time
+ - this->last_frame_time);
if (frame_duration < this->frame_target_time) {
std::chrono::milliseconds delay_time
- = std::chrono::duration_cast<std::chrono::milliseconds>(
- this->frame_target_time - frame_duration);
+ = std::chrono::duration_cast<std::chrono::milliseconds>(this->frame_target_time
+ - frame_duration);
if (delay_time.count() > 0) {
SDLContext::get_instance().delay(delay_time.count());
}