From d3a04fb1e8b119017375caab74c43674006a7348 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Thu, 12 Dec 2024 22:04:49 +0100 Subject: broken particle test --- src/test/ParticleTest.cpp | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'src/test/ParticleTest.cpp') diff --git a/src/test/ParticleTest.cpp b/src/test/ParticleTest.cpp index 9112a3f..70534f3 100644 --- a/src/test/ParticleTest.cpp +++ b/src/test/ParticleTest.cpp @@ -11,10 +11,14 @@ #include #include +#define protected public +#define private public + using namespace std; using namespace std::chrono_literals; using namespace crepe; + class ParticlesTest : public ::testing::Test { Mediator m; @@ -57,6 +61,7 @@ public: }, .sprite = test_sprite, }); + } transforms = mgr.get_components_by_id(0); Transform & transform = transforms.front().get(); @@ -76,7 +81,7 @@ public: emitter.data.end_lifespan = 0; emitter.data.force_over_time = vec2{0, 0}; emitter.data.boundary = {0, 0, vec2{0, 0}, false}; - for (auto & particle : emitter.data.particles) { + for (auto & particle : emitter.particles) { particle.active = false; } } @@ -95,19 +100,19 @@ TEST_F(ParticlesTest, spawnParticle) { emitter.data.max_angle = 10; particle_system.update(); //check if nothing happend - EXPECT_EQ(emitter.data.particles[0].active, false); + EXPECT_EQ(emitter.particles[0].active, false); emitter.data.emission_rate = 1; //check particle spawnes particle_system.update(); - EXPECT_EQ(emitter.data.particles[0].active, true); + EXPECT_EQ(emitter.particles[0].active, true); particle_system.update(); - EXPECT_EQ(emitter.data.particles[1].active, true); + EXPECT_EQ(emitter.particles[1].active, true); particle_system.update(); - EXPECT_EQ(emitter.data.particles[2].active, true); + EXPECT_EQ(emitter.particles[2].active, true); particle_system.update(); - EXPECT_EQ(emitter.data.particles[3].active, true); + EXPECT_EQ(emitter.particles[3].active, true); - for (auto & particle : emitter.data.particles) { + for (auto & particle : emitter.particles) { // Check velocity range EXPECT_GE(particle.velocity.x, emitter.data.min_speed); // Speed should be greater than or equal to min_speed @@ -139,7 +144,7 @@ TEST_F(ParticlesTest, moveParticleHorizontal) { emitter.data.emission_rate = 1; for (int a = 1; a < emitter.data.boundary.width / 2; a++) { particle_system.update(); - EXPECT_EQ(emitter.data.particles[0].position.x, a); + EXPECT_EQ(emitter.particles[0].position.x, a); } } @@ -157,7 +162,7 @@ TEST_F(ParticlesTest, moveParticleVertical) { emitter.data.emission_rate = 1; for (int a = 1; a < emitter.data.boundary.width / 2; a++) { particle_system.update(); - EXPECT_EQ(emitter.data.particles[0].position.y, a); + EXPECT_EQ(emitter.particles[0].position.y, a); } } @@ -177,7 +182,7 @@ TEST_F(ParticlesTest, boundaryParticleReset) { for (int a = 0; a < emitter.data.boundary.width / 2 + 1; a++) { particle_system.update(); } - EXPECT_EQ(emitter.data.particles[0].active, false); + EXPECT_EQ(emitter.particles[0].active, false); } TEST_F(ParticlesTest, boundaryParticleStop) { @@ -197,12 +202,12 @@ TEST_F(ParticlesTest, boundaryParticleStop) { particle_system.update(); } const double TOLERANCE = 0.01; - EXPECT_NEAR(emitter.data.particles[0].velocity.x, 0, TOLERANCE); - EXPECT_NEAR(emitter.data.particles[0].velocity.y, 0, TOLERANCE); - if (emitter.data.particles[0].velocity.x != 0) - EXPECT_NEAR(std::abs(emitter.data.particles[0].position.x), + EXPECT_NEAR(emitter.particles[0].velocity.x, 0, TOLERANCE); + EXPECT_NEAR(emitter.particles[0].velocity.y, 0, TOLERANCE); + if (emitter.particles[0].velocity.x != 0) + EXPECT_NEAR(std::abs(emitter.particles[0].position.x), emitter.data.boundary.height / 2, TOLERANCE); - if (emitter.data.particles[0].velocity.y != 0) - EXPECT_NEAR(std::abs(emitter.data.particles[0].position.y), + if (emitter.particles[0].velocity.y != 0) + EXPECT_NEAR(std::abs(emitter.particles[0].position.y), emitter.data.boundary.width / 2, TOLERANCE); } -- cgit v1.2.3 From 68f7ea611af5b9a4c19375ab3d4a351facdea9a9 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Fri, 13 Dec 2024 18:37:48 +0100 Subject: updated test --- src/test/CMakeLists.txt | 46 +++++++++++++++++++++++----------------------- src/test/ParticleTest.cpp | 31 ++++++++++++++++--------------- 2 files changed, 39 insertions(+), 38 deletions(-) (limited to 'src/test/ParticleTest.cpp') diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 11b4ca9..ed0be5c 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -1,27 +1,27 @@ target_sources(test_main PUBLIC main.cpp - CollisionTest.cpp - PhysicsTest.cpp - ScriptTest.cpp + # CollisionTest.cpp + # PhysicsTest.cpp + # ScriptTest.cpp ParticleTest.cpp - AudioTest.cpp - AssetTest.cpp - ResourceManagerTest.cpp - OptionalRefTest.cpp - RenderSystemTest.cpp - EventTest.cpp - ECSTest.cpp - SceneManagerTest.cpp - ValueBrokerTest.cpp - DBTest.cpp - Vector2Test.cpp - LoopManagerTest.cpp - LoopTimerTest.cpp - InputTest.cpp - ScriptEventTest.cpp - ScriptSceneTest.cpp - Profiling.cpp - SaveManagerTest.cpp - ScriptSaveManagerTest.cpp - ScriptECSTest.cpp + # AudioTest.cpp + # AssetTest.cpp + # ResourceManagerTest.cpp + # OptionalRefTest.cpp + # RenderSystemTest.cpp + # EventTest.cpp + # ECSTest.cpp + # SceneManagerTest.cpp + # ValueBrokerTest.cpp + # DBTest.cpp + # Vector2Test.cpp + # LoopManagerTest.cpp + # LoopTimerTest.cpp + # InputTest.cpp + # ScriptEventTest.cpp + # ScriptSceneTest.cpp + # Profiling.cpp + # SaveManagerTest.cpp + # ScriptSaveManagerTest.cpp + # ScriptECSTest.cpp ) diff --git a/src/test/ParticleTest.cpp b/src/test/ParticleTest.cpp index 70534f3..a9a26c6 100644 --- a/src/test/ParticleTest.cpp +++ b/src/test/ParticleTest.cpp @@ -1,18 +1,19 @@ #include "api/Asset.h" -#include +#include +#include #include #include -#include #include #include #include #include -#include -#include -#include - +#include #define protected public #define private public +#include +#include +#include + using namespace std; using namespace std::chrono_literals; @@ -25,6 +26,7 @@ class ParticlesTest : public ::testing::Test { public: ComponentManager component_manager{m}; ParticleSystem particle_system{m}; + LoopTimerManager loop_timer{m}; void SetUp() override { ComponentManager & mgr = this->component_manager; @@ -42,7 +44,7 @@ public: .size = {10, 10}, }); - game_object.add_component(ParticleEmitter::Data{ + game_object.add_component(test_sprite,ParticleEmitter::Data{ .position = {0, 0}, .max_particles = 100, .emission_rate = 0, @@ -59,7 +61,6 @@ public: .offset = vec2{0, 0}, .reset_on_exit = false, }, - .sprite = test_sprite, }); } @@ -101,7 +102,7 @@ TEST_F(ParticlesTest, spawnParticle) { particle_system.update(); //check if nothing happend EXPECT_EQ(emitter.particles[0].active, false); - emitter.data.emission_rate = 1; + emitter.data.emission_rate = 50; //check particle spawnes particle_system.update(); EXPECT_EQ(emitter.particles[0].active, true); @@ -138,10 +139,10 @@ TEST_F(ParticlesTest, moveParticleHorizontal) { emitter.data.end_lifespan = 100; emitter.data.boundary.height = 100; emitter.data.boundary.width = 100; - emitter.data.min_speed = 1; - emitter.data.max_speed = 1; + emitter.data.min_speed = 50; + emitter.data.max_speed = 50; emitter.data.max_angle = 0; - emitter.data.emission_rate = 1; + emitter.data.emission_rate = 50; for (int a = 1; a < emitter.data.boundary.width / 2; a++) { particle_system.update(); EXPECT_EQ(emitter.particles[0].position.x, a); @@ -155,11 +156,11 @@ TEST_F(ParticlesTest, moveParticleVertical) { emitter.data.end_lifespan = 100; emitter.data.boundary.height = 100; emitter.data.boundary.width = 100; - emitter.data.min_speed = 1; - emitter.data.max_speed = 1; + emitter.data.min_speed = 50; + emitter.data.max_speed = 50; emitter.data.min_angle = 90; emitter.data.max_angle = 90; - emitter.data.emission_rate = 1; + emitter.data.emission_rate = 50; for (int a = 1; a < emitter.data.boundary.width / 2; a++) { particle_system.update(); EXPECT_EQ(emitter.particles[0].position.y, a); -- cgit v1.2.3 From 512aa7f54b88994d3095971b2001930b4e612947 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Fri, 13 Dec 2024 20:44:32 +0100 Subject: make format --- src/crepe/Particle.h | 3 ++- src/crepe/api/ParticleEmitter.cpp | 6 +++-- src/crepe/api/ParticleEmitter.h | 5 ++-- src/crepe/system/ParticleSystem.cpp | 10 ++++---- src/crepe/system/ParticleSystem.h | 1 - src/example/game.cpp | 31 ++++++++++++------------ src/example/rendering_particle.cpp | 1 - src/test/ParticleTest.cpp | 48 ++++++++++++++++++------------------- 8 files changed, 53 insertions(+), 52 deletions(-) (limited to 'src/test/ParticleTest.cpp') diff --git a/src/crepe/Particle.h b/src/crepe/Particle.h index 0170117..ee0cd66 100644 --- a/src/crepe/Particle.h +++ b/src/crepe/Particle.h @@ -41,7 +41,8 @@ public: * \param velocity The initial velocity of the particle. * \param angle The angle of the particle's trajectory or orientation. */ - void reset(unsigned int lifespan, const vec2 & position, const vec2 & velocity, float angle); + void reset(unsigned int lifespan, const vec2 & position, const vec2 & velocity, + float angle); /** * \brief Updates the particle's state. * diff --git a/src/crepe/api/ParticleEmitter.cpp b/src/crepe/api/ParticleEmitter.cpp index 1e9cfaa..4f54bbd 100644 --- a/src/crepe/api/ParticleEmitter.cpp +++ b/src/crepe/api/ParticleEmitter.cpp @@ -3,9 +3,11 @@ using namespace crepe; -ParticleEmitter::ParticleEmitter(game_object_id_t game_object_id, const Sprite & sprite, const Data & data) +ParticleEmitter::ParticleEmitter(game_object_id_t game_object_id, const Sprite & sprite, + const Data & data) : Component(game_object_id), - sprite(sprite), data(data) { + sprite(sprite), + data(data) { for (size_t i = 0; i < this->data.max_particles; i++) { this->particles.emplace_back(); } diff --git a/src/crepe/api/ParticleEmitter.h b/src/crepe/api/ParticleEmitter.h index 5b8e8e3..be970f5 100644 --- a/src/crepe/api/ParticleEmitter.h +++ b/src/crepe/api/ParticleEmitter.h @@ -78,18 +78,19 @@ public: * \param game_object_id Identifier for the game object using this emitter. * \param data Configuration data defining particle properties. */ - ParticleEmitter(game_object_id_t game_object_id, const Sprite & sprite,const Data & data); + ParticleEmitter(game_object_id_t game_object_id, const Sprite & sprite, const Data & data); public: //! Configuration data for particle emission settings. Data data; + private: //! Only ParticleSystem can move and read particles friend ParticleSystem; //! Only RenderSystem can read particles friend RenderSystem; //! Saves time left over from last update event. - float spawn_accumulator = 0; + float spawn_accumulator = 0; //! collection of particles std::vector particles; }; diff --git a/src/crepe/system/ParticleSystem.cpp b/src/crepe/system/ParticleSystem.cpp index f98f245..31a4e9e 100644 --- a/src/crepe/system/ParticleSystem.cpp +++ b/src/crepe/system/ParticleSystem.cpp @@ -31,8 +31,8 @@ void ParticleSystem::update() { while (emitter.spawn_accumulator >= 1.0) { this->emit_particle(emitter, transform); emitter.spawn_accumulator -= 1.0; - } - + } + // Update all particles for (Particle & particle : emitter.particles) { if (particle.active) { @@ -49,9 +49,11 @@ void ParticleSystem::emit_particle(ParticleEmitter & emitter, const Transform & constexpr float DEG_TO_RAD = M_PI / 180.0; vec2 initial_position = emitter.data.position + transform.position; - float random_angle = this->generate_random_angle(emitter.data.min_angle, emitter.data.max_angle); + float random_angle + = this->generate_random_angle(emitter.data.min_angle, emitter.data.max_angle); - float random_speed = this->generate_random_speed(emitter.data.min_speed, emitter.data.max_speed); + float random_speed + = this->generate_random_speed(emitter.data.min_speed, emitter.data.max_speed); float angle_radians = random_angle * DEG_TO_RAD; vec2 velocity diff --git a/src/crepe/system/ParticleSystem.h b/src/crepe/system/ParticleSystem.h index 95a2bd5..154521d 100644 --- a/src/crepe/system/ParticleSystem.h +++ b/src/crepe/system/ParticleSystem.h @@ -23,7 +23,6 @@ public: void update() override; private: - /** * \brief Emits a particle from the specified emitter based on its emission properties. * diff --git a/src/example/game.cpp b/src/example/game.cpp index 279648e..2d25153 100644 --- a/src/example/game.cpp +++ b/src/example/game.cpp @@ -261,24 +261,23 @@ public: = false; Asset img5{"asset/texture/square.png"}; - - GameObject particle = mgr.new_object( "Name", "Tag", vec2{screen_size_width / 2, screen_size_height / 2}, 0, 1); - auto & particle_image = particle.add_component(img5, Sprite::Data{.size = {5, 5},}); - auto & test = particle.add_component(particle_image,ParticleEmitter::Data{ - .position = {0, 0}, - .max_particles = 256, - .emission_rate = 50, - .min_speed = 10, - .max_speed = 20, - .min_angle = -20, - .max_angle = 20, - .begin_lifespan = 0, - .end_lifespan = 5, - } - ); - + auto & particle_image = particle.add_component(img5, Sprite::Data{ + .size = {5, 5}, + }); + auto & test + = particle.add_component(particle_image, ParticleEmitter::Data{ + .position = {0, 0}, + .max_particles = 256, + .emission_rate = 50, + .min_speed = 10, + .max_speed = 20, + .min_angle = -20, + .max_angle = 20, + .begin_lifespan = 0, + .end_lifespan = 5, + }); } string get_name() const { return "scene1"; } diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp index 2b5c041..add43f4 100644 --- a/src/example/rendering_particle.cpp +++ b/src/example/rendering_particle.cpp @@ -17,7 +17,6 @@ using namespace crepe; using namespace std; - class TestScene : public Scene { public: diff --git a/src/test/ParticleTest.cpp b/src/test/ParticleTest.cpp index a9a26c6..8ffb140 100644 --- a/src/test/ParticleTest.cpp +++ b/src/test/ParticleTest.cpp @@ -1,6 +1,4 @@ #include "api/Asset.h" -#include -#include #include #include #include @@ -8,18 +6,18 @@ #include #include #include +#include +#include #define protected public #define private public #include #include #include - using namespace std; using namespace std::chrono_literals; using namespace crepe; - class ParticlesTest : public ::testing::Test { Mediator m; @@ -44,25 +42,25 @@ public: .size = {10, 10}, }); - game_object.add_component(test_sprite,ParticleEmitter::Data{ - .position = {0, 0}, - .max_particles = 100, - .emission_rate = 0, - .min_speed = 0, - .max_speed = 0, - .min_angle = 0, - .max_angle = 0, - .begin_lifespan = 0, - .end_lifespan = 0, - .force_over_time = vec2{0, 0}, - .boundary{ - .width = 0, - .height = 0, - .offset = vec2{0, 0}, - .reset_on_exit = false, - }, - }); - + game_object.add_component(test_sprite, + ParticleEmitter::Data{ + .position = {0, 0}, + .max_particles = 100, + .emission_rate = 0, + .min_speed = 0, + .max_speed = 0, + .min_angle = 0, + .max_angle = 0, + .begin_lifespan = 0, + .end_lifespan = 0, + .force_over_time = vec2{0, 0}, + .boundary{ + .width = 0, + .height = 0, + .offset = vec2{0, 0}, + .reset_on_exit = false, + }, + }); } transforms = mgr.get_components_by_id(0); Transform & transform = transforms.front().get(); @@ -209,6 +207,6 @@ TEST_F(ParticlesTest, boundaryParticleStop) { EXPECT_NEAR(std::abs(emitter.particles[0].position.x), emitter.data.boundary.height / 2, TOLERANCE); if (emitter.particles[0].velocity.y != 0) - EXPECT_NEAR(std::abs(emitter.particles[0].position.y), - emitter.data.boundary.width / 2, TOLERANCE); + EXPECT_NEAR(std::abs(emitter.particles[0].position.y), emitter.data.boundary.width / 2, + TOLERANCE); } -- cgit v1.2.3 From 22476a51e00089f8c7b810937250ff4d7a14329e Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Sat, 14 Dec 2024 19:59:32 +0100 Subject: updated test and game.cpp --- src/example/game.cpp | 2 +- src/test/ParticleTest.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/test/ParticleTest.cpp') diff --git a/src/example/game.cpp b/src/example/game.cpp index 7c9a227..ed6afac 100644 --- a/src/example/game.cpp +++ b/src/example/game.cpp @@ -269,7 +269,7 @@ public: }); auto & test = particle.add_component(particle_image, ParticleEmitter::Data{ - .position = {0, 0}, + .offset = {0, 0}, .max_particles = 256, .emission_rate = 50, .min_speed = 10, diff --git a/src/test/ParticleTest.cpp b/src/test/ParticleTest.cpp index 8ffb140..9263e00 100644 --- a/src/test/ParticleTest.cpp +++ b/src/test/ParticleTest.cpp @@ -44,7 +44,7 @@ public: game_object.add_component(test_sprite, ParticleEmitter::Data{ - .position = {0, 0}, + .offset = {0, 0}, .max_particles = 100, .emission_rate = 0, .min_speed = 0, @@ -70,7 +70,7 @@ public: std::vector> rigidbodies = mgr.get_components_by_id(0); ParticleEmitter & emitter = rigidbodies.front().get(); - emitter.data.position = {0, 0}; + emitter.data.offset = {0, 0}; emitter.data.emission_rate = 0; emitter.data.min_speed = 0; emitter.data.max_speed = 0; -- cgit v1.2.3