- Use 2 bytes for timestamp in net protocol, thus decreasing average packet size from 6 to 4
- Inc protocol version number
--- a/CMakeLists.txt Thu Dec 13 13:51:55 2007 +0000
+++ b/CMakeLists.txt Thu Dec 13 14:15:56 2007 +0000
@@ -9,7 +9,7 @@
endif(DEFINED DATA_INSTALL_DIR)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
-set(HEDGEWARS_PROTO_VER 7)
+set(HEDGEWARS_PROTO_VER 8)
add_subdirectory(bin)
add_subdirectory(QTfrontend)
--- a/hedgewars/uGears.pas Thu Dec 13 13:51:55 2007 +0000
+++ b/hedgewars/uGears.pas Thu Dec 13 14:15:56 2007 +0000
@@ -422,6 +422,7 @@
if ((CurrentHedgehog^.Gear^.State and gstAttacking) = 0)
and not isInMultiShoot then dec(TurnTimeLeft);
+if (GameTicks and $FFFF) = $FFFF then SendIPCTimeInc;
inc(GameTicks)
end;
--- a/hedgewars/uIO.pas Thu Dec 13 13:51:55 2007 +0000
+++ b/hedgewars/uIO.pas Thu Dec 13 14:15:56 2007 +0000
@@ -27,6 +27,7 @@
procedure SendIPCXY(cmd: char; X, Y: SmallInt);
procedure SendIPCRaw(p: pointer; len: Longword);
procedure SendIPCAndWaitReply(s: shortstring);
+procedure SendIPCTimeInc;
procedure IPCWaitPongEvent;
procedure IPCCheckSock;
procedure InitIPC;
@@ -54,6 +55,8 @@
headcmd: PCmd = nil;
lastcmd: PCmd = nil;
+ hiTicks: Word = 0;
+
function AddCmd(Time: Longword; str: shortstring): PCmd;
var Result: PCmd;
begin
@@ -61,7 +64,7 @@
FillChar(Result^, sizeof(TCmd), 0);
Result^.Time:= Time;
Result^.str:= str;
-dec(Result^.len, 4);
+dec(Result^.len, 2); // cut timestamp
if headcmd = nil then
begin
headcmd:= Result;
@@ -107,10 +110,12 @@
end;
procedure ParseIPCCommand(s: shortstring);
+var loTicks: Word;
begin
case s[1] of
'!': begin {$IFDEF DEBUGFILE}AddFileLog('Ping? Pong!');{$ENDIF}isPonged:= true; end;
'?': SendIPC('!');
+ '#': inc(hiTicks);
'e': ParseCommand(copy(s, 2, Length(s) - 1), true);
'E': OutError(copy(s, 2, Length(s) - 1), true);
'W': OutError(copy(s, 2, Length(s) - 1), false);
@@ -122,7 +127,8 @@
'S': GameType:= gmtSave;
else OutError(errmsgIncorrectUse + ' IPC "T" :' + s[2], true) end;
else
- AddCmd(SDLNet_Read32(@s[byte(s[0]) - 3]), s);
+ loTicks:= SDLNet_Read16(@s[byte(s[0]) - 1]);
+ AddCmd(hiTicks shl 16 + loTicks, s);
{$IFDEF DEBUGFILE}AddFileLog('IPC in: '+s[1]+' ticks '+inttostr(lastcmd^.Time));{$ENDIF}
end
end;
@@ -157,9 +163,9 @@
if IPCSock <> nil then
begin
if s[0]>#251 then s[0]:= #251;
- SDLNet_Write32(GameTicks, @s[Succ(byte(s[0]))]);
+ SDLNet_Write16(GameTicks, @s[Succ(byte(s[0]))]);
{$IFDEF DEBUGFILE}AddFileLog('IPC send: '+s);{$ENDIF}
- inc(s[0],4);
+ inc(s[0], 2);
SDLNet_TCP_Send(IPCSock, @s, Succ(byte(s[0])))
end
end;
@@ -182,6 +188,12 @@
SendIPC(s)
end;
+procedure SendIPCTimeInc;
+const timeinc: shortstring = '#';
+begin
+SendIPCRaw(@timeinc, 2)
+end;
+
procedure IPCWaitPongEvent;
begin
isPonged:= false;