hedgewars/uConsole.pas
author koda
Sat, 05 May 2012 19:04:59 +0100
changeset 7028 0f60591f3a16
parent 6990 40e5af28d026
child 7134 beb16926ae5c
permissions -rw-r--r--
old typed const moved to their proper unit
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
     1
(*
1066
1f1b3686a2b0 Update copyright headers a bit
unc0rr
parents: 1035
diff changeset
     2
 * Hedgewars, a free turn based strategy game
6700
e04da46ee43c the most important commit of the year
koda
parents: 6580
diff changeset
     3
 * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
     4
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
     8
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
    12
 * GNU General Public License for more details.
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    13
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
    14
 * You should have received a copy of the GNU General Public License
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
    15
 * along with this program; if not, write to the Free Software
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    17
 *)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    18
2630
079ef82eac75 revamped file access and debug display
koda
parents: 2599
diff changeset
    19
{$INCLUDE "options.inc"}
079ef82eac75 revamped file access and debug display
koda
parents: 2599
diff changeset
    20
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    21
unit uConsole;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    22
interface
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    23
3038
4e48c276a468 In pascal unit is a namespace
unc0rr
parents: 2990
diff changeset
    24
procedure initModule;
4e48c276a468 In pascal unit is a namespace
unc0rr
parents: 2990
diff changeset
    25
procedure freeModule;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    26
procedure WriteToConsole(s: shortstring);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    27
procedure WriteLnToConsole(s: shortstring);
53
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 51
diff changeset
    28
function  GetLastConsoleLine: shortstring;
6528
fb2918089225 added 'loaded locale' message, other minor things
koda
parents: 6444
diff changeset
    29
function  ShortStringAsPChar(s: shortstring): PChar;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    30
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    31
implementation
5286
22c1f4833a86 First commit..
Xeli
parents: 5132
diff changeset
    32
uses Types, uVariables, uUtils {$IFDEF ANDROID}, log in 'log.pas'{$ENDIF};
950
feb18ec0c5c2 Add nickname to message in more appropriate place
unc0rr
parents: 946
diff changeset
    33
6982
8d41d22a291d breaking news, we don't support typed consts anymore
koda
parents: 6700
diff changeset
    34
const cLinesCount = 8;
8d41d22a291d breaking news, we don't support typed consts anymore
koda
parents: 6700
diff changeset
    35
var   cLineWidth: LongInt;
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 312
diff changeset
    36
4437
05192cdbce9b un-break build (wrong merge in uConsole) and update project file with the new sources
koda
parents: 4436
diff changeset
    37
type
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6528
diff changeset
    38
    TTextLine = record
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6528
diff changeset
    39
        s: shortstring
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6528
diff changeset
    40
        end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    41
785
ac538f1a629e Start console OpenGL reincarnation
unc0rr
parents: 783
diff changeset
    42
var   ConsoleLines: array[byte] of TTextLine;
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
    43
      CurrLine: LongInt;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    44
785
ac538f1a629e Start console OpenGL reincarnation
unc0rr
parents: 783
diff changeset
    45
procedure SetLine(var tl: TTextLine; str: shortstring);
ac538f1a629e Start console OpenGL reincarnation
unc0rr
parents: 783
diff changeset
    46
begin
ac538f1a629e Start console OpenGL reincarnation
unc0rr
parents: 783
diff changeset
    47
with tl do
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6528
diff changeset
    48
    s:= str;
785
ac538f1a629e Start console OpenGL reincarnation
unc0rr
parents: 783
diff changeset
    49
end;
ac538f1a629e Start console OpenGL reincarnation
unc0rr
parents: 783
diff changeset
    50
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    51
procedure WriteToConsole(s: shortstring);
371
731ad6d27bd1 integer -> LongInt
unc0rr
parents: 351
diff changeset
    52
var Len: LongInt;
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
    53
    done: boolean;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    54
begin
3818
e668970413e6 add a noconsole symbol, update the project file for appstore distribution
koda
parents: 3777
diff changeset
    55
{$IFNDEF NOCONSOLE}
5661
45618bdce725 Fixed AddFileLog, there's now a log created in /sdcard/Android/data/org.hedgewars.mobile/cache/Data/
Xeli
parents: 5460
diff changeset
    56
AddFileLog('[Con] ' + s);
45618bdce725 Fixed AddFileLog, there's now a log created in /sdcard/Android/data/org.hedgewars.mobile/cache/Data/
Xeli
parents: 5460
diff changeset
    57
{$IFDEF ANDROID}
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6528
diff changeset
    58
    Log.__android_log_write(Log.Android_LOG_DEBUG, 'HW_Engine', ShortStringAsPChar('[Con]' + s));
5286
22c1f4833a86 First commit..
Xeli
parents: 5132
diff changeset
    59
{$ELSE}
5132
11d61349efcf Make WriteLnToConsole write to stderr instead of stdout
unc0rr
parents: 4976
diff changeset
    60
Write(stderr, s);
4046
cfdbddc4b385 making indentation consistent (noticed while debugging)
nemo
parents: 4003
diff changeset
    61
done:= false;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3617
diff changeset
    62
4046
cfdbddc4b385 making indentation consistent (noticed while debugging)
nemo
parents: 4003
diff changeset
    63
while not done do
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2915
diff changeset
    64
    begin
4046
cfdbddc4b385 making indentation consistent (noticed while debugging)
nemo
parents: 4003
diff changeset
    65
    Len:= cLineWidth - Length(ConsoleLines[CurrLine].s);
cfdbddc4b385 making indentation consistent (noticed while debugging)
nemo
parents: 4003
diff changeset
    66
    SetLine(ConsoleLines[CurrLine], ConsoleLines[CurrLine].s + copy(s, 1, Len));
cfdbddc4b385 making indentation consistent (noticed while debugging)
nemo
parents: 4003
diff changeset
    67
    Delete(s, 1, Len);
cfdbddc4b385 making indentation consistent (noticed while debugging)
nemo
parents: 4003
diff changeset
    68
    if byte(ConsoleLines[CurrLine].s[0]) = cLineWidth then
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2915
diff changeset
    69
        begin
4046
cfdbddc4b385 making indentation consistent (noticed while debugging)
nemo
parents: 4003
diff changeset
    70
        inc(CurrLine);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6528
diff changeset
    71
        if CurrLine = cLinesCount then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6528
diff changeset
    72
            CurrLine:= 0;
4046
cfdbddc4b385 making indentation consistent (noticed while debugging)
nemo
parents: 4003
diff changeset
    73
        PByte(@ConsoleLines[CurrLine].s)^:= 0
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2915
diff changeset
    74
        end;
4046
cfdbddc4b385 making indentation consistent (noticed while debugging)
nemo
parents: 4003
diff changeset
    75
    done:= (Length(s) = 0);
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2915
diff changeset
    76
    end;
3818
e668970413e6 add a noconsole symbol, update the project file for appstore distribution
koda
parents: 3777
diff changeset
    77
{$ENDIF}
5286
22c1f4833a86 First commit..
Xeli
parents: 5132
diff changeset
    78
{$ENDIF}
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    79
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    80
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    81
procedure WriteLnToConsole(s: shortstring);
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    82
begin
3825
fd6c20cd90e3 typos, reduced sound size and last minute fixes
koda
parents: 3818
diff changeset
    83
{$IFNDEF NOCONSOLE}
4046
cfdbddc4b385 making indentation consistent (noticed while debugging)
nemo
parents: 4003
diff changeset
    84
WriteToConsole(s);
5286
22c1f4833a86 First commit..
Xeli
parents: 5132
diff changeset
    85
{$IFNDEF ANDROID}
5132
11d61349efcf Make WriteLnToConsole write to stderr instead of stdout
unc0rr
parents: 4976
diff changeset
    86
WriteLn(stderr);
4046
cfdbddc4b385 making indentation consistent (noticed while debugging)
nemo
parents: 4003
diff changeset
    87
inc(CurrLine);
cfdbddc4b385 making indentation consistent (noticed while debugging)
nemo
parents: 4003
diff changeset
    88
if CurrLine = cLinesCount then
cfdbddc4b385 making indentation consistent (noticed while debugging)
nemo
parents: 4003
diff changeset
    89
    CurrLine:= 0;
cfdbddc4b385 making indentation consistent (noticed while debugging)
nemo
parents: 4003
diff changeset
    90
PByte(@ConsoleLines[CurrLine].s)^:= 0
3818
e668970413e6 add a noconsole symbol, update the project file for appstore distribution
koda
parents: 3777
diff changeset
    91
{$ENDIF}
5286
22c1f4833a86 First commit..
Xeli
parents: 5132
diff changeset
    92
{$ENDIF}
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    93
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    94
6444
eddc1e9bcd81 - Help parser more
unc0rr
parents: 6033
diff changeset
    95
function ShortStringAsPChar(s: shortstring) : PChar;
6027
302408e45052 code working on ios now
koda
parents: 5661
diff changeset
    96
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6528
diff changeset
    97
    if Length(s) = High(s) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6528
diff changeset
    98
        Dec(s[0]);
6027
302408e45052 code working on ios now
koda
parents: 5661
diff changeset
    99
    s[Ord(Length(s))+1] := #0;
6990
40e5af28d026 change every return value into a more pascal-ish form, using the name of the fucntion (helps the parser and macpas compaitilibity)
koda
parents: 6982
diff changeset
   100
    ShortStringAsPChar:= @s[1];
6027
302408e45052 code working on ios now
koda
parents: 5661
diff changeset
   101
end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   102
53
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 51
diff changeset
   103
function GetLastConsoleLine: shortstring;
2695
ed789a7ef68d makes freepascal code compatible with OBJFPC mode
koda
parents: 2630
diff changeset
   104
var valueStr: shortstring;
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2915
diff changeset
   105
    i: LongWord;
53
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 51
diff changeset
   106
begin
1242
4aca5f7b2504 Hats now fully implemented for local game
unc0rr
parents: 1066
diff changeset
   107
i:= (CurrLine + cLinesCount - 2) mod cLinesCount;
2695
ed789a7ef68d makes freepascal code compatible with OBJFPC mode
koda
parents: 2630
diff changeset
   108
valueStr:= ConsoleLines[i].s;
1242
4aca5f7b2504 Hats now fully implemented for local game
unc0rr
parents: 1066
diff changeset
   109
2695
ed789a7ef68d makes freepascal code compatible with OBJFPC mode
koda
parents: 2630
diff changeset
   110
valueStr:= valueStr + #10;
1242
4aca5f7b2504 Hats now fully implemented for local game
unc0rr
parents: 1066
diff changeset
   111
4aca5f7b2504 Hats now fully implemented for local game
unc0rr
parents: 1066
diff changeset
   112
i:= (CurrLine + cLinesCount - 1) mod cLinesCount;
2695
ed789a7ef68d makes freepascal code compatible with OBJFPC mode
koda
parents: 2630
diff changeset
   113
valueStr:= valueStr + ConsoleLines[i].s;
1242
4aca5f7b2504 Hats now fully implemented for local game
unc0rr
parents: 1066
diff changeset
   114
2695
ed789a7ef68d makes freepascal code compatible with OBJFPC mode
koda
parents: 2630
diff changeset
   115
GetLastConsoleLine:= valueStr;
53
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 51
diff changeset
   116
end;
0e27949850e3 - Fixed bubble theme object
unc0rr
parents: 51
diff changeset
   117
3038
4e48c276a468 In pascal unit is a namespace
unc0rr
parents: 2990
diff changeset
   118
procedure initModule;
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   119
var i: LongInt;
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   120
begin
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2915
diff changeset
   121
    CurrLine:= 0;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3617
diff changeset
   122
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2915
diff changeset
   123
    // initConsole
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2915
diff changeset
   124
    cLineWidth:= cScreenWidth div 10;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2915
diff changeset
   125
    if cLineWidth > 255 then
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2915
diff changeset
   126
        cLineWidth:= 255;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3617
diff changeset
   127
    for i:= 0 to Pred(cLinesCount) do
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2915
diff changeset
   128
        PByte(@ConsoleLines[i])^:= 0;
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   129
end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   130
3038
4e48c276a468 In pascal unit is a namespace
unc0rr
parents: 2990
diff changeset
   131
procedure freeModule;
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   132
begin
4437
05192cdbce9b un-break build (wrong merge in uConsole) and update project file with the new sources
koda
parents: 4436
diff changeset
   133
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2695
diff changeset
   134
end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   135
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   136
end.