RavEngine
Loading...
Searching...
No Matches
GuPruningPool.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 GU_PRUNING_POOL_H
30#define GU_PRUNING_POOL_H
31
32#include "common/PxPhysXCommonConfig.h"
33#include "GuPrunerTypedef.h"
34#include "GuPrunerPayload.h"
35#include "GuBounds.h"
36#include "GuAABBTreeBounds.h"
37
38namespace physx
39{
40namespace Gu
41{
42 enum TransformCacheMode
43 {
44 TRANSFORM_CACHE_UNUSED,
45 TRANSFORM_CACHE_LOCAL,
46 TRANSFORM_CACHE_GLOBAL
47 };
48
49 // This class is designed to maintain a two way mapping between pair(PrunerPayload/userdata,AABB) and PrunerHandle
50 // Internally there's also an index for handles (AP: can be simplified?)
51 // This class effectively stores bounded pruner payloads/userdata, returns a PrunerHandle and allows O(1)
52 // access to them using a PrunerHandle
53 // Supported operations are add, remove, update bounds
54 class PX_PHYSX_COMMON_API PruningPool : public PxUserAllocated
55 {
56 PX_NOCOPY(PruningPool)
57 public:
58 PruningPool(PxU64 contextID, TransformCacheMode mode/*=TRANSFORM_CACHE_UNUSED*/);
60
61 PX_FORCE_INLINE const PrunerPayload& getPayloadData(PrunerHandle handle, PrunerPayloadData* data=NULL) const
62 {
63 const PoolIndex index = getIndex(handle);
64 if(data)
65 {
66 PxBounds3* wb = const_cast<PxBounds3*>(mWorldBoxes.getBounds());
67 data->mBounds = wb + index;
68 data->mTransform = mTransforms ? mTransforms + index : NULL;
69 }
70 return mObjects[index];
71 }
72
73 void shiftOrigin(const PxVec3& shift);
74
75 // PT: adds 'count' objects to the pool. Needs 'count' bounds and 'count' payloads passed as input. Writes out 'count' handles
76 // in 'results' array. Function returns number of successfully added objects, ideally 'count' but can be less in case we run
77 // out of memory.
78 PxU32 addObjects(PrunerHandle* results, const PxBounds3* bounds, const PrunerPayload* data, const PxTransform* transforms, PxU32 count);
79
80 // this function will swap the last object with the hole formed by removed PrunerHandle object
81 // and return the removed last object's index in the pool
82 PoolIndex removeObject(PrunerHandle h, PrunerPayloadRemovalCallback* removalCallback);
83
84 // Data access
85 PX_FORCE_INLINE PoolIndex getIndex(PrunerHandle h)const { return mHandleToIndex[h]; }
86 PX_FORCE_INLINE PrunerPayload* getObjects() const { return mObjects; }
87 PX_FORCE_INLINE const PxTransform* getTransforms() const { return mTransforms; }
88 PX_FORCE_INLINE PxTransform* getTransforms() { return mTransforms; }
89 PX_FORCE_INLINE bool setTransform(PrunerHandle handle, const PxTransform& transform)
90 {
91 if(!mTransforms)
92 return false;
93 mTransforms[getIndex(handle)] = transform;
94 return true;
95 }
96 PX_FORCE_INLINE PxU32 getNbActiveObjects() const { return mNbObjects; }
97 PX_FORCE_INLINE const PxBounds3* getCurrentWorldBoxes() const { return mWorldBoxes.getBounds(); }
98 PX_FORCE_INLINE PxBounds3* getCurrentWorldBoxes() { return mWorldBoxes.getBounds(); }
99 PX_FORCE_INLINE const AABBTreeBounds& getCurrentAABBTreeBounds() const { return mWorldBoxes; }
100
101 void updateAndInflateBounds(const PrunerHandle* handles, const PxU32* boundsIndices, const PxBounds3* newBounds, const PxTransform32* newTransforms, PxU32 count, float epsilon);
102 void preallocate(PxU32 entries);
103// protected:
104
107
111 PxTransform* mTransforms;
112 const TransformCacheMode mTransformCacheMode;
113// private:
114 PoolIndex* mHandleToIndex;
115 PrunerHandle* mIndexToHandle;
116
117 // this is the head of a list of holes formed in mHandleToIndex by removed handles
118 // the rest of the list is stored in holes in mHandleToIndex (in place)
119 PrunerHandle mFirstRecycledHandle;
120
121 PxU64 mContextID;
122
123 bool resize(PxU32 newCapacity);
124 };
125}
126
127}
128
129#endif
Definition GuAABBTreeBounds.h:39
Definition GuPruningPool.h:55
PxU32 mNbObjects
Current number of objects.
Definition GuPruningPool.h:105
PxU32 mMaxNbObjects
Max. number of objects (capacity for mWorldBoxes, mObjects)
Definition GuPruningPool.h:106
AABBTreeBounds mWorldBoxes
List of world boxes, stores mNbObjects, capacity=mMaxNbObjects.
Definition GuPruningPool.h:109
PrunerPayload * mObjects
List of objects, stores mNbObjects, capacity=mMaxNbObjects.
Definition GuPruningPool.h:110
PrunerHandle * mIndexToHandle
Inverse map from objectIndex to PrunerHandle.
Definition GuPruningPool.h:115
PoolIndex * mHandleToIndex
Maps from PrunerHandle to internal index (payload/userData index in mObjects)
Definition GuPruningPool.h:114
Class representing 3D range or axis aligned bounding box.
Definition PxBounds3.h:58
class representing a rigid euclidean transform as a quaternion and a vector
Definition PxTransform.h:49
Definition PxUserAllocated.h:43
3 Element vector class.
Definition PxVec3.h:50
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Definition GuPrunerPayload.h:55
Definition GuPrunerPayload.h:63
Definition GuPrunerPayload.h:43