diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-20 11:10:06 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-20 11:10:06 +0100 |
commit | 5b1a26a13d8a2f44a7ef1fa8c0fc609c37adc28b (patch) | |
tree | 801ff9f3bbd82efacb5d4fdb1cbe4c09cfedf7c5 /src/test | |
parent | 88d84763147fbd6bcc087f15a7460566a009cdb2 (diff) | |
parent | 69ca2bafcd617ac8af1b8f715f0c802205a60ab1 (diff) |
merge masterloek/replay
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/CollisionTest.cpp | 93 | ||||
-rw-r--r-- | src/test/Profiling.cpp | 6 |
2 files changed, 31 insertions, 68 deletions
diff --git a/src/test/CollisionTest.cpp b/src/test/CollisionTest.cpp index 73a964a..c8d804c 100644 --- a/src/test/CollisionTest.cpp +++ b/src/test/CollisionTest.cpp @@ -67,7 +67,6 @@ public: world.add_component<Rigidbody>(Rigidbody::Data{ // TODO: remove unrelated properties: .body_type = Rigidbody::BodyType::STATIC, - .offset = {0, 0}, }); // Create a box with an inner size of 10x10 units world.add_component<BoxCollider>(vec2{100, 100}, vec2{0, -100}); // Top @@ -81,8 +80,7 @@ public: .body_type = Rigidbody::BodyType::DYNAMIC, .linear_velocity = {0, 0}, .constraints = {0, 0, 0}, - .elastisity_coefficient = 1, - .offset = {0, 0}, + .elasticity_coefficient = 1, .collision_layers = {0}, }); game_object1.add_component<BoxCollider>(vec2{10, 10}, vec2{0, 0}); @@ -97,8 +95,7 @@ public: .body_type = Rigidbody::BodyType::DYNAMIC, .linear_velocity = {0, 0}, .constraints = {0, 0, 0}, - .elastisity_coefficient = 1, - .offset = {0, 0}, + .elasticity_coefficient = 1, .collision_layers = {0}, }); game_object2.add_component<BoxCollider>(vec2{10, 10}, vec2{0, 0}); @@ -116,11 +113,11 @@ TEST_F(CollisionTest, collision_example) { bool collision_happend = false; 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.self.transform.game_object_id, 1); }; 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.self.transform.game_object_id, 2); }; EXPECT_FALSE(collision_happend); collision_sys.fixed_update(); @@ -131,16 +128,16 @@ TEST_F(CollisionTest, collision_box_box_dynamic_both_no_velocity) { bool collision_happend = false; 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.self.transform.game_object_id, 1); EXPECT_EQ(ev.info.resolution.x, 10); EXPECT_EQ(ev.info.resolution.y, 10); EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::BOTH); }; 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, 10); - EXPECT_EQ(ev.info.resolution.y, 10); + EXPECT_EQ(ev.info.self.transform.game_object_id, 2); + EXPECT_EQ(ev.info.resolution.x, -10); + EXPECT_EQ(ev.info.resolution.y, -10); EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::BOTH); }; EXPECT_FALSE(collision_happend); @@ -154,7 +151,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_x_direction_no_velocity) { bool collision_happend = false; 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.self.transform.game_object_id, 1); EXPECT_EQ(ev.info.resolution.x, -5); EXPECT_EQ(ev.info.resolution.y, 0); EXPECT_EQ(ev.info.resolution_direction, @@ -162,7 +159,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_x_direction_no_velocity) { }; 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.self.transform.game_object_id, 2); EXPECT_EQ(ev.info.resolution.x, 5); EXPECT_EQ(ev.info.resolution.y, 0); EXPECT_EQ(ev.info.resolution_direction, @@ -179,7 +176,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_y_direction_no_velocity) { bool collision_happend = false; 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.self.transform.game_object_id, 1); EXPECT_EQ(ev.info.resolution.x, 0); EXPECT_EQ(ev.info.resolution.y, -5); EXPECT_EQ(ev.info.resolution_direction, @@ -187,7 +184,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_y_direction_no_velocity) { }; 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.self.transform.game_object_id, 2); EXPECT_EQ(ev.info.resolution.x, 0); EXPECT_EQ(ev.info.resolution.y, 5); EXPECT_EQ(ev.info.resolution_direction, @@ -204,16 +201,16 @@ TEST_F(CollisionTest, collision_box_box_dynamic_both) { bool collision_happend = false; 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.self.transform.game_object_id, 1); EXPECT_EQ(ev.info.resolution.x, 10); EXPECT_EQ(ev.info.resolution.y, 10); EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::BOTH); }; 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, 10); - EXPECT_EQ(ev.info.resolution.y, 10); + EXPECT_EQ(ev.info.self.transform.game_object_id, 2); + EXPECT_EQ(ev.info.resolution.x, -10); + EXPECT_EQ(ev.info.resolution.y, -10); EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::BOTH); }; EXPECT_FALSE(collision_happend); @@ -231,7 +228,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_x_direction) { bool collision_happend = false; 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.self.transform.game_object_id, 1); EXPECT_EQ(ev.info.resolution.x, -5); EXPECT_EQ(ev.info.resolution.y, 5); EXPECT_EQ(ev.info.resolution_direction, @@ -239,7 +236,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_x_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.self.transform.game_object_id, 2); EXPECT_EQ(ev.info.resolution.x, 5); EXPECT_EQ(ev.info.resolution.y, -5); EXPECT_EQ(ev.info.resolution_direction, @@ -260,7 +257,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_y_direction) { bool collision_happend = false; 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.self.transform.game_object_id, 1); EXPECT_EQ(ev.info.resolution.x, 5); EXPECT_EQ(ev.info.resolution.y, -5); EXPECT_EQ(ev.info.resolution_direction, @@ -268,7 +265,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.self.transform.game_object_id, 2); EXPECT_EQ(ev.info.resolution.x, -5); EXPECT_EQ(ev.info.resolution.y, 5); EXPECT_EQ(ev.info.resolution_direction, @@ -289,15 +286,13 @@ TEST_F(CollisionTest, collision_box_box_static_both) { bool collision_happend = false; 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.self.transform.game_object_id, 1); EXPECT_EQ(ev.info.resolution.x, 10); EXPECT_EQ(ev.info.resolution.y, 10); EXPECT_EQ(ev.info.resolution_direction, crepe::CollisionSystem::Direction::BOTH); }; - script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { - // is static should not be called - FAIL(); - }; + script_object2_ref->test_fn + = [&collision_happend](const CollisionEvent & ev) { collision_happend = true; }; EXPECT_FALSE(collision_happend); Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get(); tf.position = {50, 30}; @@ -311,7 +306,7 @@ TEST_F(CollisionTest, collision_box_box_static_x_direction) { bool collision_happend = false; 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.self.transform.game_object_id, 1); EXPECT_EQ(ev.info.resolution.x, -5); EXPECT_EQ(ev.info.resolution.y, 5); EXPECT_EQ(ev.info.resolution_direction, @@ -319,7 +314,7 @@ TEST_F(CollisionTest, collision_box_box_static_x_direction) { }; script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { // is static should not be called - FAIL(); + //FAIL(); }; EXPECT_FALSE(collision_happend); Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get(); @@ -336,7 +331,7 @@ TEST_F(CollisionTest, collision_box_box_static_y_direction) { bool collision_happend = false; 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.self.transform.game_object_id, 1); EXPECT_EQ(ev.info.resolution.x, 5); EXPECT_EQ(ev.info.resolution.y, -5); EXPECT_EQ(ev.info.resolution_direction, @@ -344,7 +339,7 @@ TEST_F(CollisionTest, collision_box_box_static_y_direction) { }; script_object2_ref->test_fn = [&collision_happend](const CollisionEvent & ev) { // is static should not be called - FAIL(); + //FAIL(); }; EXPECT_FALSE(collision_happend); Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get(); @@ -356,37 +351,3 @@ TEST_F(CollisionTest, collision_box_box_static_y_direction) { collision_sys.fixed_update(); EXPECT_TRUE(collision_happend); } - -TEST_F(CollisionTest, collision_box_box_static_multiple) { //todo check visually - bool collision_happend = false; - float offset_value = 0; - float resolution = 0; - script_object1_ref->test_fn = [&](const CollisionEvent & ev) { - collision_happend = true; - EXPECT_EQ(ev.info.this_collider.game_object_id, 1); - EXPECT_EQ(ev.info.this_collider.offset.x, offset_value); - EXPECT_EQ(ev.info.resolution.x, resolution); - }; - script_object2_ref->test_fn = [&](const CollisionEvent & ev) { - // is static should not be called - FAIL(); - }; - EXPECT_FALSE(collision_happend); - Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get(); - tf.position = {45, 30}; - Rigidbody & rg1 = this->mgr.get_components_by_id<Rigidbody>(1).front().get(); - rg1.data.linear_velocity = {10, 10}; - Rigidbody & rg2 = this->mgr.get_components_by_id<Rigidbody>(2).front().get(); - rg2.data.body_type = crepe::Rigidbody::BodyType::STATIC; - BoxCollider & bxc = this->mgr.get_components_by_id<BoxCollider>(1).front().get(); - bxc.offset = {5, 0}; - this->game_object1.add_component<BoxCollider>(vec2{-5, 0}, vec2{10, 10}); - offset_value = 5; - resolution = 10; - collision_sys.fixed_update(); - offset_value = -5; - resolution = 10; - tf.position = {55, 30}; - collision_sys.fixed_update(); - EXPECT_TRUE(collision_happend); -} diff --git a/src/test/Profiling.cpp b/src/test/Profiling.cpp index f988700..d1da5a0 100644 --- a/src/test/Profiling.cpp +++ b/src/test/Profiling.cpp @@ -32,7 +32,7 @@ using namespace testing; class TestScript : public Script { bool oncollision(const CollisionEvent & test) { - Log::logf("Box {} script on_collision()", test.info.this_collider.game_object_id); + Log::logf("Box {} script on_collision()", test.info.self.transform.game_object_id); return true; } void init() { @@ -50,7 +50,7 @@ public: // Minimum amount to let test pass const int min_gameobject_count = 100; // Maximum amount to stop test - const int max_gameobject_count = 150; + const int max_gameobject_count = 3000; // Amount of times a test runs to calculate average const int average = 5; // Maximum duration to stop test @@ -61,6 +61,8 @@ public: ResourceManager resman{m}; ComponentManager mgr{m}; // Add system used for profling tests + EventManager evmgr{m}; + LoopTimerManager loopmgr{m}; CollisionSystem collision_sys{m}; PhysicsSystem physics_sys{m}; ParticleSystem particle_sys{m}; |