00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef NL_MOVE_CONTAINER_H
00027 #define NL_MOVE_CONTAINER_H
00028
00029 #include "nel/misc/types_nl.h"
00030 #include "nel/misc/pool_memory.h"
00031 #include "pacs/move_cell.h"
00032 #include "pacs/collision_ot.h"
00033 #include "nel/pacs/u_move_container.h"
00034 #include "pacs/collision_surface_temp.h"
00035
00036 #define NELPACS_CONTAINER_TRIGGER_DEFAULT_SIZE 100
00037
00038 namespace NLPACS
00039 {
00040
00041 class CMovePrimitive;
00042 class CMoveElement;
00043 class CGlobalRetriever;
00044 class CPrimitiveWorldImage;
00045
00056 class CMoveContainer: public UMoveContainer
00057 {
00058 friend class CMovePrimitive;
00059 friend class CPrimitiveWorldImage;
00060 public:
00062 CMoveContainer (double xmin, double ymin, double xmax, double ymax, uint widthCellCount, uint heightCellCount, double primitiveMaxSize,
00063 uint8 numWorldImage, uint maxIteration, uint otSize)
00064 {
00065 init (xmin, ymin, xmax, ymax, widthCellCount, heightCellCount, primitiveMaxSize, numWorldImage, maxIteration, otSize);
00066 }
00067
00069 CMoveContainer (CGlobalRetriever* retriever, uint widthCellCount, uint heightCellCount, double primitiveMaxSize,
00070 uint8 numWorldImage, uint maxIteration, uint otSize)
00071 {
00072 init (retriever, widthCellCount, heightCellCount, primitiveMaxSize, numWorldImage, maxIteration, otSize);
00073 }
00074
00076 ~CMoveContainer ();
00077
00079 void init (double xmin, double ymin, double xmax, double ymax, uint widthCellCount, uint heightCellCount, double primitiveMaxSize,
00080 uint8 numWorldImage, uint maxIteration, uint otSize);
00081
00083 void init (CGlobalRetriever* retriever, uint widthCellCount, uint heightCellCount, double primitiveMaxSize,
00084 uint8 numWorldImage, uint maxIteration, uint otSize);
00085
00087 UMovePrimitive* addCollisionablePrimitive (uint8 firstWorldImage, uint8 numWorldImage);
00088
00090 UMovePrimitive* addNonCollisionablePrimitive ();
00091
00093 bool loadCollisionablePrimitiveBlock (const char *filename, uint8 firstWorldImage, uint8 numWorldImage, std::vector<UMovePrimitive*> *primitives, float orientation, const NLMISC::CVector &position);
00094
00096 void setAsStatic (uint8 worldImage);
00097
00099 void duplicateWorldImage (uint8 source, uint8 dest);
00100
00102 void removePrimitive (UMovePrimitive* primitive);
00103
00105 void evalCollision (double deltaTime, uint8 worldImage);
00106
00108 bool testMove (UMovePrimitive* primitive, const NLMISC::CVectorD& speed, double deltaTime, uint8 worldImage);
00109
00111 CMoveElement *allocateMoveElement ();
00112
00114 void freeMoveElement (CMoveElement *element);
00115
00117 CGlobalRetriever *getGlobalRetriever() const
00118 {
00119 return _Retriever;
00120 }
00121
00123 uint getNumTriggerInfo() const
00124 {
00125 return _Triggers.size();
00126 }
00127
00129 const UTriggerInfo &getTriggerInfo (uint id) const
00130 {
00131
00132 nlassert (id<_Triggers.size());
00133
00134 return _Triggers[id];
00135 }
00136
00137 private:
00139 uint32 _TestTime;
00140
00142 uint32 _MaxTestIteration;
00143
00145 std::set<CMovePrimitive*> _PrimitiveSet;
00146
00148 std::vector<CMovePrimitive*> _ChangedRoot;
00149
00151 std::set<uint8> _StaticWorldImage;
00152
00154 uint _OtSize;
00155
00157 std::vector<CCollisionOT> _TimeOT;
00158
00160 CCollisionOT *_PreviousCollisionNode;
00161
00163 double _DeltaTime;
00164
00166 double _PrimitiveMaxSize;
00167
00169 double _Xmin;
00170 double _Ymin;
00171 double _Xmax;
00172 double _Ymax;
00173
00175 double _CellWidth;
00176 double _CellHeight;
00177
00179 uint _CellCountWidth;
00180 uint _CellCountHeight;
00181
00183 std::vector<std::vector<CMoveCell> > _VectorCell;
00184
00186 CGlobalRetriever *_Retriever;
00187 CCollisionSurfaceTemp _SurfaceTemp;
00188
00190 std::vector <UTriggerInfo> _Triggers;
00191 NLMISC::CPoolMemory<CCollisionOTDynamicInfo> _AllocOTDynamicInfo;
00192 NLMISC::CPoolMemory<CCollisionOTStaticInfo> _AllocOTStaticInfo;
00193
00194 private:
00195
00196
00197 void clear ();
00198
00199
00200 void updatePrimitives (double deltaTime, uint8 worldImage);
00201
00202
00203 void updateCells (CMovePrimitive *primitive, uint8 worldImage);
00204
00205
00206 void getCells (CMovePrimitive *primitive, uint8 worldImage, uint8 primitiveWorldImage, CMoveElement **elementArray);
00207
00208
00209
00210 void clearOT ();
00211
00212
00213 void checkOT ();
00214
00215
00216 bool evalOneCollision (double beginTime, CMovePrimitive *primitive, uint8 worldImage,
00217 uint8 primitiveWorldImage, bool testMove, bool secondIsStatic,
00218 bool &testMoveValid);
00219
00220
00221 bool evalFinalCollision (double beginTime, CMovePrimitive *primitive, CMovePrimitive *otherPrimitive,
00222 CPrimitiveWorldImage *wI, CPrimitiveWorldImage *otherWI, bool testMove,
00223 uint8 firstWorldImage, uint8 secondWorldImage, bool secondIsStatic);
00224
00225
00226 void evalAllCollisions (double beginTime, uint8 worldImage);
00227
00228
00229 void newCollision (CMovePrimitive* first, CMovePrimitive* second, const CCollisionDesc& desc,
00230 bool collision, bool enter, bool exit, uint firstWorldImage, uint secondWorldImage,
00231 bool secondIsStatic);
00232
00233
00234 void newCollision (CMovePrimitive* first, const CCollisionSurfaceDesc& desc, uint8 worldImage, double beginTime);
00235
00236
00237 void newTrigger (CMovePrimitive* first, CMovePrimitive* second, const CCollisionDesc& desc);
00238
00239
00240 void clearModifiedList (uint8 worldImage);
00241
00242
00243 void removeModifiedFromOT (uint8 worldImage);
00244
00245
00246 void checkSortedList ();
00247
00248
00249 CCollisionOTDynamicInfo *allocateOTDynamicInfo ();
00250
00251
00252 CCollisionOTStaticInfo *allocateOTStaticInfo ();
00253
00254
00255 void freeAllOTInfo ();
00256
00257
00258 CMovePrimitive *allocatePrimitive (uint8 firstWorldImage, uint8 numWorldImage);
00259
00260
00261 void freePrimitive (CMovePrimitive *primitive);
00262
00263
00264 CPrimitiveWorldImage **allocateWorldImagesPtrs (uint numPtrs);
00265
00266
00267 void freeWorldImagesPtrs (CPrimitiveWorldImage **ptrs);
00268
00269
00270 CPrimitiveWorldImage *allocateWorldImage ();
00271
00272
00273 void freeWorldImage (CPrimitiveWorldImage *worldImage);
00274
00275
00276 void changed (CMovePrimitive* primitive, uint8 worldImage);
00277
00278
00279 void removeFromModifiedList (CMovePrimitive* primitive, uint8 worldImage);
00280
00281
00282 void removeNCFromModifiedList (CMovePrimitive* primitive, uint8 worldImage);
00283
00284
00285 void unlinkMoveElement (CMoveElement *element, uint8 worldImage);
00286
00287
00288 void reaction (const CCollisionOTInfo& first);
00289 };
00290
00291
00292 }
00293
00294
00295 #endif // NL_MOVE_CONTAINER_H
00296
00297