16 #ifndef BT_SERIALIZER_H 17 #define BT_SERIALIZER_H 22 #if !defined( __CELLOS_LV2__) && !defined(__MWERKS__) 76 virtual const unsigned char* getBufferPointer()
const = 0;
78 virtual int getCurrentBufferSize()
const = 0;
80 virtual btChunk* allocate(
size_t size,
int numElements) = 0;
82 virtual void finalizeChunk(
btChunk* chunk,
const char* structType,
int chunkCode,
void* oldPtr)= 0;
84 virtual void* findPointer(
void* oldPtr) = 0;
86 virtual void* getUniquePointer(
void*oldPtr) = 0;
88 virtual void startSerialization() = 0;
90 virtual void finishSerialization() = 0;
92 virtual const char* findNameForPointer(
const void* ptr)
const = 0;
94 virtual void registerNameForPointer(
const void* ptr,
const char* name) = 0;
96 virtual void serializeName(
const char* ptr) = 0;
98 virtual int getSerializationFlags()
const = 0;
100 virtual void setSerializationFlags(
int flags) = 0;
102 virtual int getNumChunks()
const = 0;
104 virtual const btChunk* getChunk(
int chunkIndex)
const = 0;
110 #define BT_HEADER_LENGTH 12 111 #if defined(__sgi) || defined (__sparc) || defined (__sparc__) || defined (__PPC__) || defined (__ppc__) || defined (__BIG_ENDIAN__) 112 # define BT_MAKE_ID(a,b,c,d) ( (int)(a)<<24 | (int)(b)<<16 | (c)<<8 | (d) ) 114 # define BT_MAKE_ID(a,b,c,d) ( (int)(d)<<24 | (int)(c)<<16 | (b)<<8 | (a) ) 118 #define BT_MULTIBODY_CODE BT_MAKE_ID('M','B','D','Y') 119 #define BT_MB_LINKCOLLIDER_CODE BT_MAKE_ID('M','B','L','C') 120 #define BT_SOFTBODY_CODE BT_MAKE_ID('S','B','D','Y') 121 #define BT_COLLISIONOBJECT_CODE BT_MAKE_ID('C','O','B','J') 122 #define BT_RIGIDBODY_CODE BT_MAKE_ID('R','B','D','Y') 123 #define BT_CONSTRAINT_CODE BT_MAKE_ID('C','O','N','S') 124 #define BT_BOXSHAPE_CODE BT_MAKE_ID('B','O','X','S') 125 #define BT_QUANTIZED_BVH_CODE BT_MAKE_ID('Q','B','V','H') 126 #define BT_TRIANLGE_INFO_MAP BT_MAKE_ID('T','M','A','P') 127 #define BT_SHAPE_CODE BT_MAKE_ID('S','H','A','P') 128 #define BT_ARRAY_CODE BT_MAKE_ID('A','R','A','Y') 129 #define BT_SBMATERIAL_CODE BT_MAKE_ID('S','B','M','T') 130 #define BT_SBNODE_CODE BT_MAKE_ID('S','B','N','D') 131 #define BT_DYNAMICSWORLD_CODE BT_MAKE_ID('D','W','L','D') 132 #define BT_CONTACTMANIFOLD_CODE BT_MAKE_ID('C','O','N','T') 133 #define BT_DNA_CODE BT_MAKE_ID('D','N','A','1') 206 void** ptr = m_chunkP.
find(oldPtr);
218 btChunk* dnaChunk = allocate(m_dnaLength,1);
219 memcpy(dnaChunk->
m_oldPtr,m_dna,m_dnaLength);
227 const int* valuePtr = mTypeLookup.
find(key);
241 littleEndian= ((
char*)&littleEndian)[0];
245 memcpy(m_dna,bdnaOrg,dnalen);
246 m_dnaLength = dnalen;
250 char *cp = 0;
int dataLen =0;
251 intPtr = (
int*)m_dna;
261 if (strncmp((
const char*)m_dna,
"SDNA", 4)==0)
277 for ( i=0; i<dataLen; i++)
293 btAssert(strncmp(cp,
"TYPE", 4)==0); intPtr++;
303 for (i=0; i<dataLen; i++)
321 btAssert(strncmp(cp,
"TLEN", 4)==0); intPtr++;
323 dataLen = (int)mTypes.
size();
325 shtPtr = (
short*)intPtr;
326 for (i=0; i<dataLen; i++, shtPtr++)
333 if (dataLen & 1) shtPtr++;
346 intPtr = (
int*)shtPtr;
348 btAssert(strncmp(cp,
"STRC", 4)==0); intPtr++;
356 shtPtr = (
short*)intPtr;
357 for (i=0; i<dataLen; i++)
369 for (
int a=0; a<len; a++, shtPtr+=2)
377 shtPtr+= (2*shtPtr[1])+2;
382 for (i=0; i<(int)mStructs.
size(); i++)
384 short *strc = mStructs.
at(i);
385 mStructReverse.
insert(strc[0], i);
396 :m_uniqueIdGenerator(0),
397 m_totalSize(totalSize),
401 m_serializationFlags(0)
405 m_buffer = m_totalSize?(
unsigned char*)
btAlignedAlloc(totalSize,16):0;
410 m_ownsBuffer =
false;
413 const bool VOID_IS_8 = ((
sizeof(
void*)==8));
415 #ifdef BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES 432 #else //BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES 440 #endif //BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES 446 if (m_buffer && m_ownsBuffer)
454 const bool VOID_IS_8 = ((
sizeof(
void*) == 8));
464 const bool VOID_IS_8 = ((
sizeof(
void*) == 8));
474 writeHeader(m_buffer);
482 #ifdef BT_USE_DOUBLE_PRECISION 483 memcpy(buffer,
"BULLETd", 7);
485 memcpy(buffer,
"BULLETf", 7);
486 #endif //BT_USE_DOUBLE_PRECISION 489 littleEndian= ((
char*)&littleEndian)[0];
491 if (
sizeof(
void*)==8)
516 m_uniqueIdGenerator= 1;
539 unsigned char* currentPtr = m_buffer;
540 writeHeader(m_buffer);
543 for (
int i=0;i< m_chunkPtrs.
size();i++)
546 memcpy(currentPtr,m_chunkPtrs[i], curLength);
548 currentPtr+=curLength;
556 mStructReverse.
clear();
558 m_skipPointers.
clear();
561 m_uniquePointers.
clear();
577 void** ptr2 = m_skipPointers[oldPtr];
583 m_uniqueIdGenerator++;
588 m_uniquePointers.
insert(oldPtr,uid);
600 return m_currentSize;
610 chunk->
m_dna_nr = getReverseType(structType);
614 void* uniquePtr = getUniquePointer(oldPtr);
616 m_chunkP.
insert(oldPtr,uniquePtr);
624 unsigned char* ptr = 0;
628 ptr = m_buffer+m_currentSize;
629 m_currentSize += int(size);
630 btAssert(m_currentSize<m_totalSize);
634 m_currentSize += int(size);
644 unsigned char* ptr = internalAlloc(
int(size)*numElements+
sizeof(
btChunk));
646 unsigned char* data = ptr +
sizeof(
btChunk);
650 chunk->m_oldPtr = data;
651 chunk->m_length = int(size)*numElements;
652 chunk->m_number = numElements;
662 const char*
const * namePtr = m_nameMap.
find(ptr);
663 if (namePtr && *namePtr)
671 m_nameMap.
insert(ptr,name);
679 if (findPointer((
void*)name))
687 int padding = ((newLen+3)&~3)-newLen;
691 btChunk* chunk = allocate(
sizeof(
char),newLen);
692 char* destinationName = (
char*)chunk->
m_oldPtr;
693 for (
int i=0;i<len;i++)
695 destinationName[i] = name[i];
697 destinationName[len] = 0;
705 return m_serializationFlags;
710 m_serializationFlags = flags;
714 return m_chunkPtrs.
size();
719 return m_chunkPtrs[chunkIndex];
729 #ifdef ENABLE_INMEMORY_SERIALIZER 740 btInMemorySerializer(
int totalSize=0,
unsigned char* buffer=0)
746 virtual void startSerialization()
748 m_uid2ChunkPtr.
clear();
755 btChunk* findChunkFromUniquePointer(
void* uniquePointer)
757 btChunk** chkPtr = m_uid2ChunkPtr[uniquePointer];
765 virtual void registerNameForPointer(
const void* ptr,
const char* name)
768 m_names2Ptr.
insert(name,ptr);
771 virtual void finishSerialization()
775 virtual void* getUniquePointer(
void*oldPtr)
781 btChunk* chunk = findChunkFromUniquePointer(oldPtr);
787 const char* n = (
const char*) oldPtr;
788 const void** ptr = m_names2Ptr[n];
794 void** ptr2 = m_skipPointers[oldPtr];
811 virtual void finalizeChunk(
btChunk* chunk,
const char* structType,
int chunkCode,
void* oldPtr)
818 chunk->
m_dna_nr = getReverseType(structType);
821 m_chunkP.insert(oldPtr,oldPtr);
824 void* uid = findPointer(oldPtr);
825 m_uid2ChunkPtr.
insert(uid,chunk);
831 #ifdef BT_USE_DOUBLE_PRECISION 840 #ifdef BT_USE_DOUBLE_PRECISION 842 #else//BT_USE_DOUBLE_PRECISION 844 #endif //BT_USE_DOUBLE_PRECISION 849 #ifdef BT_USE_DOUBLE_PRECISION 853 #endif//BT_USE_DOUBLE_PRECISION 858 #ifdef BT_USE_DOUBLE_PRECISION 867 #ifdef BT_USE_DOUBLE_PRECISION 896 int getNumChunks()
const 898 return m_uid2ChunkPtr.
size();
901 const btChunk* getChunk(
int chunkIndex)
const 903 return *m_uid2ChunkPtr.
getAtIndex(chunkIndex);
907 #endif //ENABLE_INMEMORY_SERIALIZER 909 #endif //BT_SERIALIZER_H
btAlignedObjectArray< struct btRigidBodyDoubleData * > m_rigidBodyDataDouble
static int getMemoryDnaSizeInBytes()
virtual int getCurrentBufferSize() const
virtual void serializeName(const char *name)
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
btAlignedObjectArray< btChunk * > m_chunkPtrs
void push_back(const T &_Val)
virtual int getSerializationFlags() const
virtual void setSerializationFlags(int flags)
#define BT_CONSTRAINT_CODE
virtual const unsigned char * getBufferPointer() const
virtual void finalizeChunk(btChunk *chunk, const char *structType, int chunkCode, void *oldPtr)
btHashMap< btHashPtr, const char * > m_nameMap
const T & at(int n) const
virtual void registerNameForPointer(const void *ptr, const char *name)
btAlignedObjectArray< struct btDynamicsWorldFloatData * > m_dynamicWorldInfoDataFloat
btAlignedObjectArray< struct btQuantizedBvhFloatData * > m_bvhsFloat
#define BT_QUANTIZED_BVH_CODE
btAlignedObjectArray< struct btQuantizedBvhDoubleData * > m_bvhsDouble
void writeHeader(unsigned char *buffer) const
virtual btChunk * allocate(size_t size, int numElements)
btAlignedObjectArray< struct btDynamicsWorldDoubleData * > m_dynamicWorldInfoDataDouble
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
#define BT_DYNAMICSWORLD_CODE
#define SIMD_FORCE_INLINE
static const char * getMemoryDna()
btAlignedObjectArray< struct btSoftBodyDoubleData * > m_softBodyDoubleData
virtual void finishSerialization()
btHashMap< btHashString, int > mTypeLookup
virtual void * findPointer(void *oldPtr)
virtual void * getUniquePointer(void *oldPtr)
btHashMap< btHashInt, int > mStructReverse
void clear()
clear the array, deallocated memory. Generally it is better to use array.resize(0), to reduce performance overhead of run-time memory (de)allocations.
The btDefaultSerializer is the main Bullet serialization class.
btAlignedObjectArray< struct btTypedConstraintFloatData * > m_constraintDataFloat
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
const btChunk * getChunk(int chunkIndex) const
virtual unsigned char * internalAlloc(size_t size)
int size() const
return the number of elements in the array
btAlignedObjectArray< struct btCollisionObjectFloatData * > m_collisionObjectDataFloat
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
btAlignedObjectArray< struct btCollisionShapeData * > m_colShapeData
btAlignedObjectArray< struct btTypedConstraintData * > m_constraintData
void initDNA(const char *bdnaOrg, int dnalen)
btAlignedObjectArray< short * > mStructs
#define btAlignedFree(ptr)
void insert(const Key &key, const Value &value)
btBulletSerializedArrays()
btAlignedObjectArray< char * > mTypes
btAlignedObjectArray< struct btSoftBodyFloatData * > m_softBodyFloatData
int btStrLen(const char *str)
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
#define BT_COLLISIONOBJECT_CODE
btDefaultSerializer(int totalSize=0, unsigned char *buffer=0)
const Value * find(const Key &key) const
const Value * getAtIndex(int index) const
btAlignedObjectArray< struct btCollisionObjectDoubleData * > m_collisionObjectDataDouble
btHashMap< btHashPtr, void * > m_skipPointers
very basic hashable string implementation, compatible with btHashMap
#define BT_SBMATERIAL_CODE
virtual const char * findNameForPointer(const void *ptr) const
btAlignedObjectArray< struct btRigidBodyFloatData * > m_rigidBodyDataFloat
#define BT_RIGIDBODY_CODE
virtual void startSerialization()
btAlignedObjectArray< short > mTlens
unsigned btSwapEndian(unsigned val)
#define btAlignedAlloc(size, alignment)
int getReverseType(const char *type) const
T * btAlignPointer(T *unalignedPtr, size_t alignment)
align a pointer to the provided alignment, upwards
#define BT_TRIANLGE_INFO_MAP
btHashMap< btHashPtr, btPointerUid > m_uniquePointers
virtual ~btDefaultSerializer()
btHashMap< btHashPtr, void * > m_chunkP
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
btAlignedObjectArray< struct btTypedConstraintDoubleData * > m_constraintDataDouble
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...