hedgewars/uIO.pas
changeset 2699 249adefa9c1c
parent 2695 ed789a7ef68d
child 2716 b9ca1bfca24f
equal deleted inserted replaced
2698:90585aba87ad 2699:249adefa9c1c
    21 unit uIO;
    21 unit uIO;
    22 interface
    22 interface
    23 uses SDLh;
    23 uses SDLh;
    24 
    24 
    25 const ipcPort: Word = 0;
    25 const ipcPort: Word = 0;
    26 
    26 var hiTicks: Word;
       
    27 
       
    28 procedure init_uIO;
    27 procedure SendIPC(s: shortstring);
    29 procedure SendIPC(s: shortstring);
    28 procedure SendIPCXY(cmd: char; X, Y: SmallInt);
    30 procedure SendIPCXY(cmd: char; X, Y: SmallInt);
    29 procedure SendIPCRaw(p: pointer; len: Longword);
    31 procedure SendIPCRaw(p: pointer; len: Longword);
    30 procedure SendIPCAndWaitReply(s: shortstring);
    32 procedure SendIPCAndWaitReply(s: shortstring);
    31 procedure SendIPCTimeInc;
    33 procedure SendIPCTimeInc;
    35 procedure IPCCheckSock;
    37 procedure IPCCheckSock;
    36 procedure InitIPC;
    38 procedure InitIPC;
    37 procedure CloseIPC;
    39 procedure CloseIPC;
    38 procedure NetGetNextCmd;
    40 procedure NetGetNextCmd;
    39 
    41 
    40 var hiTicks: Word = 0;
       
    41 
       
    42 implementation
    42 implementation
    43 uses uConsole, uConsts, uWorld, uMisc, uLand, uChat, uTeams;
    43 uses uConsole, uConsts, uWorld, uMisc, uLand, uChat, uTeams;
    44 const isPonged: boolean = false;
       
    45 
    44 
    46 type PCmd = ^TCmd;
    45 type PCmd = ^TCmd;
    47      TCmd = packed record
    46      TCmd = packed record
    48             Next: PCmd;
    47             Next: PCmd;
    49             loTime: Word;
    48             loTime: Word;
    52                 cmd: Char;
    51                 cmd: Char;
    53                 X, Y: SmallInt);
    52                 X, Y: SmallInt);
    54             2: (str: shortstring);
    53             2: (str: shortstring);
    55             end;
    54             end;
    56 
    55 
    57 var
    56 var	IPCSock: PTCPSocket;
    58 	IPCSock: PTCPSocket = nil;
       
    59 	fds: PSDLNet_SocketSet;
    57 	fds: PSDLNet_SocketSet;
    60 
    58 	isPonged: boolean;
    61 	headcmd: PCmd = nil;
    59 
    62 	lastcmd: PCmd = nil;
    60 	headcmd: PCmd;
    63 
    61 	lastcmd: PCmd;
    64 	SendEmptyPacketTicks: LongWord = 0;
    62 
       
    63 	SendEmptyPacketTicks: LongWord;
    65 
    64 
    66 
    65 
    67 function AddCmd(Time: Word; str: shortstring): PCmd;
    66 function AddCmd(Time: Word; str: shortstring): PCmd;
    68 var command: PCmd;
    67 var command: PCmd;
    69 begin
    68 begin
   109 WriteLnToConsole(msgOK)
   108 WriteLnToConsole(msgOK)
   110 end;
   109 end;
   111 
   110 
   112 procedure CloseIPC;
   111 procedure CloseIPC;
   113 begin
   112 begin
   114 SDLNet_FreeSocketSet(fds);
   113 	SDLNet_FreeSocketSet(fds);
   115 SDLNet_TCP_Close(IPCSock);
   114 	SDLNet_TCP_Close(IPCSock);
   116 SDLNet_Quit
   115 	SDLNet_Quit();
   117 end;
   116 end;
   118 
   117 
   119 procedure ParseIPCCommand(s: shortstring);
   118 procedure ParseIPCCommand(s: shortstring);
   120 var loTicks: Word;
   119 var loTicks: Word;
   121 begin
   120 begin
   341 isInLag:= (headcmd = nil) and tmpflag and (not CurrentTeam^.hasGone);
   340 isInLag:= (headcmd = nil) and tmpflag and (not CurrentTeam^.hasGone);
   342 
   341 
   343 if isInLag then fastUntilLag:= false
   342 if isInLag then fastUntilLag:= false
   344 end;
   343 end;
   345 
   344 
       
   345 procedure init_uIO;
       
   346 begin
       
   347 	IPCSock:= nil;
       
   348 
       
   349 	headcmd:= nil;
       
   350 	lastcmd:= nil;
       
   351 	isPonged:= false;	// was const
       
   352 
       
   353 	hiTicks:= 0;
       
   354 	SendEmptyPacketTicks:= 0;
       
   355 end;
       
   356 
   346 end.
   357 end.