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