~evan-nelson/armagetronad/armagetronad+pcm

« back to all changes in this revision

Viewing changes to src/engine/eGrid.h

Attempting to create a timeout for PLAYER_CENTER_MESSAGE.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 
3
 
*************************************************************************
4
 
 
5
 
ArmageTron -- Just another Tron Lightcycle Game in 3D.
6
 
Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
7
 
 
8
 
**************************************************************************
9
 
 
10
 
This program is free software; you can redistribute it and/or
11
 
modify it under the terms of the GNU General Public License
12
 
as published by the Free Software Foundation; either version 2
13
 
of the License, or (at your option) any later version.
14
 
 
15
 
This program is distributed in the hope that it will be useful,
16
 
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 
GNU General Public License for more details.
19
 
 
20
 
You should have received a copy of the GNU General Public License
21
 
along with this program; if not, write to the Free Software
22
 
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23
 
  
24
 
***************************************************************************
25
 
 
26
 
*/
27
 
 
28
 
#ifndef ArmageTron_GRID_H
29
 
#define ArmageTron_GRID_H
30
 
 
31
 
#include "defs.h"
32
 
#include "eCoord.h"
33
 
#include "tList.h"
34
 
#include "eAxis.h"
35
 
//#include "eGameObject.h"
36
 
//#include "eWall.h"
37
 
//#include "eCamera.h"
38
 
 
39
 
class ePoint;
40
 
class eFace;
41
 
class eHalfEdge;
42
 
class eWall;
43
 
class eGrid;
44
 
class eWallView;
45
 
class eCamera;
46
 
class eAxis;
47
 
class eGameObject;
48
 
 
49
 
class nNetObject;
50
 
 
51
 
// edge class for temporary variables;  automatically creates two halfeges.
52
 
class eTempEdge: public tReferencable< eTempEdge >{
53
 
    friend class tReferencable< eTempEdge >;
54
 
public:
55
 
    eTempEdge(ePoint *p1,ePoint *p2,eWall *W=NULL);
56
 
    eTempEdge(const eCoord &c1,const eCoord &c2,eWall *W=NULL);
57
 
 
58
 
    eCoord     Vec()         const;
59
 
    eCoord&    Coord(int i)  const;
60
 
    ePoint*    Point(int i)  const;
61
 
    eFace*     Face(int i)   const;
62
 
    eHalfEdge* Edge(int i)   const;
63
 
    eWall*     Wall()        const;
64
 
 
65
 
    void     SetWall( eWall* W )       const;
66
 
 
67
 
    void CopyIntoGrid(eGrid *grid);
68
 
protected:
69
 
    ~eTempEdge();
70
 
private:
71
 
    tControlledPTR< eHalfEdge > halfEdges[2];
72
 
private:
73
 
};
74
 
 
75
 
 
76
 
class eGrid: public tReferencable< eGrid >{
77
 
    friend class eCamera;
78
 
    friend class eFace;
79
 
    friend class eHalfEdge;
80
 
    friend class ePoint;
81
 
    friend class eGameObject;
82
 
    friend class eWall;
83
 
    friend class tReferencable< eGrid >;
84
 
 
85
 
protected:
86
 
    ~eGrid();
87
 
    eAxis axis;
88
 
 
89
 
public:
90
 
    eGrid();
91
 
 
92
 
    // get the number of directions a cycle can drive in on this grid
93
 
    int WindingNumber() const {return axis.WindingNumber();}
94
 
 
95
 
    // get the number corresponding to a particular direction
96
 
    int DirectionWinding(const eCoord& dir);
97
 
 
98
 
    // get the direction associated with a winding number
99
 
    eCoord GetDirection(int winding);
100
 
 
101
 
    void SetWinding(int number);
102
 
    void SetWinding(int number, eCoord directions[], bool normalise=true);
103
 
        float GetWindingAngle(int winding);
104
 
         
105
 
    // Ask the grid to turn a winding
106
 
    void Turn(int &currentWinding, int direction);
107
 
 
108
 
    // try to get rid of eEdge number e
109
 
    void SimplifyNum(int e);
110
 
 
111
 
    // try to get rid of count edges
112
 
    void SimplifyAll(int count=1);
113
 
 
114
 
    // consistency check
115
 
    void Check() const;
116
 
 
117
 
    // create a new grid with a basic topology
118
 
    void Create();
119
 
 
120
 
    // clear all data
121
 
    void Clear();
122
 
 
123
 
    // make sure the circle with given radius lies inside the grid
124
 
    void Range(REAL range_squared);
125
 
 
126
 
    // grows the grid one step
127
 
    void Grow();
128
 
 
129
 
    // displays the grid, eWalls and gameobjects
130
 
    void Render( eCamera* cam, int viewer, REAL& zNear );
131
 
 
132
 
    // get the currently active grid (OBSOLETE)
133
 
    static eGrid *CurrentGrid();
134
 
 
135
 
    /*
136
 
      void ResetVisibles(int viewer);  // reset the visibility information
137
 
    */
138
 
 
139
 
    ePoint* Insert(const eCoord& coord, eFace *guessFace=NULL); // inserts a point at the given coordinates
140
 
 
141
 
    eFace *FindSurroundingFace(const eCoord& coord, eFace *start=NULL) const;
142
 
 
143
 
    // adds a new Point end, adds an eEdge from start to end with
144
 
    // type wall. Modifies other faces and non-eWall-edges;
145
 
    // if change_grid is set to 0, no edges will be flipped.
146
 
    // start must already be part of the grid.
147
 
 
148
 
    ePoint *DrawLine(ePoint* start, const eCoord& end, eWall *wal=NULL,bool change_grid=1);
149
 
 
150
 
 
151
 
    const tList<eCamera>&     Cameras()     const{return cameras;}
152
 
    const tList<eGameObject>& GameObjects() const{return gameObjects;}
153
 
    const tList<eGameObject>& GameObjectsInteresting() const{return gameObjectsInteresting;}
154
 
    const tList<eGameObject>& GameObjectsInactive() const{return gameObjectsInactive;}
155
 
 
156
 
 
157
 
    int    NumberOfCameras();
158
 
    const eCoord& CameraPos(int i);
159
 
    eCoord CameraGlancePos(int i);
160
 
    const eCoord& CameraDir(int i);
161
 
    REAL CameraHeight(int i);
162
 
 
163
 
 
164
 
    //  int    NumberOfCameras(){return eCamera::Number();}
165
 
    //  const eCoord& CameraPos(int i){return eCamera::PosNum(i);}
166
 
    //  const eCoord& CameraDir(int i){return eCamera::DirNum(i);}
167
 
    //  REAL CameraHeight(int i){return eCamera::HeightNum(i);}
168
 
 
169
 
 
170
 
    void AddGameObjectInteresting    (eGameObject *o);
171
 
    void RemoveGameObjectInteresting (eGameObject *o);
172
 
    void AddGameObjectInactive       (eGameObject *o);
173
 
    void RemoveGameObjectInactive    (eGameObject *o);
174
 
 
175
 
    typedef void WallProcessor          ( eWall*                        w       );      // function prototype for wall query functions
176
 
    void ProcessWallsInRange            ( WallProcessor*        proc,
177
 
                                const eCoord&           pos     ,
178
 
                                REAL                            range,
179
 
                                eFace*                  startFace );    // call WallProcessor for all walls closer than range to pos
180
 
 
181
 
protected:
182
 
    // render helper
183
 
    void display_simple( int viewer,bool floor,
184
 
                         bool sr_upperSky,bool sr_lowerSky,
185
 
                         REAL flooralpha,
186
 
                         bool eWalls,bool gameObjects,
187
 
                         REAL& zNear );
188
 
 
189
 
 
190
 
    // normal list management
191
 
    void AddFace    (eFace     *f);
192
 
    void RemoveFace (eFace     *f);
193
 
    void AddEdge    (eHalfEdge *e);
194
 
    void RemoveEdge (eHalfEdge *e);
195
 
    void AddPoint   (ePoint    *p);
196
 
    void RemovePoint(ePoint    *p);
197
 
 
198
 
    // completely unlink:
199
 
    void KillFace (eFace*      f);
200
 
    void KillEdge (eHalfEdge*  e);
201
 
    void KillPoint(ePoint*     p);
202
 
 
203
 
    // unlink face, but keep it alive for recycling ( so all gameobjects that live on it won't have to find a new face )
204
 
    tControlledPTR< eFace > ZombifyFace (eFace*      f);
205
 
 
206
 
    // adds the face, its edges and vertives to the grid
207
 
    void AddFaceAll (eFace     *f);
208
 
 
209
 
    bool       requestCleanup; // triggered when the data structures have gone bonkers
210
 
 
211
 
    // for the grid growth
212
 
    tJUST_CONTROLLED_PTR< ePoint > A,B,C;
213
 
    tJUST_CONTROLLED_PTR< eHalfEdge >  a,b,c;
214
 
    REAL       maxNormSquared;
215
 
    eCoord     base;
216
 
 
217
 
    // grid data
218
 
    tList<eHalfEdge, false, true>   edges;
219
 
    tList<ePoint, false, true>      points;
220
 
    tList<eFace, false, true>       faces;
221
 
 
222
 
    // objects
223
 
    tList<eGameObject> gameObjects;
224
 
    tList<eGameObject> gameObjectsInactive;
225
 
    tList<eGameObject> gameObjectsInteresting;
226
 
 
227
 
    // cameras
228
 
    tList<eCamera>     cameras;
229
 
 
230
 
    // walls
231
 
    // tHeap<eWallView>  wallsVisible[MAX_VIEWERS];
232
 
    tList<eWall>       wallsNotYetInserted;
233
 
 
234
 
#ifdef DEBUG
235
 
public:
236
 
    bool doCheck;
237
 
#endif
238
 
};
239
 
 
240
 
 
241
 
 
242
 
#endif
243
 
 
244
 
 
245
 
 
246