Page 1 of 1

Tiling in SDL

Posted: Wed Feb 18, 2009 9:01 pm
by Jazonxyz
Well, I'm making a cool little demo involving tiling.

What is the most efficient way to do it according to you guys?

Should I use 32x32 tile in a 640x480 screen?

I am currently using 40x40 tiles in an 800x600 screen and just drawing the map is chewing up about 20 percent of my processor.

Re: Tiling in SDL

Posted: Fri Mar 13, 2009 1:50 pm
by aerosmithfan4ever
Hmm, make sure that you show only tiles that are inside your camera boundaries.

More info about doing this and a tutorial on Lazy Foo.

And even more. :)

Re: Tiling in SDL

Posted: Fri Mar 13, 2009 2:31 pm
by Ginto8
Also, don't worry about the high CPU usage. SDL does that. ;)

Re: Tiling in SDL

Posted: Fri Mar 13, 2009 2:59 pm
by aerosmithfan4ever
Ginto8 wrote:Also, don't worry about the high CPU usage. SDL does that. ;)
So what you mean to say is that SDL is naturaly slow? :roll:

Re: Tiling in SDL

Posted: Fri Mar 13, 2009 3:16 pm
by Ginto8
aerosmithfan4ever wrote:
Ginto8 wrote:Also, don't worry about the high CPU usage. SDL does that. ;)
So what you mean to say is that SDL is naturaly slow? :roll:
:roll: no.

I was just saying it takes up a bit of CPU. I'm guessing the logic the SDL makers had is, "Give them the utility, even if it has a lot of overhead. Besides, who multitasks while playing a game?' :lol:

just a thought :mrgreen: ;)

Re: Tiling in SDL

Posted: Fri Mar 13, 2009 7:47 pm
by dandymcgee
aerosmithfan4ever wrote:
And even more. :)
Lol, wtf? :lol:

Re: Tiling in SDL

Posted: Fri Mar 13, 2009 7:51 pm
by deryni21
dandymcgee wrote:
aerosmithfan4ever wrote:
And even more. :)
Lol, wtf? :lol:
yeah what exactly was that about rofl :lol: :lol:

Re: Tiling in SDL

Posted: Fri Mar 13, 2009 8:27 pm
by Kros
Ginto8 wrote:Also, don't worry about the high CPU usage. SDL does that. ;)
It doesn't eat that much CPU if you know how to let it rest during your game loop.

Re: Tiling in SDL

Posted: Fri Mar 13, 2009 8:31 pm
by Ginto8
Kros wrote:
Ginto8 wrote:Also, don't worry about the high CPU usage. SDL does that. ;)
It doesn't eat that much CPU if you know how to let it rest during your game loop.
Pray tell?

Re: Tiling in SDL

Posted: Sat Mar 14, 2009 6:00 am
by RyanPridgeon
Ginto8 wrote:
Kros wrote:
Ginto8 wrote:Also, don't worry about the high CPU usage. SDL does that. ;)
It doesn't eat that much CPU if you know how to let it rest during your game loop.
Pray tell?
You have to either use some complex multi-threading, or you can use SDL_Delay to give the CPU a rest.

Re: Tiling in SDL

Posted: Sat Mar 14, 2009 7:42 am
by Ginto8
I use SDL_Delay, but it still uses a lot of CPU. :shock:

Re: Tiling in SDL

Posted: Sat Mar 14, 2009 8:11 am
by programmerinprogress
I know this isn't a complete solution to your problem (although I deem it pretty substantial) here it goes...

SDL can test for certain window events, such as inacticity or if the window has been minimised, if you were able to write some functions which tested for inactive or minimised window, you could make stop your game from drawing (and everything else) when you select a different window.

It's not a complete solution, but at least you will cut down on the CPU usage, and you can, in a sense 'pause' your program while you attempt other things.

I haven't had time to anaylse and lookup all of the functions and SDL constants in the DocWiki yet, but I believe our good friend LazyFoo could step in here and lend us a hand http://lazyfoo.net/SDL_tutorials/lesson26/index.php

I'm interested in the outcome of this, so i'll be looking into these events myself when I have the time :)

EDIT: had a bit of a peek at the docWiki, and I think i've found something relating to this topic that should be of some help
http://www.libsdl.org/cgi/docwiki.cgi/SDL_GetAppState

SDL_GetAppState appears to determine whether a window is in focus, by mouse, or keyboard or if it's minimised etc.

This one is a bit of an odd one, because using a simple '==' won't cut it, it's a function that uses bitwise logic.

So this is how you get it to work.

Code: Select all

if(SDL_GetAppState & SDL_APPINPUTFOCUS)
{
  // do something 
}
else 
{
 //do something else 
}
(note that we have to use the ampersand bitwise operator '&' instead of the equality operator)
if you include your drawing and updating in the APPINPUTFOCUS part, then your program SHOULD only do those things when the window is in focus, but i've only done very simple tests on this, so if anyone gets anything different, post the conclusion