RavEngine
Loading...
Searching...
No Matches
PxPvdObjectModelBaseTypes.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
27#ifndef PX_PVD_OBJECT_MODEL_BASE_TYPES_H
28#define PX_PVD_OBJECT_MODEL_BASE_TYPES_H
29
33#include "foundation/PxAssert.h"
34
35#if !PX_DOXYGEN
36namespace physx
37{
38namespace pvdsdk
39{
40#endif
41
42using namespace physx;
43
44inline const char* nonNull(const char* str)
45{
46 return str ? str : "";
47}
48// strcmp will crash if passed a null string, however,
49// so we need to make sure that doesn't happen. We do that
50// by equating NULL and the empty string, "".
51inline bool safeStrEq(const char* lhs, const char* rhs)
52{
53 return ::strcmp(nonNull(lhs), nonNull(rhs)) == 0;
54}
55
56// Does this string have useful information in it.
57inline bool isMeaningful(const char* str)
58{
59 return *(nonNull(str)) > 0;
60}
61
62inline uint32_t safeStrLen(const char* str)
63{
64 str = nonNull(str);
65 return static_cast<uint32_t>(strlen(str));
66}
67
69{
70 int32_t mInstanceId;
71
72 ObjectRef(int32_t iid = -1) : mInstanceId(iid)
73 {
74 }
75 operator int32_t() const
76 {
77 return mInstanceId;
78 }
79 bool hasValue() const
80 {
81 return mInstanceId > 0;
82 }
83};
84
86{
87 uint32_t mD0;
88 uint32_t mD1;
89 uint32_t mD2;
90 uint32_t mD3;
91 U32Array4(uint32_t d0, uint32_t d1, uint32_t d2, uint32_t d3) : mD0(d0), mD1(d1), mD2(d2), mD3(d3)
92 {
93 }
94 U32Array4() : mD0(0), mD1(0), mD2(0), mD3(0)
95 {
96 }
97};
98
99typedef bool PvdBool;
100typedef const char* String;
101typedef void* VoidPtr;
102typedef double PvdF64;
103typedef float PvdF32;
104typedef int64_t PvdI64;
105typedef uint64_t PvdU64;
106typedef int32_t PvdI32;
107typedef uint32_t PvdU32;
108typedef int16_t PvdI16;
109typedef uint16_t PvdU16;
110typedef int8_t PvdI8;
111typedef uint8_t PvdU8;
112
114{
115 uint8_t r;
116 uint8_t g;
117 uint8_t b;
118 uint8_t a;
119 PvdColor(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a = 255) : r(_r), g(_g), b(_b), a(_a)
120 {
121 }
122 PvdColor() : r(0), g(0), b(0), a(255)
123 {
124 }
125 PvdColor(uint32_t abgr)
126 {
127 uint8_t* valPtr = reinterpret_cast<uint8_t*>(&abgr);
128 r = valPtr[0];
129 g = valPtr[1];
130 b = valPtr[2];
131 a = valPtr[3];
132 }
133};
134
136{
137 uint32_t mHandle;
138 StringHandle(uint32_t val = 0) : mHandle(val)
139 {
140 }
141 operator uint32_t() const
142 {
143 return mHandle;
144 }
145};
146
147#define DECLARE_TYPES \
148DECLARE_BASE_PVD_TYPE(PvdI8) \
149DECLARE_BASE_PVD_TYPE(PvdU8) \
150DECLARE_BASE_PVD_TYPE(PvdI16) \
151DECLARE_BASE_PVD_TYPE(PvdU16) \
152DECLARE_BASE_PVD_TYPE(PvdI32) \
153DECLARE_BASE_PVD_TYPE(PvdU32) \
154DECLARE_BASE_PVD_TYPE(PvdI64) \
155DECLARE_BASE_PVD_TYPE(PvdU64) \
156DECLARE_BASE_PVD_TYPE(PvdF32) \
157DECLARE_BASE_PVD_TYPE(PvdF64) \
158DECLARE_BASE_PVD_TYPE(PvdBool) \
159DECLARE_BASE_PVD_TYPE(PvdColor) \
160DECLARE_BASE_PVD_TYPE(String) \
161DECLARE_BASE_PVD_TYPE(StringHandle) \
162DECLARE_BASE_PVD_TYPE(ObjectRef) \
163DECLARE_BASE_PVD_TYPE(VoidPtr) \
164DECLARE_BASE_PVD_TYPE(PxVec2) \
165DECLARE_BASE_PVD_TYPE(PxVec3) \
166DECLARE_BASE_PVD_TYPE(PxVec4) \
167DECLARE_BASE_PVD_TYPE(PxBounds3) \
168DECLARE_BASE_PVD_TYPE(PxQuat) \
169DECLARE_BASE_PVD_TYPE(PxTransform) \
170DECLARE_BASE_PVD_TYPE(PxMat33) \
171DECLARE_BASE_PVD_TYPE(PxMat44) \
172DECLARE_BASE_PVD_TYPE(U32Array4)
173
175{
176 enum Enum
177 {
178 None = 0,
179 InternalStart = 1,
180 InternalStop = 64,
181#define DECLARE_BASE_PVD_TYPE(type) type,
182 DECLARE_TYPES
183 Last
184#undef DECLARE_BASE_PVD_TYPE
185 };
186};
188{
189 String mNamespace;
190 String mName;
191 NamespacedName(String ns, String nm) : mNamespace(ns), mName(nm)
192 {
193 }
194 NamespacedName(String nm = "") : mNamespace(""), mName(nm)
195 {
196 }
197 bool operator==(const NamespacedName& other) const
198 {
199 return safeStrEq(mNamespace, other.mNamespace) && safeStrEq(mName, other.mName);
200 }
201};
202
204{
205 String mName;
206 uint32_t mValue;
207 NamedValue(String nm = "", uint32_t val = 0) : mName(nm), mValue(val)
208 {
209 }
210};
211
212template <typename T>
214{
215 bool compile_error;
216};
217template <PvdBaseType::Enum>
219{
220 bool compile_error;
221};
222
223// Users can extend this mapping with new datatypes.
224template <typename T>
226{
227 bool Name;
228};
229// This mapping tells you the what class id to use for the base datatypes
230//
231#define DECLARE_BASE_PVD_TYPE(type) \
232 template <> \
233 struct BaseDataTypeToTypeMap<type> \
234 { \
235 enum Enum \
236 { \
237 BaseTypeEnum = PvdBaseType::type \
238 }; \
239 }; \
240 template <> \
241 struct BaseDataTypeToTypeMap<const type&> \
242 { \
243 enum Enum \
244 { \
245 BaseTypeEnum = PvdBaseType::type \
246 }; \
247 }; \
248 template <> \
249 struct BaseTypeToDataTypeMap<PvdBaseType::type> \
250 { \
251 typedef type TDataType; \
252 }; \
253 template <> \
254 struct PvdDataTypeToNamespacedNameMap<type> \
255 { \
256 NamespacedName Name; \
257 PvdDataTypeToNamespacedNameMap<type>() : Name("physx3", #type) \
258 { \
259 } \
260 }; \
261 template <> \
262 struct PvdDataTypeToNamespacedNameMap<const type&> \
263 { \
264 NamespacedName Name; \
265 PvdDataTypeToNamespacedNameMap<const type&>() : Name("physx3", #type) \
266 { \
267 } \
268 };
269
270DECLARE_TYPES
271#undef DECLARE_BASE_PVD_TYPE
272
273template <typename TDataType>
274inline int32_t getPvdTypeForType()
275{
276 return static_cast<PvdBaseType::Enum>(BaseDataTypeToTypeMap<TDataType>::BaseTypeEnum);
277}
278template <typename TDataType>
279inline NamespacedName getPvdNamespacedNameForType()
280{
281 return PvdDataTypeToNamespacedNameMap<TDataType>().Name;
282}
283
284#define DEFINE_PVD_TYPE_NAME_MAP(type, ns, name) \
285 template <> \
286 struct PvdDataTypeToNamespacedNameMap<type> \
287 { \
288 NamespacedName Name; \
289 PvdDataTypeToNamespacedNameMap<type>() : Name(ns, name) \
290 { \
291 } \
292 };
293
294#define DEFINE_PVD_TYPE_ALIAS(newType, oldType) \
295 template <> \
296 struct PvdDataTypeToNamespacedNameMap<newType> \
297 { \
298 NamespacedName Name; \
299 PvdDataTypeToNamespacedNameMap<newType>() : Name(PvdDataTypeToNamespacedNameMap<oldType>().Name) \
300 { \
301 } \
302 };
303
304DEFINE_PVD_TYPE_ALIAS(const void*, void*)
305
307{
308 uint8_t* mBegin;
309 uint8_t* mEnd;
310 uint8_t* mCapacity; //>= stop
311 ArrayData(uint8_t* beg = NULL, uint8_t* end = NULL, uint8_t* cap = NULL) : mBegin(beg), mEnd(end), mCapacity(cap)
312 {
313 }
314 uint8_t* begin()
315 {
316 return mBegin;
317 }
318 uint8_t* end()
319 {
320 return mEnd;
321 }
322 uint32_t byteCapacity()
323 {
324 return static_cast<uint32_t>(mCapacity - mBegin);
325 }
326 uint32_t byteSize() const
327 {
328 return static_cast<uint32_t>(mEnd - mBegin);
329 } // in bytes
330 uint32_t numberOfItems(uint32_t objectByteSize)
331 {
332 if(objectByteSize)
333 return byteSize() / objectByteSize;
334 return 0;
335 }
336
337 void forgetData()
338 {
339 mBegin = mEnd = mCapacity = 0;
340 }
341};
342
343template <typename T>
345{
346 const T* mBegin;
347 const T* mEnd;
348
349 public:
350 DataRef(const T* b, uint32_t count) : mBegin(b), mEnd(b + count)
351 {
352 }
353 DataRef(const T* b = NULL, const T* e = NULL) : mBegin(b), mEnd(e)
354 {
355 }
356 DataRef(const DataRef& o) : mBegin(o.mBegin), mEnd(o.mEnd)
357 {
358 }
359 DataRef& operator=(const DataRef& o)
360 {
361 mBegin = o.mBegin;
362 mEnd = o.mEnd;
363 return *this;
364 }
365 uint32_t size() const
366 {
367 return static_cast<uint32_t>(mEnd - mBegin);
368 }
369 const T* begin() const
370 {
371 return mBegin;
372 }
373 const T* end() const
374 {
375 return mEnd;
376 }
377 const T& operator[](uint32_t idx) const
378 {
379 PX_ASSERT(idx < size());
380 return mBegin[idx];
381 }
382 const T& back() const
383 {
384 PX_ASSERT(mEnd > mBegin);
385 return *(mEnd - 1);
386 }
387};
388
390{
391 enum Enum
392 {
393 Unknown = 0,
394 Scalar,
395 Array
396 };
397};
398
399// argument to the create property message function
401{
402 String mPropertyName;
403 NamespacedName mDatatypeName;
404 // where in the message this property starts.
405 uint32_t mMessageOffset;
406 // size of this entry object
407 uint32_t mByteSize;
408
409 PropertyMessageArg(String propName, NamespacedName dtype, uint32_t msgOffset, uint32_t byteSize)
410 : mPropertyName(propName), mDatatypeName(dtype), mMessageOffset(msgOffset), mByteSize(byteSize)
411 {
412 }
413 PropertyMessageArg() : mPropertyName(""), mMessageOffset(0), mByteSize(0)
414 {
415 }
416};
417
418class PvdUserRenderer;
419DEFINE_PVD_TYPE_NAME_MAP(PvdUserRenderer, "_debugger_", "PvdUserRenderer")
420
421#if !PX_DOXYGEN
422}
423}
424#endif
425
427#endif
428
Definition PxPvdObjectModelBaseTypes.h:345
Definition PxPvdUserRenderer.h:56
uint32 uint32_t
Definition fwd.hpp:131
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Definition PxPvdObjectModelBaseTypes.h:307
Definition PxPvdObjectModelBaseTypes.h:214
Definition PxPvdObjectModelBaseTypes.h:219
Definition PxPvdObjectModelBaseTypes.h:204
Definition PxPvdObjectModelBaseTypes.h:188
Definition PxPvdObjectModelMetaData.h:308
Definition PxPvdObjectModelBaseTypes.h:69
Definition PxPvdObjectModelBaseTypes.h:401
Definition PxPvdObjectModelBaseTypes.h:390
Definition PxPvdObjectModelBaseTypes.h:175
Definition PxPvdObjectModelBaseTypes.h:114
Definition PxPvdObjectModelBaseTypes.h:226
Definition PxPvdObjectModelBaseTypes.h:136
Definition PxPvdObjectModelBaseTypes.h:86