DEADSOFTWARE

Fix building for android
[d2df-sdl.git] / src / engine / e_log.pas
index 4ba21561043872f9546d5e13e6760c2bb8a6d25c..a1ca45c21e6da75c2948a2a4c99a32b5dc66103d 100644 (file)
@@ -1,4 +1,4 @@
-(* Copyright (C)  DooM 2D:Forever Developers
+(* Copyright (C)  Doom 2D: Forever Developers
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -40,7 +40,7 @@ function DecodeIPV4 (ip: LongWord): string;
 // start Write/WriteLn driver. it will write everything to cbuf.
 procedure e_InitWritelnDriver ();
 
-procedure e_LogWritefln (const fmt: AnsiString; args: array of const; category: TMsgType=TMsgType.Notify; writeTime: Boolean=true);
+procedure e_LogWritefln (const fmt: AnsiString; args: array of const; category: TMsgType=TMsgType.Notify; writeTime: Boolean=true; writeConsole: Boolean=true);
 procedure e_LogWriteln (const s: AnsiString; category: TMsgType=TMsgType.Notify; writeTime: Boolean=true);
 
 
@@ -54,6 +54,9 @@ var
 implementation
 
 uses
+  {$IFDEF ANDROID}
+    SDL2,
+  {$ENDIF}
   conbuf, utils;
 
 var
@@ -68,15 +71,24 @@ begin
 end;
 
 
+function consoleAllow (const s: String): Boolean;
+begin
+  Result := False;
+  if Pos('[Chat] ', s) = 1 then
+    Exit;
+  Result := True;
+end;
+
+
 procedure e_WriteLog (TextLine: String; RecordCategory: TMsgType; WriteTime: Boolean=True);
 begin
-  e_LogWritefln('%s', [TextLine], RecordCategory, WriteTime);
+  e_LogWritefln('%s', [TextLine], RecordCategory, WriteTime, consoleAllow(TextLine));
 end;
 
 
 procedure e_LogWriteln (const s: AnsiString; category: TMsgType=TMsgType.Notify; writeTime: Boolean=true);
 begin
-  e_LogWritefln('%s', [s], category, writeTime);
+  e_LogWritefln('%s', [s], category, writeTime, consoleAllow(s));
 end;
 
 
@@ -89,9 +101,22 @@ var
   ss: ShortString;
   slen: Integer;
   b: PByte;
+{$IFDEF ANDROID}
+  cstr: PChar;
+{$ENDIF}
 begin
   if (len < 1) then exit;
   b := PByte(@buf);
+
+{$IFDEF ANDROID}
+  cstr := GetMem(len + 1);
+  for slen := 0 to len - 1 do
+    cstr[slen] := Chr(b[slen]);
+  cstr[len] := #0;
+  SDL_Log(cstr, []);
+  Dispose(cstr);
+{$ENDIF}
+
   while (len > 0) do
   begin
     if (len > 255) then slen := 255 else slen := Integer(len);
@@ -167,7 +192,7 @@ begin
 end;
 
 
-procedure e_LogWritefln (const fmt: AnsiString; args: array of const; category: TMsgType=TMsgType.Notify; writeTime: Boolean=true);
+procedure e_LogWritefln (const fmt: AnsiString; args: array of const; category: TMsgType=TMsgType.Notify; writeTime: Boolean=true; writeConsole: Boolean=true);
 
   procedure xwrite (const s: AnsiString);
   begin
@@ -176,7 +201,7 @@ procedure e_LogWritefln (const fmt: AnsiString; args: array of const; category:
   end;
 
 begin
-  if driverInited and (length(fmt) > 0) then
+  if driverInited and (length(fmt) > 0) and writeConsole then
   begin
     case category of
       TMsgType.Fatal: write('FATAL: ');