Particles
What would be the best way to check if particles should be rendered? Just having a 1000 particles (and not drawing a one) slows the "game" down significiantly (20-40 fps). I''m using a For loop that checks if a particle is alive and should it be drawn:
For p = 1 to ubound(particles) ''ubound =1000
if particles(p).alive = true then
''determine the current location and render it
end if
Next
Is there another way to do it? In my opinion 1000 particles without too complex physics aren''t good enough, especially when there''s no sound effects or AI yet.
Well, I''m afraid to say it, but a thousand particles is a lot, though it depends. The best optimisation here is not nessecarily going to come from view frustrum clipping, but other techneques - these depend on how your engine works though, anyway, to clip ''em to the screen, you need to be managing as much of the engines pipeline as possible. You use matrixies to transform them to screen co-orinates, and then do a simple range check. However, this is still slow, and your 3D api could be doing this anyway - post how your engine works and I''ll try to provide a better answer. Also, it helps to know what the particles are being used for.
Okay.. my engine is a tile-based, but I''m not using that right now. I''m using a simple fullscreen mode (w/o any tricks) to test this particle system, then I''ll move it to my primary engine.
Determining the location is simple -
x1= x1 + speed * sinX(direction)
y1= y1 + speed * cosY(direction)
And those sins and cos''s are precalculated.. it''s a couple of fps''s faster..
rendering:
dim vertex(1 to 4) as d3dtlvertex ''this declaration is form level
vertex(0).sx = .X1
vertex(0).sy = .Y1
vertex(1).sx = .X1 + g_particles.tilesize.x
vertex(1).sy = .Y1
vertex(2).sx = .X1
vertex(2).sy = .Y1 + g_particles.tilesize.y
vertex(3).sx = .X1 + g_particles.tilesize.x
vertex(3).sy = .Y1 + g_particles.tilesize.y
I think that using only four vertices is faster than using 1000*4 vertices that all have the same basic structure..
I''m doing a simple space shooter (me and my friends often have lan parties and this is a good way to practice both general and and multiplayer programming).
The particles are used as torpedoes, missiles, bullets etc. that can be shot- of course I don''t need a thousand particles for one spaceship but when there are 10 ships that all have 100 particles for themselves to use (plus sounds, net code etc), there are going to be some problems.
I''m trying to achieve about 200 fps in windowed 640*480 mode. There''s not much to go however- from 20 to 40 fps more and that''ll be it.
Determining the location is simple -
x1= x1 + speed * sinX(direction)
y1= y1 + speed * cosY(direction)
And those sins and cos''s are precalculated.. it''s a couple of fps''s faster..
rendering:
dim vertex(1 to 4) as d3dtlvertex ''this declaration is form level
vertex(0).sx = .X1
vertex(0).sy = .Y1
vertex(1).sx = .X1 + g_particles.tilesize.x
vertex(1).sy = .Y1
vertex(2).sx = .X1
vertex(2).sy = .Y1 + g_particles.tilesize.y
vertex(3).sx = .X1 + g_particles.tilesize.x
vertex(3).sy = .Y1 + g_particles.tilesize.y
I think that using only four vertices is faster than using 1000*4 vertices that all have the same basic structure..
I''m doing a simple space shooter (me and my friends often have lan parties and this is a good way to practice both general and and multiplayer programming).
The particles are used as torpedoes, missiles, bullets etc. that can be shot- of course I don''t need a thousand particles for one spaceship but when there are 10 ships that all have 100 particles for themselves to use (plus sounds, net code etc), there are going to be some problems.
I''m trying to achieve about 200 fps in windowed 640*480 mode. There''s not much to go however- from 20 to 40 fps more and that''ll be it.
If i''m not mistaken, this is the exact sort of thing VB chokes on.
You could try creating a Collection of CParticles and doing a
Dim Particle as CParticle
Dim ParticleHeap as Collection
ParticleHeap.Add....
...
For each Particle in ParticleHeap
Render(Particle)
next
that way you don''t blow cpu time checking for non-existent particles, and can use non-vb code (the collection) to maintain a bag of particles.
You could try creating a Collection of CParticles and doing a
Dim Particle as CParticle
Dim ParticleHeap as Collection
ParticleHeap.Add....
...
For each Particle in ParticleHeap
Render(Particle)
next
that way you don''t blow cpu time checking for non-existent particles, and can use non-vb code (the collection) to maintain a bag of particles.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
I''ve read that collections are slower than arrays so they shouldn''t be used. And yes, sometimes VB sucks. But how this would be done in, say C++ then?
I''m not sure whether this will help (I''m not up to my particle system coding yet), but you could try a bounding-box-style thing: draw an axis alligned bounding box arround the particle system, and if you can''t see the mox, turn of the particle object.
Simon Wilson,
XEOS Digital Development
Simon Wilson,
XEOS Digital Development
XEOS Digital Development - Supporting the independant and OpenSource game developers!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement