Tiling in SDL
Moderator: PC Supremacists
Tiling in SDL
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.
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.
-
- Chaos Rift Newbie
- Posts: 16
- Joined: Mon Nov 17, 2008 9:56 am
Re: Tiling in SDL
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.
More info about doing this and a tutorial on Lazy Foo.
And even more.
There is no signature.
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: Tiling in SDL
Also, don't worry about the high CPU usage. SDL does that.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
-
- Chaos Rift Newbie
- Posts: 16
- Joined: Mon Nov 17, 2008 9:56 am
Re: Tiling in SDL
So what you mean to say is that SDL is naturaly slow?Ginto8 wrote:Also, don't worry about the high CPU usage. SDL does that.
There is no signature.
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: Tiling in SDL
no.aerosmithfan4ever wrote:So what you mean to say is that SDL is naturaly slow?Ginto8 wrote:Also, don't worry about the high CPU usage. SDL does that.
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?'
just a thought
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: Tiling in SDL
Lol, wtf?aerosmithfan4ever wrote:
And even more.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
Re: Tiling in SDL
yeah what exactly was that about rofldandymcgee wrote:Lol, wtf?aerosmithfan4ever wrote:
And even more.
- Kros
- Chaos Rift Regular
- Posts: 136
- Joined: Tue Feb 24, 2009 4:01 pm
- Current Project: N/A
- Favorite Gaming Platforms: PC, Playstation/2/3
- Programming Language of Choice: C++
- Location: Oregon,USA
- Contact:
Re: Tiling in SDL
It doesn't eat that much CPU if you know how to let it rest during your game loop.Ginto8 wrote:Also, don't worry about the high CPU usage. SDL does that.
YouTube ChannelIsaac Asimov wrote:Part of the inhumanity of the computer is that, once it is competently programmed and working smoothly, it is completely honest.
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: Tiling in SDL
Pray tell?Kros wrote:It doesn't eat that much CPU if you know how to let it rest during your game loop.Ginto8 wrote:Also, don't worry about the high CPU usage. SDL does that.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
- RyanPridgeon
- Chaos Rift Maniac
- Posts: 447
- Joined: Sun Sep 21, 2008 1:34 pm
- Current Project: "Triangle"
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C/C++
- Location: UK
- Contact:
Re: Tiling in SDL
You have to either use some complex multi-threading, or you can use SDL_Delay to give the CPU a rest.Ginto8 wrote:Pray tell?Kros wrote:It doesn't eat that much CPU if you know how to let it rest during your game loop.Ginto8 wrote:Also, don't worry about the high CPU usage. SDL does that.
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: Tiling in SDL
I use SDL_Delay, but it still uses a lot of CPU.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
- programmerinprogress
- Chaos Rift Devotee
- Posts: 632
- Joined: Wed Oct 29, 2008 7:31 am
- Current Project: some crazy stuff, i'll tell soon :-)
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++!
- Location: The UK
- Contact:
Re: Tiling in SDL
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.
(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
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
}
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
---------------------------------------------------------------------------------------
I think I can program pretty well, it's my compiler that needs convincing!
---------------------------------------------------------------------------------------
And now a joke to lighten to mood :D
I wander what programming language anakin skywalker used to program C3-PO's AI back on tatooine? my guess is Jawa :P
I think I can program pretty well, it's my compiler that needs convincing!
---------------------------------------------------------------------------------------
And now a joke to lighten to mood :D
I wander what programming language anakin skywalker used to program C3-PO's AI back on tatooine? my guess is Jawa :P