NvBlastExtPxFamilyImpl.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 NVBLASTEXTPXFAMILYIMPL_H
30 #define NVBLASTEXTPXFAMILYIMPL_H
31 
32 #include "NvBlastExtPxFamily.h"
33 #include "NvBlastArray.h"
34 #include "NvBlastHashSet.h"
35 #include "PxTransform.h"
36 #include "NvBlastTkEvent.h"
37 
38 
39 using namespace physx;
40 
41 
42 namespace Nv
43 {
44 namespace Blast
45 {
46 
47 // Forward declarations
48 class ExtPxManagerImpl;
49 class ExtPxActorImpl;
50 struct PxActorCreateInfo;
51 
52 
54 {
56 
57 public:
60 
62 
63  ExtPxFamilyImpl(ExtPxManagerImpl& manager, TkFamily& tkFamily, ExtPxAsset& pxAsset);
64  ~ExtPxFamilyImpl();
65 
66  virtual void release() override;
67 
68 
70 
71 // virtual bool spawn(const PxTransform& pose, const ExtPxSpawnSettings& settings) override;
72  virtual bool spawn(const physx::PxTransform& pose, const physx::PxVec3& scale, const ExtPxSpawnSettings& settings) override;
73  virtual bool despawn() override;
74 
75 
76  virtual uint32_t getActorCount() const override
77  {
78  return m_actors.size();
79  }
80 
81  virtual uint32_t getActors(ExtPxActor** buffer, uint32_t bufferSize) const override
82  {
83  uint32_t index = 0;
84  for (auto it = const_cast<ExtPxFamilyImpl*>(this)->m_actors.getIterator(); !it.done() && index < bufferSize; ++it)
85  {
86  buffer[index++] = *it;
87  }
88  return index;
89  }
90 
91  virtual TkFamily& getTkFamily() const override
92  {
93  return m_tkFamily;
94  }
95 
96  virtual const physx::PxShape* const* getSubchunkShapes() const override
97  {
98  return m_subchunkShapes.begin();
99  }
100 
101  virtual ExtPxAsset& getPxAsset() const override
102  {
103  return m_pxAsset;
104  }
105 
106  virtual void setMaterial(PxMaterial& material) override
107  {
108  m_spawnSettings.material = &material;
109  }
110 
111  virtual void setPxShapeDescTemplate(const ExtPxShapeDescTemplate* pxShapeDesc) override
112  {
113  m_pxShapeDescTemplate = pxShapeDesc;
114  }
115 
116  virtual const ExtPxShapeDescTemplate* getPxShapeDescTemplate() const override
117  {
118  return m_pxShapeDescTemplate;
119  }
120 
121  virtual void setPxActorDesc(const ExtPxActorDescTemplate* pxActorDesc) override
122  {
123  m_pxActorDescTemplate = pxActorDesc;
124  }
125 
126  virtual const ExtPxActorDescTemplate* getPxActorDesc() const override
127  {
128  return m_pxActorDescTemplate;
129  }
130 
131  virtual const NvBlastExtMaterial* getMaterial() const override
132  {
133  return m_material;
134  }
135 
136  virtual void setMaterial(const NvBlastExtMaterial* material) override
137  {
138  m_material = material;
139  }
140 
141  virtual void subscribe(ExtPxListener& listener) override
142  {
143  m_listeners.pushBack(&listener);
144  }
145 
146  virtual void unsubscribe(ExtPxListener& listener) override
147  {
148  m_listeners.findAndReplaceWithLast(&listener);
149  }
150 
151  virtual void postSplitUpdate() override;
152 
154 
155  virtual void receive(const TkEvent* events, uint32_t eventCount) override;
156 
157 
159 
160  void dispatchActorCreated(ExtPxActor& actor);
161  void dispatchActorDestroyed(ExtPxActor& actor);
162 
163 
164 private:
166 
167  void createActors(TkActor** tkActors, const PxActorCreateInfo* pxActorInfos, uint32_t count);
168  void destroyActors(ExtPxActor** actors, uint32_t count);
169 
171 
172  ExtPxManagerImpl& m_manager;
173  TkFamily& m_tkFamily;
174  ExtPxAsset& m_pxAsset;
175  ExtPxSpawnSettings m_spawnSettings;
176  const ExtPxShapeDescTemplate* m_pxShapeDescTemplate;
177  const ExtPxActorDescTemplate* m_pxActorDescTemplate;
178  const NvBlastExtMaterial* m_material;
179  bool m_isSpawned;
180  PxTransform m_initialTransform;
181  PxVec3 m_initialScale;
183  Array<TkActor*>::type m_culledActors;
185  Array<PxShape*>::type m_subchunkShapes;
186  Array<TkActor*>::type m_newActorsBuffer;
187  Array<PxActorCreateInfo>::type m_newActorCreateInfo;
188  Array<PxActor*>::type m_physXActorsBuffer;
189  Array<ExtPxActor*>::type m_actorsBuffer;
190  Array<uint32_t>::type m_indicesScratch;
191 };
192 
193 } // namespace Blast
194 } // namespace Nv
195 
196 
197 #endif // ifndef NVBLASTEXTPXFAMILYIMPL_H
Definition: NvBlastExtApexSharedParts.h:34
Definition: NvBlastTkFamily.h:55
virtual void setMaterial(const NvBlastExtMaterial *material) override
Definition: NvBlastExtPxFamilyImpl.h:136
Definition: NvBlastArray.h:46
virtual void unsubscribe(ExtPxListener &listener) override
Definition: NvBlastExtPxFamilyImpl.h:146
friend ExtPxActorImpl
Definition: NvBlastExtPxFamilyImpl.h:58
physx::shdfnd::InlineArray< T, N, Allocator > type
Definition: NvBlastArray.h:60
virtual void setPxShapeDescTemplate(const ExtPxShapeDescTemplate *pxShapeDesc) override
Definition: NvBlastExtPxFamilyImpl.h:111
virtual ExtPxAsset & getPxAsset() const override
Definition: NvBlastExtPxFamilyImpl.h:101
Definition: NvBlastTkEvent.h:65
physx::shdfnd::HashSet< Key, HashFn, Allocator > type
Definition: NvBlastHashSet.h:47
Definition: NvBlastExtPxManagerImpl.h:52
physx::shdfnd::Array< T, Allocator > type
Definition: NvBlastArray.h:48
Definition: NvBlastExtPxFamily.h:66
virtual void setMaterial(PxMaterial &material) override
Definition: NvBlastExtPxFamilyImpl.h:106
Definition: NvBlastTkActor.h:57
virtual const ExtPxActorDescTemplate * getPxActorDesc() const override
Definition: NvBlastExtPxFamilyImpl.h:126
virtual const NvBlastExtMaterial * getMaterial() const override
Definition: NvBlastExtPxFamilyImpl.h:131
Definition: NvBlastExtPxFamily.h:81
Definition: NvBlastExtPxAsset.h:123
virtual const ExtPxShapeDescTemplate * getPxShapeDescTemplate() const override
Definition: NvBlastExtPxFamilyImpl.h:116
Definition: NvBlastExtPxFamily.h:92
virtual void setPxActorDesc(const ExtPxActorDescTemplate *pxActorDesc) override
Definition: NvBlastExtPxFamilyImpl.h:121
Definition: NvBlastTkEvent.h:168
Definition: NvBlastExtPxListener.h:48
Definition: NvBlastExtPxActor.h:57
virtual void subscribe(ExtPxListener &listener) override
Definition: NvBlastExtPxFamilyImpl.h:141
Definition: NvBlastExtPxFamily.h:105
Definition: NvBlastExtPxActorImpl.h:48
friend ExtPxManagerImpl
Definition: NvBlastExtPxFamilyImpl.h:59
virtual uint32_t getActors(ExtPxActor **buffer, uint32_t bufferSize) const override
Definition: NvBlastExtPxFamilyImpl.h:81
Definition: NvBlastExtPxFamilyImpl.h:53
virtual const physx::PxShape *const * getSubchunkShapes() const override
Definition: NvBlastExtPxFamilyImpl.h:96
virtual uint32_t getActorCount() const override
Definition: NvBlastExtPxFamilyImpl.h:76
#define NV_NOCOPY(Class)
Definition: NvPreprocessor.h:527
virtual TkFamily & getTkFamily() const override
Definition: NvBlastExtPxFamilyImpl.h:91
Definition: NvBlastArray.h:37
Definition: NvBlastExtDamageShaders.h:94