hedgewars/hwengine.pas
changeset 3611 ed00aa2b339e
parent 3610 8590424bdfb0
child 3612 b50215a8a43d
--- a/hedgewars/hwengine.pas	Fri Jul 02 17:46:53 2010 +0200
+++ b/hedgewars/hwengine.pas	Sat Jul 03 00:11:23 2010 +0200
@@ -81,6 +81,7 @@
 implementation
 {$ELSE}
 procedure OnDestroy; forward;
+procedure initEverything(complete:boolean); forward;
 procedure freeEverything(complete:boolean); forward;
 {$ENDIF}
 
@@ -245,10 +246,11 @@
 {$ENDIF}
 var p: TPathType;
     s: shortstring;
+{$IFDEF DEBUGFILE}
+    i: LongInt;
+{$ENDIF}
 begin
 {$IFDEF HWLIBRARY}
-    initEverything(true);
-
     cBits:= 32;
     cFullScreen:= false;
     cVSyncInUse:= true;
@@ -266,10 +268,15 @@
     cAltDamage:= gameArgs[5] = '1';
     val(gameArgs[6], cScreenHeight);
     val(gameArgs[7], cScreenWidth);
-    cInitHeight:= cScreenHeight;
-    cInitWidth:= cScreenWidth;
     recordFileName:= gameArgs[8];
 {$ENDIF}
+    initEverything(true);
+    WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')');
+{$IFDEF DEBUGFILE}
+    AddFileLog('Prefix: "' + PathPrefix +'"');
+    for i:= 0 to ParamCount do
+        AddFileLog(inttostr(i) + ': ' + ParamStr(i));
+{$ENDIF}
 
     for p:= Succ(Low(TPathType)) to High(TPathType) do
         if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p];
@@ -335,7 +342,7 @@
 
     MainLoop();
     OnDestroy();
-{$IFDEF HWLIBRARY}freeEverything(true);{$ENDIF}
+    freeEverything(true);
     if alsoShutdownFrontend then halt;
 end;
 
@@ -423,8 +430,8 @@
 procedure GenLandPreview{$IFDEF HWLIBRARY}(port: LongInt); cdecl; export{$ENDIF};
 var Preview: TPreview;
 begin
+    initEverything(false);
 {$IFDEF HWLIBRARY}
-    initEverything(false);
     WriteLnToConsole('Preview connecting on port ' + inttostr(port));
     ipcPort:= port;
 {$ENDIF}
@@ -438,9 +445,7 @@
     SendIPCRaw(@MaxHedgehogs, sizeof(byte));
     WriteLnToConsole('Preview sent, disconnect');
     CloseIPC();
-{$IFDEF HWLIBRARY}
     freeEverything(false);
-{$ENDIF}
 end;
 
 {$IFNDEF HWLIBRARY}
@@ -468,16 +473,11 @@
 
 ////////////////////
 procedure GetParams;
-{$IFDEF DEBUGFILE}
-var i: LongInt;
-{$ENDIF}
 begin
     case ParamCount of
         18: begin
             val(ParamStr(2), cScreenWidth);
             val(ParamStr(3), cScreenHeight);
-            cInitWidth:= cScreenWidth;
-            cInitHeight:= cScreenHeight;
             cBitsStr:= ParamStr(4);
             val(cBitsStr, cBits);
             val(ParamStr(5), ipcPort);
@@ -517,8 +517,6 @@
             begin
                 val(ParamStr(4), cScreenWidth);
                 val(ParamStr(5), cScreenHeight);
-                cInitWidth:= cScreenWidth;
-                cInitHeight:= cScreenHeight;
                 cBitsStr:= ParamStr(6);
                 val(cBitsStr, cBits);
             end
@@ -550,8 +548,6 @@
             begin
                 val(ParamStr(4), cScreenWidth);
                 val(ParamStr(5), cScreenHeight);
-                cInitWidth:= cScreenWidth;
-                cInitHeight:= cScreenHeight;
                 cBitsStr:= ParamStr(6);
                 val(cBitsStr, cBits);
                 val(ParamStr(7), cInitVolume);
@@ -569,8 +565,6 @@
             begin
                 val(ParamStr(4), cScreenWidth);
                 val(ParamStr(5), cScreenHeight);
-                cInitWidth:= cScreenWidth;
-                cInitHeight:= cScreenHeight;
                 cBitsStr:= ParamStr(6);
                 val(cBitsStr, cBits);
                 val(ParamStr(7), cInitVolume);
@@ -590,28 +584,18 @@
         end;
         else GameType:= gmtSyntax;
     end;
-
-{$IFDEF DEBUGFILE}
-    AddFileLog('Prefix: "' + PathPrefix +'"');
-    for i:= 0 to ParamCount do
-        AddFileLog(inttostr(i) + ': ' + ParamStr(i));
-{$ENDIF}
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
 /////////////////////////////// m a i n ////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////////////
 begin
-    initEverything(true);
-    WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')');
-    
     GetParams();
 
     if GameType = gmtLandPreview then GenLandPreview()
     else if GameType = gmtSyntax then DisplayUsage()
     else Game();
     
-    freeEverything(true);
     if GameType = gmtSyntax then
         ExitCode:= 1
     else