Main Page Class List Class Members

- Main Page
- User's Guide
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

# sdk/extensions/physx/source/physics/NvBlastExtPxManagerImpl.h

Go to the documentation of this file.

    00001 // This code contains NVIDIA Confidential Information and is disclosed to you
    00002 // under a form of NVIDIA software license agreement provided separately to you.
    00003 //
    00004 // Notice
    00005 // NVIDIA Corporation and its licensors retain all intellectual property and
    00006 // proprietary rights in and to this software and related documentation and
    00007 // any modifications thereto. Any use, reproduction, disclosure, or
    00008 // distribution of this software and related documentation without an express
    00009 // license agreement from NVIDIA Corporation is strictly prohibited.
    00010 //
    00011 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
    00012 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
    00013 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
    00014 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
    00015 //
    00016 // Information and code furnished is believed to be accurate and reliable.
    00017 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
    00018 // information or for any infringement of patents or other rights of third parties that may
    00019 // result from its use. No license is granted by implication or otherwise under any patent
    00020 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
    00021 // This code supersedes and replaces all information previously supplied.
    00022 // NVIDIA Corporation products are not authorized for use as critical
    00023 // components in life support devices or systems without express written approval of
    00024 // NVIDIA Corporation.
    00025 //
    00026 // Copyright (c) 2016-2020 NVIDIA Corporation. All rights reserved.
    00027
    00028
    00029 #ifndef NVBLASTEXTPXMANAGERIMPL_H
    00030 #define NVBLASTEXTPXMANAGERIMPL_H
    00031
    00032 #include "NvBlastExtPxManager.h"
    00033 #include "NvBlastArray.h"
    00034 #include "NvBlastHashMap.h"
    00035 #include "NvBlastExtPxListener.h"
    00036 #include "NvBlastExtPxFamily.h"
    00037
    00038 #include "PxRigidDynamic.h"
    00039
    00040
    00041 using namespace physx;
    00042
    00043
    00044 namespace Nv
    00045 {
    00046 namespace Blast
    00047 {
    00048
    00049 // Forward declarations
    00050 class TkActor;
    00051
    00052 class ExtPxManagerImpl final : public ExtPxManager
    00053 {
    00054     NV_NOCOPY(ExtPxManagerImpl)
    00055
    00056 public:
    00057     friend class ExtPxActorImpl;
    00058     friend class ExtPxFamilyImpl;
    00059
    00060     ExtPxManagerImpl(PxPhysics& physics, TkFramework&framework, ExtPxCreateJointFunction createFn, bool usePxUserData)
    00061         : m_physics(physics), m_framework(framework), m_createJointFn(createFn), m_usePxUserData(usePxUserData), m_actorCountLimit(0)
    00062     {
    00063     }
    00064
    00065     ~ExtPxManagerImpl()
    00066     {
    00067     }
    00068
    00069     virtual void release() override;
    00070
    00071
    00073
    00074     virtual ExtPxFamily*    createFamily(const ExtPxFamilyDesc& desc) override;
    00075
    00076     virtual bool            createJoint(TkJoint& joint) override;
    00077
    00078     virtual void            destroyJoint(TkJoint& joint) override;
    00079
    00080     virtual void            setCreateJointFunction(ExtPxCreateJointFunction createFn) override
    00081     {
    00082         m_createJointFn = createFn;
    00083     }
    00084
    00085     virtual uint32_t        getFamilyCount() const override
    00086     {
    00087         return m_tkFamiliesMap.size();
    00088     }
    00089
    00090     virtual uint32_t        getFamilies(ExtPxFamily** buffer, uint32_t bufferSize) const override
    00091     {
    00092         uint32_t index = 0;
    00093         for (auto it = const_cast<ExtPxManagerImpl*>(this)->m_tkFamiliesMap.getIterator(); !it.done() && index < bufferSize; ++it)
    00094         {
    00095             buffer[index++] = it->second;
    00096         }
    00097         return index;
    00098     }
    00099
    00100     virtual ExtPxFamily*    getFamilyFromTkFamily(TkFamily& family) const override
    00101     {
    00102         auto entry = m_tkFamiliesMap.find(&family);
    00103         return entry != nullptr ? entry->second : nullptr;
    00104     }
    00105
    00106     virtual ExtPxActor*     getActorFromPhysXActor(const PxRigidDynamic& pxActor) const override
    00107     {
    00108         auto it = m_physXActorsMap.find(&pxActor);
    00109         return it != nullptr ? it->second : nullptr;
    00110     }
    00111
    00112     virtual PxPhysics&      getPhysics() const override
    00113     {
    00114         return m_physics;
    00115     }
    00116
    00117     virtual TkFramework&    getFramework() const override
    00118     {
    00119         return m_framework;
    00120     }
    00121
    00122     virtual bool            isPxUserDataUsed() const override
    00123     {
    00124         return m_usePxUserData;
    00125     }
    00126
    00127     virtual void            subscribe(ExtPxListener& listener) override
    00128     {
    00129         m_listeners.pushBack(&listener);
    00130     }
    00131
    00132     virtual void            unsubscribe(ExtPxListener& listener) override
    00133     {
    00134         m_listeners.findAndReplaceWithLast(&listener);
    00135     }
    00136
    00137     virtual void            setActorCountLimit(uint32_t limit) override
    00138     {
    00139         m_actorCountLimit = limit;
    00140     }
    00141
    00142     virtual uint32_t        getActorCountLimit() override
    00143     {
    00144         return m_actorCountLimit;
    00145     }
    00146
    00147     virtual uint32_t        getPxActorCount() const override
    00148     {
    00149         return m_physXActorsMap.size();
    00150     }
    00151
    00152
    00154
    00155     void                    registerActor(PxRigidDynamic* pxActor, ExtPxActor* actor)
    00156     {
    00157         if (m_usePxUserData)
    00158         {
    00159             pxActor->userData = actor;
    00160         }
    00161         m_physXActorsMap[pxActor] = actor;
    00162     }
    00163
    00164     void                    unregisterActor(PxRigidDynamic* pxActor)
    00165     {
    00166         if (m_usePxUserData)
    00167         {
    00168             pxActor->userData = nullptr;
    00169         }
    00170         m_physXActorsMap.erase(pxActor);
    00171     }
    00172
    00173     void                    registerFamily(ExtPxFamily& family)
    00174     {
    00175         m_tkFamiliesMap[&family.getTkFamily()] = &family;
    00176     }
    00177
    00178     void                    unregisterFamily(ExtPxFamily& family)
    00179     {
    00180         m_tkFamiliesMap.erase(&family.getTkFamily());
    00181     }
    00182
    00183     void                    updateJoint(TkJoint& joint);
    00184
    00185
    00187
    00188     void                    dispatchActorCreated(ExtPxFamily& family, ExtPxActor& actor)
    00189     {
    00190         for (ExtPxListener* listener : m_listeners)
    00191             listener->onActorCreated(family, actor);
    00192     }
    00193
    00194     void                    dispatchActorDestroyed(ExtPxFamily& family, ExtPxActor&actor)
    00195     {
    00196         for (ExtPxListener* listener : m_listeners)
    00197             listener->onActorDestroyed(family, actor);
    00198     }
    00199
    00200
    00201 private:
    00202
    00204
    00205     PxPhysics&                                              m_physics;
    00206     TkFramework&                                            m_framework;
    00207     ExtPxCreateJointFunction                                m_createJointFn;
    00208     bool                                                    m_usePxUserData;
    00209     InlineArray<ExtPxListener*, 8>::type                    m_listeners;
    00210     HashMap<const PxRigidDynamic*, ExtPxActor*>::type       m_physXActorsMap;
    00211     HashMap<TkFamily*, ExtPxFamily*>::type                  m_tkFamiliesMap;
    00212     HashMap<TkActor*, Array<TkJoint*>::type >::type         m_incompleteJointMultiMap;
    00213     uint32_t                                                m_actorCountLimit;
    00214 };
    00215
    00216 } // namespace Blast
    00217 } // namespace Nv
    00218
    00219
    00220 #endif // ifndef NVBLASTEXTPXMANAGERIMPL_H

Copyright © 2015-2017 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com