aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/ParticleEmitter.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-13 19:32:14 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-13 19:32:14 +0100
commit56cf219a25e66f38c50a51afd01ed515de149711 (patch)
tree016293d4e13fa2e141a960062e005b608ccecebf /src/crepe/api/ParticleEmitter.cpp
parentd69f1642cb397d68d591718f83028e14620ab340 (diff)
parent0b2ca3c323c7f73d031e7014ba0a17dcf0b59751 (diff)
merge `jaro/particle-system-master` into `loek/cleanup` early
Diffstat (limited to 'src/crepe/api/ParticleEmitter.cpp')
-rw-r--r--src/crepe/api/ParticleEmitter.cpp40
1 files changed, 5 insertions, 35 deletions
diff --git a/src/crepe/api/ParticleEmitter.cpp b/src/crepe/api/ParticleEmitter.cpp
index 0bc2197..7032f9e 100644
--- a/src/crepe/api/ParticleEmitter.cpp
+++ b/src/crepe/api/ParticleEmitter.cpp
@@ -1,41 +1,11 @@
-#include <ctime>
-#include <iostream>
-
-#include "Particle.h"
#include "ParticleEmitter.h"
+#include "Particle.h"
using namespace crepe;
-ParticleEmitter::ParticleEmitter(game_object_id_t id, uint32_t max_particles,
- uint32_t emission_rate, uint32_t speed,
- uint32_t speed_offset, uint32_t angle,
- uint32_t angleOffset, float begin_lifespan,
- float end_lifespan)
- : Component(id),
- max_particles(max_particles),
- emission_rate(emission_rate),
- speed(speed),
- speed_offset(speed_offset),
- position{0, 0},
- begin_lifespan(begin_lifespan),
- end_lifespan(end_lifespan) {
- std::srand(
- static_cast<uint32_t>(std::time(nullptr))); // initialize random seed
- std::cout << "Create emitter" << std::endl;
- // FIXME: Why do these expressions start with `360 +`, only to be `% 360`'d
- // right after? This does not make any sense to me.
- min_angle = (360 + angle - (angleOffset % 360)) % 360;
- max_angle = (360 + angle + (angleOffset % 360)) % 360;
- position.x = 400; // FIXME: what are these magic values?
- position.y = 400;
- for (size_t i = 0; i < max_particles; i++) {
- this->particles.emplace_back();
- }
-}
-
-ParticleEmitter::~ParticleEmitter() {
- std::vector<Particle>::iterator it = this->particles.begin();
- while (it != this->particles.end()) {
- it = this->particles.erase(it);
+ParticleEmitter::ParticleEmitter(game_object_id_t game_object_id, const Data & data)
+ : Component(game_object_id), data(data) {
+ for (size_t i = 0; i < this->data.max_particles; i++) {
+ this->data.particles.emplace_back();
}
}