author | koda |
Wed, 05 Oct 2011 01:06:58 +0200 | |
changeset 6084 | e692c0348e74 |
parent 6083 | 72c882c0fd0f |
child 6209 | 074ab6ebcb3e |
permissions | -rw-r--r-- |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
1 |
/* |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
3 |
* Copyright (c) 2009-2011 Vittorio Giovara <vittorio.giovara@gmail.com> |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
4 |
* |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
7 |
* the Free Software Foundation; version 2 of the License |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
8 |
* |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
13 |
* |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
17 |
* |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
18 |
* File created on 18/04/2011. |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
19 |
*/ |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
20 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
21 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
22 |
#import "GameInterfaceBridge.h" |
6078
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
6020
diff
changeset
|
23 |
#import "ServerSetup.h" |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
24 |
#import "EngineProtocolNetwork.h" |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
25 |
#import "OverlayViewController.h" |
5158
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
26 |
#import "StatsPageViewController.h" |
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
5709
diff
changeset
|
27 |
#import "AudioManagerController.h" |
5174
f5294509783e
initial refactoring of ObjcExports and OverlayViewController
koda
parents:
5166
diff
changeset
|
28 |
#import "ObjcExports.h" |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
29 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
30 |
@implementation GameInterfaceBridge |
5206 | 31 |
@synthesize parentController, savePath, overlayController, engineProtocol, ipcPort, gameType; |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
32 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
33 |
-(id) initWithController:(id) viewController { |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
34 |
if (self = [super init]) { |
6078
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
6020
diff
changeset
|
35 |
self.ipcPort = [ServerSetup randomPort]; |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
36 |
self.gameType = gtNone; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
37 |
self.savePath = nil; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
38 |
|
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
39 |
self.parentController = (UIViewController *)viewController; |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
40 |
self.engineProtocol = [[EngineProtocolNetwork alloc] initOnPort:self.ipcPort]; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
41 |
self.engineProtocol.delegate = self; |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
42 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
43 |
self.overlayController = [[OverlayViewController alloc] initWithNibName:@"OverlayViewController" bundle:nil]; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
44 |
} |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
45 |
return self; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
46 |
} |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
47 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
48 |
-(void) dealloc { |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
49 |
releaseAndNil(engineProtocol); |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
50 |
releaseAndNil(savePath); |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
51 |
releaseAndNil(overlayController); |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
52 |
[super dealloc]; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
53 |
} |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
54 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
55 |
#pragma mark - |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
56 |
// overlay with controls, become visible later, with a transparency effect since the sdlwindow is not yet created |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
57 |
-(void) displayOverlayLater:(id) object { |
5662
99083392cd4f
FREE AT LAST!!! SDL came around a (mostly) sane way for implementing rotation events, so we can scrap all the workaround code that has been added to workaround it!! Also this allows us to use proper (internal) multitasking handling and can simplify optional settings and other yet unexplored features. Yay!
koda
parents:
5370
diff
changeset
|
58 |
// in order to get rotation events we have to insert the view inside the first view of the second window |
99083392cd4f
FREE AT LAST!!! SDL came around a (mostly) sane way for implementing rotation events, so we can scrap all the workaround code that has been added to workaround it!! Also this allows us to use proper (internal) multitasking handling and can simplify optional settings and other yet unexplored features. Yay!
koda
parents:
5370
diff
changeset
|
59 |
// when multihead we have to make sure that overlay is displayed in the touch-enabled window |
99083392cd4f
FREE AT LAST!!! SDL came around a (mostly) sane way for implementing rotation events, so we can scrap all the workaround code that has been added to workaround it!! Also this allows us to use proper (internal) multitasking handling and can simplify optional settings and other yet unexplored features. Yay!
koda
parents:
5370
diff
changeset
|
60 |
UIView *injected = (IS_DUALHEAD() ? self.parentController.view : UIVIEW_HW_SDLVIEW); |
99083392cd4f
FREE AT LAST!!! SDL came around a (mostly) sane way for implementing rotation events, so we can scrap all the workaround code that has been added to workaround it!! Also this allows us to use proper (internal) multitasking handling and can simplify optional settings and other yet unexplored features. Yay!
koda
parents:
5370
diff
changeset
|
61 |
[injected addSubview:self.overlayController.view]; |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
62 |
} |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
63 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
64 |
// main routine for calling the actual game engine |
6083
72c882c0fd0f
first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
6078
diff
changeset
|
65 |
-(void) engineLaunch { |
5156 | 66 |
const char *gameArgs[11]; |
5662
99083392cd4f
FREE AT LAST!!! SDL came around a (mostly) sane way for implementing rotation events, so we can scrap all the workaround code that has been added to workaround it!! Also this allows us to use proper (internal) multitasking handling and can simplify optional settings and other yet unexplored features. Yay!
koda
parents:
5370
diff
changeset
|
67 |
NSInteger width, height; |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
68 |
NSString *ipcString = [[NSString alloc] initWithFormat:@"%d", self.ipcPort]; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
69 |
NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt", [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]]; |
5206 | 70 |
NSUserDefaults *settings = [NSUserDefaults standardUserDefaults]; |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
71 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
72 |
if (IS_DUALHEAD()) { |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
73 |
CGRect screenBounds = [[[UIScreen screens] objectAtIndex:1] bounds]; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
74 |
width = (int) screenBounds.size.width; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
75 |
height = (int) screenBounds.size.height; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
76 |
} else { |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
77 |
CGRect screenBounds = [[UIScreen mainScreen] bounds]; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
78 |
width = (int) screenBounds.size.height; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
79 |
height = (int) screenBounds.size.width; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
80 |
} |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
81 |
|
6078
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
6020
diff
changeset
|
82 |
NSString *horizontalSize = [[NSString alloc] initWithFormat:@"%d", width * (int)[[UIScreen mainScreen] scale]]; |
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
6020
diff
changeset
|
83 |
NSString *verticalSize = [[NSString alloc] initWithFormat:@"%d", height * (int)[[UIScreen mainScreen] scale]]; |
5662
99083392cd4f
FREE AT LAST!!! SDL came around a (mostly) sane way for implementing rotation events, so we can scrap all the workaround code that has been added to workaround it!! Also this allows us to use proper (internal) multitasking handling and can simplify optional settings and other yet unexplored features. Yay!
koda
parents:
5370
diff
changeset
|
84 |
NSString *rotation = [[NSString alloc] initWithString:@"0"]; |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
85 |
|
6078
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
6020
diff
changeset
|
86 |
NSString *modelId = [HWUtils modelType]; |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
87 |
NSInteger tmpQuality; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
88 |
if ([modelId hasPrefix:@"iPhone1"] || [modelId hasPrefix:@"iPod1,1"] || [modelId hasPrefix:@"iPod2,1"]) // = iPhone and iPhone 3G or iPod Touch or iPod Touch 2G |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
89 |
tmpQuality = 0x00000001 | 0x00000002 | 0x00000008 | 0x00000040; // rqLowRes | rqBlurryLand | rqSimpleRope | rqKillFlakes |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
90 |
else if ([modelId hasPrefix:@"iPhone2"] || [modelId hasPrefix:@"iPod3"]) // = iPhone 3GS or iPod Touch 3G |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
91 |
tmpQuality = 0x00000002 | 0x00000040; // rqBlurryLand | rqKillFlakes |
5709 | 92 |
else if ([modelId hasPrefix:@"iPad1"] || [modelId hasPrefix:@"iPod4"]) // = iPad 1G or iPod Touch 4G |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
93 |
tmpQuality = 0x00000002; // rqBlurryLand |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
94 |
else // = everything else |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
95 |
tmpQuality = 0; // full quality |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
96 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
97 |
// disable tooltips on iPhone |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
98 |
if (IS_IPAD() == NO) |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
99 |
tmpQuality = tmpQuality | 0x00000400; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
100 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
101 |
// prevents using an empty nickname |
5206 | 102 |
NSString *username = [settings objectForKey:@"username"]; |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
103 |
if ([username length] == 0) |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
104 |
username = [NSString stringWithFormat:@"MobileUser-%@",ipcString]; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
105 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
106 |
gameArgs[ 0] = [ipcString UTF8String]; //ipcPort |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
107 |
gameArgs[ 1] = [horizontalSize UTF8String]; //cScreenWidth |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
108 |
gameArgs[ 2] = [verticalSize UTF8String]; //cScreenHeight |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
109 |
gameArgs[ 3] = [[NSString stringWithFormat:@"%d",tmpQuality] UTF8String]; //quality |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
110 |
gameArgs[ 4] = "en.txt";//[localeString UTF8String]; //cLocaleFName |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
111 |
gameArgs[ 5] = [username UTF8String]; //UserNick |
5206 | 112 |
gameArgs[ 6] = [[[settings objectForKey:@"sound"] stringValue] UTF8String]; //isSoundEnabled |
113 |
gameArgs[ 7] = [[[settings objectForKey:@"music"] stringValue] UTF8String]; //isMusicEnabled |
|
114 |
gameArgs[ 8] = [[[settings objectForKey:@"alternate"] stringValue] UTF8String]; //cAltDamage |
|
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
115 |
gameArgs[ 9] = [rotation UTF8String]; //rotateQt |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
116 |
gameArgs[10] = (self.gameType == gtSave) ? [self.savePath UTF8String] : NULL; //recordFileName |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
117 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
118 |
[verticalSize release]; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
119 |
[horizontalSize release]; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
120 |
[rotation release]; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
121 |
[localeString release]; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
122 |
[ipcString release]; |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
123 |
|
6078
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
6020
diff
changeset
|
124 |
[ObjcExports initialize]; |
5194 | 125 |
|
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
126 |
// this is the pascal fuction that starts the game, wrapped around isInGame |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
127 |
[HedgewarsAppDelegate sharedAppDelegate].isInGame = YES; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
128 |
Game(gameArgs); |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
129 |
[HedgewarsAppDelegate sharedAppDelegate].isInGame = NO; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
130 |
} |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
131 |
|
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
132 |
// prepares the controllers for hosting a game |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
133 |
-(void) prepareEngineLaunch { |
5157 | 134 |
// we add a black view hiding the background |
5156 | 135 |
CGRect theFrame = CGRectMake(0, 0, self.parentController.view.frame.size.height, self.parentController.view.frame.size.width); |
136 |
UIView *blackView = [[UIView alloc] initWithFrame:theFrame]; |
|
137 |
[self.parentController.view addSubview:blackView]; |
|
138 |
blackView.opaque = YES; |
|
139 |
blackView.backgroundColor = [UIColor blackColor]; |
|
5157 | 140 |
blackView.alpha = 0; |
141 |
// when dual screen we apply a little transition |
|
142 |
if (IS_DUALHEAD()) { |
|
143 |
[UIView beginAnimations:@"fade out" context:NULL]; |
|
144 |
[UIView setAnimationDuration:1]; |
|
145 |
blackView.alpha = 1; |
|
146 |
[UIView commitAnimations]; |
|
5166
d1eb1560b4d5
and now for something completely different, overlay refactoring!
koda
parents:
5158
diff
changeset
|
147 |
} else |
d1eb1560b4d5
and now for something completely different, overlay refactoring!
koda
parents:
5158
diff
changeset
|
148 |
blackView.alpha = 1; |
5157 | 149 |
|
150 |
// prepare options for overlay and add it to the future sdl uiwindow |
|
5195 | 151 |
[self performSelector:@selector(displayOverlayLater:) withObject:nil afterDelay:3]; |
5157 | 152 |
|
5220
76a2246f18f0
when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
5207
diff
changeset
|
153 |
// keep track of uncompleted games |
5224
6e8fbbfb0de5
muuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuusic for the ios frontend finally
koda
parents:
5220
diff
changeset
|
154 |
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; |
6e8fbbfb0de5
muuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuusic for the ios frontend finally
koda
parents:
5220
diff
changeset
|
155 |
[userDefaults setObject:self.savePath forKey:@"savedGamePath"]; |
6e8fbbfb0de5
muuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuusic for the ios frontend finally
koda
parents:
5220
diff
changeset
|
156 |
[userDefaults synchronize]; |
6e8fbbfb0de5
muuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuusic for the ios frontend finally
koda
parents:
5220
diff
changeset
|
157 |
|
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
5709
diff
changeset
|
158 |
[AudioManagerController pauseBackgroundMusic]; |
5220
76a2246f18f0
when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
5207
diff
changeset
|
159 |
|
5157 | 160 |
// SYSTEMS ARE GO!! |
6083
72c882c0fd0f
first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
6078
diff
changeset
|
161 |
[self engineLaunch]; |
5224
6e8fbbfb0de5
muuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuusic for the ios frontend finally
koda
parents:
5220
diff
changeset
|
162 |
|
5220
76a2246f18f0
when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
5207
diff
changeset
|
163 |
// remove completed games notification |
5224
6e8fbbfb0de5
muuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuusic for the ios frontend finally
koda
parents:
5220
diff
changeset
|
164 |
[userDefaults setObject:@"" forKey:@"savedGamePath"]; |
6e8fbbfb0de5
muuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuusic for the ios frontend finally
koda
parents:
5220
diff
changeset
|
165 |
[userDefaults synchronize]; |
5220
76a2246f18f0
when the match is not completed (eg out of memory or crash) the game asks for restoring it as soon as it is opened again
koda
parents:
5207
diff
changeset
|
166 |
|
5157 | 167 |
// now we can remove the cover with a transition |
6020
c792d4b3e080
this finally fixes the interaction between RestoredGameViewController and StatsPagesViewController
koda
parents:
6018
diff
changeset
|
168 |
blackView.frame = theFrame; |
c792d4b3e080
this finally fixes the interaction between RestoredGameViewController and StatsPagesViewController
koda
parents:
6018
diff
changeset
|
169 |
blackView.alpha = 1; |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
170 |
[UIView beginAnimations:@"fade in" context:NULL]; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
171 |
[UIView setAnimationDuration:1]; |
5156 | 172 |
blackView.alpha = 0; |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
173 |
[UIView commitAnimations]; |
5156 | 174 |
[blackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1]; |
175 |
[blackView release]; |
|
176 |
||
5157 | 177 |
// the overlay is not needed any more and can be removed |
178 |
[self.overlayController removeOverlay]; |
|
5158
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
179 |
|
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
180 |
// warn our host that it's going to be visible again |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
181 |
[self.parentController viewWillAppear:YES]; |
5175
a3da220dbb3f
finish overlay refactoring and some leak annihilation
koda
parents:
5174
diff
changeset
|
182 |
|
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
5709
diff
changeset
|
183 |
[AudioManagerController playBackgroundMusic]; |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
184 |
} |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
185 |
|
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
186 |
// set up variables for a local game |
6083
72c882c0fd0f
first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
6078
diff
changeset
|
187 |
-(void) startLocalGame:(NSDictionary *)withOptions { |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
188 |
self.gameType = gtLocal; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
189 |
|
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
190 |
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init]; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
191 |
[outputFormatter setDateFormat:@"yyyy-MM-dd '@' HH.mm"]; |
5696
972bf04d4a79
ios: fix a couple of bad memory management (unrelated to the crash at the end of each game)
koda
parents:
5664
diff
changeset
|
192 |
NSString *path = [[NSString alloc] initWithFormat:@"%@%@.hws",SAVES_DIRECTORY(),[outputFormatter stringFromDate:[NSDate date]]]; |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
193 |
[outputFormatter release]; |
5696
972bf04d4a79
ios: fix a couple of bad memory management (unrelated to the crash at the end of each game)
koda
parents:
5664
diff
changeset
|
194 |
self.savePath = path; |
972bf04d4a79
ios: fix a couple of bad memory management (unrelated to the crash at the end of each game)
koda
parents:
5664
diff
changeset
|
195 |
[path release]; |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
196 |
|
5158
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
197 |
// in the rare case in which a savefile with the same name exists the older one must be removed (or it gets corrupted) |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
198 |
if ([[NSFileManager defaultManager] fileExistsAtPath:self.savePath]) |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
199 |
[[NSFileManager defaultManager] removeItemAtPath:self.savePath error:nil]; |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
200 |
|
6083
72c882c0fd0f
first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
6078
diff
changeset
|
201 |
[self.engineProtocol spawnThread:self.savePath withOptions:withOptions]; |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
202 |
[self prepareEngineLaunch]; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
203 |
} |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
204 |
|
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
205 |
// set up variables for a save game |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
206 |
-(void) startSaveGame:(NSString *)atPath { |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
207 |
self.gameType = gtSave; |
5696
972bf04d4a79
ios: fix a couple of bad memory management (unrelated to the crash at the end of each game)
koda
parents:
5664
diff
changeset
|
208 |
self.savePath = atPath; |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
209 |
|
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
210 |
[self.engineProtocol spawnThread:self.savePath]; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
211 |
[self prepareEngineLaunch]; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
212 |
} |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
213 |
|
6083
72c882c0fd0f
first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
6078
diff
changeset
|
214 |
-(void) startMissionGame:(NSString *)withScript { |
72c882c0fd0f
first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
6078
diff
changeset
|
215 |
self.gameType = gtMission; |
72c882c0fd0f
first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
6078
diff
changeset
|
216 |
self.savePath = nil; |
72c882c0fd0f
first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
6078
diff
changeset
|
217 |
|
6084 | 218 |
NSString *missionPath = [[NSString alloc] initWithFormat:@"escript Missions/Training/%@.lua",withScript]; |
219 |
NSDictionary *config = [NSDictionary dictionaryWithObject:missionPath forKey:@"mission_command"]; |
|
220 |
[missionPath release]; |
|
6083
72c882c0fd0f
first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
6078
diff
changeset
|
221 |
[self.engineProtocol spawnThread:nil withOptions:config]; |
72c882c0fd0f
first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
6078
diff
changeset
|
222 |
[self prepareEngineLaunch]; |
72c882c0fd0f
first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
6078
diff
changeset
|
223 |
} |
72c882c0fd0f
first pass for implementing missions/training selection on ipad (not yet running)
koda
parents:
6078
diff
changeset
|
224 |
|
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
225 |
-(void) gameHasEndedWithStats:(NSArray *)stats { |
6020
c792d4b3e080
this finally fixes the interaction between RestoredGameViewController and StatsPagesViewController
koda
parents:
6018
diff
changeset
|
226 |
// wrap this around a retain/realse to prevent being deallocated too soon |
c792d4b3e080
this finally fixes the interaction between RestoredGameViewController and StatsPagesViewController
koda
parents:
6018
diff
changeset
|
227 |
[self retain]; |
c792d4b3e080
this finally fixes the interaction between RestoredGameViewController and StatsPagesViewController
koda
parents:
6018
diff
changeset
|
228 |
// display stats page if there is something to display |
5158
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
229 |
if (stats != nil) { |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
230 |
StatsPageViewController *statsPage = [[StatsPageViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
231 |
statsPage.statsArray = stats; |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
232 |
statsPage.modalTransitionStyle = UIModalTransitionStyleCoverVertical; |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
233 |
if ([statsPage respondsToSelector:@selector(setModalPresentationStyle:)]) |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
234 |
statsPage.modalPresentationStyle = UIModalPresentationPageSheet; |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
235 |
|
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
236 |
[self.parentController presentModalViewController:statsPage animated:YES]; |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
237 |
[statsPage release]; |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
238 |
} |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
239 |
|
5157 | 240 |
// can remove the savefile if the replay has ended |
241 |
if (self.gameType == gtSave) |
|
242 |
[[NSFileManager defaultManager] removeItemAtPath:self.savePath error:nil]; |
|
6020
c792d4b3e080
this finally fixes the interaction between RestoredGameViewController and StatsPagesViewController
koda
parents:
6018
diff
changeset
|
243 |
[self release]; |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
244 |
} |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
245 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
246 |
@end |