开发者

XNA Particle system performance

开发者 https://www.devze.com 2023-03-29 23:15 出处:网络
I have a particle system using basic spritebatch, where the particles are being created and destroyed based on decremental alpha value till 0.

I have a particle system using basic spritebatch, where the particles are being created and destroyed based on decremental alpha value till 0.

The perfomance of the system is quite poor on pc, and ver开发者_如何学JAVAy poor on xbox, with about a hundred particles on screen before significant fps slow down, I've read around regarding how to improve performance but does anyone have any tips on how to implment them, for exmaple what is the best way to - reuse particles rather than kill()? Does the image size of each particle make a difference? if I don't rotate each particle will this help?

I've played around with each of these suggestions but don't receive any significant improvement - does anyone have any advice - is it worth going gpu rather than cpu based?


From what I recall destroying and creating particles slows down the performance substantially. You might want to reuse particles.

Not sure about image size or rotation drastically reducing performance as long as the image isn't substantially large.

I would have an array with swapping dead particles to the end of the active particles therefore processing only active particles.

For example:

Make an array of MAX particles;
When you need a particle grab particle_array[count]; 
Increment count.
When a particle dies, decrement count, swap the particle with particle_array[count];
Update only count particles;

Hope this helps.


I entirely agree with subsonic's answer, but I wanted to expand on it.

Creating a new particle every time and destroying (or letting go of) old particles creates a LOT of garbage. The garbage avoidance mantra in C#, particularly on Xbox (due to the compact framework's poor garbage handling), is to NEVER new a class type in your update/draw loop. ALWAYS pre-create into pools. Shawn H explains: http://blogs.msdn.com/b/shawnhar/archive/2007/07/02/twin-paths-to-garbage-collector-nirvana.aspx.

One other thing to consider is that you using multiple textures can cause slowdown for sprite batch due to multiple draw calls. Try to merge multiple particle textures into one and use the source rectangle SpriteBatch.Draw parameter.

0

精彩评论

暂无评论...
验证码 换一张
取 消