Laggy Particle System

Started by
12 comments, last by Fingers_ 17 years, 6 months ago
Quote:Original post by Anonymous Poster
Quote:Original post by Grant1219
Thanks for the help. I did think of using an iterator for the loop, but never changed for some reason. I'll try to take out all the unecessary stuff. Also Morpheus011, you said "You're also doing a fair amount of if checks in the for loop which could lead to a high amount of branch mis-prediction", but don't those if checks have to be in the loop?


Tickstillupdate really looks like it shoudl be done Outside the particle iterator loop. Or is there a reason that ticks are updated once per particle as opposed to once per game cycle?


ticksTilUpdate is for delaying the update of the particle system, in case if I didn't the particle system to update every game loop cycle. It has nothing to do with my main timer.

I changed the map to a vector, and made a destination BITMAP so it's not calling that GetBuffer() function constantly. I was really surprised, it really speed up the particle system considerably.

Advertisement
If the particle update is determined by the tickstillupdate check
then why is that check Inside the paricle iterator loop?
Shouldnt it be Outside, so that it can turn the entire particle loop on and off?
There are 3 variables that deal with delaying the particle system update loop.

int lastTick;
int ticksTilUpdate;
int delay;

delay is the amount of miliseconds to wait between updates.

lastTick is assigned by GetTicks() which is part of the timer class.

ticksTilUpdate is decremented each loop and when it eqauls 0, the particle system updates, ticksTilUpdate is re-asigned the value of delay, and lastTick is re-asigned to GetTicks().
If that's your intention then it's not working... With the ticksTilUpdate inside the for() loop it'll update some the particles every frame and perhaps never update some of them (E.g. if delay is 1, it'll update every other particle and if the number of particles is even then half of them will never be updated). The reason you don't notice this misbehavior is that you have a typo in your code and it never sets ticksTilUpdate to non-zero (you have == instead of =).

What you described is:

if(ticksTilUpdate <= 0)
{

for(int n = 0; n <= partAmount; n++)
{
...
}

ticksTilUpdate = delay;
}
else {ticksTilUpdate--; maxLives--;}

This topic is closed to new replies.

Advertisement