aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-12-17 14:06:02 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-12-17 14:06:02 +0100
commitc00c83ee9982a7decda341ace95303f131d1b5c0 (patch)
tree097a81e7d5a7857e22e737a27de5481fd0e6c260 /src/test
parentcc2ec343367ebaa3b6a6142532f7a067c3c981a1 (diff)
parent20d19e3c714d3e8ca3e35c170c07c563ecc719bb (diff)
Merge branch 'jaro/particle-system-improvement' of github.com:lonkaars/crepe
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ParticleTest.cpp98
-rw-r--r--src/test/Profiling.cpp7
2 files changed, 55 insertions, 50 deletions
diff --git a/src/test/ParticleTest.cpp b/src/test/ParticleTest.cpp
index 9112a3f..9263e00 100644
--- a/src/test/ParticleTest.cpp
+++ b/src/test/ParticleTest.cpp
@@ -1,15 +1,18 @@
#include "api/Asset.h"
-#include <crepe/Particle.h>
#include <crepe/api/Config.h>
#include <crepe/api/GameObject.h>
-#include <crepe/api/ParticleEmitter.h>
#include <crepe/api/Rigidbody.h>
#include <crepe/api/Sprite.h>
#include <crepe/api/Transform.h>
#include <crepe/manager/ComponentManager.h>
-#include <crepe/system/ParticleSystem.h>
+#include <crepe/manager/LoopTimerManager.h>
#include <gtest/gtest.h>
#include <math.h>
+#define protected public
+#define private public
+#include <crepe/Particle.h>
+#include <crepe/api/ParticleEmitter.h>
+#include <crepe/system/ParticleSystem.h>
using namespace std;
using namespace std::chrono_literals;
@@ -21,6 +24,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;
@@ -38,25 +42,25 @@ public:
.size = {10, 10},
});
- game_object.add_component<ParticleEmitter>(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,
- },
- .sprite = test_sprite,
- });
+ game_object.add_component<ParticleEmitter>(test_sprite,
+ ParticleEmitter::Data{
+ .offset = {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<Transform>(0);
Transform & transform = transforms.front().get();
@@ -66,7 +70,7 @@ public:
std::vector<std::reference_wrapper<ParticleEmitter>> rigidbodies
= mgr.get_components_by_id<ParticleEmitter>(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;
@@ -76,7 +80,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 +99,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);
- emitter.data.emission_rate = 1;
+ EXPECT_EQ(emitter.particles[0].active, false);
+ emitter.data.emission_rate = 50;
//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
@@ -133,13 +137,13 @@ 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.data.particles[0].position.x, a);
+ EXPECT_EQ(emitter.particles[0].position.x, a);
}
}
@@ -150,14 +154,14 @@ 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.data.particles[0].position.y, a);
+ EXPECT_EQ(emitter.particles[0].position.y, a);
}
}
@@ -177,7 +181,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 +201,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),
- emitter.data.boundary.width / 2, TOLERANCE);
+ if (emitter.particles[0].velocity.y != 0)
+ EXPECT_NEAR(std::abs(emitter.particles[0].position.y), emitter.data.boundary.width / 2,
+ TOLERANCE);
}
diff --git a/src/test/Profiling.cpp b/src/test/Profiling.cpp
index 35f52dc..1585061 100644
--- a/src/test/Profiling.cpp
+++ b/src/test/Profiling.cpp
@@ -219,7 +219,7 @@ TEST_F(DISABLED_ProfilingTest, Profiling_3) {
.order_in_layer = 1,
.size = {.y = 500},
});
- auto & test = gameobject.add_component<ParticleEmitter>(ParticleEmitter::Data{
+ auto & test = gameobject.add_component<ParticleEmitter>(test_sprite,ParticleEmitter::Data{
.max_particles = 10,
.emission_rate = 100,
.end_lifespan = 100000,
@@ -229,8 +229,9 @@ TEST_F(DISABLED_ProfilingTest, Profiling_3) {
.offset = vec2{0, 0},
.reset_on_exit = false,
},
- .sprite = test_sprite,
- });
+
+ }
+ );
}
render_sys.update();
this->game_object_count++;