hedgewars/uIO.pas
changeset 4403 0dfe26f48ec1
parent 4389 d1c65b60cd68
child 4404 6bae4e9461aa
equal deleted inserted replaced
4402:54a78ec6aac4 4403:0dfe26f48ec1
    26     hiTicks: Word;
    26     hiTicks: Word;
    27 
    27 
    28 procedure initModule;
    28 procedure initModule;
    29 procedure freeModule;
    29 procedure freeModule;
    30 
    30 
    31 procedure OutError(Msg: shortstring; isFatalError: boolean);
       
    32 procedure TryDo(Assert: boolean; Msg: shortstring; isFatal: boolean); inline;
       
    33 procedure SDLTry(Assert: boolean; isFatal: boolean);
       
    34 
       
    35 procedure SendIPC(s: shortstring);
    31 procedure SendIPC(s: shortstring);
    36 procedure SendIPCXY(cmd: char; X, Y: SmallInt);
    32 procedure SendIPCXY(cmd: char; X, Y: SmallInt);
    37 procedure SendIPCRaw(p: pointer; len: Longword);
    33 procedure SendIPCRaw(p: pointer; len: Longword);
    38 procedure SendIPCAndWaitReply(s: shortstring);
    34 procedure SendIPCAndWaitReply(s: shortstring);
    39 procedure SendIPCTimeInc;
    35 procedure SendIPCTimeInc;
    45 procedure InitIPC;
    41 procedure InitIPC;
    46 procedure CloseIPC;
    42 procedure CloseIPC;
    47 procedure NetGetNextCmd;
    43 procedure NetGetNextCmd;
    48 
    44 
    49 implementation
    45 implementation
    50 uses uConsole, uConsts, uChat, uTeams, uVariables, uCommands, uUtils;
    46 uses uConsole, uConsts, uChat, uTeams, uVariables, uCommands, uUtils, uDebug;
    51 
    47 
    52 type PCmd = ^TCmd;
    48 type PCmd = ^TCmd;
    53      TCmd = packed record
    49      TCmd = packed record
    54             Next: PCmd;
    50             Next: PCmd;
    55             loTime: Word;
    51             loTime: Word;
    66 
    62 
    67     headcmd: PCmd;
    63     headcmd: PCmd;
    68     lastcmd: PCmd;
    64     lastcmd: PCmd;
    69 
    65 
    70     SendEmptyPacketTicks: LongWord;
    66     SendEmptyPacketTicks: LongWord;
    71 
       
    72 
       
    73 procedure OutError(Msg: shortstring; isFatalError: boolean);
       
    74 begin
       
    75 WriteLnToConsole(Msg);
       
    76 if isFatalError then
       
    77     begin
       
    78     SendIPC('E' + GetLastConsoleLine);
       
    79     SDL_Quit;
       
    80     halt(1)
       
    81     end
       
    82 end;
       
    83 
       
    84 procedure TryDo(Assert: boolean; Msg: shortstring; isFatal: boolean);
       
    85 begin
       
    86 if not Assert then OutError(Msg, isFatal)
       
    87 end;
       
    88 
       
    89 procedure SDLTry(Assert: boolean; isFatal: boolean);
       
    90 begin
       
    91 if not Assert then OutError(SDL_GetError, isFatal)
       
    92 end;
       
    93 
    67 
    94 function AddCmd(Time: Word; str: shortstring): PCmd;
    68 function AddCmd(Time: Word; str: shortstring): PCmd;
    95 var command: PCmd;
    69 var command: PCmd;
    96 begin
    70 begin
    97 new(command);
    71 new(command);
   384 isInLag:= (headcmd = nil) and tmpflag and (not CurrentTeam^.hasGone);
   358 isInLag:= (headcmd = nil) and tmpflag and (not CurrentTeam^.hasGone);
   385 
   359 
   386 if isInLag then fastUntilLag:= false
   360 if isInLag then fastUntilLag:= false
   387 end;
   361 end;
   388 
   362 
       
   363 procedure chFatalError(var s: shortstring);
       
   364 begin
       
   365     SendIPC('E' + s);
       
   366 end;
       
   367 
   389 procedure initModule;
   368 procedure initModule;
   390 begin
   369 begin
       
   370     RegisterVariable('fatal', vtCommand, @chFatalError, true );
       
   371 
   391     IPCSock:= nil;
   372     IPCSock:= nil;
   392 
   373 
   393     headcmd:= nil;
   374     headcmd:= nil;
   394     lastcmd:= nil;
   375     lastcmd:= nil;
   395     isPonged:= false;   // was const
   376     isPonged:= false;   // was const