project_files/HedgewarsMobile/Classes/HedgewarsAppDelegate.m
changeset 5662 99083392cd4f
parent 5503 d8632f589008
child 5699 1a9a6a7662aa
equal deleted inserted replaced
5660:1647244b3ffe 5662:99083392cd4f
   120         [titleView release];
   120         [titleView release];
   121         [self.secondWindow makeKeyAndVisible];
   121         [self.secondWindow makeKeyAndVisible];
   122     }
   122     }
   123 }
   123 }
   124 
   124 
   125 -(void) applicationWillTerminate:(UIApplication *)application {
   125 -(void) applicationDidReceiveMemoryWarning:(UIApplication *)application {
   126     if (self.isInGame)
   126     // don't stop music when it is playing
   127         HW_terminate(YES);
   127     if (self.isInGame) {
   128 
   128         [self.backgroundMusic stop];
   129     [super applicationWillTerminate:application];
   129         releaseAndNil(self.backgroundMusic);
       
   130         MSG_MEMCLEAN();
       
   131     }
       
   132     print_free_memory();
       
   133     // don't clean mainMenuViewController here!!!
   130 }
   134 }
   131 
   135 
   132 -(void) applicationDidReceiveMemoryWarning:(UIApplication *)application {
   136 -(void) applicationWillResignActive:(UIApplication *)application {
   133     // don't clean mainMenuViewController here!!!
   137     // true multitasking with sdl works only on 4.2 and above; we close the game to avoid a black screen at return
   134     [self.backgroundMusic stop];
   138     if (self.isInGame && ([[[UIDevice currentDevice] systemVersion] floatValue] < 4.2f))
   135     self.backgroundMusic = nil;
   139         HW_terminate(NO);
   136     MSG_MEMCLEAN();
   140     [super applicationWillResignActive:application];
   137     print_free_memory();
       
   138 }
   141 }
   139 
   142 
   140 //TODO: when the SDLUIKitDelegate methods applicationWillResignActive and applicationDidBecomeActive do work
       
   141 // you'll be able to remove the methods below and just handle the SDL_WINDOWEVENT_MINIMIZED/SDL_WINDOWEVENT_RESTORED
       
   142 // events in the MainLoop
       
   143 
       
   144 -(void) applicationWillResignActive:(UIApplication *)application {
       
   145     //[super applicationWillResignActive:application];
       
   146 
       
   147     UIDevice *device = [UIDevice currentDevice];
       
   148     if ([device respondsToSelector:@selector(isMultitaskingSupported)] &&
       
   149          [device isMultitaskingSupported] && self.isInGame) {
       
   150         // let's try to be permissive with multitasking here...
       
   151         if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"multitasking"] boolValue])
       
   152             HW_suspend();
       
   153         else {
       
   154             // so the game returns to the configuration view
       
   155             if (isGameRunning())
       
   156                 HW_terminate(NO);
       
   157             else {
       
   158                 // while screen is loading you can't call HW_terminate() so we close the app
       
   159                 [self applicationWillTerminate:application];
       
   160             }
       
   161         }
       
   162     }
       
   163 }
       
   164 
       
   165 -(void) applicationDidBecomeActive:(UIApplication *)application {
       
   166     //[super applicationDidBecomeActive:application];
       
   167 
       
   168     UIDevice *device = [UIDevice currentDevice];
       
   169     if ([device respondsToSelector:@selector(isMultitaskingSupported)] &&
       
   170          [device isMultitaskingSupported] && self.isInGame) {
       
   171         HW_resume();
       
   172     }
       
   173 }
       
   174 
   143 
   175 @end
   144 @end