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