diff options
-rw-r--r-- | src/crepe/api/LoopManager.cpp | 7 | ||||
-rw-r--r-- | src/crepe/api/LoopManager.h | 9 | ||||
-rw-r--r-- | src/crepe/manager/LoopTimerManager.cpp | 10 | ||||
-rw-r--r-- | src/crepe/manager/LoopTimerManager.h | 2 | ||||
-rw-r--r-- | src/test/LoopManagerTest.cpp | 8 |
5 files changed, 15 insertions, 21 deletions
diff --git a/src/crepe/api/LoopManager.cpp b/src/crepe/api/LoopManager.cpp index 922e66b..f588d7f 100644 --- a/src/crepe/api/LoopManager.cpp +++ b/src/crepe/api/LoopManager.cpp @@ -48,13 +48,13 @@ void LoopManager::loop() { while (game_running) { this->loop_timer.update(); - while (this->loop_timer.get_lag() >= this->loop_timer.get_scaled_fixed_delta_time()) { + while (this->loop_timer.get_lag() >= this->loop_timer.get_fixed_loop_interval()) { this->process_input(); this->fixed_update(); this->loop_timer.advance_fixed_update(); } - this->update(); + this->frame_update(); this->render(); this->loop_timer.enforce_frame_rate(); } @@ -72,9 +72,10 @@ void LoopManager::render() { this->get_system<AnimatorSystem>().update(); this->get_system<RenderSystem>().update(); } + bool LoopManager::on_shutdown(const ShutDownEvent & e) { this->game_running = false; return false; } -void LoopManager::update() {} +void LoopManager::frame_update() {} diff --git a/src/crepe/api/LoopManager.h b/src/crepe/api/LoopManager.h index 6b2e857..f94cea1 100644 --- a/src/crepe/api/LoopManager.h +++ b/src/crepe/api/LoopManager.h @@ -63,14 +63,7 @@ private: * * Updates the game state based on the elapsed time since the last frame. */ - virtual void update(); - - /** - * \brief Late update which is called after update(). - * - * This function can be used for final adjustments before rendering. - */ - void late_update(); + virtual void frame_update(); /** * \brief Fixed update executed at a fixed rate. diff --git a/src/crepe/manager/LoopTimerManager.cpp b/src/crepe/manager/LoopTimerManager.cpp index 9d9897d..9c77785 100644 --- a/src/crepe/manager/LoopTimerManager.cpp +++ b/src/crepe/manager/LoopTimerManager.cpp @@ -48,10 +48,6 @@ void LoopTimerManager::advance_fixed_update() { this->elapsed_fixed_time += this->fixed_delta_time; } -double LoopTimerManager::get_fixed_delta_time() const { - return this->fixed_delta_time.count(); -} - void LoopTimerManager::set_target_fps(int fps) { this->target_fps = fps; // target time per frame in seconds @@ -82,9 +78,13 @@ void LoopTimerManager::enforce_frame_rate() { double LoopTimerManager::get_lag() const { return (this->elapsed_time - this->elapsed_fixed_time).count(); } -double LoopTimerManager::get_scaled_fixed_delta_time() const { +double LoopTimerManager::get_fixed_delta_time() const { return this->fixed_delta_time.count() * this->time_scale; } void LoopTimerManager::set_fixed_delta_time(int seconds) { this->fixed_delta_time = std::chrono::duration<double>(seconds); } + +double LoopTimerManager::get_fixed_loop_interval() const { + return this->fixed_delta_time.count(); +} diff --git a/src/crepe/manager/LoopTimerManager.h b/src/crepe/manager/LoopTimerManager.h index 8fb4461..84178eb 100644 --- a/src/crepe/manager/LoopTimerManager.h +++ b/src/crepe/manager/LoopTimerManager.h @@ -73,7 +73,7 @@ public: * * \return The fixed delta time, scaled by time scale, in seconds. */ - double get_scaled_fixed_delta_time() const; + double get_fixed_loop_interval() const; /** * \brief Get the fixed delta time in seconds without scaling by the time scale. diff --git a/src/test/LoopManagerTest.cpp b/src/test/LoopManagerTest.cpp index 55ccbb3..c44ebda 100644 --- a/src/test/LoopManagerTest.cpp +++ b/src/test/LoopManagerTest.cpp @@ -15,7 +15,7 @@ protected: class TestGameLoop : public crepe::LoopManager { public: MOCK_METHOD(void, fixed_update, (), (override)); - MOCK_METHOD(void, update, (), (override)); + MOCK_METHOD(void, frame_update, (), (override)); MOCK_METHOD(void, render, (), (override)); }; @@ -29,7 +29,7 @@ TEST_F(LoopManagerTest, FixedUpdate) { // Set expectations for the mock calls EXPECT_CALL(test_loop, render).Times(::testing::Exactly(60)); - EXPECT_CALL(test_loop, update).Times(::testing::Exactly(60)); + EXPECT_CALL(test_loop, frame_update).Times(::testing::Exactly(60)); EXPECT_CALL(test_loop, fixed_update).Times(::testing::Exactly(50)); // Start the loop in a separate thread @@ -51,7 +51,7 @@ TEST_F(LoopManagerTest, ScaledFixedUpdate) { // Set expectations for the mock calls EXPECT_CALL(test_loop, render).Times(::testing::Exactly(60)); - EXPECT_CALL(test_loop, update).Times(::testing::Exactly(60)); + EXPECT_CALL(test_loop, frame_update).Times(::testing::Exactly(60)); EXPECT_CALL(test_loop, fixed_update).Times(::testing::Exactly(50)); // Start the loop in a separate thread @@ -72,7 +72,7 @@ TEST_F(LoopManagerTest, ShutDown) { test_loop.loop_timer.set_target_fps(60); EXPECT_CALL(test_loop, render).Times(::testing::AtLeast(1)); - EXPECT_CALL(test_loop, update).Times(::testing::AtLeast(1)); + 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(); }); |