I'm using a particle engine based on a pre-initiated array. Creating and destroying object is not a good practice.
I'm using a flag (status=1 particle is live, =0 is dead and can be 'reused').
Problems I see with this: If I create 1000 particles which disappear at different times, when I get to say 100 particles left, my list will iterate nice and quickly but with an array I'd still have to loop 1000 times and check each slot to see if the particle is still "active" - that could be slower than the list iteration! I could shuffle up the particles when one was deleted but that would be really slow and impractical I'm sure.
I resolved the problem using a while..wend with variable-limits.
Every time I need to use a new particle the part_counter is increased, and last_part can starts from 0 or from an higher value.
Maybe it is not the best solutions, but it seems to work...
Here a little extract of the 'CreateParticle' Function
When the particle is 'dead' I set its status to '0' and last_part=0.
Technically I could check if last_part is > 0, but I'm lazy...
I'm using a flag (status=1 particle is live, =0 is dead and can be 'reused').
Problems I see with this: If I create 1000 particles which disappear at different times, when I get to say 100 particles left, my list will iterate nice and quickly but with an array I'd still have to loop 1000 times and check each slot to see if the particle is still "active" - that could be slower than the list iteration! I could shuffle up the particles when one was deleted but that would be really slow and impractical I'm sure.
I resolved the problem using a while..wend with variable-limits.
Every time I need to use a new particle the part_counter is increased, and last_part can starts from 0 or from an higher value.
Maybe it is not the best solutions, but it seems to work...
Here a little extract of the 'CreateParticle' Function
If last_part>=max_particle-1 last_part=0 Local part_counter:Int = last_part Local findit:Int=0 While part_counter < particle.length - 1 If particle[part_counter].status = 0 particle[part_counter].status = 1 last_part = part_counter findit=1 Exit ' a new 'particle' is found End If part_counter:+ 1 Wend If findit=0 Return Null End If If part_counter > max_particle max_particle = last_part End If If part_counter>max_part max_part=part_counter Local p:tparticle = particle[last_part] ...
When the particle is 'dead' I set its status to '0' and last_part=0.
Technically I could check if last_part is > 0, but I'm lazy...