16 #ifndef BT_SERIALIZER_H
17 #define BT_SERIALIZER_H
22 #if !defined( __CELLOS_LV2__) && !defined(__MWERKS__)
81 virtual void finalizeChunk(
btChunk* chunk,
const char* structType,
int chunkCode,
void* oldPtr)= 0;
106 #define BT_HEADER_LENGTH 12
107 #if defined(__sgi) || defined (__sparc) || defined (__sparc__) || defined (__PPC__) || defined (__ppc__) || defined (__BIG_ENDIAN__)
108 # define BT_MAKE_ID(a,b,c,d) ( (int)(a)<<24 | (int)(b)<<16 | (c)<<8 | (d) )
110 # define BT_MAKE_ID(a,b,c,d) ( (int)(d)<<24 | (int)(c)<<16 | (b)<<8 | (a) )
113 #define BT_SOFTBODY_CODE BT_MAKE_ID('S','B','D','Y')
114 #define BT_COLLISIONOBJECT_CODE BT_MAKE_ID('C','O','B','J')
115 #define BT_RIGIDBODY_CODE BT_MAKE_ID('R','B','D','Y')
116 #define BT_CONSTRAINT_CODE BT_MAKE_ID('C','O','N','S')
117 #define BT_BOXSHAPE_CODE BT_MAKE_ID('B','O','X','S')
118 #define BT_QUANTIZED_BVH_CODE BT_MAKE_ID('Q','B','V','H')
119 #define BT_TRIANLGE_INFO_MAP BT_MAKE_ID('T','M','A','P')
120 #define BT_SHAPE_CODE BT_MAKE_ID('S','H','A','P')
121 #define BT_ARRAY_CODE BT_MAKE_ID('A','R','A','Y')
122 #define BT_SBMATERIAL_CODE BT_MAKE_ID('S','B','M','T')
123 #define BT_SBNODE_CODE BT_MAKE_ID('S','B','N','D')
124 #define BT_DYNAMICSWORLD_CODE BT_MAKE_ID('D','W','L','D')
125 #define BT_DNA_CODE BT_MAKE_ID('D','N','A','1')
207 littleEndian= ((
char*)&littleEndian)[0];
211 memcpy(
m_dna,bdnaOrg,dnalen);
216 char *cp = 0;
int dataLen =0;
217 intPtr = (
int*)
m_dna;
227 if (strncmp((
const char*)
m_dna,
"SDNA", 4)==0)
243 for ( i=0; i<dataLen; i++)
259 btAssert(strncmp(cp,
"TYPE", 4)==0); intPtr++;
269 for (i=0; i<dataLen; i++)
287 btAssert(strncmp(cp,
"TLEN", 4)==0); intPtr++;
291 shtPtr = (
short*)intPtr;
292 for (i=0; i<dataLen; i++, shtPtr++)
299 if (dataLen & 1) shtPtr++;
312 intPtr = (
int*)shtPtr;
314 btAssert(strncmp(cp,
"STRC", 4)==0); intPtr++;
322 shtPtr = (
short*)intPtr;
323 for (i=0; i<dataLen; i++)
335 for (
int a=0; a<len; a++, shtPtr+=2)
343 shtPtr+= (2*shtPtr[1])+2;
370 const bool VOID_IS_8 = ((
sizeof(
void*)==8));
372 #ifdef BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES
389 #else //BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES
397 #endif //BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES
413 #ifdef BT_USE_DOUBLE_PRECISION
414 memcpy(buffer,
"BULLETd", 7);
416 memcpy(buffer,
"BULLETf", 7);
417 #endif //BT_USE_DOUBLE_PRECISION
420 littleEndian= ((
char*)&littleEndian)[0];
422 if (
sizeof(
void*)==8)
470 unsigned char* currentPtr =
m_buffer;
479 currentPtr+=curLength;
546 unsigned char* ptr = 0;
551 m_currentSize += int(size);
568 unsigned char* data = ptr +
sizeof(
btChunk);
572 chunk->m_oldPtr = data;
573 chunk->m_length = int(size)*numElements;
574 chunk->m_number = numElements;
585 if (namePtr && *namePtr)
609 int padding = ((newLen+3)&~3)-newLen;
614 char* destinationName = (
char*)chunk->
m_oldPtr;
615 for (
int i=0;i<len;i++)
617 destinationName[i] = name[i];
619 destinationName[len] = 0;
638 #endif //BT_SERIALIZER_H
virtual void finishSerialization()=0
virtual int getCurrentBufferSize() const
virtual void serializeName(const char *name)
btAlignedObjectArray< btChunk * > m_chunkPtrs
void push_back(const T &_Val)
virtual int getSerializationFlags() const
virtual void setSerializationFlags(int flags)
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)
void writeHeader(unsigned char *buffer) const
virtual btChunk * allocate(size_t size, int numElements)
virtual void startSerialization()=0
virtual int getCurrentBufferSize() const =0
virtual void * getUniquePointer(void *oldPtr)=0
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
#define SIMD_FORCE_INLINE
virtual void setSerializationFlags(int flags)=0
virtual void registerNameForPointer(const void *ptr, const char *name)=0
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.
virtual unsigned char * internalAlloc(size_t size)
int size() const
return the number of elements in the array
virtual int getSerializationFlags() const =0
virtual const unsigned char * getBufferPointer() const =0
void initDNA(const char *bdnaOrg, int dnalen)
btAlignedObjectArray< short * > mStructs
#define btAlignedFree(ptr)
void insert(const Key &key, const Value &value)
btAlignedObjectArray< char * > mTypes
int btStrLen(const char *str)
btDefaultSerializer(int totalSize=0)
const Value * find(const Key &key) const
virtual void finalizeChunk(btChunk *chunk, const char *structType, int chunkCode, void *oldPtr)=0
very basic hashable string implementation, compatible with btHashMap
virtual void serializeName(const char *ptr)=0
virtual const char * findNameForPointer(const void *ptr) const
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
virtual const char * findNameForPointer(const void *ptr) const =0
btHashMap< btHashPtr, btPointerUid > m_uniquePointers
virtual void * findPointer(void *oldPtr)=0
virtual ~btDefaultSerializer()
btHashMap< btHashPtr, void * > m_chunkP
char sBulletDNAstr[]
only the 32bit versions for now
virtual btChunk * allocate(size_t size, int numElements)=0