From 08fee6eff251337dd4dca2b514a9c06d57ede0af Mon Sep 17 00:00:00 2001 From: max-001 Date: Fri, 22 Nov 2024 11:14:13 +0100 Subject: Implemented persistent objects --- src/test/ECSTest.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'src/test/ECSTest.cpp') diff --git a/src/test/ECSTest.cpp b/src/test/ECSTest.cpp index d5a5826..e1585bb 100644 --- a/src/test/ECSTest.cpp +++ b/src/test/ECSTest.cpp @@ -234,3 +234,71 @@ TEST_F(ECSTest, partentChild) { EXPECT_EQ(metadata[1].get().children[0], 3); EXPECT_EQ(metadata[2].get().children[0], 4); } + +TEST_F(ECSTest, persistent) { + GameObject obj0 = mgr.new_object("obj0", "obj0", Vector2{0, 0}, 0, 1); + GameObject obj1 = mgr.new_object("obj1", "obj1", Vector2{0, 0}, 0, 1); + obj1.set_persistent(); + GameObject obj2 = mgr.new_object("obj2", "obj2", Vector2{0, 0}, 0, 1); + + vector> metadata = mgr.get_components_by_type(); + vector> transform = mgr.get_components_by_type(); + + EXPECT_EQ(metadata.size(), 3); + EXPECT_EQ(transform.size(), 3); + + mgr.delete_components_by_id(1); + mgr.delete_components(); + mgr.delete_all_components_of_id(1); + + metadata = mgr.get_components_by_type(); + transform = mgr.get_components_by_type(); + + EXPECT_EQ(metadata.size(), 1); + EXPECT_EQ(transform.size(), 3); + + mgr.delete_all_components(); + + metadata = mgr.get_components_by_type(); + transform = mgr.get_components_by_type(); + + EXPECT_EQ(metadata.size(), 1); + EXPECT_EQ(transform.size(), 1); + + EXPECT_EQ(metadata[0].get().game_object_id, 1); + EXPECT_EQ(metadata[0].get().name, "obj1"); + EXPECT_EQ(metadata[0].get().tag, "obj1"); + EXPECT_EQ(metadata[0].get().parent, -1); + EXPECT_EQ(metadata[0].get().children.size(), 0); + + EXPECT_EQ(transform[0].get().game_object_id, 1); + EXPECT_EQ(transform[0].get().position.x, 0); + EXPECT_EQ(transform[0].get().position.y, 0); + + GameObject obj3 = mgr.new_object("obj3", "obj3", Vector2{0, 0}, 0, 5); + GameObject obj4 = mgr.new_object("obj4", "obj4", Vector2{0, 0}, 0, 5); + + metadata = mgr.get_components_by_type(); + transform = mgr.get_components_by_type(); + + EXPECT_EQ(metadata.size(), 3); + EXPECT_EQ(transform.size(), 3); + + EXPECT_EQ(metadata[0].get().game_object_id, 0); + EXPECT_EQ(metadata[0].get().name, "obj3"); + + EXPECT_EQ(metadata[1].get().game_object_id, 1); + EXPECT_EQ(metadata[1].get().name, "obj1"); + + EXPECT_EQ(metadata[2].get().game_object_id, 2); + EXPECT_EQ(metadata[2].get().name, "obj4"); + + EXPECT_EQ(transform[0].get().game_object_id, 0); + EXPECT_EQ(transform[0].get().scale, 5); + + EXPECT_EQ(transform[1].get().game_object_id, 1); + EXPECT_EQ(transform[1].get().scale, 1); + + EXPECT_EQ(transform[2].get().game_object_id, 2); + EXPECT_EQ(transform[2].get().scale, 5); +} -- cgit v1.2.3 From b1caa74439b404e4b3fe911836004dd7cb47dd50 Mon Sep 17 00:00:00 2001 From: max-001 Date: Fri, 22 Nov 2024 11:22:24 +0100 Subject: Extended test --- src/test/ECSTest.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'src/test/ECSTest.cpp') diff --git a/src/test/ECSTest.cpp b/src/test/ECSTest.cpp index e1585bb..e46705c 100644 --- a/src/test/ECSTest.cpp +++ b/src/test/ECSTest.cpp @@ -136,6 +136,53 @@ TEST_F(ECSTest, manyGameObjects) { EXPECT_EQ(metadata.size(), 10000 - 5000); EXPECT_EQ(transform.size(), 10000); + + for (int i = 0; i < 10000 - 5000; i++) { + EXPECT_EQ(metadata[i].get().game_object_id, i + 5000); + EXPECT_EQ(metadata[i].get().name, "body"); + EXPECT_EQ(metadata[i].get().tag, "person" + to_string(i)); + EXPECT_EQ(metadata[i].get().parent, -1); + EXPECT_EQ(metadata[i].get().children.size(), 0); + + EXPECT_EQ(transform[i].get().game_object_id, i); + EXPECT_EQ(transform[i].get().position.x, 0); + EXPECT_EQ(transform[i].get().position.y, 0); + EXPECT_EQ(transform[i].get().rotation, 0); + EXPECT_EQ(transform[i].get().scale, i); + } + + mgr.delete_all_components(); + + metadata = mgr.get_components_by_type(); + transform = mgr.get_components_by_type(); + + EXPECT_EQ(metadata.size(), 0); + EXPECT_EQ(transform.size(), 0); + + for (int i = 0; i < 10000; i++) { + string name = "body" + to_string(i); + GameObject obj = mgr.new_object(name, "person", Vector2{0, 0}, 0, 0); + } + + metadata = mgr.get_components_by_type(); + transform = mgr.get_components_by_type(); + + EXPECT_EQ(metadata.size(), 10000); + EXPECT_EQ(transform.size(), 10000); + + for (int i = 0; i < 10000; i++) { + EXPECT_EQ(metadata[i].get().game_object_id, i); + EXPECT_EQ(metadata[i].get().name, "body" + to_string(i)); + EXPECT_EQ(metadata[i].get().tag, "person"); + EXPECT_EQ(metadata[i].get().parent, -1); + EXPECT_EQ(metadata[i].get().children.size(), 0); + + EXPECT_EQ(transform[i].get().game_object_id, i); + EXPECT_EQ(transform[i].get().position.x, 0); + EXPECT_EQ(transform[i].get().position.y, 0); + EXPECT_EQ(transform[i].get().rotation, 0); + EXPECT_EQ(transform[i].get().scale, 0); + } } TEST_F(ECSTest, getComponentsByID) { -- cgit v1.2.3 From b86f5adb5a266dfd2ef5f7a406c22f286786351d Mon Sep 17 00:00:00 2001 From: max-001 Date: Tue, 26 Nov 2024 09:53:27 +0100 Subject: Added test --- src/test/ECSTest.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/test/ECSTest.cpp') diff --git a/src/test/ECSTest.cpp b/src/test/ECSTest.cpp index 6903731..9dbeee5 100644 --- a/src/test/ECSTest.cpp +++ b/src/test/ECSTest.cpp @@ -349,3 +349,33 @@ TEST_F(ECSTest, persistent) { EXPECT_EQ(transform[2].get().game_object_id, 2); EXPECT_EQ(transform[2].get().scale, 5); } + +TEST_F(ECSTest, resetPersistent) { + GameObject obj0 = mgr.new_object("obj0", "obj0", vec2{0, 0}, 0, 1); + GameObject obj1 = mgr.new_object("obj1", "obj1", vec2{0, 0}, 0, 1); + obj1.set_persistent(); + GameObject obj2 = mgr.new_object("obj2", "obj2", vec2{0, 0}, 0, 1); + + vector> metadata = mgr.get_components_by_type(); + vector> transform = mgr.get_components_by_type(); + + EXPECT_EQ(metadata.size(), 3); + EXPECT_EQ(transform.size(), 3); + + mgr.delete_all_components(); + + metadata = mgr.get_components_by_type(); + transform = mgr.get_components_by_type(); + + EXPECT_EQ(metadata.size(), 1); + EXPECT_EQ(transform.size(), 1); + + mgr.set_persistent(1, false); + mgr.delete_all_components(); + + metadata = mgr.get_components_by_type(); + transform = mgr.get_components_by_type(); + + EXPECT_EQ(metadata.size(), 0); + EXPECT_EQ(transform.size(), 0); +} -- cgit v1.2.3 From ee632145ee5b2c1f49e0f88dbccd3a888cf9ad3c Mon Sep 17 00:00:00 2001 From: max-001 Date: Tue, 26 Nov 2024 10:23:41 +0100 Subject: Improved test --- src/test/ECSTest.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/test/ECSTest.cpp') diff --git a/src/test/ECSTest.cpp b/src/test/ECSTest.cpp index 9dbeee5..af9d6f2 100644 --- a/src/test/ECSTest.cpp +++ b/src/test/ECSTest.cpp @@ -370,6 +370,12 @@ TEST_F(ECSTest, resetPersistent) { EXPECT_EQ(metadata.size(), 1); EXPECT_EQ(transform.size(), 1); + vector> metadata_id = mgr.get_components_by_id(1); + + EXPECT_EQ(metadata_id.size(), 1); + EXPECT_EQ(metadata_id[0].get().game_object_id, 1); + EXPECT_EQ(metadata_id[0].get().name, "obj1"); + mgr.set_persistent(1, false); mgr.delete_all_components(); -- cgit v1.2.3