aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJAROWMR <jarorutjes07@gmail.com>2024-11-10 18:30:10 +0100
committerJAROWMR <jarorutjes07@gmail.com>2024-11-10 18:30:10 +0100
commit0006e959643f0150acd230b174287a85d4cb3255 (patch)
tree533780aa22de1e1768a22224e4626107ef71a62b /src
parent08d48aabac838a641ef918da92d9827b214e5da6 (diff)
added forward declaration and const reference sprite
Diffstat (limited to 'src')
-rw-r--r--src/crepe/api/ParticleEmitter.h6
-rw-r--r--src/crepe/system/ParticleSystem.cpp1
-rw-r--r--src/crepe/system/ParticleSystem.h4
-rw-r--r--src/test/ParticleTest.cpp22
4 files changed, 22 insertions, 11 deletions
diff --git a/src/crepe/api/ParticleEmitter.h b/src/crepe/api/ParticleEmitter.h
index 2cda1bb..e81ed3b 100644
--- a/src/crepe/api/ParticleEmitter.h
+++ b/src/crepe/api/ParticleEmitter.h
@@ -5,9 +5,9 @@
#include "Component.h"
#include "Particle.h"
-#include "Transform.h"
+#include "Sprite.h"
-class Sprite;
+// class Sprite;
namespace crepe {
@@ -70,7 +70,7 @@ public:
//! collection of particles
std::vector<Particle> particles;
//! sprite reference
- const Sprite* sprite;
+ const Sprite& sprite;
};
public:
/**
diff --git a/src/crepe/system/ParticleSystem.cpp b/src/crepe/system/ParticleSystem.cpp
index 33027f8..ad6699b 100644
--- a/src/crepe/system/ParticleSystem.cpp
+++ b/src/crepe/system/ParticleSystem.cpp
@@ -4,6 +4,7 @@
#include "api/ParticleEmitter.h"
#include "api/Vector2.h"
+#include "api/Transform.h"
#include "ComponentManager.h"
#include "ParticleSystem.h"
diff --git a/src/crepe/system/ParticleSystem.h b/src/crepe/system/ParticleSystem.h
index df89ed9..023a886 100644
--- a/src/crepe/system/ParticleSystem.h
+++ b/src/crepe/system/ParticleSystem.h
@@ -1,9 +1,9 @@
#pragma once
-#include "../api/ParticleEmitter.h"
namespace crepe {
-
+class ParticleEmitter;
+class Transform;
/**
* \brief ParticleSystem class responsible for managing particle emission, updates, and bounds checking.
*/
diff --git a/src/test/ParticleTest.cpp b/src/test/ParticleTest.cpp
index 8c6a7e7..7883eca 100644
--- a/src/test/ParticleTest.cpp
+++ b/src/test/ParticleTest.cpp
@@ -5,25 +5,36 @@
#include <crepe/api/GameObject.h>
#include <crepe/api/Rigidbody.h>
#include <crepe/api/Transform.h>
+#include <crepe/api/ParticleEmitter.h>
+#include <crepe/Particle.h>
#include <crepe/system/ParticleSystem.h>
#include <gtest/gtest.h>
-
+#include <crepe/api/Sprite.h>
using namespace std;
using namespace std::chrono_literals;
using namespace crepe;
+
+
class ParticlesTest : public ::testing::Test {
protected:
- GameObject * game_object;
ParticleSystem particle_system;
void SetUp() override {
ComponentManager & mgr = ComponentManager::get_instance();
std::vector<std::reference_wrapper<Transform>> transforms
= mgr.get_components_by_id<Transform>(0);
if (transforms.empty()) {
- game_object = new GameObject(0, "", "", Vector2{0, 0}, 0, 0);
- game_object->add_component<ParticleEmitter>(ParticleEmitter::Data{
+
+
+ GameObject game_object(0, "", "", Vector2{0, 0}, 0, 0);
+
+ Color color(0, 0, 0, 0);
+ Sprite test_sprite = game_object.add_component<Sprite>(
+ make_shared<Texture>("../asset/texture/img.png"), color,
+ FlipSettings{true, true});
+
+ game_object.add_component<ParticleEmitter>(ParticleEmitter::Data{
.position = {0,0},
.max_particles = 100,
.emission_rate = 0,
@@ -40,7 +51,7 @@ protected:
.offset = Vector2{0,0},
.reset_on_exit = false,
},
- .sprite = nullptr,
+ .sprite = test_sprite,
});
}
transforms = mgr.get_components_by_id<Transform>(0);
@@ -61,7 +72,6 @@ protected:
emitter.data.end_lifespan = 0;
emitter.data.force_over_time = Vector2{0, 0};
emitter.data.boundary = {0, 0, Vector2{0, 0}, false};
- emitter.data.sprite = nullptr;
for (auto& particle : emitter.data.particles) {
particle.active = false;
}