NvBlastExtPxManagerImpl.h
Go to the documentation of this file.
1 // This code contains NVIDIA Confidential Information and is disclosed to you
2 // under a form of NVIDIA software license agreement provided separately to you.
3 //
4 // Notice
5 // NVIDIA Corporation and its licensors retain all intellectual property and
6 // proprietary rights in and to this software and related documentation and
7 // any modifications thereto. Any use, reproduction, disclosure, or
8 // distribution of this software and related documentation without an express
9 // license agreement from NVIDIA Corporation is strictly prohibited.
10 //
11 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
12 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
13 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
14 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
15 //
16 // Information and code furnished is believed to be accurate and reliable.
17 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
18 // information or for any infringement of patents or other rights of third parties that may
19 // result from its use. No license is granted by implication or otherwise under any patent
20 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
21 // This code supersedes and replaces all information previously supplied.
22 // NVIDIA Corporation products are not authorized for use as critical
23 // components in life support devices or systems without express written approval of
24 // NVIDIA Corporation.
25 //
26 // Copyright (c) 2016-2020 NVIDIA Corporation. All rights reserved.
27 
28 
29 #ifndef NVBLASTEXTPXMANAGERIMPL_H
30 #define NVBLASTEXTPXMANAGERIMPL_H
31 
32 #include "NvBlastExtPxManager.h"
33 #include "NvBlastArray.h"
34 #include "NvBlastHashMap.h"
35 #include "NvBlastExtPxListener.h"
36 #include "NvBlastExtPxFamily.h"
37 
38 #include "PxRigidDynamic.h"
39 
40 
41 using namespace physx;
42 
43 
44 namespace Nv
45 {
46 namespace Blast
47 {
48 
49 // Forward declarations
50 class TkActor;
51 
52 class ExtPxManagerImpl final : public ExtPxManager
53 {
55 
56 public:
57  friend class ExtPxActorImpl;
58  friend class ExtPxFamilyImpl;
59 
60  ExtPxManagerImpl(PxPhysics& physics, TkFramework&framework, ExtPxCreateJointFunction createFn, bool usePxUserData)
61  : m_physics(physics), m_framework(framework), m_createJointFn(createFn), m_usePxUserData(usePxUserData), m_actorCountLimit(0)
62  {
63  }
64 
66  {
67  }
68 
69  virtual void release() override;
70 
71 
73 
74  virtual ExtPxFamily* createFamily(const ExtPxFamilyDesc& desc) override;
75 
76  virtual bool createJoint(TkJoint& joint) override;
77 
78  virtual void destroyJoint(TkJoint& joint) override;
79 
80  virtual void setCreateJointFunction(ExtPxCreateJointFunction createFn) override
81  {
82  m_createJointFn = createFn;
83  }
84 
85  virtual uint32_t getFamilyCount() const override
86  {
87  return m_tkFamiliesMap.size();
88  }
89 
90  virtual uint32_t getFamilies(ExtPxFamily** buffer, uint32_t bufferSize) const override
91  {
92  uint32_t index = 0;
93  for (auto it = const_cast<ExtPxManagerImpl*>(this)->m_tkFamiliesMap.getIterator(); !it.done() && index < bufferSize; ++it)
94  {
95  buffer[index++] = it->second;
96  }
97  return index;
98  }
99 
100  virtual ExtPxFamily* getFamilyFromTkFamily(TkFamily& family) const override
101  {
102  auto entry = m_tkFamiliesMap.find(&family);
103  return entry != nullptr ? entry->second : nullptr;
104  }
105 
106  virtual ExtPxActor* getActorFromPhysXActor(const PxRigidDynamic& pxActor) const override
107  {
108  auto it = m_physXActorsMap.find(&pxActor);
109  return it != nullptr ? it->second : nullptr;
110  }
111 
112  virtual PxPhysics& getPhysics() const override
113  {
114  return m_physics;
115  }
116 
117  virtual TkFramework& getFramework() const override
118  {
119  return m_framework;
120  }
121 
122  virtual bool isPxUserDataUsed() const override
123  {
124  return m_usePxUserData;
125  }
126 
127  virtual void subscribe(ExtPxListener& listener) override
128  {
129  m_listeners.pushBack(&listener);
130  }
131 
132  virtual void unsubscribe(ExtPxListener& listener) override
133  {
134  m_listeners.findAndReplaceWithLast(&listener);
135  }
136 
137  virtual void setActorCountLimit(uint32_t limit) override
138  {
139  m_actorCountLimit = limit;
140  }
141 
142  virtual uint32_t getActorCountLimit() override
143  {
144  return m_actorCountLimit;
145  }
146 
147  virtual uint32_t getPxActorCount() const override
148  {
149  return m_physXActorsMap.size();
150  }
151 
152 
154 
155  void registerActor(PxRigidDynamic* pxActor, ExtPxActor* actor)
156  {
157  if (m_usePxUserData)
158  {
159  pxActor->userData = actor;
160  }
161  m_physXActorsMap[pxActor] = actor;
162  }
163 
164  void unregisterActor(PxRigidDynamic* pxActor)
165  {
166  if (m_usePxUserData)
167  {
168  pxActor->userData = nullptr;
169  }
170  m_physXActorsMap.erase(pxActor);
171  }
172 
174  {
175  m_tkFamiliesMap[&family.getTkFamily()] = &family;
176  }
177 
179  {
180  m_tkFamiliesMap.erase(&family.getTkFamily());
181  }
182 
183  void updateJoint(TkJoint& joint);
184 
185 
187 
189  {
190  for (ExtPxListener* listener : m_listeners)
191  listener->onActorCreated(family, actor);
192  }
193 
195  {
196  for (ExtPxListener* listener : m_listeners)
197  listener->onActorDestroyed(family, actor);
198  }
199 
200 
201 private:
202 
204 
205  PxPhysics& m_physics;
206  TkFramework& m_framework;
207  ExtPxCreateJointFunction m_createJointFn;
208  bool m_usePxUserData;
212  HashMap<TkActor*, Array<TkJoint*>::type >::type m_incompleteJointMultiMap;
213  uint32_t m_actorCountLimit;
214 };
215 
216 } // namespace Blast
217 } // namespace Nv
218 
219 
220 #endif // ifndef NVBLASTEXTPXMANAGERIMPL_H
Definition: NvBlastExtApexSharedParts.h:34
Definition: NvBlastTkFamily.h:55
Definition: NvBlastExtPxManager.h:75
virtual uint32_t getPxActorCount() const override
Definition: NvBlastExtPxManagerImpl.h:147
physx::shdfnd::InlineArray< T, N, Allocator > type
Definition: NvBlastArray.h:60
virtual uint32_t getActorCountLimit() override
Definition: NvBlastExtPxManagerImpl.h:142
Definition: NvBlastTkJoint.h:63
Definition: NvBlastExtPxManagerImpl.h:52
Definition: NvBlastHashMap.h:46
~ExtPxManagerImpl()
Definition: NvBlastExtPxManagerImpl.h:65
void registerFamily(ExtPxFamily &family)
Definition: NvBlastExtPxManagerImpl.h:173
virtual bool isPxUserDataUsed() const override
Definition: NvBlastExtPxManagerImpl.h:122
physx::shdfnd::HashMap< Key, Value, HashFn, Allocator > type
Definition: NvBlastHashMap.h:48
virtual void setCreateJointFunction(ExtPxCreateJointFunction createFn) override
Definition: NvBlastExtPxManagerImpl.h:80
Definition: NvBlastExtPxListener.h:48
virtual TkFramework & getFramework() const override
Definition: NvBlastExtPxManagerImpl.h:117
void dispatchActorDestroyed(ExtPxFamily &family, ExtPxActor &actor)
Definition: NvBlastExtPxManagerImpl.h:194
ExtPxManagerImpl(PxPhysics &physics, TkFramework &framework, ExtPxCreateJointFunction createFn, bool usePxUserData)
Definition: NvBlastExtPxManagerImpl.h:60
virtual void setActorCountLimit(uint32_t limit) override
Definition: NvBlastExtPxManagerImpl.h:137
void unregisterFamily(ExtPxFamily &family)
Definition: NvBlastExtPxManagerImpl.h:178
Definition: NvBlastExtPxActor.h:57
virtual TkFamily & getTkFamily() const =0
Definition: NvBlastExtPxActorImpl.h:58
virtual ExtPxFamily * getFamilyFromTkFamily(TkFamily &family) const override
Definition: NvBlastExtPxManagerImpl.h:100
virtual PxPhysics & getPhysics() const override
Definition: NvBlastExtPxManagerImpl.h:112
Definition: NvBlastExtPxFamily.h:105
void unregisterActor(PxRigidDynamic *pxActor)
Definition: NvBlastExtPxManagerImpl.h:164
Definition: NvBlastTkFramework.h:160
void registerActor(PxRigidDynamic *pxActor, ExtPxActor *actor)
Definition: NvBlastExtPxManagerImpl.h:155
Definition: NvBlastExtPxManager.h:99
Definition: NvBlastExtPxFamilyImpl.h:53
#define NV_NOCOPY(Class)
Definition: NvPreprocessor.h:527
virtual uint32_t getFamilyCount() const override
Definition: NvBlastExtPxManagerImpl.h:85
Definition: NvBlastArray.h:37
virtual void subscribe(ExtPxListener &listener) override
Definition: NvBlastExtPxManagerImpl.h:127
void dispatchActorCreated(ExtPxFamily &family, ExtPxActor &actor)
Definition: NvBlastExtPxManagerImpl.h:188
virtual uint32_t getFamilies(ExtPxFamily **buffer, uint32_t bufferSize) const override
Definition: NvBlastExtPxManagerImpl.h:90
virtual ExtPxActor * getActorFromPhysXActor(const PxRigidDynamic &pxActor) const override
Definition: NvBlastExtPxManagerImpl.h:106
physx::PxJoint *(* ExtPxCreateJointFunction)(ExtPxActor *actor0, const physx::PxTransform &localFrame0, ExtPxActor *actor1, const physx::PxTransform &localFrame1, physx::PxPhysics &physics, TkJoint &joint)
Definition: NvBlastExtPxManager.h:89
virtual void unsubscribe(ExtPxListener &listener) override
Definition: NvBlastExtPxManagerImpl.h:132