diff src/modules/graphics/opengl/ParticleSystem.cpp @ 1353:c3c9d6ed3e21 particlesystem-quads

ParticleSystem:setQuads can now accept a table argument, cleaned up the ParticleSystem quad code
author Alex Szpakowski <slime73@gmail.com>
date Mon, 11 Mar 2013 01:44:43 -0300
parents 470a47bebfb3
children b88c88225336 f1c353a5067d
line wrap: on
line diff
--- a/src/modules/graphics/opengl/ParticleSystem.cpp	Sun Mar 10 03:40:25 2013 -0300
+++ b/src/modules/graphics/opengl/ParticleSystem.cpp	Mon Mar 11 01:44:43 2013 -0300
@@ -100,6 +100,9 @@
 
 ParticleSystem::~ParticleSystem()
 {
+	for (size_t i = 0; i < quads.size(); i++)
+		quads[i]->release();
+
 	if (this->sprite != 0)
 		this->sprite->release();
 
@@ -370,19 +373,7 @@
 		colors[i] = colorToFloat(newColors[i]);
 }
 
-void ParticleSystem::setQuad(love::graphics::Quad *quad)
-{
-
-	for (size_t i = 0; i < quads.size(); i++)
-		quads[i]->release();
-
-	quads.resize(1);
-
-	quads[0] = quad;
-	quad->retain();
-}
-
-void ParticleSystem::setQuad(const std::vector<love::graphics::Quad *> &newQuads)
+void ParticleSystem::setQuads(const std::vector<love::graphics::Quad *> &newQuads)
 {
 	for (size_t i = 0; i < quads.size(); i++)
 		quads[i]->release();
@@ -396,7 +387,7 @@
 	}
 }
 
-void ParticleSystem::setQuad()
+void ParticleSystem::setQuads()
 {
 	for (size_t i = 0; i < quads.size(); i++)
 		quads[i]->release();
@@ -515,8 +506,8 @@
 
 	const vertex *imageVerts = sprite->getVertices();
 	const vertex *tVerts;
+
 	size_t numQuads = quads.size();
-	size_t quadIndex = 0;
 
 	// set the vertex data for each particle (transformation, texcoords, color)
 	for (int i = 0; i < numParticles; i++)
@@ -526,7 +517,7 @@
 		if (numQuads > 0)
 		{
 			// Make sure the quad index is valid
-			quadIndex = (p->quadIndex >= numQuads) ? numQuads - 1 : p->quadIndex;
+			size_t quadIndex = (p->quadIndex >= numQuads) ? numQuads - 1 : p->quadIndex;
 			tVerts = quads[quadIndex]->getVertices();
 		}
 		else
@@ -663,12 +654,12 @@
 			p->color = colors[i] * (1.0f - s) + colors[k] * s;
 
 			// Update quad index
-			if (quads.size() > 0)
+			k = quads.size();
+			if (k > 0)
 			{
-				k = quads.size() - 1;
-				s = t * (float) k;
+				s = t * (float) k; // [0:numquads-1]
 				i = (s > 0) ? (size_t) s : 0;
-				p->quadIndex = (i <= k) ? i : k;
+				p->quadIndex = (i < k) ? i : k - 1;
 			}
 			else
 				p->quadIndex = 0;