1 /*
2
3 *************************************************************************
4
5 ArmageTron -- Just another Tron Lightcycle Game in 3D.
6 Copyright (C) 2000 Manuel Moos (manuel@moosnet.de)
7
8 **************************************************************************
9
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2
13 of the License, or (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24 ***************************************************************************
25
26 */
27
28 #include "rFont.h"
29 #include "tSysTime.h"
30 #include "tConfiguration.h"
31 #include "rConsole.h"
32 #include "rScreen.h"
33 #include <iostream>
34
35
rConsole()36 rConsole::rConsole()
37 :currentTop(0),currentIn(0),
38 lastCustomTimeout(-20),height(8),timeout(2),
39 fullscreen(0),autoDisplayAtSwap(1),
40 autoDisplayAtNewline(0){
41 RegisterBetterConsole(this);
42 }
43
44 static int sr_rows = 5;
45 static tConfItem<int> sr_rowsConf("CONSOLE_ROWS",sr_rows);
46
47 static int sr_maxRows = 19;
48 static tConfItem<int> sr_maxRowsConf("CONSOLE_ROWS_MAX",sr_maxRows);
49
MaxHeight()50 int rConsole::MaxHeight(){
51 int x=int(1.7/rCHEIGHT_CON)-1;;
52 if (x>sr_maxRows)
53 return sr_maxRows;
54 else
55 return x;
56 }
57
Height()58 int rConsole::Height(){
59 if (fullscreen)
60 return MaxHeight();
61 else if (rSmallConsoleCallback::SmallColsole())
62 return sr_rows;
63 else
64 return height > sr_rows ? height : sr_rows;
65
66 }
Timeout()67 REAL rConsole::Timeout(){
68 if (fullscreen)
69 return(100000000.0);
70 else
71 return timeout;
72 }
73
74
SetHeight(int h,bool stop_scroll)75 void rConsole::SetHeight(int h,bool stop_scroll){
76 height=h;
77 if (stop_scroll)
78 lastCustomTimeout=tSysTimeFloat()-30;
79 }
80
SetTimeout(REAL to)81 void rConsole::SetTimeout(REAL to){timeout=to;}
82
83
84 //#ifdef DEBUG
85 //#define MAXBACK 10
86 //#define BACKEXTRA 5
87 //#else
88 #define MAXBACK 300
89 #define BACKEXTRA 100
90 //#endif
91
92 REAL rCWIDTH_CON=REAL(16/640.0);
93 REAL rCHEIGHT_CON=REAL(32/480.0);
94
95
96
DoPrint(const tString & s)97 tConsole & rConsole::DoPrint(const tString &s){
98 bool print_to_stdout=false;
99 #ifdef DEBUG
100 print_to_stdout=true;
101 #endif
102 bool swap = false;
103
104 if (!sr_screen)
105 print_to_stdout=true;
106 if (print_to_stdout)
107 {
108 std::cout << tColoredString::RemoveColors(s);
109 std::cout.flush();
110 }
111
112 if (sr_screen){
113 const char *c=s;
114 while (*c!=0){
115 lines[currentIn] << *c;
116 if (*c=='\n'){
117 if (currentIn<=currentTop+1)
118 lastTimeout=tSysTimeFloat()+4;
119 currentIn++;
120 if (autoDisplayAtNewline && !rNoAutoDisplayAtNewlineCallback::NoAutoDisplayAtNewline() && (sr_textOut ||
121 rForceTextCallback::ForceText()))
122 swap = true;
123
124 if (currentIn >= MAXBACK+BACKEXTRA){
125 for(int i=0;i<MAXBACK;i++)
126 lines[i]=lines[i+BACKEXTRA];
127
128 for(int j=lines.Len()-1;j>=MAXBACK;j--)
129 lines[j].Clear();
130
131 currentIn-=BACKEXTRA;
132 currentTop-=BACKEXTRA;
133 if (currentTop<0)
134 currentTop=0;
135 }
136 }
137 c++;
138 }
139
140 if (rSmallConsoleCallback::SmallColsole() || lastCustomTimeout<tSysTimeFloat()-15)
141 while ((currentIn-currentTop) > Height())
142 currentTop++;
143 }
144
145 if (swap)
146 DisplayAtNewline();
147
148 return *this;
149 }
150
Scroll(int dir)151 void rConsole::Scroll(int dir){
152 rCenterDisplayCallback::CenterDisplay();
153
154 currentTop+=dir*10;
155 lastCustomTimeout=tSysTimeFloat();
156 if (currentTop<0)
157 currentTop=0;
158
159 if (currentTop>currentIn-10)
160 lastCustomTimeout=tSysTimeFloat()-10;
161
162 if (currentTop>currentIn){
163 currentTop=currentIn;
164 lastCustomTimeout=tSysTimeFloat()-20;
165 }
166 }
167
ColorString(REAL r,REAL g,REAL b) const168 tString rConsole::ColorString(REAL r, REAL g, REAL b) const{
169 tColoredString ret;
170 ret << tColoredString::ColorString(r,g,b);
171 return ret;
172 }
173
174 rConsole sr_con;
175
176 // ---------------------------------------------------
177
178 static tCallbackOr *tCallbackOr_anchor;
179
rForceTextCallback(BOOLRETFUNC * f)180 rForceTextCallback::rForceTextCallback(BOOLRETFUNC *f)
181 :tCallbackOr(tCallbackOr_anchor, f){}
182
ForceText()183 bool rForceTextCallback::ForceText(){
184 return Exec(tCallbackOr_anchor);
185 }
186
187 static tCallbackOr *SmallColsole_anchor;
188
rSmallConsoleCallback(BOOLRETFUNC * f)189 rSmallConsoleCallback::rSmallConsoleCallback(BOOLRETFUNC *f)
190 :tCallbackOr(SmallColsole_anchor, f){}
191
SmallColsole()192 bool rSmallConsoleCallback::SmallColsole(){
193 return Exec(SmallColsole_anchor);
194 }
195
196
197 static tCallback *CenterDisplay_anchor;
198
rCenterDisplayCallback(VOIDFUNC * f)199 rCenterDisplayCallback::rCenterDisplayCallback(VOIDFUNC *f)
200 :tCallback(CenterDisplay_anchor, f){}
201
CenterDisplay()202 void rCenterDisplayCallback::CenterDisplay(){
203 Exec(CenterDisplay_anchor);
204 }
205
206 static tCallbackOr *NoAutoDisplayAtNewline_anchor;
207
rNoAutoDisplayAtNewlineCallback(BOOLRETFUNC * f)208 rNoAutoDisplayAtNewlineCallback::rNoAutoDisplayAtNewlineCallback(BOOLRETFUNC *f)
209 :tCallbackOr(NoAutoDisplayAtNewline_anchor, f){}
210
NoAutoDisplayAtNewline()211 bool rNoAutoDisplayAtNewlineCallback::NoAutoDisplayAtNewline(){
212 return Exec(NoAutoDisplayAtNewline_anchor);
213 }
214
215
216
217
218
219