--- a/hedgewars/CCHandlers.inc Mon Sep 18 18:07:41 2006 +0000
+++ b/hedgewars/CCHandlers.inc Wed Sep 20 15:33:47 2006 +0000
@@ -324,11 +324,7 @@
SDL_GetMouseState(@TargetPoint.X, @TargetPoint.Y);
dec(TargetPoint.X, WorldDx);
dec(TargetPoint.Y, WorldDy);
- s[0]:= #5;
- s[1]:= 'p';
- PSmallInt(@s[2])^:= TargetPoint.X;
- PSmallInt(@s[4])^:= TargetPoint.Y;
- SendIPC(s)
+ SendIPCXY('p', TargetPoint.X, TargetPoint.Y);
end;
State:= State and not gstHHChooseTarget;
end else if CurrentTeam.ExtDriven then OutError('got /put while not being in choose target mode', false)
--- a/hedgewars/SDLh.pas Mon Sep 18 18:07:41 2006 +0000
+++ b/hedgewars/SDLh.pas Wed Sep 20 15:33:47 2006 +0000
@@ -372,6 +372,10 @@
function SDLNet_AddSocket(_set: PSDLNet_SocketSet; sock: PTCPSocket): LongInt; cdecl; external SDL_NetLibName;
function SDLNet_CheckSockets(_set: PSDLNet_SocketSet; timeout: LongInt): LongInt; cdecl; external SDL_NetLibName;
+procedure SDLNet_Write16(value: SmallInt; buf: pointer); cdecl; external SDL_NetLibName;
+procedure SDLNet_Write32(value: LongInt; buf: pointer); cdecl; external SDL_NetLibName;
+function SDLNet_Read16(buf: pointer): SmallInt; cdecl; external SDL_NetLibName;
+function SDLNet_Read32(buf: pointer): LongInt; cdecl; external SDL_NetLibName;
implementation
--- a/hedgewars/uIO.pas Mon Sep 18 18:07:41 2006 +0000
+++ b/hedgewars/uIO.pas Wed Sep 20 15:33:47 2006 +0000
@@ -39,6 +39,7 @@
const ipcPort: Word = 0;
procedure SendIPC(s: shortstring);
+procedure SendIPCXY(cmd: char; X, Y: SmallInt);
procedure SendIPCAndWaitReply(s: shortstring);
procedure IPCCheckSock;
procedure InitIPC;
@@ -100,7 +101,7 @@
else OutError(errmsgIncorrectUse + ' IPC "T" :' + s[2], true) end;
else
inc(cmdendpos);
- extcmd[cmdendpos].Time := PLongWord(@s[byte(s[0]) - 3])^;
+ extcmd[cmdendpos].Time := SDLNet_Read32(@s[byte(s[0]) - 3]);
extcmd[cmdendpos].str := s;
{$IFDEF DEBUGFILE}AddFileLog('IPC in: '+s[1]+' ticks '+inttostr(extcmd[cmdendpos].Time)+' at '+inttostr(cmdendpos));{$ENDIF}
dec(extcmd[cmdendpos].len, 4)
@@ -137,13 +138,23 @@
if IPCSock <> nil then
begin
if s[0]>#251 then s[0]:= #251;
- PLongWord(@s[Succ(byte(s[0]))])^:= GameTicks;
+ SDLNet_Write32(GameTicks, @s[Succ(byte(s[0]))]);
{$IFDEF DEBUGFILE}AddFileLog('IPC send: '+s);{$ENDIF}
inc(s[0],4);
SDLNet_TCP_Send(IPCSock, @s, Succ(byte(s[0])))
end
end;
+procedure SendIPCXY(cmd: char; X, Y: SmallInt);
+var s: shortstring;
+begin
+s[0]:= #5;
+s[1]:= cmd;
+SDLNet_Write16(X, @s[2]);
+SDLNet_Write16(Y, @s[4]);
+SendIPC(s)
+end;
+
procedure SendIPCAndWaitReply(s: shortstring);
begin
SendIPC(s);
@@ -195,13 +206,13 @@
{$IFDEF DEBUGFILE}AddFileLog('got cmd "N": time '+inttostr(extcmd[cmdcurpos].Time)){$ENDIF}
end;
'p': begin
- TargetPoint.X:= extcmd[cmdcurpos].X;
- TargetPoint.Y:= extcmd[cmdcurpos].Y;
+ TargetPoint.X:= SDLNet_Read16(@extcmd[cmdcurpos].X);
+ TargetPoint.Y:= SDLNet_Read16(@extcmd[cmdcurpos].Y);
ParseCommand('put')
end;
'P': begin
- CursorPoint.X:= extcmd[cmdcurpos].X + WorldDx;
- CursorPoint.Y:= extcmd[cmdcurpos].Y + WorldDy;
+ CursorPoint.X:= SDLNet_Read16(@extcmd[cmdcurpos].X) + WorldDx;
+ CursorPoint.Y:= SDLNet_Read16(@extcmd[cmdcurpos].Y) + WorldDy;
end;
'1'..'5': ParseCommand('timer ' + extcmd[cmdcurpos].cmd);
#128..char(128 + cMaxSlotIndex): ParseCommand('slot ' + char(byte(extcmd[cmdcurpos].cmd) - 79))
--- a/hedgewars/uWorld.pas Mon Sep 18 18:07:41 2006 +0000
+++ b/hedgewars/uWorld.pas Wed Sep 20 15:33:47 2006 +0000
@@ -346,7 +346,6 @@
procedure MoveCamera;
const PrevSentPointTime: LongWord = 0;
-var s: string[9];
begin
if not (CurrentTeam.ExtDriven and isCursorVisible) then SDL_GetMouseState(@CursorPoint.X, @CursorPoint.Y);
if (FollowGear <> nil) then
@@ -366,11 +365,7 @@
begin
if (not CurrentTeam.ExtDriven)and(GameTicks >= PrevSentPointTime + cSendCursorPosTime) then
begin
- s[0]:= #5;
- s[1]:= 'P';
- PSmallInt(@s[2])^:= CursorPoint.X - WorldDx;
- PSmallInt(@s[4])^:= CursorPoint.Y - WorldDy;
- SendIPC(s);
+ SendIPCXY('P', CursorPoint.X - WorldDx, CursorPoint.Y - WorldDy);
PrevSentPointTime:= GameTicks
end;
end;