RavEngine
Loading...
Searching...
No Matches
BpBroadPhaseSap.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
30#ifndef BP_BROADPHASE_SAP_H
31#define BP_BROADPHASE_SAP_H
32
33#include "BpBroadPhase.h"
34#include "BpBroadPhaseSapAux.h"
35#include "CmPool.h"
36#include "CmTask.h"
37
38namespace physx
39{
40class PxcScratchAllocator;
41
42namespace Gu
43{
44 class Axes;
45}
46
47namespace Bp
48{
49
50class SapEndPoint;
51class IntegerAABB;
52
54{
55public:
56
57 BroadPhaseBatchUpdateWorkTask(PxU64 contextId=0) :
58 Cm::Task (contextId),
59 mSap (NULL),
60 mAxis (0xffffffff),
61 mPairs (NULL),
62 mPairsSize (0),
63 mPairsCapacity (0)
64 {
65 }
66
67 virtual void runInternal();
68
69 virtual const char* getName() const { return "BpBroadphaseSap.batchUpdate"; }
70
71 void set(class BroadPhaseSap* sap, const PxU32 axis) {mSap = sap; mAxis = axis;}
72
73 BroadPhasePair* getPairs() const {return mPairs;}
74 PxU32 getPairsSize() const {return mPairsSize;}
75 PxU32 getPairsCapacity() const {return mPairsCapacity;}
76
77 void setPairs(BroadPhasePair* pairs, const PxU32 pairsCapacity) {mPairs = pairs; mPairsCapacity = pairsCapacity;}
78
79 void setNumPairs(const PxU32 pairsSize) {mPairsSize=pairsSize;}
80
81private:
82
83 class BroadPhaseSap* mSap;
84 PxU32 mAxis;
85
86 BroadPhasePair* mPairs;
87 PxU32 mPairsSize;
88 PxU32 mPairsCapacity;
89};
90
91//KS - TODO, this could be reduced to U16 in smaller scenes
93{
94 PxU32 mStartIndex;
95 PxU32 mEndIndex;
96};
97
98
100{
101 PX_NOCOPY(BroadPhaseSap)
102public:
103
105 friend class SapUpdateWorkTask;
106 friend class SapPostUpdateWorkTask;
107
108 BroadPhaseSap(const PxU32 maxNbBroadPhaseOverlaps, const PxU32 maxNbStaticShapes, const PxU32 maxNbDynamicShapes, PxU64 contextID);
109 virtual ~BroadPhaseSap();
110
111 // BroadPhase
112 virtual PxBroadPhaseType::Enum getType() const PX_OVERRIDE { return PxBroadPhaseType::eSAP; }
113 virtual void release() PX_OVERRIDE;
114 virtual void update(PxcScratchAllocator* scratchAllocator, const BroadPhaseUpdateData& updateData, physx::PxBaseTask* continuation) PX_OVERRIDE;
117 virtual const BroadPhasePair* getCreatedPairs(PxU32& nbCreatedPairs) const PX_OVERRIDE { nbCreatedPairs = mCreatedPairsSize; return mCreatedPairsArray; }
118 virtual const BroadPhasePair* getDeletedPairs(PxU32& nbDeletedPairs) const PX_OVERRIDE { nbDeletedPairs = mDeletedPairsSize; return mDeletedPairsArray; }
119 virtual void freeBuffers() PX_OVERRIDE;
120 virtual void shiftOrigin(const PxVec3& shift, const PxBounds3* boundsArray, const PxReal* contactDistances) PX_OVERRIDE;
121#if PX_CHECKED
122 virtual bool isValid(const BroadPhaseUpdateData& updateData) const PX_OVERRIDE;
123#endif
124 //~BroadPhase
125
126private:
127 void resizeBuffers();
128
129 PxcScratchAllocator* mScratchAllocator;
130
131 //Data passed in from updateV.
132 const BpHandle* mCreated;
133 PxU32 mCreatedSize;
134 const BpHandle* mRemoved;
135 PxU32 mRemovedSize;
136 const BpHandle* mUpdated;
137 PxU32 mUpdatedSize;
138 const PxBounds3* mBoxBoundsMinMax;
139 const Bp::FilterGroup::Enum*mBoxGroups;
140 const BpFilter* mFilter;
141 const PxReal* mContactDistance;
142 PxU32 mBoxesCapacity;
143
144 //Boxes.
145 SapBox1D* mBoxEndPts[3]; //Position of box min/max in sorted arrays of end pts (needs to have mBoxesCapacity).
146
147 //End pts (endpts of boxes sorted along each axis).
148 ValType* mEndPointValues[3]; //Sorted arrays of min and max box coords
149 BpHandle* mEndPointDatas[3]; //Corresponding owner id and isMin/isMax for each entry in the sorted arrays of min and max box coords.
150
151 PxU8* mBoxesUpdated;
152 BpHandle* mSortedUpdateElements;
153 BroadPhaseActivityPocket* mActivityPockets;
154 BpHandle* mListNext;
155 BpHandle* mListPrev;
156
157 PxU32 mBoxesSize; //Number of sorted boxes + number of unsorted (new) boxes
158 PxU32 mBoxesSizePrev; //Number of sorted boxes
159 PxU32 mEndPointsCapacity; //Capacity of sorted arrays.
160
161 //Default maximum number of overlap pairs
162 PxU32 mDefaultPairsCapacity;
163
164 //Box-box overlap pairs created or removed each update.
165 BpHandle* mData;
166 PxU32 mDataSize;
167 PxU32 mDataCapacity;
168
169 //All current box-box overlap pairs.
170 SapPairManager mPairs;
171
172 //Created and deleted overlap pairs reported back through api.
173 BroadPhasePair* mCreatedPairsArray;
174 PxU32 mCreatedPairsSize;
175 PxU32 mCreatedPairsCapacity;
176 BroadPhasePair* mDeletedPairsArray;
177 PxU32 mDeletedPairsSize;
178 PxU32 mDeletedPairsCapacity;
179 PxU32 mActualDeletedPairSize;
180
181 bool setUpdateData(const BroadPhaseUpdateData& updateData);
182 void update();
183 void postUpdate();
184
185 //Batch create/remove/update.
186 void batchCreate();
187 void batchRemove();
188 void batchUpdate();
189
190 void batchUpdate(const PxU32 Axis, BroadPhasePair*& pairs, PxU32& pairsSize, PxU32& pairsCapacity);
191
192 void batchUpdateFewUpdates(const PxU32 Axis, BroadPhasePair*& pairs, PxU32& pairsSize, PxU32& pairsCapacity);
193
194 void ComputeSortedLists( //const PxVec4& globalMin, const PxVec4& globalMax,
195 BpHandle* PX_RESTRICT newBoxIndicesSorted, PxU32& newBoxIndicesCount, BpHandle* PX_RESTRICT oldBoxIndicesSorted, PxU32& oldBoxIndicesCount,
196 bool& allNewBoxesStatics, bool& allOldBoxesStatics);
197
198 BroadPhaseBatchUpdateWorkTask mBatchUpdateTasks[3];
199
200 const PxU64 mContextID;
201#if PX_DEBUG
202 bool isSelfOrdered() const;
203 bool isSelfConsistent() const;
204#endif
205};
206
207} //namespace Bp
208
209} //namespace physx
210
211#endif //BP_BROADPHASE_SAP_H
Definition BpFiltering.h:119
Definition BpBroadPhaseSap.h:54
virtual const char * getName() const
Return a user-provided task name for profiling purposes.
Definition BpBroadPhaseSap.h:69
Definition BpBroadPhaseSap.h:100
virtual void freeBuffers() PX_OVERRIDE
After the broadphase has completed its update() function and the created/deleted pairs have been quer...
Definition BpBroadPhaseSap.cpp:257
virtual void release() PX_OVERRIDE
Shutdown of the broadphase.
Definition BpBroadPhaseSap.cpp:211
virtual void update(PxcScratchAllocator *scratchAllocator, const BroadPhaseUpdateData &updateData, physx::PxBaseTask *continuation) PX_OVERRIDE
Updates the broadphase and computes the lists of created/deleted pairs.
Definition BpBroadPhaseSap.cpp:488
virtual void shiftOrigin(const PxVec3 &shift, const PxBounds3 *boundsArray, const PxReal *contactDistances) PX_OVERRIDE
Adjust internal structures after all bounds have been adjusted due to a scene origin shift.
Definition BpBroadPhaseSap.cpp:330
virtual void fetchBroadPhaseResults() PX_OVERRIDE
Fetch the results of any asynchronous broad phase work.
Definition BpBroadPhaseSap.h:116
virtual void preBroadPhase(const Bp::BroadPhaseUpdateData &) PX_OVERRIDE
prepare broad phase data.
Definition BpBroadPhaseSap.h:115
virtual const BroadPhasePair * getDeletedPairs(PxU32 &nbDeletedPairs) const PX_OVERRIDE
Get deleted pairs.
Definition BpBroadPhaseSap.h:118
Definition BpBroadPhaseUpdate.h:47
Definition BpBroadPhase.h:99
Definition BpBroadPhaseSapAux.h:94
Definition BpBroadPhaseSapAux.h:104
Definition CmTask.h:49
Base class of all task types.
Definition PxTask.h:45
Class representing 3D range or axis aligned bounding box.
Definition PxBounds3.h:58
3 Element vector class.
Definition PxVec3.h:50
Definition PxcScratchAllocator.h:42
#define PX_RESTRICT
Definition PxPreprocessor.h:355
#define PX_OVERRIDE
Definition PxPreprocessor.h:375
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Definition BpBroadPhaseSap.h:93
Definition BpBroadPhase.h:82
Enum
Definition PxBroadPhase.h:79
@ eSAP
3-axes sweep-and-prune
Definition PxBroadPhase.h:80