aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/LoopTimer.cpp
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-12 07:59:47 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-12 07:59:47 +0100
commit0f68177a0384d41a7feff36cc0e1869b6d2ac9aa (patch)
tree4904b60820858efd0ee6ece0af1f2c1fc5846ec5 /src/crepe/api/LoopTimer.cpp
parent73f8d5c558ebc0820ede241e64a876ff1c5ccefb (diff)
parent194ee3f192c3343c3ccc28dfa97fed180503ffd4 (diff)
Merge branch 'master' of https://github.com/lonkaars/crepe into wouter/inputSystem
Diffstat (limited to 'src/crepe/api/LoopTimer.cpp')
-rw-r--r--src/crepe/api/LoopTimer.cpp79
1 files changed, 0 insertions, 79 deletions
diff --git a/src/crepe/api/LoopTimer.cpp b/src/crepe/api/LoopTimer.cpp
deleted file mode 100644
index 15a0e3a..0000000
--- a/src/crepe/api/LoopTimer.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-#include <chrono>
-
-#include "../facade/SDLContext.h"
-#include "../util/Log.h"
-
-#include "LoopTimer.h"
-
-using namespace crepe;
-
-LoopTimer::LoopTimer() { dbg_trace(); }
-
-LoopTimer & LoopTimer::get_instance() {
- static LoopTimer instance;
- return instance;
-}
-
-void LoopTimer::start() {
- this->last_frame_time = std::chrono::steady_clock::now();
- this->elapsed_time = std::chrono::milliseconds(0);
- this->elapsed_fixed_time = std::chrono::milliseconds(0);
- this->delta_time = std::chrono::milliseconds(0);
-}
-
-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);
-
- if (this->delta_time > this->maximum_delta_time) {
- this->delta_time = this->maximum_delta_time;
- }
-
- this->delta_time *= this->game_scale;
- this->elapsed_time += this->delta_time;
- this->last_frame_time = current_frame_time;
-}
-
-double LoopTimer::get_delta_time() const { return this->delta_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; }
-
-double LoopTimer::get_fixed_delta_time() const { return this->fixed_delta_time.count(); }
-
-void LoopTimer::set_fps(int fps) {
- this->fps = fps;
- // target time per frame in seconds
- this->frame_target_time = std::chrono::duration<double>(1.0) / fps;
-}
-
-int LoopTimer::get_fps() const { return this->fps; }
-
-void LoopTimer::set_game_scale(double value) { this->game_scale = value; }
-
-double LoopTimer::get_game_scale() const { return this->game_scale; }
-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);
-
- 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);
- if (delay_time.count() > 0) {
- SDLContext::get_instance().delay(delay_time.count());
- }
- }
-
- this->last_frame_time = current_frame_time;
-}
-
-double LoopTimer::get_lag() const {
- return (this->elapsed_time - this->elapsed_fixed_time).count();
-}