diff options
author | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-11-18 15:08:31 +0100 |
---|---|---|
committer | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-11-18 15:08:31 +0100 |
commit | fee42c67918a9370f7f4e074dba9a677afccf90b (patch) | |
tree | c5ed200e3c584fafc4c6bd3df48adeed3cfbd31d /src/crepe/api/LoopTimer.cpp | |
parent | ed1403aea4412bd479244eae8e2940190e71cd28 (diff) | |
parent | 121b64b1cb6cfead5814070c8b0185d3d7308095 (diff) |
Merge remote-tracking branch 'origin/master' into niels/RenderingParticle
Diffstat (limited to 'src/crepe/api/LoopTimer.cpp')
-rw-r--r-- | src/crepe/api/LoopTimer.cpp | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/src/crepe/api/LoopTimer.cpp b/src/crepe/api/LoopTimer.cpp index 8f09e41..a9800b7 100644 --- a/src/crepe/api/LoopTimer.cpp +++ b/src/crepe/api/LoopTimer.cpp @@ -1,7 +1,7 @@ #include <chrono> #include "../facade/SDLContext.h" -#include "../util/log.h" +#include "../util/Log.h" #include "LoopTimer.h" @@ -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()); } |