aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/crepe/api/LoopManager.cpp5
-rw-r--r--src/crepe/api/LoopManager.h2
-rw-r--r--src/test/LoopManagerTest.cpp44
3 files changed, 31 insertions, 20 deletions
diff --git a/src/crepe/api/LoopManager.cpp b/src/crepe/api/LoopManager.cpp
index 5879d79..454afe8 100644
--- a/src/crepe/api/LoopManager.cpp
+++ b/src/crepe/api/LoopManager.cpp
@@ -26,7 +26,9 @@ LoopManager::LoopManager() {
this->mediator.loop_timer = *loop_timer;
}
-void LoopManager::process_input() { this->sdl_context.handle_events(this->game_running); }
+void LoopManager::process_input() {
+
+ this->sdl_context.handle_events(this->game_running); }
void LoopManager::start() {
this->setup();
@@ -57,7 +59,6 @@ void LoopManager::setup() {
this->game_running = true;
this->loop_timer->start();
- this->loop_timer->set_target_fps(200);
}
void LoopManager::render() {
diff --git a/src/crepe/api/LoopManager.h b/src/crepe/api/LoopManager.h
index 7097ee1..2161dff 100644
--- a/src/crepe/api/LoopManager.h
+++ b/src/crepe/api/LoopManager.h
@@ -81,7 +81,7 @@ private:
*
* Renders the current state of the game to the screen.
*/
- void render();
+ virtual void render();
bool game_running = false;
diff --git a/src/test/LoopManagerTest.cpp b/src/test/LoopManagerTest.cpp
index f2ca8db..503eb1f 100644
--- a/src/test/LoopManagerTest.cpp
+++ b/src/test/LoopManagerTest.cpp
@@ -2,12 +2,13 @@
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <thread>
-
+#include <iostream>
#define private public
#define protected public
#include "api/LoopManager.h"
#include "api/LoopTimer.h"
-
+#include "manager/EventManager.h"
+#include "api/Event.h"
using namespace std::chrono;
using namespace crepe;
@@ -15,33 +16,42 @@ class LoopManagerTest : public ::testing::Test {
protected:
class TestGameLoop : public crepe::LoopManager {
public:
- MOCK_METHOD(void, fixed_update, (), (override));
+ MOCK_METHOD(void, fixed_update, (), (override));
MOCK_METHOD(void, update, (), (override));
+ MOCK_METHOD(void, render, (), (override));
};
TestGameLoop test_loop;
-
+ // LoopManager test_loop;
void SetUp() override {
- test_loop.loop_timer->set_target_fps(60); // Example target FPS
+ test_loop.loop_timer->set_target_fps(10);
+
}
};
-// Test to check if exactly 50 fixed updates occur in 1 second (50Hz)
TEST_F(LoopManagerTest, FixedUpdate) {
// Arrange
- using ::testing::AtLeast;
- using ::testing::Exactly;
+ test_loop.loop_timer->set_target_fps(60);
- test_loop.loop_timer->fixed_delta_time = std::chrono::milliseconds(20);
- test_loop.start();
- // Expect the `fixed_update` method to be called exactly 50 times
- EXPECT_CALL(test_loop, fixed_update()).Times(Exactly(50));
+ // 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, fixed_update).Times(::testing::AtLeast(50));
- auto start_time = steady_clock::now();
+ // Start the loop in a separate thread
+ std::thread loop_thread([&]() { test_loop.start(); });
- // Act: Simulate the game loop for 1 second
- while (duration_cast<milliseconds>(steady_clock::now() - start_time) < std::chrono::milliseconds(1000)) {
+ // Let the loop run for exactly 1 second
+ std::this_thread::sleep_for(std::chrono::seconds(1));
- }
- test_loop.game_running = false;
+ // Stop the game loop
+ test_loop.game_running = false;
+
+ // Wait for the loop thread to finish
+ loop_thread.join();
+
+ // Test finished
}
+
+
+