PxSerialFramework.h
Go to the documentation of this file.00001 // This code contains NVIDIA Confidential Information and is disclosed to you 00002 // under a form of NVIDIA software license agreement provided separately to you. 00003 // 00004 // Notice 00005 // NVIDIA Corporation and its licensors retain all intellectual property and 00006 // proprietary rights in and to this software and related documentation and 00007 // any modifications thereto. Any use, reproduction, disclosure, or 00008 // distribution of this software and related documentation without an express 00009 // license agreement from NVIDIA Corporation is strictly prohibited. 00010 // 00011 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES 00012 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO 00013 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, 00014 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. 00015 // 00016 // Information and code furnished is believed to be accurate and reliable. 00017 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such 00018 // information or for any infringement of patents or other rights of third parties that may 00019 // result from its use. No license is granted by implication or otherwise under any patent 00020 // or patent rights of NVIDIA Corporation. Details are subject to change without notice. 00021 // This code supersedes and replaces all information previously supplied. 00022 // NVIDIA Corporation products are not authorized for use as critical 00023 // components in life support devices or systems without express written approval of 00024 // NVIDIA Corporation. 00025 // 00026 // Copyright (c) 2008-2012 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 //#ifdef REMOVED 00032 00033 #ifndef PX_PHYSICS_COMMON_NX_SERIAL_FRAMEWORK 00034 #define PX_PHYSICS_COMMON_NX_SERIAL_FRAMEWORK 00035 00040 #include "common/PxPhysXCommon.h" 00041 #include "common/PxTypeInfo.h" 00042 #include "common/PxFields.h" 00043 #include "common/PxFieldDescriptor.h" 00044 #include "foundation/PxFlags.h" 00045 00046 00047 #ifndef PX_DOXYGEN 00048 namespace physx 00049 { 00050 #endif 00051 00052 typedef PxU16 PxType; 00053 class PxSerializable; 00054 class PxOutputStream; 00055 class PxSerialStream; 00056 00058 #define PX_SERIAL_FILE_ALIGN 128 00059 00061 struct PxSerialOrder 00062 { 00063 enum Enum 00064 { 00065 eCONVEX = 20, 00066 eTRIMESH = 21, 00067 eHEIGHTFIELD = 22, 00068 eDEFMESH = 23, 00069 eCLOTHMESH = 24, 00070 eMATERIAL = 50, 00071 eSHAPE = 80, 00072 eSTATIC = 81, 00073 eDYNAMIC = 82, 00074 eDEFAULT = 100, 00075 eARTICULATION = 120, 00076 eJOINT = 150, 00077 eCONSTRAINT = 200, 00078 eAGGREGATE = 300, 00079 }; 00080 }; 00081 00082 typedef PxU64 PxSerialObjectRef; 00083 00084 struct PxSerialObjectAndRef 00085 { 00086 PxSerializable* serializable; 00087 PxSerialObjectRef ref; 00088 }; 00089 00098 class PX_PHYSX_COMMON_API PxRefResolver 00099 { 00100 public: 00101 virtual ~PxRefResolver() {} 00102 00111 virtual void* newAddress(void* oldAddress) const = 0; 00112 00121 virtual void setNewAddress(void* oldAddress, void* newAddress) = 0; 00122 00130 virtual void setStringTable(const char* stringTable) = 0; 00131 00140 virtual const char* resolveName(const char* name) = 0; 00141 }; 00142 00151 class PX_PHYSX_COMMON_API PxUserReferences 00152 { 00153 public: 00154 virtual ~PxUserReferences() {} 00155 00156 00162 PX_DEPRECATED PX_INLINE PxSerializable* getObjectFromID(PxSerialObjectRef ref) const { return getObjectFromRef(ref); } 00163 00172 PX_DEPRECATED PX_INLINE void setUserData(PxSerializable* object, PxSerialObjectRef ref) { setObjectRef(*object, ref); } 00173 00174 00187 virtual PxSerializable* getObjectFromRef(PxSerialObjectRef ref) const = 0; 00188 00205 virtual bool setObjectRef(PxSerializable& object, PxSerialObjectRef ref) = 0; 00206 00207 00219 virtual bool objectIsReferenced(PxSerializable& object) const = 0; 00220 00221 00229 virtual PxU32 getNbObjectRefs() const = 0; 00230 00231 00242 virtual PxU32 getObjectRefs(PxSerialObjectAndRef* buffer, PxU32 bufSize) const = 0; 00243 00244 00251 virtual void release() = 0; 00252 }; 00253 00254 struct PxSerialFlag 00255 { 00256 enum Enum 00257 { 00258 eOWNS_MEMORY = (1<<0), 00259 // eDISABLED = (1<<1), 00260 eDISABLE_AUTO_RESOLVE = (1<<1), 00261 eDISABLE_FIELDS = (1<<2), 00262 eIN_SCENE = (1<<3), 00263 }; 00264 }; 00265 00266 00267 #if (defined(PX_WINDOWS) || defined(PX_WIN8ARM)) 00269 template class PX_PHYSX_COMMON_API PxFlags<PxSerialFlag::Enum, PxU16>; // needed for dll export 00271 #endif 00272 00273 typedef PxFlags<PxSerialFlag::Enum, PxU16> PxSerialFlags; 00274 PX_FLAGS_OPERATORS(PxSerialFlag::Enum, PxU16); 00275 00276 00277 typedef PxSerializable* (*PxClassCreationCallback)(char*& address, PxRefResolver& v); 00278 00279 00326 class PxCollection 00327 { 00328 friend class PxSerializable; 00329 virtual void addUnique(PxSerializable&) = 0; 00330 00331 public: 00332 PxCollection() {} 00333 virtual ~PxCollection() {} 00334 00342 PX_DEPRECATED PX_INLINE void setUserData(PxSerializable& object, PxSerialObjectRef ref) { setObjectRef(object, ref); } 00343 00344 00360 virtual void serialize(PxOutputStream& stream, bool exportNames=false) = 0; 00361 00362 00382 virtual bool deserialize(void* buffer128, PxUserReferences* newReferences, const PxUserReferences* externalReferences) = 0; 00383 00396 virtual bool setObjectRef(PxSerializable& object, PxSerialObjectRef ref) = 0; 00397 00398 00405 virtual PxUserReferences* getObjectRefs() const = 0; 00406 00407 00421 virtual bool addExternalRef(PxSerializable& object, PxSerialObjectRef ref) = 0; 00422 00434 virtual PxUserReferences* getExternalRefs() const = 0; 00435 00436 00441 virtual PxU32 getNbObjects() const = 0; 00442 00443 00452 virtual PxSerializable* getObject(PxU32 index) const = 0; 00453 00463 virtual void release() = 0; 00464 }; 00465 00466 class PxNameManager 00467 { 00468 public: 00469 virtual ~PxNameManager() {} 00470 virtual void registerName(const char**) = 0; 00471 }; 00472 00473 class PxPtrManager 00474 { 00475 public: 00476 virtual ~PxPtrManager() {} 00477 virtual void registerPtr(void*) = 0; 00478 }; 00479 00485 class PxSerializable 00486 { 00487 public: 00488 00494 virtual const char* getConcreteTypeName() const { return NULL; } 00495 00496 /* brief dynamic casts a pointer to a pointer to the given type 00497 \return a pointer to the given type, or NULL 00498 */ 00499 00500 template<class T> T* is() { return typeMatch<T>() ? static_cast<T*>(this) : NULL; } 00501 00502 /* brief dynamic casts a pointer-to-const to a pointer to the given type 00503 \return a pointer to the given type, or NULL 00504 */ 00505 00506 template<class T> const T* is() const { return typeMatch<T>() ? static_cast<const T*>(this) : NULL; } 00507 00508 00515 PX_INLINE PxType getConcreteType() const { return mConcreteType; } 00516 00517 00518 virtual PxU32 getOrder() const { return PxSerialOrder::eDEFAULT; } 00519 00527 virtual void collectForExport(PxCollection& c) { c.addUnique(*this); } 00528 00529 virtual bool getFields(PxSerialStream&, PxU32) const { return true; } 00530 virtual bool getFields(PxSerialStream&, PxField::Enum) const { return true; } 00531 virtual bool getFields(PxSerialStream&) const { return true; } 00532 virtual const PxFieldDescriptor* getFieldDescriptor(const char*) const { return NULL; } 00533 00534 virtual PxU32 getObjectSize() const = 0; 00535 00536 virtual void exportExtraData(PxSerialStream&) { } 00537 virtual char* importExtraData(char* address, PxU32&) { return address; } 00538 virtual bool resolvePointers(PxRefResolver&, void*) { return true; } 00539 00540 virtual void registerNameForExport(PxNameManager&) { } 00541 virtual void registerPtrsForExport(PxPtrManager& manager) { manager.registerPtr(this); } 00542 00543 virtual void disableInternalCaching(bool) {} 00544 00545 PX_INLINE void setSerialFlag(PxSerialFlag::Enum flag, bool value) { mSerialFlags = value ? mSerialFlags|flag : mSerialFlags&~flag; } 00546 PX_INLINE void setSerialFlags(PxSerialFlags inFlags ) { mSerialFlags = inFlags; } 00547 PX_INLINE PxSerialFlags getSerialFlags() const { return mSerialFlags; } 00548 00549 static void getMetaData(PxSerialStream& stream); 00550 virtual ~PxSerializable() {} 00551 00552 protected: 00553 PxSerializable(PxRefResolver& v) 00554 { 00555 mSerialFlags &= ~PxSerialFlag::eOWNS_MEMORY; 00556 PX_UNUSED(v); 00557 } 00558 PxSerializable() : mConcreteType(PxConcreteType::eUNDEFINED), mSerialFlags(PxSerialFlag::eOWNS_MEMORY) 00559 { 00560 } 00561 00562 00563 PX_INLINE void setSerialType(PxType t) { mConcreteType = t; } 00564 00565 template<class T> bool typeMatch() const 00566 { 00567 return PxU32(PxTypeInfo<T>::eFastTypeId)!=PxU32(PxConcreteType::eUNDEFINED) ? PxU32(getConcreteType()) == PxU32(PxTypeInfo<T>::eFastTypeId) 00568 : isKindOf(PxTypeInfo<T>::name()); 00569 } 00570 00571 00572 virtual bool isKindOf(const char* superClass) const { return !strcmp(superClass, "PxSerializable"); } 00573 00574 00575 00576 private: 00577 PxType mConcreteType; // Some kind of class identifier. Could use a string = class name 00578 PxSerialFlags mSerialFlags; // Serialization flags 00579 }; 00580 00581 00582 #ifndef PX_DOXYGEN 00583 } // namespace physx 00584 #endif 00585 00587 #endif
Copyright © 2008-2012 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com