pxWorld.h
Engine/source/T3D/physics/physx/pxWorld.h
Classes:
class
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _PHYSX_WORLD_H_ 25#define _PHYSX_WORLD_H_ 26 27#ifndef _T3D_PHYSICS_PHYSICSWORLD_H_ 28#include "T3D/physics/physicsWorld.h" 29#endif 30#ifndef _MMATH_H_ 31#include "math/mMath.h" 32#endif 33#ifndef _PHYSX_H_ 34#include "T3D/physics/physX/px.h" 35#endif 36#ifndef _TVECTOR_H_ 37#include "core/util/tVector.h" 38#endif 39 40class PxContactReporter; 41class PxUserNotify; 42class NxController; 43class NxControllerDesc; 44class ShapeBase; 45class TSStatic; 46class SceneObject; 47class ProcessList; 48class GameBase; 49class CharacterControllerManager; 50class PxConsoleStream; 51 52 53class PxWorld : public PhysicsWorld 54{ 55protected: 56 57 F32 mEditorTimeScale; 58 59 Vector<NxCloth*> mReleaseClothQueue; 60 Vector<NxJoint*> mReleaseJointQueue; 61 Vector<NxActor*> mReleaseActorQueue; 62 Vector<NxMaterial*> mReleaseMaterialQueue; 63 Vector<NxHeightField*> mReleaseHeightFieldQueue; 64 Vector<NxFluid*> mReleaseFluidQueue; 65 //Vector<StrongRefPtr<PxCollision>> mReleaseColQueue; 66 67 Vector<NxActor*> mCatchupQueue; 68 69 PxContactReporter *mConactReporter; 70 71 PxUserNotify *mUserNotify; 72 73 NxScene *mScene; 74 75 CharacterControllerManager *mControllerManager; 76 77 bool mErrorReport; 78 79 bool mIsEnabled; 80 81 bool mIsSimulating; 82 83 U32 mTickCount; 84 85 ProcessList *mProcessList; 86 87 bool _init( bool isServer, ProcessList *processList ); 88 89 void _destroy(); 90 91 void _releaseQueues(); 92 93 void _updateScheduledStatics(); 94 95 /// The mesh cooking interface which is loaded on first use. 96 /// @see getCooking 97 static NxCookingInterface *smCooking; 98 99 /// The console stream for PhysX error reporting. 100 static PxConsoleStream *smConsoleStream; 101 102public: 103 104 // PhysicWorld 105 virtual bool initWorld( bool isServer, ProcessList *processList ); 106 virtual void destroyWorld(); 107 virtual bool castRay( const Point3F &startPnt, const Point3F &endPnt, RayInfo *ri, const Point3F &impulse ); 108 virtual PhysicsBody* castRay( const Point3F &start, const Point3F &end, U32 bodyTypes = BT_All ); 109 virtual void explosion( const Point3F &pos, F32 radius, F32 forceMagnitude ); 110 virtual void onDebugDraw( const SceneRenderState *state ); 111 virtual void reset() {} 112 virtual bool isEnabled() const { return mIsEnabled; } 113 114 /// @name Static Methods 115 /// @{ 116 117 static bool restartSDK( bool destroyOnly = false, PxWorld *clientWorld = NULL, PxWorld *serverWorld = NULL ); 118 119 static void releaseWriteLocks(); 120 121 /// @} 122 123 PxWorld(); 124 virtual ~PxWorld(); 125 126public: 127 128 NxScene* getScene() { return mScene; } 129 130 /// Returns the cooking interface. Will only return NULL 131 /// in the case of a missing or bad PhysX install. 132 static NxCookingInterface* getCooking(); 133 134 U32 getTick() { return mTickCount; } 135 136 void tickPhysics( U32 elapsedMs ); 137 138 void getPhysicsResults(); 139 140 //void enableCatchupMode( GameBase *obj ); 141 142 bool isWritable() const { return !mIsSimulating; /* mScene->isWritable(); */ } 143 144 void releaseWriteLock(); 145 146 void setEnabled( bool enabled ); 147 bool getEnabled() const { return mIsEnabled; } 148 149 NxMaterial* createMaterial( NxMaterialDesc &material ); 150 151 /// 152 /// @see releaseController 153 NxController* createController( NxControllerDesc &desc ); 154 155 //U16 setMaterial(NxMaterialDesc &material, U16 id); 156 157 // NOTE: This is all a mess, but its a side effect of how 158 // PhysX works. Many objects cannot be deleted without write 159 // access to the scene. Worse some objects cannot be deleted 160 // until their owner objects are deleted first. 161 // 162 // For these reasons we have these methods to register objects to be 163 // released after the Scene has been ticked. 164 // 165 // Since there is no common base to PhysX objects we're stuck with 166 // this list of release methods. 167 // 168 169 void releaseActor( NxActor &actor ); 170 171 void releaseMaterial( NxMaterial &mat ); 172 173 void releaseJoint( NxJoint &joint ); 174 175 void releaseCloth( NxCloth &cloth ); 176 177 void releaseClothMesh( NxClothMesh &clothMesh ); 178 179 void releaseController( NxController &controller ); 180 181 void releaseHeightField( NxHeightField &heightfield ); 182 183 void releaseFluid( NxFluid &fluid ); 184 185 //void releaseCol( PxCollision *col ); 186 187 /// Returns the contact reporter for this scene. 188 PxContactReporter* getContactReporter() { return mConactReporter; } 189 190 void setEditorTimeScale( F32 timeScale ) { mEditorTimeScale = timeScale; } 191 const F32 getEditorTimeScale() const { return mEditorTimeScale; } 192}; 193 194#endif // _PHYSX_WORLD_H_ 195
