project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m
author koda
Sun, 17 Apr 2011 20:52:56 +0200
changeset 5154 851f36579ed4
child 5155 f2165724605c
permissions -rw-r--r--
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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"
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    26
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    27
#define BUFFER_SIZE 255     // like in original frontend
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
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    30
@synthesize parentController, systemSettings, savePath, overlayController, ipcPort, gameType, engineProtocol;
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]) {
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    34
        self.parentController = (UIViewController *)viewController;
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    35
        self.engineProtocol = [[EngineProtocolNetwork alloc] init];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    36
;
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    37
        self.savePath = nil;
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    38
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    39
        self.systemSettings = [NSDictionary dictionaryWithContentsOfFile:SETTINGS_FILE()];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    40
        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
    41
        self.ipcPort = randomPort();
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.gameType = gtNone;
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(parentController);
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    50
    releaseAndNil(engineProtocol);
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    51
    releaseAndNil(systemSettings);
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    52
    releaseAndNil(savePath);
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    53
    releaseAndNil(overlayController);
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    54
    [super dealloc];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    55
}
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    56
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    57
#pragma mark -
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    58
// 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
    59
-(void) displayOverlayLater:(id) object {
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    60
    NSDictionary *dict = (NSDictionary *)object;
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    61
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    62
    [self.overlayController setUseClassicMenu:[[dict objectForKey:@"menu"] boolValue]];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    63
    [self.overlayController setInitialOrientation:[[dict objectForKey:@"orientation"] intValue]];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    64
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    65
    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
    66
    [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
    67
}
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    68
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    69
// 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
    70
-(void) startGameEngine {
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    71
    self.parentController.view.opaque = YES;
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    72
    self.parentController.view.backgroundColor = [UIColor blackColor];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    73
    self.parentController.view.alpha = 0;
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    74
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    75
    [UIView beginAnimations:@"fade out to black" context:NULL];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    76
    [UIView setAnimationDuration:1];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    77
    self.parentController.view.alpha = 1;
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    78
    [UIView commitAnimations];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    79
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    80
    self.engineProtocol.savePath = self.savePath;
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    81
    [self.engineProtocol spawnThreadOnPort:self.ipcPort];
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
    NSDictionary *overlayOptions = [[NSDictionary alloc] initWithObjectsAndKeys:
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    84
                                    [NSNumber numberWithInt:self.parentController.interfaceOrientation],@"orientation",
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    85
                                    [self.systemSettings objectForKey:@"menu"],@"menu",
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    86
                                    nil];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    87
    [self performSelector:@selector(displayOverlayLater:) withObject:overlayOptions afterDelay:1];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    88
    [overlayOptions release];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    89
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    90
    // this is the pascal fuction that starts the game, wrapped around isInGame
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    91
    [HedgewarsAppDelegate sharedAppDelegate].isInGame = YES;
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    92
    Game([self gatherGameSettings]);
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    93
    [HedgewarsAppDelegate sharedAppDelegate].isInGame = NO;
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    94
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    95
    [UIView beginAnimations:@"fade in" context:NULL];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    96
    [UIView setAnimationDuration:1];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    97
    self.parentController.view.alpha = 0;
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
    98
    [UIView commitAnimations];
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
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   101
-(void) startLocalGame:(NSDictionary *)withDictionary {
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   102
    self.gameType = gtLocal;
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   103
    [self.engineProtocol setGameConfig:withDictionary];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   104
    
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   105
    NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   106
    [outputFormatter setDateFormat:@"yyyy-MM-dd '@' HH.mm"];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   107
    NSString *newDateString = [outputFormatter stringFromDate:[NSDate date]];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   108
    self.savePath = [SAVES_DIRECTORY() stringByAppendingFormat:@"%@.hws", newDateString];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   109
    [outputFormatter release];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   110
    
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   111
    [self startGameEngine];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   112
}
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   113
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   114
-(void) startSaveGame:(NSString *)atPath {
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   115
    self.gameType = gtSave;
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   116
    self.savePath = atPath;
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   117
    [self.engineProtocol setGameConfig:nil];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   118
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   119
    [self startGameEngine];
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
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   122
#pragma mark -
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   123
-(const char **)gatherGameSettings {
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   124
    const char *gameArgs[10];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   125
    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
   126
    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
   127
    NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt", [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   128
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   129
    if (IS_DUALHEAD()) {
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   130
        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
   131
        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
   132
        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
   133
        orientation = 0;
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   134
    } else {
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   135
        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
   136
        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
   137
        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
   138
        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
   139
    }
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   140
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   141
    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
   142
    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
   143
    NSString *rotation = [[NSString alloc] initWithFormat:@"%d", orientation];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   144
    BOOL enhanced = [[self.systemSettings objectForKey:@"enhanced"] boolValue];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   145
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   146
    NSString *modelId = modelType();
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   147
    NSInteger tmpQuality;
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   148
    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
   149
        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
   150
    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
   151
        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
   152
    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
   153
        tmpQuality = 0x00000002;                                                        // rqBlurryLand
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   154
    else                                                                                                        // = everything else
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   155
        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
   156
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   157
    // 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
   158
    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
   159
        tmpQuality = tmpQuality | 0x00000400;
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   160
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   161
    // prevents using an empty nickname
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   162
    NSString *username = [self.systemSettings objectForKey:@"username"];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   163
    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
   164
        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
   165
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   166
    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
   167
    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
   168
    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
   169
    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
   170
    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
   171
    gameArgs[ 5] = [username UTF8String];                                                       //UserNick
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   172
    gameArgs[ 6] = [[[self.systemSettings objectForKey:@"sound"] stringValue] UTF8String];      //isSoundEnabled
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   173
    gameArgs[ 7] = [[[self.systemSettings objectForKey:@"music"] stringValue] UTF8String];      //isMusicEnabled
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   174
    gameArgs[ 8] = [[[self.systemSettings objectForKey:@"alternate"] stringValue] UTF8String];  //cAltDamage
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   175
    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
   176
    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
   177
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   178
    [verticalSize release];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   179
    [horizontalSize release];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   180
    [rotation release];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   181
    [localeString release];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   182
    [ipcString release];
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   183
    return gameArgs;
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
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   186
851f36579ed4 initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
koda
parents:
diff changeset
   187
@end