Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Tile organisation during redraw...

This topic is 6340 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay a quickie question for all the experts here I''m very new to this 2d tile lark and found the gamedev articles archive very useful. I ''ported'' the DirectX examples to SDL and now wonder which is fastest / better... 1. Putting all my ground tiles in one big surface. Every redraw use some math to blit the tiles from this each frame. (Thats ALOT of mults if you ask me!) OR 2. At init, load my tiles into an array of ''mini'' surfaces. When I come to redraw my map, I use the map ''index'' to reference the tile I want to blit from my array of mini surfaces. Phew! Did that come out right? So which does everybody think is best? Personally, I find number 2 more ''elegant'' I just wondered if there was some weirdo 2d hardware reason why this could be bad. Also, I''m not planning on changing these tiles during the ''game'', so would uploading them to video RAM be a better idea too? Thanks for your time, Paul. (OpenGL guy - not with all this 2d gubbins!)

Share this post


Link to post
Share on other sites
Advertisement
I personally use the first option for the following reasons:

1) Easier to maintain palettes across tiles, if I use 256 mode.
2) I never have tiles that are not a power of 2 in size (1,2,4,8,16,32,64,etc), this is so I can use bit shifts for speed.
3) Uses less memory than storing tiles on a per tile basis IMHO, since I do not need to have a pointer to another surface for each tile.

If you decide to go to a one file for all tiles, try and arrang your tiles on a power of 2 per row i.e. 8,16,32 tiles across. This will allow you to use bit shifts and a bitwise and operation to get the tile cell, then use bit shifts to get the cell offsets.

I''ve also found that using SDL is slow so using something else, like a custom wrapper that you wrote yourself (if possible), is faster.

Before anyone starts to flame me about the SDL comment this is my experience and since I have used CDX & SDL on my system I found CDX (an inferiour product IMHO to SDL) was faster.

When I find my code in tons of trouble,
Friends and colleages come to me,
Speaking words of wisdom:
"Write in C."

Share this post


Link to post
Share on other sites
Thanks for the reply. People do seem to have wildly different opinions of SDL - seems fast enough for me so far...

Share this post


Link to post
Share on other sites
Just a quick update

I''ve gone with method (1) from above, done a little optimising, hell I''ve even read some of SDL''s documentation. You have to use SDL_DisplayFormat on your tileset, that converts it the exactly the same format as the screen.

Doing this gives me a 23x speed increase from a bizarrly awful 24fps to ~540fps (!)
Like I said if I run the app un-vsynched in fullscreen I get around 540fps, windowed however it goes down to about 40fps. Go figure.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!