aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/crepe/manager/LoopTimerManager.cpp15
-rw-r--r--src/crepe/manager/LoopTimerManager.h2
-rw-r--r--src/test/LoopManagerTest.cpp7
3 files changed, 10 insertions, 14 deletions
diff --git a/src/crepe/manager/LoopTimerManager.cpp b/src/crepe/manager/LoopTimerManager.cpp
index 5a6cc76..ea4619f 100644
--- a/src/crepe/manager/LoopTimerManager.cpp
+++ b/src/crepe/manager/LoopTimerManager.cpp
@@ -18,13 +18,12 @@ void LoopTimerManager::start() {
this->last_frame_time = std::chrono::steady_clock::now();
this->elapsed_time = elapsed_time_t{0};
- // by starting the elapsed_fixed_time at (0 - fixed_delta_time) in milliseconds it calls a fixed update at the start of the loop.
- // this->elapsed_fixed_time = -this->fixed_delta_time;
+ this->elapsed_fixed_time = elapsed_time_t{0};
this->delta_time = duration_t{0};
}
void LoopTimerManager::update() {
- TimePoint_t current_frame_time
+ time_point_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;
@@ -41,12 +40,12 @@ 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;}
elapsed_time_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<elapsed_time_t>(this->fixed_delta_time);
}
void LoopTimerManager::set_target_framerate(unsigned fps) {
@@ -64,9 +63,9 @@ 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
+ time_point_t current_frame_time
= std::chrono::steady_clock::now();
- Duration_t frame_duration = current_frame_time - this->last_frame_time;
+ 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) {
duration_t delay_time = this->frame_target_time - frame_duration;
@@ -88,6 +87,6 @@ void LoopTimerManager::set_fixed_delta_time(float seconds) {
this->fixed_delta_time = duration_t(seconds);
}
-Duration_t LoopTimerManager::get_fixed_delta_time() const {
+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 ad522f7..0eda156 100644
--- a/src/crepe/manager/LoopTimerManager.h
+++ b/src/crepe/manager/LoopTimerManager.h
@@ -6,7 +6,7 @@
namespace crepe {
-typedef std::chrono::duration<float> duration_t;
+typedef std::chrono::duration<double> duration_t;
typedef std::chrono::duration<unsigned long long, std::micro> elapsed_time_t;
/**
diff --git a/src/test/LoopManagerTest.cpp b/src/test/LoopManagerTest.cpp
index 4e0ecdc..cf7a454 100644
--- a/src/test/LoopManagerTest.cpp
+++ b/src/test/LoopManagerTest.cpp
@@ -28,7 +28,7 @@ TEST_F(LoopManagerTest, FixedUpdate) {
// Set expectations for the mock calls
EXPECT_CALL(test_loop, frame_update).Times(::testing::Exactly(60));
- EXPECT_CALL(test_loop, fixed_update).Times(::testing::Exactly(50));
+ EXPECT_CALL(test_loop, fixed_update).Times(::testing::Exactly(49));
// Start the loop in a separate thread
std::thread loop_thread([&]() { test_loop.start(); });
@@ -49,7 +49,7 @@ TEST_F(LoopManagerTest, ScaledFixedUpdate) {
// Set expectations for the mock calls
EXPECT_CALL(test_loop, frame_update).Times(::testing::Exactly(60));
- EXPECT_CALL(test_loop, fixed_update).Times(::testing::Exactly(50));
+ EXPECT_CALL(test_loop, fixed_update).Times(::testing::Exactly(49));
// Start the loop in a separate thread
std::thread loop_thread([&]() { test_loop.start(); });
@@ -67,9 +67,6 @@ TEST_F(LoopManagerTest, ScaledFixedUpdate) {
TEST_F(LoopManagerTest, ShutDown) {
// Arrange
test_loop.loop_timer.set_target_framerate(60);
-
- EXPECT_CALL(test_loop, frame_update).Times(::testing::AtLeast(1));
- EXPECT_CALL(test_loop, fixed_update).Times(::testing::AtLeast(1));
// Start the loop in a separate thread
std::thread loop_thread([&]() { test_loop.start(); });
std::this_thread::sleep_for(std::chrono::milliseconds(1));