RavEngine
Loading...
Searching...
No Matches
PxPvdObjectModelMetaData.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_METADATA_H
28#define PX_PVD_OBJECT_MODEL_METADATA_H
29
30#include "foundation/PxAssert.h"
31#include "PxPvdObjectModelBaseTypes.h"
32#include "PxPvdBits.h"
33
34namespace physx
35{
36namespace pvdsdk
37{
38
39class PvdInputStream;
40class PvdOutputStream;
41
43{
44 NamespacedName mOwnerClassName;
45 int32_t mOwnerClassId;
46 String mName;
47 String mSemantic;
48 // The datatype this property corresponds to.
49 int32_t mDatatype;
50 // The name of the datatype
51 NamespacedName mDatatypeName;
52 // Scalar or array.
53 PropertyType::Enum mPropertyType;
54 // No other property under any class has this id, it is DB-unique.
55 int32_t mPropertyId;
56 // Offset in bytes into the object's data section where this property starts.
57 uint32_t m32BitOffset;
58 // Offset in bytes into the object's data section where this property starts.
59 uint32_t m64BitOffset;
60
61 PropertyDescription(const NamespacedName& clsName, int32_t classId, String name, String semantic, int32_t datatype,
62 const NamespacedName& datatypeName, PropertyType::Enum propType, int32_t propId,
63 uint32_t offset32, uint32_t offset64)
64 : mOwnerClassName(clsName)
65 , mOwnerClassId(classId)
66 , mName(name)
67 , mSemantic(semantic)
68 , mDatatype(datatype)
69 , mDatatypeName(datatypeName)
70 , mPropertyType(propType)
71 , mPropertyId(propId)
72 , m32BitOffset(offset32)
73 , m64BitOffset(offset64)
74 {
75 }
77 : mOwnerClassId(-1)
78 , mName("")
79 , mSemantic("")
80 , mDatatype(-1)
81 , mPropertyType(PropertyType::Unknown)
82 , mPropertyId(-1)
83 , m32BitOffset(0)
84 , m64BitOffset(0)
85
86 {
87 }
88
89 virtual ~PropertyDescription()
90 {
91 }
92};
93
95{
96 enum Enum
97 {
98 UnknownOffset,
99 VoidPtrOffset,
100 StringOffset
101 };
102};
103
105{
106 PtrOffsetType::Enum mOffsetType;
107 uint32_t mOffset;
108 PtrOffset(PtrOffsetType::Enum type, uint32_t offset) : mOffsetType(type), mOffset(offset)
109 {
110 }
111 PtrOffset() : mOffsetType(PtrOffsetType::UnknownOffset), mOffset(0)
112 {
113 }
114};
115
116inline uint32_t align(uint32_t offset, uint32_t alignment)
117{
118 uint32_t startOffset = offset;
119 uint32_t alignmentMask = ~(alignment - 1);
120 offset = (offset + alignment - 1) & alignmentMask;
121 PX_ASSERT(offset >= startOffset && (offset % alignment) == 0);
122 (void)startOffset;
123 return offset;
124}
125
127{
128 // The size of the data section of this object, padded to alignment.
129 uint32_t mByteSize;
130 // The last data member goes to here.
131 uint32_t mDataByteSize;
132 // Alignment in bytes of the data section of this object.
133 uint32_t mAlignment;
134 // the offsets of string handles in the binary value of this class
135 DataRef<PtrOffset> mPtrOffsets;
136 ClassDescriptionSizeInfo() : mByteSize(0), mDataByteSize(0), mAlignment(0)
137 {
138 }
139};
140
142{
143 NamespacedName mName;
144 // No other class has this id, it is DB-unique
145 int32_t mClassId;
146 // Only single derivation supported.
147 int32_t mBaseClass;
148 // If this class has properties that are of uniform type, then we note that.
149 // This means that when deserialization an array of these objects we can just use
150 // single function to endian convert the entire mess at once.
151 int32_t mPackedUniformWidth;
152 // If this class is composed uniformly of members of a given type
153 // Or all of its properties are composed uniformly of members of
154 // a give ntype, then this class's packed type is that type.
155 // PxTransform's packed type would be float.
156 int32_t mPackedClassType;
157 // 0: 32Bit 1: 64Bit
158 ClassDescriptionSizeInfo mSizeInfo[2];
159 // No further property additions allowed.
160 bool mLocked;
161 // True when this datatype has an array on it that needs to be
162 // separately deleted.
163 bool mRequiresDestruction;
164
165 ClassDescription(NamespacedName name, int32_t id)
166 : mName(name)
167 , mClassId(id)
168 , mBaseClass(-1)
169 , mPackedUniformWidth(-1)
170 , mPackedClassType(-1)
171 , mLocked(false)
172 , mRequiresDestruction(false)
173 {
174 }
176 : mClassId(-1), mBaseClass(-1), mPackedUniformWidth(-1), mPackedClassType(-1), mLocked(false), mRequiresDestruction(false)
177 {
178 }
179 virtual ~ClassDescription()
180 {
181 }
182
183 ClassDescriptionSizeInfo& get32BitSizeInfo()
184 {
185 return mSizeInfo[0];
186 }
187 ClassDescriptionSizeInfo& get64BitSizeInfo()
188 {
189 return mSizeInfo[1];
190 }
191 uint32_t& get32BitSize()
192 {
193 return get32BitSizeInfo().mByteSize;
194 }
195 uint32_t& get64BitSize()
196 {
197 return get64BitSizeInfo().mByteSize;
198 }
199
200 uint32_t get32BitSize() const
201 {
202 return mSizeInfo[0].mByteSize;
203 }
204 const ClassDescriptionSizeInfo& getNativeSizeInfo() const
205 {
206 return mSizeInfo[(sizeof(void*) >> 2) - 1];
207 }
208 uint32_t getNativeSize() const
209 {
210 return getNativeSizeInfo().mByteSize;
211 }
212};
213
215{
216 int32_t srcType;
217 int32_t dstType;
218 // If canMarshal != needsMarshalling we have a problem.
219 bool canMarshal;
220 bool needsMarshalling;
221 // Non null if marshalling is possible.
222 TBlockMarshaller marshaller;
223 MarshalQueryResult(int32_t _srcType = -1, int32_t _dstType = -1, bool _canMarshal = false, bool _needs = false,
224 TBlockMarshaller _m = NULL)
225 : srcType(_srcType), dstType(_dstType), canMarshal(_canMarshal), needsMarshalling(_needs), marshaller(_m)
226 {
227 }
228};
229
231{
232 PropertyDescription mProperty;
233 NamespacedName mDatatypeName;
234 // datatype of the data in the message.
235 int32_t mDatatypeId;
236 // where in the message this property starts.
237 uint32_t mMessageOffset;
238 // size of this entry object
239 uint32_t mByteSize;
240
241 // If the chain of properties doesn't have any array properties this indicates the
242 uint32_t mDestByteSize;
243
244 PropertyMessageEntry(PropertyDescription propName, NamespacedName dtypeName, int32_t dtype, uint32_t messageOff,
245 uint32_t byteSize, uint32_t destByteSize)
246 : mProperty(propName)
247 , mDatatypeName(dtypeName)
248 , mDatatypeId(dtype)
249 , mMessageOffset(messageOff)
250 , mByteSize(byteSize)
251 , mDestByteSize(destByteSize)
252 {
253 }
254 PropertyMessageEntry() : mDatatypeId(-1), mMessageOffset(0), mByteSize(0), mDestByteSize(0)
255 {
256 }
257};
258
259// Create a struct that defines a subset of the properties on an object.
261{
262 NamespacedName mClassName;
263 // No other class has this id, it is DB-unique
264 int32_t mClassId;
265 NamespacedName mMessageName;
266 int32_t mMessageId;
268 uint32_t mMessageByteSize;
269 // Offsets into the property message where const char* items are.
270 DataRef<uint32_t> mStringOffsets;
271 PropertyMessageDescription(const NamespacedName& nm, int32_t clsId, const NamespacedName& msgName, int32_t msgId,
272 uint32_t msgSize)
273 : mClassName(nm), mClassId(clsId), mMessageName(msgName), mMessageId(msgId), mMessageByteSize(msgSize)
274 {
275 }
276 PropertyMessageDescription() : mClassId(-1), mMessageId(-1), mMessageByteSize(0)
277 {
278 }
280 {
281 }
282};
283
285{
286 protected:
287 virtual ~StringTable()
288 {
289 }
290
291 public:
292 virtual uint32_t getNbStrs() = 0;
293 virtual uint32_t getStrs(const char** outStrs, uint32_t bufLen, uint32_t startIdx = 0) = 0;
294 virtual const char* registerStr(const char* str, bool& outAdded) = 0;
295 const char* registerStr(const char* str)
296 {
297 bool ignored;
298 return registerStr(str, ignored);
299 }
300 virtual StringHandle strToHandle(const char* str) = 0;
301 virtual const char* handleToStr(uint32_t hdl) = 0;
302 virtual void release() = 0;
303
304 static StringTable& create();
305};
306
307struct None
308{
309};
310
311template <typename T>
313{
314 T mValue;
315 bool mHasValue;
316
317 public:
318 Option(const T& val) : mValue(val), mHasValue(true)
319 {
320 }
321 Option(None nothing = None()) : mHasValue(false)
322 {
323 (void)nothing;
324 }
325 Option(const Option& other) : mValue(other.mValue), mHasValue(other.mHasValue)
326 {
327 }
328 Option& operator=(const Option& other)
329 {
330 mValue = other.mValue;
331 mHasValue = other.mHasValue;
332 return *this;
333 }
334 bool hasValue() const
335 {
336 return mHasValue;
337 }
338 const T& getValue() const
339 {
340 PX_ASSERT(hasValue());
341 return mValue;
342 }
343 T& getValue()
344 {
345 PX_ASSERT(hasValue());
346 return mValue;
347 }
348 operator const T&() const
349 {
350 return getValue();
351 }
352 operator T&()
353 {
354 return getValue();
355 }
356 T* operator->()
357 {
358 return &getValue();
359 }
360 const T* operator->() const
361 {
362 return &getValue();
363 }
364};
365
374{
375 protected:
377 {
378 }
379
380 public:
381 virtual ClassDescription getOrCreateClass(const NamespacedName& nm) = 0;
382 // get or create parent, lock parent. deriveFrom getOrCreatechild.
383 virtual bool deriveClass(const NamespacedName& parent, const NamespacedName& child) = 0;
384 virtual Option<ClassDescription> findClass(const NamespacedName& nm) const = 0;
385 template <typename TDataType>
386 Option<ClassDescription> findClass()
387 {
388 return findClass(getPvdNamespacedNameForType<TDataType>());
389 }
390 virtual Option<ClassDescription> getClass(int32_t classId) const = 0;
391 virtual ClassDescription* getClassPtr(int32_t classId) const = 0;
392
393 virtual Option<ClassDescription> getParentClass(int32_t classId) const = 0;
394 bool isDerivedFrom(int32_t classId, int32_t parentClass) const
395 {
396 if(classId == parentClass)
397 return true;
398 ClassDescription* p = getClassPtr(getClassPtr(classId)->mBaseClass);
399 while(p != NULL)
400 {
401 if(p->mClassId == parentClass)
402 return true;
403 p = getClassPtr(p->mBaseClass);
404 }
405 return false;
406 }
407
408 virtual void lockClass(int32_t classId) = 0;
409
410 virtual uint32_t getNbClasses() const = 0;
411 virtual uint32_t getClasses(ClassDescription* outClasses, uint32_t requestCount, uint32_t startIndex = 0) const = 0;
412
413 // Create a nested property.
414 // This way you can have obj.p.x without explicity defining the class p.
415 virtual Option<PropertyDescription> createProperty(int32_t classId, String name, String semantic, int32_t datatype,
416 PropertyType::Enum propertyType = PropertyType::Scalar) = 0;
417 Option<PropertyDescription> createProperty(NamespacedName clsId, String name, String semantic, NamespacedName dtype,
418 PropertyType::Enum propertyType = PropertyType::Scalar)
419 {
420 return createProperty(findClass(clsId)->mClassId, name, semantic, findClass(dtype)->mClassId, propertyType);
421 }
422 Option<PropertyDescription> createProperty(NamespacedName clsId, String name, NamespacedName dtype,
423 PropertyType::Enum propertyType = PropertyType::Scalar)
424 {
425 return createProperty(findClass(clsId)->mClassId, name, "", findClass(dtype)->mClassId, propertyType);
426 }
427 Option<PropertyDescription> createProperty(int32_t clsId, String name, int32_t dtype,
428 PropertyType::Enum propertyType = PropertyType::Scalar)
429 {
430 return createProperty(clsId, name, "", dtype, propertyType);
431 }
432 template <typename TDataType>
433 Option<PropertyDescription> createProperty(int32_t clsId, String name, String semantic = "",
434 PropertyType::Enum propertyType = PropertyType::Scalar)
435 {
436 return createProperty(clsId, name, semantic, getPvdNamespacedNameForType<TDataType>(), propertyType);
437 }
438 virtual Option<PropertyDescription> findProperty(const NamespacedName& cls, String prop) const = 0;
439 virtual Option<PropertyDescription> findProperty(int32_t clsId, String prop) const = 0;
440 virtual Option<PropertyDescription> getProperty(int32_t propId) const = 0;
441 virtual void setNamedPropertyValues(DataRef<NamedValue> values, int32_t propId) = 0;
442 // for enumerations and flags.
443 virtual DataRef<NamedValue> getNamedPropertyValues(int32_t propId) const = 0;
444
445 virtual uint32_t getNbProperties(int32_t classId) const = 0;
446 virtual uint32_t getProperties(int32_t classId, PropertyDescription* outBuffer, uint32_t bufCount,
447 uint32_t startIdx = 0) const = 0;
448
449 // Does one cls id differ marshalling to another and if so return the functions to do it.
450 virtual MarshalQueryResult checkMarshalling(int32_t srcClsId, int32_t dstClsId) const = 0;
451
452 // messages and classes are stored in separate maps, so a property message can have the same name as a class.
453 virtual Option<PropertyMessageDescription> createPropertyMessage(const NamespacedName& cls,
454 const NamespacedName& msgName,
456 uint32_t messageSize) = 0;
457 virtual Option<PropertyMessageDescription> findPropertyMessage(const NamespacedName& msgName) const = 0;
458 virtual Option<PropertyMessageDescription> getPropertyMessage(int32_t msgId) const = 0;
459
460 virtual uint32_t getNbPropertyMessages() const = 0;
461 virtual uint32_t getPropertyMessages(PropertyMessageDescription* msgBuf, uint32_t bufLen,
462 uint32_t startIdx = 0) const = 0;
463
464 virtual StringTable& getStringTable() const = 0;
465
466 virtual void write(PvdOutputStream& stream) const = 0;
467 void save(PvdOutputStream& stream) const
468 {
469 write(stream);
470 }
471
472 virtual void addRef() = 0;
473 virtual void release() = 0;
474
475 static uint32_t getCurrentPvdObjectModelVersion();
476 static PvdObjectModelMetaData& create();
477 static PvdObjectModelMetaData& create(PvdInputStream& stream);
478};
479}
480}
481#endif
Definition PxPvdObjectModelBaseTypes.h:345
Definition PxPvdObjectModelMetaData.h:313
Definition PxPvdByteStreams.h:52
Definition PxPvdObjectModelMetaData.h:374
Definition PxPvdByteStreams.h:87
Definition PxPvdObjectModelMetaData.h:285
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Definition PxPvdObjectModelMetaData.h:127
Definition PxPvdObjectModelMetaData.h:142
Definition PxPvdObjectModelMetaData.h:215
Definition PxPvdObjectModelBaseTypes.h:188
Definition PxPvdObjectModelMetaData.h:308
Definition PxPvdObjectModelMetaData.h:43
Definition PxPvdObjectModelMetaData.h:261
Definition PxPvdObjectModelMetaData.h:231
Definition PxPvdObjectModelMetaData.h:95
Definition PxPvdObjectModelMetaData.h:105
Definition PxPvdObjectModelBaseTypes.h:136