src/engine/eGrid.h

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 #ifndef ArmageTron_GRID_H
00029 #define ArmageTron_GRID_H
00030 
00031 #include "defs.h"
00032 #include "eCoord.h"
00033 #include "tList.h"
00034 #include "eAxis.h"
00035 //#include "eGameObject.h"
00036 //#include "eWall.h"
00037 //#include "eCamera.h"
00038 
00039 class ePoint;
00040 class eFace;
00041 class eHalfEdge;
00042 class eWall;
00043 class eGrid;
00044 class eWallView;
00045 class eCamera;
00046 class eAxis;
00047 class eGameObject;
00048 
00049 class nNetObject;
00050 
00051 // edge class for temporary variables;  automatically creates two halfeges.
00052 class eTempEdge: public tReferencable< eTempEdge >{
00053     friend class tReferencable< eTempEdge >;
00054 public:
00055     eTempEdge(ePoint *p1,ePoint *p2,eWall *W=NULL);
00056     eTempEdge(const eCoord &c1,const eCoord &c2,eWall *W=NULL);
00057 
00058     eCoord     Vec()         const;
00059     eCoord&    Coord(int i)  const;
00060     ePoint*    Point(int i)  const;
00061     eFace*     Face(int i)   const;
00062     eHalfEdge* Edge(int i)   const;
00063     eWall*     Wall()        const;
00064 
00065     void     SetWall( eWall* W )       const;
00066 
00067     void CopyIntoGrid(eGrid *grid);
00068 protected:
00069     ~eTempEdge();
00070 private:
00071     tControlledPTR< eHalfEdge > halfEdges[2];
00072 private:
00073 };
00074 
00075 
00076 class eGrid: public tReferencable< eGrid >{
00077     friend class eCamera;
00078     friend class eFace;
00079     friend class eHalfEdge;
00080     friend class ePoint;
00081     friend class eGameObject;
00082     friend class eWall;
00083     friend class tReferencable< eGrid >;
00084 
00085 protected:
00086     ~eGrid();
00087     eAxis axis;
00088 
00089 public:
00090     eGrid();
00091 
00092     // get the number of directions a cycle can drive in on this grid
00093     int WindingNumber() const {return axis.WindingNumber();}
00094 
00095     // get the number corresponding to a particular direction
00096     int DirectionWinding(const eCoord& dir);
00097 
00098     // get the direction associated with a winding number
00099     eCoord GetDirection(int winding);
00100 
00101     void SetWinding(int number);
00102     void SetWinding(int number, eCoord directions[], bool normalise=true);
00103 
00104     // Ask the grid to turn a winding
00105     void Turn(int &currentWinding, int direction);
00106 
00107     // try to get rid of eEdge number e
00108     void SimplifyNum(int e);
00109 
00110     // try to get rid of count edges
00111     void SimplifyAll(int count=1);
00112 
00113     // consistency check
00114     void Check() const;
00115 
00116     // create a new grid with a basic topology
00117     void Create();
00118 
00119     // clear all data
00120     void Clear();
00121 
00122     // make sure the circle with given radius lies inside the grid
00123     void Range(REAL range_squared);
00124 
00125     // grows the grid one step
00126     void Grow();
00127 
00128     // displays the grid, eWalls and gameobjects
00129     void Render( eCamera* cam, int viewer, REAL& zNear );
00130 
00131     // get the currently active grid (OBSOLETE)
00132     static eGrid *CurrentGrid();
00133 
00134     /*
00135       void ResetVisibles(int viewer);  // reset the visibility information
00136     */
00137 
00138     ePoint* Insert(const eCoord& coord, eFace *guessFace=NULL); // inserts a point at the given coordinates
00139 
00140     eFace *FindSurroundingFace(const eCoord& coord, eFace *start=NULL) const;
00141 
00142     // adds a new Point end, adds an eEdge from start to end with
00143     // type wall. Modifies other faces and non-eWall-edges;
00144     // if change_grid is set to 0, no edges will be flipped.
00145     // start must already be part of the grid.
00146 
00147     ePoint *DrawLine(ePoint* start, const eCoord& end, eWall *wal=NULL,bool change_grid=1);
00148 
00149 
00150     const tList<eCamera>&     Cameras()     const{return cameras;}
00151     const tList<eGameObject>& GameObjects() const{return gameObjects;}
00152     const tList<eGameObject>& GameObjectsInteresting() const{return gameObjectsInteresting;}
00153     const tList<eGameObject>& GameObjectsInactive() const{return gameObjectsInactive;}
00154 
00155 
00156     int    NumberOfCameras();
00157     const eCoord& CameraPos(int i);
00158     eCoord CameraGlancePos(int i);
00159     const eCoord& CameraDir(int i);
00160     REAL CameraHeight(int i);
00161 
00162 
00163     //  int    NumberOfCameras(){return eCamera::Number();}
00164     //  const eCoord& CameraPos(int i){return eCamera::PosNum(i);}
00165     //  const eCoord& CameraDir(int i){return eCamera::DirNum(i);}
00166     //  REAL CameraHeight(int i){return eCamera::HeightNum(i);}
00167 
00168 
00169     void AddGameObjectInteresting    (eGameObject *o);
00170     void RemoveGameObjectInteresting (eGameObject *o);
00171     void AddGameObjectInactive       (eGameObject *o);
00172     void RemoveGameObjectInactive    (eGameObject *o);
00173 
00174     typedef void WallProcessor          ( eWall*                        w       );      // function prototype for wall query functions
00175     void ProcessWallsInRange            ( WallProcessor*        proc,
00176                                 const eCoord&           pos     ,
00177                                 REAL                            range,
00178                                 eFace*                  startFace );    // call WallProcessor for all walls closer than range to pos
00179 
00180 protected:
00181     // render helper
00182     void display_simple( int viewer,bool floor,
00183                          bool sr_upperSky,bool sr_lowerSky,
00184                          REAL flooralpha,
00185                          bool eWalls,bool gameObjects,
00186                          REAL& zNear );
00187 
00188 
00189     // normal list management
00190     void AddFace    (eFace     *f);
00191     void RemoveFace (eFace     *f);
00192     void AddEdge    (eHalfEdge *e);
00193     void RemoveEdge (eHalfEdge *e);
00194     void AddPoint   (ePoint    *p);
00195     void RemovePoint(ePoint    *p);
00196 
00197     // completely unlink:
00198     void KillFace (eFace*      f);
00199     void KillEdge (eHalfEdge*  e);
00200     void KillPoint(ePoint*     p);
00201 
00202     // unlink face, but keep it alive for recycling ( so all gameobjects that live on it won't have to find a new face )
00203     tControlledPTR< eFace > ZombifyFace (eFace*      f);
00204 
00205     // adds the face, its edges and vertives to the grid
00206     void AddFaceAll (eFace     *f);
00207 
00208     bool       requestCleanup; // triggered when the data structures have gone bonkers
00209 
00210     // for the grid growth
00211     tJUST_CONTROLLED_PTR< ePoint > A,B,C;
00212     tJUST_CONTROLLED_PTR< eHalfEdge >  a,b,c;
00213     REAL       maxNormSquared;
00214     eCoord     base;
00215 
00216     // grid data
00217     tList<eHalfEdge, false, true>   edges;
00218     tList<ePoint, false, true>      points;
00219     tList<eFace, false, true>       faces;
00220 
00221     // objects
00222     tList<eGameObject> gameObjects;
00223     tList<eGameObject> gameObjectsInactive;
00224     tList<eGameObject> gameObjectsInteresting;
00225 
00226     // cameras
00227     tList<eCamera>     cameras;
00228 
00229     // walls
00230     // tHeap<eWallView>  wallsVisible[MAX_VIEWERS];
00231     tList<eWall>       wallsNotYetInserted;
00232 
00233 #ifdef DEBUG
00234 public:
00235     bool doCheck;
00236 #endif
00237 };
00238 
00239 
00240 
00241 #endif
00242 
00243 
00244 
00245 

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