PxSerialFramework.h

Go to the documentation of this file.
00001 //
00002 // Redistribution and use in source and binary forms, with or without
00003 // modification, are permitted provided that the following conditions
00004 // are met:
00005 //  * Redistributions of source code must retain the above copyright
00006 //    notice, this list of conditions and the following disclaimer.
00007 //  * Redistributions in binary form must reproduce the above copyright
00008 //    notice, this list of conditions and the following disclaimer in the
00009 //    documentation and/or other materials provided with the distribution.
00010 //  * Neither the name of NVIDIA CORPORATION nor the names of its
00011 //    contributors may be used to endorse or promote products derived
00012 //    from this software without specific prior written permission.
00013 //
00014 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
00015 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00016 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00017 // PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
00018 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00019 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00020 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00021 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00022 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00023 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00024 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025 //
00026 // Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved.
00027 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
00028 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.  
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 } // namespace physx
00403 #endif
00404 
00406 #endif


Copyright © 2008-2018 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com