Tiling in SDL

Anything related in any way to game development as a whole is welcome here. Tell us about your game, grace us with your project, show us your new YouTube video, etc.

Moderator: PC Supremacists

Post Reply
Jazonxyz
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 10
Joined: Mon Sep 29, 2008 8:37 pm

Tiling in SDL

Post 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.
aerosmithfan4ever
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 16
Joined: Mon Nov 17, 2008 9:56 am

Re: Tiling in SDL

Post 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. :)
There is no signature.
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Tiling in SDL

Post by Ginto8 »

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.
aerosmithfan4ever
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 16
Joined: Mon Nov 17, 2008 9:56 am

Re: Tiling in SDL

Post 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:
There is no signature.
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Tiling in SDL

Post 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: ;)
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.
User avatar
dandymcgee
ES Beta Backer
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

Post by dandymcgee »

aerosmithfan4ever wrote:
And even more. :)
Lol, wtf? :lol:
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
deryni21
Chaos Rift Regular
Chaos Rift Regular
Posts: 124
Joined: Wed Dec 24, 2008 9:55 pm

Re: Tiling in SDL

Post by deryni21 »

dandymcgee wrote:
aerosmithfan4ever wrote:
And even more. :)
Lol, wtf? :lol:
yeah what exactly was that about rofl :lol: :lol:
Image
User avatar
Kros
Chaos Rift Regular
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

Post 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.
Isaac Asimov wrote:Part of the inhumanity of the computer is that, once it is competently programmed and working smoothly, it is completely honest.
YouTube Channel
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Tiling in SDL

Post 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?
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.
User avatar
RyanPridgeon
Chaos Rift Maniac
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

Post 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.
Ryan Pridgeon
C, C++, C#, Java, ActionScript 3, HaXe, PHP, VB.Net, Pascal
Music | Blog
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Tiling in SDL

Post by Ginto8 »

I use SDL_Delay, but it still uses a lot of CPU. :shock:
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.
User avatar
programmerinprogress
Chaos Rift Devotee
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

Post 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
---------------------------------------------------------------------------------------
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
Post Reply