we get our own AppDelegate, subclassing SDL_UikitAppDelegate so that we don't have to mess with sdl build system
authorkoda
Sun, 13 Mar 2011 03:43:18 +0100
changeset 5002 a9c44a8ffec8
parent 5001 312f4dd41753
child 5004 2efa6a414518
we get our own AppDelegate, subclassing SDL_UikitAppDelegate so that we don't have to mess with sdl build system
project_files/HedgewarsMobile/Classes/GameConfigViewController.m
project_files/HedgewarsMobile/Classes/GameSetup.m
project_files/HedgewarsMobile/Classes/HedgewarsAppDelegate.h
project_files/HedgewarsMobile/Classes/HedgewarsAppDelegate.m
project_files/HedgewarsMobile/Classes/InGameMenuViewController.m
project_files/HedgewarsMobile/Classes/MainMenuViewController.m
project_files/HedgewarsMobile/Classes/ObjcExports.m
project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.h
project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m
project_files/HedgewarsMobile/Classes/SavedGamesViewController.m
project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.m
project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj
project_files/HedgewarsMobile/Hedgewars_Prefix.pch
--- a/project_files/HedgewarsMobile/Classes/GameConfigViewController.m	Sat Mar 12 22:55:25 2011 +0300
+++ b/project_files/HedgewarsMobile/Classes/GameConfigViewController.m	Sun Mar 13 03:43:18 2011 +0100
@@ -20,7 +20,6 @@
 
 
 #import "GameConfigViewController.h"
-#import "SDL_uikitappdelegate.h"
 #import "MapConfigViewController.h"
 #import "TeamConfigViewController.h"
 #import "SchemeWeaponConfigViewController.h"
@@ -242,11 +241,11 @@
 
     NSArray *stats;
     if (IS_DUALHEAD()) {
-        stats = [[SDLUIKitDelegate sharedAppDelegate] startSDLgame:allDataNecessary];
+        stats = [[HedgewarsAppDelegate sharedAppDelegate] startSDLgame:allDataNecessary];
         [self presentModalViewController:statsPage animated:NO];
     } else {
         [self performSelector:@selector(presentModalViewController:animated:) withObject:statsPage afterDelay:3];
-        stats = [[SDLUIKitDelegate sharedAppDelegate] startSDLgame:allDataNecessary];
+        stats = [[HedgewarsAppDelegate sharedAppDelegate] startSDLgame:allDataNecessary];
     }
 
     if ([stats count] <= 1) {
--- a/project_files/HedgewarsMobile/Classes/GameSetup.m	Sat Mar 12 22:55:25 2011 +0300
+++ b/project_files/HedgewarsMobile/Classes/GameSetup.m	Sun Mar 13 03:43:18 2011 +0100
@@ -20,7 +20,6 @@
 
 
 #import "GameSetup.h"
-#import "SDL_uikitappdelegate.h"
 #import "PascalImports.h"
 #import "CommodityFunctions.h"
 #import "OverlayViewController.h"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/HedgewarsMobile/Classes/HedgewarsAppDelegate.h	Sun Mar 13 03:43:18 2011 +0100
@@ -0,0 +1,48 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997-2011 Sam Lantinga
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+    Sam Lantinga
+    slouken@libsdl.org
+*/
+
+#import <UIKit/UIKit.h>
+#import "SDL_uikitappdelegate.h"
+
+@class MainMenuViewController;
+@class OverlayViewController;
+
+@interface HedgewarsAppDelegate:SDLUIKitDelegate {
+    MainMenuViewController *mainViewController;
+    OverlayViewController *overlayController;
+    UIWindow *uiwindow;
+    UIWindow *secondWindow;
+    BOOL isInGame;
+}
+
+@property (assign) BOOL isInGame;
+@property (nonatomic,retain) MainMenuViewController *mainViewController;
+@property (nonatomic,retain) OverlayViewController *overlayController;
+@property (nonatomic,retain) UIWindow *uiwindow;
+@property (nonatomic,retain) UIWindow *secondWindow;
+
++(HedgewarsAppDelegate *)sharedAppDelegate;
+-(NSArray *)startSDLgame:(NSDictionary *)gameDictionary;
+-(void) displayOverlayLater:(id) object;
+
+@end
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/HedgewarsMobile/Classes/HedgewarsAppDelegate.m	Sun Mar 13 03:43:18 2011 +0100
@@ -0,0 +1,261 @@
+/*
+ SDL - Simple DirectMedia Layer
+ Copyright (C) 1997-2011 Sam Lantinga
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+ Sam Lantinga, mods for Hedgewars by Vittorio Giovara
+ slouken@libsdl.org, vittorio.giovara@gmail.com
+*/
+
+#import "HedgewarsAppDelegate.h"
+#import "PascalImports.h"
+#import "ObjcExports.h"
+#import "CommodityFunctions.h"
+#import "GameSetup.h"
+#import "MainMenuViewController.h"
+#import "OverlayViewController.h"
+#import "Appirater.h"
+#include <unistd.h>
+
+#ifdef main
+#undef main
+#endif
+
+#define BLACKVIEW_TAG 17935
+#define SECONDBLACKVIEW_TAG 48620
+#define VALGRIND "/opt/fink/bin/valgrind"
+
+int main (int argc, char *argv[]) {
+#ifdef VALGRIND_REXEC
+    // Using the valgrind build config, rexec ourself in valgrind
+    // from http://landonf.bikemonkey.org/code/iphone/iPhone_Simulator_Valgrind.20081224.html
+    if (argc < 2 || (argc >= 2 && strcmp(argv[1], "-valgrind") != 0))
+        execl(VALGRIND, VALGRIND, "--leak-check=full", "--dsymutil=yes", argv[0], "-valgrind", NULL);
+#endif
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+    int retVal = UIApplicationMain(argc, argv, nil, @"HedgewarsAppDelegate");
+    [pool release];
+    return retVal;
+}
+
+int SDL_main(int argc, char **argv) {
+    // dummy function to prevent linkage fail
+    return 0;
+}
+
+@implementation HedgewarsAppDelegate
+@synthesize mainViewController, overlayController, uiwindow, secondWindow, isInGame;
+
+// convenience method
++(HedgewarsAppDelegate *)sharedAppDelegate {
+    return (HedgewarsAppDelegate *)[[UIApplication sharedApplication] delegate];
+}
+
+-(id) init {
+    if (self = [super init]){
+        mainViewController = nil;
+        uiwindow = nil;
+        secondWindow = nil;
+        isInGame = NO;
+    }
+    return self;
+}
+
+-(void) dealloc {
+    [mainViewController release];
+    [overlayController release];
+    [uiwindow release];
+    [secondWindow release];
+    [super dealloc];
+}
+
+// main routine for calling the actual game engine
+-(NSArray *)startSDLgame:(NSDictionary *)gameDictionary {
+    UIWindow *gameWindow;
+    if (IS_DUALHEAD())
+        gameWindow = self.secondWindow;
+    else
+        gameWindow = self.uiwindow;
+
+    UIView *blackView = [[UIView alloc] initWithFrame:gameWindow.frame];
+    blackView.backgroundColor = [UIColor blackColor];
+    blackView.opaque = YES;
+    blackView.tag = BLACKVIEW_TAG;
+    [gameWindow addSubview:blackView];
+    if (IS_DUALHEAD()) {
+        blackView.alpha = 0;
+        [UIView beginAnimations:@"fading to game first" context:NULL];
+        [UIView setAnimationDuration:1];
+        blackView.alpha = 1;
+        [UIView commitAnimations];
+
+        UIView *secondBlackView = [[UIView alloc] initWithFrame:self.uiwindow.frame];
+        secondBlackView.backgroundColor = [UIColor blackColor];
+        secondBlackView.opaque = YES;
+        secondBlackView.tag = SECONDBLACKVIEW_TAG;
+        secondBlackView.alpha = 0;
+        [self.uiwindow addSubview:secondBlackView];
+        [UIView beginAnimations:@"fading to game second" context:NULL];
+        [UIView setAnimationDuration:1];
+        secondBlackView.alpha = 1;
+        [UIView commitAnimations];
+        [secondBlackView release];
+    }
+    [blackView release];
+
+
+    // pull out useful configuration info from various files
+    GameSetup *setup = [[GameSetup alloc] initWithDictionary:gameDictionary];
+    NSNumber *isNetGameNum = [gameDictionary objectForKey:@"netgame"];
+
+    [NSThread detachNewThreadSelector:@selector(engineProtocol)
+                             toTarget:setup
+                           withObject:nil];
+
+    NSNumber *menuStyle = [NSNumber numberWithBool:setup.menuStyle];
+    NSNumber *orientation = [[gameDictionary objectForKey:@"game_dictionary"] objectForKey:@"orientation"];
+    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
+                          isNetGameNum,@"net",
+                          menuStyle,@"menu",
+                          orientation,@"orientation",
+                          nil];
+    [self performSelector:@selector(displayOverlayLater:) withObject:dict afterDelay:1];
+
+    // need to set again [gameDictionary objectForKey:@"savefile"] because if it's empty it means it's a normal game
+    const char **gameArgs = [setup getGameSettings:[gameDictionary objectForKey:@"savefile"]];
+    self.isInGame = YES;
+    // this is the pascal fuction that starts the game
+    Game(gameArgs);
+    self.isInGame = NO;
+    free(gameArgs);
+
+    NSArray *stats = setup.statsArray;
+    [setup release];
+
+
+    [self.uiwindow makeKeyAndVisible];
+    [self.uiwindow bringSubviewToFront:self.mainViewController.view];
+
+    UIView *refBlackView = [gameWindow viewWithTag:BLACKVIEW_TAG];
+    UIView *refSecondBlackView = [self.uiwindow viewWithTag:SECONDBLACKVIEW_TAG];
+    [UIView beginAnimations:@"fading in from ingame" context:NULL];
+    [UIView setAnimationDuration:1];
+    refBlackView.alpha = 0;
+    refSecondBlackView.alpha = 0;
+    [UIView commitAnimations];
+    [refBlackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1];
+    [refSecondBlackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:2];
+
+    return stats;
+}
+
+// overlay with controls, become visible later, with a transparency effect since the sdlwindow is not yet created
+-(void) displayOverlayLater:(id) object {
+    NSDictionary *dict = (NSDictionary *)object;
+    self.overlayController = [[OverlayViewController alloc] initWithNibName:@"OverlayViewController" bundle:nil];
+    self.overlayController.isNetGame = [[dict objectForKey:@"net"] boolValue];
+    self.overlayController.useClassicMenu = [[dict objectForKey:@"menu"] boolValue];
+    self.overlayController.initialOrientation = [[dict objectForKey:@"orientation"] intValue];
+
+    UIWindow *gameWindow;
+    if (IS_DUALHEAD())
+        gameWindow = self.uiwindow;
+    else
+        gameWindow = [[UIApplication sharedApplication] keyWindow];
+    [gameWindow addSubview:self.overlayController.view];
+}
+
+// override the direct execution of SDL_main to allow us to implement our own frontend
+-(void) postFinishLaunch {
+    [[UIApplication sharedApplication] setStatusBarHidden:YES];
+    [Appirater appLaunched];
+
+    self.uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
+
+    if (IS_IPAD())
+        self.mainViewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController-iPad" bundle:nil];
+    else
+        self.mainViewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController-iPhone" bundle:nil];
+
+    [self.uiwindow addSubview:self.mainViewController.view];
+    [self.mainViewController release];
+    self.uiwindow.backgroundColor = [UIColor blackColor];
+    [self.uiwindow makeKeyAndVisible];
+
+    // check for dual monitor support
+    if (IS_DUALHEAD()) {
+        DLog(@"dual head mode ftw");
+        self.secondWindow = [[UIWindow alloc] initWithFrame:[[[UIScreen screens] objectAtIndex:1] bounds]];
+        self.secondWindow.backgroundColor = [UIColor blackColor];
+        self.secondWindow.screen = [[UIScreen screens] objectAtIndex:1];
+        UIImage *titleImage = [UIImage imageWithContentsOfFile:@"title.png"];
+        UIImageView *titleView = [[UIImageView alloc] initWithImage:titleImage];
+        titleView.center = self.secondWindow.center;
+        [self.secondWindow addSubview:titleView];
+        [titleView release];
+        [self.secondWindow makeKeyAndVisible];
+    }
+}
+
+-(void) applicationWillTerminate:(UIApplication *)application {
+    if (self.isInGame)
+        HW_terminate(YES);
+
+    [super applicationWillTerminate:application];
+}
+
+-(void) applicationDidReceiveMemoryWarning:(UIApplication *)application {
+    // don't clean mainMenuViewController here!!!
+    MSG_MEMCLEAN();
+    print_free_memory();
+}
+
+-(void) applicationWillResignActive:(UIApplication *)application {
+    [super applicationWillResignActive: application];
+
+    UIDevice* device = [UIDevice currentDevice];
+    if ([device respondsToSelector:@selector(isMultitaskingSupported)] &&
+         device.multitaskingSupported &&
+         self.isInGame) {
+        // let's try to be permissive with multitasking here...
+        NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:SETTINGS_FILE()];
+        if ([[settings objectForKey:@"multitasking"] boolValue])
+            HW_suspend();
+        else {
+            // so the game returns to the configuration view
+            if (isGameRunning())
+                HW_terminate(NO);
+            else {
+                // while screen is loading you can't call HW_terminate() so we close the app
+                [self applicationWillTerminate:application];
+            }
+        }
+        [settings release];
+    }
+}
+
+-(void) applicationDidBecomeActive:(UIApplication *)application {
+    [super applicationDidBecomeActive:application];
+
+    UIDevice* device = [UIDevice currentDevice];
+    if ([device respondsToSelector:@selector(isMultitaskingSupported)] &&
+         device.multitaskingSupported &&
+         self.isInGame) {
+        HW_resume();
+    }
+}
+
+@end
--- a/project_files/HedgewarsMobile/Classes/InGameMenuViewController.m	Sat Mar 12 22:55:25 2011 +0300
+++ b/project_files/HedgewarsMobile/Classes/InGameMenuViewController.m	Sun Mar 13 03:43:18 2011 +0100
@@ -19,7 +19,6 @@
  */
 
 
-#import "SDL_uikitappdelegate.h"
 #import "InGameMenuViewController.h"
 #import "PascalImports.h"
 #import "CommodityFunctions.h"
--- a/project_files/HedgewarsMobile/Classes/MainMenuViewController.m	Sat Mar 12 22:55:25 2011 +0300
+++ b/project_files/HedgewarsMobile/Classes/MainMenuViewController.m	Sun Mar 13 03:43:18 2011 +0100
@@ -21,7 +21,6 @@
 
 #import "MainMenuViewController.h"
 #import "CreationChamber.h"
-#import "SDL_uikitappdelegate.h"
 #import "PascalImports.h"
 #import "GameConfigViewController.h"
 #import "SplitViewRootController.h"
--- a/project_files/HedgewarsMobile/Classes/ObjcExports.m	Sat Mar 12 22:55:25 2011 +0300
+++ b/project_files/HedgewarsMobile/Classes/ObjcExports.m	Sun Mar 13 03:43:18 2011 +0100
@@ -97,7 +97,7 @@
 
 void clearView() {
     // don't use any engine calls here as this function is called every time the ammomenu is opened
-    UIWindow *theWindow = (IS_DUALHEAD()) ? [SDLUIKitDelegate sharedAppDelegate].uiwindow : [[UIApplication sharedApplication] keyWindow];
+    UIWindow *theWindow = (IS_DUALHEAD()) ? [HedgewarsAppDelegate sharedAppDelegate].uiwindow : [[UIApplication sharedApplication] keyWindow];
     UIButton *theButton = (UIButton *)[theWindow viewWithTag:CONFIRMATION_TAG];
     UISegmentedControl *theSegment = (UISegmentedControl *)[theWindow viewWithTag:GRENADE_TAG];
 
--- a/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.h	Sat Mar 12 22:55:25 2011 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-/*
-    SDL - Simple DirectMedia Layer
-    Copyright (C) 1997-2011 Sam Lantinga
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    This library is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-    Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with this library; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-
-    Sam Lantinga
-    slouken@libsdl.org
-*/
-
-#import <UIKit/UIKit.h>
-
-@class MainMenuViewController;
-@class OverlayViewController;
-
-@interface SDLUIKitDelegate:NSObject<UIApplicationDelegate> {
-    MainMenuViewController *mainViewController;
-    OverlayViewController *overlayController;
-    UIWindow *uiwindow;
-    UIWindow *secondWindow;
-    BOOL isInGame;
-}
-
-@property (assign) BOOL isInGame;
-@property (nonatomic,retain) MainMenuViewController *mainViewController;
-@property (nonatomic,retain) OverlayViewController *overlayController;
-@property (nonatomic,retain) UIWindow *uiwindow;
-@property (nonatomic,retain) UIWindow *secondWindow;
-
-+(SDLUIKitDelegate *)sharedAppDelegate;
--(NSArray *)startSDLgame:(NSDictionary *)gameDictionary;
--(void) displayOverlayLater:(id) object;
-
-@end
-
--- a/project_files/HedgewarsMobile/Classes/SDL_uikitappdelegate.m	Sat Mar 12 22:55:25 2011 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,269 +0,0 @@
-/*
- SDL - Simple DirectMedia Layer
- Copyright (C) 1997-2011 Sam Lantinga
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-
- Sam Lantinga, mods for Hedgewars by Vittorio Giovara
- slouken@libsdl.org, vittorio.giovara@gmail.com
-*/
-
-#import "SDL_uikitappdelegate.h"
-#import "SDL_uikitopenglview.h"
-#import "SDL_uikitwindow.h"
-#import "SDL_events_c.h"
-#import "jumphack.h"
-#import "SDL_video.h"
-#import "SDL_mixer.h"
-#import "PascalImports.h"
-#import "ObjcExports.h"
-#import "CommodityFunctions.h"
-#import "GameSetup.h"
-#import "MainMenuViewController.h"
-#import "OverlayViewController.h"
-#import "Appirater.h"
-#include <unistd.h>
-
-#ifdef main
-#undef main
-#endif
-
-#define BLACKVIEW_TAG 17935
-#define SECONDBLACKVIEW_TAG 48620
-#define VALGRIND "/opt/fink/bin/valgrind"
-
-int main (int argc, char *argv[]) {
-#ifdef VALGRIND_REXEC
-    // Using the valgrind build config, rexec ourself in valgrind
-    // from http://landonf.bikemonkey.org/code/iphone/iPhone_Simulator_Valgrind.20081224.html
-    if (argc < 2 || (argc >= 2 && strcmp(argv[1], "-valgrind") != 0))
-        execl(VALGRIND, VALGRIND, "--leak-check=full", "--dsymutil=yes", argv[0], "-valgrind", NULL);
-#endif
-    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-    int retVal = UIApplicationMain(argc, argv, nil, @"SDLUIKitDelegate");
-    [pool release];
-    return retVal;
-}
-
-@implementation SDLUIKitDelegate
-@synthesize mainViewController, overlayController, uiwindow, secondWindow, isInGame;
-
-// convenience method
-+(SDLUIKitDelegate *)sharedAppDelegate {
-    // the delegate is set in UIApplicationMain(), which is guaranteed to be called before this method
-    return (SDLUIKitDelegate *)[[UIApplication sharedApplication] delegate];
-}
-
--(id) init {
-    if (self = [super init]){
-        mainViewController = nil;
-        uiwindow = nil;
-        secondWindow = nil;
-        isInGame = NO;
-    }
-    return self;
-}
-
--(void) dealloc {
-    [mainViewController release];
-    [overlayController release];
-    [uiwindow release];
-    [secondWindow release];
-    [super dealloc];
-}
-
-// main routine for calling the actual game engine
--(NSArray *)startSDLgame:(NSDictionary *)gameDictionary {
-    UIWindow *gameWindow;
-    if (IS_DUALHEAD())
-        gameWindow = self.secondWindow;
-    else
-        gameWindow = self.uiwindow;
-
-    UIView *blackView = [[UIView alloc] initWithFrame:gameWindow.frame];
-    blackView.backgroundColor = [UIColor blackColor];
-    blackView.opaque = YES;
-    blackView.tag = BLACKVIEW_TAG;
-    [gameWindow addSubview:blackView];    
-    if (IS_DUALHEAD()) {
-        blackView.alpha = 0;
-        [UIView beginAnimations:@"fading to game first" context:NULL];
-        [UIView setAnimationDuration:1];
-        blackView.alpha = 1;
-        [UIView commitAnimations];
-        
-        UIView *secondBlackView = [[UIView alloc] initWithFrame:self.uiwindow.frame];
-        secondBlackView.backgroundColor = [UIColor blackColor];
-        secondBlackView.opaque = YES;
-        secondBlackView.tag = SECONDBLACKVIEW_TAG;
-        secondBlackView.alpha = 0;
-        [self.uiwindow addSubview:secondBlackView];
-        [UIView beginAnimations:@"fading to game second" context:NULL];
-        [UIView setAnimationDuration:1];
-        secondBlackView.alpha = 1;
-        [UIView commitAnimations];
-        [secondBlackView release];
-    }
-    [blackView release];
-
-
-    // pull out useful configuration info from various files
-    GameSetup *setup = [[GameSetup alloc] initWithDictionary:gameDictionary];
-    NSNumber *isNetGameNum = [gameDictionary objectForKey:@"netgame"];
-
-    [NSThread detachNewThreadSelector:@selector(engineProtocol)
-                             toTarget:setup
-                           withObject:nil];
-
-    NSNumber *menuStyle = [NSNumber numberWithBool:setup.menuStyle];
-    NSNumber *orientation = [[gameDictionary objectForKey:@"game_dictionary"] objectForKey:@"orientation"];
-    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
-                          isNetGameNum,@"net",
-                          menuStyle,@"menu",
-                          orientation,@"orientation",
-                          nil];
-    [self performSelector:@selector(displayOverlayLater:) withObject:dict afterDelay:1];
-
-    // need to set again [gameDictionary objectForKey:@"savefile"] because if it's empty it means it's a normal game
-    const char **gameArgs = [setup getGameSettings:[gameDictionary objectForKey:@"savefile"]];
-    self.isInGame = YES;
-    // this is the pascal fuction that starts the game
-    Game(gameArgs);
-    self.isInGame = NO;
-    free(gameArgs);
-    
-    NSArray *stats = setup.statsArray;
-    [setup release];
-
-
-    [self.uiwindow makeKeyAndVisible];
-    [self.uiwindow bringSubviewToFront:self.mainViewController.view];
-    
-    UIView *refBlackView = [gameWindow viewWithTag:BLACKVIEW_TAG];
-    UIView *refSecondBlackView = [self.uiwindow viewWithTag:SECONDBLACKVIEW_TAG];
-    [UIView beginAnimations:@"fading in from ingame" context:NULL];
-    [UIView setAnimationDuration:1];
-    refBlackView.alpha = 0;
-    refSecondBlackView.alpha = 0;
-    [UIView commitAnimations];
-    [refBlackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1];
-    [refSecondBlackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:2];
-
-    return stats;
-}
-
-// overlay with controls, become visible later, with a transparency effect since the sdlwindow is not yet created
--(void) displayOverlayLater:(id) object {
-    NSDictionary *dict = (NSDictionary *)object;
-    self.overlayController = [[OverlayViewController alloc] initWithNibName:@"OverlayViewController" bundle:nil];
-    self.overlayController.isNetGame = [[dict objectForKey:@"net"] boolValue];
-    self.overlayController.useClassicMenu = [[dict objectForKey:@"menu"] boolValue];
-    self.overlayController.initialOrientation = [[dict objectForKey:@"orientation"] intValue];
-    
-    UIWindow *gameWindow;
-    if (IS_DUALHEAD())
-        gameWindow = self.uiwindow;
-    else
-        gameWindow = [[UIApplication sharedApplication] keyWindow];
-    [gameWindow addSubview:self.overlayController.view];
-}
-
-// override the direct execution of SDL_main to allow us to implement the frontend (or even using a nib)
--(BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
-    [application setStatusBarHidden:YES];
-
-    self.uiwindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
-
-    if (IS_IPAD())
-        self.mainViewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController-iPad" bundle:nil];
-    else
-        self.mainViewController = [[MainMenuViewController alloc] initWithNibName:@"MainMenuViewController-iPhone" bundle:nil];
-
-    [self.uiwindow addSubview:self.mainViewController.view];
-    [self.mainViewController release];
-    self.uiwindow.backgroundColor = [UIColor blackColor];
-    [self.uiwindow makeKeyAndVisible];
-
-    // set working directory to resource path
-    [[NSFileManager defaultManager] changeCurrentDirectoryPath:[[NSBundle mainBundle] resourcePath]];
-
-    // check for dual monitor support
-    if (IS_DUALHEAD()) {
-        DLog(@"dual head mode ftw");
-        self.secondWindow = [[UIWindow alloc] initWithFrame:[[[UIScreen screens] objectAtIndex:1] bounds]];
-        self.secondWindow.backgroundColor = [UIColor blackColor];
-        self.secondWindow.screen = [[UIScreen screens] objectAtIndex:1];
-        UIImage *titleImage = [UIImage imageWithContentsOfFile:@"title.png"];
-        UIImageView *titleView = [[UIImageView alloc] initWithImage:titleImage];
-        titleView.center = self.secondWindow.center;
-        [self.secondWindow addSubview:titleView];
-        [titleView release];
-        [self.secondWindow makeKeyAndVisible];
-    }
-
-    [Appirater appLaunched];
-    return YES;
-}
-
--(void) applicationWillTerminate:(UIApplication *)application {
-    SDL_SendQuit();
-
-    if (self.isInGame) {
-        HW_terminate(YES);
-        // hack to prevent automatic termination. See SDL_uikitevents.m for details
-        longjmp(*(jump_env()), 1);
-    }
-}
-
--(void) applicationDidReceiveMemoryWarning:(UIApplication *)application {
-    // don't clean mainMenuViewController here!!!
-    MSG_MEMCLEAN();
-    print_free_memory();
-}
-
--(void) applicationWillResignActive:(UIApplication *)application {
-    UIDevice* device = [UIDevice currentDevice];
-    if ([device respondsToSelector:@selector(isMultitaskingSupported)] &&
-         device.multitaskingSupported &&
-         self.isInGame) {
-        // let's try to be permissive with multitasking here...
-        NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:SETTINGS_FILE()];
-        if ([[settings objectForKey:@"multitasking"] boolValue])
-            HW_suspend();
-        else {
-            // so the game returns to the configuration view
-            if (isGameRunning())
-                HW_terminate(NO);
-            else {
-                // while screen is loading you can't call HW_terminate() so we close the app
-                SDL_SendQuit();
-                HW_terminate(YES);
-                longjmp(*(jump_env()), 1);
-            }
-        }
-        [settings release];
-    }
-}
-
--(void) applicationDidBecomeActive:(UIApplication *)application {
-    UIDevice* device = [UIDevice currentDevice];
-    if ([device respondsToSelector:@selector(isMultitaskingSupported)] &&
-         device.multitaskingSupported &&
-         self.isInGame) {
-        HW_resume();
-    }
-}
-
-@end
--- a/project_files/HedgewarsMobile/Classes/SavedGamesViewController.m	Sat Mar 12 22:55:25 2011 +0300
+++ b/project_files/HedgewarsMobile/Classes/SavedGamesViewController.m	Sun Mar 13 03:43:18 2011 +0100
@@ -20,7 +20,6 @@
 
 
 #import "SavedGamesViewController.h"
-#import "SDL_uikitappdelegate.h"
 #import "StatsPageViewController.h"
 #import "CommodityFunctions.h"
 
@@ -228,11 +227,11 @@
 
     NSArray *stats;
     if (IS_DUALHEAD()) {
-        stats = [[SDLUIKitDelegate sharedAppDelegate] startSDLgame:allDataNecessary];
+        stats = [[HedgewarsAppDelegate sharedAppDelegate] startSDLgame:allDataNecessary];
         [self presentModalViewController:statsPage animated:NO];
     } else {
         [self performSelector:@selector(presentModalViewController:animated:) withObject:statsPage afterDelay:3];
-        stats = [[SDLUIKitDelegate sharedAppDelegate] startSDLgame:allDataNecessary];
+        stats = [[HedgewarsAppDelegate sharedAppDelegate] startSDLgame:allDataNecessary];
     }
 
     if ([stats count] <= 1) {
--- a/project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.m	Sat Mar 12 22:55:25 2011 +0300
+++ b/project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.m	Sun Mar 13 03:43:18 2011 +0100
@@ -21,7 +21,6 @@
 
 #import "SchemeWeaponConfigViewController.h"
 #import "CommodityFunctions.h"
-#import "SDL_uikitappdelegate.h"
 
 #define LABEL_TAG 57423
 
@@ -262,7 +261,7 @@
 #pragma mark -
 #pragma mark Memory management
 -(void) didReceiveMemoryWarning {
-    if ([[SDLUIKitDelegate sharedAppDelegate] isInGame]) {
+    if ([[HedgewarsAppDelegate sharedAppDelegate] isInGame]) {
         self.lastIndexPath_sc = nil;
         self.lastIndexPath_we = nil;
         self.listOfSchemes = nil;
--- a/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj	Sat Mar 12 22:55:25 2011 +0300
+++ b/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj	Sun Mar 13 03:43:18 2011 +0100
@@ -111,7 +111,7 @@
 		6165925311CA9CB400D6E256 /* MainMenuViewController-iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6165924B11CA9CB400D6E256 /* MainMenuViewController-iPad.xib */; };
 		6165925511CA9CB400D6E256 /* MapConfigViewController-iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6165924D11CA9CB400D6E256 /* MapConfigViewController-iPad.xib */; };
 		6165925811CA9CB400D6E256 /* OverlayViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6165925011CA9CB400D6E256 /* OverlayViewController.xib */; };
-		6165929E11CA9E2F00D6E256 /* SDL_uikitappdelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6165929D11CA9E2F00D6E256 /* SDL_uikitappdelegate.m */; };
+		6165929E11CA9E2F00D6E256 /* HedgewarsAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6165929D11CA9E2F00D6E256 /* HedgewarsAppDelegate.m */; };
 		6172555A12B3DD4A0098D069 /* libLua.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6172555912B3DCEE0098D069 /* libLua.a */; };
 		6172FED91298CF9800D73365 /* background~iphone.png in Resources */ = {isa = PBXBuildFile; fileRef = 6172FED71298CF9800D73365 /* background~iphone.png */; };
 		6172FEEF1298D25D00D73365 /* mediumBackground~ipad.png in Resources */ = {isa = PBXBuildFile; fileRef = 6172FEEB1298D25D00D73365 /* mediumBackground~ipad.png */; };
@@ -182,7 +182,7 @@
 		61AC067412B2E32D000B52A2 /* Appirater.m in Sources */ = {isa = PBXBuildFile; fileRef = 61AC067312B2E32D000B52A2 /* Appirater.m */; };
 		61B3D71C11EA6F2700EC7420 /* uKeys.pas in Sources */ = {isa = PBXBuildFile; fileRef = 617987FE114AA34C00BA94A9 /* uKeys.pas */; };
 		61B7A33812CC21080086B604 /* StatsPageViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B7A33712CC21080086B604 /* StatsPageViewController.m */; };
-		61B7A61512FA13B00051E14E /* libSDLiPhoneOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 61B7A54E12FA129F0051E14E /* libSDLiPhoneOS.a */; };
+		61B7A61512FA13B00051E14E /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 61B7A54E12FA129F0051E14E /* libSDL.a */; };
 		61B7A61612FA13B00051E14E /* libSDL_image.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 61B7A55812FA12AD0051E14E /* libSDL_image.a */; };
 		61B7A61712FA13B00051E14E /* libSDL_mixer.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 61B7A56012FA12BF0051E14E /* libSDL_mixer.a */; };
 		61B7A61812FA13B00051E14E /* libSDL_net.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 61B7A56812FA12D00051E14E /* libSDL_net.a */; };
@@ -879,8 +879,8 @@
 		6165924D11CA9CB400D6E256 /* MapConfigViewController-iPad.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = "MapConfigViewController-iPad.xib"; path = "Resources/MapConfigViewController-iPad.xib"; sourceTree = SOURCE_ROOT; };
 		6165924E11CA9CB400D6E256 /* MapConfigViewController-iPhone.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = "MapConfigViewController-iPhone.xib"; path = "Resources/MapConfigViewController-iPhone.xib"; sourceTree = SOURCE_ROOT; };
 		6165925011CA9CB400D6E256 /* OverlayViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = OverlayViewController.xib; path = Resources/OverlayViewController.xib; sourceTree = SOURCE_ROOT; };
-		6165929C11CA9E2F00D6E256 /* SDL_uikitappdelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_uikitappdelegate.h; path = Classes/SDL_uikitappdelegate.h; sourceTree = "<group>"; };
-		6165929D11CA9E2F00D6E256 /* SDL_uikitappdelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDL_uikitappdelegate.m; path = Classes/SDL_uikitappdelegate.m; sourceTree = "<group>"; };
+		6165929C11CA9E2F00D6E256 /* HedgewarsAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HedgewarsAppDelegate.h; path = Classes/HedgewarsAppDelegate.h; sourceTree = "<group>"; };
+		6165929D11CA9E2F00D6E256 /* HedgewarsAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = HedgewarsAppDelegate.m; path = Classes/HedgewarsAppDelegate.m; sourceTree = "<group>"; };
 		6172554E12B3DCEE0098D069 /* Lua.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Lua.xcodeproj; path = ../../../Library/Lua/Lua.xcodeproj; sourceTree = SOURCE_ROOT; };
 		6172FEA21298C7F900D73365 /* Default@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Default@2x.png"; path = "Resources/Icons/Default@2x.png"; sourceTree = "<group>"; };
 		6172FEC81298CE4800D73365 /* savesButton@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "savesButton@2x.png"; path = "Resources/Frontend/savesButton@2x.png"; sourceTree = "<group>"; };
@@ -1023,7 +1023,7 @@
 				922F64900F10F53100DC6EC0 /* libfpc.a in Frameworks */,
 				611E03E711FA747C0077A41E /* libvorbis.a in Frameworks */,
 				611E0E5111FA92170077A41E /* libfreetype.a in Frameworks */,
-				61B7A61512FA13B00051E14E /* libSDLiPhoneOS.a in Frameworks */,
+				61B7A61512FA13B00051E14E /* libSDL.a in Frameworks */,
 				61B7A61612FA13B00051E14E /* libSDL_image.a in Frameworks */,
 				61B7A61712FA13B00051E14E /* libSDL_mixer.a in Frameworks */,
 				61B7A61812FA13B00051E14E /* libSDL_net.a in Frameworks */,
@@ -1089,10 +1089,10 @@
 		29B97315FDCFA39411CA2CEA /* Other Sources */ = {
 			isa = PBXGroup;
 			children = (
-				6165929C11CA9E2F00D6E256 /* SDL_uikitappdelegate.h */,
-				6165929D11CA9E2F00D6E256 /* SDL_uikitappdelegate.m */,
 				61AC067212B2E32D000B52A2 /* Appirater.h */,
 				61AC067312B2E32D000B52A2 /* Appirater.m */,
+				6165929C11CA9E2F00D6E256 /* HedgewarsAppDelegate.h */,
+				6165929D11CA9E2F00D6E256 /* HedgewarsAppDelegate.m */,
 				61DE91561258B76800B80214 /* Custom UIs */,
 				32CA4F630368D1EE00C91783 /* Hedgewars_Prefix.pch */,
 				6165922911CA9BD500D6E256 /* PascalImports.h */,
@@ -1403,7 +1403,7 @@
 		61B7A54712FA129F0051E14E /* Products */ = {
 			isa = PBXGroup;
 			children = (
-				61B7A54E12FA129F0051E14E /* libSDLiPhoneOS.a */,
+				61B7A54E12FA129F0051E14E /* libSDL.a */,
 				61B7A55012FA129F0051E14E /* testsdl.app */,
 			);
 			name = Products;
@@ -2151,10 +2151,10 @@
 			remoteRef = 6172555812B3DCEE0098D069 /* PBXContainerItemProxy */;
 			sourceTree = BUILT_PRODUCTS_DIR;
 		};
-		61B7A54E12FA129F0051E14E /* libSDLiPhoneOS.a */ = {
+		61B7A54E12FA129F0051E14E /* libSDL.a */ = {
 			isa = PBXReferenceProxy;
 			fileType = archive.ar;
-			path = libSDLiPhoneOS.a;
+			path = libSDL.a;
 			remoteRef = 61B7A54D12FA129F0051E14E /* PBXContainerItemProxy */;
 			sourceTree = BUILT_PRODUCTS_DIR;
 		};
@@ -2405,7 +2405,7 @@
 				6165922F11CA9BD500D6E256 /* CommodityFunctions.m in Sources */,
 				6165923111CA9BD500D6E256 /* SquareButtonView.m in Sources */,
 				6165923211CA9BD500D6E256 /* UIImageExtra.m in Sources */,
-				6165929E11CA9E2F00D6E256 /* SDL_uikitappdelegate.m in Sources */,
+				6165929E11CA9E2F00D6E256 /* HedgewarsAppDelegate.m in Sources */,
 				6163EE7E11CC2600001C0453 /* SingleWeaponViewController.m in Sources */,
 				61E1F4F811D004240016A5AA /* adler32.pas in Sources */,
 				61F904D711DF7DA30068B24D /* WeaponCellView.m in Sources */,
--- a/project_files/HedgewarsMobile/Hedgewars_Prefix.pch	Sat Mar 12 22:55:25 2011 +0300
+++ b/project_files/HedgewarsMobile/Hedgewars_Prefix.pch	Sun Mar 13 03:43:18 2011 +0100
@@ -23,7 +23,7 @@
 #import "PascalImports.h"
 #import "UIImageExtra.h"
 #import "CommodityFunctions.h"
-#import "SDL_uikitappdelegate.h"
+#import "HedgewarsAppDelegate.h"
 #import "SDL.h"
 #import "SDL_video.h"
 #import "SDL_net.h"