RavEngine
Loading...
Searching...
No Matches
PxsSimpleIslandManager.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 PXS_SIMPLE_ISLAND_GEN_H
30#define PXS_SIMPLE_ISLAND_GEN_H
31
32#include "foundation/PxUserAllocated.h"
33#include "PxsIslandSim.h"
34#include "CmTask.h"
35
36namespace physx
37{
38
39namespace Sc
40{
41 class Interaction;
42}
43namespace IG
44{
45
46 class SimpleIslandManager;
47
48class ThirdPassTask : public Cm::Task
49{
50 SimpleIslandManager& mIslandManager;
51 IslandSim& mIslandSim;
52
53public:
54
55 ThirdPassTask(PxU64 contextID, SimpleIslandManager& islandManager, IslandSim& islandSim);
56
57 virtual void runInternal();
58
59 virtual const char* getName() const
60 {
61 return "ThirdPassIslandGenTask";
62 }
63
64private:
65 PX_NOCOPY(ThirdPassTask)
66};
67
69{
70 SimpleIslandManager& mIslandManager;
71
72public:
73
74 PostThirdPassTask(PxU64 contextID, SimpleIslandManager& islandManager);
75
76 virtual void runInternal();
77
78 virtual const char* getName() const
79 {
80 return "PostThirdPassTask";
81 }
82private:
83 PX_NOCOPY(PostThirdPassTask)
84};
85
87{
88 HandleManager<PxU32> mNodeHandles;
89 HandleManager<EdgeIndex> mEdgeHandles;
90
91 //An array of destroyed nodes
92 PxArray<PxNodeIndex> mDestroyedNodes;
94
95
96 //Edges destroyed this frame
97 PxArray<EdgeIndex> mDestroyedEdges;
98 PxArray<PartitionEdge*> mFirstPartitionEdges;
99 PxArray<PartitionEdge*> mDestroyedPartitionEdges;
100 //KS - stores node indices for a given edge. Node index 0 is at 2* edgeId and NodeIndex1 is at 2*edgeId + 1
101 //can also be used for edgeInstance indexing so there's no need to figure out outboundNode ID either!
102 Cm::BlockArray<PxNodeIndex> mEdgeNodeIndices;
103 Cm::BlockArray<void*> mConstraintOrCm;
104
105 PxBitMap mConnectedMap;
106
107 IslandSim mIslandManager;
108 IslandSim mSpeculativeIslandManager;
109
110 ThirdPassTask mSpeculativeThirdPassTask;
111 ThirdPassTask mAccurateThirdPassTask;
112
113 PostThirdPassTask mPostThirdPassTask;
114 PxU32 mMaxDirtyNodesPerFrame;
115
116 PxU64 mContextID;
117public:
118
119 SimpleIslandManager(bool useEnhancedDeterminism, PxU64 contextID);
120
122
123 PxNodeIndex addRigidBody(PxsRigidBody* body, bool isKinematic, bool isActive);
124
125 void removeNode(const PxNodeIndex index);
126
127 PxNodeIndex addArticulation(Sc::ArticulationSim* articulation, Dy::FeatherstoneArticulation* llArtic, bool isActive);
128
129#if PX_SUPPORT_GPU_PHYSX
130 PxNodeIndex addSoftBody(Dy::SoftBody* llSoftBody, bool isActive);
131
132 PxNodeIndex addFEMCloth(Dy::FEMCloth* llFEMCloth, bool isActive);
133
134 PxNodeIndex addParticleSystem(Dy::ParticleSystem* llParticleSystem, bool isActive);
135
136 PxNodeIndex addHairSystem(Dy::HairSystem* llHairSystem, bool isActive);
137#endif
138
139 EdgeIndex addContactManager(PxsContactManager* manager, PxNodeIndex nodeHandle1, PxNodeIndex nodeHandle2, Sc::Interaction* interaction,
140 Edge::EdgeType edgeType);
141
142 EdgeIndex addConstraint(Dy::Constraint* constraint, PxNodeIndex nodeHandle1, PxNodeIndex nodeHandle2, Sc::Interaction* interaction);
143
144 bool isConnected(EdgeIndex edgeIndex) const { return !!mConnectedMap.test(edgeIndex); }
145
146 PX_FORCE_INLINE PxNodeIndex getEdgeIndex(EdgeInstanceIndex edgeIndex) const { return mEdgeNodeIndices[edgeIndex]; }
147
148 void activateNode(PxNodeIndex index);
149 void deactivateNode(PxNodeIndex index);
150 void putNodeToSleep(PxNodeIndex index);
151
152 void removeConnection(EdgeIndex edgeIndex);
153
154 void firstPassIslandGen();
155 void additionalSpeculativeActivation();
156 void secondPassIslandGen();
157 void thirdPassIslandGen(PxBaseTask* continuation);
158
159 PX_INLINE void clearDestroyedEdges()
160 {
161 mDestroyedPartitionEdges.forceSize_Unsafe(0);
162 }
163
164 void setEdgeConnected(EdgeIndex edgeIndex, Edge::EdgeType edgeType);
165 void setEdgeDisconnected(EdgeIndex edgeIndex);
166
167 bool getIsEdgeConnected(EdgeIndex edgeIndex);
168
169 void setEdgeRigidCM(const EdgeIndex edgeIndex, PxsContactManager* cm);
170
171 void clearEdgeRigidCM(const EdgeIndex edgeIndex);
172
173 void setKinematic(PxNodeIndex nodeIndex);
174
175 void setDynamic(PxNodeIndex nodeIndex);
176
177 const IslandSim& getSpeculativeIslandSim() const { return mSpeculativeIslandManager; }
178 const IslandSim& getAccurateIslandSim() const { return mIslandManager; }
179
180 IslandSim& getAccurateIslandSim() { return mIslandManager; }
181 IslandSim& getSpeculativeIslandSim() { return mSpeculativeIslandManager; }
182
183 PX_FORCE_INLINE PxU32 getNbEdgeHandles() const { return mEdgeHandles.getTotalHandles(); }
184
185 PX_FORCE_INLINE PxU32 getNbNodeHandles() const { return mNodeHandles.getTotalHandles(); }
186
187 void deactivateEdge(const EdgeIndex edge);
188
189 PX_FORCE_INLINE PxsContactManager* getContactManager(IG::EdgeIndex edgeId) const { return reinterpret_cast<PxsContactManager*>(mConstraintOrCm[edgeId]); }
190 PX_FORCE_INLINE PxsContactManager* getContactManagerUnsafe(IG::EdgeIndex edgeId) const { return reinterpret_cast<PxsContactManager*>(mConstraintOrCm[edgeId]); }
191 PX_FORCE_INLINE Dy::Constraint* getConstraint(IG::EdgeIndex edgeId) const { return reinterpret_cast<Dy::Constraint*>(mConstraintOrCm[edgeId]); }
192 PX_FORCE_INLINE Dy::Constraint* getConstraintUnsafe(IG::EdgeIndex edgeId) const { return reinterpret_cast<Dy::Constraint*>(mConstraintOrCm[edgeId]); }
193
194 PX_FORCE_INLINE Sc::Interaction* getInteraction(IG::EdgeIndex edgeId) const { return mInteractions[edgeId]; }
195
196 PX_FORCE_INLINE PxU64 getContextId() const { return mContextID; }
197
198 bool checkInternalConsistency();
199
200
201private:
202
203 friend class ThirdPassTask;
204 friend class PostThirdPassTask;
205
206 bool validateDeactivations() const;
207
208 PX_NOCOPY(SimpleIslandManager)
209};
210
211
212
213}
214}
215
216#endif
Definition CmBlockArray.h:47
Definition CmTask.h:49
Definition DyFEMCloth.h:50
Definition DyFeatherstoneArticulation.h:590
Definition DyHairSystem.h:81
Definition DyParticleSystem.h:66
Definition DySoftBody.h:52
Definition PxsIslandSim.h:157
Definition PxsIslandSim.h:412
Definition PxsSimpleIslandManager.h:69
virtual const char * getName() const
Return a user-provided task name for profiling purposes.
Definition PxsSimpleIslandManager.h:78
Definition PxsSimpleIslandManager.h:87
Definition PxsSimpleIslandManager.h:49
virtual const char * getName() const
Return a user-provided task name for profiling purposes.
Definition PxsSimpleIslandManager.h:59
Definition PxArray.h:53
PX_FORCE_INLINE void forceSize_Unsafe(uint32_t size)
Definition PxArray.h:507
Base class of all task types.
Definition PxTask.h:45
Definition PxBitMap.h:52
PxNodeIndex.
Definition PxNodeIndex.h:51
Definition PxUserAllocated.h:43
Definition PxsContactManager.h:77
Definition PxsRigidBody.h:43
Definition ScArticulationSim.h:68
Definition ScInteraction.h:50
#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
Definition DyConstraint.h:53