diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-11-24 16:38:58 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-11-24 16:38:58 +0100 |
commit | 020cdfddcd06e162515deee4941ce91f3a945ee6 (patch) | |
tree | 0c63057c6ba464d88260bfa0c1a71601ad1a03ff /src/crepe/api/LoopTimer.cpp | |
parent | a1a95627c8c2a77530feeee8507b5409616bc54a (diff) |
fps counter functionality
Diffstat (limited to 'src/crepe/api/LoopTimer.cpp')
-rw-r--r-- | src/crepe/api/LoopTimer.cpp | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/crepe/api/LoopTimer.cpp b/src/crepe/api/LoopTimer.cpp index 15a0e3a..f94e24b 100644 --- a/src/crepe/api/LoopTimer.cpp +++ b/src/crepe/api/LoopTimer.cpp @@ -30,7 +30,8 @@ void LoopTimer::update() { if (this->delta_time > this->maximum_delta_time) { this->delta_time = this->maximum_delta_time; } - + this->actual_fps = 1.0 / this->delta_time.count(); + this->delta_time *= this->game_scale; this->elapsed_time += this->delta_time; this->last_frame_time = current_frame_time; @@ -44,13 +45,13 @@ void LoopTimer::advance_fixed_update() { this->elapsed_fixed_time += this->fixed double LoopTimer::get_fixed_delta_time() const { return this->fixed_delta_time.count(); } -void LoopTimer::set_fps(int fps) { - this->fps = fps; +void LoopTimer::set_target_fps(int fps) { + this->target_fps = fps; // target time per frame in seconds - this->frame_target_time = std::chrono::duration<double>(1.0) / fps; + this->frame_target_time = std::chrono::duration<double>(1.0) / target_fps; } -int LoopTimer::get_fps() const { return this->fps; } +int LoopTimer::get_fps() const { return this->actual_fps; } void LoopTimer::set_game_scale(double value) { this->game_scale = value; } @@ -70,8 +71,6 @@ void LoopTimer::enforce_frame_rate() { SDLContext::get_instance().delay(delay_time.count()); } } - - this->last_frame_time = current_frame_time; } double LoopTimer::get_lag() const { |