Bullet Collision Detection & Physics Library
btSerializer.h
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. This notice may not be removed or altered from any source distribution.
14*/
15
16#ifndef BT_SERIALIZER_H
17#define BT_SERIALIZER_H
18
19#include "btScalar.h" // has definitions like SIMD_FORCE_INLINE
20#include "btHashMap.h"
21
22#if !defined( __CELLOS_LV2__) && !defined(__MWERKS__)
23#include <memory.h>
24#endif
25#include <string.h>
26
27
28
29
30extern char sBulletDNAstr[];
31extern int sBulletDNAlen;
32extern char sBulletDNAstr64[];
33extern int sBulletDNAlen64;
34
35SIMD_FORCE_INLINE int btStrLen(const char* str)
36{
37 if (!str)
38 return(0);
39 int len = 0;
40
41 while (*str != 0)
42 {
43 str++;
44 len++;
45 }
46
47 return len;
48}
49
50
52{
53public:
56 void *m_oldPtr;
59};
60
62{
66};
67
69{
70
71public:
72
73 virtual ~btSerializer() {}
74
75 virtual const unsigned char* getBufferPointer() const = 0;
76
77 virtual int getCurrentBufferSize() const = 0;
78
79 virtual btChunk* allocate(size_t size, int numElements) = 0;
80
81 virtual void finalizeChunk(btChunk* chunk, const char* structType, int chunkCode,void* oldPtr)= 0;
82
83 virtual void* findPointer(void* oldPtr) = 0;
84
85 virtual void* getUniquePointer(void*oldPtr) = 0;
86
87 virtual void startSerialization() = 0;
88
89 virtual void finishSerialization() = 0;
90
91 virtual const char* findNameForPointer(const void* ptr) const = 0;
92
93 virtual void registerNameForPointer(const void* ptr, const char* name) = 0;
94
95 virtual void serializeName(const char* ptr) = 0;
96
97 virtual int getSerializationFlags() const = 0;
98
99 virtual void setSerializationFlags(int flags) = 0;
100
101 virtual int getNumChunks() const = 0;
102
103 virtual const btChunk* getChunk(int chunkIndex) const = 0;
104
105};
106
107
108
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) )
112#else
113# define BT_MAKE_ID(a,b,c,d) ( (int)(d)<<24 | (int)(c)<<16 | (b)<<8 | (a) )
114#endif
115
116
117#define BT_MULTIBODY_CODE BT_MAKE_ID('M','B','D','Y')
118#define BT_SOFTBODY_CODE BT_MAKE_ID('S','B','D','Y')
119#define BT_COLLISIONOBJECT_CODE BT_MAKE_ID('C','O','B','J')
120#define BT_RIGIDBODY_CODE BT_MAKE_ID('R','B','D','Y')
121#define BT_CONSTRAINT_CODE BT_MAKE_ID('C','O','N','S')
122#define BT_BOXSHAPE_CODE BT_MAKE_ID('B','O','X','S')
123#define BT_QUANTIZED_BVH_CODE BT_MAKE_ID('Q','B','V','H')
124#define BT_TRIANLGE_INFO_MAP BT_MAKE_ID('T','M','A','P')
125#define BT_SHAPE_CODE BT_MAKE_ID('S','H','A','P')
126#define BT_ARRAY_CODE BT_MAKE_ID('A','R','A','Y')
127#define BT_SBMATERIAL_CODE BT_MAKE_ID('S','B','M','T')
128#define BT_SBNODE_CODE BT_MAKE_ID('S','B','N','D')
129#define BT_DYNAMICSWORLD_CODE BT_MAKE_ID('D','W','L','D')
130#define BT_DNA_CODE BT_MAKE_ID('D','N','A','1')
131
132
134{
135 union
136 {
137 void* m_ptr;
139 };
140};
141
143{
145 {
146 }
161
162};
163
164
168{
169
170protected:
171
177
178
179
181
183
186
188 unsigned char* m_buffer;
191 void* m_dna;
193
195
196
198
199protected:
200
201
202 virtual void* findPointer(void* oldPtr)
203 {
204 void** ptr = m_chunkP.find(oldPtr);
205 if (ptr && *ptr)
206 return *ptr;
207 return 0;
208 }
209
210
211
212
213
214 virtual void writeDNA()
215 {
216 btChunk* dnaChunk = allocate(m_dnaLength,1);
217 memcpy(dnaChunk->m_oldPtr,m_dna,m_dnaLength);
218 finalizeChunk(dnaChunk,"DNA1",BT_DNA_CODE, m_dna);
219 }
220
221 int getReverseType(const char *type) const
222 {
223
224 btHashString key(type);
225 const int* valuePtr = mTypeLookup.find(key);
226 if (valuePtr)
227 return *valuePtr;
228
229 return -1;
230 }
231
232 void initDNA(const char* bdnaOrg,int dnalen)
233 {
235 if (m_dna)
236 return;
237
238 int littleEndian= 1;
239 littleEndian= ((char*)&littleEndian)[0];
240
241
242 m_dna = btAlignedAlloc(dnalen,16);
243 memcpy(m_dna,bdnaOrg,dnalen);
244 m_dnaLength = dnalen;
245
246 int *intPtr=0;
247 short *shtPtr=0;
248 char *cp = 0;int dataLen =0;
249 intPtr = (int*)m_dna;
250
251 /*
252 SDNA (4 bytes) (magic number)
253 NAME (4 bytes)
254 <nr> (4 bytes) amount of names (int)
255 <string>
256 <string>
257 */
258
259 if (strncmp((const char*)m_dna, "SDNA", 4)==0)
260 {
261 // skip ++ NAME
262 intPtr++; intPtr++;
263 }
264
265 // Parse names
266 if (!littleEndian)
267 *intPtr = btSwapEndian(*intPtr);
268
269 dataLen = *intPtr;
270
271 intPtr++;
272
273 cp = (char*)intPtr;
274 int i;
275 for ( i=0; i<dataLen; i++)
276 {
277
278 while (*cp)cp++;
279 cp++;
280 }
281 cp = btAlignPointer(cp,4);
282
283 /*
284 TYPE (4 bytes)
285 <nr> amount of types (int)
286 <string>
287 <string>
288 */
289
290 intPtr = (int*)cp;
291 btAssert(strncmp(cp, "TYPE", 4)==0); intPtr++;
292
293 if (!littleEndian)
294 *intPtr = btSwapEndian(*intPtr);
295
296 dataLen = *intPtr;
297 intPtr++;
298
299
300 cp = (char*)intPtr;
301 for (i=0; i<dataLen; i++)
302 {
303 mTypes.push_back(cp);
304 while (*cp)cp++;
305 cp++;
306 }
307
308 cp = btAlignPointer(cp,4);
309
310
311 /*
312 TLEN (4 bytes)
313 <len> (short) the lengths of types
314 <len>
315 */
316
317 // Parse type lens
318 intPtr = (int*)cp;
319 btAssert(strncmp(cp, "TLEN", 4)==0); intPtr++;
320
321 dataLen = (int)mTypes.size();
322
323 shtPtr = (short*)intPtr;
324 for (i=0; i<dataLen; i++, shtPtr++)
325 {
326 if (!littleEndian)
327 shtPtr[0] = btSwapEndian(shtPtr[0]);
328 mTlens.push_back(shtPtr[0]);
329 }
330
331 if (dataLen & 1) shtPtr++;
332
333 /*
334 STRC (4 bytes)
335 <nr> amount of structs (int)
336 <typenr>
337 <nr_of_elems>
338 <typenr>
339 <namenr>
340 <typenr>
341 <namenr>
342 */
343
344 intPtr = (int*)shtPtr;
345 cp = (char*)intPtr;
346 btAssert(strncmp(cp, "STRC", 4)==0); intPtr++;
347
348 if (!littleEndian)
349 *intPtr = btSwapEndian(*intPtr);
350 dataLen = *intPtr ;
351 intPtr++;
352
353
354 shtPtr = (short*)intPtr;
355 for (i=0; i<dataLen; i++)
356 {
357 mStructs.push_back (shtPtr);
358
359 if (!littleEndian)
360 {
361 shtPtr[0]= btSwapEndian(shtPtr[0]);
362 shtPtr[1]= btSwapEndian(shtPtr[1]);
363
364 int len = shtPtr[1];
365 shtPtr+= 2;
366
367 for (int a=0; a<len; a++, shtPtr+=2)
368 {
369 shtPtr[0]= btSwapEndian(shtPtr[0]);
370 shtPtr[1]= btSwapEndian(shtPtr[1]);
371 }
372
373 } else
374 {
375 shtPtr+= (2*shtPtr[1])+2;
376 }
377 }
378
379 // build reverse lookups
380 for (i=0; i<(int)mStructs.size(); i++)
381 {
382 short *strc = mStructs.at(i);
383 mStructReverse.insert(strc[0], i);
384 mTypeLookup.insert(btHashString(mTypes[strc[0]]),i);
385 }
386 }
387
388public:
389
391
392
393 btDefaultSerializer(int totalSize=0, unsigned char* buffer=0)
395 m_totalSize(totalSize),
396 m_currentSize(0),
397 m_dna(0),
398 m_dnaLength(0),
400 {
401 if (buffer==0)
402 {
403 m_buffer = m_totalSize?(unsigned char*)btAlignedAlloc(totalSize,16):0;
404 m_ownsBuffer = true;
405 } else
406 {
407 m_buffer = buffer;
408 m_ownsBuffer = false;
409 }
410
411 const bool VOID_IS_8 = ((sizeof(void*)==8));
412
413#ifdef BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES
414 if (VOID_IS_8)
415 {
416#if _WIN64
418#else
419 btAssert(0);
420#endif
421 } else
422 {
423#ifndef _WIN64
424 initDNA((const char*)sBulletDNAstr,sBulletDNAlen);
425#else
426 btAssert(0);
427#endif
428 }
429
430#else //BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES
431 if (VOID_IS_8)
432 {
434 } else
435 {
436 initDNA((const char*)sBulletDNAstr,sBulletDNAlen);
437 }
438#endif //BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES
439
440 }
441
443 {
444 if (m_buffer && m_ownsBuffer)
446 if (m_dna)
448 }
449
451 {
452 const bool VOID_IS_8 = ((sizeof(void*) == 8));
453
454 if (VOID_IS_8)
455 {
456 return sBulletDNAlen64;
457 }
458 return sBulletDNAlen;
459 }
460 static const char* getMemoryDna()
461 {
462 const bool VOID_IS_8 = ((sizeof(void*) == 8));
463 if (VOID_IS_8)
464 {
465 return (const char*)sBulletDNAstr64;
466 }
467 return (const char*)sBulletDNAstr;
468 }
469
471 {
474 }
475
476 void writeHeader(unsigned char* buffer) const
477 {
478
479
480#ifdef BT_USE_DOUBLE_PRECISION
481 memcpy(buffer, "BULLETd", 7);
482#else
483 memcpy(buffer, "BULLETf", 7);
484#endif //BT_USE_DOUBLE_PRECISION
485
486 int littleEndian= 1;
487 littleEndian= ((char*)&littleEndian)[0];
488
489 if (sizeof(void*)==8)
490 {
491 buffer[7] = '-';
492 } else
493 {
494 buffer[7] = '_';
495 }
496
497 if (littleEndian)
498 {
499 buffer[8]='v';
500 } else
501 {
502 buffer[8]='V';
503 }
504
505
506 buffer[9] = '2';
507 buffer[10] = '8';
508 buffer[11] = '7';
509
510 }
511
512 virtual void startSerialization()
513 {
515 if (m_totalSize)
516 {
517 unsigned char* buffer = internalAlloc(BT_HEADER_LENGTH);
518 writeHeader(buffer);
519 }
520
521 }
522
523 virtual void finishSerialization()
524 {
525 writeDNA();
526
527 //if we didn't pre-allocate a buffer, we need to create a contiguous buffer now
528 int mysize = 0;
529 if (!m_totalSize)
530 {
531 if (m_buffer)
533
535 m_buffer = (unsigned char*)btAlignedAlloc(m_currentSize,16);
536
537 unsigned char* currentPtr = m_buffer;
539 currentPtr += BT_HEADER_LENGTH;
540 mysize+=BT_HEADER_LENGTH;
541 for (int i=0;i< m_chunkPtrs.size();i++)
542 {
543 int curLength = sizeof(btChunk)+m_chunkPtrs[i]->m_length;
544 memcpy(currentPtr,m_chunkPtrs[i], curLength);
546 currentPtr+=curLength;
547 mysize+=curLength;
548 }
549 }
550
551 mTypes.clear();
552 mStructs.clear();
553 mTlens.clear();
554 mStructReverse.clear();
555 mTypeLookup.clear();
556 m_skipPointers.clear();
557 m_chunkP.clear();
558 m_nameMap.clear();
559 m_uniquePointers.clear();
560 m_chunkPtrs.clear();
561 }
562
563 virtual void* getUniquePointer(void*oldPtr)
564 {
566 if (!oldPtr)
567 return 0;
568
569 btPointerUid* uptr = (btPointerUid*)m_uniquePointers.find(oldPtr);
570 if (uptr)
571 {
572 return uptr->m_ptr;
573 }
574
575 void** ptr2 = m_skipPointers[oldPtr];
576 if (ptr2)
577 {
578 return 0;
579 }
580
582
583 btPointerUid uid;
586 m_uniquePointers.insert(oldPtr,uid);
587 return uid.m_ptr;
588
589 }
590
591 virtual const unsigned char* getBufferPointer() const
592 {
593 return m_buffer;
594 }
595
596 virtual int getCurrentBufferSize() const
597 {
598 return m_currentSize;
599 }
600
601 virtual void finalizeChunk(btChunk* chunk, const char* structType, int chunkCode,void* oldPtr)
602 {
604 {
605 btAssert(!findPointer(oldPtr));
606 }
607
608 chunk->m_dna_nr = getReverseType(structType);
609
610 chunk->m_chunkCode = chunkCode;
611
612 void* uniquePtr = getUniquePointer(oldPtr);
613
614 m_chunkP.insert(oldPtr,uniquePtr);//chunk->m_oldPtr);
615 chunk->m_oldPtr = uniquePtr;//oldPtr;
616
617 }
618
619
620 virtual unsigned char* internalAlloc(size_t size)
621 {
622 unsigned char* ptr = 0;
623
624 if (m_totalSize)
625 {
627 m_currentSize += int(size);
629 } else
630 {
631 ptr = (unsigned char*)btAlignedAlloc(size,16);
632 m_currentSize += int(size);
633 }
634 return ptr;
635 }
636
637
638
639 virtual btChunk* allocate(size_t size, int numElements)
640 {
641
642 unsigned char* ptr = internalAlloc(int(size)*numElements+sizeof(btChunk));
643
644 unsigned char* data = ptr + sizeof(btChunk);
645
646 btChunk* chunk = (btChunk*)ptr;
647 chunk->m_chunkCode = 0;
648 chunk->m_oldPtr = data;
649 chunk->m_length = int(size)*numElements;
650 chunk->m_number = numElements;
651
652 m_chunkPtrs.push_back(chunk);
653
654
655 return chunk;
656 }
657
658 virtual const char* findNameForPointer(const void* ptr) const
659 {
660 const char*const * namePtr = m_nameMap.find(ptr);
661 if (namePtr && *namePtr)
662 return *namePtr;
663 return 0;
664
665 }
666
667 virtual void registerNameForPointer(const void* ptr, const char* name)
668 {
669 m_nameMap.insert(ptr,name);
670 }
671
672 virtual void serializeName(const char* name)
673 {
674 if (name)
675 {
676 //don't serialize name twice
677 if (findPointer((void*)name))
678 return;
679
680 int len = btStrLen(name);
681 if (len)
682 {
683
684 int newLen = len+1;
685 int padding = ((newLen+3)&~3)-newLen;
686 newLen += padding;
687
688 //serialize name string now
689 btChunk* chunk = allocate(sizeof(char),newLen);
690 char* destinationName = (char*)chunk->m_oldPtr;
691 for (int i=0;i<len;i++)
692 {
693 destinationName[i] = name[i];
694 }
695 destinationName[len] = 0;
696 finalizeChunk(chunk,"char",BT_ARRAY_CODE,(void*)name);
697 }
698 }
699 }
700
701 virtual int getSerializationFlags() const
702 {
704 }
705
706 virtual void setSerializationFlags(int flags)
707 {
708 m_serializationFlags = flags;
709 }
710 int getNumChunks() const
711 {
712 return m_chunkPtrs.size();
713 }
714
715 const btChunk* getChunk(int chunkIndex) const
716 {
717 return m_chunkPtrs[chunkIndex];
718 }
719};
720
721
727#ifdef ENABLE_INMEMORY_SERIALIZER
728
729struct btInMemorySerializer : public btDefaultSerializer
730{
731 btHashMap<btHashPtr,btChunk*> m_uid2ChunkPtr;
732 btHashMap<btHashPtr,void*> m_orgPtr2UniqueDataPtr;
734
735
737
738 btInMemorySerializer(int totalSize=0, unsigned char* buffer=0)
739 :btDefaultSerializer(totalSize,buffer)
740 {
741
742 }
743
744 virtual void startSerialization()
745 {
746 m_uid2ChunkPtr.clear();
747 //todo: m_arrays.clear();
749 }
750
751
752
753 btChunk* findChunkFromUniquePointer(void* uniquePointer)
754 {
755 btChunk** chkPtr = m_uid2ChunkPtr[uniquePointer];
756 if (chkPtr)
757 {
758 return *chkPtr;
759 }
760 return 0;
761 }
762
763 virtual void registerNameForPointer(const void* ptr, const char* name)
764 {
766 m_names2Ptr.insert(name,ptr);
767 }
768
769 virtual void finishSerialization()
770 {
771 }
772
773 virtual void* getUniquePointer(void*oldPtr)
774 {
775 if (oldPtr==0)
776 return 0;
777
778 // void* uniquePtr = getUniquePointer(oldPtr);
779 btChunk* chunk = findChunkFromUniquePointer(oldPtr);
780 if (chunk)
781 {
782 return chunk->m_oldPtr;
783 } else
784 {
785 const char* n = (const char*) oldPtr;
786 const void** ptr = m_names2Ptr[n];
787 if (ptr)
788 {
789 return oldPtr;
790 } else
791 {
792 void** ptr2 = m_skipPointers[oldPtr];
793 if (ptr2)
794 {
795 return 0;
796 } else
797 {
798 //If this assert hit, serialization happened in the wrong order
799 // 'getUniquePointer'
800 btAssert(0);
801 }
802
803 }
804 return 0;
805 }
806 return oldPtr;
807 }
808
809 virtual void finalizeChunk(btChunk* chunk, const char* structType, int chunkCode,void* oldPtr)
810 {
811 if (!(m_serializationFlags&BT_SERIALIZE_NO_DUPLICATE_ASSERT))
812 {
813 btAssert(!findPointer(oldPtr));
814 }
815
816 chunk->m_dna_nr = getReverseType(structType);
817 chunk->m_chunkCode = chunkCode;
818 //void* uniquePtr = getUniquePointer(oldPtr);
819 m_chunkP.insert(oldPtr,oldPtr);//chunk->m_oldPtr);
820 // chunk->m_oldPtr = uniquePtr;//oldPtr;
821
822 void* uid = findPointer(oldPtr);
823 m_uid2ChunkPtr.insert(uid,chunk);
824
825 switch (chunk->m_chunkCode)
826 {
827 case BT_SOFTBODY_CODE:
828 {
829 #ifdef BT_USE_DOUBLE_PRECISION
830 m_arrays.m_softBodyDoubleData.push_back((btSoftBodyDoubleData*) chunk->m_oldPtr);
831 #else
832 m_arrays.m_softBodyFloatData.push_back((btSoftBodyFloatData*) chunk->m_oldPtr);
833 #endif
834 break;
835 }
837 {
838 #ifdef BT_USE_DOUBLE_PRECISION
840 #else//BT_USE_DOUBLE_PRECISION
842 #endif //BT_USE_DOUBLE_PRECISION
843 break;
844 }
846 {
847 #ifdef BT_USE_DOUBLE_PRECISION
848 m_arrays.m_rigidBodyDataDouble.push_back((btRigidBodyDoubleData*)chunk->m_oldPtr);
849 #else
850 m_arrays.m_rigidBodyDataFloat.push_back((btRigidBodyFloatData*)chunk->m_oldPtr);
851 #endif//BT_USE_DOUBLE_PRECISION
852 break;
853 };
855 {
856 #ifdef BT_USE_DOUBLE_PRECISION
858 #else
859 m_arrays.m_constraintDataFloat.push_back((btTypedConstraintFloatData*)chunk->m_oldPtr);
860 #endif
861 break;
862 }
864 {
865 #ifdef BT_USE_DOUBLE_PRECISION
866 m_arrays.m_bvhsDouble.push_back((btQuantizedBvhDoubleData*) chunk->m_oldPtr);
867 #else
868 m_arrays.m_bvhsFloat.push_back((btQuantizedBvhFloatData*) chunk->m_oldPtr);
869 #endif
870 break;
871 }
872
873 case BT_SHAPE_CODE:
874 {
876 m_arrays.m_colShapeData.push_back(shapeData);
877 break;
878 }
880 case BT_ARRAY_CODE:
882 case BT_SBNODE_CODE:
884 case BT_DNA_CODE:
885 {
886 break;
887 }
888 default:
889 {
890 }
891 };
892 }
893
894 int getNumChunks() const
895 {
896 return m_uid2ChunkPtr.size();
897 }
898
899 const btChunk* getChunk(int chunkIndex) const
900 {
901 return *m_uid2ChunkPtr.getAtIndex(chunkIndex);
902 }
903
904};
905#endif //ENABLE_INMEMORY_SERIALIZER
906
907#endif //BT_SERIALIZER_H
908
#define btAlignedFree(ptr)
#define btAlignedAlloc(size, alignment)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
#define SIMD_FORCE_INLINE
Definition: btScalar.h:81
unsigned btSwapEndian(unsigned val)
Definition: btScalar.h:629
T * btAlignPointer(T *unalignedPtr, size_t alignment)
align a pointer to the provided alignment, upwards
Definition: btScalar.h:792
#define btAssert(x)
Definition: btScalar.h:131
btSerializationFlags
Definition: btSerializer.h:62
@ BT_SERIALIZE_NO_DUPLICATE_ASSERT
Definition: btSerializer.h:65
@ BT_SERIALIZE_NO_TRIANGLEINFOMAP
Definition: btSerializer.h:64
@ BT_SERIALIZE_NO_BVH
Definition: btSerializer.h:63
int sBulletDNAlen64
#define BT_DNA_CODE
Definition: btSerializer.h:130
#define BT_SBMATERIAL_CODE
Definition: btSerializer.h:127
char sBulletDNAstr[]
Definition: btSerializer.cpp:1
#define BT_COLLISIONOBJECT_CODE
Definition: btSerializer.h:119
char sBulletDNAstr64[]
#define BT_HEADER_LENGTH
Definition: btSerializer.h:109
#define BT_TRIANLGE_INFO_MAP
Definition: btSerializer.h:124
#define BT_QUANTIZED_BVH_CODE
Definition: btSerializer.h:123
#define BT_RIGIDBODY_CODE
Definition: btSerializer.h:120
int btStrLen(const char *str)
Definition: btSerializer.h:35
int sBulletDNAlen
#define BT_DYNAMICSWORLD_CODE
Definition: btSerializer.h:129
#define BT_SOFTBODY_CODE
Definition: btSerializer.h:118
#define BT_SHAPE_CODE
Definition: btSerializer.h:125
#define BT_ARRAY_CODE
Definition: btSerializer.h:126
#define BT_CONSTRAINT_CODE
Definition: btSerializer.h:121
#define BT_SBNODE_CODE
Definition: btSerializer.h:128
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
int m_number
Definition: btSerializer.h:58
int m_length
Definition: btSerializer.h:55
int m_chunkCode
Definition: btSerializer.h:54
void * m_oldPtr
Definition: btSerializer.h:56
int m_dna_nr
Definition: btSerializer.h:57
The btDefaultSerializer is the main Bullet serialization class.
Definition: btSerializer.h:168
void initDNA(const char *bdnaOrg, int dnalen)
Definition: btSerializer.h:232
virtual const char * findNameForPointer(const void *ptr) const
Definition: btSerializer.h:658
virtual void setSerializationFlags(int flags)
Definition: btSerializer.h:706
btAlignedObjectArray< char * > mTypes
Definition: btSerializer.h:172
static const char * getMemoryDna()
Definition: btSerializer.h:460
virtual ~btDefaultSerializer()
Definition: btSerializer.h:442
btHashMap< btHashPtr, btPointerUid > m_uniquePointers
Definition: btSerializer.h:184
virtual void * getUniquePointer(void *oldPtr)
Definition: btSerializer.h:563
virtual unsigned char * internalAlloc(size_t size)
Definition: btSerializer.h:620
btAlignedObjectArray< btChunk * > m_chunkPtrs
Definition: btSerializer.h:197
virtual void * findPointer(void *oldPtr)
Definition: btSerializer.h:202
int getNumChunks() const
Definition: btSerializer.h:710
virtual void serializeName(const char *name)
Definition: btSerializer.h:672
virtual void startSerialization()
Definition: btSerializer.h:512
int getReverseType(const char *type) const
Definition: btSerializer.h:221
btAlignedObjectArray< short > mTlens
Definition: btSerializer.h:174
virtual int getSerializationFlags() const
Definition: btSerializer.h:701
const btChunk * getChunk(int chunkIndex) const
Definition: btSerializer.h:715
unsigned char * m_buffer
Definition: btSerializer.h:188
virtual void registerNameForPointer(const void *ptr, const char *name)
Definition: btSerializer.h:667
btHashMap< btHashPtr, void * > m_chunkP
Definition: btSerializer.h:180
virtual int getCurrentBufferSize() const
Definition: btSerializer.h:596
virtual void finalizeChunk(btChunk *chunk, const char *structType, int chunkCode, void *oldPtr)
Definition: btSerializer.h:601
btHashMap< btHashInt, int > mStructReverse
Definition: btSerializer.h:175
virtual void finishSerialization()
Definition: btSerializer.h:523
btDefaultSerializer(int totalSize=0, unsigned char *buffer=0)
Definition: btSerializer.h:393
void writeHeader(unsigned char *buffer) const
Definition: btSerializer.h:476
btHashMap< btHashString, int > mTypeLookup
Definition: btSerializer.h:176
btHashMap< btHashPtr, void * > m_skipPointers
Definition: btSerializer.h:390
btHashMap< btHashPtr, const char * > m_nameMap
Definition: btSerializer.h:182
virtual void writeDNA()
Definition: btSerializer.h:214
static int getMemoryDnaSizeInBytes()
Definition: btSerializer.h:450
virtual const unsigned char * getBufferPointer() const
Definition: btSerializer.h:591
btAlignedObjectArray< short * > mStructs
Definition: btSerializer.h:173
virtual btChunk * allocate(size_t size, int numElements)
Definition: btSerializer.h:639
The btHashMap template class implements a generic and lightweight hashmap.
Definition: btHashMap.h:226
void insert(const Key &key, const Value &value)
Definition: btHashMap.h:274
void clear()
Definition: btHashMap.h:472
int size() const
Definition: btHashMap.h:384
const Value * getAtIndex(int index) const
Definition: btHashMap.h:389
virtual btChunk * allocate(size_t size, int numElements)=0
virtual void setSerializationFlags(int flags)=0
virtual int getCurrentBufferSize() const =0
virtual void * getUniquePointer(void *oldPtr)=0
virtual int getSerializationFlags() const =0
virtual void serializeName(const char *ptr)=0
virtual void finishSerialization()=0
virtual const char * findNameForPointer(const void *ptr) const =0
virtual void startSerialization()=0
virtual const btChunk * getChunk(int chunkIndex) const =0
virtual int getNumChunks() const =0
virtual void finalizeChunk(btChunk *chunk, const char *structType, int chunkCode, void *oldPtr)=0
virtual ~btSerializer()
Definition: btSerializer.h:73
virtual const unsigned char * getBufferPointer() const =0
virtual void registerNameForPointer(const void *ptr, const char *name)=0
virtual void * findPointer(void *oldPtr)=0
const bool VOID_IS_8
Definition: bChunk.h:89
btAlignedObjectArray< struct btQuantizedBvhDoubleData * > m_bvhsDouble
Definition: btSerializer.h:147
btAlignedObjectArray< struct btTypedConstraintData * > m_constraintData
Definition: btSerializer.h:158
btAlignedObjectArray< struct btRigidBodyDoubleData * > m_rigidBodyDataDouble
Definition: btSerializer.h:152
btAlignedObjectArray< struct btCollisionObjectFloatData * > m_collisionObjectDataFloat
Definition: btSerializer.h:155
btAlignedObjectArray< struct btSoftBodyDoubleData * > m_softBodyDoubleData
Definition: btSerializer.h:160
btAlignedObjectArray< struct btRigidBodyFloatData * > m_rigidBodyDataFloat
Definition: btSerializer.h:153
btAlignedObjectArray< struct btTypedConstraintDoubleData * > m_constraintDataDouble
Definition: btSerializer.h:157
btAlignedObjectArray< struct btDynamicsWorldDoubleData * > m_dynamicWorldInfoDataDouble
Definition: btSerializer.h:150
btAlignedObjectArray< struct btTypedConstraintFloatData * > m_constraintDataFloat
Definition: btSerializer.h:156
btAlignedObjectArray< struct btCollisionObjectDoubleData * > m_collisionObjectDataDouble
Definition: btSerializer.h:154
btAlignedObjectArray< struct btCollisionShapeData * > m_colShapeData
Definition: btSerializer.h:149
btAlignedObjectArray< struct btDynamicsWorldFloatData * > m_dynamicWorldInfoDataFloat
Definition: btSerializer.h:151
btAlignedObjectArray< struct btQuantizedBvhFloatData * > m_bvhsFloat
Definition: btSerializer.h:148
btAlignedObjectArray< struct btSoftBodyFloatData * > m_softBodyFloatData
Definition: btSerializer.h:159
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
very basic hashable string implementation, compatible with btHashMap
Definition: btHashMap.h:24
int m_uniqueIds[2]
Definition: btSerializer.h:138
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
Definition: btRigidBody.h:591
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
Definition: btRigidBody.h:565
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64