1 | // |
2 | // Redistribution and use in source and binary forms, with or without |
3 | // modification, are permitted provided that the following conditions |
4 | // are met: |
5 | // * Redistributions of source code must retain the above copyright |
6 | // notice, this list of conditions and the following disclaimer. |
7 | // * Redistributions in binary form must reproduce the above copyright |
8 | // notice, this list of conditions and the following disclaimer in the |
9 | // documentation and/or other materials provided with the distribution. |
10 | // * Neither the name of NVIDIA CORPORATION nor the names of its |
11 | // contributors may be used to endorse or promote products derived |
12 | // from this software without specific prior written permission. |
13 | // |
14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY |
15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
17 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
18 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
19 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
20 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
21 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
22 | // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 | // |
26 | // Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved. |
27 | // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. |
28 | // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. |
29 | |
30 | |
31 | #ifndef PXS_NPHASE_IMPLEMENTATION_CONTEXT_H |
32 | #define PXS_NPHASE_IMPLEMENTATION_CONTEXT_H |
33 | |
34 | #include "PxvNphaseImplementationContext.h" |
35 | #include "PxsContactManagerState.h" |
36 | #include "PxcNpCache.h" |
37 | |
38 | namespace physx |
39 | { |
40 | |
41 | struct PxsContactManagers : PxsContactManagerBase |
42 | { |
43 | Ps::Array<PxsContactManagerOutput> mOutputContactManagers; |
44 | Ps::Array<PxsContactManager*> mContactManagerMapping; |
45 | Ps::Array<Gu::Cache> mCaches; |
46 | |
47 | |
48 | PxsContactManagers(const PxU32 bucketId) : PxsContactManagerBase(bucketId), |
49 | mOutputContactManagers(PX_DEBUG_EXP("mOutputContactManagers" )), |
50 | mContactManagerMapping(PX_DEBUG_EXP("mContactManagerMapping" )), |
51 | mCaches(PX_DEBUG_EXP("mCaches" )) |
52 | { |
53 | } |
54 | |
55 | void clear() |
56 | { |
57 | mOutputContactManagers.forceSize_Unsafe(size: 0); |
58 | mContactManagerMapping.forceSize_Unsafe(size: 0); |
59 | mCaches.forceSize_Unsafe(size: 0); |
60 | |
61 | } |
62 | private: |
63 | PX_NOCOPY(PxsContactManagers) |
64 | }; |
65 | |
66 | |
67 | class PxsNphaseImplementationContext: public PxvNphaseImplementationContextUsableAsFallback |
68 | { |
69 | public: |
70 | static PxsNphaseImplementationContext* create(PxsContext& context, IG::IslandSim* islandSim); |
71 | |
72 | PxsNphaseImplementationContext(PxsContext& context, IG::IslandSim* islandSim, PxU32 index = 0): PxvNphaseImplementationContextUsableAsFallback(context), mNarrowPhasePairs(index), mNewNarrowPhasePairs(index), |
73 | mModifyCallback(NULL), mIslandSim(islandSim) {} |
74 | virtual void destroy(); |
75 | virtual void updateContactManager(PxReal dt, bool hasBoundsArrayChanged, bool hasContactDistanceChanged, PxBaseTask* continuation, PxBaseTask* firstPassContinuation); |
76 | virtual void postBroadPhaseUpdateContactManager() {} |
77 | virtual void secondPassUpdateContactManager(PxReal dt, PxBaseTask* continuation); |
78 | |
79 | virtual void registerContactManager(PxsContactManager* cm, PxI32 touching, PxU32 numPatches); |
80 | virtual void registerContactManagers(PxsContactManager** cm, PxU32 nbContactManagers, PxU32 maxContactManagerId); |
81 | virtual void unregisterContactManager(PxsContactManager* cm); |
82 | virtual void unregisterContactManagerFallback(PxsContactManager* cm, PxsContactManagerOutput* cmOutputs); |
83 | |
84 | |
85 | virtual void refreshContactManager(PxsContactManager* cm); |
86 | virtual void refreshContactManagerFallback(PxsContactManager* cm, PxsContactManagerOutput* cmOutputs); |
87 | |
88 | virtual void registerShape(const PxsShapeCore& shapeCore); |
89 | |
90 | virtual void updateShapeMaterial(const PxsShapeCore& shapeCore); |
91 | virtual void updateShapeContactOffset(const PxsShapeCore& shapeCore); |
92 | |
93 | virtual void unregisterShape(const PxsShapeCore& shapeCore); |
94 | |
95 | virtual void registerMaterial(const PxsMaterialCore& materialCore); |
96 | virtual void updateMaterial(const PxsMaterialCore& materialCore); |
97 | virtual void unregisterMaterial(const PxsMaterialCore& materialCore); |
98 | |
99 | virtual void appendContactManagers(); |
100 | virtual void appendContactManagersFallback(PxsContactManagerOutput* cmOutputs); |
101 | |
102 | virtual void removeContactManagersFallback(PxsContactManagerOutput* cmOutputs); |
103 | |
104 | virtual void setContactModifyCallback(PxContactModifyCallback* callback) { mModifyCallback = callback; } |
105 | |
106 | virtual PxsContactManagerOutputIterator getContactManagerOutputs(); |
107 | |
108 | virtual PxsContactManagerOutput& getNewContactManagerOutput(PxU32 npIndex); |
109 | |
110 | virtual PxsContactManagerOutput* getGPUContactManagerOutputBase() { return NULL; } |
111 | |
112 | virtual void acquireContext(){} |
113 | virtual void releaseContext(){} |
114 | virtual void preallocateNewBuffers(PxU32 /*nbNewPairs*/, PxU32 /*maxIndex*/) { /*TODO - implement if it's useful to do so*/} |
115 | |
116 | void processContactManager(PxReal dt, PxsContactManagerOutput* cmOutputs, PxBaseTask* continuation); |
117 | void processContactManagerSecondPass(PxReal dt, PxBaseTask* continuation); |
118 | void fetchUpdateContactManager() {} |
119 | |
120 | |
121 | |
122 | void startNarrowPhaseTasks() {} |
123 | |
124 | virtual void lock() { mContactManagerMutex.lock(); } |
125 | virtual void unlock() { mContactManagerMutex.unlock(); } |
126 | |
127 | |
128 | |
129 | Ps::Array<PxU32> mRemovedContactManagers; |
130 | PxsContactManagers mNarrowPhasePairs; |
131 | PxsContactManagers mNewNarrowPhasePairs; |
132 | |
133 | PxContactModifyCallback* mModifyCallback; |
134 | |
135 | IG::IslandSim* mIslandSim; |
136 | |
137 | Ps::Mutex mContactManagerMutex; |
138 | |
139 | private: |
140 | |
141 | void unregisterContactManagerInternal(PxU32 npIndex, PxsContactManagers& managers, PxsContactManagerOutput* cmOutputs); |
142 | |
143 | PX_NOCOPY(PxsNphaseImplementationContext) |
144 | }; |
145 | |
146 | } |
147 | |
148 | #endif |
149 | |