Optimizing Particle System Under SDL

Started by
7 comments, last by toXic1337 18 years, 3 months ago
Hi, I've been working on my game for a week now and have finished the player and weapon class. All that remains is getting a tile system setup and network code. Anyways, I've run into a brick wall. I've noticed that my particle engine is bogging down the fps when lots of particles are on screen. Here's a download of the game thus far so you can see exactly what im talking about. Arena Particle Demo I will post the particle engine code if needed but just to prevent that (it's long), I'll describe the system. It's a basic particle system that runs it's position updates and state checks in a vector. Thanks in advance for any advice, toXic~ EDIT1: Beware programmer art, but I think the particle effects are beautiful and I don't want to remove them from the game or output any less of them, just looking for a "fix" to speed up calculations, etc etc. I was wondering if it's just because it's SDL and maybe that's slow. I don't know.
toXic1337
Advertisement
SDL is notoriously sluggish.

Honestly if you're doing advanced things like particle engines I say move on to OpenGL rendering.

Learn to make games with my SDL 2 Tutorials

Well, I was fumbling around to see if I was eating up resources after firing for a long time, and it seems I have a leak somewhere.

However, when the window was not running in full-screen mode it never got sluggish and stayed at a constant 60fps. Weird...

I've been thinking of moving to OGL for a while now... but I don't want to lose all the code I've worked on so hard. How hard is it to port all this over to OGL. Maybe OGL with SDL.

toXic1337
Quote:Original post by toXic1337
Well, I was fumbling around to see if I was eating up resources after firing for a long time, and it seems I have a leak somewhere.

However, when the window was not running in full-screen mode it never got sluggish and stayed at a constant 60fps. Weird...

I've been thinking of moving to OGL for a while now... but I don't want to lose all the code I've worked on so hard. How hard is it to port all this over to OGL. Maybe OGL with SDL.


Not very. I ported all my sprite classes and engine classes to openGL with a couple of lines being changed. The only _big_ thing is that you have to create textures and not just SDL_Surface*'s.
It completely depends on what you're doing with the surfaces that makes them slow. Using some surfaces in hardware memory and some on software memory really lags the system. Another slow down is alpha blending, if you're doing massive amounts of blending, you'll notice the slow down. The last big thing that slows down SDL are software rotations in realtime, you'll want to avoid that...
Rob Loach [Website] [Projects] [Contact]
I mentioned this on a similiar thread a couple days ago:

Are you 'locking'(with SDL_LockSurface)/'unlocking'(with SDL_UnlockSurface) your SDL_Surfaces if you're drawing the particles just as single pixels with some sort of PutPixel() routine? This is very important; without locking it, SDL will have to lock/unlock the surface for every single pixel. This can cause a big slow down.

The first game I made with SDL was drawn completely pixel-by-pixel. I saw about a two-fold increase in speed when I locked the surface.

BTW, your game didn't work for me. It was one of those errors where you see four or five of everything and it sometimes skips every other line. I tried it at three resolutions(1024x768, 800x600, and 640x480) and it didn't work for any of them.
I looked into converting over to a Ogl/SDL framework to take advantage of Ogl's hardware acceleration.

However, I made the decision to decrease resolution and remove alpha blending and it runs at a more acceptable fps while maintaining full gameplay.

And with your error... It seems to work for everyone else that's tried it around school. Could you post your machine specs so I can figure out what exactly is wrong?

It seems that the biggest problem was the alpha blending on 100+ particles. I'm going to look to make sure im doing all hardware blits.

toXic~
toXic1337
I put together a particle engine in SDL.NET named SdlDotNet.Particles. Although it's written in C# and for SDL.NET, it works quite well with 2000+ particles. You could easily look at the source code and see what you could salvage into your own application.

The basic concept is that you have particles, manipulators and emitters. The particles fly around, the emitters shoot out more particles and the manipulators apply forces to the particles. Check out the Particles Example for an example of its use.
Rob Loach [Website] [Projects] [Contact]
You're a cool man Rob Loach, a cool man. Haha

Thanks
toXic1337

This topic is closed to new replies.

Advertisement