NvBlastTkFamilyImpl.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 NVBLASTTKFAMILYIMPL_H
30 #define NVBLASTTKFAMILYIMPL_H
31 
32 #include "NvBlastTkCommon.h"
33 
34 #include "NvBlastTkFamily.h"
35 #include "NvBlastTkTypeImpl.h"
36 #include "NvBlastTkActorImpl.h"
37 
38 #include "NvBlastTkEventQueue.h"
39 #include "NvBlastHashSet.h"
40 #include "NvBlastHashMap.h"
41 
42 #include "NvBlast.h"
43 #include "NvBlastAssert.h"
44 #include "NvBlastDLink.h"
45 
46 
47 // Forward declarations
48 struct NvBlastFamily;
49 
50 namespace Nv
51 {
52 namespace Blast
53 {
54 
55 // Forward declarations
56 class TkGroupImpl;
57 class TkAssetImpl;
58 
59 
61 {
62 public:
63  TkFamilyImpl();
64  TkFamilyImpl(const NvBlastID& id);
65  ~TkFamilyImpl();
66 
67  NVBLASTTK_IMPL_DEFINE_IDENTIFIABLE('A', 'C', 'T', 'F');
68 
69  // Begin TkFamily
70  virtual const NvBlastFamily* getFamilyLL() const override;
71 
72  virtual uint32_t getActorCount() const override;
73 
74  virtual uint32_t getActors(TkActor** buffer, uint32_t bufferSize, uint32_t indexStart = 0) const override;
75 
76  virtual void addListener(TkEventListener& l) override { m_queue.addListener(l); }
77 
78  virtual void removeListener(TkEventListener& l) override { m_queue.removeListener(l); }
79 
80  virtual void applyFracture(const NvBlastFractureBuffers* commands) override { applyFractureInternal(commands); }
81 
82  virtual const TkAsset* getAsset() const override;
83 
84  virtual void reinitialize(const NvBlastFamily* newFamily, TkGroup* group) override;
85  // End TkFamily
86 
87  // Public methods
88  static TkFamilyImpl* create(const TkAssetImpl* asset);
89 
90  const TkAssetImpl* getAssetImpl() const;
91 
92  NvBlastFamily* getFamilyLLInternal() const;
93 
94  uint32_t getActorCountInternal() const;
95 
96  TkActorImpl* addActor(NvBlastActor* actorLL);
97 
98  void applyFractureInternal(const NvBlastFractureBuffers* commands);
99 
100  void removeActor(TkActorImpl* actorLL);
101 
102  TkEventQueue& getQueue() { return m_queue; }
103 
104  TkActorImpl* getActorByActorLL(const NvBlastActor* actorLL);
105 
106  void updateJoints(TkActorImpl* actor, TkEventQueue* alternateQueue = nullptr);
107 
108  Array<TkActorImpl>::type& getActorsInternal();
109 
110  uint32_t getInternalJointCount() const;
111 
112  TkJointImpl* getInternalJoints() const;
113 
114  TkJointImpl** createExternalJointHandle(const NvBlastID& otherFamilyID, uint32_t chunkIndex0, uint32_t chunkIndex1);
115 
116  bool deleteExternalJointHandle(TkJointImpl*& joint, const NvBlastID& otherFamilyID, uint32_t chunkIndex0, uint32_t chunkIndex1);
117 
118  void releaseJoint(TkJointImpl& joint);
119 
120  TkActorImpl* getActorByChunk(uint32_t chunkIndex);
121 
122  typedef physx::shdfnd::Pair<uint32_t, uint32_t> ExternalJointKey;
123 
124  TkJointImpl* findExternalJoint(const TkFamilyImpl* otherFamily, ExternalJointKey key) const;
125 
126 private:
127  TkActorImpl* getActorByIndex(uint32_t index);
128 
129  struct JointSet
130  {
131  NvBlastID m_familyID;
133  };
134 
135  typedef HashMap<NvBlastID, uint32_t>::type FamilyIDMap;
136 
137  NvBlastFamily* m_familyLL;
138  Array<TkActorImpl>::type m_actors;
139  uint32_t m_internalJointCount;
140  Array<uint8_t>::type m_internalJointBuffer;
141  Array<JointSet*>::type m_jointSets;
142  FamilyIDMap m_familyIDMap;
143  const TkAssetImpl* m_asset;
144 
145  TkEventQueue m_queue;
146 };
147 
148 
150 
151 NV_INLINE const TkAssetImpl* TkFamilyImpl::getAssetImpl() const
152 {
153  return m_asset;
154 }
155 
156 
157 NV_INLINE NvBlastFamily* TkFamilyImpl::getFamilyLLInternal() const
158 {
159  return m_familyLL;
160 }
161 
162 
163 NV_INLINE uint32_t TkFamilyImpl::getActorCountInternal() const
164 {
165  NVBLAST_ASSERT(m_familyLL != nullptr);
166 
167  return NvBlastFamilyGetActorCount(m_familyLL, logLL);
168 }
169 
170 
171 NV_INLINE TkActorImpl* TkFamilyImpl::getActorByIndex(uint32_t index)
172 {
173  NVBLAST_ASSERT(index < m_actors.size());
174  return &m_actors[index];
175 }
176 
177 
178 NV_INLINE TkActorImpl* TkFamilyImpl::getActorByActorLL(const NvBlastActor* actorLL)
179 {
180  uint32_t index = NvBlastActorGetIndex(actorLL, logLL);
181  return getActorByIndex(index);
182 }
183 
184 
185 NV_INLINE Array<TkActorImpl>::type& TkFamilyImpl::getActorsInternal()
186 {
187  return m_actors;
188 }
189 
190 
191 NV_INLINE uint32_t TkFamilyImpl::getInternalJointCount() const
192 {
193  return m_internalJointCount;
194 }
195 
196 
197 NV_INLINE TkJointImpl* TkFamilyImpl::getInternalJoints() const
198 {
199  return const_cast<TkJointImpl*>(reinterpret_cast<const TkJointImpl*>(m_internalJointBuffer.begin()));
200 }
201 
202 
203 NV_INLINE void TkFamilyImpl::releaseJoint(TkJointImpl& joint)
204 {
205  NVBLAST_ASSERT(joint.m_owner == this);
206  NVBLAST_ASSERT(&joint >= getInternalJoints() && &joint < getInternalJoints() + getInternalJointCount() * sizeof(TkJointImpl));
207 
208  joint.~TkJointImpl();
209  joint.m_owner = nullptr;
210 }
211 
212 
214 
216 {
217  return actor != nullptr ? static_cast<const TkActorImpl*>(actor)->getFamilyImpl().getIDInternal() : *reinterpret_cast<const NvBlastID*>("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
218 }
219 
220 NV_INLINE const NvBlastID& getFamilyID(const TkFamilyImpl* family)
221 {
222  return family != nullptr ? family->getIDInternal() : *reinterpret_cast<const NvBlastID*>("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
223 }
224 
225 } // namespace Blast
226 } // namespace Nv
227 
228 
229 #endif // ifndef NVBLASTTKFAMILYIMPL_H
Definition: NvBlastTkActorImpl.h:75
NV_INLINE const NvBlastID & getFamilyID(const TkActor *actor)
Definition: NvBlastTkFamilyImpl.h:215
physx::shdfnd::Array< T, Allocator > type
Definition: NvBlastArray.h:48
Definition: NvBlastTkActor.h:57
Definition: NvBlastTkAsset.h:59
NV_INLINE void logLL(int type, const char *msg, const char *file, int line)
Definition: NvBlastGlobals.h:195
NVBLAST_API uint32_t NvBlastActorGetIndex(const NvBlastActor *actor, NvBlastLog logFn)
physx::shdfnd::HashMap< Key, Value, HashFn, Allocator > type
Definition: NvBlastHashMap.h:48
#define NVBLAST_ASSERT(exp)
Definition: NvBlastAssert.h:37
Definition: NvBlastTkEvent.h:168
#define NVBLASTTK_IMPL_DEFINE_IDENTIFIABLE(_id0, _id1, _id2, _id3)
Definition: NvBlastTkCommon.h:91
NVBLASTTK_IMPL_DECLARE(Asset)
Definition: NvBlastTkAssetImpl.h:52
NVBLAST_API uint32_t NvBlastFamilyGetActorCount(const NvBlastFamily *family, NvBlastLog logFn)
#define NV_INLINE
Definition: NvPreprocessor.h:350
Definition: NvBlastTypes.h:69
Definition: NvBlastTkEventQueue.h:61
Definition: NvBlastTypes.h:468
Definition: NvBlastTkJointImpl.h:67
Definition: NvBlastTkGroup.h:101
Definition: NvBlastArray.h:37
Definition: NvBlastTypes.h:387
Definition: NvBlastTypes.h:376