RavEngine
Loading...
Searching...
No Matches
BpAABBManager.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 BP_AABBMANAGER_H
30#define BP_AABBMANAGER_H
31
32#include "foundation/PxHashSet.h"
33#include "foundation/PxHashMap.h"
34#include "BpAABBManagerTasks.h"
35#include "BpAABBManagerBase.h"
36
37namespace physx
38{
39namespace Cm
40{
41 class FlushPool;
42}
43
44namespace Bp
45{
46 struct BroadPhasePair;
47
48 // PT: TODO: revisit this.....
49 class Aggregate;
50 class PersistentPairs;
54
55 struct AggPair
56 {
58 PX_FORCE_INLINE AggPair(ShapeHandle index0, ShapeHandle index1) : mIndex0(index0), mIndex1(index1) {}
59 ShapeHandle mIndex0;
60 ShapeHandle mIndex1;
61
62 PX_FORCE_INLINE bool operator==(const AggPair& p) const
63 {
64 return (p.mIndex0 == mIndex0) && (p.mIndex1 == mIndex1);
65 }
66 };
68
69 // PT: TODO: isn't there a generic pair structure somewhere? refactor with AggPair anyway
70 struct Pair
71 {
72 PX_FORCE_INLINE Pair(PxU32 id0, PxU32 id1) : mID0(id0), mID1(id1) {}
74
75 PX_FORCE_INLINE bool operator<(const Pair& p) const
76 {
77 const PxU64 value0 = *reinterpret_cast<const PxU64*>(this);
78 const PxU64 value1 = *reinterpret_cast<const PxU64*>(&p);
79 return value0 < value1;
80 }
81
82 PX_FORCE_INLINE bool operator==(const Pair& p) const
83 {
84 return (p.mID0 == mID0) && (p.mID1 == mID1);
85 }
86
87 PX_FORCE_INLINE bool operator!=(const Pair& p) const
88 {
89 return (p.mID0 != mID0) || (p.mID1 != mID1);
90 }
91
92 PxU32 mID0;
93 PxU32 mID1;
94 };
95
96 class AABBManager;
97
99 {
100 Cm::FlushPool* mFlushPool;
101 AABBManager& mManager;
102
103 PX_NOCOPY(PostBroadPhaseStage2Task)
104 public:
105
106 PostBroadPhaseStage2Task(PxU64 contextID, AABBManager& manager) : Cm::Task(contextID), mFlushPool(NULL), mManager(manager)
107 {
108 }
109
110 virtual const char* getName() const { return "PostBroadPhaseStage2Task"; }
111
112 void setFlushPool(Cm::FlushPool* pool) { mFlushPool = pool; }
113
114 virtual void runInternal();
115 };
116
118
128 {
129 PX_NOCOPY(AABBManager)
130 public:
131 AABBManager(BroadPhase& bp, BoundsArray& boundsArray, PxFloatArrayPinned& contactDistance,
132 PxU32 maxNbAggregates, PxU32 maxNbShapes, PxVirtualAllocator& allocator, PxU64 contextID,
133 PxPairFilteringMode::Enum kineKineFilteringMode, PxPairFilteringMode::Enum staticKineFilteringMode);
134
135 virtual ~AABBManager() {}
136
137 // AABBManagerBase
138 virtual void destroy() PX_OVERRIDE;
139 virtual AggregateHandle createAggregate(BoundsIndex index, Bp::FilterGroup::Enum group, void* userData, PxU32 maxNumShapes, PxAggregateFilterHint filterHint) PX_OVERRIDE;
140 virtual bool destroyAggregate(BoundsIndex& index, Bp::FilterGroup::Enum& group, AggregateHandle aggregateHandle) PX_OVERRIDE;
141 virtual bool addBounds(BoundsIndex index, PxReal contactDistance, Bp::FilterGroup::Enum group, void* userdata, AggregateHandle aggregateHandle, ElementType::Enum volumeType) PX_OVERRIDE;
142 virtual bool removeBounds(BoundsIndex index) PX_OVERRIDE;
143 virtual void updateBPFirstPass(PxU32 numCpuTasks, Cm::FlushPool& flushPool, bool hasContactDistanceUpdated, PxBaseTask* continuation) PX_OVERRIDE;
144 virtual void updateBPSecondPass(PxU32 numCpuTasks, PxcScratchAllocator* scratchAllocator, PxBaseTask* continuation) PX_OVERRIDE;
145 virtual void postBroadPhase(PxBaseTask*, Cm::FlushPool& flushPool) PX_OVERRIDE;
146 virtual void reallocateChangedAABBMgActorHandleMap(const PxU32 size) PX_OVERRIDE;
147 virtual void visualize(PxRenderOutput& out) PX_OVERRIDE;
148 virtual void releaseDeferredAggregateIds() PX_OVERRIDE{}
149 //~AABBManagerBase
150
151 void preBpUpdate_CPU(PxU32 numCpuTasks);
152
153 // PT: TODO: what is that BpCacheData for?
154 BpCacheData* getBpCacheData();
155 void putBpCacheData(BpCacheData*);
156 void resetBpCacheData();
157
158 PxMutex mMapLock;
159 private:
160 //void reserveShapeSpace(PxU32 nbShapes);
161
162 void postBpStage2(PxBaseTask*, Cm::FlushPool&);
163 void postBpStage3(PxBaseTask*);
164
165 PostBroadPhaseStage2Task mPostBroadPhase2;
167
168 PreBpUpdateTask mPreBpUpdateTask;
169
170 PxU32 mTimestamp;
171 PxU32 mFirstFreeAggregate;
172 PxArray<Aggregate*> mAggregates; // PT: indexed by AggregateHandle
173 PxArray<Aggregate*> mDirtyAggregates;
174
175 AggPairMap mActorAggregatePairs;
176 AggPairMap mAggregateAggregatePairs;
177
178 PxArray<ProcessAggPairsBase*> mAggPairTasks;
179
180 PxHashSet<Pair> mCreatedPairs;
181
182 PxSList mBpThreadContextPool;
183
184 PX_FORCE_INLINE Aggregate* getAggregateFromHandle(AggregateHandle handle)
185 {
186 PX_ASSERT(handle<mAggregates.size());
187 return mAggregates[handle];
188 }
189
190 void startAggregateBoundsComputationTasks(PxU32 nbToGo, PxU32 numCpuTasks, Cm::FlushPool& flushPool);
191 PersistentActorAggregatePair* createPersistentActorAggregatePair(ShapeHandle volA, ShapeHandle volB);
192 PersistentAggregateAggregatePair* createPersistentAggregateAggregatePair(ShapeHandle volA, ShapeHandle volB);
193 void updatePairs(PersistentPairs& p, BpCacheData* data = NULL);
194 void handleOriginShift();
195
196 public:
197 void processBPCreatedPair(const BroadPhasePair& pair);
198 void processBPDeletedPair(const BroadPhasePair& pair);
199
200 friend class PersistentActorAggregatePair;
203 friend class PostBroadPhaseStage2Task;
204 };
205
206} //namespace Bp
207} //namespace physx
208
209#endif //BP_AABBMANAGER_H
Definition BpAABBManager.cpp:676
Definition BpAABBManager.cpp:766
Definition BpAABBManager.cpp:812
Definition BpAABBManager.cpp:1882
Definition BpAABBManager.cpp:1992
A structure responsible for: storing an aabb representation for each active shape in the related scen...
Definition BpAABBManagerBase.h:165
A structure responsible for: storing an aabb representation for each active shape in the related scen...
Definition BpAABBManager.h:128
Definition BpAABBManager.cpp:98
Definition BpAABBManagerBase.h:101
Definition BpBroadPhase.h:99
Definition BpAABBManager.cpp:192
Definition BpAABBManager.h:99
virtual const char * getName() const
Return a user-provided task name for profiling purposes.
Definition BpAABBManager.h:110
Definition BpAABBManagerTasks.h:75
Definition CmTask.h:90
Definition CmFlushPool.h:49
Definition CmTask.h:49
PX_FORCE_INLINE uint32_t size() const
Definition PxArray.h:242
Base class of all task types.
Definition PxTask.h:45
Definition PxHashMap.h:101
Definition PxHashSet.h:77
Definition PxMutex.h:89
Definition PxRenderOutput.h:50
Definition PxSList.h:90
Definition PxAllocator.h:158
Definition PxcScratchAllocator.h:42
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#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 BpAABBManager.h:56
Definition BpAABBManagerBase.h:83
Definition BpBroadPhase.h:82
Definition BpAABBManager.h:71
Enum
Definition PxFiltering.h:717