author | koda |
Sat, 28 May 2011 23:40:42 +0200 | |
changeset 5220 | 76a2246f18f0 |
parent 5207 | 4c9ae0f484da |
child 5224 | 6e8fbbfb0de5 |
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" |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
23 |
#import "PascalImports.h" |
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" |
5174
f5294509783e
initial refactoring of ObjcExports and OverlayViewController
koda
parents:
5166
diff
changeset
|
27 |
#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
|
28 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
29 |
@implementation GameInterfaceBridge |
5206 | 30 |
@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
|
31 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
32 |
-(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
|
33 |
if (self = [super init]) { |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
34 |
self.ipcPort = randomPort(); |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
35 |
self.gameType = gtNone; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
36 |
self.savePath = nil; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
37 |
|
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
38 |
self.parentController = (UIViewController *)viewController; |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
39 |
self.engineProtocol = [[EngineProtocolNetwork alloc] initOnPort:self.ipcPort]; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
40 |
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
|
41 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
42 |
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
|
43 |
} |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
44 |
return self; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
45 |
} |
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 |
-(void) dealloc { |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
48 |
releaseAndNil(parentController); |
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 { |
5195 | 58 |
[self.overlayController setInitialOrientation:self.parentController.interfaceOrientation]; |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
59 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
60 |
UIWindow *gameWindow = (IS_DUALHEAD() ? [HedgewarsAppDelegate sharedAppDelegate].uiwindow : [[UIApplication sharedApplication] keyWindow]); |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
61 |
[gameWindow addSubview:self.overlayController.view]; |
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 |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
65 |
-(void) startGameEngine { |
5156 | 66 |
const char *gameArgs[11]; |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
67 |
NSInteger width, height, orientation; |
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 |
orientation = 0; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
77 |
} else { |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
78 |
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
|
79 |
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
|
80 |
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
|
81 |
orientation = (self.parentController.interfaceOrientation == UIDeviceOrientationLandscapeLeft) ? -90 : 90; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
82 |
} |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
83 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
84 |
NSString *horizontalSize = [[NSString alloc] initWithFormat:@"%d", width]; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
85 |
NSString *verticalSize = [[NSString alloc] initWithFormat:@"%d", height]; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
86 |
NSString *rotation = [[NSString alloc] initWithFormat:@"%d", orientation]; |
5206 | 87 |
BOOL enhanced = [[settings objectForKey:@"enhanced"] boolValue]; |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
88 |
|
5207
4c9ae0f484da
some general tweaks (more intelligent use of macros and more caching)
koda
parents:
5206
diff
changeset
|
89 |
NSString *modelId = getModelType(); |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
90 |
NSInteger tmpQuality; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
91 |
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
|
92 |
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
|
93 |
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
|
94 |
tmpQuality = 0x00000002 | 0x00000040; // rqBlurryLand | rqKillFlakes |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
95 |
else if ([modelId hasPrefix:@"iPad1"] || [modelId hasPrefix:@"iPod4"] || enhanced == NO) // = iPad 1G or iPod Touch 4G or not enhanced mode |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
96 |
tmpQuality = 0x00000002; // rqBlurryLand |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
97 |
else // = everything else |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
98 |
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
|
99 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
100 |
// 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
|
101 |
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
|
102 |
tmpQuality = tmpQuality | 0x00000400; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
103 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
104 |
// prevents using an empty nickname |
5206 | 105 |
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
|
106 |
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
|
107 |
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
|
108 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
109 |
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
|
110 |
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
|
111 |
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
|
112 |
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
|
113 |
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
|
114 |
gameArgs[ 5] = [username UTF8String]; //UserNick |
5206 | 115 |
gameArgs[ 6] = [[[settings objectForKey:@"sound"] stringValue] UTF8String]; //isSoundEnabled |
116 |
gameArgs[ 7] = [[[settings objectForKey:@"music"] stringValue] UTF8String]; //isMusicEnabled |
|
117 |
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
|
118 |
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
|
119 |
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
|
120 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
121 |
[verticalSize release]; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
122 |
[horizontalSize release]; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
123 |
[rotation release]; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
124 |
[localeString release]; |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
125 |
[ipcString release]; |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
126 |
|
5194 | 127 |
objcExportsInit(self.overlayController); |
128 |
||
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
129 |
// 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
|
130 |
[HedgewarsAppDelegate sharedAppDelegate].isInGame = YES; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
131 |
Game(gameArgs); |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
132 |
[HedgewarsAppDelegate sharedAppDelegate].isInGame = NO; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
133 |
} |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
134 |
|
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
135 |
// prepares the controllers for hosting a game |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
136 |
-(void) prepareEngineLaunch { |
5157 | 137 |
// we add a black view hiding the background |
5156 | 138 |
CGRect theFrame = CGRectMake(0, 0, self.parentController.view.frame.size.height, self.parentController.view.frame.size.width); |
139 |
UIView *blackView = [[UIView alloc] initWithFrame:theFrame]; |
|
140 |
[self.parentController.view addSubview:blackView]; |
|
141 |
blackView.opaque = YES; |
|
142 |
blackView.backgroundColor = [UIColor blackColor]; |
|
5157 | 143 |
blackView.alpha = 0; |
144 |
// when dual screen we apply a little transition |
|
145 |
if (IS_DUALHEAD()) { |
|
146 |
[UIView beginAnimations:@"fade out" context:NULL]; |
|
147 |
[UIView setAnimationDuration:1]; |
|
148 |
blackView.alpha = 1; |
|
149 |
[UIView commitAnimations]; |
|
5166
d1eb1560b4d5
and now for something completely different, overlay refactoring!
koda
parents:
5158
diff
changeset
|
150 |
} else |
d1eb1560b4d5
and now for something completely different, overlay refactoring!
koda
parents:
5158
diff
changeset
|
151 |
blackView.alpha = 1; |
5157 | 152 |
|
153 |
// prepare options for overlay and add it to the future sdl uiwindow |
|
5195 | 154 |
[self performSelector:@selector(displayOverlayLater:) withObject:nil afterDelay:3]; |
5157 | 155 |
|
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
|
156 |
// keep track of uncompleted games |
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
|
157 |
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; |
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
|
158 |
[defaults setObject:self.savePath forKey:@"savedGamePath"]; |
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 |
[defaults synchronize]; |
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
|
160 |
|
5157 | 161 |
// SYSTEMS ARE GO!! |
162 |
[self startGameEngine]; |
|
163 |
||
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
|
164 |
// remove completed games notification |
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
|
165 |
[defaults setObject:@"" forKey:@"savedGamePath"]; |
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 |
[defaults synchronize]; |
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
|
167 |
|
5157 | 168 |
// now we can remove the cover with a transition |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
169 |
[UIView beginAnimations:@"fade in" context:NULL]; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
170 |
[UIView setAnimationDuration:1]; |
5156 | 171 |
blackView.alpha = 0; |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
172 |
[UIView commitAnimations]; |
5156 | 173 |
[blackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1]; |
174 |
[blackView release]; |
|
175 |
||
5157 | 176 |
// the overlay is not needed any more and can be removed |
177 |
[self.overlayController removeOverlay]; |
|
5158
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
178 |
|
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
179 |
// warn our host that it's going to be visible again |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
180 |
[self.parentController viewWillAppear:YES]; |
5175
a3da220dbb3f
finish overlay refactoring and some leak annihilation
koda
parents:
5174
diff
changeset
|
181 |
|
a3da220dbb3f
finish overlay refactoring and some leak annihilation
koda
parents:
5174
diff
changeset
|
182 |
// release the network manager and the savepath as they are not needed anymore |
a3da220dbb3f
finish overlay refactoring and some leak annihilation
koda
parents:
5174
diff
changeset
|
183 |
[self.engineProtocol release]; |
a3da220dbb3f
finish overlay refactoring and some leak annihilation
koda
parents:
5174
diff
changeset
|
184 |
[self.savePath release]; |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
185 |
} |
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
186 |
|
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
187 |
// set up variables for a local game |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
188 |
-(void) startLocalGame:(NSDictionary *)withDictionary { |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
189 |
self.gameType = gtLocal; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
190 |
|
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
191 |
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init]; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
192 |
[outputFormatter setDateFormat:@"yyyy-MM-dd '@' HH.mm"]; |
5175
a3da220dbb3f
finish overlay refactoring and some leak annihilation
koda
parents:
5174
diff
changeset
|
193 |
self.savePath = [[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
|
194 |
[outputFormatter release]; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
195 |
|
5158
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
196 |
// 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
|
197 |
if ([[NSFileManager defaultManager] fileExistsAtPath:self.savePath]) |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
198 |
[[NSFileManager defaultManager] removeItemAtPath:self.savePath error:nil]; |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
199 |
|
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
200 |
[self.engineProtocol spawnThread:self.savePath withOptions:withDictionary]; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
201 |
[self prepareEngineLaunch]; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
202 |
} |
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 |
// set up variables for a save game |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
205 |
-(void) startSaveGame:(NSString *)atPath { |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
206 |
self.gameType = gtSave; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
207 |
self.savePath = atPath; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
208 |
|
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
209 |
[self.engineProtocol spawnThread:self.savePath]; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
210 |
[self prepareEngineLaunch]; |
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
211 |
} |
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 |
-(void) gameHasEndedWithStats:(NSArray *)stats { |
5158
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
214 |
// display stats page |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
215 |
if (stats != nil) { |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
216 |
StatsPageViewController *statsPage = [[StatsPageViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
217 |
statsPage.statsArray = stats; |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
218 |
statsPage.modalTransitionStyle = UIModalTransitionStyleCoverVertical; |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
219 |
if ([statsPage respondsToSelector:@selector(setModalPresentationStyle:)]) |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
220 |
statsPage.modalPresentationStyle = UIModalPresentationPageSheet; |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
221 |
|
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
222 |
[self.parentController presentModalViewController:statsPage animated:YES]; |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
223 |
[statsPage release]; |
4941df038b95
stats implemented once again! refactoring complete \o/
koda
parents:
5157
diff
changeset
|
224 |
} |
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
225 |
|
5157 | 226 |
// can remove the savefile if the replay has ended |
227 |
if (self.gameType == gtSave) |
|
228 |
[[NSFileManager defaultManager] removeItemAtPath:self.savePath error:nil]; |
|
5155
f2165724605c
more refactoring, less warnings, less stuff kept around
koda
parents:
5154
diff
changeset
|
229 |
} |
5154
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
230 |
|
851f36579ed4
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff
changeset
|
231 |
@end |