src/engine/eWall.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 "rRender.h"
00030 #include "rTexture.h"
00031 #include "eGameObject.h"
00032 #include "eTess2.h"
00033 #include "eGrid.h"
00034 
00035 /* ***************************************************
00036    eWall:
00037    *************************************************** */
00038 
00039 tHeap<eWallView> se_wallsVisible[MAX_VIEWERS];
00040 // List<eWall> se_wallsNotYetInserted;
00041 
00042 eWallView::~eWallView()
00043 {
00044     RemoveFromHeap();
00045 }
00046 
00047 tHeapBase *eWallView::Heap() const{
00048     return &(se_wallsVisible[viewer]);
00049 }
00050 
00051 
00052 void eWallView::SetValue(REAL v){
00053     tHeapElement::SetVal( v, se_wallsVisible[viewer] );
00054 }
00055 
00056 eWall::eWall(eGrid *g):holder_(NULL), grid(g), flipped(0)
00057 {
00058     id = -1;
00059     //Remove();
00060     //initialize viewers
00061     for(int i=MAX_VIEWERS-1;i>=0;i--){
00062         view[i].Set(i,this);
00063         se_wallsVisible[i].Insert(&view[i]);
00064     }
00065 }
00066 
00067 eWall::~eWall()
00068 {
00069     if (holder_ )
00070         holder_->wall_ = NULL;
00071 
00072     for(int i=MAX_VIEWERS-1;i>=0;i--)
00073         se_wallsVisible[i].Remove(&view[i]);
00074     tCHECK_DEST;
00075 
00076     Insert();
00077 }
00078 
00079 eHalfEdge* eWall::Edge() const
00080 {
00081     if ( holder_ )
00082     {
00083         return static_cast< eHalfEdge* >( holder_ );
00084     }
00085     else
00086     {
00087         return NULL;
00088     }
00089 }
00090 
00091 void eWall::CalcLen(){
00092     len = sqrt(Edge()->Vec().NormSquared());
00093 
00094     //  Insert();
00095 }
00096 
00097 
00098 
00099 
00100 #ifdef DEDICATED_XXX
00101 void eWall::Render_helper(eWall *w,REAL tBeg,REAL tEnd,REAL h,REAL hfrac,REAL bot){
00102     glDisable(GL_CULL_FACE);
00103 
00104     const eCoord *p1 = &w->EndPoint(0);
00105     const eCoord *p2 = &w->EndPoint(1);
00106 
00107     BeginQuads();
00108     TexVertex(p1->x, p1->y, bot,
00109               tBeg        , hfrac);
00110 
00111     TexVertex(p1->x, p1->y, h*hfrac,
00112               tBeg        , 0);
00113 
00114     TexVertex(p2->x, p2->y, h*hfrac,
00115               0           , 0);
00116 
00117     TexVertex(p2->x, p2->y, bot,
00118               0           , hfrac);
00119 
00120     RenderEnd();
00121 
00122     if (TextureMode[rTEX_WALL]<0){
00123         Color(1,1,1);
00124 
00125         Line(p1->x,p1->y,h*hfrac,
00126              p2->x,p2->y,h*hfrac);
00127 
00128     }
00129 }
00130 
00131 void eWall::Render(){
00132     return;
00133     /*
00134     if (edge){
00135       const eCoord *p1 = &EndPoint(0);
00136       const eCoord *p2 = &EndPoint(1);
00137       
00138       Color(0,0,1,.5);
00139       
00140       eWall::Render_helper(this,(p1->x+p1->y)/40,(p2->x+p2->y)/40,4,1);
00141     }
00142     */
00143 }
00144 #endif
00145 
00146 //ArmageTron_eWalltype eWall::type(){return ArmageTron_GENERIC_WALL;}
00147 
00148 //void eWall::Flip(){}
00149 
00150 bool eWall::Splittable() const {return 0;}
00151 bool eWall::Deletable() const {return 0;}
00152 
00153 void eWall::Split(eWall *& s1,eWall *& s2,REAL){
00154     s1=tNEW(eWall)(*this);
00155     s2=tNEW(eWall)(*this);
00156 }
00157 
00158 void eWall::SplitComplete(eWall *& s1,eWall *& s2,REAL a){
00159     /*
00160     if ( !edge )
00161         return Split( s1, s2, a );
00162 
00163     eHalfEdge* other = edge->other();
00164 
00165 
00166      situation:
00167 
00168      *--------------*
00169      |                    /     |
00170      |                  /       |
00171      |          e /             |
00172      |          /o              |
00173      |    /                     |
00174      |  /                       |
00175      |/                         |
00176      *--------------*
00177 
00178     grid->Check();
00179     */
00180 }
00181 
00182 void eWall::PassingGameObject(eGameObject *pass,REAL,REAL,int){
00183     pass->Kill();
00184 }
00185 
00186 void eWall::SplitByActive( eWall * oldWall )
00187 {
00188     if ( oldWall )
00189         oldWall->SplitByPassive( this );
00190 }
00191 
00192 void eWall::SplitByPassive( eWall * newWall )
00193 {
00194 }
00195 
00196 bool eWall::RunsParallelActive( eWall * oldWall )
00197 {
00198     if ( oldWall )
00199         return oldWall->RunsParallelPassive( this );
00200     else
00201         return true;
00202 }
00203 
00204 bool eWall::RunsParallelPassive( eWall * newWall )
00205 {
00206     return true;
00207 }
00208 
00209 void eWall::SetVisHeight(int v,REAL h){
00210     if (h>=SeeHeight()-EPS)
00211         view[v].SetValue(h);
00212     else
00213         view[v].SetValue(-1000);
00214 }
00215 
00216 
00217 void eWall::Insert(){
00218     if (grid)
00219         grid->wallsNotYetInserted.Remove(this,id);
00220 }
00221 
00222 
00223 void eWall::Remove(){
00224     if (grid)
00225         grid->wallsNotYetInserted.Add(this,id);
00226 }
00227 
00228 const eCoord& eWall::EndPoint(int i) const{
00229     eHalfEdge* edge = this->Edge();
00230 
00231     if (edge)
00232     {
00233         if (flipped != i)
00234             return *edge->Other()->Point();
00235         else
00236             return *(edge->Point());
00237     }
00238     else
00239         return se_zeroCoord;
00240 }
00241 
00242 eCoord eWall::Point(REAL a) const{
00243     eCoord beg = EndPoint(0);
00244     eCoord end = EndPoint(1);
00245 
00246     return beg + ( end - beg ) * a;
00247 }
00248 
00249 eCoord eWall::Vec() const{
00250     eHalfEdge* edge = this->Edge();
00251 
00252     if (edge)
00253         return (edge->Vec())*((1 - 2*flipped)*.5f);
00254     else
00255         return eCoord(0,0);
00256 }
00257 
00258 void eWallHolder::SetWall( eWall* wall )
00259 {
00260     if ( wall_ )
00261     {
00262         wall_->holder_ = NULL;
00263     }
00264 
00265     wall_ = wall;
00266 
00267     if ( wall )
00268     {
00269         if ( wall->holder_ )
00270         {
00271             wall->holder_->wall_ = NULL;
00272         }
00273 
00274         wall->holder_ = this;
00275     }
00276 }
00277 
00278 eWall* eWallHolder::GetWall( void ) const
00279 {
00280     return wall_;
00281 }
00282 
00283 eWallHolder::eWallHolder()
00284 {
00285 }
00286 
00287 eWallHolder::~eWallHolder()
00288 {
00289     if ( wall_ )
00290     {
00291         wall_->holder_ = NULL;
00292     }
00293 }
00294 
00295 eWall *eWallView::Belongs()
00296 {
00297 #ifdef CAUTION_WALL
00298     return wall;
00299 #else
00300     static eWall* pwall = NULL;
00301     static eWall& wall = *pwall;
00302 
00303     // Z-Man: this code is still evil, but it seems to work. The proper way would be to enable CAUTION_WALL in the header, but that wastes 16 bytes per eWall. Can't go arount wasting memory for the sake of portability, can we?
00304     return reinterpret_cast<eWall *> (reinterpret_cast<char*>(&this[-viewer]) - reinterpret_cast<char*>(&wall.view[0]) + reinterpret_cast<char*>(&wall));
00305 #endif
00306 }
00307 
00308 // *******************************************************************************************
00309 // *
00310 // *    OnBlocksCamera
00311 // *
00312 // *******************************************************************************************
00317 // *******************************************************************************************
00318 
00319 void eWall::OnBlocksCamera( eCamera * camera, REAL height ) const
00320 {
00321 }
00322 
00323 

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