aboutsummaryrefslogtreecommitdiffstats
path: root/src/world.cpp
diff options
context:
space:
mode:
authordrumsetmonkey <abelleisle@roadrunner.com>2016-05-15 21:25:41 -0400
committerdrumsetmonkey <abelleisle@roadrunner.com>2016-05-15 21:25:41 -0400
commit0d4504017648b56a565216119a82166deb1f8d5d (patch)
treec2139ae55552009e176c7abfc8e98443784fb638 /src/world.cpp
parent23f3b1471b2bbfe92252456f32c9ae55a9d1f213 (diff)
more efficient particles
Diffstat (limited to 'src/world.cpp')
-rw-r--r--src/world.cpp34
1 files changed, 18 insertions, 16 deletions
diff --git a/src/world.cpp b/src/world.cpp
index 327a787..0c5007d 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -410,17 +410,19 @@ void World::draw(Player *p)
glEnableVertexAttribArray(worldShader_attribute_coord);
glEnableVertexAttribArray(worldShader_attribute_tex);
- std::vector<GLfloat> partc(0);
- std::vector<GLfloat> partt(0);
+ uint ps = particles.size();
+
+ std::vector<GLfloat> partVec;
+ partVec.reserve(ps * 6 * 5);
for (auto &p : particles) {
- if (p.behind)
- p.draw(partc, partt);
+ if (!p.behind)
+ p.draw(partVec);
}
- glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, &partc[0]);
- glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, &partt[0]);
- glDrawArrays(GL_TRIANGLES, 0, partc.size()/3);
+ glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &partVec[0]);
+ glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &partVec[3]);
+ glDrawArrays(GL_TRIANGLES, 0, ps * 6);
glDisableVertexAttribArray(worldShader_attribute_tex);
glDisableVertexAttribArray(worldShader_attribute_coord);
@@ -618,17 +620,17 @@ void World::draw(Player *p)
glEnableVertexAttribArray(worldShader_attribute_coord);
glEnableVertexAttribArray(worldShader_attribute_tex);
- partc.clear();
- partt.clear();
+ partVec.clear();
+ partVec.reserve(ps * 6 * 5);
for (auto &p : particles) {
if (!p.behind)
- p.draw(partc, partt);
+ p.draw(partVec);
}
- glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 0, &partc[0]);
- glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 0, &partt[0]);
- glDrawArrays(GL_TRIANGLES, 0, partc.size()/3);
+ glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &partVec[0]);
+ glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &partVec[3]);
+ glDrawArrays(GL_TRIANGLES, 0, ps * 6);
glDisableVertexAttribArray(worldShader_attribute_tex);
glDisableVertexAttribArray(worldShader_attribute_coord);
@@ -855,8 +857,8 @@ update(Player *p, unsigned int delta, unsigned int ticks)
if (weather == WorldWeather::Sunny)
weather = WorldWeather::Dark;
else if (weather == WorldWeather::Dark)
- weather = WorldWeather::Sunny;
- }
+ weather = WorldWeather::Sunny;
+ }
// update player coords
p->loc.y += p->vel.y * delta;
@@ -1285,7 +1287,7 @@ bool World::goWorldRight(NPC *e)
npc.erase(std::find(std::begin(npc), std::end(npc), e));
entity.erase(std::find(std::begin(entity), std::end(entity), e));
-
+
e->loc.x = currentWorldToRight->worldStart + HLINES(15);
e->loc.y = GROUND_HEIGHT_MINIMUM;
--e->outnabout;