PxSerialFramework.h
Go to the documentation of this file.
1 //
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions
4 // are met:
5 // * Redistributions of source code must retain the above copyright
6 // notice, this list of conditions and the following disclaimer.
7 // * Redistributions in binary form must reproduce the above copyright
8 // notice, this list of conditions and the following disclaimer in the
9 // documentation and/or other materials provided with the distribution.
10 // * Neither the name of NVIDIA CORPORATION nor the names of its
11 // contributors may be used to endorse or promote products derived
12 // from this software without specific prior written permission.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
15 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 //
26 // Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved.
27 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
28 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
29 
30 
31 #ifndef PX_PHYSICS_COMMON_NX_SERIAL_FRAMEWORK
32 #define PX_PHYSICS_COMMON_NX_SERIAL_FRAMEWORK
33 
39 
40 #if !PX_DOXYGEN
41 namespace physx
42 {
43 #endif
44 
45 typedef PxU16 PxType;
46 class PxBase;
48 class PxRepXSerializer;
49 class PxSerializer;
50 class PxPhysics;
51 
53 #define PX_SERIAL_ALIGN 16
54 
56 #define PX_SERIAL_FILE_ALIGN 128
57 
59 #define PX_SERIAL_OBJECT_ID_INVALID 0
60 
63 
65 #define PX_SERIAL_REF_KIND_PTR_TYPE_BIT (1u<<31)
66 
68 #define PX_SERIAL_REF_KIND_PXBASE (0 | PX_SERIAL_REF_KIND_PTR_TYPE_BIT)
69 
71 #define PX_SERIAL_REF_KIND_MATERIAL_IDX (1)
72 
74 #define PX_MAKE_FOURCC(a, b, c, d) ( (a) | ((b)<<8) | ((c)<<16) | ((d)<<24) )
75 
82 {
83 public:
85  virtual void process(PxBase&) = 0;
86 };
87 
88 
100 {
101 public:
102 
124  virtual void registerReference(PxBase& base, PxU32 kind, size_t reference) = 0;
125 
129  virtual const PxCollection& getCollection() const = 0;
130 
138  virtual void writeData(const void* data, PxU32 size) = 0;
139 
147  virtual void alignData(PxU32 alignment = PX_SERIAL_ALIGN) = 0;
148 
156  virtual void writeName(const char* name) = 0;
157 
158 protected:
159 
162 };
163 
164 
175 {
176 public:
177 
196  virtual PxBase* resolveReference(PxU32 kind, size_t reference) const = 0;
197 
203  template<typename T>
204  void translatePxBase(T*& base) { if (base) { base = static_cast<T*>(resolveReference(PX_SERIAL_REF_KIND_PXBASE, size_t(base))); } }
205 
213  PX_INLINE void readName(const char*& name)
214  {
215  PxU32 len = *reinterpret_cast<PxU32*>(mExtraDataAddress);
216  mExtraDataAddress += sizeof(len);
217  name = len ? reinterpret_cast<const char*>(mExtraDataAddress) : NULL;
218  mExtraDataAddress += len;
219  }
220 
228  template<typename T>
230  {
231  T* data = reinterpret_cast<T*>(mExtraDataAddress);
232  mExtraDataAddress += sizeof(T)*count;
233  return data;
234  }
235 
243  template<typename T, PxU32 alignment>
245  {
246  alignExtraData(alignment);
247  return readExtraData<T>(count);
248  }
249 
258  {
259  size_t addr = reinterpret_cast<size_t>(mExtraDataAddress);
260  addr = (addr+alignment-1)&~size_t(alignment-1);
261  mExtraDataAddress = reinterpret_cast<PxU8*>(addr);
262  }
263 
264 
269  virtual PxU32 getPhysXVersion() const = 0;
270 
271 protected:
272 
275 
277 };
278 
285 typedef void (*PxBinaryMetaDataCallback)(PxOutputStream& stream);
286 
298 {
299 public:
300  /************************************************************************************************/
301 
305 
314  virtual void registerSerializer(PxType type, PxSerializer& serializer) = 0;
315 
324  virtual PxSerializer* unregisterSerializer(PxType type) = 0;
325 
335  virtual void registerBinaryMetaDataCallback(PxBinaryMetaDataCallback callback) = 0;
336 
345  virtual const PxSerializer* getSerializer(PxType type) const = 0;
346 
348  /************************************************************************************************/
349 
353 
362  virtual void registerRepXSerializer(PxType type, PxRepXSerializer& serializer) = 0;
363 
372  virtual PxRepXSerializer* unregisterRepXSerializer(PxType type) = 0;
373 
382  virtual PxRepXSerializer* getRepXSerializer(const char* typeName) const = 0;
383 
385  /************************************************************************************************/
386 
395  virtual void release() = 0;
396 
397 protected:
399 };
400 
401 #if !PX_DOXYGEN
402 } // namespace physx
403 #endif
404 
406 #endif
Definition: GuContactBuffer.h:37
Class serving as a registry for XML (RepX) and binary serializable types.
Definition: PxSerialFramework.h:297
PX_INLINE T * readExtraData(PxU32 count=1)
Function to read extra data during deserialization optionally aligning the extra data stream before r...
Definition: PxSerialFramework.h:244
PX_INLINE void readName(const char *&name)
Helper function to read a name from the extra data during deserialization.
Definition: PxSerialFramework.h:213
#define PX_SERIAL_REF_KIND_PXBASE
Reference kind value for PxBase objects.
Definition: PxSerialFramework.h:68
PxU16 PxType
Definition: PxSerialFramework.h:45
PX_INLINE void alignExtraData(PxU32 alignment=PX_SERIAL_ALIGN)
Function to align the extra data stream to a power of 2 alignment.
Definition: PxSerialFramework.h:257
Output stream class for I/O.
Definition: PxIO.h:114
uint64_t PxU64
Definition: PxSimpleTypes.h:69
#define PX_SERIAL_ALIGN
Default serialization alignment.
Definition: PxSerialFramework.h:53
Serialization interface class.
Definition: PxSerializer.h:61
Serializer interface for RepX (Xml) serialization.
Definition: PxRepXSerializer.h:66
PxU64 PxSerialObjectId
ID type for PxBase objects in a PxCollection.
Definition: PxSerialFramework.h:62
virtual ~PxProcessPxBaseCallback()
Definition: PxSerialFramework.h:84
PxSerializationContext()
Definition: PxSerialFramework.h:160
PxDeserializationContext()
Definition: PxSerialFramework.h:273
uint8_t PxU8
Definition: PxSimpleTypes.h:75
PxU8 * mExtraDataAddress
Definition: PxSerialFramework.h:276
virtual ~PxDeserializationContext()
Definition: PxSerialFramework.h:274
void translatePxBase(T *&base)
Helper function to update PxBase pointer on deserialization.
Definition: PxSerialFramework.h:204
Binary deserialization context class.
Definition: PxSerialFramework.h:174
Collection class for serialization.
Definition: PxCollection.h:105
virtual ~PxSerializationRegistry()
Definition: PxSerialFramework.h:398
Abstract singleton factory class used for instancing objects in the Physics SDK.
Definition: PxPhysics.h:71
uint16_t PxU16
Definition: PxSimpleTypes.h:73
uint32_t PxU32
Definition: Px.h:48
PX_INLINE T * readExtraData(PxU32 count=1)
Function to read extra data during deserialization.
Definition: PxSerialFramework.h:229
Base class for objects that can be members of a PxCollection.
Definition: PxBase.h:73
virtual ~PxSerializationContext()
Definition: PxSerialFramework.h:161
Binary serialization context class.
Definition: PxSerialFramework.h:99
#define PX_INLINE
Definition: PxPreprocessor.h:349
Callback class used to process PxBase objects.
Definition: PxSerialFramework.h:81
void(* PxBinaryMetaDataCallback)(PxOutputStream &stream)
Callback type for exporting binary meta data for a serializable type.
Definition: PxSerialFramework.h:285