src/engine/eDebugLine.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 "eDebugLine.h"
00029 #include "tArray.h"
00030 #include "rRender.h"
00031 
00032 #ifdef DEBUG
00033 #define DEBUGLINE
00034 #endif
00035 
00036 
00037 static REAL se_r=1, se_g=1, se_b=1;
00038 static REAL se_timeout=.1;
00039 
00040 class eLineEntry
00041 {
00042 public:
00043     int    index;
00044     REAL   r, g, b;
00045     REAL   timeout;
00046     eCoord start , stop;
00047     REAL   startH, stopH;
00048 
00049     eLineEntry()
00050             :r(se_r), g(se_g), b(se_b),
00051             timeout(se_timeout)
00052     {
00053     }
00054 
00055     void Delete();
00056     static eLineEntry& Create();
00057 };
00058 
00059 static tArray<eLineEntry> se_lines;
00060 
00061 void eLineEntry::Delete()
00062 {
00063     int i = index;
00064     *this = se_lines(se_lines.Len()-1);
00065     index = i;
00066 
00067     if (se_lines.Len() > 0)
00068         se_lines.SetLen(se_lines.Len()-1);
00069 }
00070 
00071 eLineEntry& eLineEntry::Create()
00072 {
00073     eLineEntry& ret = se_lines[se_lines.Len()];
00074     ret.index = se_lines.Len()-1;
00075     ret.timeout = se_timeout;
00076     ret.r       = se_r;
00077     ret.g       = se_g;
00078     ret.b       = se_b;
00079     return ret;
00080 }
00081 
00082 
00083 void eDebugLine::Update(REAL ts)
00084 {
00085     for (int i = se_lines.Len()-1; i>=0; i--)
00086     {
00087         eLineEntry& entry = se_lines(i);
00088         entry.timeout -= ts;
00089         if (entry.timeout < 0)
00090             entry.Delete();
00091     }
00092 }
00093 
00094 
00095 void eDebugLine::Render()
00096 {
00097 #ifndef DEDICATED
00098 #ifdef DEBUGLINE
00099     glDisable(GL_TEXTURE_2D);
00100     glDisable(GL_LIGHTING);
00101     BeginLines();
00102     for (int i = se_lines.Len()-1; i>=0; i--)
00103     {
00104         eLineEntry& entry = se_lines(i);
00105         Color(entry.r, entry.g, entry.b);
00106         Vertex(entry.start.x, entry.start.y, entry.startH);
00107         Vertex(entry.stop.x,  entry.stop.y,  entry.stopH);
00108     }
00109     RenderEnd();
00110 #endif
00111 #endif
00112 }
00113 
00114 void eDebugLine::SetColor(REAL r, REAL g, REAL b)
00115 {
00116     se_r = r;
00117     se_g = g;
00118     se_b = b;
00119 }
00120 
00121 void eDebugLine::SetTimeout(REAL time)
00122 {
00123     se_timeout = time;
00124 }
00125 
00126 void eDebugLine::ResetOptions()
00127 {
00128     se_r = 1;
00129     se_g = 1;
00130     se_b = 1;
00131     se_timeout = .1f;
00132 }
00133 
00134 void eDebugLine::Draw(const eCoord& start, REAL startH,
00135                       const eCoord& stop , REAL stopH)
00136 {
00137 #ifdef DEBUGLINE
00138     eLineEntry& line = eLineEntry::Create();
00139     line.start  = start;
00140     line.startH = startH;
00141     line.stop   = stop;
00142     line.stopH  = stopH;
00143 #endif
00144 }
00145 

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