aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorheavydemon21 <nielsstunnebrink1@gmail.com>2024-11-28 08:51:20 +0100
committerheavydemon21 <nielsstunnebrink1@gmail.com>2024-11-28 08:51:20 +0100
commit5fa57ab2d8f809b8cb6bd72f54567a01f3e63b95 (patch)
treed436ae304ce590b3778b6c8f77ada3596c2a8887 /src
parent87c147dde61e2534d4e66c159a711b0f1ab68b8b (diff)
making test work again
Diffstat (limited to 'src')
-rw-r--r--src/crepe/api/Config.h2
-rw-r--r--src/crepe/api/Vector2.h13
-rw-r--r--src/test/ParticleTest.cpp7
-rw-r--r--src/test/RenderSystemTest.cpp58
4 files changed, 35 insertions, 45 deletions
diff --git a/src/crepe/api/Config.h b/src/crepe/api/Config.h
index 2525120..d73e488 100644
--- a/src/crepe/api/Config.h
+++ b/src/crepe/api/Config.h
@@ -66,7 +66,7 @@ public:
//! default window settings
struct {
//TODO make this constexpr because this will never change
- const ivec2 def_size = {1080, 720};
+ ivec2 def_size = {1080, 720};
} win_set;
//! Asset loading options
diff --git a/src/crepe/api/Vector2.h b/src/crepe/api/Vector2.h
index 2b31d90..c278c87 100644
--- a/src/crepe/api/Vector2.h
+++ b/src/crepe/api/Vector2.h
@@ -31,14 +31,8 @@ struct Vector2 {
//! Divides this vector by another vector element-wise and returns the result.
Vector2 operator/(const Vector2<T> & other) const;
- //! Multiplies this vector by another vector element-wise and updates this vector.
- Vector2 & operator*=(const Vector2<T> & other);
-
- //! Divides a scalar value to both components of this vector and updates this vector.
- Vector2 operator/(const T & other) const;
-
- //! Divides a scalar value to both components of this vector and updates this vector.
- Vector2 operator/(T other) const;
+ //! Divides this vector by a scalar and returns the result.
+ Vector2 operator/(T scalar) const;
//! Adds another vector to this vector and updates this vector.
Vector2 & operator+=(const Vector2<T> & other);
@@ -52,6 +46,9 @@ struct Vector2 {
//! Subtracts a scalar value from both components of this vector and updates this vector.
Vector2 & operator-=(T other);
+ //! Multiplies this vector by another vector element-wise and updates this vector.
+ Vector2 & operator*=(const Vector2<T> & other);
+
//! Multiplies this vector by a scalar and updates this vector.
Vector2 & operator*=(T other);
diff --git a/src/test/ParticleTest.cpp b/src/test/ParticleTest.cpp
index 8b81e74..ea3652a 100644
--- a/src/test/ParticleTest.cpp
+++ b/src/test/ParticleTest.cpp
@@ -1,4 +1,4 @@
-#include "api/Vector2.h"
+#include "api/Texture.h"
#include <crepe/ComponentManager.h>
#include <crepe/Particle.h>
#include <crepe/api/Config.h>
@@ -28,9 +28,10 @@ public:
GameObject game_object = mgr.new_object("", "", vec2{0, 0}, 0, 0);
Color color(0, 0, 0, 0);
+ auto s1 = Texture("asset/texture/img.png");
Sprite & test_sprite = game_object.add_component<Sprite>(
- make_shared<Texture>("asset/texture/img.png"), color,
- FlipSettings{true, true});
+ s1, color,
+ FlipSettings{true, true}, 1,1,100);
game_object.add_component<ParticleEmitter>(ParticleEmitter::Data{
.position = {0, 0},
diff --git a/src/test/RenderSystemTest.cpp b/src/test/RenderSystemTest.cpp
index f37fb56..2c4f21c 100644
--- a/src/test/RenderSystemTest.cpp
+++ b/src/test/RenderSystemTest.cpp
@@ -1,4 +1,4 @@
-#include "api/Camera.h"
+#include "types.h"
#include <functional>
#include <gtest/gtest.h>
#include <memory>
@@ -12,6 +12,7 @@
#include <crepe/api/GameObject.h>
#include <crepe/api/Sprite.h>
#include <crepe/api/Texture.h>
+#include "crepe/api/Camera.h"
#include <crepe/system/RenderSystem.h>
@@ -29,40 +30,30 @@ public:
GameObject entity4 = this->mgr.new_object("name");
void SetUp() override {
- auto & sprite1
- = entity1.add_component<Sprite>(make_shared<Texture>("asset/texture/img.png"),
- Color(0, 0, 0, 0), FlipSettings{false, false});
- ASSERT_NE(sprite1.sprite_image.get(), nullptr);
- sprite1.order_in_layer = 5;
- sprite1.sorting_in_layer = 5;
+ auto s1 = Texture("asset/texture/img.png");
+ 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),
+ 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>(make_shared<Texture>("asset/texture/img.png"),
- Color(0, 0, 0, 0), FlipSettings{false, false});
- ASSERT_NE(sprite2.sprite_image.get(), nullptr);
- sprite2.sorting_in_layer = 2;
- sprite2.order_in_layer = 1;
-
+ auto & sprite2 = entity2.add_component<Sprite>(s2, Color(0, 0, 0, 0),
+ 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>(make_shared<Texture>("asset/texture/img.png"),
- Color(0, 0, 0, 0), FlipSettings{false, false});
- ASSERT_NE(sprite3.sprite_image.get(), nullptr);
- sprite3.sorting_in_layer = 1;
- sprite3.order_in_layer = 2;
-
+ auto & sprite3 = entity3.add_component<Sprite>(s3, Color(0, 0, 0, 0),
+ 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>(make_shared<Texture>("asset/texture/img.png"),
- Color(0, 0, 0, 0), FlipSettings{false, false});
- ASSERT_NE(sprite4.sprite_image.get(), nullptr);
- sprite4.sorting_in_layer = 1;
- sprite4.order_in_layer = 1;
+ auto & sprite4 = entity4.add_component<Sprite>(s4, Color(0, 0, 0, 0),
+ 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);
}
@@ -73,8 +64,9 @@ TEST_F(RenderSystemTest, expected_throws) {
// no texture img
EXPECT_ANY_THROW({
- entity1.add_component<Sprite>(make_shared<Texture>("NO_IMAGE"), Color(0, 0, 0, 0),
- FlipSettings{false, false});
+ auto test = Texture("");
+ entity1.add_component<Sprite>(test, Color(0, 0, 0, 0),
+ FlipSettings{false, false},1,1,100);
});
// No camera
@@ -121,7 +113,7 @@ TEST_F(RenderSystemTest, sorting_sprites) {
}
TEST_F(RenderSystemTest, Update) {
- entity1.add_component<Camera>(Color::WHITE);
+ entity1.add_component<Camera>(Color::WHITE, ivec2{1080, 720}, ivec2{2000, 2000}, 1.0f);
{
vector<reference_wrapper<Sprite>> sprites = this->mgr.get_components_by_type<Sprite>();
ASSERT_EQ(sprites.size(), 4);
@@ -149,7 +141,7 @@ TEST_F(RenderSystemTest, Camera) {
EXPECT_NE(cameras.size(), 1);
}
{
- entity1.add_component<Camera>(Color::WHITE);
+ entity1.add_component<Camera>(Color::WHITE, ivec2{1080, 720}, ivec2{2000, 2000}, 1.0f);
auto cameras = this->mgr.get_components_by_type<Camera>();
EXPECT_EQ(cameras.size(), 1);
}
@@ -157,9 +149,9 @@ TEST_F(RenderSystemTest, Camera) {
//TODO improve with newer version
}
TEST_F(RenderSystemTest, Color) {
- entity1.add_component<Camera>(Color::WHITE);
+ entity1.add_component<Camera>(Color::WHITE, ivec2{1080, 720}, ivec2{2000, 2000}, 1.0f);
auto & sprite = this->mgr.get_components_by_id<Sprite>(entity1.id).front().get();
- ASSERT_NE(sprite.sprite_image.get(), nullptr);
+ ASSERT_NE(sprite.sprite_image.texture.get(), nullptr);
sprite.color = Color::GREEN;
EXPECT_EQ(sprite.color.r, Color::GREEN.r);