From f7b4866811c63ae24c366d9452e53d24e504336f Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Thu, 12 Dec 2024 19:47:59 +0100 Subject: fps fix + regression test --- src/test/LoopTimerTest.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/test') diff --git a/src/test/LoopTimerTest.cpp b/src/test/LoopTimerTest.cpp index 5e1eccf..c468567 100644 --- a/src/test/LoopTimerTest.cpp +++ b/src/test/LoopTimerTest.cpp @@ -76,3 +76,19 @@ TEST_F(LoopTimerTest, getCurrentTime) { ASSERT_NEAR(loop_timer.get_elapsed_time().count(), elapsed_time, 5); } +TEST_F(LoopTimerTest, getFPS) { + // Set the target FPS to 60 (which gives a target time per frame of ~16.67 ms) + loop_timer.set_target_framerate(60); + + auto start_time = steady_clock::now(); + loop_timer.enforce_frame_rate(); + + auto elapsed_time = steady_clock::now() - start_time; + loop_timer.update(); + unsigned int fps = loop_timer.get_fps(); + auto elapsed_ms = duration_cast(elapsed_time).count(); + + // For 60 FPS, the target frame time is around 16.67ms + ASSERT_NEAR(elapsed_ms, 16.7, 1); + ASSERT_NEAR(fps, 60, 2); +} -- cgit v1.2.3 From ca4c004d473ad5ed02abd4a7beff3a5a65c83487 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Fri, 13 Dec 2024 16:31:13 +0100 Subject: made test less strict --- src/test/LoopTimerTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/test') diff --git a/src/test/LoopTimerTest.cpp b/src/test/LoopTimerTest.cpp index 6391076..7bd6305 100644 --- a/src/test/LoopTimerTest.cpp +++ b/src/test/LoopTimerTest.cpp @@ -30,7 +30,7 @@ TEST_F(LoopTimerTest, EnforcesTargetFrameRate) { auto elapsed_ms = duration_cast(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, 5); } TEST_F(LoopTimerTest, SetTargetFps) { -- cgit v1.2.3 From b9fc66f6922b1f40f2dbe14e8dfc4caa469654bc Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sat, 14 Dec 2024 11:28:34 +0100 Subject: fix SceneManagerTest --- src/test/SceneManagerTest.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'src/test') diff --git a/src/test/SceneManagerTest.cpp b/src/test/SceneManagerTest.cpp index 9bb260c..480e07a 100644 --- a/src/test/SceneManagerTest.cpp +++ b/src/test/SceneManagerTest.cpp @@ -15,11 +15,9 @@ using namespace crepe; class ConcreteScene1 : public Scene { public: void load_scene() { - Mediator & mediator = this->mediator; - ComponentManager & mgr = mediator.component_manager; - GameObject object1 = mgr.new_object("scene_1", "tag_scene_1", vec2{0, 0}, 0, 1); - GameObject object2 = mgr.new_object("scene_1", "tag_scene_1", vec2{1, 0}, 0, 1); - GameObject object3 = mgr.new_object("scene_1", "tag_scene_1", vec2{2, 0}, 0, 1); + GameObject object1 = new_object("scene_1", "tag_scene_1", vec2{0, 0}, 0, 1); + GameObject object2 = new_object("scene_1", "tag_scene_1", vec2{1, 0}, 0, 1); + GameObject object3 = new_object("scene_1", "tag_scene_1", vec2{2, 0}, 0, 1); } string get_name() const { return "scene1"; } @@ -28,12 +26,10 @@ public: class ConcreteScene2 : public Scene { public: void load_scene() { - Mediator & mediator = this->mediator; - ComponentManager & mgr = mediator.component_manager; - GameObject object1 = mgr.new_object("scene_2", "tag_scene_2", vec2{0, 0}, 0, 1); - GameObject object2 = mgr.new_object("scene_2", "tag_scene_2", vec2{0, 1}, 0, 1); - GameObject object3 = mgr.new_object("scene_2", "tag_scene_2", vec2{0, 2}, 0, 1); - GameObject object4 = mgr.new_object("scene_2", "tag_scene_2", vec2{0, 3}, 0, 1); + GameObject object1 = new_object("scene_2", "tag_scene_2", vec2{0, 0}, 0, 1); + GameObject object2 = new_object("scene_2", "tag_scene_2", vec2{0, 1}, 0, 1); + GameObject object3 = new_object("scene_2", "tag_scene_2", vec2{0, 2}, 0, 1); + GameObject object4 = new_object("scene_2", "tag_scene_2", vec2{0, 3}, 0, 1); } string get_name() const { return "scene2"; } @@ -44,9 +40,7 @@ public: ConcreteScene3(const string & name) : name(name) {} void load_scene() { - Mediator & mediator = this->mediator; - ComponentManager & mgr = mediator.component_manager; - GameObject object1 = mgr.new_object("scene_3", "tag_scene_3", vec2{0, 0}, 0, 1); + GameObject object1 = new_object("scene_3", "tag_scene_3", vec2{0, 0}, 0, 1); } string get_name() const { return name; } -- cgit v1.2.3 From fd2ebb54d0c2b269c15fc84a4ac77993efc917d7 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Sat, 14 Dec 2024 11:40:20 +0100 Subject: updated test values --- src/test/CollisionTest.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/test') diff --git a/src/test/CollisionTest.cpp b/src/test/CollisionTest.cpp index dd45eb6..e93d61f 100644 --- a/src/test/CollisionTest.cpp +++ b/src/test/CollisionTest.cpp @@ -231,7 +231,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_x_direction) { collision_happend = true; EXPECT_EQ(ev.info.this_collider.game_object_id, 1); EXPECT_EQ(ev.info.resolution.x, -5); - EXPECT_EQ(ev.info.resolution.y, -5); + EXPECT_EQ(ev.info.resolution.y, 5); EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::X_DIRECTION); }; @@ -239,7 +239,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_x_direction) { collision_happend = true; EXPECT_EQ(ev.info.this_collider.game_object_id, 2); EXPECT_EQ(ev.info.resolution.x, 5); - EXPECT_EQ(ev.info.resolution.y, 5); + EXPECT_EQ(ev.info.resolution.y, -5); EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::X_DIRECTION); }; @@ -259,7 +259,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_y_direction) { script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { collision_happend = true; EXPECT_EQ(ev.info.this_collider.game_object_id, 1); - EXPECT_EQ(ev.info.resolution.x, -5); + EXPECT_EQ(ev.info.resolution.x, 5); EXPECT_EQ(ev.info.resolution.y, -5); EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::Y_DIRECTION); @@ -267,7 +267,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_y_direction) { script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { collision_happend = true; EXPECT_EQ(ev.info.this_collider.game_object_id, 2); - EXPECT_EQ(ev.info.resolution.x, 5); + EXPECT_EQ(ev.info.resolution.x, -5); EXPECT_EQ(ev.info.resolution.y, 5); EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::Y_DIRECTION); @@ -311,7 +311,7 @@ TEST_F(CollisionTest, collision_box_box_static_x_direction) { collision_happend = true; EXPECT_EQ(ev.info.this_collider.game_object_id, 1); EXPECT_EQ(ev.info.resolution.x, -5); - EXPECT_EQ(ev.info.resolution.y, -5); + EXPECT_EQ(ev.info.resolution.y, 5); EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::X_DIRECTION); }; @@ -335,7 +335,7 @@ TEST_F(CollisionTest, collision_box_box_static_y_direction) { script_object1_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { collision_happend = true; EXPECT_EQ(ev.info.this_collider.game_object_id, 1); - EXPECT_EQ(ev.info.resolution.x, -5); + EXPECT_EQ(ev.info.resolution.x, 5); EXPECT_EQ(ev.info.resolution.y, -5); EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::Y_DIRECTION); -- cgit v1.2.3