RavEngine
Loading...
Searching...
No Matches
ScActorPair.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef SC_ACTOR_PAIR_H
30#define SC_ACTOR_PAIR_H
31
32#include "ScRigidSim.h"
33#include "ScContactStream.h"
34#include "ScNPhaseCore.h"
35#if PX_SUPPORT_GPU_PHYSX
36#include "ScSoftBodySim.h"
37#endif
38
39
40namespace physx
41{
42namespace Sc
43{
45 {
46 public:
48 mStrmResetStamp (0xffffffff),
49 mActorAID (0xffffffff),
50 mActorBID (0xffffffff),
51 mPxActorA (NULL),
52 mPxActorB (NULL)
53 {}
54
55 ContactStreamManager mContactStreamManager;
56 PxU32 mStrmResetStamp;
57 PxU32 mActorAID;
58 PxU32 mActorBID;
59 PxActor* mPxActorA;
60 PxActor* mPxActorB;
61 };
62
69 {
70 public:
71
72 enum ActorPairFlags
73 {
74 eIS_REPORT_PAIR = (1<<0),
75 eNEXT_FREE = (1<<1)
76 };
77
78 PX_FORCE_INLINE ActorPair() : mInternalFlags(0), mTouchCount(0), mRefCount(0) {}
80
81 PX_FORCE_INLINE PxIntBool isReportPair() const { return (mInternalFlags & eIS_REPORT_PAIR); }
82
83 PX_FORCE_INLINE void incTouchCount() { mTouchCount++; PX_ASSERT(mTouchCount); }
84 PX_FORCE_INLINE void decTouchCount() { PX_ASSERT(mTouchCount); mTouchCount--; }
85 PX_FORCE_INLINE PxU32 getTouchCount() const { return mTouchCount; }
86
87 PX_FORCE_INLINE void incRefCount() { ++mRefCount; PX_ASSERT(mRefCount>0); }
88 PX_FORCE_INLINE PxU32 decRefCount() { PX_ASSERT(mRefCount>0); return --mRefCount; }
89 PX_FORCE_INLINE PxU32 getRefCount() const { return mRefCount; }
90
91 private:
92 ActorPair& operator=(const ActorPair&);
93
94 protected:
95 PxU16 mInternalFlags;
96 PxU16 mTouchCount;
97 PxU16 mRefCount;
98 PxU16 mPad; // instances of this class are stored in a pool which needs an item size of at least size_t
99 };
100
110 {
111 public:
112
113 enum ActorPairReportFlags
114 {
115 eIS_IN_CONTACT_REPORT_ACTOR_PAIR_SET = ActorPair::eNEXT_FREE // PT: whether the pair is already stored in the 'ContactReportActorPairSet' or not
116 };
117
120
121 PX_INLINE ContactStreamManager& createContactStreamManager(NPhaseCore&);
122 PX_FORCE_INLINE ContactStreamManager& getContactStreamManager() const { PX_ASSERT(mReportData); return mReportData->mContactStreamManager; }
123 PX_FORCE_INLINE ActorSim& getActorA() const { return mActorA; }
124 PX_FORCE_INLINE ActorSim& getActorB() const { return mActorB; }
125 PX_INLINE PxU32 getActorAID() const { PX_ASSERT(mReportData); return mReportData->mActorAID; }
126 PX_INLINE PxU32 getActorBID() const { PX_ASSERT(mReportData); return mReportData->mActorBID; }
127 PX_INLINE PxActor* getPxActorA() const { PX_ASSERT(mReportData); return mReportData->mPxActorA; }
128 PX_INLINE PxActor* getPxActorB() const { PX_ASSERT(mReportData); return mReportData->mPxActorB; }
129 PX_INLINE bool streamResetStamp(PxU32 cmpStamp);
130
131 PX_FORCE_INLINE PxU16 isInContactReportActorPairSet() const { return PxU16(mInternalFlags & eIS_IN_CONTACT_REPORT_ACTOR_PAIR_SET); }
132 PX_FORCE_INLINE void setInContactReportActorPairSet() { mInternalFlags |= eIS_IN_CONTACT_REPORT_ACTOR_PAIR_SET; }
133 PX_FORCE_INLINE void clearInContactReportActorPairSet() { mInternalFlags &= ~eIS_IN_CONTACT_REPORT_ACTOR_PAIR_SET; }
134
135 PX_FORCE_INLINE void createContactReportData(NPhaseCore&);
136 PX_FORCE_INLINE void releaseContactReportData(NPhaseCore&);
137
138 PX_FORCE_INLINE void convert(ActorPair& aPair) { PX_ASSERT(!aPair.isReportPair()); mTouchCount = PxU16(aPair.getTouchCount()); mRefCount = PxU16(aPair.getRefCount()); }
139
140 PX_FORCE_INLINE static ActorPairReport& cast(ActorPair& aPair) { PX_ASSERT(aPair.isReportPair()); return static_cast<ActorPairReport&>(aPair); }
141
142 private:
143 ActorPairReport& operator=(const ActorPairReport&);
144
145 ActorSim& mActorA;
146 ActorSim& mActorB;
147
148 ActorPairContactReportData* mReportData;
149 };
150
151} // namespace Sc
152
153PX_FORCE_INLINE Sc::ActorPairReport::ActorPairReport(ActorSim& actor0, ActorSim& actor1) : ActorPair(),
154mActorA (actor0),
155mActorB (actor1),
156mReportData (NULL)
157{
158 PX_ASSERT(mInternalFlags == 0);
159 mInternalFlags = ActorPair::eIS_REPORT_PAIR;
160}
161
162PX_FORCE_INLINE Sc::ActorPairReport::~ActorPairReport()
163{
164 PX_ASSERT(mReportData == NULL);
165}
166
167PX_INLINE bool Sc::ActorPairReport::streamResetStamp(PxU32 cmpStamp)
168{
169 PX_ASSERT(mReportData);
170 const bool ret = (cmpStamp != mReportData->mStrmResetStamp);
171 mReportData->mStrmResetStamp = cmpStamp;
172 return ret;
173}
174
175PX_INLINE Sc::ContactStreamManager& Sc::ActorPairReport::createContactStreamManager(NPhaseCore& npCore)
176{
177 // Lazy create report data
178 if(!mReportData)
179 createContactReportData(npCore);
180
181 return mReportData->mContactStreamManager;
182}
183
184PX_FORCE_INLINE void Sc::ActorPairReport::createContactReportData(NPhaseCore& npCore)
185{
186 PX_ASSERT(!mReportData);
187 Sc::ActorPairContactReportData* reportData = npCore.createActorPairContactReportData();
188 mReportData = reportData;
189
190 if(reportData)
191 {
192 const ActorCore& actorCoreA = mActorA.getActorCore();
193 const ActorCore& actorCoreB = mActorB.getActorCore();
194
195 reportData->mActorAID = mActorA.getActorID();
196 reportData->mActorBID = mActorB.getActorID();
197
198#if PX_SUPPORT_GPU_PHYSX
199 if (mActorA.getActorType() == PxActorType::eSOFTBODY)
200 reportData->mPxActorA = static_cast<const SoftBodyCore&>(actorCoreA).getPxActor();
201 else
202#endif
203 reportData->mPxActorA = static_cast<const RigidCore&>(actorCoreA).getPxActor();
204
205#if PX_SUPPORT_GPU_PHYSX
206 if (mActorA.getActorType() == PxActorType::eSOFTBODY)
207 reportData->mPxActorB = static_cast<const SoftBodyCore&>(actorCoreB).getPxActor();
208 else
209#endif
210 reportData->mPxActorB = static_cast<const RigidCore&>(actorCoreB).getPxActor();
211 }
212}
213
214PX_FORCE_INLINE void Sc::ActorPairReport::releaseContactReportData(NPhaseCore& npCore)
215{
216 // Can't take the NPhaseCore (scene) reference from the actors since they're already gone on scene release
217
218 if(mReportData)
219 {
220 npCore.releaseActorPairContactReportData(mReportData);
221 mReportData = NULL;
222 }
223}
224
225}
226
227#endif
PxActor is the base class for the main simulation objects in the physics SDK.
Definition PxActor.h:201
Definition ScActorPair.h:45
Class shared by all shape interactions for a pair of actors if contact reports are requested.
Definition ScActorPair.h:110
Class shared by all shape interactions for a pair of actors.
Definition ScActorPair.h:69
Definition ScActorSim.h:83
Contact report logic and data management.
Definition ScContactStream.h:125
Definition ScNPhaseCore.h:193
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_INLINE
Definition PxPreprocessor.h:320
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
@ eSOFTBODY
A FEM-based soft body.
Definition PxActor.h:144