Advertisement

Need for speed

Started by December 27, 2000 03:43 PM
11 comments, last by vidlgon 24 years ago
Hi everybody! I''m an idiot. I just found this wonderful board and thought of asking you people about something you''ll probably hang me for. Okay, I have a simple isometric tile-engine. It uses 40x20 sized tiles with 40x96 sized walls and any-sized sprites. I''m using 640x480@16b resolution. My problem is the speed of my engine. Platform: AMD Duron 600 / 128 MB RAM / Matrox G400 FPS: 50-60 (with just tiles - no sprites and no walls) I use SDL (Simple DirectMedia Layer - http://www.libsdl.org) for graphics output, so the problem ain''t in blitting. You all know the way isometric tiling engine works (I have y and x loops and so on) so I won''t be writing anything about that. Is there a way to easily optimize my engine .. umh.. now lets be honest shall we, the engine originally by Jim Adams, without touching asm (please no asm!!! Not these days!)? I would really appreciate any kind of (working) tips and hints. Thank you! vidlgon a fweak''n idiot
If you are NOT using any alpha-blending or shadowing (software manipulation of individual pixels) then be sure that all your graphics are in video memory.

If you have so many graphics that they could never all fit in video memory then work out a caching system that loads the most frequently used graphics in vidmem and the others in sysmem.

If you are using or plan on using alpha blending then you need to keep all graphics that will be involved in the blending in system memory. Create a scratch buffer in system memory where you will build the next frame of animation. Then last you should use a dirty rectangle scheme to transfer the least amount of graphics from the scratch buffer to the vidmem back buffer (or directly to the primary buffer).

It is possible to have your scratch buffer wrap around itself such that if you need to display the next 2 pixels to the left then all you have to draw is 2 pixels x the height of the back buffer.

-hebertjo
Advertisement
SDL might indeed be the problem though, I did some tests with it recently and I cannot say I got very satisfying performance. Even just a SDL_Flip/SDL_UpdateRects would cause things to slow down massivly. This was on a Windows box with DirectX, btw (DGA performs pretty well I hear ). I especially had problems with sw->sw and sw->hw blits, so make sure everything is in the video memory (I don''t thing SDL_LoadBMP does this by default? Well, I''m to lazy to look it up ). I tried sending a post to the mailing list but I didn''t get any satisfying replies, Sam answears everyone but me..boohoo .

"This album was written, recorded and edited at Gröndal, Stockholm in the year of 2000. At this point in time money still ruled the world. Capitalistic thoughts were wide spread. From the sky filled with the fumes of a billionarie''s cigar to the deepest abyss drenched in nuclear waste. A rich kid was a happy kid, oh..dirty, filthy times. Let this be a reminder."
- Fireside, taken from back of the Elite album
Hey thanks for the tips!

I successfully increased FPS by 14-16 by using video
memory. But I''m afraid this is only a temporary solution
because I really am using tons of graphics. I think I have
to start thinking of that tile-caching system. Besides,
70fps is still way too slow.. doubling it would be nice,
but I think it still wouldn''t be enough.
I should be able to get the 70-80fps with maximum stuff on
the screen, like buildings, npc''s and other sprites, lighting
effects, mp3 player on the background, etc.

I''m a bit suprised to hear that the blitting routines in
SDL would be slow... after all, some Windows games are
ported to Linux using SDL and things run smoothly.
Oh well..

And hey, any good ideas on how to make good looking
lights that won''t slow down engine too much? I''m not sure
if I need color lights, but it would be a nice touch. I''m
thinking of using just tile-based lighting, but I''m still a
bit lost on how to actually do it. Currently I''m just using
alpha-blending which is VERY slow. Modifying RGB values during
blitting is also slow. Any good ideas? Hmmh... maybe I
should start a new topic with this one.

Okay well thanks for your advices so far!

vidlgon
I haven''t confirmed that it''s slow under DirectX but I think there might be one or two issues, it seems more gears towards Linux (for a good reason, obviously). Also if you browse the source code you''ll find most if not all blitting routines seem to be made in C, so they could probably be optimized with asm and MMX.

As for lightning alpha blending does seem like the only easy answear...you could probably set up OpenGL to do this for you though (assuming you have one of those kick ass 3D cards which I don''t ).

"This album was written, recorded and edited at Gröndal, Stockholm in the year of 2000. At this point in time money still ruled the world. Capitalistic thoughts were wide spread. From the sky filled with the fumes of a billionarie''s cigar to the deepest abyss drenched in nuclear waste. A rich kid was a happy kid, oh..dirty, filthy times. Let this be a reminder."
- Fireside, taken from back of the Elite album
Well if the problem is in SDL''s blitting
routines, then I''m stuck I''m afraid. And
what comes to using OpenGL, I don''t want to
do that. I think it sucks that simple isometric
tile-engine requires OpenGL.
I have to think of another way of doing things.
Lets take one good example: Diablo II.
Now how the hell can one get that fast engine?!
It runs smoothly even without 3d acceleration
and looks awesomely good.
Well I don''t have so high standards; all I
want from my engine is that can produce
Jagged Alliance 2/Fallout type of graphics with
decent speed even on slower systems.
Well I can dream now can I!

vidlgon a fweak''n idiot
Advertisement
You could try writing your own alpha blitting routine. You could use SDL_Surface''s all the same just do the blitting yourself, lock it up and it''s ready to tampered with . I agree with on the OGL/D3D thing, just because I''m stuck with this old crappy card...grr . A few things you could use to get faster alpha blending would be; RLE encoding (you could only code the fully transulent as a "run" to get rid of any comparision), MMX (asm needed for this), as much pre-calculation as possible (Imagine a [2^bpp-1][2^bpp-1][255] LUT for your alpha blending ), and um, I don''t know . And the golden rule of course, never read from the video memory.

"This album was written, recorded and edited at Gröndal, Stockholm in the year of 2000. At this point in time money still ruled the world. Capitalistic thoughts were wide spread. From the sky filled with the fumes of a billionarie''s cigar to the deepest abyss drenched in nuclear waste. A rich kid was a happy kid, oh..dirty, filthy times. Let this be a reminder."
- Fireside, taken from back of the Elite album
If you want some light effects look under this forumn about 2 months ago..i started a thread about UO (ultima online) and 16-bit lighting effects. Lots of info. Also plenty of how-to threads on alpha blending pixels under the graphics programming forumn.

aka John M.
Never give up. Never surrender!


My system is close (P2-333 Ce instead of the AMD) and I get close to the same results that you posted. Have you looked at the D2 engine? I only get 20FPS with no NPC''s on screen, it jumps to about 10 when any NPC comes onscreen. After a close inspection of a screen shot of the game with no smoothing of the lighting effects reveals that they are using tiles that are 16x8 or 32x16, but do not quote me on this as it has been a while since I looked at a screen shot of the game.

As far as getting 50-60 fps then just for the tile engine that IMHO is a lot better than getting 20-30 FPS on the tile engine alone. Also which version of the SDL wrapper have you got? I read somewhere there is two versions, non DX and a DX one. Make sure you are using the DX one if you plan on sticking with the SDL wrapper.

Any good iso engine would more than likely be wrote in a pure DX (read not SDL) program with ASM optonisations. I''ve wrote my own DX wrapper that works pretty well (well I think so). I had a play with CDX (crap but a good learning wrapper), and SDL and if you do not intend on porting your game over to Linux then I would suggest dumping the SDL (or as I call it the Sadisically Diabolical crap Layer) and looking into writing your own DX Wrapper. As far as your no asm (what do you mean not these days?) statement I have coded a blitter that copyies from my source surface to by back buffer and also outputs to a thrid buffer the tile number as a colour, thus allowing the tile engine to use height maps. Also you have to hit the asm when you want to do the alpha blending under DirectDraw.

If you want I could send you a copy of my ISO test enginge, current status is stopped as I''m working on a good random height map creation routien, and you can use it as much as you want.

Something else you could try is the 3D Iso article that is on the GameDev programming articles section. It''s a good engine that uses D3D to render the tiles and with a couple of changes to the code you can produce a good engine that has walls, etc.

When I find my code in tons of trouble,
Friends and colleages come to me,
Speaking words of wisdom:
"Write in C."
When I find my code in tons of trouble,Friends and colleages come to me,Speaking words of wisdom:"Write in C."My Web Site
Yes you can say there are two versions of SDL, stable and development. There is however no such thing as a non-DX (read GDI) and a DX version. SDL uses DirectX where it is availible (or unless you tell it so) but it can also fall back to using GDI when and if needed. You can set the environment variable SDL_VIDEODRIVER (I think) to explicitly specify which driver it should use. Also, SDL is something more than just a wrapper...just look at the source and you''ll know what I mean.

Also he stated that he didn''t want to use any 3D hw accel., thus no D3D nor any OGL. You should bother to read the posts before you reply.

> Sadisically Diabolical crap Layer

May I ask why that is? Why is it so bad?


"This album was written, recorded and edited at Gröndal, Stockholm in the year of 2000. At this point in time money still ruled the world. Capitalistic thoughts were wide spread. From the sky filled with the fumes of a billionarie''s cigar to the deepest abyss drenched in nuclear waste. A rich kid was a happy kid, oh..dirty, filthy times. Let this be a reminder."
- Fireside, taken from back of the Elite album

This topic is closed to new replies.

Advertisement