restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
authorkoda
Wed, 23 Jan 2013 03:37:27 +0100
changeset 8425 4f226963faef
parent 8424 225ede46e3dc
child 8426 4b66e60c9967
restored ios project file, updated Game() interface, tweaked arg parsing, updated log writing, minor warnings
hedgewars/ArgParsers.inc
hedgewars/uGears.pas
hedgewars/uUtils.pas
hedgewars/uWorld.pas
project_files/HedgewarsMobile/Classes/DefinesAndMacros.h
project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m
project_files/HedgewarsMobile/Classes/PascalImports.h
project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj
--- a/hedgewars/ArgParsers.inc	Mon Jan 21 21:52:49 2013 -0500
+++ b/hedgewars/ArgParsers.inc	Wed Jan 23 03:37:27 2013 +0100
@@ -118,6 +118,7 @@
         // any other mode
         cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp-6)));
 {$ELSE}
+    tmp:= tmp;
     cStereoMode:= smNone;
 {$ENDIF}
 end;
@@ -190,8 +191,8 @@
         {--locale}               2 : cLocaleFName      := getStringParameter (arg, paramIndex, parseParameter);
         {--fullscreen-width}     3 : cFullscreenWidth  := getLongIntParameter(arg, paramIndex, parseParameter);
         {--fullscreen-height}    4 : cFullscreenHeight := getLongIntParameter(arg, paramIndex, parseParameter);
-        {--width}       5 : cWindowedWidth    := getLongIntParameter(arg, paramIndex, parseParameter);
-        {--height}      6 : cWindowedHeight   := getLongIntParameter(arg, paramIndex, parseParameter);
+        {--width}                5 : cWindowedWidth    := getLongIntParameter(arg, paramIndex, parseParameter);
+        {--height}               6 : cWindowedHeight   := getLongIntParameter(arg, paramIndex, parseParameter);
         {--frame-interval}       7 : cTimerInterval    := getLongIntParameter(arg, paramIndex, parseParameter);
         {--volume}               8 : SetVolume          ( getLongIntParameter(arg, paramIndex, parseParameter) );
         {--nomusic}              9 : SetMusic           ( false );
@@ -211,7 +212,7 @@
         {--set-multimedia}      22 : parseClassicParameter(mediaArray,10,paramIndex);
         {--set-everything}      23 : parseClassicParameter(allArray,14,paramIndex);
         {"internal" options}
-        {--internal}            24 : {note it, but do nothing};
+        {--internal}            24 : {$IFDEF HWLIBRARY}isInternal:= true{$ENDIF};
         {--port}                25 : setIpcPort( getLongIntParameter(arg, paramIndex, parseParameter), parseParameter );
         {--recorder}            26 : startVideoRecording(paramIndex);
         {--landpreview}         27 : GameType := gmtLandPreview;
@@ -278,17 +279,32 @@
 procedure parseCommandLine{$IFDEF HWLIBRARY}(argc: LongInt; argv: PPChar){$ENDIF};
 var paramIndex: LongInt;
     paramTotal: LongInt;
+    index, nextIndex: LongInt;
     wrongParameter: boolean;
+//var tmpInt: LongInt;
 begin
-    paramIndex:= 1;
-    paramTotal:={$IFDEF HWLIBRARY}argc{$ELSE}ParamCount{$ENDIF};
+    paramIndex:= {$IFDEF HWLIBRARY}0{$ELSE}1{$ENDIF};
+    paramTotal:= {$IFDEF HWLIBRARY}argc-1{$ELSE}ParamCount{$ENDIF}; //-1 because pascal enumeration is inclusive
+    (*
+    WriteLn(stdout, 'total parameters: ' + inttostr(paramTotal));
+    tmpInt:= 0;
+    while (tmpInt <= paramTotal) do
+        begin
+        WriteLn(stdout, inttostr(tmpInt) + ': ' + {$IFDEF HWLIBRARY}argv[tmpInt]{$ELSE}paramCount(tmpInt){$ENDIF});
+        inc(tmpInt);
+        end;
+    *)
     wrongParameter:= false;
     while (paramIndex <= paramTotal) do
         begin
+        // avoid going past the number of paramTotal (esp. w/ library)
+        index:= paramIndex;
+        if index = paramTotal then nextIndex:= index
+        else nextIndex:= index+1;
         {$IFDEF HWLIBRARY}
-        wrongParameter:= parseParameter( argv[paramIndex], argv[paramIndex+1], paramIndex);
+        wrongParameter:= parseParameter( argv[index], argv[nextIndex], paramIndex);
         {$ELSE}
-        wrongParameter:= parseParameter( ParamStr(paramIndex), ParamStr(paramIndex+1), paramIndex);
+        wrongParameter:= parseParameter( ParamStr(index), ParamStr(nextIndex), paramIndex);
         {$ENDIF}
         inc(paramIndex);
         end;
@@ -298,17 +314,7 @@
 
 {$IFNDEF HWLIBRARY}
 procedure GetParams;
-//var tmpInt: LongInt;
 begin
-    (*
-    tmpInt:=0;
-    while (tmpInt <= ParamCount) do
-        begin
-        WriteLn(stdout, inttostr(tmpInt) + ': ' + ParamStr(tmpInt));
-        inc(tmpInt);
-        end;
-    *)
-
     isInternal:= (ParamStr(1) = '--internal');
 
     UserPathPrefix := '.';
--- a/hedgewars/uGears.pas	Mon Jan 21 21:52:49 2013 -0500
+++ b/hedgewars/uGears.pas	Wed Jan 23 03:37:27 2013 +0100
@@ -56,7 +56,7 @@
 
 
 implementation
-uses uStore, uSound, uTeams, uRandom, uCollisions, uIO, uLandGraphics,
+uses uStore, uSound, uTeams, uRandom, uCollisions, uIO, uLandGraphics, {$IFDEF SDL13}uTouch,{$ENDIF}
     uLocale, uAI, uAmmos, uStats, uVisualGears, uScript, GLunit, uVariables,
     uCommands, uUtils, uTextures, uRenderUtils, uGearsRender, uCaptions, uDebug, uLandTexture,
     uGearsHedgehog, uGearsUtils, uGearsList, uGearsHandlers, uGearsHandlersRope;
--- a/hedgewars/uUtils.pas	Mon Jan 21 21:52:49 2013 -0500
+++ b/hedgewars/uUtils.pas	Wed Jan 23 03:37:27 2013 +0100
@@ -461,16 +461,14 @@
     InitCriticalSection(logMutex);
 {$ENDIF}
 {$I-}
-{$IFDEF MOBILE}
-    {$IFDEF IPHONEOS} Assign(f, UserPathPrefix + '/hw-' + logfileBase + '.log'); {$ENDIF}
-    {$IFDEF ANDROID} Assign(f, pathPrefix + '/' + logfileBase + '.log'); {$ENDIF}
-    i:= i; // avoid hint
-{$ELSE}
-    f:= stdout; // if everything fails, write to stderr
+    f:= stderr; // if everything fails, write to stderr
     if (UserPathPrefix <> '') then
         begin
+        // create directory if it doesn't exist
         if not FileExists(UserPathPrefix + '/Logs/') then
             CreateDir(UserPathPrefix + '/Logs/');
+
+        // if log is locked, write to the next one
         i:= 0;
         while(i < 7) do
             begin
@@ -480,7 +478,6 @@
             inc(i)
             end;
         end;
-{$ENDIF}
     Rewrite(f);
 {$I+}
 {$ENDIF}
--- a/hedgewars/uWorld.pas	Mon Jan 21 21:52:49 2013 -0500
+++ b/hedgewars/uWorld.pas	Wed Jan 23 03:37:27 2013 +0100
@@ -108,7 +108,6 @@
 
 {$IFDEF MOBILE}
       AMSlotSize = 48;
-      AMTITLE    = 30;
 {$ELSE}
       AMSlotSize = 32;
 {$ENDIF}
--- a/project_files/HedgewarsMobile/Classes/DefinesAndMacros.h	Mon Jan 21 21:52:49 2013 -0500
+++ b/project_files/HedgewarsMobile/Classes/DefinesAndMacros.h	Wed Jan 23 03:37:27 2013 +0100
@@ -44,7 +44,7 @@
 
 #define DOCUMENTS_FOLDER()      [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
 
-#define DEBUG_FILE()            [DOCUMENTS_FOLDER() stringByAppendingString:@"/hw-game.log"]
+#define DEBUG_FILE()            [DOCUMENTS_FOLDER() stringByAppendingString:@"/Logs/game0.log"]
 #define BASICFLAGS_FILE()       [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/basicFlags.plist"]
 #define GAMEMODS_FILE()         [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/gameMods.plist"]
 #define CREDITS_FILE()          [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/credits.plist"]
--- a/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m	Mon Jan 21 21:52:49 2013 -0500
+++ b/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m	Wed Jan 23 03:37:27 2013 +0100
@@ -96,7 +96,6 @@
 
 // main routine for calling the actual game engine
 -(void) engineLaunch {
-    const char *gameArgs[11];
     CGFloat width, height;
     CGFloat screenScale = [[UIScreen mainScreen] safeScale];
     NSString *ipcString = [[NSString alloc] initWithFormat:@"%d",self.port];
@@ -127,34 +126,60 @@
     // disable tooltips on iPhone
     if (IS_IPAD() == NO)
         tmpQuality = tmpQuality | 0x00000400;
-
-    // prevents using an empty nickname
-    NSString *username = [settings objectForKey:@"username"];
-    if ([username length] == 0)
-        username = [NSString stringWithFormat:@"MobileUser-%@",ipcString];
+    NSString *rawQuality = [NSString stringWithFormat:@"%d",tmpQuality];
+    NSString *documentsDirectory = DOCUMENTS_FOLDER();
 
-    gameArgs[ 0] = [ipcString UTF8String];                                                      //ipcPort
-    gameArgs[ 1] = [horizontalSize UTF8String];                                                 //cScreenWidth
-    gameArgs[ 2] = [verticalSize UTF8String];                                                   //cScreenHeight
-    gameArgs[ 3] = [[NSString stringWithFormat:@"%d",tmpQuality] UTF8String];                   //quality
-    gameArgs[ 4] = [localeString UTF8String];                                                   //cLocaleFName
-    gameArgs[ 5] = [username UTF8String];                                                       //UserNick
-    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] = [resourcePath UTF8String];                                                   //PathPrefix
-    gameArgs[10] = ([HWUtils gameType] == gtSave) ? [self.savePath UTF8String] : NULL;          //recordFileName
-
+    NSMutableArray *gameParameters = [[NSMutableArray alloc] initWithObjects:
+                                      @"--internal",
+                                      @"--port", ipcString,
+                                      @"--width", horizontalSize,
+                                      @"--height", verticalSize,
+                                      @"--raw-quality", rawQuality,
+                                      @"--locale", localeString,
+                                      @"--prefix", resourcePath,
+                                      @"--user-prefix", documentsDirectory,
+                                      nil];
     [verticalSize release];
     [horizontalSize release];
     [resourcePath release];
     [localeString release];
     [ipcString release];
 
+    NSString *username = [settings objectForKey:@"username"];
+    if ([username length] > 0) {
+        [gameParameters addObject:@"--nick"];
+        [gameParameters addObject: username];
+    }
+
+    if ([[settings objectForKey:@"sound"] boolValue] == NO)
+        [gameParameters addObject:@"--nosound"];
+
+    if ([[settings objectForKey:@"music"] boolValue] == NO)
+        [gameParameters addObject:@"--nomusic"];
+
+    if([[settings objectForKey:@"alternate"] boolValue] == YES)
+        [gameParameters addObject:@"--altdmg"];
+
+    if ([HWUtils gameType] == gtSave)
+        [gameParameters addObject:self.savePath];
+
     [HWUtils setGameStatus:gsLoading];
 
+    int argc = [gameParameters count];
+    const char **argv = (const char **)malloc(sizeof(const char*)*argc);
+    for (int i = 0; i < argc; i++)
+        argv[i] = strdup([[gameParameters objectAtIndex:i] UTF8String]);
+    [gameParameters release];
+
     // this is the pascal function that starts the game
-    Game(gameArgs);
+    Game(argc, argv);
+
+    // cleanup
+    for (int i = 0; i < argc; i++)
+        free((void *)argv[i]);
+    free(argv);
+
+    // moar cleanup
     [self lateEngineLaunch];
 }
 
--- a/project_files/HedgewarsMobile/Classes/PascalImports.h	Mon Jan 21 21:52:49 2013 -0500
+++ b/project_files/HedgewarsMobile/Classes/PascalImports.h	Wed Jan 23 03:37:27 2013 +0100
@@ -28,7 +28,7 @@
      * that you want to use in your non-Pascal code
      */
 
-    void Game(const char *args[]);
+    void Game(const int argc, const char *argv[]);
     void GenLandPreview(void);
     void LoadLocaleWrapper(const char *filename);
 
--- a/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj	Mon Jan 21 21:52:49 2013 -0500
+++ b/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj	Wed Jan 23 03:37:27 2013 +0100
@@ -67,7 +67,6 @@
 		6129B9F711EFB04D0017E305 /* denied.png in Resources */ = {isa = PBXBuildFile; fileRef = 6129B9F611EFB04D0017E305 /* denied.png */; };
 		612CABAB1391CE68005E9596 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 612CABAA1391CE68005E9596 /* AVFoundation.framework */; };
 		61370653117B1D50004EE44A /* Entitlements-Distribution.plist in Resources */ = {isa = PBXBuildFile; fileRef = 61370652117B1D50004EE44A /* Entitlements-Distribution.plist */; };
-		61399013125D19C0003C2DC0 /* uMobile.pas in Sources */ = {isa = PBXBuildFile; fileRef = 61399012125D19C0003C2DC0 /* uMobile.pas */; };
 		6147DAD31253DCDE0010357E /* savesButton.png in Resources */ = {isa = PBXBuildFile; fileRef = 6147DAD21253DCDE0010357E /* savesButton.png */; };
 		61536DF411CEAE7100D87A7E /* GameConfigViewController-iPhone.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6165924A11CA9CB400D6E256 /* GameConfigViewController-iPhone.xib */; };
 		615AD96212073B4D00F2FF04 /* startGameButton.png in Resources */ = {isa = PBXBuildFile; fileRef = 615AD96112073B4D00F2FF04 /* startGameButton.png */; };
@@ -456,7 +455,6 @@
 		6129B9F611EFB04D0017E305 /* denied.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = denied.png; path = Resources/denied.png; sourceTree = "<group>"; };
 		612CABAA1391CE68005E9596 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; };
 		61370652117B1D50004EE44A /* Entitlements-Distribution.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Entitlements-Distribution.plist"; sourceTree = "<group>"; };
-		61399012125D19C0003C2DC0 /* uMobile.pas */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.pascal; name = uMobile.pas; path = ../../hedgewars/uMobile.pas; sourceTree = SOURCE_ROOT; };
 		6147DAD21253DCDE0010357E /* savesButton.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = savesButton.png; path = Resources/Frontend/savesButton.png; sourceTree = "<group>"; };
 		614E333D11DE9A93009DBA4E /* VGSHandlers.inc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.pascal; name = VGSHandlers.inc; path = ../../hedgewars/VGSHandlers.inc; sourceTree = SOURCE_ROOT; };
 		6154A53114C37E4A00F6EEF6 /* Romanian */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Romanian; path = Locale/Romanian.lproj/About.strings; sourceTree = "<group>"; };
@@ -1243,7 +1241,6 @@
 				61A4A39112A5CCC2004D81E6 /* uTypes.pas */,
 				61A4A39212A5CCC2004D81E6 /* uUtils.pas */,
 				61A4A39312A5CCC2004D81E6 /* uVariables.pas */,
-				61399012125D19C0003C2DC0 /* uMobile.pas */,
 				619C5AF3124F7E3100D041AE /* LuaPas.pas */,
 				61E1F4F711D004240016A5AA /* adler32.pas */,
 				617987E7114AA34C00BA94A9 /* hwengine.pas */,
@@ -1711,7 +1708,6 @@
 				611D9BFB12497E9800008271 /* SavedGamesViewController.m in Sources */,
 				619C5AF4124F7E3100D041AE /* LuaPas.pas in Sources */,
 				619C5BA2124FA59000D041AE /* MapPreviewButtonView.m in Sources */,
-				61399013125D19C0003C2DC0 /* uMobile.pas in Sources */,
 				61D205A1127CDD1100ABD83E /* ObjcExports.m in Sources */,
 				61006F95128DE31F00EBA7F7 /* CreationChamber.m in Sources */,
 				61A4A39412A5CCC2004D81E6 /* uCommandHandlers.pas in Sources */,