RavEngine
Loading...
Searching...
No Matches
PxCoreUtilityTypes.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 PX_CORE_UTILITY_TYPES_H
30#define PX_CORE_UTILITY_TYPES_H
35#include "foundation/PxAssert.h"
36#include "foundation/PxMemory.h"
37
38#if !PX_DOXYGEN
39namespace physx
40{
41#endif
42
43
45{
51 PxU32 stride;
52 const void* data;
53
54 PxStridedData() : stride( 0 ), data( NULL ) {}
55
56 template<typename TDataType>
57 PX_INLINE const TDataType& at( PxU32 idx ) const
58 {
59 PxU32 theStride( stride );
60 if ( theStride == 0 )
61 theStride = sizeof( TDataType );
62 PxU32 offset( theStride * idx );
63 return *(reinterpret_cast<const TDataType*>( reinterpret_cast< const PxU8* >( data ) + offset ));
64 }
65};
66
67template<typename TDataType>
69{
70 PxU32 stride;
71 const TDataType* data;
72
74 : stride( 0 )
75 , data( NULL )
76 {
77 }
78
79 PxTypedStridedData(const TDataType* data_, PxU32 stride_ = 0)
80 : stride(stride_)
81 , data(data_)
82 {
83 }
84
85 PX_INLINE const TDataType& at(PxU32 idx) const
86 {
87 PxU32 theStride(stride);
88 if (theStride == 0)
89 theStride = sizeof(TDataType);
90 PxU32 offset(theStride * idx);
91 return *(reinterpret_cast<const TDataType*>(reinterpret_cast<const PxU8*>(data) + offset));
92 }
93};
94
96{
97 PxU32 count;
98 PxBoundedData() : count( 0 ) {}
99};
100
101template<PxU8 TNumBytes>
103{
104 PxU8 mPadding[TNumBytes];
105 PxPadding()
106 {
107 for ( PxU8 idx =0; idx < TNumBytes; ++idx )
108 mPadding[idx] = 0;
109 }
110};
111
112template <PxU32 NB_ELEMENTS> class PxFixedSizeLookupTable
113{
114//= ATTENTION! =====================================================================================
115// Changing the data layout of this class breaks the binary serialization format. See comments for
116// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
117// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
118// accordingly.
119//==================================================================================================
120public:
121
123 : mNbDataPairs(0)
124 {
125 }
126
128
129 PxFixedSizeLookupTable(const PxReal* dataPairs, const PxU32 numDataPairs)
130 {
131 PxMemCopy(mDataPairs,dataPairs,sizeof(PxReal)*2*numDataPairs);
132 mNbDataPairs=numDataPairs;
133 }
134
136 {
137 PxMemCopy(mDataPairs,src.mDataPairs,sizeof(PxReal)*2*src.mNbDataPairs);
138 mNbDataPairs=src.mNbDataPairs;
139 }
140
142 {
143 }
144
146 {
147 PxMemCopy(mDataPairs,src.mDataPairs,sizeof(PxReal)*2*src.mNbDataPairs);
148 mNbDataPairs=src.mNbDataPairs;
149 return *this;
150 }
151
152 PX_FORCE_INLINE void addPair(const PxReal x, const PxReal y)
153 {
154 PX_ASSERT(mNbDataPairs<NB_ELEMENTS);
155 mDataPairs[2*mNbDataPairs+0]=x;
156 mDataPairs[2*mNbDataPairs+1]=y;
157 mNbDataPairs++;
158 }
159
160 PX_FORCE_INLINE PxReal getYVal(const PxReal x) const
161 {
162 if(0==mNbDataPairs)
163 {
164 PX_ASSERT(false);
165 return 0;
166 }
167
168 if(1==mNbDataPairs || x<getX(0))
169 {
170 return getY(0);
171 }
172
173 PxReal x0=getX(0);
174 PxReal y0=getY(0);
175
176 for(PxU32 i=1;i<mNbDataPairs;i++)
177 {
178 const PxReal x1=getX(i);
179 const PxReal y1=getY(i);
180
181 if((x>=x0)&&(x<x1))
182 {
183 return (y0+(y1-y0)*(x-x0)/(x1-x0));
184 }
185
186 x0=x1;
187 y0=y1;
188 }
189
190 PX_ASSERT(x>=getX(mNbDataPairs-1));
191 return getY(mNbDataPairs-1);
192 }
193
194 PxU32 getNbDataPairs() const {return mNbDataPairs;}
195
196 void clear()
197 {
198 PxMemSet(mDataPairs, 0, NB_ELEMENTS*2*sizeof(PxReal));
199 mNbDataPairs = 0;
200 }
201
202 PX_FORCE_INLINE PxReal getX(const PxU32 i) const
203 {
204 return mDataPairs[2*i];
205 }
206 PX_FORCE_INLINE PxReal getY(const PxU32 i) const
207 {
208 return mDataPairs[2*i+1];
209 }
210
211 PxReal mDataPairs[2*NB_ELEMENTS];
212 PxU32 mNbDataPairs;
213 PxU32 mPad[3];
214
215
216};
217
218#if !PX_DOXYGEN
219} // namespace physx
220#endif
221
223#endif
Definition PxCoreUtilityTypes.h:113
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_INLINE
Definition PxPreprocessor.h:320
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PX_FORCE_INLINE void * PxMemSet(void *dest, PxI32 c, PxU32 count)
Sets the bytes of the provided buffer to the specified value.
Definition PxMemory.h:67
PX_FORCE_INLINE void * PxMemCopy(void *dest, const void *src, PxU32 count)
Copies the bytes of one memory block to another. The memory blocks must not overlap.
Definition PxMemory.h:83
PxEMPTY
Definition Px.h:87
Definition PxCoreUtilityTypes.h:96
Definition PxCoreUtilityTypes.h:103
Definition PxCoreUtilityTypes.h:45
PxU32 stride
The offset in bytes between consecutive samples in the data.
Definition PxCoreUtilityTypes.h:51
Definition PxCoreUtilityTypes.h:69