aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/Particle.cpp
diff options
context:
space:
mode:
authorjaroWMR <jarorutjes07@gmail.com>2024-10-07 18:07:17 +0200
committerjaroWMR <jarorutjes07@gmail.com>2024-10-07 18:07:17 +0200
commit5f84969c851530ebc430be2cf8e99c945ff7a4a7 (patch)
tree9fcd2755dbfd456f20f0ad37c18c7281b81382b1 /src/crepe/Particle.cpp
parent5cf5cf64d6f9597849ed5558da4f1bc201165fed (diff)
improved particle system from 90ms to ~ 0.7ms
Diffstat (limited to 'src/crepe/Particle.cpp')
-rw-r--r--src/crepe/Particle.cpp19
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;
-}