Main Page   Class List   Class Members  

  • Main Page
  • User's Guide
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

sdk/toolkit/source/NvBlastTkFamilyImpl.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 NVBLASTTKFAMILYIMPL_H
00030 #define NVBLASTTKFAMILYIMPL_H
00031 
00032 #include "NvBlastTkCommon.h"
00033 
00034 #include "NvBlastTkFamily.h"
00035 #include "NvBlastTkTypeImpl.h"
00036 #include "NvBlastTkActorImpl.h"
00037 
00038 #include "NvBlastTkEventQueue.h"
00039 #include "NvBlastHashSet.h"
00040 #include "NvBlastHashMap.h"
00041 
00042 #include "NvBlast.h"
00043 #include "NvBlastAssert.h"
00044 #include "NvBlastDLink.h"
00045 
00046 
00047 // Forward declarations
00048 struct NvBlastFamily;
00049 
00050 namespace Nv
00051 {
00052 namespace Blast
00053 {
00054 
00055 // Forward declarations
00056 class TkGroupImpl;
00057 class TkAssetImpl;
00058 
00059 
00060 NVBLASTTK_IMPL_DECLARE(Family)
00061 {
00062 public:
00063     TkFamilyImpl();
00064     TkFamilyImpl(const NvBlastID& id);
00065     ~TkFamilyImpl();
00066 
00067     NVBLASTTK_IMPL_DEFINE_IDENTIFIABLE('A', 'C', 'T', 'F');
00068 
00069     // Begin TkFamily
00070     virtual const NvBlastFamily*    getFamilyLL() const override;
00071 
00072     virtual uint32_t                getActorCount() const override;
00073 
00074     virtual uint32_t                getActors(TkActor** buffer, uint32_t bufferSize, uint32_t indexStart = 0) const override;
00075 
00076     virtual void                    addListener(TkEventListener& l) override { m_queue.addListener(l); }
00077 
00078     virtual void                    removeListener(TkEventListener& l) override { m_queue.removeListener(l); }
00079 
00080     virtual void                    applyFracture(const NvBlastFractureBuffers* commands) override { applyFractureInternal(commands); }
00081 
00082     virtual const TkAsset*          getAsset() const override;
00083 
00084     virtual void                    reinitialize(const NvBlastFamily* newFamily, TkGroup* group) override;
00085     // End TkFamily
00086 
00087     // Public methods
00088     static TkFamilyImpl*            create(const TkAssetImpl* asset);
00089 
00090     const TkAssetImpl*              getAssetImpl() const;
00091 
00092     NvBlastFamily*                  getFamilyLLInternal() const;
00093 
00094     uint32_t                        getActorCountInternal() const;
00095 
00096     TkActorImpl*                    addActor(NvBlastActor* actorLL);
00097 
00098     void                            applyFractureInternal(const NvBlastFractureBuffers* commands);
00099 
00100     void                            removeActor(TkActorImpl* actorLL);
00101 
00102     TkEventQueue&                   getQueue() { return m_queue; }
00103 
00104     TkActorImpl*                    getActorByActorLL(const NvBlastActor* actorLL);
00105 
00106     void                            updateJoints(TkActorImpl* actor, TkEventQueue* alternateQueue = nullptr);
00107 
00108     Array<TkActorImpl>::type&       getActorsInternal();
00109 
00110     uint32_t                        getInternalJointCount() const;
00111 
00112     TkJointImpl*                    getInternalJoints() const;
00113 
00114     TkJointImpl**                   createExternalJointHandle(const NvBlastID& otherFamilyID, uint32_t chunkIndex0, uint32_t chunkIndex1);
00115 
00116     bool                            deleteExternalJointHandle(TkJointImpl*& joint, const NvBlastID& otherFamilyID, uint32_t chunkIndex0, uint32_t chunkIndex1);
00117 
00118     void                            releaseJoint(TkJointImpl& joint);
00119 
00120     TkActorImpl*                    getActorByChunk(uint32_t chunkIndex);
00121 
00122     typedef physx::shdfnd::Pair<uint32_t, uint32_t> ExternalJointKey;   
00123 
00124     TkJointImpl*                    findExternalJoint(const TkFamilyImpl* otherFamily, ExternalJointKey key) const;
00125 
00126 private:
00127     TkActorImpl*                    getActorByIndex(uint32_t index);
00128 
00129     struct JointSet
00130     {
00131         NvBlastID                                       m_familyID;
00132         HashMap<ExternalJointKey, TkJointImpl*>::type   m_joints;
00133     };
00134 
00135     typedef HashMap<NvBlastID, uint32_t>::type  FamilyIDMap;
00136 
00137     NvBlastFamily*              m_familyLL;
00138     Array<TkActorImpl>::type    m_actors;
00139     uint32_t                    m_internalJointCount;
00140     Array<uint8_t>::type        m_internalJointBuffer;
00141     Array<JointSet*>::type      m_jointSets;
00142     FamilyIDMap                 m_familyIDMap;
00143     const TkAssetImpl*          m_asset;
00144 
00145     TkEventQueue                m_queue;
00146 };
00147 
00148 
00150 
00151 NV_INLINE const TkAssetImpl* TkFamilyImpl::getAssetImpl() const
00152 {
00153     return m_asset;
00154 }
00155 
00156 
00157 NV_INLINE NvBlastFamily* TkFamilyImpl::getFamilyLLInternal() const
00158 { 
00159     return m_familyLL; 
00160 }
00161 
00162 
00163 NV_INLINE uint32_t TkFamilyImpl::getActorCountInternal() const
00164 {
00165     NVBLAST_ASSERT(m_familyLL != nullptr);
00166 
00167     return NvBlastFamilyGetActorCount(m_familyLL, logLL);
00168 }
00169 
00170 
00171 NV_INLINE TkActorImpl* TkFamilyImpl::getActorByIndex(uint32_t index)
00172 {
00173     NVBLAST_ASSERT(index < m_actors.size());
00174     return &m_actors[index];
00175 }
00176 
00177 
00178 NV_INLINE TkActorImpl* TkFamilyImpl::getActorByActorLL(const NvBlastActor* actorLL)
00179 {
00180     uint32_t index = NvBlastActorGetIndex(actorLL, logLL);
00181     return getActorByIndex(index);
00182 }
00183 
00184 
00185 NV_INLINE Array<TkActorImpl>::type& TkFamilyImpl::getActorsInternal()
00186 {
00187     return m_actors;
00188 }
00189 
00190 
00191 NV_INLINE uint32_t TkFamilyImpl::getInternalJointCount() const
00192 {
00193     return m_internalJointCount;
00194 }
00195 
00196 
00197 NV_INLINE TkJointImpl* TkFamilyImpl::getInternalJoints() const
00198 {
00199     return const_cast<TkJointImpl*>(reinterpret_cast<const TkJointImpl*>(m_internalJointBuffer.begin()));
00200 }
00201 
00202 
00203 NV_INLINE void TkFamilyImpl::releaseJoint(TkJointImpl& joint)
00204 {
00205     NVBLAST_ASSERT(joint.m_owner == this);
00206     NVBLAST_ASSERT(&joint >= getInternalJoints() && &joint < getInternalJoints() + getInternalJointCount() * sizeof(TkJointImpl));
00207 
00208     joint.~TkJointImpl();
00209     joint.m_owner = nullptr;
00210 }
00211 
00212 
00214 
00215 NV_INLINE const NvBlastID& getFamilyID(const TkActor* actor)
00216 {
00217     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");
00218 }
00219 
00220 NV_INLINE const NvBlastID& getFamilyID(const TkFamilyImpl* family)
00221 {
00222     return family != nullptr ? family->getIDInternal() : *reinterpret_cast<const NvBlastID*>("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
00223 }
00224 
00225 } // namespace Blast
00226 } // namespace Nv
00227 
00228 
00229 #endif // ifndef NVBLASTTKFAMILYIMPL_H
Copyright © 2015-2017 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com