I’ve been doing a lot of research on this and while I haven’t attempted an implementation (I just hacked the SDL code to call back into my code), I want to explain where I’m coming from. It does not look like, especially for me, anything but callbacks will work.
There are really 4 message we are looking at (the patch floating around only handles 2 of them, plus memory low.)
applicationWillResignActive
applicationDidEnterBackground
applicationWillEnterForeground
applicationDidBecomeActive
How Apple wants you to handle this is:
applicationWillResignActive - slow down or stop your loops
applicationDidEnterBackground - save your state
NOTE, and this is very important. If you have a tight loop, it will CONTINUE TO RUN during these messages. ResignActive is called first (where you should shut down your loops) and EnterBackground is next, where you have 5 seconds to save your state. After 5 seconds, your code is frozen.
The big problem is you need to deal with your loop. In ResignActive, I’ll need to use a mutex to make sure my loop has completed one trip before I release back to the OS, and before I get EnterBackground. Otherwise, my game will still be generating state and there will be all sorts of havok. Yes, I’m running a tight loop instead of responding to timers, I understand the ins-and-outs of this
The opposite number, EnterForeground and BecomeActive, basically have the same problem in reverse, but should be solved by making sure the loop pauses in the right place.
Even worse, your code is frozen so you can’t poll for events; therefore you will never get the “memory low warnings.” Without a doubt, games are going to be the number one targets of this and iOS will just send a KILL to your app after you do nothing on a memory warning.
As I was looking through this, I also noticed that there is a bizarre bit of code to deal with the terminate message. This is also something that should be in the callback, we’ll just have to know if we write an iOS application to handle quiting in a callback. The same thing applies – need to mutex the loop and then quit.
Now, you CAN get away with this (in a manner) in the queued polling, you’re just asking for a large number or hard to debug crashes in the future.
The original patch is still good. It just needs to add:
applicationDidEnterBackground
applicationWillEnterForeground
applicationWillTerminate
And probably that wacky long jump stuff can go.
[>] Brian