Particle engine

Hi there,

Which would be the best solution for my particle engine.

-The number of particles will not be greater then 200
-Each particle has the size of exactly one pixel

I use them now in a construction like;

UpdateParticles()
if particle[i].alive
do some x y work
restore background pixelcolor on old location
draw new pixelcolor on new location
…repeat for all particles
SDL_Flip

but this is terribly slow (just the right speed at my P3-900Mhz but no
speed at my laptop P1-100Mhz)

It looks like SDL_Flip is the one that makes it so slow (if I remove
that line all happens within a second so it is not the calculations
that makes it slow).

Should I use SDL_UpdateRects with a rect of 1x1 for every pixel?

Any thoughts?

Thanks in advance,
Rob

restore background pixelcolor on old location
draw new pixelcolor on new location

Are you drawing in a swsurface or a hwsurface? If the latter, you
may want to try drawing the pixels on an offscreen software surface
first, and blitting that whole surface in one go to the screen.–
Matthijs Hollemans
www.allyoursoftware.com

Which would be the best solution for my particle engine.

-The number of particles will not be greater then 200
-Each particle has the size of exactly one pixel

I use them now in a construction like;

UpdateParticles()
if particle[i].alive
do some x y work
restore background pixelcolor on old location
draw new pixelcolor on new location
…repeat for all particles
SDL_Flip

but this is terribly slow (just the right speed at my P3-900Mhz but no
speed at my laptop P1-100Mhz)

It looks like SDL_Flip is the one that makes it so slow (if I remove
that line all happens within a second so it is not the calculations
that makes it slow).

Should I use SDL_UpdateRects with a rect of 1x1 for every pixel?

No, but you might calculate concentrations of particles and update larger
rectangles around those, and then fill in the stragglers using 4x4 rects.
It may or may not be faster, you’ll have to benchmark it.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

i’ve written a few particle engines, and never had any problems

basically what i did was have a linked list of particles (b/c i didnt know
the upper limit and didnt want to set one)
then every frames i would go thru the list and move each one
then i’d go thru the list and see if any of them had lived long enough (or
whatever triggered them to be deleted from the list) and deleted them as
necessary
then i went thru the list and did SDL_FillRect() for each one of them
then i’d SDL_Flip()

i’ve never had any problems with it

<M@ the MadProgrammer>_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail

Why not blit background, then draw particles?On Mon, Nov 25, 2002 at 02:21:32PM +0100, Rob van Putten wrote:

UpdateParticles()
if particle[i].alive
do some x y work
restore background pixelcolor on old location
draw new pixelcolor on new location
…repeat for all particles
SDL_Flip


http://decopter.sf.net - free unrealistic helicopter simulator