aboutsummaryrefslogtreecommitdiff
path: root/src/crepe
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe')
-rw-r--r--src/crepe/api/LoopManager.cpp2
-rw-r--r--src/crepe/manager/LoopTimerManager.cpp14
-rw-r--r--src/crepe/manager/LoopTimerManager.h9
3 files changed, 14 insertions, 11 deletions
diff --git a/src/crepe/api/LoopManager.cpp b/src/crepe/api/LoopManager.cpp
index 492b982..6ebf280 100644
--- a/src/crepe/api/LoopManager.cpp
+++ b/src/crepe/api/LoopManager.cpp
@@ -50,7 +50,7 @@ void LoopManager::loop() {
while (this->loop_timer.get_lag() >= this->loop_timer.get_fixed_delta_time()) {
this->process_input();
this->fixed_update();
- this->loop_timer.advance_fixed_update();
+ this->loop_timer.advance_fixed_elapsed_time();
}
this->frame_update();
diff --git a/src/crepe/manager/LoopTimerManager.cpp b/src/crepe/manager/LoopTimerManager.cpp
index d2e40fe..057a18e 100644
--- a/src/crepe/manager/LoopTimerManager.cpp
+++ b/src/crepe/manager/LoopTimerManager.cpp
@@ -47,7 +47,7 @@ double LoopTimerManager::get_delta_time() const {
double LoopTimerManager::get_current_time() const { return this->elapsed_time.count(); }
-void LoopTimerManager::advance_fixed_update() {
+void LoopTimerManager::advance_fixed_elapsed_time() {
this->elapsed_fixed_time += this->fixed_delta_time;
}
@@ -68,13 +68,15 @@ void LoopTimerManager::set_time_scale(double value) { this->time_scale = value;
double LoopTimerManager::get_time_scale() const { return this->time_scale; }
void LoopTimerManager::enforce_frame_rate() {
- auto current_frame_time = std::chrono::steady_clock::now();
- auto frame_duration = current_frame_time - this->last_frame_time;
+ std::chrono::steady_clock::time_point current_frame_time = std::chrono::steady_clock::now();
+ std::chrono::duration<double> frame_duration = current_frame_time - this->last_frame_time;
+
// Check if frame duration is less than the target frame time
if (frame_duration < this->frame_target_time) {
- auto delay_time = std::chrono::duration_cast<std::chrono::microseconds>(
- this->frame_target_time - frame_duration);
+ std::chrono::microseconds delay_time = std::chrono::duration_cast<std::chrono::microseconds>(
+ this->frame_target_time - frame_duration);
+
if (delay_time.count() > 0) {
std::this_thread::sleep_for(delay_time);
@@ -85,7 +87,7 @@ void LoopTimerManager::enforce_frame_rate() {
double LoopTimerManager::get_lag() const {
return (this->elapsed_time - this->elapsed_fixed_time).count();
}
-double LoopTimerManager::get_fixed_delta_time() const {
+double LoopTimerManager::get_scaled_fixed_delta_time() const {
return this->fixed_delta_time.count() * this->time_scale;
}
void LoopTimerManager::set_fixed_delta_time(double seconds) {
diff --git a/src/crepe/manager/LoopTimerManager.h b/src/crepe/manager/LoopTimerManager.h
index 46a0dcb..9336520 100644
--- a/src/crepe/manager/LoopTimerManager.h
+++ b/src/crepe/manager/LoopTimerManager.h
@@ -139,12 +139,13 @@ private:
void update();
/**
- * \brief Advance the game loop by a fixed update interval.
+ * \brief Progress the elapsed fixed time by the fixed delta time interval.
*
- * This method progresses the game state by a consistent, fixed time step, allowing for
- * stable updates independent of frame rate fluctuations.
+ * This method advances the game's fixed update loop by adding the fixed_delta_time
+ * to elapsed_fixed_time, ensuring the fixed update catches up with the elapsed time.
*/
- void advance_fixed_update();
+ void advance_fixed_elapsed_time();
+
private:
//! Target frames per second