diff options
author | jaroWMR <jarorutjes07@gmail.com> | 2024-10-07 18:07:17 +0200 |
---|---|---|
committer | jaroWMR <jarorutjes07@gmail.com> | 2024-10-07 18:07:17 +0200 |
commit | 5f84969c851530ebc430be2cf8e99c945ff7a4a7 (patch) | |
tree | 9fcd2755dbfd456f20f0ad37c18c7281b81382b1 /src/crepe/Particle.cpp | |
parent | 5cf5cf64d6f9597849ed5558da4f1bc201165fed (diff) |
improved particle system from 90ms to ~ 0.7ms
Diffstat (limited to 'src/crepe/Particle.cpp')
-rw-r--r-- | src/crepe/Particle.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/crepe/Particle.cpp b/src/crepe/Particle.cpp index 3254b5b..8cf7f7e 100644 --- a/src/crepe/Particle.cpp +++ b/src/crepe/Particle.cpp @@ -1,16 +1,23 @@ #include "Particle.hpp" #include <iostream> -Particle::Particle(float lifespan, Position position, Position velocity) - : lifespan(lifespan), position(position), velocity(velocity), timeInLife(0.0f) {} +Particle::Particle() +{ + this->active = false; +} + +void Particle::reset(float lifespan, Position position, Position velocity) { + this->timeInLife = 0; + this->lifespan = lifespan; + this->position = position; + this->velocity = velocity; + this->active = true; +} void Particle::update(float deltaTime) { timeInLife += deltaTime; position.x += velocity.x * deltaTime; position.y += velocity.y * deltaTime; + if(timeInLife >= lifespan)this->active = false; } -bool Particle::isAlive() const { - std::cout << "lifespan" << lifespan << std::endl; - return timeInLife < lifespan; -} |