Changeset View
Changeset View
Standalone View
Standalone View
extern/bullet2/src/LinearMath/btSerializer.h
| Show All 10 Lines | |||||
| 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. | 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. | ||||
| 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. | 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. | ||||
| 3. This notice may not be removed or altered from any source distribution. | 3. This notice may not be removed or altered from any source distribution. | ||||
| */ | */ | ||||
| #ifndef BT_SERIALIZER_H | #ifndef BT_SERIALIZER_H | ||||
| #define BT_SERIALIZER_H | #define BT_SERIALIZER_H | ||||
| #include "btScalar.h" // has definitions like SIMD_FORCE_INLINE | #include "btScalar.h" // has definitions like SIMD_FORCE_INLINE | ||||
| #include "btHashMap.h" | #include "btHashMap.h" | ||||
| #if !defined( __CELLOS_LV2__) && !defined(__MWERKS__) | #if !defined(__CELLOS_LV2__) && !defined(__MWERKS__) | ||||
| #include <memory.h> | #include <memory.h> | ||||
| #endif | #endif | ||||
| #include <string.h> | #include <string.h> | ||||
| ///only the 32bit versions for now | |||||
| extern char sBulletDNAstr[]; | extern char sBulletDNAstr[]; | ||||
| extern int sBulletDNAlen; | extern int sBulletDNAlen; | ||||
| extern char sBulletDNAstr64[]; | extern char sBulletDNAstr64[]; | ||||
| extern int sBulletDNAlen64; | extern int sBulletDNAlen64; | ||||
| SIMD_FORCE_INLINE int btStrLen(const char* str) | SIMD_FORCE_INLINE int btStrLen(const char* str) | ||||
| { | { | ||||
| if (!str) | if (!str) | ||||
| return(0); | return (0); | ||||
| int len = 0; | int len = 0; | ||||
| while (*str != 0) | while (*str != 0) | ||||
| { | { | ||||
| str++; | str++; | ||||
| len++; | len++; | ||||
| } | } | ||||
| return len; | return len; | ||||
| } | } | ||||
| class btChunk | class btChunk | ||||
| { | { | ||||
| public: | public: | ||||
| int m_chunkCode; | int m_chunkCode; | ||||
| int m_length; | int m_length; | ||||
| void *m_oldPtr; | void* m_oldPtr; | ||||
| int m_dna_nr; | int m_dna_nr; | ||||
| int m_number; | int m_number; | ||||
| }; | }; | ||||
| enum btSerializationFlags | enum btSerializationFlags | ||||
| { | { | ||||
| BT_SERIALIZE_NO_BVH = 1, | BT_SERIALIZE_NO_BVH = 1, | ||||
| BT_SERIALIZE_NO_TRIANGLEINFOMAP = 2, | BT_SERIALIZE_NO_TRIANGLEINFOMAP = 2, | ||||
| BT_SERIALIZE_NO_DUPLICATE_ASSERT = 4 | BT_SERIALIZE_NO_DUPLICATE_ASSERT = 4, | ||||
| BT_SERIALIZE_CONTACT_MANIFOLDS = 8, | |||||
| }; | }; | ||||
| class btSerializer | class btSerializer | ||||
| { | { | ||||
| public: | public: | ||||
| virtual ~btSerializer() {} | virtual ~btSerializer() {} | ||||
| virtual const unsigned char* getBufferPointer() const = 0; | virtual const unsigned char* getBufferPointer() const = 0; | ||||
| virtual int getCurrentBufferSize() const = 0; | virtual int getCurrentBufferSize() const = 0; | ||||
| virtual btChunk* allocate(size_t size, int numElements) = 0; | virtual btChunk* allocate(size_t size, int numElements) = 0; | ||||
| virtual void finalizeChunk(btChunk* chunk, const char* structType, int chunkCode,void* oldPtr)= 0; | virtual void finalizeChunk(btChunk* chunk, const char* structType, int chunkCode, void* oldPtr) = 0; | ||||
| virtual void* findPointer(void* oldPtr) = 0; | virtual void* findPointer(void* oldPtr) = 0; | ||||
| virtual void* getUniquePointer(void*oldPtr) = 0; | virtual void* getUniquePointer(void* oldPtr) = 0; | ||||
| virtual void startSerialization() = 0; | virtual void startSerialization() = 0; | ||||
| virtual void finishSerialization() = 0; | virtual void finishSerialization() = 0; | ||||
| virtual const char* findNameForPointer(const void* ptr) const = 0; | virtual const char* findNameForPointer(const void* ptr) const = 0; | ||||
| virtual void registerNameForPointer(const void* ptr, const char* name) = 0; | virtual void registerNameForPointer(const void* ptr, const char* name) = 0; | ||||
| virtual void serializeName(const char* ptr) = 0; | virtual void serializeName(const char* ptr) = 0; | ||||
| virtual int getSerializationFlags() const = 0; | virtual int getSerializationFlags() const = 0; | ||||
| virtual void setSerializationFlags(int flags) = 0; | virtual void setSerializationFlags(int flags) = 0; | ||||
| virtual int getNumChunks() const = 0; | virtual int getNumChunks() const = 0; | ||||
| virtual const btChunk* getChunk(int chunkIndex) const = 0; | virtual const btChunk* getChunk(int chunkIndex) const = 0; | ||||
| }; | }; | ||||
| #define BT_HEADER_LENGTH 12 | #define BT_HEADER_LENGTH 12 | ||||
| #if defined(__sgi) || defined (__sparc) || defined (__sparc__) || defined (__PPC__) || defined (__ppc__) || defined (__BIG_ENDIAN__) | #if defined(__sgi) || defined(__sparc) || defined(__sparc__) || defined(__PPC__) || defined(__ppc__) || defined(__BIG_ENDIAN__) | ||||
| # define BT_MAKE_ID(a,b,c,d) ( (int)(a)<<24 | (int)(b)<<16 | (c)<<8 | (d) ) | #define BT_MAKE_ID(a, b, c, d) ((int)(a) << 24 | (int)(b) << 16 | (c) << 8 | (d)) | ||||
| #else | #else | ||||
| # define BT_MAKE_ID(a,b,c,d) ( (int)(d)<<24 | (int)(c)<<16 | (b)<<8 | (a) ) | #define BT_MAKE_ID(a, b, c, d) ((int)(d) << 24 | (int)(c) << 16 | (b) << 8 | (a)) | ||||
| #endif | #endif | ||||
| #define BT_MULTIBODY_CODE BT_MAKE_ID('M','B','D','Y') | #define BT_MULTIBODY_CODE BT_MAKE_ID('M', 'B', 'D', 'Y') | ||||
| #define BT_MB_LINKCOLLIDER_CODE BT_MAKE_ID('M', 'B', 'L', 'C') | |||||
| #define BT_SOFTBODY_CODE BT_MAKE_ID('S','B','D','Y') | #define BT_SOFTBODY_CODE BT_MAKE_ID('S', 'B', 'D', 'Y') | ||||
| #define BT_COLLISIONOBJECT_CODE BT_MAKE_ID('C','O','B','J') | #define BT_COLLISIONOBJECT_CODE BT_MAKE_ID('C', 'O', 'B', 'J') | ||||
| #define BT_RIGIDBODY_CODE BT_MAKE_ID('R','B','D','Y') | #define BT_RIGIDBODY_CODE BT_MAKE_ID('R', 'B', 'D', 'Y') | ||||
| #define BT_CONSTRAINT_CODE BT_MAKE_ID('C','O','N','S') | #define BT_CONSTRAINT_CODE BT_MAKE_ID('C', 'O', 'N', 'S') | ||||
| #define BT_BOXSHAPE_CODE BT_MAKE_ID('B','O','X','S') | #define BT_BOXSHAPE_CODE BT_MAKE_ID('B', 'O', 'X', 'S') | ||||
| #define BT_QUANTIZED_BVH_CODE BT_MAKE_ID('Q','B','V','H') | #define BT_QUANTIZED_BVH_CODE BT_MAKE_ID('Q', 'B', 'V', 'H') | ||||
| #define BT_TRIANLGE_INFO_MAP BT_MAKE_ID('T','M','A','P') | #define BT_TRIANLGE_INFO_MAP BT_MAKE_ID('T', 'M', 'A', 'P') | ||||
| #define BT_SHAPE_CODE BT_MAKE_ID('S','H','A','P') | #define BT_SHAPE_CODE BT_MAKE_ID('S', 'H', 'A', 'P') | ||||
| #define BT_ARRAY_CODE BT_MAKE_ID('A','R','A','Y') | #define BT_ARRAY_CODE BT_MAKE_ID('A', 'R', 'A', 'Y') | ||||
| #define BT_SBMATERIAL_CODE BT_MAKE_ID('S','B','M','T') | #define BT_SBMATERIAL_CODE BT_MAKE_ID('S', 'B', 'M', 'T') | ||||
| #define BT_SBNODE_CODE BT_MAKE_ID('S','B','N','D') | #define BT_SBNODE_CODE BT_MAKE_ID('S', 'B', 'N', 'D') | ||||
| #define BT_DYNAMICSWORLD_CODE BT_MAKE_ID('D','W','L','D') | #define BT_DYNAMICSWORLD_CODE BT_MAKE_ID('D', 'W', 'L', 'D') | ||||
| #define BT_CONTACTMANIFOLD_CODE BT_MAKE_ID('C', 'O', 'N', 'T') | |||||
| #define BT_DNA_CODE BT_MAKE_ID('D','N','A','1') | #define BT_DNA_CODE BT_MAKE_ID('D', 'N', 'A', '1') | ||||
| struct btPointerUid | struct btPointerUid | ||||
| { | { | ||||
| union | union { | ||||
| { | |||||
| void* m_ptr; | void* m_ptr; | ||||
| int m_uniqueIds[2]; | int m_uniqueIds[2]; | ||||
| }; | }; | ||||
| }; | }; | ||||
| struct btBulletSerializedArrays | struct btBulletSerializedArrays | ||||
| { | { | ||||
| btBulletSerializedArrays() | btBulletSerializedArrays() | ||||
| { | { | ||||
| } | } | ||||
| btAlignedObjectArray<struct btQuantizedBvhDoubleData*> m_bvhsDouble; | btAlignedObjectArray<struct btQuantizedBvhDoubleData*> m_bvhsDouble; | ||||
| btAlignedObjectArray<struct btQuantizedBvhFloatData*> m_bvhsFloat; | btAlignedObjectArray<struct btQuantizedBvhFloatData*> m_bvhsFloat; | ||||
| btAlignedObjectArray<struct btCollisionShapeData*> m_colShapeData; | btAlignedObjectArray<struct btCollisionShapeData*> m_colShapeData; | ||||
| btAlignedObjectArray<struct btDynamicsWorldDoubleData*> m_dynamicWorldInfoDataDouble; | btAlignedObjectArray<struct btDynamicsWorldDoubleData*> m_dynamicWorldInfoDataDouble; | ||||
| btAlignedObjectArray<struct btDynamicsWorldFloatData*> m_dynamicWorldInfoDataFloat; | btAlignedObjectArray<struct btDynamicsWorldFloatData*> m_dynamicWorldInfoDataFloat; | ||||
| btAlignedObjectArray<struct btRigidBodyDoubleData*> m_rigidBodyDataDouble; | btAlignedObjectArray<struct btRigidBodyDoubleData*> m_rigidBodyDataDouble; | ||||
| btAlignedObjectArray<struct btRigidBodyFloatData*> m_rigidBodyDataFloat; | btAlignedObjectArray<struct btRigidBodyFloatData*> m_rigidBodyDataFloat; | ||||
| btAlignedObjectArray<struct btCollisionObjectDoubleData*> m_collisionObjectDataDouble; | btAlignedObjectArray<struct btCollisionObjectDoubleData*> m_collisionObjectDataDouble; | ||||
| btAlignedObjectArray<struct btCollisionObjectFloatData*> m_collisionObjectDataFloat; | btAlignedObjectArray<struct btCollisionObjectFloatData*> m_collisionObjectDataFloat; | ||||
| btAlignedObjectArray<struct btTypedConstraintFloatData*> m_constraintDataFloat; | btAlignedObjectArray<struct btTypedConstraintFloatData*> m_constraintDataFloat; | ||||
| btAlignedObjectArray<struct btTypedConstraintDoubleData*> m_constraintDataDouble; | btAlignedObjectArray<struct btTypedConstraintDoubleData*> m_constraintDataDouble; | ||||
| btAlignedObjectArray<struct btTypedConstraintData*> m_constraintData;//for backwards compatibility | btAlignedObjectArray<struct btTypedConstraintData*> m_constraintData; //for backwards compatibility | ||||
| btAlignedObjectArray<struct btSoftBodyFloatData*> m_softBodyFloatData; | btAlignedObjectArray<struct btSoftBodyFloatData*> m_softBodyFloatData; | ||||
| btAlignedObjectArray<struct btSoftBodyDoubleData*> m_softBodyDoubleData; | btAlignedObjectArray<struct btSoftBodyDoubleData*> m_softBodyDoubleData; | ||||
| }; | }; | ||||
| ///The btDefaultSerializer is the main Bullet serialization class. | ///The btDefaultSerializer is the main Bullet serialization class. | ||||
| ///The constructor takes an optional argument for backwards compatibility, it is recommended to leave this empty/zero. | ///The constructor takes an optional argument for backwards compatibility, it is recommended to leave this empty/zero. | ||||
| class btDefaultSerializer : public btSerializer | class btDefaultSerializer : public btSerializer | ||||
| { | { | ||||
| protected: | protected: | ||||
| btAlignedObjectArray<char*> mTypes; | btAlignedObjectArray<char*> mTypes; | ||||
| btAlignedObjectArray<short*> mStructs; | btAlignedObjectArray<short*> mStructs; | ||||
| btAlignedObjectArray<short> mTlens; | btAlignedObjectArray<short> mTlens; | ||||
| btHashMap<btHashInt, int> mStructReverse; | btHashMap<btHashInt, int> mStructReverse; | ||||
| btHashMap<btHashString,int> mTypeLookup; | btHashMap<btHashString, int> mTypeLookup; | ||||
| btHashMap<btHashPtr,void*> m_chunkP; | btHashMap<btHashPtr, void*> m_chunkP; | ||||
| btHashMap<btHashPtr,const char*> m_nameMap; | btHashMap<btHashPtr, const char*> m_nameMap; | ||||
| btHashMap<btHashPtr,btPointerUid> m_uniquePointers; | btHashMap<btHashPtr, btPointerUid> m_uniquePointers; | ||||
| int m_uniqueIdGenerator; | int m_uniqueIdGenerator; | ||||
| int m_totalSize; | int m_totalSize; | ||||
| unsigned char* m_buffer; | unsigned char* m_buffer; | ||||
| bool m_ownsBuffer; | bool m_ownsBuffer; | ||||
| int m_currentSize; | int m_currentSize; | ||||
| void* m_dna; | void* m_dna; | ||||
| int m_dnaLength; | int m_dnaLength; | ||||
| int m_serializationFlags; | int m_serializationFlags; | ||||
| btAlignedObjectArray<btChunk*> m_chunkPtrs; | btAlignedObjectArray<btChunk*> m_chunkPtrs; | ||||
| protected: | protected: | ||||
| virtual void* findPointer(void* oldPtr) | virtual void* findPointer(void* oldPtr) | ||||
| { | { | ||||
| void** ptr = m_chunkP.find(oldPtr); | void** ptr = m_chunkP.find(oldPtr); | ||||
| if (ptr && *ptr) | if (ptr && *ptr) | ||||
| return *ptr; | return *ptr; | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| virtual void writeDNA() | virtual void writeDNA() | ||||
| { | { | ||||
| btChunk* dnaChunk = allocate(m_dnaLength,1); | btChunk* dnaChunk = allocate(m_dnaLength, 1); | ||||
| memcpy(dnaChunk->m_oldPtr,m_dna,m_dnaLength); | memcpy(dnaChunk->m_oldPtr, m_dna, m_dnaLength); | ||||
| finalizeChunk(dnaChunk,"DNA1",BT_DNA_CODE, m_dna); | finalizeChunk(dnaChunk, "DNA1", BT_DNA_CODE, m_dna); | ||||
| } | } | ||||
| int getReverseType(const char *type) const | int getReverseType(const char* type) const | ||||
| { | { | ||||
| btHashString key(type); | btHashString key(type); | ||||
| const int* valuePtr = mTypeLookup.find(key); | const int* valuePtr = mTypeLookup.find(key); | ||||
| if (valuePtr) | if (valuePtr) | ||||
| return *valuePtr; | return *valuePtr; | ||||
| return -1; | return -1; | ||||
| } | } | ||||
| void initDNA(const char* bdnaOrg,int dnalen) | void initDNA(const char* bdnaOrg, int dnalen) | ||||
| { | { | ||||
| ///was already initialized | ///was already initialized | ||||
| if (m_dna) | if (m_dna) | ||||
| return; | return; | ||||
| int littleEndian= 1; | int littleEndian = 1; | ||||
| littleEndian= ((char*)&littleEndian)[0]; | littleEndian = ((char*)&littleEndian)[0]; | ||||
| m_dna = btAlignedAlloc(dnalen,16); | m_dna = btAlignedAlloc(dnalen, 16); | ||||
| memcpy(m_dna,bdnaOrg,dnalen); | memcpy(m_dna, bdnaOrg, dnalen); | ||||
| m_dnaLength = dnalen; | m_dnaLength = dnalen; | ||||
| int *intPtr=0; | int* intPtr = 0; | ||||
| short *shtPtr=0; | short* shtPtr = 0; | ||||
| char *cp = 0;int dataLen =0; | char* cp = 0; | ||||
| int dataLen = 0; | |||||
| intPtr = (int*)m_dna; | intPtr = (int*)m_dna; | ||||
| /* | /* | ||||
| SDNA (4 bytes) (magic number) | SDNA (4 bytes) (magic number) | ||||
| NAME (4 bytes) | NAME (4 bytes) | ||||
| <nr> (4 bytes) amount of names (int) | <nr> (4 bytes) amount of names (int) | ||||
| <string> | <string> | ||||
| <string> | <string> | ||||
| */ | */ | ||||
| if (strncmp((const char*)m_dna, "SDNA", 4)==0) | if (strncmp((const char*)m_dna, "SDNA", 4) == 0) | ||||
| { | { | ||||
| // skip ++ NAME | // skip ++ NAME | ||||
| intPtr++; intPtr++; | intPtr++; | ||||
| intPtr++; | |||||
| } | } | ||||
| // Parse names | // Parse names | ||||
| if (!littleEndian) | if (!littleEndian) | ||||
| *intPtr = btSwapEndian(*intPtr); | *intPtr = btSwapEndian(*intPtr); | ||||
| dataLen = *intPtr; | dataLen = *intPtr; | ||||
| intPtr++; | intPtr++; | ||||
| cp = (char*)intPtr; | cp = (char*)intPtr; | ||||
| int i; | int i; | ||||
| for ( i=0; i<dataLen; i++) | for (i = 0; i < dataLen; i++) | ||||
| { | { | ||||
| while (*cp)cp++; | while (*cp) cp++; | ||||
| cp++; | cp++; | ||||
| } | } | ||||
| cp = btAlignPointer(cp,4); | cp = btAlignPointer(cp, 4); | ||||
| /* | /* | ||||
| TYPE (4 bytes) | TYPE (4 bytes) | ||||
| <nr> amount of types (int) | <nr> amount of types (int) | ||||
| <string> | <string> | ||||
| <string> | <string> | ||||
| */ | */ | ||||
| intPtr = (int*)cp; | intPtr = (int*)cp; | ||||
| btAssert(strncmp(cp, "TYPE", 4)==0); intPtr++; | btAssert(strncmp(cp, "TYPE", 4) == 0); | ||||
| intPtr++; | |||||
| if (!littleEndian) | if (!littleEndian) | ||||
| *intPtr = btSwapEndian(*intPtr); | *intPtr = btSwapEndian(*intPtr); | ||||
| dataLen = *intPtr; | dataLen = *intPtr; | ||||
| intPtr++; | intPtr++; | ||||
| cp = (char*)intPtr; | cp = (char*)intPtr; | ||||
| for (i=0; i<dataLen; i++) | for (i = 0; i < dataLen; i++) | ||||
| { | { | ||||
| mTypes.push_back(cp); | mTypes.push_back(cp); | ||||
| while (*cp)cp++; | while (*cp) cp++; | ||||
| cp++; | cp++; | ||||
| } | } | ||||
| cp = btAlignPointer(cp,4); | cp = btAlignPointer(cp, 4); | ||||
| /* | /* | ||||
| TLEN (4 bytes) | TLEN (4 bytes) | ||||
| <len> (short) the lengths of types | <len> (short) the lengths of types | ||||
| <len> | <len> | ||||
| */ | */ | ||||
| // Parse type lens | // Parse type lens | ||||
| intPtr = (int*)cp; | intPtr = (int*)cp; | ||||
| btAssert(strncmp(cp, "TLEN", 4)==0); intPtr++; | btAssert(strncmp(cp, "TLEN", 4) == 0); | ||||
| intPtr++; | |||||
| dataLen = (int)mTypes.size(); | dataLen = (int)mTypes.size(); | ||||
| shtPtr = (short*)intPtr; | shtPtr = (short*)intPtr; | ||||
| for (i=0; i<dataLen; i++, shtPtr++) | for (i = 0; i < dataLen; i++, shtPtr++) | ||||
| { | { | ||||
| if (!littleEndian) | if (!littleEndian) | ||||
| shtPtr[0] = btSwapEndian(shtPtr[0]); | shtPtr[0] = btSwapEndian(shtPtr[0]); | ||||
| mTlens.push_back(shtPtr[0]); | mTlens.push_back(shtPtr[0]); | ||||
| } | } | ||||
| if (dataLen & 1) shtPtr++; | if (dataLen & 1) shtPtr++; | ||||
| /* | /* | ||||
| STRC (4 bytes) | STRC (4 bytes) | ||||
| <nr> amount of structs (int) | <nr> amount of structs (int) | ||||
| <typenr> | <typenr> | ||||
| <nr_of_elems> | <nr_of_elems> | ||||
| <typenr> | <typenr> | ||||
| <namenr> | <namenr> | ||||
| <typenr> | <typenr> | ||||
| <namenr> | <namenr> | ||||
| */ | */ | ||||
| intPtr = (int*)shtPtr; | intPtr = (int*)shtPtr; | ||||
| cp = (char*)intPtr; | cp = (char*)intPtr; | ||||
| btAssert(strncmp(cp, "STRC", 4)==0); intPtr++; | btAssert(strncmp(cp, "STRC", 4) == 0); | ||||
| intPtr++; | |||||
| if (!littleEndian) | if (!littleEndian) | ||||
| *intPtr = btSwapEndian(*intPtr); | *intPtr = btSwapEndian(*intPtr); | ||||
| dataLen = *intPtr ; | dataLen = *intPtr; | ||||
| intPtr++; | intPtr++; | ||||
| shtPtr = (short*)intPtr; | shtPtr = (short*)intPtr; | ||||
| for (i=0; i<dataLen; i++) | for (i = 0; i < dataLen; i++) | ||||
| { | { | ||||
| mStructs.push_back (shtPtr); | mStructs.push_back(shtPtr); | ||||
| if (!littleEndian) | if (!littleEndian) | ||||
| { | { | ||||
| shtPtr[0]= btSwapEndian(shtPtr[0]); | shtPtr[0] = btSwapEndian(shtPtr[0]); | ||||
| shtPtr[1]= btSwapEndian(shtPtr[1]); | shtPtr[1] = btSwapEndian(shtPtr[1]); | ||||
| int len = shtPtr[1]; | int len = shtPtr[1]; | ||||
| shtPtr+= 2; | shtPtr += 2; | ||||
| for (int a=0; a<len; a++, shtPtr+=2) | for (int a = 0; a < len; a++, shtPtr += 2) | ||||
| { | { | ||||
| shtPtr[0]= btSwapEndian(shtPtr[0]); | shtPtr[0] = btSwapEndian(shtPtr[0]); | ||||
| shtPtr[1]= btSwapEndian(shtPtr[1]); | shtPtr[1] = btSwapEndian(shtPtr[1]); | ||||
| } | } | ||||
| } | |||||
| } else | else | ||||
| { | { | ||||
| shtPtr+= (2*shtPtr[1])+2; | shtPtr += (2 * shtPtr[1]) + 2; | ||||
| } | } | ||||
| } | } | ||||
| // build reverse lookups | // build reverse lookups | ||||
| for (i=0; i<(int)mStructs.size(); i++) | for (i = 0; i < (int)mStructs.size(); i++) | ||||
| { | { | ||||
| short *strc = mStructs.at(i); | short* strc = mStructs.at(i); | ||||
| mStructReverse.insert(strc[0], i); | mStructReverse.insert(strc[0], i); | ||||
| mTypeLookup.insert(btHashString(mTypes[strc[0]]),i); | mTypeLookup.insert(btHashString(mTypes[strc[0]]), i); | ||||
| } | } | ||||
| } | } | ||||
| public: | public: | ||||
| btHashMap<btHashPtr,void*> m_skipPointers; | btHashMap<btHashPtr, void*> m_skipPointers; | ||||
| btDefaultSerializer(int totalSize=0, unsigned char* buffer=0) | btDefaultSerializer(int totalSize = 0, unsigned char* buffer = 0) | ||||
| :m_totalSize(totalSize), | : m_uniqueIdGenerator(0), | ||||
| m_totalSize(totalSize), | |||||
| m_currentSize(0), | m_currentSize(0), | ||||
| m_dna(0), | m_dna(0), | ||||
| m_dnaLength(0), | m_dnaLength(0), | ||||
| m_serializationFlags(0) | m_serializationFlags(0) | ||||
| { | { | ||||
| if (buffer==0) | if (buffer == 0) | ||||
| { | { | ||||
| m_buffer = m_totalSize?(unsigned char*)btAlignedAlloc(totalSize,16):0; | m_buffer = m_totalSize ? (unsigned char*)btAlignedAlloc(totalSize, 16) : 0; | ||||
| m_ownsBuffer = true; | m_ownsBuffer = true; | ||||
| } else | } | ||||
| else | |||||
| { | { | ||||
| m_buffer = buffer; | m_buffer = buffer; | ||||
| m_ownsBuffer = false; | m_ownsBuffer = false; | ||||
| } | } | ||||
| const bool VOID_IS_8 = ((sizeof(void*)==8)); | const bool VOID_IS_8 = ((sizeof(void*) == 8)); | ||||
| #ifdef BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES | #ifdef BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES | ||||
| if (VOID_IS_8) | if (VOID_IS_8) | ||||
| { | { | ||||
| #if _WIN64 | #if _WIN64 | ||||
| initDNA((const char*)sBulletDNAstr64,sBulletDNAlen64); | initDNA((const char*)sBulletDNAstr64, sBulletDNAlen64); | ||||
| #else | #else | ||||
| btAssert(0); | btAssert(0); | ||||
| #endif | #endif | ||||
| } else | } | ||||
| else | |||||
| { | { | ||||
| #ifndef _WIN64 | #ifndef _WIN64 | ||||
| initDNA((const char*)sBulletDNAstr,sBulletDNAlen); | initDNA((const char*)sBulletDNAstr, sBulletDNAlen); | ||||
| #else | #else | ||||
| btAssert(0); | btAssert(0); | ||||
| #endif | #endif | ||||
| } | } | ||||
| #else //BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES | #else //BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES | ||||
| if (VOID_IS_8) | if (VOID_IS_8) | ||||
| { | { | ||||
| initDNA((const char*)sBulletDNAstr64,sBulletDNAlen64); | initDNA((const char*)sBulletDNAstr64, sBulletDNAlen64); | ||||
| } else | } | ||||
| else | |||||
| { | { | ||||
| initDNA((const char*)sBulletDNAstr,sBulletDNAlen); | initDNA((const char*)sBulletDNAstr, sBulletDNAlen); | ||||
| } | } | ||||
| #endif //BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES | #endif //BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES | ||||
| } | } | ||||
| virtual ~btDefaultSerializer() | virtual ~btDefaultSerializer() | ||||
| { | { | ||||
| if (m_buffer && m_ownsBuffer) | if (m_buffer && m_ownsBuffer) | ||||
| btAlignedFree(m_buffer); | btAlignedFree(m_buffer); | ||||
| if (m_dna) | if (m_dna) | ||||
| btAlignedFree(m_dna); | btAlignedFree(m_dna); | ||||
| } | } | ||||
| static int getMemoryDnaSizeInBytes() | |||||
| { | |||||
| const bool VOID_IS_8 = ((sizeof(void*) == 8)); | |||||
| if (VOID_IS_8) | |||||
| { | |||||
| return sBulletDNAlen64; | |||||
| } | |||||
| return sBulletDNAlen; | |||||
| } | |||||
| static const char* getMemoryDna() | |||||
| { | |||||
| const bool VOID_IS_8 = ((sizeof(void*) == 8)); | |||||
| if (VOID_IS_8) | |||||
| { | |||||
| return (const char*)sBulletDNAstr64; | |||||
| } | |||||
| return (const char*)sBulletDNAstr; | |||||
| } | |||||
| void insertHeader() | void insertHeader() | ||||
| { | { | ||||
| writeHeader(m_buffer); | writeHeader(m_buffer); | ||||
| m_currentSize += BT_HEADER_LENGTH; | m_currentSize += BT_HEADER_LENGTH; | ||||
| } | } | ||||
| void writeHeader(unsigned char* buffer) const | void writeHeader(unsigned char* buffer) const | ||||
| { | { | ||||
| #ifdef BT_USE_DOUBLE_PRECISION | #ifdef BT_USE_DOUBLE_PRECISION | ||||
| memcpy(buffer, "BULLETd", 7); | memcpy(buffer, "BULLETd", 7); | ||||
| #else | #else | ||||
| memcpy(buffer, "BULLETf", 7); | memcpy(buffer, "BULLETf", 7); | ||||
| #endif //BT_USE_DOUBLE_PRECISION | #endif //BT_USE_DOUBLE_PRECISION | ||||
| int littleEndian= 1; | int littleEndian = 1; | ||||
| littleEndian= ((char*)&littleEndian)[0]; | littleEndian = ((char*)&littleEndian)[0]; | ||||
| if (sizeof(void*)==8) | if (sizeof(void*) == 8) | ||||
| { | { | ||||
| buffer[7] = '-'; | buffer[7] = '-'; | ||||
| } else | } | ||||
| else | |||||
| { | { | ||||
| buffer[7] = '_'; | buffer[7] = '_'; | ||||
| } | } | ||||
| if (littleEndian) | if (littleEndian) | ||||
| { | { | ||||
| buffer[8]='v'; | buffer[8] = 'v'; | ||||
| } else | } | ||||
| else | |||||
| { | { | ||||
| buffer[8]='V'; | buffer[8] = 'V'; | ||||
| } | } | ||||
| buffer[9] = '2'; | buffer[9] = '2'; | ||||
| buffer[10] = '8'; | buffer[10] = '8'; | ||||
| buffer[11] = '4'; | buffer[11] = '9'; | ||||
| } | } | ||||
| virtual void startSerialization() | virtual void startSerialization() | ||||
| { | { | ||||
| m_uniqueIdGenerator= 1; | m_uniqueIdGenerator = 1; | ||||
| if (m_totalSize) | if (m_totalSize) | ||||
| { | { | ||||
| unsigned char* buffer = internalAlloc(BT_HEADER_LENGTH); | unsigned char* buffer = internalAlloc(BT_HEADER_LENGTH); | ||||
| writeHeader(buffer); | writeHeader(buffer); | ||||
| } | } | ||||
| } | } | ||||
| virtual void finishSerialization() | virtual void finishSerialization() | ||||
| { | { | ||||
| writeDNA(); | writeDNA(); | ||||
| //if we didn't pre-allocate a buffer, we need to create a contiguous buffer now | //if we didn't pre-allocate a buffer, we need to create a contiguous buffer now | ||||
| int mysize = 0; | int mysize = 0; | ||||
| if (!m_totalSize) | if (!m_totalSize) | ||||
| { | { | ||||
| if (m_buffer) | if (m_buffer) | ||||
| btAlignedFree(m_buffer); | btAlignedFree(m_buffer); | ||||
| m_currentSize += BT_HEADER_LENGTH; | m_currentSize += BT_HEADER_LENGTH; | ||||
| m_buffer = (unsigned char*)btAlignedAlloc(m_currentSize,16); | m_buffer = (unsigned char*)btAlignedAlloc(m_currentSize, 16); | ||||
| unsigned char* currentPtr = m_buffer; | unsigned char* currentPtr = m_buffer; | ||||
| writeHeader(m_buffer); | writeHeader(m_buffer); | ||||
| currentPtr += BT_HEADER_LENGTH; | currentPtr += BT_HEADER_LENGTH; | ||||
| mysize+=BT_HEADER_LENGTH; | mysize += BT_HEADER_LENGTH; | ||||
| for (int i=0;i< m_chunkPtrs.size();i++) | for (int i = 0; i < m_chunkPtrs.size(); i++) | ||||
| { | { | ||||
| int curLength = sizeof(btChunk)+m_chunkPtrs[i]->m_length; | int curLength = sizeof(btChunk) + m_chunkPtrs[i]->m_length; | ||||
| memcpy(currentPtr,m_chunkPtrs[i], curLength); | memcpy(currentPtr, m_chunkPtrs[i], curLength); | ||||
| btAlignedFree(m_chunkPtrs[i]); | btAlignedFree(m_chunkPtrs[i]); | ||||
| currentPtr+=curLength; | currentPtr += curLength; | ||||
| mysize+=curLength; | mysize += curLength; | ||||
| } | } | ||||
| } | } | ||||
| mTypes.clear(); | mTypes.clear(); | ||||
| mStructs.clear(); | mStructs.clear(); | ||||
| mTlens.clear(); | mTlens.clear(); | ||||
| mStructReverse.clear(); | mStructReverse.clear(); | ||||
| mTypeLookup.clear(); | mTypeLookup.clear(); | ||||
| m_skipPointers.clear(); | m_skipPointers.clear(); | ||||
| m_chunkP.clear(); | m_chunkP.clear(); | ||||
| m_nameMap.clear(); | m_nameMap.clear(); | ||||
| m_uniquePointers.clear(); | m_uniquePointers.clear(); | ||||
| m_chunkPtrs.clear(); | m_chunkPtrs.clear(); | ||||
| } | } | ||||
| virtual void* getUniquePointer(void*oldPtr) | virtual void* getUniquePointer(void* oldPtr) | ||||
| { | { | ||||
| btAssert(m_uniqueIdGenerator >= 0); | |||||
| if (!oldPtr) | if (!oldPtr) | ||||
| return 0; | return 0; | ||||
| btPointerUid* uptr = (btPointerUid*)m_uniquePointers.find(oldPtr); | btPointerUid* uptr = (btPointerUid*)m_uniquePointers.find(oldPtr); | ||||
| if (uptr) | if (uptr) | ||||
| { | { | ||||
| return uptr->m_ptr; | return uptr->m_ptr; | ||||
| } | } | ||||
| void** ptr2 = m_skipPointers[oldPtr]; | void** ptr2 = m_skipPointers[oldPtr]; | ||||
| if (ptr2) | if (ptr2) | ||||
| { | { | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| m_uniqueIdGenerator++; | m_uniqueIdGenerator++; | ||||
| btPointerUid uid; | btPointerUid uid; | ||||
| uid.m_uniqueIds[0] = m_uniqueIdGenerator; | uid.m_uniqueIds[0] = m_uniqueIdGenerator; | ||||
| uid.m_uniqueIds[1] = m_uniqueIdGenerator; | uid.m_uniqueIds[1] = m_uniqueIdGenerator; | ||||
| m_uniquePointers.insert(oldPtr,uid); | m_uniquePointers.insert(oldPtr, uid); | ||||
| return uid.m_ptr; | return uid.m_ptr; | ||||
| } | } | ||||
| virtual const unsigned char* getBufferPointer() const | virtual const unsigned char* getBufferPointer() const | ||||
| { | { | ||||
| return m_buffer; | return m_buffer; | ||||
| } | } | ||||
| virtual int getCurrentBufferSize() const | virtual int getCurrentBufferSize() const | ||||
| { | { | ||||
| return m_currentSize; | return m_currentSize; | ||||
| } | } | ||||
| virtual void finalizeChunk(btChunk* chunk, const char* structType, int chunkCode,void* oldPtr) | virtual void finalizeChunk(btChunk* chunk, const char* structType, int chunkCode, void* oldPtr) | ||||
| { | { | ||||
| if (!(m_serializationFlags&BT_SERIALIZE_NO_DUPLICATE_ASSERT)) | if (!(m_serializationFlags & BT_SERIALIZE_NO_DUPLICATE_ASSERT)) | ||||
| { | { | ||||
| btAssert(!findPointer(oldPtr)); | btAssert(!findPointer(oldPtr)); | ||||
| } | } | ||||
| chunk->m_dna_nr = getReverseType(structType); | chunk->m_dna_nr = getReverseType(structType); | ||||
| chunk->m_chunkCode = chunkCode; | chunk->m_chunkCode = chunkCode; | ||||
| void* uniquePtr = getUniquePointer(oldPtr); | void* uniquePtr = getUniquePointer(oldPtr); | ||||
| m_chunkP.insert(oldPtr,uniquePtr);//chunk->m_oldPtr); | m_chunkP.insert(oldPtr, uniquePtr); //chunk->m_oldPtr); | ||||
| chunk->m_oldPtr = uniquePtr;//oldPtr; | chunk->m_oldPtr = uniquePtr; //oldPtr; | ||||
| } | } | ||||
| virtual unsigned char* internalAlloc(size_t size) | virtual unsigned char* internalAlloc(size_t size) | ||||
| { | { | ||||
| unsigned char* ptr = 0; | unsigned char* ptr = 0; | ||||
| if (m_totalSize) | if (m_totalSize) | ||||
| { | { | ||||
| ptr = m_buffer+m_currentSize; | ptr = m_buffer + m_currentSize; | ||||
| m_currentSize += int(size); | m_currentSize += int(size); | ||||
| btAssert(m_currentSize<m_totalSize); | btAssert(m_currentSize < m_totalSize); | ||||
| } else | } | ||||
| else | |||||
| { | { | ||||
| ptr = (unsigned char*)btAlignedAlloc(size,16); | ptr = (unsigned char*)btAlignedAlloc(size, 16); | ||||
| m_currentSize += int(size); | m_currentSize += int(size); | ||||
| } | } | ||||
| return ptr; | return ptr; | ||||
| } | } | ||||
| virtual btChunk* allocate(size_t size, int numElements) | virtual btChunk* allocate(size_t size, int numElements) | ||||
| { | { | ||||
| unsigned char* ptr = internalAlloc(int(size)*numElements+sizeof(btChunk)); | unsigned char* ptr = internalAlloc(int(size) * numElements + sizeof(btChunk)); | ||||
| unsigned char* data = ptr + sizeof(btChunk); | unsigned char* data = ptr + sizeof(btChunk); | ||||
| btChunk* chunk = (btChunk*)ptr; | btChunk* chunk = (btChunk*)ptr; | ||||
| chunk->m_chunkCode = 0; | chunk->m_chunkCode = 0; | ||||
| chunk->m_oldPtr = data; | chunk->m_oldPtr = data; | ||||
| chunk->m_length = int(size)*numElements; | chunk->m_length = int(size) * numElements; | ||||
| chunk->m_number = numElements; | chunk->m_number = numElements; | ||||
| m_chunkPtrs.push_back(chunk); | m_chunkPtrs.push_back(chunk); | ||||
| return chunk; | return chunk; | ||||
| } | } | ||||
| virtual const char* findNameForPointer(const void* ptr) const | virtual const char* findNameForPointer(const void* ptr) const | ||||
| { | { | ||||
| const char*const * namePtr = m_nameMap.find(ptr); | const char* const* namePtr = m_nameMap.find(ptr); | ||||
| if (namePtr && *namePtr) | if (namePtr && *namePtr) | ||||
| return *namePtr; | return *namePtr; | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| virtual void registerNameForPointer(const void* ptr, const char* name) | virtual void registerNameForPointer(const void* ptr, const char* name) | ||||
| { | { | ||||
| m_nameMap.insert(ptr,name); | m_nameMap.insert(ptr, name); | ||||
| } | } | ||||
| virtual void serializeName(const char* name) | virtual void serializeName(const char* name) | ||||
| { | { | ||||
| if (name) | if (name) | ||||
| { | { | ||||
| //don't serialize name twice | //don't serialize name twice | ||||
| if (findPointer((void*)name)) | if (findPointer((void*)name)) | ||||
| return; | return; | ||||
| int len = btStrLen(name); | int len = btStrLen(name); | ||||
| if (len) | if (len) | ||||
| { | { | ||||
| int newLen = len+1; | int newLen = len + 1; | ||||
| int padding = ((newLen+3)&~3)-newLen; | int padding = ((newLen + 3) & ~3) - newLen; | ||||
| newLen += padding; | newLen += padding; | ||||
| //serialize name string now | //serialize name string now | ||||
| btChunk* chunk = allocate(sizeof(char),newLen); | btChunk* chunk = allocate(sizeof(char), newLen); | ||||
| char* destinationName = (char*)chunk->m_oldPtr; | char* destinationName = (char*)chunk->m_oldPtr; | ||||
| for (int i=0;i<len;i++) | for (int i = 0; i < len; i++) | ||||
| { | { | ||||
| destinationName[i] = name[i]; | destinationName[i] = name[i]; | ||||
| } | } | ||||
| destinationName[len] = 0; | destinationName[len] = 0; | ||||
| finalizeChunk(chunk,"char",BT_ARRAY_CODE,(void*)name); | finalizeChunk(chunk, "char", BT_ARRAY_CODE, (void*)name); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| virtual int getSerializationFlags() const | virtual int getSerializationFlags() const | ||||
| { | { | ||||
| return m_serializationFlags; | return m_serializationFlags; | ||||
| } | } | ||||
| virtual void setSerializationFlags(int flags) | virtual void setSerializationFlags(int flags) | ||||
| { | { | ||||
| m_serializationFlags = flags; | m_serializationFlags = flags; | ||||
| } | } | ||||
| int getNumChunks() const | int getNumChunks() const | ||||
| { | { | ||||
| return m_chunkPtrs.size(); | return m_chunkPtrs.size(); | ||||
| } | } | ||||
| const btChunk* getChunk(int chunkIndex) const | const btChunk* getChunk(int chunkIndex) const | ||||
| { | { | ||||
| return m_chunkPtrs[chunkIndex]; | return m_chunkPtrs[chunkIndex]; | ||||
| } | } | ||||
| }; | }; | ||||
| ///In general it is best to use btDefaultSerializer, | ///In general it is best to use btDefaultSerializer, | ||||
| ///in particular when writing the data to disk or sending it over the network. | ///in particular when writing the data to disk or sending it over the network. | ||||
| ///The btInMemorySerializer is experimental and only suitable in a few cases. | ///The btInMemorySerializer is experimental and only suitable in a few cases. | ||||
| ///The btInMemorySerializer takes a shortcut and can be useful to create a deep-copy | ///The btInMemorySerializer takes a shortcut and can be useful to create a deep-copy | ||||
| ///of objects. There will be a demo on how to use the btInMemorySerializer. | ///of objects. There will be a demo on how to use the btInMemorySerializer. | ||||
| #ifdef ENABLE_INMEMORY_SERIALIZER | #ifdef ENABLE_INMEMORY_SERIALIZER | ||||
| struct btInMemorySerializer : public btDefaultSerializer | struct btInMemorySerializer : public btDefaultSerializer | ||||
| { | { | ||||
| btHashMap<btHashPtr,btChunk*> m_uid2ChunkPtr; | btHashMap<btHashPtr, btChunk*> m_uid2ChunkPtr; | ||||
| btHashMap<btHashPtr,void*> m_orgPtr2UniqueDataPtr; | btHashMap<btHashPtr, void*> m_orgPtr2UniqueDataPtr; | ||||
| btHashMap<btHashString,const void*> m_names2Ptr; | btHashMap<btHashString, const void*> m_names2Ptr; | ||||
| btBulletSerializedArrays m_arrays; | btBulletSerializedArrays m_arrays; | ||||
| btInMemorySerializer(int totalSize=0, unsigned char* buffer=0) | btInMemorySerializer(int totalSize = 0, unsigned char* buffer = 0) | ||||
| :btDefaultSerializer(totalSize,buffer) | : btDefaultSerializer(totalSize, buffer) | ||||
| { | { | ||||
| } | } | ||||
| virtual void startSerialization() | virtual void startSerialization() | ||||
| { | { | ||||
| m_uid2ChunkPtr.clear(); | m_uid2ChunkPtr.clear(); | ||||
| //todo: m_arrays.clear(); | //todo: m_arrays.clear(); | ||||
| btDefaultSerializer::startSerialization(); | btDefaultSerializer::startSerialization(); | ||||
| } | } | ||||
| btChunk* findChunkFromUniquePointer(void* uniquePointer) | btChunk* findChunkFromUniquePointer(void* uniquePointer) | ||||
| { | { | ||||
| btChunk** chkPtr = m_uid2ChunkPtr[uniquePointer]; | btChunk** chkPtr = m_uid2ChunkPtr[uniquePointer]; | ||||
| if (chkPtr) | if (chkPtr) | ||||
| { | { | ||||
| return *chkPtr; | return *chkPtr; | ||||
| } | } | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| virtual void registerNameForPointer(const void* ptr, const char* name) | virtual void registerNameForPointer(const void* ptr, const char* name) | ||||
| { | { | ||||
| btDefaultSerializer::registerNameForPointer(ptr,name); | btDefaultSerializer::registerNameForPointer(ptr, name); | ||||
| m_names2Ptr.insert(name,ptr); | m_names2Ptr.insert(name, ptr); | ||||
| } | } | ||||
| virtual void finishSerialization() | virtual void finishSerialization() | ||||
| { | { | ||||
| } | } | ||||
| virtual void* getUniquePointer(void*oldPtr) | virtual void* getUniquePointer(void* oldPtr) | ||||
| { | { | ||||
| if (oldPtr==0) | if (oldPtr == 0) | ||||
| return 0; | return 0; | ||||
| // void* uniquePtr = getUniquePointer(oldPtr); | // void* uniquePtr = getUniquePointer(oldPtr); | ||||
| btChunk* chunk = findChunkFromUniquePointer(oldPtr); | btChunk* chunk = findChunkFromUniquePointer(oldPtr); | ||||
| if (chunk) | if (chunk) | ||||
| { | { | ||||
| return chunk->m_oldPtr; | return chunk->m_oldPtr; | ||||
| } else | } | ||||
| else | |||||
| { | { | ||||
| const char* n = (const char*) oldPtr; | const char* n = (const char*)oldPtr; | ||||
| const void** ptr = m_names2Ptr[n]; | const void** ptr = m_names2Ptr[n]; | ||||
| if (ptr) | if (ptr) | ||||
| { | { | ||||
| return oldPtr; | return oldPtr; | ||||
| } else | } | ||||
| else | |||||
| { | { | ||||
| void** ptr2 = m_skipPointers[oldPtr]; | void** ptr2 = m_skipPointers[oldPtr]; | ||||
| if (ptr2) | if (ptr2) | ||||
| { | { | ||||
| return 0; | return 0; | ||||
| } else | } | ||||
| else | |||||
| { | { | ||||
| //If this assert hit, serialization happened in the wrong order | //If this assert hit, serialization happened in the wrong order | ||||
| // 'getUniquePointer' | // 'getUniquePointer' | ||||
| btAssert(0); | btAssert(0); | ||||
| } | } | ||||
| } | } | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| return oldPtr; | return oldPtr; | ||||
| } | } | ||||
| virtual void finalizeChunk(btChunk* chunk, const char* structType, int chunkCode,void* oldPtr) | virtual void finalizeChunk(btChunk* chunk, const char* structType, int chunkCode, void* oldPtr) | ||||
| { | { | ||||
| if (!(m_serializationFlags&BT_SERIALIZE_NO_DUPLICATE_ASSERT)) | if (!(m_serializationFlags & BT_SERIALIZE_NO_DUPLICATE_ASSERT)) | ||||
| { | { | ||||
| btAssert(!findPointer(oldPtr)); | btAssert(!findPointer(oldPtr)); | ||||
| } | } | ||||
| chunk->m_dna_nr = getReverseType(structType); | chunk->m_dna_nr = getReverseType(structType); | ||||
| chunk->m_chunkCode = chunkCode; | chunk->m_chunkCode = chunkCode; | ||||
| //void* uniquePtr = getUniquePointer(oldPtr); | //void* uniquePtr = getUniquePointer(oldPtr); | ||||
| m_chunkP.insert(oldPtr,oldPtr);//chunk->m_oldPtr); | m_chunkP.insert(oldPtr, oldPtr); //chunk->m_oldPtr); | ||||
| // chunk->m_oldPtr = uniquePtr;//oldPtr; | // chunk->m_oldPtr = uniquePtr;//oldPtr; | ||||
| void* uid = findPointer(oldPtr); | void* uid = findPointer(oldPtr); | ||||
| m_uid2ChunkPtr.insert(uid,chunk); | m_uid2ChunkPtr.insert(uid, chunk); | ||||
| switch (chunk->m_chunkCode) | switch (chunk->m_chunkCode) | ||||
| { | { | ||||
| case BT_SOFTBODY_CODE: | case BT_SOFTBODY_CODE: | ||||
| { | { | ||||
| #ifdef BT_USE_DOUBLE_PRECISION | #ifdef BT_USE_DOUBLE_PRECISION | ||||
| m_arrays.m_softBodyDoubleData.push_back((btSoftBodyDoubleData*) chunk->m_oldPtr); | m_arrays.m_softBodyDoubleData.push_back((btSoftBodyDoubleData*)chunk->m_oldPtr); | ||||
| #else | #else | ||||
| m_arrays.m_softBodyFloatData.push_back((btSoftBodyFloatData*) chunk->m_oldPtr); | m_arrays.m_softBodyFloatData.push_back((btSoftBodyFloatData*)chunk->m_oldPtr); | ||||
| #endif | #endif | ||||
| break; | break; | ||||
| } | } | ||||
| case BT_COLLISIONOBJECT_CODE: | case BT_COLLISIONOBJECT_CODE: | ||||
| { | { | ||||
| #ifdef BT_USE_DOUBLE_PRECISION | #ifdef BT_USE_DOUBLE_PRECISION | ||||
| m_arrays.m_collisionObjectDataDouble.push_back((btCollisionObjectDoubleData*)chunk->m_oldPtr); | m_arrays.m_collisionObjectDataDouble.push_back((btCollisionObjectDoubleData*)chunk->m_oldPtr); | ||||
| #else//BT_USE_DOUBLE_PRECISION | #else //BT_USE_DOUBLE_PRECISION | ||||
| m_arrays.m_collisionObjectDataFloat.push_back((btCollisionObjectFloatData*)chunk->m_oldPtr); | m_arrays.m_collisionObjectDataFloat.push_back((btCollisionObjectFloatData*)chunk->m_oldPtr); | ||||
| #endif //BT_USE_DOUBLE_PRECISION | #endif //BT_USE_DOUBLE_PRECISION | ||||
| break; | break; | ||||
| } | } | ||||
| case BT_RIGIDBODY_CODE: | case BT_RIGIDBODY_CODE: | ||||
| { | { | ||||
| #ifdef BT_USE_DOUBLE_PRECISION | #ifdef BT_USE_DOUBLE_PRECISION | ||||
| m_arrays.m_rigidBodyDataDouble.push_back((btRigidBodyDoubleData*)chunk->m_oldPtr); | m_arrays.m_rigidBodyDataDouble.push_back((btRigidBodyDoubleData*)chunk->m_oldPtr); | ||||
| #else | #else | ||||
| m_arrays.m_rigidBodyDataFloat.push_back((btRigidBodyFloatData*)chunk->m_oldPtr); | m_arrays.m_rigidBodyDataFloat.push_back((btRigidBodyFloatData*)chunk->m_oldPtr); | ||||
| #endif//BT_USE_DOUBLE_PRECISION | #endif //BT_USE_DOUBLE_PRECISION | ||||
| break; | break; | ||||
| }; | }; | ||||
| case BT_CONSTRAINT_CODE: | case BT_CONSTRAINT_CODE: | ||||
| { | { | ||||
| #ifdef BT_USE_DOUBLE_PRECISION | #ifdef BT_USE_DOUBLE_PRECISION | ||||
| m_arrays.m_constraintDataDouble.push_back((btTypedConstraintDoubleData*)chunk->m_oldPtr); | m_arrays.m_constraintDataDouble.push_back((btTypedConstraintDoubleData*)chunk->m_oldPtr); | ||||
| #else | #else | ||||
| m_arrays.m_constraintDataFloat.push_back((btTypedConstraintFloatData*)chunk->m_oldPtr); | m_arrays.m_constraintDataFloat.push_back((btTypedConstraintFloatData*)chunk->m_oldPtr); | ||||
| #endif | #endif | ||||
| break; | break; | ||||
| } | } | ||||
| case BT_QUANTIZED_BVH_CODE: | case BT_QUANTIZED_BVH_CODE: | ||||
| { | { | ||||
| #ifdef BT_USE_DOUBLE_PRECISION | #ifdef BT_USE_DOUBLE_PRECISION | ||||
| m_arrays.m_bvhsDouble.push_back((btQuantizedBvhDoubleData*) chunk->m_oldPtr); | m_arrays.m_bvhsDouble.push_back((btQuantizedBvhDoubleData*)chunk->m_oldPtr); | ||||
| #else | #else | ||||
| m_arrays.m_bvhsFloat.push_back((btQuantizedBvhFloatData*) chunk->m_oldPtr); | m_arrays.m_bvhsFloat.push_back((btQuantizedBvhFloatData*)chunk->m_oldPtr); | ||||
| #endif | #endif | ||||
| break; | break; | ||||
| } | } | ||||
| case BT_SHAPE_CODE: | case BT_SHAPE_CODE: | ||||
| { | { | ||||
| btCollisionShapeData* shapeData = (btCollisionShapeData*) chunk->m_oldPtr; | btCollisionShapeData* shapeData = (btCollisionShapeData*)chunk->m_oldPtr; | ||||
| m_arrays.m_colShapeData.push_back(shapeData); | m_arrays.m_colShapeData.push_back(shapeData); | ||||
| break; | break; | ||||
| } | } | ||||
| case BT_TRIANLGE_INFO_MAP: | case BT_TRIANLGE_INFO_MAP: | ||||
| case BT_ARRAY_CODE: | case BT_ARRAY_CODE: | ||||
| case BT_SBMATERIAL_CODE: | case BT_SBMATERIAL_CODE: | ||||
| case BT_SBNODE_CODE: | case BT_SBNODE_CODE: | ||||
| case BT_DYNAMICSWORLD_CODE: | case BT_DYNAMICSWORLD_CODE: | ||||
| case BT_DNA_CODE: | case BT_DNA_CODE: | ||||
| { | { | ||||
| break; | break; | ||||
| } | } | ||||
| default: | default: | ||||
| { | { | ||||
| } | } | ||||
| }; | }; | ||||
| } | } | ||||
| int getNumChunks() const | int getNumChunks() const | ||||
| { | { | ||||
| return m_uid2ChunkPtr.size(); | return m_uid2ChunkPtr.size(); | ||||
| } | } | ||||
| const btChunk* getChunk(int chunkIndex) const | const btChunk* getChunk(int chunkIndex) const | ||||
| { | { | ||||
| return *m_uid2ChunkPtr.getAtIndex(chunkIndex); | return *m_uid2ChunkPtr.getAtIndex(chunkIndex); | ||||
| } | } | ||||
| }; | }; | ||||
| #endif //ENABLE_INMEMORY_SERIALIZER | #endif //ENABLE_INMEMORY_SERIALIZER | ||||
| #endif //BT_SERIALIZER_H | #endif //BT_SERIALIZER_H | ||||