gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Help to optmize SDL game

#174498 - protomank - Thu Jun 17, 2010 2:58 pm

Hello, I need some help to optimize my game project, that is based on SDL.
The code is available in http://rockman-engine.svn.sourceforge.net/viewvc/rockman-engine/.

It becomes very slow when there are too much sprites (a player, 3 npcs and shots) in the screen. But even on a clean screen, it looks like the update of the background is slow.

Disclaimer:
- there is no way I will not not SDL unless some brave sould takes the step to do a full port to DS ;)
- I've already saw DS programs running in full speed in the DS
- so, fell free to point errors in my code that are making things slow, even if you say "you need to rewrite 80% of the code". It is ok, I'm open to critics.
_________________
Iuri Fiedoruk
http://rockbot.upperland.net

#174520 - relminator - Sun Jun 20, 2010 2:28 am

I'll be looking at your code and see if I can overload some stuff to use the 3d core.

[edit]

Can you zip your sources? I'm having probs navigating.
_________________
http://rel.betterwebber.com

#174523 - Sektor - Sun Jun 20, 2010 4:03 am

No need to zip it. You can get the GNU tarball.
_________________
GTAMP.com/DS

#174524 - relminator - Sun Jun 20, 2010 6:11 am

I've seen your graphics.h file and unless you invest time changing your rendering engine, It's gonna be hard to help you.
_________________
http://rel.betterwebber.com

#174563 - protomank - Sat Jun 26, 2010 1:16 pm

well, and how do you suggest I change it?
_________________
Iuri Fiedoruk
http://rockbot.upperland.net

#174565 - relminator - Sat Jun 26, 2010 3:00 pm

Ditch SDL and use the 3d engine. Trust me, once you make your 2d renderer using the 3d engine. It's almost like SDL as long as you don't use per pixel surface access.
_________________
http://rel.betterwebber.com

#174566 - protomank - Sat Jun 26, 2010 3:54 pm

Does the 3d engine runs on Windows, Linux, Mac, PS2, Dingoo and PSP? :D

I use SDL because this is a multi-platform game.
Anyway, I've did some optimizations in how I clear screen and how I move sprites that made the game run full-speed without sound, and using maxmod to play a background music, it runs, not well, but well-enought.
I think I can achieve a good speed in the DS, even if using SDL.
_________________
Iuri Fiedoruk
http://rockbot.upperland.net

#174569 - DiscoStew - Sat Jun 26, 2010 5:32 pm

SDL will only limit you when using it on the DS because it is all software-based rendering, which probably doesn't use the VRAM at all, making it even worse.

Without using the device's hardware capabilities, you end up running via software rendering, which takes up CPU cycles vs letting hardware handle it at literally no cost.

Without use of the tcm and cache, the ARM9 CPU would be limited to 33Mhz vs the 66Mhz when used efficiently, and this doesn't include teh hardware glitch.

The hardware glitch occurs when non-sequential access to RAM are done, resulting in an extra 3 waitcycles added to each operation. In worse-case scenarios, including the lack of tcm and cache use, the 66Mhz that was started with will drop to a measly 8Mhz, which is half the processing capabilities of the GBA.

This is why SDL is not recommended with DS development. It currently forces everything to be rendered via the CPU, as well as clashes with the hardware defects of the device because of it being done through the CPU.
_________________
DS - It's all about DiscoStew

#174570 - protomank - Sat Jun 26, 2010 6:37 pm

Well, it is just a matter of someone fixing SDL. Sadly, it seems no one with the knowledge in DS development wants to do it.

So, I'll just keep using to old version, and make sure it runs half-ok, while more decent SDL ports like the Dingoo-Linux and PSP gives me more joy ;)
_________________
Iuri Fiedoruk
http://rockbot.upperland.net

#174574 - SteveH - Sun Jun 27, 2010 12:39 pm

The reason that SDL exists at this moment in time on the DS is due to the portee wanting to port something to the DS, and then they ditched the SDL code as soon as they reliased that SDL + DS = Nightmare to implement.

SDL is the worst games lib to exist ever, I used an earler version and all I managed to get was a 10fps animation on my PC at that time, if I went native I got 120fps (Windowed mode BTW) on a fairly decent spec'd P4 PC at the time.

Even professional studios that do cross platform development write everything in a native layer that can be changed at compile time before shiping things out. There's even a book wrote on the subject of cross platform development, and IIRC there's a section on why SDL, and the other cross platform libs, are bad vs native libs.

#174578 - protomank - Mon Jun 28, 2010 12:31 am

Well, SDL is indeed slower than native ports, but the portability it brings have no price for homebrew developers. Not every person have enought free time or money to make native ports of their projects.
And my experience with SDL is fairly good with Rockbot and several open-source games I've helped to develop, Rockbot for example, is now running so well on Nintendo DS, that I'll probally will have to slow it down a bit :)

I do not have a fps counter, because, on my experience, the FPS system itself does slow down things a good bit, but I am moving the player 3 pixels each loop and animation is smooth, even with a lot of simultaneous sprites (3 npcs and 4 shots/projectiles) and background music. The PC port runs at full speed even on my old eePC 701. The PS2 port runs fine, only have some problems with the sound (that is not caused by SDL itself, but thread rotating).
Another thing: it is WAY MORE EASY than doing native ports.

So, I am happy with it, even if a LOT of people here in DSDev keeps saying that it sucks :)
_________________
Iuri Fiedoruk
http://rockbot.upperland.net

#174580 - elhobbs - Mon Jun 28, 2010 12:44 am

if it runs so well on the ds using sdl then what are you going on about?

#174587 - protomank - Mon Jun 28, 2010 12:10 pm

In the mean time after I posted here, I found a way to optimize drawing the sprites, so that this is not a problem anymore :)

The fact is that I've recycled an old RPG engine I had, while the map did not scroll most of time, so each sprite had a copy of it's background to clear the screen when it moved. Also, not all sprites moved at same time.

Rockbot is a side scrolling game, so I've tryied to repaint all screen each loop, thus clearing all the sprites, and then redraw them. What I tought would be slower, in fact is faster, and else it will free some memory (no backup of the screen in each sprite/surface needed anymore).

All in all, SDL can be fast, it just depends what you are trying to do with it ;)
_________________
Iuri Fiedoruk
http://rockbot.upperland.net

#174588 - elhobbs - Mon Jun 28, 2010 2:33 pm

I thought you said the buttons were broken in the ds port of sdl? How are you getting around that?

#174590 - protomank - Mon Jun 28, 2010 2:38 pm

Do not ask me WHY, but after I've upgraded my machine to the lastest Ubuntu.. the problem simply vanished.
It could be that I had some trash in the libraries.
Or maybe because the compatibility gcc is now 4.1 instead of 4.2 in Ubuntu.
Or maybe some magic unicorn flyied under a rainbow and fixed it when a butterfly winged in Japan...

I do now have an answer, but I am happy that it is working ;)
I'll drop a test build for you guys to check it out soon.
_________________
Iuri Fiedoruk
http://rockbot.upperland.net