Use std::chrono in ParticleEmitter class for particle lifetime

This commit is contained in:
SeanOMik 2021-03-29 22:09:59 -05:00
parent bde19814a5
commit 2f1922952c
No known key found for this signature in database
GPG Key ID: CA09E5BE1F32728A
2 changed files with 3 additions and 5 deletions

View File

@ -20,11 +20,12 @@
#include <SFML/System/Clock.hpp>
#include <SFML/System/Vector2.hpp>
#include <chrono>
namespace simpleengine {
namespace particle {
struct ParticleAttributes {
uint32_t lifetime_ms;
std::chrono::milliseconds lifetime;
sf::Vector2f start_velocity;
float rotation_velocity = 0;
sf::Vector2f scale = sf::Vector2f(1, 1);

View File

@ -28,7 +28,6 @@ void simpleengine::particle::ParticleEmitter::Update(const float &delta_time) {
// Check if we can spawn particles with max particle count, also use chance to check if we can.
if (particles.size() + emit_count <= particle_count && random.NextInRange(0, 1) < emit_variance) {
// Make sure that we don't emit too many particles to go over the max particle count
//uint32_t emitting_ct = (particles.size() + emit_count > particle_count) ? particle_count - particles.size() : emit_count;
for (uint32_t i = 0; i < emit_count; i++) {
ParticlePropertyVector particle_properties_clone;
@ -36,7 +35,7 @@ void simpleengine::particle::ParticleEmitter::Update(const float &delta_time) {
particle_properties_clone.push_back(std::move(property->Clone()));
}
Particle particle(texture, attributes.start_velocity, std::chrono::milliseconds(attributes.lifetime_ms), attributes.rotation_velocity, std::move(particle_properties_clone));
Particle particle(texture, attributes.start_velocity, attributes.lifetime, attributes.rotation_velocity, std::move(particle_properties_clone));
// Offset the position of the particle randomly
sf::Vector2f new_pos;
@ -67,8 +66,6 @@ void simpleengine::particle::ParticleEmitter::Update(const float &delta_time) {
}
}
avg_particle_lifetime /= particles.size();
//std::cout << "Particle Count: " << particles.size() << " - Avg. lifetime: " << avg_particle_lifetime.count() << "ms - Max lifetime: " << max_lifetime.count() << "ms" << std::endl;
}
}