00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef PX_PHYSICS_COMMON_NX_SERIAL_FRAMEWORK
00032 #define PX_PHYSICS_COMMON_NX_SERIAL_FRAMEWORK
00033
00038 #include "common/PxPhysXCommonConfig.h"
00039
00040 #if !PX_DOXYGEN
00041 namespace physx
00042 {
00043 #endif
00044
00045 typedef PxU16 PxType;
00046 class PxBase;
00047 class PxSerializationContext;
00048 class PxRepXSerializer;
00049 class PxSerializer;
00050 class PxPhysics;
00051
00053 #define PX_SERIAL_ALIGN 16
00054
00056 #define PX_SERIAL_FILE_ALIGN 128
00057
00059 #define PX_SERIAL_OBJECT_ID_INVALID 0
00060
00062 typedef PxU64 PxSerialObjectId;
00063
00065 #define PX_SERIAL_REF_KIND_PTR_TYPE_BIT (1u<<31)
00066
00068 #define PX_SERIAL_REF_KIND_PXBASE (0 | PX_SERIAL_REF_KIND_PTR_TYPE_BIT)
00069
00071 #define PX_SERIAL_REF_KIND_MATERIAL_IDX (1)
00072
00074 #define PX_MAKE_FOURCC(a, b, c, d) ( (a) | ((b)<<8) | ((c)<<16) | ((d)<<24) )
00075
00081 class PxProcessPxBaseCallback
00082 {
00083 public:
00084 virtual ~PxProcessPxBaseCallback() {}
00085 virtual void process(PxBase&) = 0;
00086 };
00087
00088
00099 class PxSerializationContext
00100 {
00101 public:
00102
00124 virtual void registerReference(PxBase& base, PxU32 kind, size_t reference) = 0;
00125
00129 virtual const PxCollection& getCollection() const = 0;
00130
00138 virtual void writeData(const void* data, PxU32 size) = 0;
00139
00147 virtual void alignData(PxU32 alignment = PX_SERIAL_ALIGN) = 0;
00148
00156 virtual void writeName(const char* name) = 0;
00157
00158 protected:
00159
00160 PxSerializationContext() {}
00161 virtual ~PxSerializationContext() {}
00162 };
00163
00164
00174 class PxDeserializationContext
00175 {
00176 public:
00177
00196 virtual PxBase* resolveReference(PxU32 kind, size_t reference) const = 0;
00197
00203 template<typename T>
00204 void translatePxBase(T*& base) { if (base) { base = static_cast<T*>(resolveReference(PX_SERIAL_REF_KIND_PXBASE, size_t(base))); } }
00205
00213 PX_INLINE void readName(const char*& name)
00214 {
00215 PxU32 len = *reinterpret_cast<PxU32*>(mExtraDataAddress);
00216 mExtraDataAddress += sizeof(len);
00217 name = len ? reinterpret_cast<const char*>(mExtraDataAddress) : NULL;
00218 mExtraDataAddress += len;
00219 }
00220
00228 template<typename T>
00229 PX_INLINE T* readExtraData(PxU32 count=1)
00230 {
00231 T* data = reinterpret_cast<T*>(mExtraDataAddress);
00232 mExtraDataAddress += sizeof(T)*count;
00233 return data;
00234 }
00235
00243 template<typename T, PxU32 alignment>
00244 PX_INLINE T* readExtraData(PxU32 count=1)
00245 {
00246 alignExtraData(alignment);
00247 return readExtraData<T>(count);
00248 }
00249
00257 PX_INLINE void alignExtraData(PxU32 alignment = PX_SERIAL_ALIGN)
00258 {
00259 size_t addr = reinterpret_cast<size_t>(mExtraDataAddress);
00260 addr = (addr+alignment-1)&~size_t(alignment-1);
00261 mExtraDataAddress = reinterpret_cast<PxU8*>(addr);
00262 }
00263
00264
00269 virtual PxU32 getPhysXVersion() const = 0;
00270
00271 protected:
00272
00273 PxDeserializationContext() {}
00274 virtual ~PxDeserializationContext() {}
00275
00276 PxU8* mExtraDataAddress;
00277 };
00278
00285 typedef void (*PxBinaryMetaDataCallback)(PxOutputStream& stream);
00286
00297 class PxSerializationRegistry
00298 {
00299 public:
00300
00301
00305
00314 virtual void registerSerializer(PxType type, PxSerializer& serializer) = 0;
00315
00324 virtual PxSerializer* unregisterSerializer(PxType type) = 0;
00325
00335 virtual void registerBinaryMetaDataCallback(PxBinaryMetaDataCallback callback) = 0;
00336
00345 virtual const PxSerializer* getSerializer(PxType type) const = 0;
00346
00348
00349
00353
00362 virtual void registerRepXSerializer(PxType type, PxRepXSerializer& serializer) = 0;
00363
00372 virtual PxRepXSerializer* unregisterRepXSerializer(PxType type) = 0;
00373
00382 virtual PxRepXSerializer* getRepXSerializer(const char* typeName) const = 0;
00383
00385
00386
00395 virtual void release() = 0;
00396
00397 protected:
00398 virtual ~PxSerializationRegistry(){}
00399 };
00400
00401 #if !PX_DOXYGEN
00402 }
00403 #endif
00404
00406 #endif