Hi!
I'm doing a particle engine for our next project. The engine is at the moment just drawing lines, but the performance is not very good I think. At least not when comparing to geoDefence. I get framerates around 20fps with more than 1000 particles. However, I don't know if I'm totally off route somewhere. Hope that someone here can help me a bit. I'm thinking about c-arrays intead of nsmutablearray. But I don't know if it will help that much. Perhaps the bottleneck if obvious for some of you?
I've cut down the code to the basic core. tickParticles is called each tick. (30 times/sec)
-(void) tickParticles{
availableVerts = 0;
v = 0;
for (LineParticle *p in Particles) {
if( ccpLengthSQ(p.Velocity) >= 0.5 ){
p.Velocity = ccpMult(p.Velocity, 0.95);
[p setPosition: ccpAdd(p.Position, p.Velocity)];
verts[v++] = p.Position.x;
verts[v++] = p.Position.y;
verts[v++] = p.Position.x+p.Velocity.x*1.8;
verts[v++] = p.Position.y+p.Velocity.y*1.8;
availableVerts += 2;
}
}
}
-(void)draw{
glColor4ub(100, 255, 100, 180);
drawLines( verts, Nil, availableVerts);
}
void drawLines( GLfloat *vertices, GLubyte *colors, unsigned int numberOfPoints )
{
glVertexPointer(2, GL_FLOAT, 0, vertices);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_LINES, 0, numberOfPoints);
glDisableClientState(GL_VERTEX_ARRAY);
}