| How to make SDL 2.0, iOS work together. (Game Center too) |
|
BJ
|
The problem is that SDL uses a pull messaging system, but iOS requires a pull system. Here is how to get the two working together correctly.
(I am using this on a project that is on PC and iOS) This only change that I made to SDL was as follows
This stops SDL processing all the events ( I added a return at the top of the function ). This fixes SDL crashing some times when other views are laid over the top. The problem of needing the long jump is avoided as this message will be processed when iOS sends the message and not during the next update. The next thing that needs to be done is to intercept the events as they occur, fortunately this is an easy thing to do. Create a callback function and inform SDL, like so. Always return 0, this will stop SDL from storing the event.
The event handler looks something like this. (Remember that the events are processed as they occur, so save results when needed)
Not sure these events work I applied the patch http://forums.libsdl.org/viewtopic.php?t=7733&sid=c9ade150b99a01c8f080cdd465f21b11 to this code so I use the SDL_SYSEVENT_WILL_SUSPEND and SDL_SYSEVENT_WILL_SUSPEND events. So now we are half done, the other problem is that SDL runs in a tight loop. It is time to change this to an event driven approach. First SDL_uikitopenglview needs to be modified. Create a new objective c class and implement as follows. (Header first)
The initWithFrame function is a copy of the function in SDL with one exception [self startAnimation];. This is the important part as it sets up the way that we do a loop by callback. The start animation function basically sets up the doLoop function to run every x number of frames. Set this animationFrameInterval variable to 1 to run every frame, 2 for every 2nd frame etc. For more details (and other ways to do this) http://www.ananseproductions.com/game-loops-on-ios/. Call the stopAnimation function when the application is suspended; and call the startAnimation function when the application resumes. Lastly setup the function to run the application runApplicationFrame();.
I am assuming that SDL has already been setup, this can all happen as usual. The important one is the SDL_JoystickUpdate (if you are using it) as it was called in the PollEvent function. Game center and all other iOS windows will now work correctly. Enjoy |
|||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| How to make SDL 2.0, iOS work together. (Game Center too) |
|
Brian Barnes
Guest
|
BJ wrote:
This is the 3rd different solution for this. I want to note a couple problems with it. 1. (I made the same mistake), we don't need to add some new callback to get events in a callback. SDL_EventFilter will actually handle that already, you just need to add the new events. 2. You HAVE to have separate events for will suspend, will resume, did enter background, did enter foreground, low memory, and quit. You can NOT just over ride it as if it's a activate/deactivate, this will NOT follow the guide lines and you WILL have crazy hard to fix crashes. 3. The changes to pump events is unnecessary, just remove the long jump stuff 4. The start/stop animation is a bit different than SDL works anywhere else and is a pretty big mountain to climb. Is that what is causing the game center problem? There's my patch, there's Piotr's patch, and there's this (which doesn't solve other problems). I think the solution is use SDL_EventFilter and just add the necessary 6 events. I can work up a patch that does just this, it's a small change from my patch. Adding these additional calls, through whatever callback mechanism, makes SDL work great for me. Not sure exactly what the game center problem is though, so some of this might be required. [>] Brian _______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||
|
|
||||||||||||||
| How to make SDL 2.0, iOS work together. (Game Center too) |
|
Sam Lantinga
|
BJ, do you have an example of using Game Center with an SDL app set up this way?
Thanks! On Thu, May 3, 2012 at 12:27 AM, BJ wrote:
|
|||||||||||||
|
|
||||||||||||||
| How to make SDL 2.0, iOS work together. (Game Center too) |
|
BJ
|
Yes, I do. I can't give you the commercial version; but I did make a little test app before adding it to the commercial one.
Would you like a copy of the xcode project? |
|||||||||||
|
|
||||||||||||
| How to make SDL 2.0, iOS work together. (Game Center too) |
|
Sam Lantinga
|
Yes please. Thanks!
On Mon, May 28, 2012 at 12:44 AM, Brad Jackson wrote:
|
|||||||||||||||||
|
|
||||||||||||||||||
| How to make SDL 2.0, iOS work together. (Game Center too) |
|
BJ
|
I have just shared the code from my google docs.
Hope that helps. https://docs.google.com/open?id=0B0oC0oisumE2NTk0R0N4MEJibEk |
|||||||||||
|
|
||||||||||||
| Re: How to make SDL 2.0, iOS work together. (Game Center too |
|
BJ
|
The 4th step is essential for Game Center to work, or the messages that the game center windows puts out are lost. iOS expects the applications to take a 'break' between updates to allow other processes to happen.
|
|||||||||||||||
|
|
||||||||||||||||

