Changeset 8393 for code/trunk/src/external/bullet/LinearMath/btSerializer.h
- Timestamp:
- May 3, 2011, 5:07:42 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/external/bullet/LinearMath/btSerializer.h
r8351 r8393 112 112 #endif 113 113 114 #define BT_SOFTBODY_CODE MAKE_ID('S','B','D','Y') 114 115 #define BT_COLLISIONOBJECT_CODE MAKE_ID('C','O','B','J') 115 116 #define BT_RIGIDBODY_CODE MAKE_ID('R','B','D','Y') … … 120 121 #define BT_SHAPE_CODE MAKE_ID('S','H','A','P') 121 122 #define BT_ARRAY_CODE MAKE_ID('A','R','A','Y') 123 #define BT_SBMATERIAL_CODE MAKE_ID('S','B','M','T') 124 #define BT_SBNODE_CODE MAKE_ID('S','B','N','D') 122 125 #define BT_DNA_CODE MAKE_ID('D','N','A','1') 123 124 126 125 127 … … 133 135 }; 134 136 135 137 ///The btDefaultSerializer is the main Bullet serialization class. 138 ///The constructor takes an optional argument for backwards compatibility, it is recommended to leave this empty/zero. 136 139 class btDefaultSerializer : public btSerializer 137 140 { … … 372 375 373 376 374 btDefaultSerializer(int totalSize )377 btDefaultSerializer(int totalSize=0) 375 378 :m_totalSize(totalSize), 376 379 m_currentSize(0), … … 379 382 m_serializationFlags(0) 380 383 { 381 m_buffer = (unsigned char*)btAlignedAlloc(totalSize, 16);384 m_buffer = m_totalSize?(unsigned char*)btAlignedAlloc(totalSize,16):0; 382 385 383 386 const bool VOID_IS_8 = ((sizeof(void*)==8)); … … 420 423 } 421 424 422 virtual void startSerialization() 423 { 424 m_uniqueIdGenerator= 1; 425 426 m_currentSize = BT_HEADER_LENGTH; 425 void writeHeader(unsigned char* buffer) const 426 { 427 427 428 428 429 #ifdef BT_USE_DOUBLE_PRECISION 429 memcpy( m_buffer, "BULLETd", 7);430 memcpy(buffer, "BULLETd", 7); 430 431 #else 431 memcpy( m_buffer, "BULLETf", 7);432 memcpy(buffer, "BULLETf", 7); 432 433 #endif //BT_USE_DOUBLE_PRECISION 433 434 … … 437 438 if (sizeof(void*)==8) 438 439 { 439 m_buffer[7] = '-';440 buffer[7] = '-'; 440 441 } else 441 442 { 442 m_buffer[7] = '_';443 buffer[7] = '_'; 443 444 } 444 445 445 446 if (littleEndian) 446 447 { 447 m_buffer[8]='v';448 buffer[8]='v'; 448 449 } else 449 450 { 450 m_buffer[8]='V'; 451 } 452 453 454 m_buffer[9] = '2'; 455 m_buffer[10] = '7'; 456 m_buffer[11] = '7'; 457 451 buffer[8]='V'; 452 } 453 454 455 buffer[9] = '2'; 456 buffer[10] = '7'; 457 buffer[11] = '8'; 458 459 } 460 461 virtual void startSerialization() 462 { 463 m_uniqueIdGenerator= 1; 464 if (m_totalSize) 465 { 466 unsigned char* buffer = internalAlloc(BT_HEADER_LENGTH); 467 writeHeader(buffer); 468 } 458 469 459 470 } … … 463 474 writeDNA(); 464 475 476 //if we didn't pre-allocate a buffer, we need to create a contiguous buffer now 477 int mysize = 0; 478 if (!m_totalSize) 479 { 480 if (m_buffer) 481 btAlignedFree(m_buffer); 482 483 m_currentSize += BT_HEADER_LENGTH; 484 m_buffer = (unsigned char*)btAlignedAlloc(m_currentSize,16); 485 486 unsigned char* currentPtr = m_buffer; 487 writeHeader(m_buffer); 488 currentPtr += BT_HEADER_LENGTH; 489 mysize+=BT_HEADER_LENGTH; 490 for (int i=0;i< m_chunkPtrs.size();i++) 491 { 492 int curLength = sizeof(btChunk)+m_chunkPtrs[i]->m_length; 493 memcpy(currentPtr,m_chunkPtrs[i], curLength); 494 btAlignedFree(m_chunkPtrs[i]); 495 currentPtr+=curLength; 496 mysize+=curLength; 497 } 498 } 465 499 466 500 mTypes.clear(); … … 472 506 m_nameMap.clear(); 473 507 m_uniquePointers.clear(); 508 m_chunkPtrs.clear(); 474 509 } 475 510 … … 523 558 524 559 560 virtual unsigned char* internalAlloc(size_t size) 561 { 562 unsigned char* ptr = 0; 563 564 if (m_totalSize) 565 { 566 ptr = m_buffer+m_currentSize; 567 m_currentSize += int(size); 568 btAssert(m_currentSize<m_totalSize); 569 } else 570 { 571 ptr = (unsigned char*)btAlignedAlloc(size,16); 572 m_currentSize += int(size); 573 } 574 return ptr; 575 } 525 576 526 577 … … 529 580 { 530 581 531 unsigned char* ptr = m_buffer+m_currentSize; 532 m_currentSize += int(size)*numElements+sizeof(btChunk); 533 btAssert(m_currentSize<m_totalSize); 582 unsigned char* ptr = internalAlloc(int(size)*numElements+sizeof(btChunk)); 534 583 535 584 unsigned char* data = ptr + sizeof(btChunk);
Note: See TracChangeset
for help on using the changeset viewer.