diff options
author | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-12-02 21:17:12 +0100 |
---|---|---|
committer | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-12-02 21:17:12 +0100 |
commit | 9f243b9a7a19cc626e787cd71c83e3c3225018b9 (patch) | |
tree | 3ab8ff5316147c1e59601d2fd754f34390ae9515 /src | |
parent | 900cfa9f31de40308b9ea3d0c73372d44f11094c (diff) |
made the test work with the adjustments
Diffstat (limited to 'src')
-rw-r--r-- | src/test/ParticleTest.cpp | 6 | ||||
-rw-r--r-- | src/test/RenderSystemTest.cpp | 132 |
2 files changed, 89 insertions, 49 deletions
diff --git a/src/test/ParticleTest.cpp b/src/test/ParticleTest.cpp index 976f9a1..3cfc466 100644 --- a/src/test/ParticleTest.cpp +++ b/src/test/ParticleTest.cpp @@ -30,7 +30,11 @@ public: Color color(0, 0, 0, 0); auto s1 = Texture("asset/texture/img.png"); Sprite & test_sprite = game_object.add_component<Sprite>( - s1, color, Sprite::FlipSettings{true, true}, 1, 1, 100); + s1, Sprite::Data{ + .color = color, + .flip = Sprite::FlipSettings{true, true}, + .size = {10, 10}, + }); game_object.add_component<ParticleEmitter>(ParticleEmitter::Data{ .position = {0, 0}, diff --git a/src/test/RenderSystemTest.cpp b/src/test/RenderSystemTest.cpp index bb5b81a..bfb761d 100644 --- a/src/test/RenderSystemTest.cpp +++ b/src/test/RenderSystemTest.cpp @@ -34,28 +34,50 @@ public: auto s2 = Texture("asset/texture/img.png"); auto s3 = Texture("asset/texture/img.png"); auto s4 = Texture("asset/texture/img.png"); - auto & sprite1 = entity1.add_component<Sprite>( - s1, Color(0, 0, 0, 0), Sprite::FlipSettings{false, false}, 5, 5, 100); - ASSERT_NE(sprite1.sprite_image.texture.get(), nullptr); - EXPECT_EQ(sprite1.order_in_layer, 5); - EXPECT_EQ(sprite1.sorting_in_layer, 5); - auto & sprite2 = entity2.add_component<Sprite>( - s2, Color(0, 0, 0, 0), Sprite::FlipSettings{false, false}, 2, 1, 100); - ASSERT_NE(sprite2.sprite_image.texture.get(), nullptr); - EXPECT_EQ(sprite2.sorting_in_layer, 2); - EXPECT_EQ(sprite2.order_in_layer, 1); - - auto & sprite3 = entity3.add_component<Sprite>( - s3, Color(0, 0, 0, 0), Sprite::FlipSettings{false, false}, 1, 2, 100); - ASSERT_NE(sprite3.sprite_image.texture.get(), nullptr); - EXPECT_EQ(sprite3.sorting_in_layer, 1); - EXPECT_EQ(sprite3.order_in_layer, 2); - - auto & sprite4 = entity4.add_component<Sprite>( - s4, Color(0, 0, 0, 0), Sprite::FlipSettings{false, false}, 1, 1, 100); - ASSERT_NE(sprite4.sprite_image.texture.get(), nullptr); - EXPECT_EQ(sprite4.sorting_in_layer, 1); - EXPECT_EQ(sprite4.order_in_layer, 1); + auto & sprite1 + = entity1.add_component<Sprite>(s1, Sprite::Data{ + .color = Color(0, 0, 0, 0), + .flip = Sprite::FlipSettings{false, false}, + .sorting_in_layer = 5, + .order_in_layer = 5, + .size = {10, 10}, + }); + + ASSERT_NE(sprite1.texture.texture.get(), nullptr); + EXPECT_EQ(sprite1.data.order_in_layer, 5); + EXPECT_EQ(sprite1.data.sorting_in_layer, 5); + auto & sprite2 + = entity2.add_component<Sprite>(s2, Sprite::Data{ + .color = Color(0, 0, 0, 0), + .flip = Sprite::FlipSettings{false, false}, + .sorting_in_layer = 2, + .order_in_layer = 1, + }); + ASSERT_NE(sprite2.texture.texture.get(), nullptr); + EXPECT_EQ(sprite2.data.sorting_in_layer, 2); + EXPECT_EQ(sprite2.data.order_in_layer, 1); + + auto & sprite3 + = entity3.add_component<Sprite>(s3, Sprite::Data{ + .color = Color(0, 0, 0, 0), + .flip = Sprite::FlipSettings{false, false}, + .sorting_in_layer = 1, + .order_in_layer = 2, + }); + ASSERT_NE(sprite3.texture.texture.get(), nullptr); + EXPECT_EQ(sprite3.data.sorting_in_layer, 1); + EXPECT_EQ(sprite3.data.order_in_layer, 2); + + auto & sprite4 + = entity4.add_component<Sprite>(s4, Sprite::Data{ + .color = Color(0, 0, 0, 0), + .flip = Sprite::FlipSettings{false, false}, + .sorting_in_layer = 1, + .order_in_layer = 1, + }); + ASSERT_NE(sprite4.texture.texture.get(), nullptr); + EXPECT_EQ(sprite4.data.sorting_in_layer, 1); + EXPECT_EQ(sprite4.data.order_in_layer, 1); } }; @@ -65,8 +87,13 @@ TEST_F(RenderSystemTest, expected_throws) { // no texture img EXPECT_ANY_THROW({ auto test = Texture(""); - entity1.add_component<Sprite>(test, Color(0, 0, 0, 0), - Sprite::FlipSettings{false, false}, 1, 1, 100); + auto & sprite1 = entity1.add_component<Sprite>( + test, Sprite::Data{ + .color = Color(0, 0, 0, 0), + .flip = Sprite::FlipSettings{false, false}, + .sorting_in_layer = 1, + .order_in_layer = 1, + }); }); // No camera @@ -88,32 +115,35 @@ TEST_F(RenderSystemTest, sorting_sprites) { // 3. sorting_in_layer: 2, order_in_layer: 1 (entity2) // 4. sorting_in_layer: 5, order_in_layer: 5 (entity1) - EXPECT_EQ(sorted_sprites[0].get().sorting_in_layer, 1); - EXPECT_EQ(sorted_sprites[0].get().order_in_layer, 1); + EXPECT_EQ(sorted_sprites[0].get().data.sorting_in_layer, 1); + EXPECT_EQ(sorted_sprites[0].get().data.order_in_layer, 1); - EXPECT_EQ(sorted_sprites[1].get().sorting_in_layer, 1); - EXPECT_EQ(sorted_sprites[1].get().order_in_layer, 2); + EXPECT_EQ(sorted_sprites[1].get().data.sorting_in_layer, 1); + EXPECT_EQ(sorted_sprites[1].get().data.order_in_layer, 2); - EXPECT_EQ(sorted_sprites[2].get().sorting_in_layer, 2); - EXPECT_EQ(sorted_sprites[2].get().order_in_layer, 1); + EXPECT_EQ(sorted_sprites[2].get().data.sorting_in_layer, 2); + EXPECT_EQ(sorted_sprites[2].get().data.order_in_layer, 1); - EXPECT_EQ(sorted_sprites[3].get().sorting_in_layer, 5); - EXPECT_EQ(sorted_sprites[3].get().order_in_layer, 5); + EXPECT_EQ(sorted_sprites[3].get().data.sorting_in_layer, 5); + EXPECT_EQ(sorted_sprites[3].get().data.order_in_layer, 5); for (size_t i = 1; i < sorted_sprites.size(); ++i) { const Sprite & prev = sorted_sprites[i - 1].get(); const Sprite & curr = sorted_sprites[i].get(); - if (prev.sorting_in_layer == curr.sorting_in_layer) { - EXPECT_LE(prev.order_in_layer, curr.order_in_layer); + if (prev.data.sorting_in_layer == curr.data.sorting_in_layer) { + EXPECT_LE(prev.data.order_in_layer, curr.data.order_in_layer); } else { - EXPECT_LE(prev.sorting_in_layer, curr.sorting_in_layer); + EXPECT_LE(prev.data.sorting_in_layer, curr.data.sorting_in_layer); } } } TEST_F(RenderSystemTest, Update) { - entity1.add_component<Camera>(Color::WHITE, ivec2{1080, 720}, vec2{2000, 2000}, 1.0f); + entity1.add_component<Camera>(Camera::Data{.bg_color = Color::WHITE, + .screen = ivec2{1080, 720}, + .viewport_size = vec2{2000, 2000}, + .zoom = 1.0f}); { vector<reference_wrapper<Sprite>> sprites = this->mgr.get_components_by_type<Sprite>(); ASSERT_EQ(sprites.size(), 4); @@ -141,7 +171,10 @@ TEST_F(RenderSystemTest, Camera) { EXPECT_NE(cameras.size(), 1); } { - entity1.add_component<Camera>(Color::WHITE, ivec2{1080, 720}, vec2{2000, 2000}, 1.0f); + entity1.add_component<Camera>(Camera::Data{.bg_color = Color::WHITE, + .screen = ivec2{1080, 720}, + .viewport_size = vec2{2000, 2000}, + .zoom = 1.0f}); auto cameras = this->mgr.get_components_by_type<Camera>(); EXPECT_EQ(cameras.size(), 1); } @@ -149,18 +182,21 @@ TEST_F(RenderSystemTest, Camera) { //TODO improve with newer version } TEST_F(RenderSystemTest, Color) { - entity1.add_component<Camera>(Color::WHITE, ivec2{1080, 720}, vec2{2000, 2000}, 1.0f); + entity1.add_component<Camera>(Camera::Data{.bg_color = Color::WHITE, + .screen = ivec2{1080, 720}, + .viewport_size = vec2{2000, 2000}, + .zoom = 1.0f}); auto & sprite = this->mgr.get_components_by_id<Sprite>(entity1.id).front().get(); - ASSERT_NE(sprite.sprite_image.texture.get(), nullptr); + ASSERT_NE(sprite.texture.texture.get(), nullptr); - sprite.color = Color::GREEN; - EXPECT_EQ(sprite.color.r, Color::GREEN.r); - EXPECT_EQ(sprite.color.g, Color::GREEN.g); - EXPECT_EQ(sprite.color.b, Color::GREEN.b); - EXPECT_EQ(sprite.color.a, Color::GREEN.a); + sprite.data.color = Color::GREEN; + EXPECT_EQ(sprite.data.color.r, Color::GREEN.r); + EXPECT_EQ(sprite.data.color.g, Color::GREEN.g); + EXPECT_EQ(sprite.data.color.b, Color::GREEN.b); + EXPECT_EQ(sprite.data.color.a, Color::GREEN.a); this->sys.update(); - EXPECT_EQ(sprite.color.r, Color::GREEN.r); - EXPECT_EQ(sprite.color.g, Color::GREEN.g); - EXPECT_EQ(sprite.color.b, Color::GREEN.b); - EXPECT_EQ(sprite.color.a, Color::GREEN.a); + EXPECT_EQ(sprite.data.color.r, Color::GREEN.r); + EXPECT_EQ(sprite.data.color.g, Color::GREEN.g); + EXPECT_EQ(sprite.data.color.b, Color::GREEN.b); + EXPECT_EQ(sprite.data.color.a, Color::GREEN.a); } |