| 1 | // |
| 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions |
| 4 | // are met: |
| 5 | // * Redistributions of source code must retain the above copyright |
| 6 | // notice, this list of conditions and the following disclaimer. |
| 7 | // * Redistributions in binary form must reproduce the above copyright |
| 8 | // notice, this list of conditions and the following disclaimer in the |
| 9 | // documentation and/or other materials provided with the distribution. |
| 10 | // * Neither the name of NVIDIA CORPORATION nor the names of its |
| 11 | // contributors may be used to endorse or promote products derived |
| 12 | // from this software without specific prior written permission. |
| 13 | // |
| 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY |
| 15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 17 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 18 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 19 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 20 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 21 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 22 | // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | // |
| 26 | // Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved. |
| 27 | // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. |
| 28 | // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. |
| 29 | |
| 30 | |
| 31 | #ifndef PX_PHYSICS_SC_PHYSICS |
| 32 | #define PX_PHYSICS_SC_PHYSICS |
| 33 | |
| 34 | #include "PxPhysics.h" |
| 35 | #include "PxScene.h" |
| 36 | #include "PsUserAllocated.h" |
| 37 | #include "CmPhysXCommon.h" |
| 38 | #include "PsBasicTemplates.h" |
| 39 | #include "PxActor.h" |
| 40 | |
| 41 | namespace physx |
| 42 | { |
| 43 | |
| 44 | class PxMaterial; |
| 45 | class PxTolerancesScale; |
| 46 | struct PxvOffsetTable; |
| 47 | |
| 48 | #if PX_SUPPORT_GPU_PHYSX |
| 49 | class PxPhysXGpu; |
| 50 | #endif |
| 51 | |
| 52 | namespace Sc |
| 53 | { |
| 54 | class Scene; |
| 55 | class StaticCore; |
| 56 | class RigidCore; |
| 57 | class BodyCore; |
| 58 | class ArticulationCore; |
| 59 | class ArticulationJointCore; |
| 60 | class ConstraintCore; |
| 61 | class ShapeCore; |
| 62 | |
| 63 | struct OffsetTable |
| 64 | { |
| 65 | PX_FORCE_INLINE OffsetTable() {} |
| 66 | |
| 67 | PX_FORCE_INLINE PxActor* convertScRigidStatic2PxActor(StaticCore* sc) const { return Ps::pointerOffset<PxActor*>(p: sc, offset: scRigidStatic2PxActor); } |
| 68 | PX_FORCE_INLINE PxActor* convertScRigidDynamic2PxActor(BodyCore* sc) const { return Ps::pointerOffset<PxActor*>(p: sc, offset: scRigidDynamic2PxActor); } |
| 69 | PX_FORCE_INLINE PxActor* convertScArticulationLink2PxActor(BodyCore* sc) const { return Ps::pointerOffset<PxActor*>(p: sc, offset: scArticulationLink2PxActor); } |
| 70 | |
| 71 | PX_FORCE_INLINE PxShape* convertScShape2Px(ShapeCore* sc) const { return Ps::pointerOffset<PxShape*>(p: sc, offset: scShape2Px); } |
| 72 | PX_FORCE_INLINE const PxShape* convertScShape2Px(const ShapeCore* sc) const { return Ps::pointerOffset<const PxShape*>(p: sc, offset: scShape2Px); } |
| 73 | |
| 74 | PX_FORCE_INLINE PxConstraint* convertScConstraint2Px(ConstraintCore* sc) const { return Ps::pointerOffset<PxConstraint*>(p: sc, offset: scConstraint2Px); } |
| 75 | PX_FORCE_INLINE const PxConstraint* convertScConstraint2Px(const ConstraintCore* sc) const { return Ps::pointerOffset<const PxConstraint*>(p: sc, offset: scConstraint2Px); } |
| 76 | |
| 77 | PX_FORCE_INLINE PxArticulationBase* convertScArticulation2Px(ArticulationCore* sc, bool isRC) const |
| 78 | { |
| 79 | ptrdiff_t sc2Px = isRC ? scArticulationRC2Px : scArticulationMC2Px; |
| 80 | return Ps::pointerOffset<PxArticulationBase*>(p: sc, offset: sc2Px); |
| 81 | } |
| 82 | PX_FORCE_INLINE const PxArticulationBase* convertScArticulation2Px(const ArticulationCore* sc, bool isRC) const |
| 83 | { |
| 84 | ptrdiff_t sc2Px = isRC ? scArticulationRC2Px : scArticulationMC2Px; |
| 85 | return Ps::pointerOffset<const PxArticulationBase*>(p: sc, offset: sc2Px); |
| 86 | } |
| 87 | |
| 88 | PX_FORCE_INLINE PxArticulationJointBase* convertScArticulationJoint2Px(ArticulationJointCore* sc, bool isRC) const |
| 89 | { |
| 90 | ptrdiff_t sc2Px = isRC ? scArticulationJointRC2Px : scArticulationJointMC2Px; |
| 91 | return Ps::pointerOffset<PxArticulationJointBase*>(p: sc, offset: sc2Px); |
| 92 | } |
| 93 | PX_FORCE_INLINE const PxArticulationJointBase* convertScArticulationJoint2Px(const ArticulationJointCore* sc, bool isRC) const |
| 94 | { |
| 95 | ptrdiff_t sc2Px = isRC ? scArticulationJointRC2Px : scArticulationJointMC2Px; |
| 96 | return Ps::pointerOffset<const PxArticulationJointBase*>(p: sc, offset: sc2Px); |
| 97 | } |
| 98 | |
| 99 | |
| 100 | ptrdiff_t scRigidStatic2PxActor; |
| 101 | ptrdiff_t scRigidDynamic2PxActor; |
| 102 | ptrdiff_t scArticulationLink2PxActor; |
| 103 | ptrdiff_t scShape2Px; |
| 104 | ptrdiff_t scArticulationMC2Px; |
| 105 | ptrdiff_t scArticulationRC2Px; |
| 106 | ptrdiff_t scArticulationJointMC2Px; |
| 107 | ptrdiff_t scArticulationJointRC2Px; |
| 108 | ptrdiff_t scSoftBody2Px; |
| 109 | ptrdiff_t scConstraint2Px; |
| 110 | |
| 111 | ptrdiff_t scCore2PxActor[PxActorType::eACTOR_COUNT]; |
| 112 | }; |
| 113 | extern OffsetTable gOffsetTable; |
| 114 | |
| 115 | class Physics : public Ps::UserAllocated |
| 116 | { |
| 117 | public: |
| 118 | PX_FORCE_INLINE static Physics& getInstance() { return *mInstance; } |
| 119 | |
| 120 | Physics(const PxTolerancesScale&, const PxvOffsetTable& pxvOffsetTable); |
| 121 | ~Physics(); // use release() instead |
| 122 | public: |
| 123 | void release(); |
| 124 | |
| 125 | PX_FORCE_INLINE const PxTolerancesScale& getTolerancesScale() const { return mScale; } |
| 126 | |
| 127 | private: |
| 128 | PxTolerancesScale mScale; |
| 129 | static Physics* mInstance; |
| 130 | |
| 131 | public: |
| 132 | static const PxReal sWakeCounterOnCreation; |
| 133 | }; |
| 134 | |
| 135 | } // namespace Sc |
| 136 | |
| 137 | } |
| 138 | |
| 139 | #endif |
| 140 | |