pxWorld.h 5.5 KB

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