# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

move_container.h

Go to the documentation of this file.
00001 
00007 /* Copyright, 2001 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
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                 // check
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         // Clear the container
00197         void                                            clear ();
00198 
00199         // Update modified primitives bounding box
00200         void                                            updatePrimitives (double deltaTime, uint8 worldImage);
00201 
00202         // Update cells list for this primitive
00203         void                                            updateCells (CMovePrimitive *primitive, uint8 worldImage);
00204 
00205         // Fill the elementArray descriptor.
00206         void                                            getCells (CMovePrimitive *primitive, uint8 worldImage, uint8 primitiveWorldImage, CMoveElement **elementArray);
00207 
00208 
00209         // Clear the time ordered table
00210         void                                            clearOT ();
00211 
00212         // Check the OT is cleared and linked
00213         void                                            checkOT ();
00214 
00215         // Eval one collision
00216         bool                                            evalOneCollision (double beginTime, CMovePrimitive *primitive, uint8 worldImage, 
00217                                                                                                         uint8 primitiveWorldImage, bool testMove, bool secondIsStatic, 
00218                                                                                                         bool &testMoveValid);
00219 
00220         // Eval final step
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         // Eval all collision for modified primitives
00226         void                                            evalAllCollisions (double beginTime, uint8 worldImage);
00227 
00228         // Add a collision in the time ordered table
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         // Add a collision in the time ordered table
00234         void                                            newCollision (CMovePrimitive* first, const CCollisionSurfaceDesc& desc, uint8 worldImage, double beginTime);
00235 
00236         // Add a trigger in the trigger array
00237         void                                            newTrigger (CMovePrimitive* first, CMovePrimitive* second, const CCollisionDesc& desc);
00238 
00239         // Clear modified primitive list
00240         void                                            clearModifiedList (uint8 worldImage);
00241 
00242         // Remove modified primitive from time ordered table
00243         void                                            removeModifiedFromOT (uint8 worldImage);
00244 
00245         // Check sorted list
00246         void                                            checkSortedList ();
00247 
00248         // Allocate ordered table info
00249         CCollisionOTDynamicInfo         *allocateOTDynamicInfo ();
00250 
00251         // Allocate ordered table info
00252         CCollisionOTStaticInfo          *allocateOTStaticInfo ();
00253 
00254         // Free all ordered table info
00255         void                                            freeAllOTInfo ();
00256 
00257         // Allocate a primitive
00258         CMovePrimitive                          *allocatePrimitive (uint8 firstWorldImage, uint8 numWorldImage);
00259 
00260         // Free a primitive
00261         void                                            freePrimitive (CMovePrimitive *primitive);
00262 
00263         // Allocate world image pointers
00264         CPrimitiveWorldImage            **allocateWorldImagesPtrs (uint numPtrs);
00265 
00266         // Free world image pointers
00267         void                                            freeWorldImagesPtrs (CPrimitiveWorldImage **ptrs);
00268 
00269         // Allocate a world image
00270         CPrimitiveWorldImage            *allocateWorldImage ();
00271 
00272         // Free world image pointers
00273         void                                            freeWorldImage (CPrimitiveWorldImage *worldImage);
00274 
00275         // Called by CMovePrimitive when a change occured on the primitive BB
00276         void                                            changed (CMovePrimitive* primitive, uint8 worldImage);
00277 
00278         // Remove the collisionable primitive from the modified list
00279         void                                            removeFromModifiedList (CMovePrimitive* primitive, uint8 worldImage);
00280 
00281         // Remove the non collisionable primitive from the modified lists
00282         void                                            removeNCFromModifiedList (CMovePrimitive* primitive, uint8 worldImage);
00283 
00284         // Unlink this move element
00285         void                                            unlinkMoveElement  (CMoveElement *element, uint8 worldImage);
00286 
00287         // Reaction of the collision between two primitives. Return true if one object has been modified.
00288         void                                            reaction (const CCollisionOTInfo& first);
00289 };
00290 
00291 
00292 } // NLPACS
00293 
00294 
00295 #endif // NL_MOVE_CONTAINER_H
00296 
00297 /* End of move_container.h */