16 #ifndef BT_SERIALIZER_H 17 #define BT_SERIALIZER_H 22 #if !defined( __CELLOS_LV2__) && !defined(__MWERKS__) 75 virtual const unsigned char* getBufferPointer()
const = 0;
77 virtual int getCurrentBufferSize()
const = 0;
79 virtual btChunk* allocate(
size_t size,
int numElements) = 0;
81 virtual void finalizeChunk(
btChunk* chunk,
const char* structType,
int chunkCode,
void* oldPtr)= 0;
83 virtual void* findPointer(
void* oldPtr) = 0;
85 virtual void* getUniquePointer(
void*oldPtr) = 0;
87 virtual void startSerialization() = 0;
89 virtual void finishSerialization() = 0;
91 virtual const char* findNameForPointer(
const void* ptr)
const = 0;
93 virtual void registerNameForPointer(
const void* ptr,
const char* name) = 0;
95 virtual void serializeName(
const char* ptr) = 0;
97 virtual int getSerializationFlags()
const = 0;
99 virtual void setSerializationFlags(
int flags) = 0;
101 virtual int getNumChunks()
const = 0;
103 virtual const btChunk* getChunk(
int chunkIndex)
const = 0;
109 #define BT_HEADER_LENGTH 12 110 #if defined(__sgi) || defined (__sparc) || defined (__sparc__) || defined (__PPC__) || defined (__ppc__) || defined (__BIG_ENDIAN__) 111 # define BT_MAKE_ID(a,b,c,d) ( (int)(a)<<24 | (int)(b)<<16 | (c)<<8 | (d) ) 113 # define BT_MAKE_ID(a,b,c,d) ( (int)(d)<<24 | (int)(c)<<16 | (b)<<8 | (a) ) 116 #define BT_SOFTBODY_CODE BT_MAKE_ID('S','B','D','Y') 117 #define BT_COLLISIONOBJECT_CODE BT_MAKE_ID('C','O','B','J') 118 #define BT_RIGIDBODY_CODE BT_MAKE_ID('R','B','D','Y') 119 #define BT_CONSTRAINT_CODE BT_MAKE_ID('C','O','N','S') 120 #define BT_BOXSHAPE_CODE BT_MAKE_ID('B','O','X','S') 121 #define BT_QUANTIZED_BVH_CODE BT_MAKE_ID('Q','B','V','H') 122 #define BT_TRIANLGE_INFO_MAP BT_MAKE_ID('T','M','A','P') 123 #define BT_SHAPE_CODE BT_MAKE_ID('S','H','A','P') 124 #define BT_ARRAY_CODE BT_MAKE_ID('A','R','A','Y') 125 #define BT_SBMATERIAL_CODE BT_MAKE_ID('S','B','M','T') 126 #define BT_SBNODE_CODE BT_MAKE_ID('S','B','N','D') 127 #define BT_DYNAMICSWORLD_CODE BT_MAKE_ID('D','W','L','D') 128 #define BT_DNA_CODE BT_MAKE_ID('D','N','A','1') 199 void** ptr = m_chunkP.
find(oldPtr);
211 btChunk* dnaChunk = allocate(m_dnaLength,1);
212 memcpy(dnaChunk->
m_oldPtr,m_dna,m_dnaLength);
220 const int* valuePtr = mTypeLookup.
find(key);
234 littleEndian= ((
char*)&littleEndian)[0];
238 memcpy(m_dna,bdnaOrg,dnalen);
239 m_dnaLength = dnalen;
243 char *cp = 0;
int dataLen =0;
244 intPtr = (
int*)m_dna;
254 if (strncmp((
const char*)m_dna,
"SDNA", 4)==0)
270 for ( i=0; i<dataLen; i++)
286 btAssert(strncmp(cp,
"TYPE", 4)==0); intPtr++;
296 for (i=0; i<dataLen; i++)
314 btAssert(strncmp(cp,
"TLEN", 4)==0); intPtr++;
316 dataLen = (int)mTypes.
size();
318 shtPtr = (
short*)intPtr;
319 for (i=0; i<dataLen; i++, shtPtr++)
326 if (dataLen & 1) shtPtr++;
339 intPtr = (
int*)shtPtr;
341 btAssert(strncmp(cp,
"STRC", 4)==0); intPtr++;
349 shtPtr = (
short*)intPtr;
350 for (i=0; i<dataLen; i++)
362 for (
int a=0; a<len; a++, shtPtr+=2)
370 shtPtr+= (2*shtPtr[1])+2;
375 for (i=0; i<(int)mStructs.
size(); i++)
377 short *strc = mStructs.
at(i);
378 mStructReverse.
insert(strc[0], i);
389 :m_totalSize(totalSize),
393 m_serializationFlags(0)
395 m_buffer = m_totalSize?(
unsigned char*)
btAlignedAlloc(totalSize,16):0;
397 const bool VOID_IS_8 = ((
sizeof(
void*)==8));
399 #ifdef BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES 416 #else //BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES 424 #endif //BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES 440 #ifdef BT_USE_DOUBLE_PRECISION 441 memcpy(buffer,
"BULLETd", 7);
443 memcpy(buffer,
"BULLETf", 7);
444 #endif //BT_USE_DOUBLE_PRECISION 447 littleEndian= ((
char*)&littleEndian)[0];
449 if (
sizeof(
void*)==8)
474 m_uniqueIdGenerator= 1;
497 unsigned char* currentPtr = m_buffer;
498 writeHeader(m_buffer);
501 for (
int i=0;i< m_chunkPtrs.
size();i++)
504 memcpy(currentPtr,m_chunkPtrs[i], curLength);
506 currentPtr+=curLength;
514 mStructReverse.
clear();
518 m_uniquePointers.
clear();
532 m_uniqueIdGenerator++;
537 m_uniquePointers.
insert(oldPtr,uid);
549 return m_currentSize;
559 chunk->
m_dna_nr = getReverseType(structType);
563 void* uniquePtr = getUniquePointer(oldPtr);
565 m_chunkP.
insert(oldPtr,uniquePtr);
573 unsigned char* ptr = 0;
577 ptr = m_buffer+m_currentSize;
578 m_currentSize += int(size);
579 btAssert(m_currentSize<m_totalSize);
583 m_currentSize += int(size);
593 unsigned char* ptr = internalAlloc(
int(size)*numElements+
sizeof(
btChunk));
595 unsigned char* data = ptr +
sizeof(
btChunk);
599 chunk->m_oldPtr = data;
600 chunk->m_length = int(size)*numElements;
601 chunk->m_number = numElements;
611 const char*
const * namePtr = m_nameMap.
find(ptr);
612 if (namePtr && *namePtr)
620 m_nameMap.
insert(ptr,name);
628 if (findPointer((
void*)name))
636 int padding = ((newLen+3)&~3)-newLen;
640 btChunk* chunk = allocate(
sizeof(
char),newLen);
641 char* destinationName = (
char*)chunk->
m_oldPtr;
642 for (
int i=0;i<len;i++)
644 destinationName[i] = name[i];
646 destinationName[len] = 0;
654 return m_serializationFlags;
659 m_serializationFlags = flags;
663 return m_chunkPtrs.
size();
668 return m_chunkPtrs[chunkIndex];
678 #ifdef ENABLE_INMEMORY_SERIALIZER 690 virtual void startSerialization()
692 m_uid2ChunkPtr.
clear();
697 btChunk* findChunkFromUniquePointer(
void* uniquePointer)
699 btChunk** chkPtr = m_uid2ChunkPtr[uniquePointer];
707 virtual void registerNameForPointer(
const void* ptr,
const char* name)
710 m_names2Ptr.
insert(name,ptr);
713 virtual void finishSerialization()
717 virtual void* getUniquePointer(
void*oldPtr)
723 btChunk* chunk = findChunkFromUniquePointer(oldPtr);
729 const char* n = (
const char*) oldPtr;
730 const void** ptr = m_names2Ptr[n];
736 void** ptr2 = m_skipPointers[oldPtr];
753 virtual void finalizeChunk(
btChunk* chunk,
const char* structType,
int chunkCode,
void* oldPtr)
760 chunk->
m_dna_nr = getReverseType(structType);
763 m_chunkP.insert(oldPtr,oldPtr);
766 void* uid = findPointer(oldPtr);
767 m_uid2ChunkPtr.
insert(uid,chunk);
773 #ifdef BT_USE_DOUBLE_PRECISION 782 #ifdef BT_USE_DOUBLE_PRECISION 784 #else//BT_USE_DOUBLE_PRECISION 786 #endif //BT_USE_DOUBLE_PRECISION 791 #ifdef BT_USE_DOUBLE_PRECISION 795 #endif//BT_USE_DOUBLE_PRECISION 800 #ifdef BT_USE_DOUBLE_PRECISION 809 #ifdef BT_USE_DOUBLE_PRECISION 838 int getNumChunks()
const 840 return m_uid2ChunkPtr.
size();
843 const btChunk* getChunk(
int chunkIndex)
const 845 return *m_uid2ChunkPtr.
getAtIndex(chunkIndex);
849 #endif //ENABLE_INMEMORY_SERIALIZER 851 #endif //BT_SERIALIZER_H
btAlignedObjectArray< struct btRigidBodyDoubleData * > m_rigidBodyDataDouble
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 void setSerializationFlags(int flags)
#define BT_CONSTRAINT_CODE
virtual void finalizeChunk(btChunk *chunk, const char *structType, int chunkCode, void *oldPtr)
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
btHashMap< btHashPtr, const char * > m_nameMap
virtual void registerNameForPointer(const void *ptr, const char *name)
const Value * find(const Key &key) const
btAlignedObjectArray< struct btDynamicsWorldFloatData * > m_dynamicWorldInfoDataFloat
btAlignedObjectArray< struct btQuantizedBvhFloatData * > m_bvhsFloat
#define BT_QUANTIZED_BVH_CODE
btAlignedObjectArray< struct btQuantizedBvhDoubleData * > m_bvhsDouble
virtual btChunk * allocate(size_t size, int numElements)
btAlignedObjectArray< struct btDynamicsWorldDoubleData * > m_dynamicWorldInfoDataDouble
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
const T & at(int n) const
#define BT_DYNAMICSWORLD_CODE
#define SIMD_FORCE_INLINE
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
const Value * getAtIndex(int index) const
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.
virtual const char * findNameForPointer(const void *ptr) const
btAlignedObjectArray< struct btTypedConstraintFloatData * > m_constraintDataFloat
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
virtual unsigned char * internalAlloc(size_t size)
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)
virtual const unsigned char * getBufferPointer() const
int size() const
return the number of elements in the array
btAlignedObjectArray< struct btCollisionObjectDoubleData * > m_collisionObjectDataDouble
very basic hashable string implementation, compatible with btHashMap
int getReverseType(const char *type) const
#define BT_SBMATERIAL_CODE
btAlignedObjectArray< struct btRigidBodyFloatData * > m_rigidBodyDataFloat
#define BT_RIGIDBODY_CODE
virtual void startSerialization()
void writeHeader(unsigned char *buffer) const
btAlignedObjectArray< short > mTlens
unsigned btSwapEndian(unsigned val)
#define btAlignedAlloc(size, alignment)
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
char sBulletDNAstr[]
only the 32bit versions for now
virtual int getSerializationFlags() const
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 ...
virtual int getCurrentBufferSize() const
const btChunk * getChunk(int chunkIndex) const