1 (* |
1 (* |
2 * Hedgewars, a free turn based strategy game |
2 * Hedgewars, a free turn based strategy game |
3 * Copyright (c) 2004-2011 Andrey Korotaev <unC0Rr@gmail.com> |
3 * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com> |
4 * |
4 * |
5 * This program is free software; you can redistribute it and/or modify |
5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License as published by |
6 * it under the terms of the GNU General Public License as published by |
7 * the Free Software Foundation; version 2 of the License |
7 * the Free Software Foundation; version 2 of the License |
8 * |
8 * |
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(s: shortstring): PChar; |
29 function ShortStringAsPChar(s: shortstring): PChar; |
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 cLinesCount = 8; |
35 cLinesCount = 8; |
35 var cLineWidth: LongInt; |
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 {$IFNDEF NOCONSOLE} |
52 var Len: LongInt; |
53 var Len: LongInt; |
53 done: boolean; |
54 done: boolean; |
|
55 {$ENDIF} |
54 begin |
56 begin |
55 {$IFNDEF NOCONSOLE} |
57 {$IFNDEF NOCONSOLE} |
56 AddFileLog('[Con] ' + s); |
58 AddFileLog('[Con] ' + s); |
57 {$IFDEF ANDROID} |
59 {$IFDEF ANDROID} |
58 Log.__android_log_write(Log.Android_LOG_DEBUG, 'HW_Engine', ShortStringAsPChar('[Con]' + s)); |
60 Log.__android_log_write(Log.Android_LOG_DEBUG, 'HW_Engine', ShortStringAsPChar('[Con]' + s)); |
59 {$ELSE} |
61 {$ELSE} |
60 Write(stderr, s); |
62 Write(stderr, s); |
61 done:= false; |
63 done:= false; |
62 |
64 |
63 while not done do |
65 while not done do |
66 SetLine(ConsoleLines[CurrLine], ConsoleLines[CurrLine].s + copy(s, 1, Len)); |
68 SetLine(ConsoleLines[CurrLine], ConsoleLines[CurrLine].s + copy(s, 1, Len)); |
67 Delete(s, 1, Len); |
69 Delete(s, 1, Len); |
68 if byte(ConsoleLines[CurrLine].s[0]) = cLineWidth then |
70 if byte(ConsoleLines[CurrLine].s[0]) = cLineWidth then |
69 begin |
71 begin |
70 inc(CurrLine); |
72 inc(CurrLine); |
71 if CurrLine = cLinesCount then CurrLine:= 0; |
73 if CurrLine = cLinesCount then |
|
74 CurrLine:= 0; |
72 PByte(@ConsoleLines[CurrLine].s)^:= 0 |
75 PByte(@ConsoleLines[CurrLine].s)^:= 0 |
73 end; |
76 end; |
74 done:= (Length(s) = 0); |
77 done:= (Length(s) = 0); |
75 end; |
78 end; |
76 {$ENDIF} |
79 {$ENDIF} |
80 procedure WriteLnToConsole(s: shortstring); |
83 procedure WriteLnToConsole(s: shortstring); |
81 begin |
84 begin |
82 {$IFNDEF NOCONSOLE} |
85 {$IFNDEF NOCONSOLE} |
83 WriteToConsole(s); |
86 WriteToConsole(s); |
84 {$IFNDEF ANDROID} |
87 {$IFNDEF ANDROID} |
85 WriteLn(stderr); |
88 WriteLn(stderr, ''); |
86 inc(CurrLine); |
89 inc(CurrLine); |
87 if CurrLine = cLinesCount then |
90 if CurrLine = cLinesCount then |
88 CurrLine:= 0; |
91 CurrLine:= 0; |
89 PByte(@ConsoleLines[CurrLine].s)^:= 0 |
92 PByte(@ConsoleLines[CurrLine].s)^:= 0 |
90 {$ENDIF} |
93 {$ENDIF} |
91 {$ENDIF} |
94 {$ENDIF} |
92 end; |
95 end; |
93 |
96 |
94 function ShortStringAsPChar(s: ShortString) : PChar; |
97 function ShortStringAsPChar(s: shortstring) : PChar; |
95 begin |
98 begin |
96 if Length(s) = High(s) then Dec(s[0]); |
99 if Length(s) = High(s) then |
|
100 Dec(s[0]); |
97 s[Ord(Length(s))+1] := #0; |
101 s[Ord(Length(s))+1] := #0; |
98 exit(@s[1]); |
102 ShortStringAsPChar:= @s[1]; |
99 end; |
103 end; |
100 |
104 |
101 function GetLastConsoleLine: shortstring; |
105 function GetLastConsoleLine: shortstring; |
102 var valueStr: shortstring; |
106 var valueStr: shortstring; |
103 i: LongWord; |
107 i: LongWord; |