hedgewars/uConsole.pas
branchhedgeroid
changeset 5286 22c1f4833a86
parent 5132 11d61349efcf
child 5460 c33b4daa4ce4
equal deleted inserted replaced
5284:34abd278344e 5286:22c1f4833a86
    24 procedure initModule;
    24 procedure initModule;
    25 procedure freeModule;
    25 procedure freeModule;
    26 procedure WriteToConsole(s: shortstring);
    26 procedure WriteToConsole(s: shortstring);
    27 procedure WriteLnToConsole(s: shortstring);
    27 procedure WriteLnToConsole(s: shortstring);
    28 function  GetLastConsoleLine: shortstring;
    28 function  GetLastConsoleLine: shortstring;
       
    29 function ShortStringAsPChar(var s: shortstring): PChar;
    29 
    30 
    30 implementation
    31 implementation
    31 uses Types, uVariables, uUtils;
    32 uses Types, uVariables, uUtils {$IFDEF ANDROID}, log in 'log.pas'{$ENDIF};
    32 
    33 
    33 const cLineWidth: LongInt = 0;
    34 const cLineWidth: LongInt = 0;
    34       cLinesCount = 8;
    35       cLinesCount = 8;
    35 
    36 
    36 type
    37 type
    50 procedure WriteToConsole(s: shortstring);
    51 procedure WriteToConsole(s: shortstring);
    51 var Len: LongInt;
    52 var Len: LongInt;
    52     done: boolean;
    53     done: boolean;
    53 begin
    54 begin
    54 {$IFNDEF NOCONSOLE}
    55 {$IFNDEF NOCONSOLE}
       
    56  {$IFDEF ANDROID}
       
    57   Log.__android_log_write(Log.Android_LOG_DEBUG, 'HW_Engine', ShortStringAsPChar(s));
       
    58 {$ELSE}
    55 AddFileLog('[Con] ' + s);
    59 AddFileLog('[Con] ' + s);
    56 Write(stderr, s);
    60 Write(stderr, s);
    57 done:= false;
    61 done:= false;
    58 
    62 
    59 while not done do
    63 while not done do
    68         PByte(@ConsoleLines[CurrLine].s)^:= 0
    72         PByte(@ConsoleLines[CurrLine].s)^:= 0
    69         end;
    73         end;
    70     done:= (Length(s) = 0);
    74     done:= (Length(s) = 0);
    71     end;
    75     end;
    72 {$ENDIF}
    76 {$ENDIF}
       
    77 {$ENDIF}
    73 end;
    78 end;
    74 
    79 
    75 procedure WriteLnToConsole(s: shortstring);
    80 procedure WriteLnToConsole(s: shortstring);
    76 begin
    81 begin
    77 {$IFNDEF NOCONSOLE}
    82 {$IFNDEF NOCONSOLE}
    78 WriteToConsole(s);
    83 WriteToConsole(s);
       
    84 {$IFNDEF ANDROID}
    79 WriteLn(stderr);
    85 WriteLn(stderr);
    80 inc(CurrLine);
    86 inc(CurrLine);
    81 if CurrLine = cLinesCount then
    87 if CurrLine = cLinesCount then
    82     CurrLine:= 0;
    88     CurrLine:= 0;
    83 PByte(@ConsoleLines[CurrLine].s)^:= 0
    89 PByte(@ConsoleLines[CurrLine].s)^:= 0
       
    90 {$ENDIF}
    84 {$ENDIF}
    91 {$ENDIF}
    85 end;
    92 end;
    86 
    93 
    87 
    94 
    88 function GetLastConsoleLine: shortstring;
    95 function GetLastConsoleLine: shortstring;
   116 procedure freeModule;
   123 procedure freeModule;
   117 begin
   124 begin
   118 
   125 
   119 end;
   126 end;
   120 
   127 
       
   128 Function ShortStringAsPChar(var S: ShortString) : PChar;
       
   129 Var NewString : String;
       
   130 Begin
       
   131 if Length(S) = High(S) then Dec(S[0]);
       
   132 s[Ord(Length(s))+1] := #0;
       
   133 Result := @S[1];
       
   134 End;
       
   135 
   121 end.
   136 end.