aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/system
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/system')
-rw-r--r--src/crepe/system/ParticleSystem.cpp16
-rw-r--r--src/crepe/system/RenderSystem.cpp2
2 files changed, 11 insertions, 7 deletions
diff --git a/src/crepe/system/ParticleSystem.cpp b/src/crepe/system/ParticleSystem.cpp
index 3befb03..941e502 100644
--- a/src/crepe/system/ParticleSystem.cpp
+++ b/src/crepe/system/ParticleSystem.cpp
@@ -1,3 +1,4 @@
+#include <chrono>
#include <cmath>
#include <cstdlib>
#include <ctime>
@@ -5,6 +6,7 @@
#include "../api/ParticleEmitter.h"
#include "../api/Transform.h"
#include "../manager/ComponentManager.h"
+#include "../manager/LoopTimerManager.h"
#include "ParticleSystem.h"
@@ -12,10 +14,12 @@ using namespace crepe;
void ParticleSystem::update() {
// Get all emitters
-
- ComponentManager & mgr = this->mediator.component_manager;
+ const Mediator & mediator = this->mediator;
+ LoopTimerManager & loop_timer = mediator.loop_timer;
+ ComponentManager & mgr = mediator.component_manager;
+ float dt = std::chrono::duration<float>(loop_timer.get_scaled_fixed_delta_time()).count();
+
RefVector<ParticleEmitter> emitters = mgr.get_components_by_type<ParticleEmitter>();
- double dt = LoopTimer::get_instance().get_fixed_delta_time();
for (ParticleEmitter & emitter : emitters) {
// Get transform linked to emitter
@@ -23,10 +27,10 @@ void ParticleSystem::update() {
= mgr.get_components_by_id<Transform>(emitter.game_object_id).front().get();
// Emit particles based on emission_rate
- emitter.data.spawn_accumulator = emitter.data.emission_rate * dt;
- while (emitter.data.spawn_accumulator >= 1.0) {
+ emitter.spawn_accumulator = emitter.data.emission_rate * dt;
+ while (emitter.spawn_accumulator >= 1.0) {
this->emit_particle(emitter, transform);
- emitter.data.spawn_accumulator -= 1.0;
+ emitter.spawn_accumulator -= 1.0;
}
// Update all particles
diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp
index afd9548..cc633e8 100644
--- a/src/crepe/system/RenderSystem.cpp
+++ b/src/crepe/system/RenderSystem.cpp
@@ -83,7 +83,7 @@ bool RenderSystem::render_particle(const Sprite & sprite, const double & scale)
bool rendering_particles = false;
for (const ParticleEmitter & em : emitters) {
- if (&em.data.sprite != &sprite) continue;
+ if (&em.sprite != &sprite) continue;
rendering_particles = true;
if (!em.active) continue;