RavEngine
Loading...
Searching...
No Matches
PxsTransformCache.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_TRANSFORM_CACHE_H
30#define PXS_TRANSFORM_CACHE_H
31
32#include "CmIDPool.h"
33#include "foundation/PxBitMap.h"
34#include "foundation/PxTransform.h"
35#include "foundation/PxUserAllocated.h"
36#include "foundation/PxPinnedArray.h"
37
38#define PX_DEFAULT_CACHE_SIZE 512
39
40namespace physx
41{
43 {
44 enum Flags
45 {
46 eFROZEN = (1 << 0)
47 };
48 };
49
50 struct PX_ALIGN_PREFIX(16) PxsCachedTransform
51 {
52 PxTransform transform;
53 PxU32 flags;
54
55 PX_FORCE_INLINE PxU32 isFrozen() const { return flags & PxsTransformFlag::eFROZEN; }
56 }
57 PX_ALIGN_SUFFIX(16);
58
60 {
61 typedef PxU32 RefCountType;
62
63 public:
64 PxsTransformCache(PxVirtualAllocatorCallback& allocatorCallback) : mTransformCache(PxVirtualAllocator(&allocatorCallback)), mHasAnythingChanged(true)
65 {
66 /*mTransformCache.reserve(PX_DEFAULT_CACHE_SIZE);
67 mTransformCache.forceSize_Unsafe(PX_DEFAULT_CACHE_SIZE);*/
68 mUsedSize = 0;
69 }
70
71 void initEntry(PxU32 index)
72 {
73 PxU32 oldCapacity = mTransformCache.capacity();
74 if (index >= oldCapacity)
75 {
76 PxU32 newCapacity = PxNextPowerOfTwo(index);
77 mTransformCache.reserve(newCapacity);
78 mTransformCache.forceSize_Unsafe(newCapacity);
79 }
80 mUsedSize = PxMax(mUsedSize, index + 1u);
81 }
82
83 PX_FORCE_INLINE void setTransformCache(const PxTransform& transform, const PxU32 flags, const PxU32 index)
84 {
85 mTransformCache[index].transform = transform;
86 mTransformCache[index].flags = flags;
87 mHasAnythingChanged = true;
88 }
89
90 PX_FORCE_INLINE const PxsCachedTransform& getTransformCache(const PxU32 index) const
91 {
92 return mTransformCache[index];
93 }
94
95 PX_FORCE_INLINE PxsCachedTransform& getTransformCache(const PxU32 index)
96 {
97 return mTransformCache[index];
98 }
99
100 PX_FORCE_INLINE void shiftTransforms(const PxVec3& shift)
101 {
102 for (PxU32 i = 0; i < mTransformCache.capacity(); i++)
103 {
104 mTransformCache[i].transform.p += shift;
105 }
106 mHasAnythingChanged = true;
107 }
108
109 PX_FORCE_INLINE PxU32 getTotalSize() const
110 {
111 return mUsedSize;
112 }
113
114 PX_FORCE_INLINE const PxsCachedTransform* getTransforms() const
115 {
116 return mTransformCache.begin();
117 }
118
119 PX_FORCE_INLINE PxsCachedTransform* getTransforms()
120 {
121 return mTransformCache.begin();
122 }
123
124 PX_FORCE_INLINE PxPinnedArray<PxsCachedTransform>* getCachedTransformArray()
125 {
126 return &mTransformCache;
127 }
128
129 PX_FORCE_INLINE void resetChangedState() { mHasAnythingChanged = false; }
130 PX_FORCE_INLINE void setChangedState() { mHasAnythingChanged = true; }
131 PX_FORCE_INLINE bool hasChanged() const { return mHasAnythingChanged; }
132
133 private:
134 PxPinnedArray<PxsCachedTransform> mTransformCache;
135 PxU32 mUsedSize;
136 bool mHasAnythingChanged;
137 };
138}
139
140#endif
Definition PxArray.h:53
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
Definition PxAllocator.h:140
Definition PxAllocator.h:158
Definition PxsTransformCache.h:60
#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
PX_CUDA_CALLABLE PX_FORCE_INLINE T PxMax(T a, T b)
The return value is the greater of the two specified values.
Definition PxMath.h:72
Definition PxsTransformCache.h:43