Fixed loop, can't miss particles. (tried to add physics to particles)

This commit is contained in:
Stiffly
2014-04-24 00:44:26 +02:00
parent 5997ee2320
commit b07605594d
2 changed files with 23 additions and 9 deletions
+21 -9
View File
@@ -34,21 +34,24 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID
} }
std::list<ParticleData>::iterator it; std::list<ParticleData>::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; EntityID particleID = it->ParticleID;
auto particleComponent = m_World->GetComponent<Components::Particle>(particleID, "Particle"); auto particleComponent = m_World->GetComponent<Components::Particle>(particleID, "Particle");
double timeLived = glfwGetTime() - it->SpawnTime; double timeLived = glfwGetTime() - it->SpawnTime;
if(timeLived > particleComponent->LifeTime) if(timeLived > particleComponent->LifeTime)
{ {
m_World->RemoveEntity(particleID);
m_ParticleEmitter[entity].erase(it); m_ParticleEmitter[entity].erase(it);
//std::cout<<"Removed dead particle..."<<std::endl; // TEMP //std::cout<<"Removed dead particle..."<<std::endl; // TEMP
break; break;
} }
/*else else
{ {
it++; it++;
}*/ }
auto transformComponent = m_World->GetComponent<Components::Transform>(particleID, "Transform"); auto transformComponent = m_World->GetComponent<Components::Transform>(particleID, "Transform");
float speed = 10 * dt; float speed = 10 * dt;
@@ -113,6 +116,14 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID, float spawnCoun
auto model = m_World->AddComponent<Components::Model>(ent, "Model"); auto model = m_World->AddComponent<Components::Model>(ent, "Model");
model->ModelFile = "Models/Placeholders/PhysicsTest/Cube.obj"; model->ModelFile = "Models/Placeholders/PhysicsTest/Cube.obj";
/*auto physics = m_World->AddComponent<Components::Physics>(ent, "Physics");
physics->Mass = 1;
auto physicShape = m_World->AddComponent<Components::Box>(ent, "Box");
physicShape->Width = 0.5;
physicShape->Height = 0.5;
physicShape->Depth = 0.5;*/
ParticleData data; ParticleData data;
data.ParticleID = ent; data.ParticleID = ent;
data.SpawnTime = glfwGetTime(); data.SpawnTime = glfwGetTime();
@@ -123,12 +134,13 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID, float spawnCoun
m_ParticleEmitter[emitterID].push_back(data); m_ParticleEmitter[emitterID].push_back(data);
} }
std::cout<<"Added "<<spawnCount<<" particles..."<<std::endl; //std::cout<<"Added "<<spawnCount<<" particles..."<<std::endl;
}
void Systems::ParticleSystem::Draw(double dt)
{
} }
// void Systems::ParticleSystem::Draw(double dt)
// {
//
// }
+2
View File
@@ -6,6 +6,8 @@
#include "Components/ParticleEmitter.h" #include "Components/ParticleEmitter.h"
#include "Components/Particle.h" #include "Components/Particle.h"
#include "Components/Model.h" #include "Components/Model.h"
#include "Components/Physics.h"
#include "Components/Box.h"
#include "Color.h" #include "Color.h"
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>