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.h5
-rw-r--r--src/crepe/manager/EventManager.cpp2
-rw-r--r--src/crepe/manager/EventManager.h1
-rw-r--r--src/crepe/manager/LoopTimerManager.cpp18
-rw-r--r--src/test/EventTest.cpp13
-rw-r--r--src/test/LoopManagerTest.cpp70
-rw-r--r--src/test/LoopTimerTest.cpp4
-rw-r--r--src/test/ScriptTest.h2
9 files changed, 57 insertions, 63 deletions
diff --git a/src/crepe/api/LoopManager.cpp b/src/crepe/api/LoopManager.cpp
index c25e31e..f41c357 100644
--- a/src/crepe/api/LoopManager.cpp
+++ b/src/crepe/api/LoopManager.cpp
@@ -27,9 +27,7 @@ LoopManager::LoopManager() {
[this](const ShutDownEvent & event) { return this->on_shutdown(event); });
}
-void LoopManager::process_input() {
- this->get_system<InputSystem>().update();
-}
+void LoopManager::process_input() { this->get_system<InputSystem>().update(); }
void LoopManager::start() {
this->setup();
@@ -45,7 +43,6 @@ void LoopManager::fixed_update() {
}
void LoopManager::loop() {
-
while (game_running) {
this->loop_timer.update();
diff --git a/src/crepe/api/LoopManager.h b/src/crepe/api/LoopManager.h
index 9986aa5..6b2e857 100644
--- a/src/crepe/api/LoopManager.h
+++ b/src/crepe/api/LoopManager.h
@@ -4,11 +4,11 @@
#include "../facade/SDLContext.h"
#include "../manager/ComponentManager.h"
-#include "../manager/SceneManager.h"
#include "../manager/EventManager.h"
#include "../manager/LoopTimerManager.h"
-#include "../system/System.h"
#include "../manager/Mediator.h"
+#include "../manager/SceneManager.h"
+#include "../system/System.h"
#include "api/Event.h"
@@ -103,7 +103,6 @@ private:
//! SDL context \todo no more singletons!
SDLContext & sdl_context = SDLContext::get_instance();
-
private:
/**
* \brief Callback function for ShutDownEvent
diff --git a/src/crepe/manager/EventManager.cpp b/src/crepe/manager/EventManager.cpp
index 9b0fa95..6aa49ee 100644
--- a/src/crepe/manager/EventManager.cpp
+++ b/src/crepe/manager/EventManager.cpp
@@ -3,7 +3,7 @@
using namespace crepe;
using namespace std;
-EventManager::EventManager(Mediator & mediator) : Manager(mediator){
+EventManager::EventManager(Mediator & mediator) : Manager(mediator) {
this->mediator.event_manager = *this;
}
void EventManager::dispatch_events() {
diff --git a/src/crepe/manager/EventManager.h b/src/crepe/manager/EventManager.h
index 30b929c..ba55edf 100644
--- a/src/crepe/manager/EventManager.h
+++ b/src/crepe/manager/EventManager.h
@@ -98,7 +98,6 @@ public:
void clear();
private:
-
/**
* \struct QueueEntry
* \brief Represents an entry in the event queue.
diff --git a/src/crepe/manager/LoopTimerManager.cpp b/src/crepe/manager/LoopTimerManager.cpp
index 2379fdd..9bf30ae 100644
--- a/src/crepe/manager/LoopTimerManager.cpp
+++ b/src/crepe/manager/LoopTimerManager.cpp
@@ -8,10 +8,10 @@
using namespace crepe;
-LoopTimerManager::LoopTimerManager(Mediator & mediator) : Manager(mediator) {
+LoopTimerManager::LoopTimerManager(Mediator & mediator) : Manager(mediator) {
this->mediator.loop_timer = *this;
- dbg_trace();
- }
+ dbg_trace();
+}
void LoopTimerManager::start() {
this->last_frame_time = std::chrono::steady_clock::now();
@@ -38,13 +38,19 @@ void LoopTimerManager::update() {
this->last_frame_time = current_frame_time;
}
-double LoopTimerManager::get_delta_time() const { return this->delta_time.count() * this->time_scale; }
+double LoopTimerManager::get_delta_time() const {
+ return this->delta_time.count() * this->time_scale;
+}
double LoopTimerManager::get_current_time() const { return this->elapsed_time.count(); }
-void LoopTimerManager::advance_fixed_update() { this->elapsed_fixed_time += this->fixed_delta_time; }
+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(); }
+double LoopTimerManager::get_fixed_delta_time() const {
+ return this->fixed_delta_time.count();
+}
void LoopTimerManager::set_target_fps(int fps) {
this->target_fps = fps;
diff --git a/src/test/EventTest.cpp b/src/test/EventTest.cpp
index 8479998..82272b5 100644
--- a/src/test/EventTest.cpp
+++ b/src/test/EventTest.cpp
@@ -1,8 +1,8 @@
-#include <gmock/gmock.h>
-#include <gtest/gtest.h>
#include <crepe/api/Event.h>
#include <crepe/manager/EventManager.h>
#include <crepe/manager/Mediator.h>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
using namespace std;
using namespace std::chrono_literals;
using namespace crepe;
@@ -53,13 +53,11 @@ TEST_F(EventManagerTest, EventManagerTest_trigger_all_channels) {
EXPECT_EQ(e.button, MouseButton::LEFT_MOUSE);
return false;
};
- event_mgr.subscribe<MouseClickEvent>(mouse_handler,
- EventManager::CHANNEL_ALL);
+ event_mgr.subscribe<MouseClickEvent>(mouse_handler, EventManager::CHANNEL_ALL);
MouseClickEvent click_event{
.mouse_x = 100, .mouse_y = 200, .button = MouseButton::LEFT_MOUSE};
- event_mgr.trigger_event<MouseClickEvent>(click_event,
- EventManager::CHANNEL_ALL);
+ event_mgr.trigger_event<MouseClickEvent>(click_event, EventManager::CHANNEL_ALL);
EXPECT_TRUE(triggered);
}
@@ -77,8 +75,7 @@ TEST_F(EventManagerTest, EventManagerTest_trigger_one_channel) {
MouseClickEvent click_event{
.mouse_x = 100, .mouse_y = 200, .button = MouseButton::LEFT_MOUSE};
- event_mgr.trigger_event<MouseClickEvent>(click_event,
- EventManager::CHANNEL_ALL);
+ event_mgr.trigger_event<MouseClickEvent>(click_event, EventManager::CHANNEL_ALL);
EXPECT_FALSE(triggered);
event_mgr.trigger_event<MouseClickEvent>(click_event, test_channel);
diff --git a/src/test/LoopManagerTest.cpp b/src/test/LoopManagerTest.cpp
index 13a0ada..f73605e 100644
--- a/src/test/LoopManagerTest.cpp
+++ b/src/test/LoopManagerTest.cpp
@@ -1,67 +1,63 @@
#include <chrono>
-#include <gtest/gtest.h>
#include <gmock/gmock.h>
+#include <gtest/gtest.h>
#include <thread>
#define private public
#define protected public
#include <crepe/api/LoopManager.h>
-#include <crepe/manager/LoopTimerManager.h>
#include <crepe/manager/EventManager.h>
+#include <crepe/manager/LoopTimerManager.h>
using namespace std::chrono;
using namespace crepe;
class LoopManagerTest : public ::testing::Test {
protected:
- class TestGameLoop : public crepe::LoopManager {
- public:
- MOCK_METHOD(void, fixed_update, (), (override));
- MOCK_METHOD(void, update, (), (override));
+ class TestGameLoop : public crepe::LoopManager {
+ public:
+ MOCK_METHOD(void, fixed_update, (), (override));
+ MOCK_METHOD(void, update, (), (override));
MOCK_METHOD(void, render, (), (override));
- };
+ };
- TestGameLoop test_loop;
- void SetUp() override {
-
- }
+ TestGameLoop test_loop;
+ void SetUp() override {}
};
TEST_F(LoopManagerTest, FixedUpdate) {
- // Arrange
- test_loop.loop_timer.set_target_fps(60);
+ // Arrange
+ test_loop.loop_timer.set_target_fps(60);
- // Set expectations for the mock calls
- EXPECT_CALL(test_loop, render).Times(::testing::Exactly(60));
+ // 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::Exactly(50));
+ EXPECT_CALL(test_loop, fixed_update).Times(::testing::Exactly(50));
- // Start the loop in a separate thread
- std::thread loop_thread([&]() { test_loop.start(); });
+ // Start the loop in a separate thread
+ std::thread loop_thread([&]() { test_loop.start(); });
- // Let the loop run for exactly 1 second
- std::this_thread::sleep_for(std::chrono::seconds(1));
+ // Let the loop run for exactly 1 second
+ std::this_thread::sleep_for(std::chrono::seconds(1));
- // Stop the game loop
- test_loop.game_running = false;
- // Wait for the loop thread to finish
- loop_thread.join();
+ // Stop the game loop
+ test_loop.game_running = false;
+ // Wait for the loop thread to finish
+ loop_thread.join();
- // Test finished
+ // Test finished
}
TEST_F(LoopManagerTest, ShutDown) {
- // Arrange
- test_loop.loop_timer.set_target_fps(60);
+ // Arrange
+ test_loop.loop_timer.set_target_fps(60);
- EXPECT_CALL(test_loop, render).Times(::testing::AtLeast(1));
+ EXPECT_CALL(test_loop, render).Times(::testing::AtLeast(1));
EXPECT_CALL(test_loop, 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));
+ 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));
test_loop.event_manager.trigger_event<ShutDownEvent>(ShutDownEvent{});
- // Wait for the loop thread to finish
- loop_thread.join();
+ // Wait for the loop thread to finish
+ loop_thread.join();
- // Test finished
+ // Test finished
}
-
-
diff --git a/src/test/LoopTimerTest.cpp b/src/test/LoopTimerTest.cpp
index 09b4e00..c6655d9 100644
--- a/src/test/LoopTimerTest.cpp
+++ b/src/test/LoopTimerTest.cpp
@@ -1,6 +1,6 @@
#include <chrono>
-#include <thread>
#include <gtest/gtest.h>
+#include <thread>
#define private public
#define protected public
#include <crepe/manager/LoopTimerManager.h>
@@ -26,7 +26,7 @@ TEST_F(LoopTimerTest, EnforcesTargetFrameRate) {
auto elapsed_ms = duration_cast<milliseconds>(elapsed_time).count();
// For 60 FPS, the target frame time is around 16.67ms
- ASSERT_NEAR(elapsed_ms,16.7,1);
+ ASSERT_NEAR(elapsed_ms, 16.7, 1);
}
TEST_F(LoopTimerTest, SetTargetFps) {
// Set the target FPS to 120
diff --git a/src/test/ScriptTest.h b/src/test/ScriptTest.h
index ee68c23..e0205ff 100644
--- a/src/test/ScriptTest.h
+++ b/src/test/ScriptTest.h
@@ -6,8 +6,8 @@
#include <crepe/api/BehaviorScript.h>
#include <crepe/api/Script.h>
#include <crepe/manager/ComponentManager.h>
-#include <crepe/system/ScriptSystem.h>
#include <crepe/manager/EventManager.h>
+#include <crepe/system/ScriptSystem.h>
class ScriptTest : public testing::Test {
protected:
crepe::Mediator mediator;