# HG changeset patch # User Xeli # Date 1321290231 -3600 # Node ID db58a42bb5e7d8ae1bdfaab1f331af949267c928 # Parent 9df5a486f41e0bdcab6eb0f0265dc07bb13244b0# Parent cba81e10235c0b851f43ea5d5221f1a60ff498ef merge diff -r 9df5a486f41e -r db58a42bb5e7 hedgewars/SDLh.pas --- a/hedgewars/SDLh.pas Mon Nov 14 18:03:31 2011 +0100 +++ b/hedgewars/SDLh.pas Mon Nov 14 18:03:51 2011 +0100 @@ -41,8 +41,8 @@ {$IFDEF HAIKU} {$linklib root} {$ELSE} - {$IFNDEF ANDROID} - {$linklib pthread} + {$IFNDEF ANDROID} + {$linklib pthread} {$ENDIF} {$ENDIF} {$ENDIF} @@ -464,9 +464,6 @@ text: array[0..31] of Byte; end; - SDL_TouchID = LongInt; - SDL_FingerID = LongInt; - TSDL_TouchFingerEvent = record type_: LongWord; windowId: LongWord; @@ -615,8 +612,6 @@ {$ENDIF} end; -//TODO: implement SDL_TouchButtonEvent, SDL_MultiGestureEvent, SDL_DollarGestureEvent - TSDL_QuitEvent = record type_: {$IFDEF SDL13}LongWord{$ELSE}Byte{$ENDIF}; end; @@ -865,9 +860,9 @@ procedure SDL_StartTextInput; cdecl; external SDLLibName; function SDL_PeepEvents(event: PSDL_Event; numevents: LongInt; action: SDL_eventaction; minType, maxType: LongWord): LongInt; cdecl; external SDLLibName; -function SDL_CreateThread(fn: pointer; name: PChar; data: pointer): PSDL_Thread; cdecl; external SDLLibName; +function SDL_CreateThread(fn: Pointer; name: PChar; data: Pointer): PSDL_Thread; cdecl; external SDLLibName; {$ELSE} -function SDL_CreateThread(fn: pointer; data: pointer): PSDL_Thread; cdecl; external SDLLibName; +function SDL_CreateThread(fn: Pointer; data: Pointer): PSDL_Thread; cdecl; external SDLLibName; function SDL_PeepEvents(event: PSDL_Event; numevents: LongInt; action: SDL_eventaction; mask: LongWord): LongInt; cdecl; external SDLLibName; {$ENDIF} diff -r 9df5a486f41e -r db58a42bb5e7 hedgewars/hwengine.pas --- a/hedgewars/hwengine.pas Mon Nov 14 18:03:31 2011 +0100 +++ b/hedgewars/hwengine.pas Mon Nov 14 18:03:51 2011 +0100 @@ -31,7 +31,8 @@ uses SDLh, uMisc, uConsole, uGame, uConsts, uLand, uAmmos, uVisualGears, uGears, uStore, uWorld, uKeys, uSound, uScript, uTeams, uStats, uIO, uLocale, uChat, uAI, uAIMisc, uRandom, uLandTexture, uCollisions, - sysutils, uTypes, uVariables, uCommands, uUtils, uCaptions, uDebug, uCommandHandlers, uLandPainted,uTouch {$IFDEF ANDROID}, GLUnit {$ENDIF}; + sysutils, uTypes, uVariables, uCommands, uUtils, uCaptions, uDebug, uCommandHandlers, uLandPainted + {$IFDEF SDL13}, uTouch{$ENDIF}{$IFDEF ANDROID}, GLUnit{$ENDIF}; {$IFDEF HWLIBRARY} procedure initEverything(complete:boolean); @@ -258,8 +259,6 @@ cBits:= 32; cFullScreen:= false; cTimerInterval:= 8; - PathPrefix:= 'Data'; - UserPathPrefix:= '../Documents'; cShowFPS:= {$IFDEF DEBUGFILE}true{$ELSE}false{$ENDIF}; val(gameArgs[0], ipcPort); val(gameArgs[1], cScreenWidth); @@ -273,7 +272,7 @@ isMusicEnabled:= gameArgs[7] = '1'; cAltDamage:= gameArgs[8] = '1'; PathPrefix:= gameArgs[9]; - UserPathPrefix:= PathPrefix; + UserPathPrefix:= '../Documents'; recordFileName:= gameArgs[10]; cStereoMode:= smNone; {$ENDIF} @@ -388,10 +387,8 @@ if complete then begin -{$IFDEF ANDROID} - GLUnit.init; -{$ENDIF} - uTouch.initModule; +{$IFDEF ANDROID}GLUnit.init;{$ENDIF} +{$IFDEF SDL13}uTouch.initModule;{$ENDIF} uAI.initModule; //uAIActions does not need initialization //uAIAmmoTests does not need initialization diff -r 9df5a486f41e -r db58a42bb5e7 hedgewars/uAI.pas --- a/hedgewars/uAI.pas Mon Nov 14 18:03:31 2011 +0100 +++ b/hedgewars/uAI.pas Mon Nov 14 18:03:51 2011 +0100 @@ -320,10 +320,7 @@ //TODO: sdl_thread works on device but crashes in simulator, most likely because of outdated toolchain BeginThread(@Think, Me, ThinkThread); {$ELSE} -{$IFDEF SDL13} -ThinkThread := SDL_CreateThread(@Think, nil, Me); -{$ELSE} -ThinkThread := SDL_CreateThread(@Think, Me); +ThinkThread := SDL_CreateThread(@Think{$IFDEF SDL13}, nil{$ENDIF}, Me); {$ENDIF} {$ENDIF} AddFileLog('Thread started'); diff -r 9df5a486f41e -r db58a42bb5e7 hedgewars/uGame.pas --- a/hedgewars/uGame.pas Mon Nov 14 18:03:31 2011 +0100 +++ b/hedgewars/uGame.pas Mon Nov 14 18:03:51 2011 +0100 @@ -26,7 +26,7 @@ //////////////////// implementation //////////////////// -uses uKeys, uTeams, uIO, uAI, uGears, uSound, uMobile, uVisualGears, uTypes, uVariables, uTouch; +uses uKeys, uTeams, uIO, uAI, uGears, uSound, uMobile, uVisualGears, uTypes, uVariables{$IFDEF SDL13}, uTouch{$ENDIF}; procedure DoGameTick(Lag: LongInt); var i: LongInt; @@ -53,7 +53,7 @@ begin if CurrentHedgehog^.BotLevel <> 0 then ProcessBot; ProcessGears; - ProcessTouch; + {$IFDEF SDL13}ProcessTouch;{$ENDIF} end else begin NetGetNextCmd; diff -r 9df5a486f41e -r db58a42bb5e7 hedgewars/uTouch.pas --- a/hedgewars/uTouch.pas Mon Nov 14 18:03:31 2011 +0100 +++ b/hedgewars/uTouch.pas Mon Nov 14 18:03:51 2011 +0100 @@ -24,6 +24,10 @@ uses sysutils, math, uConsole, uVariables, SDLh, uTypes, uFloat, uConsts, uIO, uCommands, GLUnit; +// TODO: this type should be Int64 +// TODO: this type should be named TSDL_FingerId +type SDL_FingerId = LongInt; + type PTouch_Finger = ^Touch_Finger; Touch_Finger = record diff -r 9df5a486f41e -r db58a42bb5e7 hedgewars/uWorld.pas --- a/hedgewars/uWorld.pas Mon Nov 14 18:03:31 2011 +0100 +++ b/hedgewars/uWorld.pas Mon Nov 14 18:03:51 2011 +0100 @@ -306,6 +306,11 @@ inc(g) end; inc(t) + end; + for g:= g to cMaxSlotAmmoIndex do + DrawSprite(sprAMSlot, x + g * AMSlotSize, y, 1); + DrawSprite(sprAMBorderVertical, x + AMWidth - AMxOffset, y, 1); + inc(y, AMSlotSize); end; DrawSprite(sprAMCorners, x - BORDERSIZE, y, 2); diff -r 9df5a486f41e -r db58a42bb5e7 project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m --- a/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m Mon Nov 14 18:03:31 2011 +0100 +++ b/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m Mon Nov 14 18:03:51 2011 +0100 @@ -20,7 +20,6 @@ #import "GameInterfaceBridge.h" -#import "ServerSetup.h" #import "EngineProtocolNetwork.h" #import "OverlayViewController.h" #import "StatsPageViewController.h" @@ -28,46 +27,70 @@ #import "ObjcExports.h" @implementation GameInterfaceBridge -@synthesize parentController, savePath, overlayController, engineProtocol, ipcPort, gameType; +@synthesize blackView; --(id) initWithController:(id) viewController { - if (self = [super init]) { - self.ipcPort = [ServerSetup randomPort]; - self.gameType = gtNone; - self.savePath = nil; +#pragma mark - +#pragma mark Instance methods for engine interaction +// prepares the controllers for hosting a game +-(void) earlyEngineLaunch:(NSString *)pathOrNil withOptions:(NSDictionary *)optionsOrNil { + [self retain]; + [AudioManagerController stopBackgroundMusic]; + [EngineProtocolNetwork spawnThread:pathOrNil withOptions:optionsOrNil]; - self.parentController = (UIViewController *)viewController; - self.engineProtocol = [[EngineProtocolNetwork alloc] initOnPort:self.ipcPort]; - self.engineProtocol.delegate = self; + // add a black view hiding the background + CGRect theFrame = [[UIScreen mainScreen] bounds]; + UIWindow *thisWindow = [[HedgewarsAppDelegate sharedAppDelegate] uiwindow]; + self.blackView = [[UIView alloc] initWithFrame:theFrame]; + self.blackView.opaque = YES; + self.blackView.backgroundColor = [UIColor blackColor]; + self.blackView.alpha = 0; + [UIView beginAnimations:@"fade out" context:NULL]; + [UIView setAnimationDuration:1]; + self.blackView.alpha = 1; + [UIView commitAnimations]; + [thisWindow addSubview:self.blackView]; + [self.blackView release]; - self.overlayController = [[OverlayViewController alloc] initWithNibName:@"OverlayViewController" bundle:nil]; - } - return self; + // keep track of uncompleted games + NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; + [userDefaults setObject:pathOrNil forKey:@"savedGamePath"]; + [userDefaults synchronize]; + + // let's launch the engine using this -perfomSelector so that the runloop can deal with queued messages first + [self performSelector:@selector(engineLaunch:) withObject:pathOrNil afterDelay:0.1f]; } --(void) dealloc { - releaseAndNil(engineProtocol); - releaseAndNil(savePath); - releaseAndNil(overlayController); - [super dealloc]; -} +// cleans up everything +-(void) lateEngineLaunch { + // remove completed games notification + NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; + [userDefaults setObject:@"" forKey:@"savedGamePath"]; + [userDefaults synchronize]; -#pragma mark - -// overlay with controls, become visible later, with a transparency effect since the sdlwindow is not yet created --(void) displayOverlayLater:(id) object { - // in order to get rotation events we have to insert the view inside the first view of the second window - // when multihead we have to make sure that overlay is displayed in the touch-enabled window - UIView *injected = (IS_DUALHEAD() ? self.parentController.view : UIVIEW_HW_SDLVIEW); - [injected addSubview:self.overlayController.view]; + // remove the cover view with a transition + self.blackView.alpha = 1; + [UIView beginAnimations:@"fade in" context:NULL]; + [UIView setAnimationDuration:1]; + self.blackView.alpha = 0; + [UIView commitAnimations]; + [self.blackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1]; + + // the overlay is not needed any more and can be removed + [[OverlayViewController mainOverlay] removeOverlay]; + + // restart music and we're done + [AudioManagerController playBackgroundMusic]; + [self release]; } // main routine for calling the actual game engine --(void) engineLaunch { +-(void) engineLaunch:(NSString *)pathOrNil { const char *gameArgs[11]; CGFloat width, height; + NSInteger enginePort = [EngineProtocolNetwork activeEnginePort]; CGFloat screenScale = [[UIScreen mainScreen] safeScale]; - NSString *ipcString = [[NSString alloc] initWithFormat:@"%d", self.ipcPort]; - NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt", [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]]; + NSString *ipcString = [[NSString alloc] initWithFormat:@"%d",enginePort]; + NSString *localeString = [[NSString alloc] initWithFormat:@"%@.txt",[[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]]; NSUserDefaults *settings = [NSUserDefaults standardUserDefaults]; if (IS_DUALHEAD()) { @@ -82,6 +105,7 @@ NSString *horizontalSize = [[NSString alloc] initWithFormat:@"%d", (int)(width * screenScale)]; NSString *verticalSize = [[NSString alloc] initWithFormat:@"%d", (int)(height * screenScale)]; + NSString *resourcePath = [[NSString alloc] initWithFormat:@"%@/Data", [[NSBundle mainBundle] resourcePath]]; NSString *modelId = [HWUtils modelType]; NSInteger tmpQuality; @@ -94,6 +118,8 @@ else // = everything else tmpQuality = 0; // full quality + // disable ammomenu animation + tmpQuality = tmpQuality | 0x00000080; // disable tooltips on iPhone if (IS_IPAD() == NO) tmpQuality = tmpQuality | 0x00000400; @@ -112,115 +138,59 @@ gameArgs[ 6] = [[[settings objectForKey:@"sound"] stringValue] UTF8String]; //isSoundEnabled gameArgs[ 7] = [[[settings objectForKey:@"music"] stringValue] UTF8String]; //isMusicEnabled gameArgs[ 8] = [[[settings objectForKey:@"alternate"] stringValue] UTF8String]; //cAltDamage - gameArgs[ 9] = [[[NSBundle mainBundle] resourcePath] UTF8String]; //PathPrefix - gameArgs[10] = (self.gameType == gtSave) ? [self.savePath UTF8String] : NULL; //recordFileName + gameArgs[ 9] = [resourcePath UTF8String]; //PathPrefix + gameArgs[10] = ([HWUtils gameType] == gtSave) ? [pathOrNil UTF8String] : NULL; //recordFileName [verticalSize release]; [horizontalSize release]; + [resourcePath release]; [localeString release]; [ipcString release]; - [ObjcExports initialize]; + [HWUtils setGameStatus:gsLoading]; + + // this is the pascal function that starts the game + Game(gameArgs); + [self lateEngineLaunch]; +} - // this is the pascal fuction that starts the game, wrapped around isInGame - [HedgewarsAppDelegate sharedAppDelegate].isInGame = YES; - Game(gameArgs); - [HedgewarsAppDelegate sharedAppDelegate].isInGame = NO; +#pragma mark - +#pragma mark Class methods for setting up the engine from outsite ++(void) startGame:(TGameType) type atPath:(NSString *)path withOptions:(NSDictionary *)config { + [HWUtils setGameType:type]; + GameInterfaceBridge *bridge = [[GameInterfaceBridge alloc] init]; + [bridge earlyEngineLaunch:path withOptions:config]; + [bridge release]; } -// prepares the controllers for hosting a game --(void) prepareEngineLaunch { - // we add a black view hiding the background - CGRect theFrame = CGRectMake(0, 0, self.parentController.view.frame.size.height, self.parentController.view.frame.size.width); - UIView *blackView = [[UIView alloc] initWithFrame:theFrame]; - [self.parentController.view addSubview:blackView]; - blackView.opaque = YES; - blackView.backgroundColor = [UIColor blackColor]; - blackView.alpha = 0; - // when dual screen we apply a little transition - if (IS_DUALHEAD()) { - [UIView beginAnimations:@"fade out" context:NULL]; - [UIView setAnimationDuration:1]; - blackView.alpha = 1; - [UIView commitAnimations]; - } else - blackView.alpha = 1; - - // prepare options for overlay and add it to the future sdl uiwindow - [self performSelector:@selector(displayOverlayLater:) withObject:nil afterDelay:3]; - - // keep track of uncompleted games - NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; - [userDefaults setObject:self.savePath forKey:@"savedGamePath"]; - [userDefaults synchronize]; ++(void) startLocalGame:(NSDictionary *)withOptions { + NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init]; + [outputFormatter setDateFormat:@"yyyy-MM-dd '@' HH.mm"]; + NSString *savePath = [[NSString alloc] initWithFormat:@"%@%@.hws",SAVES_DIRECTORY(),[outputFormatter stringFromDate:[NSDate date]]]; + [outputFormatter release]; - [AudioManagerController pauseBackgroundMusic]; - - // SYSTEMS ARE GO!! - [self engineLaunch]; - - // remove completed games notification - [userDefaults setObject:@"" forKey:@"savedGamePath"]; - [userDefaults synchronize]; + // in the rare case in which a savefile with the same name exists the older one must be removed (otherwise it gets corrupted) + if ([[NSFileManager defaultManager] fileExistsAtPath:savePath]) + [[NSFileManager defaultManager] removeItemAtPath:savePath error:nil]; - // now we can remove the cover with a transition - blackView.frame = theFrame; - blackView.alpha = 1; - [UIView beginAnimations:@"fade in" context:NULL]; - [UIView setAnimationDuration:1]; - blackView.alpha = 0; - [UIView commitAnimations]; - [blackView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1]; - [blackView release]; - - // the overlay is not needed any more and can be removed - [self.overlayController removeOverlay]; - - // warn our host that it's going to be visible again - [self.parentController viewWillAppear:YES]; - - [AudioManagerController playBackgroundMusic]; + [self startGame:gtLocal atPath:savePath withOptions:withOptions]; + [savePath release]; } -// set up variables for a local game --(void) startLocalGame:(NSDictionary *)withOptions { - self.gameType = gtLocal; - - NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init]; - [outputFormatter setDateFormat:@"yyyy-MM-dd '@' HH.mm"]; - NSString *path = [[NSString alloc] initWithFormat:@"%@%@.hws",SAVES_DIRECTORY(),[outputFormatter stringFromDate:[NSDate date]]]; - [outputFormatter release]; - self.savePath = path; - [path release]; - - // in the rare case in which a savefile with the same name exists the older one must be removed (or it gets corrupted) - if ([[NSFileManager defaultManager] fileExistsAtPath:self.savePath]) - [[NSFileManager defaultManager] removeItemAtPath:self.savePath error:nil]; - - [self.engineProtocol spawnThread:self.savePath withOptions:withOptions]; - [self prepareEngineLaunch]; ++(void) startSaveGame:(NSString *)atPath { + [self startGame:gtSave atPath:atPath withOptions:nil]; } -// set up variables for a save game --(void) startSaveGame:(NSString *)atPath { - self.gameType = gtSave; - self.savePath = atPath; ++(void) startMissionGame:(NSString *)withScript { + NSString *missionPath = [[NSString alloc] initWithFormat:@"escript Missions/Training/%@.lua",withScript]; + NSDictionary *missionLine = [[NSDictionary alloc] initWithObjectsAndKeys:missionPath,@"mission_command",nil]; + [missionPath release]; - [self.engineProtocol spawnThread:self.savePath]; - [self prepareEngineLaunch]; + [self startGame:gtMission atPath:nil withOptions:missionLine]; + [missionLine release]; } --(void) startMissionGame:(NSString *)withScript { - self.gameType = gtMission; - self.savePath = nil; - - NSString *missionPath = [[NSString alloc] initWithFormat:@"escript Missions/Training/%@.lua",withScript]; - NSDictionary *config = [NSDictionary dictionaryWithObject:missionPath forKey:@"mission_command"]; - [missionPath release]; - [self.engineProtocol spawnThread:nil withOptions:config]; - [self prepareEngineLaunch]; -} - +/* -(void) gameHasEndedWithStats:(NSArray *)stats { // wrap this around a retain/realse to prevent being deallocated too soon [self retain]; @@ -237,9 +207,10 @@ } // can remove the savefile if the replay has ended - if (self.gameType == gtSave) + if ([HWUtils gameType] == gtSave) [[NSFileManager defaultManager] removeItemAtPath:self.savePath error:nil]; [self release]; } +*/ @end diff -r 9df5a486f41e -r db58a42bb5e7 project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj --- a/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj Mon Nov 14 18:03:31 2011 +0100 +++ b/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj Mon Nov 14 18:03:51 2011 +0100 @@ -366,12 +366,12 @@ 6103D39C129B350700911D8D /* arrowRight@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "arrowRight@2x.png"; path = "Resources/Overlay/arrowRight@2x.png"; sourceTree = ""; }; 6103D39D129B350700911D8D /* arrowUp@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "arrowUp@2x.png"; path = "Resources/Overlay/arrowUp@2x.png"; sourceTree = ""; }; 6103D39E129B350700911D8D /* cornerButton@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "cornerButton@2x.png"; path = "Resources/Overlay/cornerButton@2x.png"; sourceTree = ""; }; - 611D7A4F142FDCD3006E0798 /* uTouch.pas */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.pascal; name = uTouch.pas; path = ../../hedgewars/uTouch.pas; sourceTree = SOURCE_ROOT; }; 61077E86143FB09800645B29 /* MissionTrainingViewController-iPad.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = "MissionTrainingViewController-iPad.xib"; sourceTree = ""; }; 61078029143FCCC800645B29 /* startGameButton@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "startGameButton@2x.png"; path = "Resources/Frontend/startGameButton@2x.png"; sourceTree = ""; }; 610782931440EE5C00645B29 /* basicFlags.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = basicFlags.plist; path = Resources/basicFlags.plist; sourceTree = ""; }; 610782941440EE5C00645B29 /* credits.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = credits.plist; path = Resources/credits.plist; sourceTree = ""; }; 610782951440EE5C00645B29 /* gameMods.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = gameMods.plist; path = Resources/gameMods.plist; sourceTree = ""; }; + 611D7A4F142FDCD3006E0798 /* uTouch.pas */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.pascal; name = uTouch.pas; path = ../../hedgewars/uTouch.pas; sourceTree = SOURCE_ROOT; }; 611D9BF812497E9800008271 /* SavedGamesViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SavedGamesViewController.h; sourceTree = ""; }; 611D9BF912497E9800008271 /* SavedGamesViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SavedGamesViewController.m; sourceTree = ""; }; 611D9BFA12497E9800008271 /* SavedGamesViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SavedGamesViewController.xib; sourceTree = ""; };