Add a parameter for game simulation with no gui/sound enabled, just to get statistics
authorunc0rr
Sun, 10 Apr 2011 20:24:25 +0400
changeset 5130 3602ede67ec5
parent 5128 3c65326bb713
child 5132 11d61349efcf
Add a parameter for game simulation with no gui/sound enabled, just to get statistics
hedgewars/ArgParsers.inc
hedgewars/hwengine.pas
hedgewars/uGame.pas
hedgewars/uIO.pas
hedgewars/uStore.pas
hedgewars/uUtils.pas
hedgewars/uVariables.pas
--- a/hedgewars/ArgParsers.inc	Sat Apr 09 15:54:28 2011 -0400
+++ b/hedgewars/ArgParsers.inc	Sun Apr 10 20:24:25 2011 +0400
@@ -16,12 +16,19 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  *)
 
+procedure playReplayFileWithParameters(); forward;
+
 procedure internalSetGameTypeLandPreviewFromParameters();
 begin
-    val(ParamStr(2), ipcPort);
-    GameType:= gmtLandPreview;
-    if ParamStr(3) <> 'landpreview' then
-        GameType:= gmtSyntax
+    if ParamStr(3) = '--stats-only' then
+        playReplayFileWithParameters()
+    else
+        begin
+        val(ParamStr(2), ipcPort);
+        GameType:= gmtLandPreview;
+        if ParamStr(3) <> 'landpreview' then
+            GameType:= gmtSyntax
+        end
 end;
 
 procedure internalStartGameWithParameters();
@@ -210,10 +217,19 @@
                             paramIndex:= paramIndex + 13
                             end
                         else
-                            begin
-                            wrongParameter:= true;
-                            GameType:= gmtSyntax
-                            end
+                            if ParamStr(paramIndex) = '--stats-only'  then
+                                begin
+                                cOnlyStats:= true;
+                                isSoundEnabled:= false;
+                                isMusicEnabled:= false;
+                                cReducedQuality:= $FFFFFFFF xor rqLowRes; // HACK
+                                paramIndex:= paramIndex + 1
+                                end
+                            else
+                                begin
+                                wrongParameter:= true;
+                                GameType:= gmtSyntax
+                                end
     end
 end;
 
--- a/hedgewars/hwengine.pas	Sat Apr 09 15:54:28 2011 -0400
+++ b/hedgewars/hwengine.pas	Sun Apr 10 20:24:25 2011 +0400
@@ -437,6 +437,7 @@
     WriteLn(' --set-other [language file] [full screen] [show FPS]');
     WriteLn(' --set-multimedia [screen width] [screen height] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen]');
     WriteLn(' --set-everything [screen width] [screen height] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen] [show FPS] [alternate damage] [timer value] [reduced quality]');
+    WriteLn(' --stats-only');
     WriteLn();
     WriteLn('Read documentation online at http://code.google.com/p/hedgewars/wiki/CommandLineOptions for more information');
     WriteLn();
--- a/hedgewars/uGame.pas	Sat Apr 09 15:54:28 2011 -0400
+++ b/hedgewars/uGame.pas	Sun Apr 10 20:24:25 2011 +0400
@@ -40,7 +40,11 @@
     end;
 if Lag > 100 then Lag:= 100
 else if (GameType = gmtSave) or (fastUntilLag and (GameType = gmtNet)) then Lag:= 2500;
-if (GameType = gmtDemo) and isSpeed then Lag:= Lag * 10;
+
+if (GameType = gmtDemo) then 
+    if isSpeed then Lag:= Lag * 10
+    else
+        if cOnlyStats then Lag:= High(LongInt);
 
 i:= 1;
 while (GameState <> gsExit) and (i <= Lag) do
--- a/hedgewars/uIO.pas	Sat Apr 09 15:54:28 2011 -0400
+++ b/hedgewars/uIO.pas	Sun Apr 10 20:24:25 2011 +0400
@@ -178,10 +178,12 @@
 
 // set RDNLY on file open
 filemode:= 0;
-
+{$I-}
 assign(f, fileName);
 reset(f, 1);
 
+tryDo(IOResult = 0, 'Error opening file ' + fileName, true);
+
 i:= 0; // avoid compiler hints
 buf[0]:= 0;
 repeat
@@ -199,6 +201,7 @@
 until i = 0;
 
 close(f)
+{$I+}
 end;
 
 procedure SendStat(sit: TStatInfoType; s: shortstring);
--- a/hedgewars/uStore.pas	Sat Apr 09 15:54:28 2011 -0400
+++ b/hedgewars/uStore.pas	Sun Apr 10 20:24:25 2011 +0400
@@ -943,8 +943,11 @@
     glMatrixMode(GL_PROJECTION);
     glLoadIdentity();
 {$ELSE}
-    SDLPrimSurface:= SDL_SetVideoMode(cScreenWidth, cScreenHeight, cBits, flags);
-    SDLTry(SDLPrimSurface <> nil, true);
+    if not cOnlyStats then
+        begin
+        SDLPrimSurface:= SDL_SetVideoMode(cScreenWidth, cScreenHeight, cBits, flags);
+        SDLTry(SDLPrimSurface <> nil, true);
+        end;
 {$ENDIF}
 
     AddFileLog('Setting up OpenGL (using driver: ' + shortstring(SDL_VideoDriverName(buf, sizeof(buf))) + ')');
--- a/hedgewars/uUtils.pas	Sat Apr 09 15:54:28 2011 -0400
+++ b/hedgewars/uUtils.pas	Sun Apr 10 20:24:25 2011 +0400
@@ -338,23 +338,27 @@
     if (ParamStr(1) <> '') and (ParamStr(2) <> '') then
         if (ParamCount <> 3) and (ParamCount <> cDefaultParamNum) then
         begin
-            for i:= 0 to 7 do
+            i:= 0;
+            while(i < 7) do
             begin
                 assign(f, ExtractFileDir(ParamStr(2)) + '/' + cLogfileBase + inttostr(i) + '.log');
                 rewrite(f);
                 if IOResult = 0 then break;
+                inc(i)
             end;
-            if IOResult <> 0 then f:= stderr; // if everything fails, write to stderr
+            if i = 7 then f:= stderr; // if everything fails, write to stderr
         end
         else
         begin
-            for i:= 0 to 7 do
+            i:= 0;
+            while(i < 7) do
             begin
                 assign(f, ParamStr(1) + '/Logs/' + cLogfileBase + inttostr(i) + '.log');
                 rewrite(f);
                 if IOResult = 0 then break;
+                inc(i)
             end;
-            if IOResult <> 0 then f:= stderr; // if everything fails, write to stderr
+            if i = 7 then f:= stderr; // if everything fails, write to stderr
         end
     else
         f:= stderr;
--- a/hedgewars/uVariables.pas	Sat Apr 09 15:54:28 2011 -0400
+++ b/hedgewars/uVariables.pas	Sun Apr 10 20:24:25 2011 +0400
@@ -45,6 +45,7 @@
     cReadyDelay     : Longword    = 5000;
     cLogfileBase    : shortstring = 'debug';
     cStereoMode     : TStereoMode = smNone;
+    cOnlyStats      : boolean = False;
 //////////////////////////
 
     alsoShutdownFrontend: boolean = false;