Add an ability to run engine without IPC connection.
authorunc0rr
Thu, 12 Mar 2009 20:29:01 +0000
changeset 1888 e76274ce7365
parent 1887 d68939b3f7f0
child 1889 b8590b604fdd
Add an ability to run engine without IPC connection. It requires two parameters: 1) ful path to share/hedgewars/Data 2) full path to record file (hwd_24 or hws_24) debug #0.txt will be created it path passed in 1st param
hedgewars/hwengine.dpr
hedgewars/uIO.pas
hedgewars/uMisc.pas
--- a/hedgewars/hwengine.dpr	Thu Mar 12 20:19:33 2009 +0000
+++ b/hedgewars/hwengine.dpr	Thu Mar 12 20:29:01 2009 +0000
@@ -62,6 +62,7 @@
 //       SinTable.inc
 //       proto.inc
 
+var recordFileName : shortstring = '';
 
 procedure OnDestroy; forward;
 
@@ -214,7 +215,13 @@
      val(ParamStr(2), ipcPort);
      GameType:= gmtLandPreview;
      if ParamStr(3) <> 'landpreview' then OutError(errmsgShouldntRun, true);
-     end
+     end;
+  2: begin
+     PathPrefix:= ParamStr(1);
+     recordFileName:= ParamStr(2);
+     for p:= Succ(Low(TPathType)) to High(TPathType) do
+         if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p]
+     end;
    else
    OutError(errmsgShouldntRun, true)
    end
@@ -244,12 +251,16 @@
 ShowMainWindow;
 
 InitKbdKeyTable;
-InitIPC;
+
+if recordFileName = '' then InitIPC;
 WriteLnToConsole(msgGettingConfig);
 
 LoadLocale(Pathz[ptLocale] + '/' + cLocaleFName);
 
-SendIPCAndWaitReply('C');        // ask for game config
+if recordFileName = '' then
+	SendIPCAndWaitReply('C')        // ask for game config
+else
+	LoadRecordFromFile(recordFileName);
 
 s:= 'eproto ' + inttostr(cNetProtoVersion);
 SendIPCRaw(@s[0], Length(s) + 1); // send proto version
--- a/hedgewars/uIO.pas	Thu Mar 12 20:19:33 2009 +0000
+++ b/hedgewars/uIO.pas	Thu Mar 12 20:29:01 2009 +0000
@@ -28,6 +28,7 @@
 procedure SendIPCRaw(p: pointer; len: Longword);
 procedure SendIPCAndWaitReply(s: shortstring);
 procedure SendIPCTimeInc;
+procedure LoadRecordFromFile(fileName: shortstring);
 procedure IPCWaitPongEvent;
 procedure IPCCheckSock;
 procedure InitIPC;
@@ -136,26 +137,57 @@
 procedure IPCCheckSock;
 const ss: string = '';
 var i: LongInt;
-    buf: array[0..255] of byte;
-    s: shortstring absolute buf;
+	buf: array[0..255] of byte;
+	s: shortstring absolute buf;
 begin
+if IPCSock = nil then
+   exit;
+
 fds^.numsockets:= 0;
 SDLNet_AddSocket(fds, IPCSock);
 
 while SDLNet_CheckSockets(fds, 0) > 0 do
-      begin
-      i:= SDLNet_TCP_Recv(IPCSock, @buf[1], 255 - Length(ss));
-      if i > 0 then
-         begin
-         buf[0]:= i;
-         ss:= ss + s;
-         while (Length(ss) > 1)and(Length(ss) > byte(ss[1])) do
-               begin
-               ParseIPCCommand(copy(ss, 2, byte(ss[1])));
-               Delete(ss, 1, Succ(byte(ss[1])))
-               end
-         end else OutError('IPC connection lost', true)
-      end;
+	begin
+	i:= SDLNet_TCP_Recv(IPCSock, @buf[1], 255 - Length(ss));
+	if i > 0 then
+		begin
+		buf[0]:= i;
+		ss:= ss + s;
+		while (Length(ss) > 1)and(Length(ss) > byte(ss[1])) do
+			begin
+			ParseIPCCommand(copy(ss, 2, byte(ss[1])));
+			Delete(ss, 1, Succ(byte(ss[1])))
+			end
+		end else OutError('IPC connection lost', true)
+	end;
+end;
+
+procedure LoadRecordFromFile(fileName: shortstring);
+var f: file;
+	ss: string = '';
+	i: LongInt;
+	buf: array[0..255] of byte;
+	s: shortstring absolute buf;
+begin
+assign(f, fileName);
+
+reset(f, 1);
+
+repeat
+	BlockRead(f, buf[1], 255 - Length(ss), i);
+	if i > 0 then
+		begin
+		buf[0]:= i;
+		ss:= ss + s;
+		while (Length(ss) > 1)and(Length(ss) > byte(ss[1])) do
+			begin
+			ParseIPCCommand(copy(ss, 2, byte(ss[1])));
+			Delete(ss, 1, Succ(byte(ss[1])))
+			end
+		end
+until i = 0;
+
+close(f)
 end;
 
 procedure SendIPC(s: shortstring);
--- a/hedgewars/uMisc.pas	Thu Mar 12 20:19:33 2009 +0000
+++ b/hedgewars/uMisc.pas	Thu Mar 12 20:29:01 2009 +0000
@@ -39,7 +39,7 @@
 	TurnTimeLeft  : Longword = 0;
 	cSuddenDTurns : LongInt = 15;
 	cTemplateFilter : LongInt = 0;
-    
+
 	cHedgehogTurnTime: Longword = 45000;
 	cMaxAIThinkTime  : Longword = 9000;
 
@@ -69,7 +69,7 @@
 	cShowFPS      : boolean = true;
 	cCaseFactor   : Longword = 5;  {0..9}
 	cLandAdditions: Longword = 4;
-	cFullScreen   : boolean = true;
+	cFullScreen   : boolean = false;
 	cReducedQuality : boolean = false;
 	cLocaleFName  : shortstring = 'en.txt';
 	cSeed         : shortstring = '';