aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/crepe/api/LoopManager.cpp26
-rw-r--r--src/crepe/api/LoopManager.h2
-rw-r--r--src/crepe/manager/LoopTimerManager.cpp17
-rw-r--r--src/crepe/manager/LoopTimerManager.h3
-rw-r--r--src/test/LoopTimerTest.cpp4
5 files changed, 25 insertions, 27 deletions
diff --git a/src/crepe/api/LoopManager.cpp b/src/crepe/api/LoopManager.cpp
index 4ca9928..b335cad 100644
--- a/src/crepe/api/LoopManager.cpp
+++ b/src/crepe/api/LoopManager.cpp
@@ -1,4 +1,6 @@
#include "../facade/SDLContext.h"
+#include "../manager/EventManager.h"
+#include "../manager/LoopTimerManager.h"
#include "../system/AISystem.h"
#include "../system/AnimatorSystem.h"
#include "../system/AudioSystem.h"
@@ -8,8 +10,6 @@
#include "../system/PhysicsSystem.h"
#include "../system/RenderSystem.h"
#include "../system/ScriptSystem.h"
-#include "../manager/EventManager.h"
-#include "../manager/LoopTimerManager.h"
#include "../util/Log.h"
#include "LoopManager.h"
@@ -44,18 +44,18 @@ void LoopManager::setup() {
void LoopManager::loop() {
try {
- while (game_running) {
- this->loop_timer.update();
+ while (game_running) {
+ this->loop_timer.update();
- while (this->loop_timer.get_lag() >= this->loop_timer.get_fixed_delta_time()) {
- this->fixed_update();
- this->loop_timer.advance_fixed_elapsed_time();
- }
+ while (this->loop_timer.get_lag() >= this->loop_timer.get_fixed_delta_time()) {
+ this->fixed_update();
+ this->loop_timer.advance_fixed_elapsed_time();
+ }
- this->frame_update();
- this->loop_timer.enforce_frame_rate();
- }
- }catch(const exception & e){
+ this->frame_update();
+ this->loop_timer.enforce_frame_rate();
+ }
+ } catch (const exception & e) {
Log::logf(Log::Level::ERROR, "Exception caught in main loop: %s", e.what());
this->event_manager.trigger_event<ShutDownEvent>(ShutDownEvent{});
}
@@ -73,7 +73,7 @@ void LoopManager::fixed_update() {
}
// will be called every frame
-void LoopManager::frame_update() {
+void LoopManager::frame_update() {
this->scene_manager.load_next_scene();
this->get_system<AnimatorSystem>().update();
//render
diff --git a/src/crepe/api/LoopManager.h b/src/crepe/api/LoopManager.h
index 0110695..487f07a 100644
--- a/src/crepe/api/LoopManager.h
+++ b/src/crepe/api/LoopManager.h
@@ -69,6 +69,7 @@ private:
//! Indicates whether the game is running.
bool game_running = false;
+
private:
//! Global context
Mediator mediator;
@@ -90,7 +91,6 @@ private:
SDLContext & sdl_context = SDLContext::get_instance();
private:
-
/**
* \brief Callback function for ShutDownEvent
*
diff --git a/src/crepe/manager/LoopTimerManager.cpp b/src/crepe/manager/LoopTimerManager.cpp
index a306eb7..71a72e2 100644
--- a/src/crepe/manager/LoopTimerManager.cpp
+++ b/src/crepe/manager/LoopTimerManager.cpp
@@ -23,8 +23,7 @@ void LoopTimerManager::start() {
}
void LoopTimerManager::update() {
- TimePoint_t current_frame_time
- = std::chrono::steady_clock::now();
+ TimePoint_t current_frame_time = std::chrono::steady_clock::now();
// Convert to duration in seconds for delta time
this->delta_time = current_frame_time - last_frame_time;
@@ -40,12 +39,15 @@ void LoopTimerManager::update() {
this->last_frame_time = current_frame_time;
}
-Duration_t LoopTimerManager::get_delta_time() const {return this->delta_time * this->time_scale;}
+Duration_t LoopTimerManager::get_delta_time() const {
+ return this->delta_time * this->time_scale;
+}
ElapsedTime_t LoopTimerManager::get_elapsed_time() const { return this->elapsed_time; }
void LoopTimerManager::advance_fixed_elapsed_time() {
- this->elapsed_fixed_time += std::chrono::duration_cast<ElapsedTime_t>(this->fixed_delta_time);
+ this->elapsed_fixed_time
+ += std::chrono::duration_cast<ElapsedTime_t>(this->fixed_delta_time);
}
void LoopTimerManager::set_target_framerate(unsigned fps) {
@@ -63,8 +65,7 @@ void LoopTimerManager::set_time_scale(double value) { this->time_scale = value;
float LoopTimerManager::get_time_scale() const { return this->time_scale; }
void LoopTimerManager::enforce_frame_rate() {
- TimePoint_t current_frame_time
- = std::chrono::steady_clock::now();
+ TimePoint_t current_frame_time = std::chrono::steady_clock::now();
Duration_t 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) {
@@ -89,6 +90,4 @@ void LoopTimerManager::set_fixed_delta_time(float seconds) {
this->fixed_delta_time = Duration_t(seconds);
}
-Duration_t LoopTimerManager::get_fixed_delta_time() const {
- return this->fixed_delta_time;
-}
+Duration_t LoopTimerManager::get_fixed_delta_time() const { return this->fixed_delta_time; }
diff --git a/src/crepe/manager/LoopTimerManager.h b/src/crepe/manager/LoopTimerManager.h
index c5f3cb0..61ae6ef 100644
--- a/src/crepe/manager/LoopTimerManager.h
+++ b/src/crepe/manager/LoopTimerManager.h
@@ -158,8 +158,7 @@ private:
//! Delta time for the current frame in seconds.
Duration_t delta_time{0.0};
//! Target time per frame in seconds
- Duration_t frame_target_time
- = Duration_t(1.0) / target_fps;
+ Duration_t frame_target_time = Duration_t(1.0) / target_fps;
//! Fixed delta time for fixed updates in seconds.
Duration_t fixed_delta_time = Duration_t(1.0) / 50.0;
//! Total elapsed game time in microseconds.
diff --git a/src/test/LoopTimerTest.cpp b/src/test/LoopTimerTest.cpp
index 1216e5e..e4f8477 100644
--- a/src/test/LoopTimerTest.cpp
+++ b/src/test/LoopTimerTest.cpp
@@ -68,8 +68,8 @@ TEST_F(LoopTimerTest, getCurrentTime) {
auto end_time = steady_clock::now();
// Get the elapsed time in seconds as a double
- auto elapsed_time = std::chrono::duration_cast<ElapsedTime_t>(end_time - start_time).count();
-
+ auto elapsed_time
+ = std::chrono::duration_cast<ElapsedTime_t>(end_time - start_time).count();
ASSERT_NEAR(loop_timer.get_elapsed_time().count(), elapsed_time, 5);
}