00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef LILITH_OBJECT_INCLUDED
00024 #define LILITH_OBJECT_INCLUDED
00025
00026 #include <string>
00027 #include <list>
00028
00029 #include "../grinliz/glvector.h"
00030
00031 namespace lilith3d
00032 {
00033 class TerrainMesh;
00034 class Mesh;
00035 struct PathSurfaceInstance;
00036 class BuildingMesh;
00037 class WalkingMob;
00038
00039 enum
00040 {
00041 TEST_TERRAIN = 0x01,
00042 TEST_PSI = 0x02,
00043 TEST_MESH = 0x04,
00044 TEST_TREE = 0x08,
00045 TEST_ALL = TEST_TERRAIN | TEST_PSI | TEST_MESH | TEST_TREE
00046 };
00047
00053 class LilithObject
00054 {
00055 public:
00057 LilithObject();
00059 LilithObject( TerrainMesh* tmesh, const grinliz::Vector3F& intersect, float distance );
00061 LilithObject( Mesh* mesh, const grinliz::Vector3F& intersect, float distance );
00063 LilithObject( PathSurfaceInstance* psi, const grinliz::Vector3F& intersect, float distance );
00064
00066 grinliz::Vector3F Intersection() const { return intersect; }
00068 float X() const { return intersect.x; }
00070 float Y() const { return intersect.y; }
00072 float Z() const { return intersect.z; }
00073
00075 const std::string& Description() const { return desc; }
00076
00078 TerrainMesh* ToTerrain() const { return tmesh; }
00082 Mesh* ToMesh() const { return mesh; }
00085 PathSurfaceInstance* ToPSI() const { return psi; }
00086
00088 float Distance() const { return distance; }
00089
00090 friend bool operator<( const LilithObject& lhs, const LilithObject& rhs ) { return lhs.distance < rhs.distance; }
00091
00092 private:
00093 void Clear();
00094
00095 float distance;
00096 grinliz::Vector3F intersect;
00097
00098 TerrainMesh* tmesh;
00099 Mesh* mesh;
00100 PathSurfaceInstance* psi;
00101 std::string desc;
00102 };
00103
00104 class LilithObjectFar : public std::unary_function< LilithObject, bool>
00105 {
00106 public:
00107 const float d;
00108 LilithObjectFar( float _d ) : d( _d ) {}
00109 bool operator()(const LilithObject& a) const { return a.Distance() >= d; }
00110
00111 private:
00112 void operator=(const LilithObjectFar& );
00113 };
00114
00115 typedef std::list< LilithObject > LilithObjectList;
00116 typedef LilithObjectList::iterator LilithObjectListIterator;
00117
00118 struct PSIMobRing
00119 {
00120 PSIMobRing() {
00121 next = this;
00122 prev = this;
00123 psi = 0;
00124 mob = 0;
00125 }
00126 ~PSIMobRing() {
00127 Unlink();
00128 #if defined( _MSC_VER ) && defined( DEBUG )
00129 GLASSERT( _CrtCheckMemory() );
00130 #endif
00131 }
00132
00133 PathSurfaceInstance* psi;
00134 WalkingMob* mob;
00135
00136 PSIMobRing* Next() { return next; }
00137
00138 bool IsLinked() {
00139 if ( next == this ) {
00140 GLASSERT( prev == this );
00141 return false;
00142 }
00143 return true;
00144 }
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 void Unlink() {
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 next->prev = prev;
00175 prev->next = next;
00176 next = prev = this;
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188 }
00189
00190 void Link( PSIMobRing* addMe )
00191 {
00192 GLASSERT( !addMe->psi && addMe->mob );
00193 GLASSERT( this->psi && !this->mob );
00194
00195 addMe->next = next;
00196 addMe->prev = this;
00197
00198 next->prev = addMe;
00199 next = addMe;
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212 }
00213
00214 static PathSurfaceInstance* FindPSI( PSIMobRing* ring )
00215 {
00216
00217 GLASSERT( !(ring->psi && ring->mob ) );
00218 if ( ring->psi )
00219 return ring->psi;
00220
00221 for( PSIMobRing* node = ring->next; node != ring; node=node->next )
00222 {
00223 GLASSERT( !(node->psi && node->mob ) );
00224 if ( node->psi )
00225 return node->psi;
00226 }
00227 return 0;
00228 }
00229
00230 private:
00231 PSIMobRing* next;
00232 PSIMobRing* prev;
00233 };
00234
00235 };
00236 #endif