src/engine/eAdvWall.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 "eWall.h"
00029 #include "math.h"
00030 #include "rTexture.h"
00031 #include "rDisplayList.h"
00032 #include "eTimer.h"
00033 #include "rScreen.h"
00034 #include "eAdvWall.h"
00035 #include "eCamera.h"
00036 #include "tConfiguration.h"
00037 #include "eRectangle.h"
00038 #include "rRender.h"
00039 
00040 #include <vector>
00041 
00042 /* **********************************************
00043    RimWall
00044    ********************************************** */
00045 
00046 static eRectangle se_rimWallBounds;
00047 tList<eWallRim> se_rimWalls;
00048 
00049 eWallRim::eWallRim(eGrid *grid, bool backface_cull, REAL h)
00050         :eWall(grid), rim_id(-1),bf_cull(backface_cull), height(h)
00051 {
00052     if (h>100 && !sr_highRim)
00053         height=4;
00054 
00055     //  if(bf_cull && sr_ZTrick)
00056     se_rimWalls.Add(this,rim_id);
00057     DestroyDisplayList();}
00058 
00059 
00060 eWallRim::~eWallRim()
00061 {
00062     se_rimWalls.Remove(this,rim_id);
00063     DestroyDisplayList();
00064 }
00065 
00066 //ArmageTron_eWalltype gWallRim::type(){return ArmageTron_RIM;}
00067 
00068 //void eWallRim::Flip(){}
00069 
00070 bool eWallRim::Splittable() const
00071 {
00072     return 0;
00073 }
00074 
00075 static inline eRectangle se_OffsetBounds( REAL offset )
00076 {
00077     return eRectangle( se_rimWallBounds.GetLow()  + eCoord(offset,offset),
00078                        se_rimWallBounds.GetHigh() - eCoord(offset,offset) );
00079 }
00080 
00081 // *******************************************************************************************
00082 // *
00083 // *    Bound
00084 // *
00085 // *******************************************************************************************
00092 // *******************************************************************************************
00093 
00094 REAL eWallRim::Bound(eCoord &x,REAL offset)
00095 {
00096     //return -1E+30;
00097     return se_OffsetBounds( offset ).Clamp( x );
00098 }
00099 
00100 // *******************************************************************************************
00101 // *
00102 // *    IsBound
00103 // *
00104 // *******************************************************************************************
00110 // *******************************************************************************************
00111 
00112 bool eWallRim::IsBound(const eCoord &x, REAL offset)
00113 {
00114     // return true;
00115     return se_OffsetBounds( offset ).Contains( x );
00116 }
00117 
00118 static bool se_RimWrapY=true;
00119 static tSettingItem<bool> se_RimWrapYConf
00120 ("RIM_WALL_WRAP_Y",se_RimWrapY);
00121 
00122 #ifndef DEDICATED
00123 static rDisplayList se_rimDisplayList;
00124 
00125 extern bool sg_MoviePack();
00126 
00127 static rFileTexture se_RimWallNoWrap(rTextureGroups::TEX_WALL,"textures/rim_wall.png",1,0);
00128 static rFileTexture se_RimWallWrap(rTextureGroups::TEX_WALL,"textures/rim_wall.png",1,1);
00129 
00130 #endif
00131 
00132 // *******************************************************************************************
00133 // *
00134 // *    RenderAll
00135 // *
00136 // *******************************************************************************************
00138 // *******************************************************************************************
00139 void eWallRim::RenderAll( eCamera * camera )
00140 {
00141 #ifndef DEDICATED
00142     // call or fill display list
00143     if ( se_rimDisplayList.Call() )
00144     {
00145         return;
00146     }
00147     rDisplayListFiller filler( se_rimDisplayList );
00148 
00149     glEnable(GL_DEPTH_TEST);
00150     glDisable(GL_CULL_FACE);
00151     
00152     if ( !sg_MoviePack() )
00153     {
00154         ( se_RimWrapY ? se_RimWallWrap : se_RimWallNoWrap).Select();
00155     }
00156 
00157     for(int i=se_rimWalls.Len()-1;i>=0;i--){
00158         se_rimWalls(i)->RenderReal( rDisplayList::IsRecording() ? 0 : camera );
00159     }
00160     RenderEnd();
00161     
00162     glEnable(GL_CULL_FACE);
00163 #endif
00164 }
00165 
00166 // *******************************************************************************************
00167 // *
00168 // *    DestroyDisplayList
00169 // *
00170 // *******************************************************************************************
00171 void eWallRim::DestroyDisplayList()
00172 {
00173 #ifndef DEDICATED
00174     se_rimDisplayList.Clear( 3 );
00175 #endif
00176 }
00177 
00178 static rCallbackBeforeScreenModeChange unload(&eWallRim::DestroyDisplayList);
00179 
00180 // *******************************************************************************************
00181 // *
00182 // *    Clip
00183 // *
00184 // *******************************************************************************************
00191 // *******************************************************************************************
00192 
00193 REAL eWallRim::Clip( const eCoord & in, eCoord & out, REAL offset )
00194 {
00195     //return 1;
00196     return se_OffsetBounds( offset ).Clip(in, out);
00197 }
00198 
00199 // ****************************************************************************
00200 // *
00201 // *    GetBounds
00202 // *
00203 // ****************************************************************************
00207 // ****************************************************************************
00208 
00209 const eRectangle & eWallRim::GetBounds( void )
00210 {
00211     return se_rimWallBounds;
00212 }
00213 
00214 std::vector<eCoord> se_rimWallRubberBand;
00215 
00216 // ****************************************************************************
00217 // *
00218 // *    UpdateBounds
00219 // *
00220 // ****************************************************************************
00223 // ****************************************************************************
00224 
00225 void eWallRim::UpdateBounds( void )
00226 {
00227     std::vector<tCoord> allPoints;
00228 
00229     // calculate bounding box
00230     se_rimWallBounds.Clear();
00231     for(int i = se_rimWalls.Len()-1; i>=0; --i )
00232     {
00233         eWall * w = se_rimWalls(i);
00234         se_rimWallBounds.Include(w->EndPoint(0)).Include(w->EndPoint(1));
00235         allPoints.push_back(w->EndPoint(0));
00236         allPoints.push_back(w->EndPoint(1));
00237     }
00238 
00239     //calculate the bounding polygon of the map
00240     tCoord::GrahamScan(allPoints, se_rimWallRubberBand);
00241 }
00242 
00243 

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