author | unc0rr |
Sun, 20 Nov 2011 19:45:40 +0300 | |
changeset 6407 | f63b2330147a |
parent 5132 | 11d61349efcf |
child 5286 | 22c1f4833a86 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
4976 | 3 |
* Copyright (c) 2004-2011 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 4 |
* |
183 | 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 |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
4 | 8 |
* |
183 | 9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
4 | 13 |
* |
183 | 14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
4 | 17 |
*) |
18 |
||
2630 | 19 |
{$INCLUDE "options.inc"} |
20 |
||
4 | 21 |
unit uConsole; |
22 |
interface |
|
23 |
||
3038 | 24 |
procedure initModule; |
25 |
procedure freeModule; |
|
4 | 26 |
procedure WriteToConsole(s: shortstring); |
27 |
procedure WriteLnToConsole(s: shortstring); |
|
53 | 28 |
function GetLastConsoleLine: shortstring; |
4 | 29 |
|
30 |
implementation |
|
4437
05192cdbce9b
un-break build (wrong merge in uConsole) and update project file with the new sources
koda
parents:
4436
diff
changeset
|
31 |
uses Types, uVariables, uUtils; |
950 | 32 |
|
371 | 33 |
const cLineWidth: LongInt = 0; |
4555
85150dfb5959
Try to avoid binary data in log, use shorter descriptions
unc0rr
parents:
4437
diff
changeset
|
34 |
cLinesCount = 8; |
351 | 35 |
|
4437
05192cdbce9b
un-break build (wrong merge in uConsole) and update project file with the new sources
koda
parents:
4436
diff
changeset
|
36 |
type |
785 | 37 |
TTextLine = record |
38 |
s: shortstring; |
|
39 |
end; |
|
4 | 40 |
|
785 | 41 |
var ConsoleLines: array[byte] of TTextLine; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
42 |
CurrLine: LongInt; |
4 | 43 |
|
785 | 44 |
procedure SetLine(var tl: TTextLine; str: shortstring); |
45 |
begin |
|
46 |
with tl do |
|
47 |
s:= str; |
|
48 |
end; |
|
49 |
||
4 | 50 |
procedure WriteToConsole(s: shortstring); |
371 | 51 |
var Len: LongInt; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
52 |
done: boolean; |
4 | 53 |
begin |
3818
e668970413e6
add a noconsole symbol, update the project file for appstore distribution
koda
parents:
3777
diff
changeset
|
54 |
{$IFNDEF NOCONSOLE} |
4900 | 55 |
AddFileLog('[Con] ' + s); |
5132
11d61349efcf
Make WriteLnToConsole write to stderr instead of stdout
unc0rr
parents:
4976
diff
changeset
|
56 |
Write(stderr, s); |
4046
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
57 |
done:= false; |
3697 | 58 |
|
4046
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
59 |
while not done do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2915
diff
changeset
|
60 |
begin |
4046
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
61 |
Len:= cLineWidth - Length(ConsoleLines[CurrLine].s); |
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
62 |
SetLine(ConsoleLines[CurrLine], ConsoleLines[CurrLine].s + copy(s, 1, Len)); |
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
63 |
Delete(s, 1, Len); |
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
64 |
if byte(ConsoleLines[CurrLine].s[0]) = cLineWidth then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2915
diff
changeset
|
65 |
begin |
4046
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
66 |
inc(CurrLine); |
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
67 |
if CurrLine = cLinesCount then CurrLine:= 0; |
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
68 |
PByte(@ConsoleLines[CurrLine].s)^:= 0 |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2915
diff
changeset
|
69 |
end; |
4046
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
70 |
done:= (Length(s) = 0); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2915
diff
changeset
|
71 |
end; |
3818
e668970413e6
add a noconsole symbol, update the project file for appstore distribution
koda
parents:
3777
diff
changeset
|
72 |
{$ENDIF} |
4 | 73 |
end; |
74 |
||
75 |
procedure WriteLnToConsole(s: shortstring); |
|
76 |
begin |
|
3825 | 77 |
{$IFNDEF NOCONSOLE} |
4046
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
78 |
WriteToConsole(s); |
5132
11d61349efcf
Make WriteLnToConsole write to stderr instead of stdout
unc0rr
parents:
4976
diff
changeset
|
79 |
WriteLn(stderr); |
4046
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
80 |
inc(CurrLine); |
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
81 |
if CurrLine = cLinesCount then |
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
82 |
CurrLine:= 0; |
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
83 |
PByte(@ConsoleLines[CurrLine].s)^:= 0 |
3818
e668970413e6
add a noconsole symbol, update the project file for appstore distribution
koda
parents:
3777
diff
changeset
|
84 |
{$ENDIF} |
4 | 85 |
end; |
86 |
||
87 |
||
53 | 88 |
function GetLastConsoleLine: shortstring; |
2695 | 89 |
var valueStr: shortstring; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2915
diff
changeset
|
90 |
i: LongWord; |
53 | 91 |
begin |
1242 | 92 |
i:= (CurrLine + cLinesCount - 2) mod cLinesCount; |
2695 | 93 |
valueStr:= ConsoleLines[i].s; |
1242 | 94 |
|
2695 | 95 |
valueStr:= valueStr + #10; |
1242 | 96 |
|
97 |
i:= (CurrLine + cLinesCount - 1) mod cLinesCount; |
|
2695 | 98 |
valueStr:= valueStr + ConsoleLines[i].s; |
1242 | 99 |
|
2695 | 100 |
GetLastConsoleLine:= valueStr; |
53 | 101 |
end; |
102 |
||
3038 | 103 |
procedure initModule; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
104 |
var i: LongInt; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
105 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2915
diff
changeset
|
106 |
CurrLine:= 0; |
3697 | 107 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2915
diff
changeset
|
108 |
// initConsole |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2915
diff
changeset
|
109 |
cLineWidth:= cScreenWidth div 10; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2915
diff
changeset
|
110 |
if cLineWidth > 255 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2915
diff
changeset
|
111 |
cLineWidth:= 255; |
3697 | 112 |
for i:= 0 to Pred(cLinesCount) do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2915
diff
changeset
|
113 |
PByte(@ConsoleLines[i])^:= 0; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
114 |
end; |
4 | 115 |
|
3038 | 116 |
procedure freeModule; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
117 |
begin |
4437
05192cdbce9b
un-break build (wrong merge in uConsole) and update project file with the new sources
koda
parents:
4436
diff
changeset
|
118 |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
119 |
end; |
4 | 120 |
|
121 |
end. |