convert Game() library call to argc,argv format so that we can use the new parsing functions
authorkoda
Tue, 25 Dec 2012 01:13:07 +0100
changeset 8327 a6f3452f5f94
parent 8326 023a71940f26
child 8328 03684c667664
convert Game() library call to argc,argv format so that we can use the new parsing functions
hedgewars/ArgParsers.inc
hedgewars/hwengine.pas
--- a/hedgewars/ArgParsers.inc	Mon Dec 24 12:52:14 2012 -0500
+++ b/hedgewars/ArgParsers.inc	Tue Dec 25 01:13:07 2012 +0100
@@ -267,22 +267,28 @@
     WriteLn(stdout, '');
 end;
 
-procedure playReplayFileWithParameters;
+procedure parseCommandLine{$IFDEF HWLIBRARY}(argc: LongInt; argv: PPChar){$ENDIF};
 var paramIndex: LongInt;
+    paramTotal: LongInt;
     wrongParameter: boolean;
 begin
     paramIndex:= 1;
+    paramTotal:={$IFDEF HWLIBRARY}argc{$ELSE}ParamCount{$ENDIF};
     wrongParameter:= false;
-    while (paramIndex <= ParamCount) do
+    while (paramIndex <= paramTotal) do
         begin
-        if parseParameter( ParamStr(paramIndex), ParamStr(paramIndex+1), paramIndex) then
-            wrongParameter:= true;
+        {$IFDEF HWLIBRARY}
+        wrongParameter:= parseParameter( argv[paramIndex], argv[paramIndex+1], paramIndex);
+        {$ELSE}
+        wrongParameter:= parseParameter( ParamStr(paramIndex), ParamStr(paramIndex+1), paramIndex);
+        {$ENDIF}
         inc(paramIndex);
         end;
     if wrongParameter = true then
         GameType:= gmtSyntax;
 end;
 
+{$IFNDEF HWLIBRARY}
 procedure GetParams;
 //var tmpInt: LongInt;
 begin
@@ -300,7 +306,7 @@
     UserPathPrefix := '.';
     PathPrefix     := cDefaultPathPrefix;
     recordFileName := '';
-    playReplayFileWithParameters();
+    parseCommandLine();
 
     if (isInternal) and (ParamCount<=1) then
         begin
@@ -324,3 +330,5 @@
     WriteLn(stdout,'UserPathPrefix: ' + UserPathPrefix);
     *)
 end;
+{$ENDIF}
+
--- a/hedgewars/hwengine.pas	Mon Dec 24 12:52:14 2012 -0500
+++ b/hedgewars/hwengine.pas	Tue Dec 25 01:13:07 2012 +0100
@@ -44,7 +44,7 @@
 procedure preInitEverything();
 procedure initEverything(complete:boolean);
 procedure freeEverything(complete:boolean);
-procedure Game(gameArgs: PPChar); cdecl; export;
+procedure Game(argc: LongInt; argv: PPChar); cdecl; export;
 procedure GenLandPreview(port: Longint); cdecl; export;
 
 implementation
@@ -54,6 +54,8 @@
 procedure freeEverything(complete:boolean); forward;
 {$ENDIF}
 
+{$INCLUDE "ArgParsers.inc"}
+
 ///////////////////////////////////////////////////////////////////////////////
 function DoTimer(Lag: LongInt): boolean;
 var s: shortstring;
@@ -321,28 +323,14 @@
 {$ENDIF}
 
 ///////////////////////////////////////////////////////////////////////////////
-procedure Game{$IFDEF HWLIBRARY}(gameArgs: PPChar); cdecl; export{$ENDIF};
+procedure Game{$IFDEF HWLIBRARY}(argc: LongInt; argv: PPChar); cdecl; export{$ENDIF};
 var p: TPathType;
     s: shortstring;
     i: LongInt;
 begin
 {$IFDEF HWLIBRARY}
     preInitEverything();
-    cShowFPS:= {$IFDEF DEBUGFILE}true{$ELSE}false{$ENDIF};
-    ipcPort:= StrToInt(gameArgs[0]);
-    cScreenWidth:= StrToInt(gameArgs[1]);
-    cScreenHeight:= StrToInt(gameArgs[2]);
-    cReducedQuality:= StrToInt(gameArgs[3]);
-    cLocaleFName:= gameArgs[4];
-    UserNick:= gameArgs[5];
-    SetSound(gameArgs[6] = '1');
-    SetMusic(gameArgs[7] = '1');
-    cAltDamage:= gameArgs[8] = '1';
-    PathPrefix:= gameArgs[9];
-{$IFDEF IPHONEOS}
-    UserPathPrefix:= '../Documents';
-{$ENDIF}
-    recordFileName:= gameArgs[10];
+    parseCommandLine(argc, argv);
 {$ENDIF}
     initEverything(true);
     WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')');
@@ -545,8 +533,6 @@
 
 {$IFNDEF HWLIBRARY}
 
-{$INCLUDE "ArgParsers.inc"}
-
 ///////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////// m a i n ///////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////