From 0006e959643f0150acd230b174287a85d4cb3255 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Sun, 10 Nov 2024 18:30:10 +0100 Subject: added forward declaration and const reference sprite --- src/crepe/api/ParticleEmitter.h | 6 +++--- src/crepe/system/ParticleSystem.cpp | 1 + src/crepe/system/ParticleSystem.h | 4 ++-- src/test/ParticleTest.cpp | 22 ++++++++++++++++------ 4 files changed, 22 insertions(+), 11 deletions(-) (limited to 'src') 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 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 #include #include +#include +#include #include #include - +#include 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> transforms = mgr.get_components_by_id(0); if (transforms.empty()) { - game_object = new GameObject(0, "", "", Vector2{0, 0}, 0, 0); - game_object->add_component(ParticleEmitter::Data{ + + + GameObject game_object(0, "", "", Vector2{0, 0}, 0, 0); + + Color color(0, 0, 0, 0); + Sprite test_sprite = game_object.add_component( + make_shared("../asset/texture/img.png"), color, + FlipSettings{true, true}); + + game_object.add_component(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(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; } -- cgit v1.2.3