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#ifndef PXS_SIMPLE_ISLAND_GEN_H
31#define PXS_SIMPLE_ISLAND_GEN_H
32
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
68class PostThirdPassTask : public Cm::Task
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
86class SimpleIslandManager
87{
88
89 HandleManager<PxU32> mNodeHandles; //! Handle manager for nodes
90 HandleManager<EdgeIndex> mEdgeHandles; //! Handle manager for edges
91
92 //An array of destroyed nodes
93 Ps::Array<NodeIndex> mDestroyedNodes;
94 Cm::BlockArray<Sc::Interaction*> mInteractions;
95
96
97 //Edges destroyed this frame
98 Ps::Array<EdgeIndex> mDestroyedEdges;
99 Ps::Array<PartitionEdge*> mFirstPartitionEdges;
100 Ps::Array<PartitionEdge*> mDestroyedPartitionEdges;
101 //KS - stores node indices for a given edge. Node index 0 is at 2* edgeId and NodeIndex1 is at 2*edgeId + 1
102 //can also be used for edgeInstance indexing so there's no need to figure out outboundNode ID either!
103 Cm::BlockArray<NodeIndex> mEdgeNodeIndices;
104 Cm::BlockArray<void*> mConstraintOrCm; //! Pointers to either the constraint or Cm for this pair
105
106 Cm::BitMap mConnectedMap;
107
108 IslandSim mIslandManager;
109 IslandSim mSpeculativeIslandManager;
110
111 ThirdPassTask mSpeculativeThirdPassTask;
112 ThirdPassTask mAccurateThirdPassTask;
113
114 PostThirdPassTask mPostThirdPassTask;
115 PxU32 mMaxDirtyNodesPerFrame;
116
117 PxU64 mContextID;
118public:
119
120 SimpleIslandManager(bool useEnhancedDeterminism, PxU64 contextID);
121
122 ~SimpleIslandManager();
123
124 NodeIndex addRigidBody(PxsRigidBody* body, bool isKinematic, bool isActive);
125
126 void removeNode(const NodeIndex index);
127
128 NodeIndex addArticulation(Sc::ArticulationSim* articulation, Dy::ArticulationV* llArtic, bool isActive);
129
130 EdgeIndex addContactManager(PxsContactManager* manager, NodeIndex nodeHandle1, NodeIndex nodeHandle2, Sc::Interaction* interaction);
131
132 EdgeIndex addConstraint(Dy::Constraint* constraint, NodeIndex nodeHandle1, NodeIndex nodeHandle2, Sc::Interaction* interaction);
133
134 bool isConnected(EdgeIndex edgeIndex) const { return !!mConnectedMap.test(index: edgeIndex); }
135
136 PX_FORCE_INLINE NodeIndex getEdgeIndex(EdgeInstanceIndex edgeIndex) const { return mEdgeNodeIndices[edgeIndex]; }
137
138 void activateNode(NodeIndex index);
139 void deactivateNode(NodeIndex index);
140 void putNodeToSleep(NodeIndex index);
141
142 void removeConnection(EdgeIndex edgeIndex);
143
144 void firstPassIslandGen();
145 void additionalSpeculativeActivation();
146 void secondPassIslandGen();
147 void thirdPassIslandGen(PxBaseTask* continuation);
148
149 void clearDestroyedEdges();
150
151 void setEdgeConnected(EdgeIndex edgeIndex);
152 void setEdgeDisconnected(EdgeIndex edgeIndex);
153
154 bool getIsEdgeConnected(EdgeIndex edgeIndex);
155
156 void setEdgeRigidCM(const EdgeIndex edgeIndex, PxsContactManager* cm);
157
158 void clearEdgeRigidCM(const EdgeIndex edgeIndex);
159
160 void setKinematic(IG::NodeIndex nodeIndex);
161
162 void setDynamic(IG::NodeIndex nodeIndex);
163
164 const IslandSim& getSpeculativeIslandSim() const { return mSpeculativeIslandManager; }
165 const IslandSim& getAccurateIslandSim() const { return mIslandManager; }
166
167 IslandSim& getAccurateIslandSim() { return mIslandManager; }
168
169 PX_FORCE_INLINE PxU32 getNbEdgeHandles() const { return mEdgeHandles.getTotalHandles(); }
170
171 PX_FORCE_INLINE PxU32 getNbNodeHandles() const { return mNodeHandles.getTotalHandles(); }
172
173 void deactivateEdge(const EdgeIndex edge);
174
175 PX_FORCE_INLINE PxsContactManager* getContactManager(IG::EdgeIndex edgeId) const { return reinterpret_cast<PxsContactManager*>(mConstraintOrCm[edgeId]); }
176 PX_FORCE_INLINE PxsContactManager* getContactManagerUnsafe(IG::EdgeIndex edgeId) const { return reinterpret_cast<PxsContactManager*>(mConstraintOrCm[edgeId]); }
177 PX_FORCE_INLINE Dy::Constraint* getConstraint(IG::EdgeIndex edgeId) const { return reinterpret_cast<Dy::Constraint*>(mConstraintOrCm[edgeId]); }
178 PX_FORCE_INLINE Dy::Constraint* getConstraintUnsafe(IG::EdgeIndex edgeId) const { return reinterpret_cast<Dy::Constraint*>(mConstraintOrCm[edgeId]); }
179
180 PX_FORCE_INLINE Sc::Interaction* getInteraction(IG::EdgeIndex edgeId) const { return mInteractions[edgeId]; }
181
182 PX_FORCE_INLINE PxU64 getContextId() const { return mContextID; }
183
184 bool checkInternalConsistency();
185
186
187private:
188
189 friend class ThirdPassTask;
190 friend class PostThirdPassTask;
191
192 bool validateDeactivations() const;
193
194 PX_NOCOPY(SimpleIslandManager)
195};
196
197
198
199}
200}
201
202#endif
203

source code of qtquick3dphysics/src/3rdparty/PhysX/source/lowlevel/software/include/PxsSimpleIslandManager.h