From b07605594d748c6feff89de1e1f4feac625086f3 Mon Sep 17 00:00:00 2001 From: Stiffly Date: Thu, 24 Apr 2014 00:44:26 +0200 Subject: [PATCH] Fixed loop, can't miss particles. (tried to add physics to particles) --- src/Systems/ParticleSystem.cpp | 30 +++++++++++++++++++++--------- src/Systems/ParticleSystem.h | 2 ++ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/Systems/ParticleSystem.cpp b/src/Systems/ParticleSystem.cpp index e62218d..7cdec83 100644 --- a/src/Systems/ParticleSystem.cpp +++ b/src/Systems/ParticleSystem.cpp @@ -34,21 +34,24 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID } std::list::iterator it; - for(it = m_ParticleEmitter[entity].begin(); it != m_ParticleEmitter[entity].end(); it++) + for(it = m_ParticleEmitter[entity].begin(); it != m_ParticleEmitter[entity].end();) { EntityID particleID = it->ParticleID; auto particleComponent = m_World->GetComponent(particleID, "Particle"); double timeLived = glfwGetTime() - it->SpawnTime; if(timeLived > particleComponent->LifeTime) { + + m_World->RemoveEntity(particleID); m_ParticleEmitter[entity].erase(it); //std::cout<<"Removed dead particle..."<GetComponent(particleID, "Transform"); float speed = 10 * dt; @@ -113,6 +116,14 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID, float spawnCoun auto model = m_World->AddComponent(ent, "Model"); model->ModelFile = "Models/Placeholders/PhysicsTest/Cube.obj"; + /*auto physics = m_World->AddComponent(ent, "Physics"); + physics->Mass = 1; + + auto physicShape = m_World->AddComponent(ent, "Box"); + physicShape->Width = 0.5; + physicShape->Height = 0.5; + physicShape->Depth = 0.5;*/ + ParticleData data; data.ParticleID = ent; data.SpawnTime = glfwGetTime(); @@ -123,12 +134,13 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID, float spawnCoun m_ParticleEmitter[emitterID].push_back(data); } - std::cout<<"Added "<