aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/particle.hpp2
-rw-r--r--main.cpp4
-rw-r--r--src/particle.cpp18
3 files changed, 12 insertions, 12 deletions
diff --git a/include/particle.hpp b/include/particle.hpp
index 4d42b39..a022583 100644
--- a/include/particle.hpp
+++ b/include/particle.hpp
@@ -34,7 +34,7 @@ public:
void add(const vec2& pos, const ParticleType& type, const int& timeleft = 3000);
void addMultiple(const int& count, const ParticleType& type, std::function<vec2(void)> f, const int& timeleft = 3000);
- void render(void) const;
+ void render(void);
void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
int getCount(void) const;
diff --git a/main.cpp b/main.cpp
index 0c5a6f2..d2ae419 100644
--- a/main.cpp
+++ b/main.cpp
@@ -224,7 +224,7 @@ int main(int argc, char *argv[])
while (run) {
fpsInternal++;
render();
- game::engine.resetRender(0);
+ game::engine.resetRender(0); // TODO stupid
}
// on game end, get back together
@@ -321,7 +321,7 @@ void render() {
//player->inv->draw();
game::engine.render(0);
-
+
// draw the fade overlay
ui::drawFade();
diff --git a/src/particle.cpp b/src/particle.cpp
index 52a5635..1cab0e9 100644
--- a/src/particle.cpp
+++ b/src/particle.cpp
@@ -26,7 +26,7 @@ void ParticleSystem::addMultiple(const int& count, const ParticleType& type, std
parts.emplace_back(f(), type, timeleft);
}
-void ParticleSystem::render(void) const
+void ParticleSystem::render(void)
{
static GLuint particleVBO = 9999, texVBO = 0;
@@ -50,9 +50,14 @@ void ParticleSystem::render(void) const
glBindBuffer(GL_ARRAY_BUFFER, particleVBO);
+ // clear dead particles
+ parts.erase(std::remove_if(parts.begin(), parts.end(),
+ [](const Particle& p) { return p.timeLeft <= 0; }), parts.end());
+
// copy data into VBO
int offset = 0;
for (const auto& p : parts) {
+
GLfloat coords[18] = {
p.location.x, p.location.y, -1,
p.location.x, p.location.y + 5, -1,
@@ -61,11 +66,11 @@ void ParticleSystem::render(void) const
p.location.x + 5, p.location.y, -1,
p.location.x, p.location.y, -1
};
-
+
glBufferSubData(GL_ARRAY_BUFFER, offset, 18 * sizeof(GLfloat), coords);
offset += 18 * sizeof(GLfloat);
}
-
+
Render::worldShader.use();
Render::worldShader.enable();
Colors::blue.use();
@@ -103,8 +108,6 @@ void ParticleSystem::update(entityx::EntityManager &en, entityx::EventManager &e
// update timers
p.timeLeft -= dt;
- if (p.timeLeft <= 0)
- parts.erase(part);
// update movement
switch (p.type) {
@@ -131,11 +134,9 @@ void ParticleSystem::update(entityx::EntityManager &en, entityx::EventManager &e
if ((p.velocity.x > -0.01 && p.velocity.x < 0.01) &&
(p.velocity.y > -0.01 && p.velocity.y < 0.01)) {
p.timeLeft = 0;
- if (p.timeLeft <= 0)
- parts.erase(part);
}
}
-
+
break;
}
@@ -154,4 +155,3 @@ int ParticleSystem::getCount(void) const
{
return parts.size();
}
-