2017-08-01 14:30:58 +02:00
|
|
|
/*
|
|
|
|
Bullet Continuous Collision Detection and Physics Library
|
|
|
|
Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied warranty.
|
|
|
|
In no event will the authors be held liable for any damages arising from the use of this software.
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it freely,
|
|
|
|
subject to the following restrictions:
|
|
|
|
|
|
|
|
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.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BT_SERIALIZER_H
|
|
|
|
#define BT_SERIALIZER_H
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
#include "btScalar.h" // has definitions like SIMD_FORCE_INLINE
|
2017-08-01 14:30:58 +02:00
|
|
|
#include "btHashMap.h"
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
#if !defined(__CELLOS_LV2__) && !defined(__MWERKS__)
|
2017-08-01 14:30:58 +02:00
|
|
|
#include <memory.h>
|
|
|
|
#endif
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
extern char sBulletDNAstr[];
|
|
|
|
extern int sBulletDNAlen;
|
|
|
|
extern char sBulletDNAstr64[];
|
|
|
|
extern int sBulletDNAlen64;
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
SIMD_FORCE_INLINE int btStrLen(const char* str)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
if (!str)
|
|
|
|
return (0);
|
2017-08-01 14:30:58 +02:00
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
while (*str != 0)
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
str++;
|
|
|
|
len++;
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
return len;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class btChunk
|
|
|
|
{
|
|
|
|
public:
|
2019-01-03 14:26:51 +01:00
|
|
|
int m_chunkCode;
|
|
|
|
int m_length;
|
|
|
|
void* m_oldPtr;
|
|
|
|
int m_dna_nr;
|
|
|
|
int m_number;
|
2017-08-01 14:30:58 +02:00
|
|
|
};
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
enum btSerializationFlags
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
BT_SERIALIZE_NO_BVH = 1,
|
|
|
|
BT_SERIALIZE_NO_TRIANGLEINFOMAP = 2,
|
2018-09-07 16:11:04 +02:00
|
|
|
BT_SERIALIZE_NO_DUPLICATE_ASSERT = 4,
|
|
|
|
BT_SERIALIZE_CONTACT_MANIFOLDS = 8,
|
2017-08-01 14:30:58 +02:00
|
|
|
};
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
class btSerializer
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~btSerializer() {}
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual const unsigned char* getBufferPointer() const = 0;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual int getCurrentBufferSize() const = 0;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual btChunk* allocate(size_t size, int numElements) = 0;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual void finalizeChunk(btChunk* chunk, const char* structType, int chunkCode, void* oldPtr) = 0;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual void* findPointer(void* oldPtr) = 0;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual void* getUniquePointer(void* oldPtr) = 0;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual void startSerialization() = 0;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual void finishSerialization() = 0;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual const char* findNameForPointer(const void* ptr) const = 0;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual void registerNameForPointer(const void* ptr, const char* name) = 0;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual void serializeName(const char* ptr) = 0;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual int getSerializationFlags() const = 0;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual void setSerializationFlags(int flags) = 0;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
virtual int getNumChunks() const = 0;
|
|
|
|
|
|
|
|
virtual const btChunk* getChunk(int chunkIndex) const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define BT_HEADER_LENGTH 12
|
2019-01-03 14:26:51 +01:00
|
|
|
#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))
|
2017-08-01 14:30:58 +02:00
|
|
|
#else
|
2019-01-03 14:26:51 +01:00
|
|
|
#define BT_MAKE_ID(a, b, c, d) ((int)(d) << 24 | (int)(c) << 16 | (b) << 8 | (a))
|
2017-08-01 14:30:58 +02:00
|
|
|
#endif
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
#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_COLLISIONOBJECT_CODE BT_MAKE_ID('C', 'O', 'B', 'J')
|
|
|
|
#define BT_RIGIDBODY_CODE BT_MAKE_ID('R', 'B', 'D', 'Y')
|
|
|
|
#define BT_CONSTRAINT_CODE BT_MAKE_ID('C', 'O', 'N', '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_TRIANLGE_INFO_MAP BT_MAKE_ID('T', 'M', '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_SBMATERIAL_CODE BT_MAKE_ID('S', 'B', 'M', 'T')
|
|
|
|
#define BT_SBNODE_CODE BT_MAKE_ID('S', 'B', 'N', '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')
|
|
|
|
|
|
|
|
struct btPointerUid
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
union {
|
|
|
|
void* m_ptr;
|
|
|
|
int m_uniqueIds[2];
|
2017-08-01 14:30:58 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct btBulletSerializedArrays
|
|
|
|
{
|
|
|
|
btBulletSerializedArrays()
|
|
|
|
{
|
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
btAlignedObjectArray<struct btQuantizedBvhDoubleData*> m_bvhsDouble;
|
|
|
|
btAlignedObjectArray<struct btQuantizedBvhFloatData*> m_bvhsFloat;
|
2017-08-01 14:30:58 +02:00
|
|
|
btAlignedObjectArray<struct btCollisionShapeData*> m_colShapeData;
|
|
|
|
btAlignedObjectArray<struct btDynamicsWorldDoubleData*> m_dynamicWorldInfoDataDouble;
|
|
|
|
btAlignedObjectArray<struct btDynamicsWorldFloatData*> m_dynamicWorldInfoDataFloat;
|
|
|
|
btAlignedObjectArray<struct btRigidBodyDoubleData*> m_rigidBodyDataDouble;
|
|
|
|
btAlignedObjectArray<struct btRigidBodyFloatData*> m_rigidBodyDataFloat;
|
|
|
|
btAlignedObjectArray<struct btCollisionObjectDoubleData*> m_collisionObjectDataDouble;
|
|
|
|
btAlignedObjectArray<struct btCollisionObjectFloatData*> m_collisionObjectDataFloat;
|
|
|
|
btAlignedObjectArray<struct btTypedConstraintFloatData*> m_constraintDataFloat;
|
|
|
|
btAlignedObjectArray<struct btTypedConstraintDoubleData*> m_constraintDataDouble;
|
2019-01-03 14:26:51 +01:00
|
|
|
btAlignedObjectArray<struct btTypedConstraintData*> m_constraintData; //for backwards compatibility
|
2017-08-01 14:30:58 +02:00
|
|
|
btAlignedObjectArray<struct btSoftBodyFloatData*> m_softBodyFloatData;
|
|
|
|
btAlignedObjectArray<struct btSoftBodyDoubleData*> m_softBodyDoubleData;
|
|
|
|
};
|
|
|
|
|
|
|
|
///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.
|
2019-01-03 14:26:51 +01:00
|
|
|
class btDefaultSerializer : public btSerializer
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
protected:
|
2019-01-03 14:26:51 +01:00
|
|
|
btAlignedObjectArray<char*> mTypes;
|
|
|
|
btAlignedObjectArray<short*> mStructs;
|
|
|
|
btAlignedObjectArray<short> mTlens;
|
|
|
|
btHashMap<btHashInt, int> mStructReverse;
|
|
|
|
btHashMap<btHashString, int> mTypeLookup;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
btHashMap<btHashPtr, void*> m_chunkP;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
btHashMap<btHashPtr, const char*> m_nameMap;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
btHashMap<btHashPtr, btPointerUid> m_uniquePointers;
|
|
|
|
int m_uniqueIdGenerator;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
int m_totalSize;
|
|
|
|
unsigned char* m_buffer;
|
|
|
|
bool m_ownsBuffer;
|
|
|
|
int m_currentSize;
|
|
|
|
void* m_dna;
|
|
|
|
int m_dnaLength;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
int m_serializationFlags;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
btAlignedObjectArray<btChunk*> m_chunkPtrs;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
protected:
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual void* findPointer(void* oldPtr)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
void** ptr = m_chunkP.find(oldPtr);
|
|
|
|
if (ptr && *ptr)
|
|
|
|
return *ptr;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual void writeDNA()
|
|
|
|
{
|
|
|
|
btChunk* dnaChunk = allocate(m_dnaLength, 1);
|
|
|
|
memcpy(dnaChunk->m_oldPtr, m_dna, m_dnaLength);
|
|
|
|
finalizeChunk(dnaChunk, "DNA1", BT_DNA_CODE, m_dna);
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
int getReverseType(const char* type) const
|
|
|
|
{
|
|
|
|
btHashString key(type);
|
|
|
|
const int* valuePtr = mTypeLookup.find(key);
|
|
|
|
if (valuePtr)
|
|
|
|
return *valuePtr;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
void initDNA(const char* bdnaOrg, int dnalen)
|
|
|
|
{
|
|
|
|
///was already initialized
|
|
|
|
if (m_dna)
|
|
|
|
return;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
int littleEndian = 1;
|
|
|
|
littleEndian = ((char*)&littleEndian)[0];
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
m_dna = btAlignedAlloc(dnalen, 16);
|
|
|
|
memcpy(m_dna, bdnaOrg, dnalen);
|
|
|
|
m_dnaLength = dnalen;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
int* intPtr = 0;
|
|
|
|
short* shtPtr = 0;
|
|
|
|
char* cp = 0;
|
|
|
|
int dataLen = 0;
|
|
|
|
intPtr = (int*)m_dna;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
/*
|
2017-08-01 14:30:58 +02:00
|
|
|
SDNA (4 bytes) (magic number)
|
|
|
|
NAME (4 bytes)
|
|
|
|
<nr> (4 bytes) amount of names (int)
|
|
|
|
<string>
|
|
|
|
<string>
|
|
|
|
*/
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
if (strncmp((const char*)m_dna, "SDNA", 4) == 0)
|
|
|
|
{
|
|
|
|
// skip ++ NAME
|
|
|
|
intPtr++;
|
|
|
|
intPtr++;
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
// Parse names
|
|
|
|
if (!littleEndian)
|
|
|
|
*intPtr = btSwapEndian(*intPtr);
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
dataLen = *intPtr;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
intPtr++;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
cp = (char*)intPtr;
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < dataLen; i++)
|
|
|
|
{
|
|
|
|
while (*cp) cp++;
|
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
cp = btAlignPointer(cp, 4);
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
/*
|
2017-08-01 14:30:58 +02:00
|
|
|
TYPE (4 bytes)
|
|
|
|
<nr> amount of types (int)
|
|
|
|
<string>
|
|
|
|
<string>
|
|
|
|
*/
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
intPtr = (int*)cp;
|
|
|
|
btAssert(strncmp(cp, "TYPE", 4) == 0);
|
|
|
|
intPtr++;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
if (!littleEndian)
|
|
|
|
*intPtr = btSwapEndian(*intPtr);
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
dataLen = *intPtr;
|
|
|
|
intPtr++;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
cp = (char*)intPtr;
|
|
|
|
for (i = 0; i < dataLen; i++)
|
|
|
|
{
|
|
|
|
mTypes.push_back(cp);
|
|
|
|
while (*cp) cp++;
|
|
|
|
cp++;
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
cp = btAlignPointer(cp, 4);
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
/*
|
2017-08-01 14:30:58 +02:00
|
|
|
TLEN (4 bytes)
|
|
|
|
<len> (short) the lengths of types
|
|
|
|
<len>
|
|
|
|
*/
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
// Parse type lens
|
|
|
|
intPtr = (int*)cp;
|
|
|
|
btAssert(strncmp(cp, "TLEN", 4) == 0);
|
|
|
|
intPtr++;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
dataLen = (int)mTypes.size();
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
shtPtr = (short*)intPtr;
|
|
|
|
for (i = 0; i < dataLen; i++, shtPtr++)
|
|
|
|
{
|
|
|
|
if (!littleEndian)
|
|
|
|
shtPtr[0] = btSwapEndian(shtPtr[0]);
|
|
|
|
mTlens.push_back(shtPtr[0]);
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
if (dataLen & 1) shtPtr++;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
/*
|
2017-08-01 14:30:58 +02:00
|
|
|
STRC (4 bytes)
|
|
|
|
<nr> amount of structs (int)
|
|
|
|
<typenr>
|
|
|
|
<nr_of_elems>
|
|
|
|
<typenr>
|
|
|
|
<namenr>
|
|
|
|
<typenr>
|
|
|
|
<namenr>
|
|
|
|
*/
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
intPtr = (int*)shtPtr;
|
|
|
|
cp = (char*)intPtr;
|
|
|
|
btAssert(strncmp(cp, "STRC", 4) == 0);
|
|
|
|
intPtr++;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
if (!littleEndian)
|
|
|
|
*intPtr = btSwapEndian(*intPtr);
|
|
|
|
dataLen = *intPtr;
|
|
|
|
intPtr++;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
shtPtr = (short*)intPtr;
|
|
|
|
for (i = 0; i < dataLen; i++)
|
|
|
|
{
|
|
|
|
mStructs.push_back(shtPtr);
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
if (!littleEndian)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
shtPtr[0] = btSwapEndian(shtPtr[0]);
|
|
|
|
shtPtr[1] = btSwapEndian(shtPtr[1]);
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
int len = shtPtr[1];
|
|
|
|
shtPtr += 2;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
for (int a = 0; a < len; a++, shtPtr += 2)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
shtPtr[0] = btSwapEndian(shtPtr[0]);
|
|
|
|
shtPtr[1] = btSwapEndian(shtPtr[1]);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
else
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
shtPtr += (2 * shtPtr[1]) + 2;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
// build reverse lookups
|
|
|
|
for (i = 0; i < (int)mStructs.size(); i++)
|
|
|
|
{
|
|
|
|
short* strc = mStructs.at(i);
|
|
|
|
mStructReverse.insert(strc[0], i);
|
|
|
|
mTypeLookup.insert(btHashString(mTypes[strc[0]]), i);
|
|
|
|
}
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
public:
|
|
|
|
btHashMap<btHashPtr, void*> m_skipPointers;
|
|
|
|
|
|
|
|
btDefaultSerializer(int totalSize = 0, unsigned char* buffer = 0)
|
|
|
|
: m_uniqueIdGenerator(0),
|
|
|
|
m_totalSize(totalSize),
|
|
|
|
m_currentSize(0),
|
|
|
|
m_dna(0),
|
|
|
|
m_dnaLength(0),
|
|
|
|
m_serializationFlags(0)
|
|
|
|
{
|
|
|
|
if (buffer == 0)
|
|
|
|
{
|
|
|
|
m_buffer = m_totalSize ? (unsigned char*)btAlignedAlloc(totalSize, 16) : 0;
|
|
|
|
m_ownsBuffer = true;
|
|
|
|
}
|
|
|
|
else
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
m_buffer = buffer;
|
|
|
|
m_ownsBuffer = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool VOID_IS_8 = ((sizeof(void*) == 8));
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
#ifdef BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES
|
2019-01-03 14:26:51 +01:00
|
|
|
if (VOID_IS_8)
|
|
|
|
{
|
2017-08-01 14:30:58 +02:00
|
|
|
#if _WIN64
|
2019-01-03 14:26:51 +01:00
|
|
|
initDNA((const char*)sBulletDNAstr64, sBulletDNAlen64);
|
2017-08-01 14:30:58 +02:00
|
|
|
#else
|
2019-01-03 14:26:51 +01:00
|
|
|
btAssert(0);
|
2017-08-01 14:30:58 +02:00
|
|
|
#endif
|
2019-01-03 14:26:51 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-01 14:30:58 +02:00
|
|
|
#ifndef _WIN64
|
2019-01-03 14:26:51 +01:00
|
|
|
initDNA((const char*)sBulletDNAstr, sBulletDNAlen);
|
2017-08-01 14:30:58 +02:00
|
|
|
#else
|
2019-01-03 14:26:51 +01:00
|
|
|
btAssert(0);
|
2017-08-01 14:30:58 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
#else //BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES
|
|
|
|
if (VOID_IS_8)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
initDNA((const char*)sBulletDNAstr64, sBulletDNAlen64);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
else
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
initDNA((const char*)sBulletDNAstr, sBulletDNAlen);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
#endif //BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual ~btDefaultSerializer()
|
|
|
|
{
|
|
|
|
if (m_buffer && m_ownsBuffer)
|
|
|
|
btAlignedFree(m_buffer);
|
|
|
|
if (m_dna)
|
|
|
|
btAlignedFree(m_dna);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int getMemoryDnaSizeInBytes()
|
|
|
|
{
|
|
|
|
const bool VOID_IS_8 = ((sizeof(void*) == 8));
|
|
|
|
|
|
|
|
if (VOID_IS_8)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
return sBulletDNAlen64;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
return sBulletDNAlen;
|
|
|
|
}
|
|
|
|
static const char* getMemoryDna()
|
|
|
|
{
|
|
|
|
const bool VOID_IS_8 = ((sizeof(void*) == 8));
|
|
|
|
if (VOID_IS_8)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
return (const char*)sBulletDNAstr64;
|
|
|
|
}
|
|
|
|
return (const char*)sBulletDNAstr;
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
void insertHeader()
|
|
|
|
{
|
|
|
|
writeHeader(m_buffer);
|
|
|
|
m_currentSize += BT_HEADER_LENGTH;
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
void writeHeader(unsigned char* buffer) const
|
|
|
|
{
|
|
|
|
#ifdef BT_USE_DOUBLE_PRECISION
|
|
|
|
memcpy(buffer, "BULLETd", 7);
|
2017-08-01 14:30:58 +02:00
|
|
|
#else
|
2019-01-03 14:26:51 +01:00
|
|
|
memcpy(buffer, "BULLETf", 7);
|
|
|
|
#endif //BT_USE_DOUBLE_PRECISION
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
int littleEndian = 1;
|
|
|
|
littleEndian = ((char*)&littleEndian)[0];
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
if (sizeof(void*) == 8)
|
|
|
|
{
|
|
|
|
buffer[7] = '-';
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
else
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
buffer[7] = '_';
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
if (littleEndian)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
buffer[8] = 'v';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buffer[8] = 'V';
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2021-09-29 15:47:08 +02:00
|
|
|
buffer[9] = '3';
|
|
|
|
buffer[10] = '1';
|
|
|
|
buffer[11] = '7';
|
2019-01-03 14:26:51 +01:00
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual void startSerialization()
|
|
|
|
{
|
|
|
|
m_uniqueIdGenerator = 1;
|
|
|
|
if (m_totalSize)
|
|
|
|
{
|
|
|
|
unsigned char* buffer = internalAlloc(BT_HEADER_LENGTH);
|
|
|
|
writeHeader(buffer);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual void finishSerialization()
|
|
|
|
{
|
|
|
|
writeDNA();
|
|
|
|
|
|
|
|
//if we didn't pre-allocate a buffer, we need to create a contiguous buffer now
|
|
|
|
if (!m_totalSize)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
if (m_buffer)
|
|
|
|
btAlignedFree(m_buffer);
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
m_currentSize += BT_HEADER_LENGTH;
|
|
|
|
m_buffer = (unsigned char*)btAlignedAlloc(m_currentSize, 16);
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
unsigned char* currentPtr = m_buffer;
|
|
|
|
writeHeader(m_buffer);
|
|
|
|
currentPtr += BT_HEADER_LENGTH;
|
|
|
|
for (int i = 0; i < m_chunkPtrs.size(); i++)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
int curLength = sizeof(btChunk) + m_chunkPtrs[i]->m_length;
|
|
|
|
memcpy(currentPtr, m_chunkPtrs[i], curLength);
|
|
|
|
btAlignedFree(m_chunkPtrs[i]);
|
|
|
|
currentPtr += curLength;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
mTypes.clear();
|
|
|
|
mStructs.clear();
|
|
|
|
mTlens.clear();
|
|
|
|
mStructReverse.clear();
|
|
|
|
mTypeLookup.clear();
|
|
|
|
m_skipPointers.clear();
|
|
|
|
m_chunkP.clear();
|
|
|
|
m_nameMap.clear();
|
|
|
|
m_uniquePointers.clear();
|
|
|
|
m_chunkPtrs.clear();
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual void* getUniquePointer(void* oldPtr)
|
|
|
|
{
|
|
|
|
btAssert(m_uniqueIdGenerator >= 0);
|
|
|
|
if (!oldPtr)
|
|
|
|
return 0;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
btPointerUid* uptr = (btPointerUid*)m_uniquePointers.find(oldPtr);
|
|
|
|
if (uptr)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
return uptr->m_ptr;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
void** ptr2 = m_skipPointers[oldPtr];
|
|
|
|
if (ptr2)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
return 0;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
m_uniqueIdGenerator++;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
btPointerUid uid;
|
|
|
|
uid.m_uniqueIds[0] = m_uniqueIdGenerator;
|
|
|
|
uid.m_uniqueIds[1] = m_uniqueIdGenerator;
|
|
|
|
m_uniquePointers.insert(oldPtr, uid);
|
|
|
|
return uid.m_ptr;
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual const unsigned char* getBufferPointer() const
|
|
|
|
{
|
|
|
|
return m_buffer;
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual int getCurrentBufferSize() const
|
|
|
|
{
|
|
|
|
return m_currentSize;
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual void finalizeChunk(btChunk* chunk, const char* structType, int chunkCode, void* oldPtr)
|
|
|
|
{
|
|
|
|
if (!(m_serializationFlags & BT_SERIALIZE_NO_DUPLICATE_ASSERT))
|
|
|
|
{
|
|
|
|
btAssert(!findPointer(oldPtr));
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
chunk->m_dna_nr = getReverseType(structType);
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
chunk->m_chunkCode = chunkCode;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
void* uniquePtr = getUniquePointer(oldPtr);
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
m_chunkP.insert(oldPtr, uniquePtr); //chunk->m_oldPtr);
|
|
|
|
chunk->m_oldPtr = uniquePtr; //oldPtr;
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual unsigned char* internalAlloc(size_t size)
|
|
|
|
{
|
|
|
|
unsigned char* ptr = 0;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
if (m_totalSize)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
ptr = m_buffer + m_currentSize;
|
|
|
|
m_currentSize += int(size);
|
|
|
|
btAssert(m_currentSize < m_totalSize);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ptr = (unsigned char*)btAlignedAlloc(size, 16);
|
|
|
|
m_currentSize += int(size);
|
|
|
|
}
|
|
|
|
return ptr;
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual btChunk* allocate(size_t size, int numElements)
|
|
|
|
{
|
|
|
|
unsigned char* ptr = internalAlloc(int(size) * numElements + sizeof(btChunk));
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
unsigned char* data = ptr + sizeof(btChunk);
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
btChunk* chunk = (btChunk*)ptr;
|
|
|
|
chunk->m_chunkCode = 0;
|
|
|
|
chunk->m_oldPtr = data;
|
|
|
|
chunk->m_length = int(size) * numElements;
|
|
|
|
chunk->m_number = numElements;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
m_chunkPtrs.push_back(chunk);
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
return chunk;
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual const char* findNameForPointer(const void* ptr) const
|
|
|
|
{
|
|
|
|
const char* const* namePtr = m_nameMap.find(ptr);
|
|
|
|
if (namePtr && *namePtr)
|
|
|
|
return *namePtr;
|
|
|
|
return 0;
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual void registerNameForPointer(const void* ptr, const char* name)
|
|
|
|
{
|
|
|
|
m_nameMap.insert(ptr, name);
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual void serializeName(const char* name)
|
|
|
|
{
|
|
|
|
if (name)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
//don't serialize name twice
|
|
|
|
if (findPointer((void*)name))
|
|
|
|
return;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
int len = btStrLen(name);
|
|
|
|
if (len)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
int newLen = len + 1;
|
|
|
|
int padding = ((newLen + 3) & ~3) - newLen;
|
|
|
|
newLen += padding;
|
|
|
|
|
|
|
|
//serialize name string now
|
|
|
|
btChunk* chunk = allocate(sizeof(char), newLen);
|
|
|
|
char* destinationName = (char*)chunk->m_oldPtr;
|
|
|
|
for (int i = 0; i < len; i++)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
destinationName[i] = name[i];
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
destinationName[len] = 0;
|
|
|
|
finalizeChunk(chunk, "char", BT_ARRAY_CODE, (void*)name);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual int getSerializationFlags() const
|
|
|
|
{
|
|
|
|
return m_serializationFlags;
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual void setSerializationFlags(int flags)
|
|
|
|
{
|
|
|
|
m_serializationFlags = flags;
|
|
|
|
}
|
|
|
|
int getNumChunks() const
|
|
|
|
{
|
|
|
|
return m_chunkPtrs.size();
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
const btChunk* getChunk(int chunkIndex) const
|
|
|
|
{
|
|
|
|
return m_chunkPtrs[chunkIndex];
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
///In general it is best to use btDefaultSerializer,
|
|
|
|
///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 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.
|
|
|
|
#ifdef ENABLE_INMEMORY_SERIALIZER
|
|
|
|
|
|
|
|
struct btInMemorySerializer : public btDefaultSerializer
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
btHashMap<btHashPtr, btChunk*> m_uid2ChunkPtr;
|
|
|
|
btHashMap<btHashPtr, void*> m_orgPtr2UniqueDataPtr;
|
|
|
|
btHashMap<btHashString, const void*> m_names2Ptr;
|
|
|
|
|
|
|
|
btBulletSerializedArrays m_arrays;
|
|
|
|
|
|
|
|
btInMemorySerializer(int totalSize = 0, unsigned char* buffer = 0)
|
|
|
|
: btDefaultSerializer(totalSize, buffer)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void startSerialization()
|
|
|
|
{
|
|
|
|
m_uid2ChunkPtr.clear();
|
|
|
|
//todo: m_arrays.clear();
|
|
|
|
btDefaultSerializer::startSerialization();
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
btChunk* findChunkFromUniquePointer(void* uniquePointer)
|
|
|
|
{
|
|
|
|
btChunk** chkPtr = m_uid2ChunkPtr[uniquePointer];
|
|
|
|
if (chkPtr)
|
|
|
|
{
|
|
|
|
return *chkPtr;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual void registerNameForPointer(const void* ptr, const char* name)
|
|
|
|
{
|
|
|
|
btDefaultSerializer::registerNameForPointer(ptr, name);
|
|
|
|
m_names2Ptr.insert(name, ptr);
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual void finishSerialization()
|
|
|
|
{
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual void* getUniquePointer(void* oldPtr)
|
|
|
|
{
|
|
|
|
if (oldPtr == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// void* uniquePtr = getUniquePointer(oldPtr);
|
|
|
|
btChunk* chunk = findChunkFromUniquePointer(oldPtr);
|
|
|
|
if (chunk)
|
|
|
|
{
|
|
|
|
return chunk->m_oldPtr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char* n = (const char*)oldPtr;
|
|
|
|
const void** ptr = m_names2Ptr[n];
|
|
|
|
if (ptr)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
return oldPtr;
|
|
|
|
}
|
|
|
|
else
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
void** ptr2 = m_skipPointers[oldPtr];
|
|
|
|
if (ptr2)
|
|
|
|
{
|
|
|
|
return 0;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
else
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
//If this assert hit, serialization happened in the wrong order
|
|
|
|
// 'getUniquePointer'
|
|
|
|
btAssert(0);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
2019-01-03 14:26:51 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return oldPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void finalizeChunk(btChunk* chunk, const char* structType, int chunkCode, void* oldPtr)
|
|
|
|
{
|
|
|
|
if (!(m_serializationFlags & BT_SERIALIZE_NO_DUPLICATE_ASSERT))
|
|
|
|
{
|
|
|
|
btAssert(!findPointer(oldPtr));
|
|
|
|
}
|
|
|
|
|
|
|
|
chunk->m_dna_nr = getReverseType(structType);
|
|
|
|
chunk->m_chunkCode = chunkCode;
|
|
|
|
//void* uniquePtr = getUniquePointer(oldPtr);
|
|
|
|
m_chunkP.insert(oldPtr, oldPtr); //chunk->m_oldPtr);
|
|
|
|
// chunk->m_oldPtr = uniquePtr;//oldPtr;
|
|
|
|
|
|
|
|
void* uid = findPointer(oldPtr);
|
|
|
|
m_uid2ChunkPtr.insert(uid, chunk);
|
|
|
|
|
|
|
|
switch (chunk->m_chunkCode)
|
|
|
|
{
|
|
|
|
case BT_SOFTBODY_CODE:
|
|
|
|
{
|
|
|
|
#ifdef BT_USE_DOUBLE_PRECISION
|
|
|
|
m_arrays.m_softBodyDoubleData.push_back((btSoftBodyDoubleData*)chunk->m_oldPtr);
|
|
|
|
#else
|
|
|
|
m_arrays.m_softBodyFloatData.push_back((btSoftBodyFloatData*)chunk->m_oldPtr);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BT_COLLISIONOBJECT_CODE:
|
|
|
|
{
|
|
|
|
#ifdef BT_USE_DOUBLE_PRECISION
|
|
|
|
m_arrays.m_collisionObjectDataDouble.push_back((btCollisionObjectDoubleData*)chunk->m_oldPtr);
|
|
|
|
#else //BT_USE_DOUBLE_PRECISION
|
|
|
|
m_arrays.m_collisionObjectDataFloat.push_back((btCollisionObjectFloatData*)chunk->m_oldPtr);
|
|
|
|
#endif //BT_USE_DOUBLE_PRECISION
|
|
|
|
break;
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
case BT_RIGIDBODY_CODE:
|
2019-01-03 14:26:51 +01:00
|
|
|
{
|
|
|
|
#ifdef BT_USE_DOUBLE_PRECISION
|
|
|
|
m_arrays.m_rigidBodyDataDouble.push_back((btRigidBodyDoubleData*)chunk->m_oldPtr);
|
|
|
|
#else
|
|
|
|
m_arrays.m_rigidBodyDataFloat.push_back((btRigidBodyFloatData*)chunk->m_oldPtr);
|
|
|
|
#endif //BT_USE_DOUBLE_PRECISION
|
|
|
|
break;
|
|
|
|
};
|
2017-08-01 14:30:58 +02:00
|
|
|
case BT_CONSTRAINT_CODE:
|
2019-01-03 14:26:51 +01:00
|
|
|
{
|
|
|
|
#ifdef BT_USE_DOUBLE_PRECISION
|
|
|
|
m_arrays.m_constraintDataDouble.push_back((btTypedConstraintDoubleData*)chunk->m_oldPtr);
|
|
|
|
#else
|
|
|
|
m_arrays.m_constraintDataFloat.push_back((btTypedConstraintFloatData*)chunk->m_oldPtr);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
case BT_QUANTIZED_BVH_CODE:
|
2019-01-03 14:26:51 +01:00
|
|
|
{
|
|
|
|
#ifdef BT_USE_DOUBLE_PRECISION
|
|
|
|
m_arrays.m_bvhsDouble.push_back((btQuantizedBvhDoubleData*)chunk->m_oldPtr);
|
|
|
|
#else
|
|
|
|
m_arrays.m_bvhsFloat.push_back((btQuantizedBvhFloatData*)chunk->m_oldPtr);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
case BT_SHAPE_CODE:
|
2019-01-03 14:26:51 +01:00
|
|
|
{
|
|
|
|
btCollisionShapeData* shapeData = (btCollisionShapeData*)chunk->m_oldPtr;
|
|
|
|
m_arrays.m_colShapeData.push_back(shapeData);
|
|
|
|
break;
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
case BT_TRIANLGE_INFO_MAP:
|
|
|
|
case BT_ARRAY_CODE:
|
|
|
|
case BT_SBMATERIAL_CODE:
|
|
|
|
case BT_SBNODE_CODE:
|
|
|
|
case BT_DYNAMICSWORLD_CODE:
|
|
|
|
case BT_DNA_CODE:
|
2019-01-03 14:26:51 +01:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
default:
|
2019-01-03 14:26:51 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
int getNumChunks() const
|
|
|
|
{
|
|
|
|
return m_uid2ChunkPtr.size();
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
const btChunk* getChunk(int chunkIndex) const
|
|
|
|
{
|
|
|
|
return *m_uid2ChunkPtr.getAtIndex(chunkIndex);
|
|
|
|
}
|
2017-08-01 14:30:58 +02:00
|
|
|
};
|
2019-01-03 14:26:51 +01:00
|
|
|
#endif //ENABLE_INMEMORY_SERIALIZER
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
#endif //BT_SERIALIZER_H
|