00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef ArmageTron_TESS_H
00029 #define ArmageTron_TESS_H
00030
00031 #include "tMemManager.h"
00032 #include "tList.h"
00033 #include "eCoord.h"
00034 #include "tHeap.h"
00035 #include <iostream>
00036 #include "eWall.h"
00037
00038 extern int se_debugExt;
00039
00040 class ePoint;
00041
00042 class eFace;
00043 class eWall;
00044 class eGameObject;
00045 class ePath;
00046 class eHalfEdge;
00047 class eGrid;
00048
00049
00050
00051
00052
00053
00054 class eDual{
00055 friend class eHalfEdge;
00056 friend class eGrid;
00057 friend class eFace;
00058 friend class ePoint;
00059
00060
00061 public:
00062 eDual();
00063
00064 eHalfEdge *Edge()const {return edge;}
00065
00066 bool IsInGrid() const {return ID >= 0;}
00067 protected:
00068 ~eDual();
00069
00070 bool Check(int type);
00071 void Unlink(int type);
00072
00073 int ID;
00074 tJUST_CONTROLLED_PTR<eHalfEdge> edge;
00075 };
00076
00077
00078 typedef enum { PATH_NEXT=0, PATH_PREV=1, PATH_OTHER_NEXT=2, PATH_PREV_OTHER=3,
00079 PATH_START=4, PATH_CLOSED=8, PATH_CLOSED_START=12, PATH_NONE=16}
00080 ePATH_ORIGIN;
00081
00082 class eHalfEdge: public tHeapElement, public eWallHolder, public tReferencable< eHalfEdge > {
00083 friend class eDual;
00084 friend class ePoint;
00085 friend class eFace;
00086 friend class eGrid;
00087 friend class eTempEdge;
00088 friend class eWall;
00089 friend class tReferencable< eHalfEdge >;
00090
00091 ~eHalfEdge();
00092 eHalfEdge(ePoint *p = NULL);
00093 public:
00094 eHalfEdge(ePoint *a, ePoint *b,eWall *w=NULL);
00095
00096
00097
00098 void SetWall(eWall *w);
00099 void ClearWall( void );
00100
00101 void SetOther(eHalfEdge *e)
00102 {
00103 tASSERT(e != this);
00104
00105 if (e == other)
00106 return;
00107
00108 if (other)
00109 other->other = NULL;
00110
00111 if (e->other)
00112 e->other->other = NULL;
00113
00114 e->other = this;
00115 other = e;
00116 }
00117
00118
00119 void Destroy()
00120 {
00121 tJUST_CONTROLLED_PTR< eHalfEdge > holder( this );
00122 Unlink();
00123 }
00124
00125
00126 REAL Ratio(const eCoord &c) const;
00127
00128
00129 eCoord Vec() const;
00130
00131
00132 bool Movable() const{return !GetWall() && (!other || !other->GetWall());}
00133
00134
00135 bool Splittable() const;
00136
00137
00138 void Split(eHalfEdge *& e1,eHalfEdge *& e2,ePoint *s);
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156 eCoord IntersectWithCareless(const eHalfEdge *e2) const;
00157
00158
00159
00160 ePoint * IntersectWith(const eHalfEdge *e2) const;
00161
00162
00163 void CopyIntoGrid(eGrid *grid, bool change_grid=1);
00164
00165 bool Simplify(eGrid *grid);
00166
00167
00168
00169 void Print(std::ostream &s) const;
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195 ePoint* Point() const;
00196 eFace* Face () const;
00197 eHalfEdge* Other() const {return other;}
00198 eHalfEdge* Next() const {return next;}
00199
00200
00201
00202 static void FindPath(const eCoord& originPoint, const eFace* originFace,
00203 const eCoord& targetPoint, const eFace* targetFace,
00204 const eGameObject* gameObject,
00205 ePath& path);
00206
00207 static void ClearPathData();
00208
00209 eWall* CrossesNewWall(const eGrid *grid) const;
00210
00211 protected:
00212
00213
00214 ePATH_ORIGIN origin_;
00215
00216 REAL MinPathLength(){ return Val(); }
00217 void SetMinPathLength( REAL length, tHeapBase& heap, ePATH_ORIGIN origin );
00218
00219 void PossiblePath( ePATH_ORIGIN origin, REAL minLength );
00220
00221 virtual tHeapBase *Heap() const;
00222
00223 void Unlink();
00224 bool Check() const;
00225
00226
00227 void SetPoint(ePoint *p);
00228
00229 void SetFace(eFace *p);
00230
00231
00232
00233 int ID;
00234 tJUST_CONTROLLED_PTR<ePoint> point;
00235 tJUST_CONTROLLED_PTR<eFace> face;
00236 tJUST_CONTROLLED_PTR<eHalfEdge> next;
00237 tJUST_CONTROLLED_PTR<eHalfEdge> prev;
00238 tJUST_CONTROLLED_PTR<eHalfEdge> other;
00239
00240
00241 };
00242
00243
00244
00245 class ePoint:public eDual, public eCoord, public tReferencable< ePoint >{
00246 friend class tReferencable< ePoint >;
00247
00248 public:
00249 ePoint() {}
00250 ePoint(const eCoord &c):eCoord(c){}
00251
00252
00253 bool Check() {return eDual::Check(0);}
00254
00255
00256 bool operator==(const ePoint &a) const{return eCoord::operator==(a);}
00257 bool operator!=(const ePoint &a) const{return !eCoord::operator==(a);}
00258 eCoord operator-(const ePoint &a) const{return eCoord(x-a.x,y-a.y);}
00259 eCoord operator+(const ePoint &a) const{return eCoord(x+a.x,y+a.y);}
00260 REAL operator*(const ePoint &a) const{return -x*a.y+y*a.x;}
00261 const eCoord &operator=(const eCoord &a){x=a.x;y=a.y;return *this;}
00262
00263 bool operator==(const eCoord &a) const{return eCoord::operator==(a);}
00264 bool operator!=(const eCoord &a) const{return !eCoord::operator==(a);}
00265 eCoord operator-(const eCoord &a) const{return eCoord(x-a.x,y-a.y);}
00266 eCoord operator-() const{return eCoord(-x,-y);}
00267 eCoord operator+(const eCoord &a) const{return eCoord(x+a.x,y+a.y);}
00268 REAL operator*(const eCoord &a) const{return -x*a.y+y*a.x;}
00269 const eCoord &operator=(const ePoint &a){x=a.x;y=a.y;return *this;}
00270
00271
00272
00273 void Replace(ePoint *P);
00274
00275 void Unlink();
00276
00277 void Print(std::ostream &s) const;
00278 protected:
00279 ~ePoint() {Unlink();}
00280 };
00281
00282 class eReplacementStorage;
00283
00284 class eFace:public eDual, public tReferencable< eFace >{
00285 friend class tReferencable< eFace >;
00286
00287 ~eFace();
00288 public:
00289
00290 eFace(eHalfEdge *a, eHalfEdge *b, eHalfEdge *c );
00291 eFace(eHalfEdge *a, eHalfEdge *b, eHalfEdge *c, tControlledPTR< eFace >& old );
00292 eFace(eHalfEdge *a, eHalfEdge *b, eHalfEdge *c, tControlledPTR< eFace >& old1, tControlledPTR< eFace >& old2 );
00293
00294
00295 void Create(eHalfEdge *a, eHalfEdge *b, eHalfEdge *c);
00296
00297
00298
00299
00300
00301
00302
00303
00304 bool Check() {return eDual::Check(1);}
00305
00306
00307
00308
00309
00310 void Print(std::ostream &s) const;
00311
00312 void Unlink();
00313
00314
00315 bool IsInside( const eCoord& coord ) const;
00316
00317
00318 REAL Insideness( const eCoord& coord, const eCoord& direction, const eCoord& lastDirection ) const;
00319 REAL Insideness( const eCoord& coord, const eCoord& direction ) const;
00320 REAL Insideness( const eCoord& coord ) const;
00321
00322
00323 eFace* FindReplacement( const eCoord& coord, const eCoord& direction, const eCoord& lastDirection ) const;
00324 eFace* FindReplacement( const eCoord& coord, const eCoord& direction ) const;
00325 eFace* FindReplacement( const eCoord& coord ) const;
00326
00327
00328 bool CorrectArea();
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339 eFace* nextProcessed;
00340
00341
00342 eReplacementStorage& GetReplacementStorage() const;
00343 protected:
00344
00345
00346
00347
00348
00349
00350
00351 private:
00352 mutable eReplacementStorage* replacementStorage;
00353 };
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406 inline eDual::eDual():ID(-1),edge(NULL){}
00407
00408
00409 inline eCoord eHalfEdge::Vec() const{
00410 tASSERT(other);
00411 return *(other->Point()) - *Point();
00412 }
00413
00414
00415 inline ePoint *eHalfEdge::Point() const { return point;}
00416 inline void eHalfEdge::SetPoint(ePoint *p) {point = p;}
00417
00418 inline eFace *eHalfEdge::Face() const {return face;}
00419 inline void eHalfEdge::SetFace(eFace *f) {face = f;}
00420
00421
00422 inline REAL eHalfEdge::Ratio(const eCoord &c)const
00423 {
00424 return eCoord::V(*Point(),c,*other->Point());
00425 }
00426
00427
00428
00429
00430 inline std::ostream & operator<<(std::ostream &s,const ePoint &x){x.Print(s);return s;}
00431 inline std::ostream & operator<<(std::ostream &s,const eHalfEdge &x){x.Print(s);return s;}
00432 inline std::ostream & operator<<(std::ostream &s,const eFace &x){x.Print(s);return s;}
00433
00434
00435
00436
00437 #endif
00438
00439
00440
00441