From 0d2491e8619ec9012381ed3e39e85e37e0cb7765 Mon Sep 17 00:00:00 2001 From: jaroWMR Date: Wed, 23 Oct 2024 18:42:44 +0200 Subject: moved particleEmitter --- src/crepe/CMakeLists.txt | 2 -- src/crepe/ParticleEmitter.cpp | 28 ---------------------------- src/crepe/ParticleEmitter.h | 32 -------------------------------- src/crepe/ParticleSystem.cpp | 2 +- src/crepe/ParticleSystem.h | 2 +- src/crepe/SDLApp.cpp | 2 +- src/crepe/SDLApp.h | 2 +- src/crepe/api/CMakeLists.txt | 2 ++ src/crepe/api/ParticleEmitter.cpp | 28 ++++++++++++++++++++++++++++ src/crepe/api/ParticleEmitter.h | 32 ++++++++++++++++++++++++++++++++ src/example/particle.cpp | 5 +++-- 11 files changed, 69 insertions(+), 68 deletions(-) delete mode 100644 src/crepe/ParticleEmitter.cpp delete mode 100644 src/crepe/ParticleEmitter.h create mode 100644 src/crepe/api/ParticleEmitter.cpp create mode 100644 src/crepe/api/ParticleEmitter.h diff --git a/src/crepe/CMakeLists.txt b/src/crepe/CMakeLists.txt index 57c77be..2ad20a7 100644 --- a/src/crepe/CMakeLists.txt +++ b/src/crepe/CMakeLists.txt @@ -4,7 +4,6 @@ target_sources(crepe PUBLIC Sound.cpp SoundContext.cpp Particle.cpp - ParticleEmitter.cpp ParticleSystem.cpp SDLApp.cpp ComponentManager.cpp @@ -20,7 +19,6 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES Asset.h Sound.h SoundContext.h - ParticleEmitter.h ParticleSystem.h Particle.h SDLApp.h diff --git a/src/crepe/ParticleEmitter.cpp b/src/crepe/ParticleEmitter.cpp deleted file mode 100644 index 318c6db..0000000 --- a/src/crepe/ParticleEmitter.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "ParticleEmitter.h" -#include -#include "Particle.h" -#include - -using namespace crepe; - -ParticleEmitter::ParticleEmitter(uint32_t gameObjectId ,uint32_t maxParticles, uint32_t emissionRate, uint32_t speed, uint32_t speedOffset, uint32_t angle, uint32_t angleOffset, float m_beginLifespan, float m_endLifespan) - : Component(gameObjectId), m_maxParticles(maxParticles), m_emissionRate(emissionRate), m_speed(speed), m_speedOffset(speedOffset), m_position{0, 0}, m_beginLifespan(m_beginLifespan),m_endLifespan(m_endLifespan) { - std::srand(static_cast(std::time(nullptr))); // initialize random seed - std::cout << "Create emitter" << std::endl; - m_minAngle = (360 + angle - (angleOffset % 360)) % 360; // calculate minAngle - m_maxAngle = (360 + angle + (angleOffset % 360)) % 360; // calculate maxAngle - m_position.x = 400; - m_position.y = 400; - for (size_t i = 0; i < m_maxParticles; i++) - { - this->particles.emplace_back(); - } - -} - -ParticleEmitter::~ParticleEmitter() { - std::vector::iterator it = this->particles.begin(); - while (it != this->particles.end()) { - it = this->particles.erase(it); - } -} diff --git a/src/crepe/ParticleEmitter.h b/src/crepe/ParticleEmitter.h deleted file mode 100644 index 8cd78a9..0000000 --- a/src/crepe/ParticleEmitter.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include -#include "Particle.h" -#include -#include "Component.h" -# - -namespace crepe { - -class ParticleEmitter : public Component { -public: - ParticleEmitter(uint32_t gameObjectId, uint32_t maxParticles, uint32_t emissionRate, uint32_t speed, uint32_t speedOffset, uint32_t angle, uint32_t angleOffset,float m_beginLifespan,float m_endLifespan); - ~ParticleEmitter(); - - Position m_position; //position of the emitter - uint32_t m_maxParticles; //maximum number of particles - uint32_t m_emissionRate; //rate of particle emission - uint32_t m_speed; //base speed of the particles - uint32_t m_speedOffset; //offset for random speed variation - uint32_t m_minAngle; //min angle of particle emission - uint32_t m_maxAngle; //max angle of particle emission - float m_beginLifespan; //begin Lifespan of particle (only visual) - float m_endLifespan; //begin Lifespan of particle - - std::vector particles; //collection of particles - -}; - -} - - diff --git a/src/crepe/ParticleSystem.cpp b/src/crepe/ParticleSystem.cpp index 0dad4cd..bf7f8fc 100644 --- a/src/crepe/ParticleSystem.cpp +++ b/src/crepe/ParticleSystem.cpp @@ -1,7 +1,7 @@ #include "ParticleSystem.h" #include #include -#include "ParticleEmitter.h" +#include "api/ParticleEmitter.h" #include "Particle.h" #include "ComponentManager.h" diff --git a/src/crepe/ParticleSystem.h b/src/crepe/ParticleSystem.h index c8777f5..313e1dd 100644 --- a/src/crepe/ParticleSystem.h +++ b/src/crepe/ParticleSystem.h @@ -1,7 +1,7 @@ #pragma once #include -#include "ParticleEmitter.h" +#include "api/ParticleEmitter.h" namespace crepe { diff --git a/src/crepe/SDLApp.cpp b/src/crepe/SDLApp.cpp index 715dd6f..ca7e819 100644 --- a/src/crepe/SDLApp.cpp +++ b/src/crepe/SDLApp.cpp @@ -2,7 +2,7 @@ #include #include #include "Particle.h" -#include "ParticleEmitter.h" +#include "api/ParticleEmitter.h" SDLApp::SDLApp(int windowWidth, int windowHeight) : windowWidth(windowWidth), windowHeight(windowHeight), window(nullptr), renderer(nullptr) {} diff --git a/src/crepe/SDLApp.h b/src/crepe/SDLApp.h index 8915d30..b536ac8 100644 --- a/src/crepe/SDLApp.h +++ b/src/crepe/SDLApp.h @@ -3,7 +3,7 @@ #include #include "Particle.h" -#include "ParticleEmitter.h" +#include "api/ParticleEmitter.h" class SDLApp { public: diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt index c97423d..465ba46 100644 --- a/src/crepe/api/CMakeLists.txt +++ b/src/crepe/api/CMakeLists.txt @@ -6,6 +6,7 @@ target_sources(crepe PUBLIC Rigidbody.cpp Sprite.cpp Force.cpp + ParticleEmitter.cpp ) target_sources(crepe PUBLIC FILE_SET HEADERS FILES @@ -17,5 +18,6 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES Rigidbody.h Sprite.h Force.h + ParticleEmitter.h ) diff --git a/src/crepe/api/ParticleEmitter.cpp b/src/crepe/api/ParticleEmitter.cpp new file mode 100644 index 0000000..318c6db --- /dev/null +++ b/src/crepe/api/ParticleEmitter.cpp @@ -0,0 +1,28 @@ +#include "ParticleEmitter.h" +#include +#include "Particle.h" +#include + +using namespace crepe; + +ParticleEmitter::ParticleEmitter(uint32_t gameObjectId ,uint32_t maxParticles, uint32_t emissionRate, uint32_t speed, uint32_t speedOffset, uint32_t angle, uint32_t angleOffset, float m_beginLifespan, float m_endLifespan) + : Component(gameObjectId), m_maxParticles(maxParticles), m_emissionRate(emissionRate), m_speed(speed), m_speedOffset(speedOffset), m_position{0, 0}, m_beginLifespan(m_beginLifespan),m_endLifespan(m_endLifespan) { + std::srand(static_cast(std::time(nullptr))); // initialize random seed + std::cout << "Create emitter" << std::endl; + m_minAngle = (360 + angle - (angleOffset % 360)) % 360; // calculate minAngle + m_maxAngle = (360 + angle + (angleOffset % 360)) % 360; // calculate maxAngle + m_position.x = 400; + m_position.y = 400; + for (size_t i = 0; i < m_maxParticles; i++) + { + this->particles.emplace_back(); + } + +} + +ParticleEmitter::~ParticleEmitter() { + std::vector::iterator it = this->particles.begin(); + while (it != this->particles.end()) { + it = this->particles.erase(it); + } +} diff --git a/src/crepe/api/ParticleEmitter.h b/src/crepe/api/ParticleEmitter.h new file mode 100644 index 0000000..8cd78a9 --- /dev/null +++ b/src/crepe/api/ParticleEmitter.h @@ -0,0 +1,32 @@ +#pragma once + +#include +#include "Particle.h" +#include +#include "Component.h" +# + +namespace crepe { + +class ParticleEmitter : public Component { +public: + ParticleEmitter(uint32_t gameObjectId, uint32_t maxParticles, uint32_t emissionRate, uint32_t speed, uint32_t speedOffset, uint32_t angle, uint32_t angleOffset,float m_beginLifespan,float m_endLifespan); + ~ParticleEmitter(); + + Position m_position; //position of the emitter + uint32_t m_maxParticles; //maximum number of particles + uint32_t m_emissionRate; //rate of particle emission + uint32_t m_speed; //base speed of the particles + uint32_t m_speedOffset; //offset for random speed variation + uint32_t m_minAngle; //min angle of particle emission + uint32_t m_maxAngle; //max angle of particle emission + float m_beginLifespan; //begin Lifespan of particle (only visual) + float m_endLifespan; //begin Lifespan of particle + + std::vector particles; //collection of particles + +}; + +} + + diff --git a/src/example/particle.cpp b/src/example/particle.cpp index df1dbfd..fb89a3d 100644 --- a/src/example/particle.cpp +++ b/src/example/particle.cpp @@ -2,14 +2,15 @@ #include #include #include "SDLApp.h" -#include "ParticleEmitter.h" +#include "api/ParticleEmitter.h" #include "ParticleSystem.h" #include "Particle.h" #include #include -#include +#include #include +using namespace crepe::api; using namespace crepe; using namespace std; -- cgit v1.2.3