diff options
| author | jaroWMR <jarorutjes07@gmail.com> | 2024-10-20 12:59:18 +0200 | 
|---|---|---|
| committer | jaroWMR <jarorutjes07@gmail.com> | 2024-10-20 12:59:18 +0200 | 
| commit | 0f03cdbf23f57116b7664a7c98c4605fd69bb961 (patch) | |
| tree | 6e592bd7e94cd5954a8a49209de815fc0ae0becd /src | |
| parent | 016070d47f2fff8cfdd49cc0bdf65c14ef922c94 (diff) | |
updated particle system
Diffstat (limited to 'src')
| -rw-r--r-- | src/crepe/ParticleSystem.cpp | 7 | ||||
| -rw-r--r-- | src/crepe/ParticleSystem.h | 2 | ||||
| -rw-r--r-- | src/crepe/Transform.cpp | 6 | ||||
| -rw-r--r-- | src/crepe/Transform.h | 16 | ||||
| -rw-r--r-- | src/example/components_internal.cpp | 4 | ||||
| -rw-r--r-- | src/example/particle.cpp | 17 | 
6 files changed, 40 insertions, 12 deletions
| diff --git a/src/crepe/ParticleSystem.cpp b/src/crepe/ParticleSystem.cpp index 3a1f653..0dad4cd 100644 --- a/src/crepe/ParticleSystem.cpp +++ b/src/crepe/ParticleSystem.cpp @@ -1,8 +1,6 @@  #include "ParticleSystem.h"  #include <cmath> -// #include <cstdlib>  #include <ctime> -#include <iostream>  // include iostream for std::cout  #include "ParticleEmitter.h"  #include "Particle.h"  #include "ComponentManager.h" @@ -11,7 +9,10 @@ using namespace crepe;  ParticleSystem::ParticleSystem() : m_elapsedTime(0.0f) {}  // Initialize m_elapsedTime to 0 -void ParticleSystem::update(float deltaTime, std::vector<std::reference_wrapper<ParticleEmitter>>& emitters) { +void ParticleSystem::update() { +	ComponentManager& mgr = ComponentManager::get_instance(); +	std::vector<std::reference_wrapper<ParticleEmitter>> emitters = mgr.get_components_by_type<ParticleEmitter>(); +	float deltaTime = 0.10;      for (ParticleEmitter& emitter : emitters) {          float updateAmount = 1/static_cast<float>(emitter.m_emissionRate);          for (float i = 0; i < deltaTime; i += updateAmount) diff --git a/src/crepe/ParticleSystem.h b/src/crepe/ParticleSystem.h index 7b14f71..c8777f5 100644 --- a/src/crepe/ParticleSystem.h +++ b/src/crepe/ParticleSystem.h @@ -9,7 +9,7 @@ namespace crepe {  class ParticleSystem {  public:      ParticleSystem(); -    void update(float deltaTime, std::vector<std::reference_wrapper<ParticleEmitter>>& emitters); +    void update();  private:      void emitParticle(ParticleEmitter &emitter); //emits a new particle diff --git a/src/crepe/Transform.cpp b/src/crepe/Transform.cpp new file mode 100644 index 0000000..0e4b0cf --- /dev/null +++ b/src/crepe/Transform.cpp @@ -0,0 +1,6 @@ +#include "Transform.h" + +using namespace crepe; + +Transform::Transform(int mass, int gravityScale, int bodyType) +	: mass(mass), gravity_scale(gravityScale), body_type(bodyType) {} diff --git a/src/crepe/Transform.h b/src/crepe/Transform.h new file mode 100644 index 0000000..c72ebc4 --- /dev/null +++ b/src/crepe/Transform.h @@ -0,0 +1,16 @@ +#pragma once + +#include "Component.h" + +namespace crepe { + +class Transform : public Component { +public: +	Transform(int mass, int gravityScale, int bodyType); + +	int mass; +	int gravity_scale; +	int body_type; +}; + +} // namespace crepe diff --git a/src/example/components_internal.cpp b/src/example/components_internal.cpp index 54ce295..3ba5b5a 100644 --- a/src/example/components_internal.cpp +++ b/src/example/components_internal.cpp @@ -39,8 +39,8 @@ int main() {  	auto stop_adding = chrono::high_resolution_clock::now();  	auto sprites = mgr.get_components_by_type<Sprite>(); -	for (auto sprite : sprites) { -		assert(sprite.get().path == "test"); +	for (auto & sprite : sprites) { +		assert(sprite.path == "test");  	}  	auto stop_looping = chrono::high_resolution_clock::now(); diff --git a/src/example/particle.cpp b/src/example/particle.cpp index fc56230..df1dbfd 100644 --- a/src/example/particle.cpp +++ b/src/example/particle.cpp @@ -24,7 +24,7 @@ int main(int argc, char* argv[]) {          return 1;      } -	auto & mgr = ComponentManager::get_instance(); +	  	GameObject * game_object[1];  	game_object[0] = new GameObject(0, "Name", "Tag", 0); @@ -32,19 +32,19 @@ int main(int argc, char* argv[]) {      ParticleSystem particleSystem;      unsigned int maxParticles = 100;         // maximum number of particles -    unsigned int emissionRate = 1;          // particles created per second +    unsigned int emissionRate = 10;          // particles created per second      unsigned int speed = 50;                 // base speed of particles      unsigned int speedOffset = 10;           // random offset for particle speed -    unsigned int angle = 90;                 // base angle of particle emission +    unsigned int angle = 270;                 // base angle of particle emission      unsigned int angleOffset = 30;           // random offset for particle angle      float beginLifespan = 0.0f;             // beginning lifespan of particles -    float endLifespan = 2.0f;               // ending lifespan of particles +    float endLifespan = 6.0f;               // ending lifespan of particles      // Vector to hold all the emitters      // vector<ParticleEmitter> emitters;  	game_object[0]->add_component<ParticleEmitter>(maxParticles, emissionRate, speed, speedOffset, angle, angleOffset, beginLifespan, endLifespan); -	std::vector<std::reference_wrapper<ParticleEmitter>> emitters = mgr.get_components_by_type<ParticleEmitter>(); +	      // Loop to create 1000 emitters @@ -65,7 +65,10 @@ int main(int argc, char* argv[]) {          // Start timing          auto start = chrono::high_resolution_clock::now(); -        particleSystem.update(deltaTime, emitters); // update particle system with delta time and emitters + +		// POC CODE +        particleSystem.update();  +		// POC CODE          // End timing          auto end = chrono::high_resolution_clock::now(); @@ -76,6 +79,8 @@ int main(int argc, char* argv[]) {          start = chrono::high_resolution_clock::now();          // render particles using the drawSquare method from SDLApp +		ComponentManager& mgr = ComponentManager::get_instance(); +		std::vector<std::reference_wrapper<ParticleEmitter>> emitters = mgr.get_components_by_type<ParticleEmitter>();          for (const ParticleEmitter& emitter : emitters) {              for (const Particle& particle : emitter.particles) {                  if(particle.active)app.drawSquare(particle.position.x, particle.position.y, 5); // draw each particle |