hedgewars/uIO.pas
changeset 4377 43945842da0c
parent 4376 9654205a9424
child 4389 d1c65b60cd68
--- a/hedgewars/uIO.pas	Thu Nov 18 11:50:02 2010 +0300
+++ b/hedgewars/uIO.pas	Thu Nov 18 12:12:51 2010 +0300
@@ -28,6 +28,10 @@
 procedure initModule;
 procedure freeModule;
 
+procedure OutError(Msg: shortstring; isFatalError: boolean);
+procedure TryDo(Assert: boolean; Msg: shortstring; isFatal: boolean); inline;
+procedure SDLTry(Assert: boolean; isFatal: boolean);
+
 procedure SendIPC(s: shortstring);
 procedure SendIPCXY(cmd: char; X, Y: SmallInt);
 procedure SendIPCRaw(p: pointer; len: Longword);
@@ -43,7 +47,7 @@
 procedure NetGetNextCmd;
 
 implementation
-uses uConsole, uConsts, uMisc, uLand, uChat, uTeams, uVariables, uCommands, uUtils;
+uses uConsole, uConsts, uLand, uChat, uTeams, uVariables, uCommands, uUtils;
 
 type PCmd = ^TCmd;
      TCmd = packed record
@@ -66,6 +70,27 @@
     SendEmptyPacketTicks: LongWord;
 
 
+procedure OutError(Msg: shortstring; isFatalError: boolean);
+begin
+WriteLnToConsole(Msg);
+if isFatalError then
+    begin
+    SendIPC('E' + GetLastConsoleLine);
+    SDL_Quit;
+    halt(1)
+    end
+end;
+
+procedure TryDo(Assert: boolean; Msg: shortstring; isFatal: boolean);
+begin
+if not Assert then OutError(Msg, isFatal)
+end;
+
+procedure SDLTry(Assert: boolean; isFatal: boolean);
+begin
+if not Assert then OutError(SDL_GetError, isFatal)
+end;
+
 function AddCmd(Time: Word; str: shortstring): PCmd;
 var command: PCmd;
 begin
@@ -212,6 +237,7 @@
 SendIPCRaw(@buf[0], length(buf) + 1)
 end;
 
+
 procedure SendIPC(s: shortstring);
 begin
 if IPCSock <> nil then