Overwrite last '+' cmd in the queue instead of appending new command
authorunc0rr
Mon, 04 Jan 2016 10:08:26 +0300
changeset 11488 dbc0d54798dc
parent 11487 b053f1fb631d
child 11489 cb64affd7715
Overwrite last '+' cmd in the queue instead of appending new command
hedgewars/uIO.pas
--- a/hedgewars/uIO.pas	Fri Jan 01 19:34:48 2016 -0500
+++ b/hedgewars/uIO.pas	Mon Jan 04 10:08:26 2016 +0300
@@ -72,22 +72,31 @@
 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;