project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m
changeset 4454 42bfc1a70968
parent 4356 d1d26f8963a3
child 4504 8906b2409d97
--- a/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m	Thu Dec 02 20:40:30 2010 -0500
+++ b/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m	Sat Dec 04 08:52:57 2010 +0100
@@ -29,6 +29,7 @@
 #import "SDL_video.h"
 #import "SDL_mixer.h"
 #import "PascalImports.h"
+#import "ObjcExports.h"
 #import "CommodityFunctions.h"
 #import "GameSetup.h"
 #import "MainMenuViewController.h"
@@ -222,40 +223,33 @@
 }
 
 -(void) applicationWillResignActive:(UIApplication *)application {
-    if (self.isInGame) {
-        HW_pause();
-
-        // Send every window on every screen a MINIMIZED event.
-        SDL_VideoDevice *_this = SDL_GetVideoDevice();
-        if (!_this)
-            return;
-
-        int i;
-        for (i = 0; i < _this->num_displays; i++) {
-            const SDL_VideoDisplay *display = &_this->displays[i];
-            SDL_Window *window;
-            for (window = display->windows; window != nil; window = window->next)
-                SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
+    UIDevice* device = [UIDevice currentDevice];
+    if ([device respondsToSelector:@selector(isMultitaskingSupported)] &&
+         device.multitaskingSupported &&
+         self.isInGame) {
+        // there is a bug on iphone that presents a sdl view with a black screen, so it returns to frontend
+        if (IS_IPAD())
+            HW_suspend();
+        else {
+            // while screen is loading you can't call HW_terminate() so we close the app
+            if (isGameRunning())
+                HW_terminate(NO);
+            else {
+                // force app closure
+                SDL_SendQuit();
+                HW_terminate(YES);
+                longjmp(*(jump_env()), 1);
+            }
         }
     }
 }
 
 -(void) applicationDidBecomeActive:(UIApplication *)application {
-    if (self.isInGame) {
-        HW_pause();
-
-        // Send every window on every screen a RESTORED event.
-        SDL_VideoDevice *_this = SDL_GetVideoDevice();
-        if (!_this)
-            return;
-
-        int i;
-        for (i = 0; i < _this->num_displays; i++) {
-            const SDL_VideoDisplay *display = &_this->displays[i];
-            SDL_Window *window;
-            for (window = display->windows; window != nil; window = window->next)
-                SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
-        }
+    UIDevice* device = [UIDevice currentDevice];
+    if ([device respondsToSelector:@selector(isMultitaskingSupported)] &&
+         device.multitaskingSupported &&
+         self.isInGame) {
+        HW_resume();
     }
 }