src/render/rConsoleGraph.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023 
00024 ***************************************************************************
00025 
00026 */
00027 
00028 #include "aa_config.h"
00029 
00030 #ifndef DEDICATED
00031 
00032 #include "rFont.h"
00033 #include "tSysTime.h"
00034 #include "rConsole.h"
00035 #include "rSysdep.h"
00036 #include "rScreen.h"
00037 #include "rGL.h"
00038 #include "tConfiguration.h"
00039 #include "rDisplayList.h"
00040 
00041 static tColoredString sr_centerString;
00042 static REAL center_r,center_g,center_b,center_fadetime;
00043 
00044 static REAL Time;
00045 
00046 static rDisplayListAlphaSensitive sr_consoleDisplayList;
00047 
00048 static void sr_ConsolePerFrame(){
00049     if (sr_con.autoDisplayAtSwap)
00050         sr_con.Render();
00051 }
00052 
00053 static rPerFrameTask console_pf(&sr_ConsolePerFrame);
00054 
00055 
00056 void rConsole::DisplayAtNewline(){
00057     bool sw=autoDisplayAtSwap;
00058     autoDisplayAtSwap=true;
00059     if (sr_glOut){
00060         rSysDep::SwapGL();
00061         rSysDep::ClearGL();
00062     }
00063     autoDisplayAtSwap=sw;
00064 }
00065 
00066 REAL centerMessageY=0;
00067 
00068 static tConfItem<REAL> cmlocy("CM_LOCY",centerMessageY);
00069 
00070 static int sr_columns = 78;
00071 static tConfItem<int> sr_columnsConf("CONSOLE_COLUMNS",sr_columns);
00072 
00073 static int sr_indent = 3;
00074 static tConfItem<int> sr_indentConf("CONSOLE_INDENT",sr_indent);
00075 
00076 void rConsole::Render(){
00077     if (!sr_glOut)
00078         return;
00079 
00080     sr_ResetRenderState(true);
00081 
00082     REAL W=sr_screenWidth;
00083     REAL H=sr_screenHeight;
00084 
00085     // previous logic
00086     //REAL MW=400;
00087     //REAL MH=(MW*3)/4;
00088     //if(W>MW)
00089     //    W=MW;
00090     //if(H>MH)
00091     //    H=MH;
00092     // rCWIDTH_CON=10/W;
00093     // rCHEIGHT_CON=18/H;
00094 
00095     // the text field has an openGL coordinate with of 1.9; cram the specified number
00096     // of columns in it
00097     rCWIDTH_CON=1.9/sr_columns;
00098 
00099     // get corresponding character height
00100     rCHEIGHT_CON=rCWIDTH_CON*W*9/(5*H);
00101 
00102     if (sr_screen){
00103         Time=tSysTimeFloat();
00104 
00105         if (Time-center_fadetime<2){
00106             REAL alpha=center_fadetime-Time+1;
00107             if (alpha>1) alpha=1;
00108             if (alpha<0) alpha=0;
00109             rTextField::SetDefaultColor( tColor(center_r,center_g,center_b,alpha) );
00110 
00111             REAL width=rCWIDTH_CON*4;
00112             REAL height=rCHEIGHT_CON*4;
00113             REAL len=sr_centerString.LongestLine();
00114             REAL lines=(REAL)(sr_centerString.Count('\n')+1);
00115 
00116             REAL space = 1.6;
00117             REAL needed = width * len;
00118             if (needed > space) {
00119                 width *= space/needed;
00120                 height *= space/needed;
00121             }
00122             space = 0.9 + centerMessageY;
00123             needed = height*lines;
00124             if (needed > space) {
00125                 width *= space/needed;
00126                 height *= space/needed;
00127             }
00128 
00129             DisplayText(0,centerMessageY,height,sr_centerString,sr_fontCenterMessage);
00130             //std::cerr << "DisplayText(0," << centerMessageY << "," << (rCWIDTH_CON*4*fak) << "," << (rCHEIGHT_CON*4*fak) << "," <<sr_centerString << ");\n";
00131         }
00132 
00133         if (sr_textOut || rForceTextCallback::ForceText()){
00134             if (lastCustomTimeout<Time-5 &&
00135                     lastTimeout+timeout<Time && currentTop<currentIn){
00136                 currentTop++;
00137                 lastTimeout=Time;
00138             }
00139 
00140             static int lastTop = currentTop;
00141             static int lastIn  = currentIn;
00142             if ( lastTop != currentTop || lastIn != currentIn )
00143             {
00144                 lastTop = currentTop;
00145                 lastIn  = currentIn;
00146                 sr_consoleDisplayList.Clear();
00147             }
00148 
00149             rTextField::SetDefaultColor( tColor(1,1,1) );
00150 
00151             if ( sr_consoleDisplayList.Call() )
00152             {
00153                 return;
00154             }
00155             rDisplayListFiller filler( sr_consoleDisplayList );
00156 
00157             rTextField out(-.95f,.99f,rCHEIGHT_CON, sr_fontConsole);//,&rFont::s_defaultFontSmall);
00158             out.SetWidth(1.9f);
00159             out.EnableLineWrap();
00160             out.SetIndent(sr_indent);
00161 
00162             int i;
00163             for (i=currentTop;i<=currentIn && i<=currentTop+MaxHeight();i++)
00164                 if (lines[i].Len()>1){
00165                     rTextField::SetDefaultColor( tColor(1,1,1) );
00166                     out << lines[i];
00167                     out.ResetColor();
00168                 }
00169             if (i<currentIn){
00170                 // rTextField::SetDefaultColor( tColor(1,.8,.5) );
00171                 out << tColoredString::ColorString( 1,.8,.5) << "       v   v   v   v   v   v   v   v   v\n";
00172             }
00173 
00174 
00175             int over=out.Lines()-Height();
00176             if (over>0 && (rSmallConsoleCallback::SmallColsole() || lastCustomTimeout<tSysTimeFloat()-15)){
00177                 lastTimeout=Time;
00178                 currentTop+=(over+1)/2;
00179             }
00180         }
00181 
00182         rTextField::SetDefaultColor( tColor(1,1,1) );
00183     }
00184 }
00185 
00186 
00187 void CenterDisplay(const tString &s,REAL timeout,REAL r,REAL g,REAL b){
00188     rCenterDisplayCallback::CenterDisplay();
00189 
00190     sr_centerString=s;
00191     center_fadetime=timeout+tSysTimeFloat();
00192     center_r=r;
00193     center_g=g;
00194     center_b=b;
00195 }
00196 
00197 void rConsole::DoCenterDisplay(const tString &s,REAL timeout,REAL r,REAL g,REAL b){
00198     rCenterDisplayCallback::CenterDisplay();
00199 
00200     sr_centerString=s;
00201     center_fadetime=timeout+tSysTimeFloat();
00202     center_r=r;
00203     center_g=g;
00204     center_b=b;
00205 }
00206 
00207 #else
00208 #include "rConsoleCout.cpp"
00209 #endif

Generated on Sat Mar 15 22:55:52 2008 for Armagetron Advanced by  doxygen 1.5.4