hedgewars/uConsole.pas
changeset 6580 6155187bf599
parent 6528 fb2918089225
child 6700 e04da46ee43c
equal deleted inserted replaced
6579:fc52f7c22c9b 6580:6155187bf599
    30 
    30 
    31 implementation
    31 implementation
    32 uses Types, uVariables, uUtils {$IFDEF ANDROID}, log in 'log.pas'{$ENDIF};
    32 uses Types, uVariables, uUtils {$IFDEF ANDROID}, log in 'log.pas'{$ENDIF};
    33 
    33 
    34 const cLineWidth: LongInt = 0;
    34 const cLineWidth: LongInt = 0;
    35       cLinesCount = 8;
    35     cLinesCount = 8;
    36 
    36 
    37 type
    37 type
    38       TTextLine = record
    38     TTextLine = record
    39                   s: shortstring;
    39         s: shortstring
    40                   end;
    40         end;
    41 
    41 
    42 var   ConsoleLines: array[byte] of TTextLine;
    42 var   ConsoleLines: array[byte] of TTextLine;
    43       CurrLine: LongInt;
    43       CurrLine: LongInt;
    44 
    44 
    45 procedure SetLine(var tl: TTextLine; str: shortstring);
    45 procedure SetLine(var tl: TTextLine; str: shortstring);
    46 begin
    46 begin
    47 with tl do
    47 with tl do
    48      s:= str;
    48     s:= str;
    49 end;
    49 end;
    50 
    50 
    51 procedure WriteToConsole(s: shortstring);
    51 procedure WriteToConsole(s: shortstring);
    52 var Len: LongInt;
    52 var Len: LongInt;
    53     done: boolean;
    53     done: boolean;
    54 begin
    54 begin
    55 {$IFNDEF NOCONSOLE}
    55 {$IFNDEF NOCONSOLE}
    56 AddFileLog('[Con] ' + s);
    56 AddFileLog('[Con] ' + s);
    57 {$IFDEF ANDROID}
    57 {$IFDEF ANDROID}
    58   Log.__android_log_write(Log.Android_LOG_DEBUG, 'HW_Engine', ShortStringAsPChar('[Con]' + s));
    58     Log.__android_log_write(Log.Android_LOG_DEBUG, 'HW_Engine', ShortStringAsPChar('[Con]' + s));
    59 {$ELSE}
    59 {$ELSE}
    60 Write(stderr, s);
    60 Write(stderr, s);
    61 done:= false;
    61 done:= false;
    62 
    62 
    63 while not done do
    63 while not done do
    66     SetLine(ConsoleLines[CurrLine], ConsoleLines[CurrLine].s + copy(s, 1, Len));
    66     SetLine(ConsoleLines[CurrLine], ConsoleLines[CurrLine].s + copy(s, 1, Len));
    67     Delete(s, 1, Len);
    67     Delete(s, 1, Len);
    68     if byte(ConsoleLines[CurrLine].s[0]) = cLineWidth then
    68     if byte(ConsoleLines[CurrLine].s[0]) = cLineWidth then
    69         begin
    69         begin
    70         inc(CurrLine);
    70         inc(CurrLine);
    71         if CurrLine = cLinesCount then CurrLine:= 0;
    71         if CurrLine = cLinesCount then
       
    72             CurrLine:= 0;
    72         PByte(@ConsoleLines[CurrLine].s)^:= 0
    73         PByte(@ConsoleLines[CurrLine].s)^:= 0
    73         end;
    74         end;
    74     done:= (Length(s) = 0);
    75     done:= (Length(s) = 0);
    75     end;
    76     end;
    76 {$ENDIF}
    77 {$ENDIF}
    91 {$ENDIF}
    92 {$ENDIF}
    92 end;
    93 end;
    93 
    94 
    94 function ShortStringAsPChar(s: shortstring) : PChar;
    95 function ShortStringAsPChar(s: shortstring) : PChar;
    95 begin
    96 begin
    96     if Length(s) = High(s) then Dec(s[0]);
    97     if Length(s) = High(s) then
       
    98         Dec(s[0]);
    97     s[Ord(Length(s))+1] := #0;
    99     s[Ord(Length(s))+1] := #0;
    98     exit(@s[1]);
   100     exit(@s[1]);
    99 end;
   101 end;
   100 
   102 
   101 function GetLastConsoleLine: shortstring;
   103 function GetLastConsoleLine: shortstring;