hedgewars/uIO.pas
branchqmlfrontend
changeset 11549 b69f5f22a3ba
parent 11459 3c5d99013baf
parent 11544 c22d292e7266
child 11639 0af93f018701
--- a/hedgewars/uIO.pas	Fri Jan 01 19:15:32 2016 +0300
+++ b/hedgewars/uIO.pas	Tue Feb 09 21:11:16 2016 +0300
@@ -70,28 +70,36 @@
 function AddCmd(Time: Word; str: shortstring): PCmd;
 var command: PCmd;
 begin
-new(command);
-FillChar(command^, sizeof(TCmd), 0);
-command^.loTime:= Time;
-command^.str:= str;
-if (command^.cmd <> 'F') and (command^.cmd <> 'G') then dec(command^.len, 2); // cut timestamp
-if headcmd = nil then
+    if (lastcmd <> nil) and (lastcmd^.cmd = '+') then
+    begin
+        command:= lastcmd;
+    end else
     begin
-    headcmd:= command;
-    lastcmd:= command
-    end
-else
-    begin
-    lastcmd^.Next:= command;
-    lastcmd:= command
+        new(command);
+
+        if headcmd = nil then
+            begin
+            headcmd:= command;
+            lastcmd:= command
+            end
+        else
+            begin
+            lastcmd^.Next:= command;
+            lastcmd:= command
+            end;
     end;
-AddCmd:= command;
+
+    FillChar(command^, sizeof(TCmd), 0);
+    command^.loTime:= Time;
+    command^.str:= str;
+    if (command^.cmd <> 'F') and (command^.cmd <> 'G') then dec(command^.len, 2); // cut timestamp
+
+    AddCmd:= command;
 end;
 
 procedure RemoveCmd;
 var tmp: PCmd;
 begin
-TryDo(headcmd <> nil, 'Engine bug: headcmd = nil', true);
 tmp:= headcmd;
 headcmd:= headcmd^.Next;
 if headcmd = nil then
@@ -202,7 +210,8 @@
 {$I-}
 assign(f, fileName);
 reset(f, 1);
-tryDo(IOResult = 0, 'Error opening file ' + fileName, true);
+if checkFails(IOResult = 0, 'Error opening file ' + fileName, true) then
+    exit;
 
 i:= 0; // avoid compiler hints
 s[0]:= #0;
@@ -212,13 +221,13 @@
         begin
         s[0]:= char(i);
         ss:= ss + s;
-        while (Length(ss) > 1)and(Length(ss) > byte(ss[1])) do
+        while (Length(ss) > 1)and(Length(ss) > byte(ss[1])) and allOK do
             begin
             ParseIPCCommand(copy(ss, 2, byte(ss[1])));
             Delete(ss, 1, Succ(byte(ss[1])));
             end
         end
-until i = 0;
+until (i = 0) or (not allOK);
 
 close(f)
 {$I+}
@@ -284,7 +293,7 @@
 repeat
     IPCCheckSock;
     SDL_Delay(1)
-until isPonged
+until isPonged or (not allOK)
 end;
 
 procedure SendIPCAndWaitReply(s: shortstring);
@@ -391,7 +400,7 @@
     end;
 
 if (headcmd <> nil) and tmpflag and (not CurrentTeam^.hasGone) then
-    TryDo(GameTicks < LongWord(hiTicks shl 16) + headcmd^.loTime,
+    checkFails(GameTicks < LongWord(hiTicks shl 16) + headcmd^.loTime,
             'oops, queue error. in buffer: ' + headcmd^.cmd +
             ' (' + IntToStr(GameTicks) + ' > ' +
             IntToStr(hiTicks shl 16 + headcmd^.loTime) + ')',