Added preliminary binary serialization code in btCollisionWorld.cpp, with example in Bullet/Demos/BasicDemo.cpp
(work-in-progress, some initial working version should be ready very soon, for Bullet 2.76)
This commit is contained in:
@@ -5,34 +5,35 @@ INCLUDE_DIRECTORIES(
|
||||
|
||||
SET(LinearMath_SRCS
|
||||
btAlignedAllocator.cpp
|
||||
btConvexHull.cpp
|
||||
btGeometryUtil.cpp
|
||||
btConvexHull.cpp
|
||||
btGeometryUtil.cpp
|
||||
btQuickprof.cpp
|
||||
btSerializer.cpp
|
||||
)
|
||||
|
||||
SET(LinearMath_HDRS
|
||||
btAabbUtil2.h
|
||||
btAlignedAllocator.h
|
||||
btAlignedObjectArray.h
|
||||
btAlignedObjectArray.h
|
||||
btConvexHull.h
|
||||
btDefaultMotionState.h
|
||||
btDefaultMotionState.h
|
||||
btGeometryUtil.h
|
||||
btHashMap.h
|
||||
btHashMap.h
|
||||
btIDebugDraw.h
|
||||
btList.h
|
||||
btMatrix3x3.h
|
||||
btMinMax.h
|
||||
btMinMax.h
|
||||
btMotionState.h
|
||||
btPoolAllocator.h
|
||||
btQuadWord.h
|
||||
btQuaternion.h
|
||||
btQuaternion.h
|
||||
btQuickprof.h
|
||||
btRandom.h
|
||||
btScalar.h
|
||||
btSerializer.h
|
||||
btStackAlloc.h
|
||||
btTransform.h
|
||||
btTransformUtil.h
|
||||
btStackAlloc.h
|
||||
btTransform.h
|
||||
btTransformUtil.h
|
||||
btVector3.h
|
||||
)
|
||||
|
||||
|
||||
89
src/LinearMath/btSerializer.cpp
Normal file
89
src/LinearMath/btSerializer.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
unsigned char sBulletDNAstr[]= {
|
||||
83,68,78,65,78,65,77,69,64,0,0,0,109,95,115,105,122,101,0,109,
|
||||
95,99,97,112,97,99,105,116,121,0,42,109,95,100,97,116,97,0,109,95,
|
||||
99,111,108,108,105,115,105,111,110,83,104,97,112,101,115,0,109,95,99,111,
|
||||
108,108,105,115,105,111,110,79,98,106,101,99,116,115,0,109,95,99,111,110,
|
||||
115,116,114,97,105,110,116,115,0,42,102,105,114,115,116,0,42,108,97,115,
|
||||
116,0,109,95,102,108,111,97,116,115,91,52,93,0,121,97,119,0,112,105,
|
||||
116,99,104,0,114,111,108,108,0,109,95,101,108,91,51,93,0,109,95,98,
|
||||
97,115,105,115,0,109,95,111,114,105,103,105,110,0,42,109,95,117,115,101,
|
||||
114,80,111,105,110,116,101,114,0,109,95,115,104,97,112,101,84,121,112,101,
|
||||
0,109,95,112,97,100,100,105,110,103,91,52,93,0,109,95,104,97,108,102,
|
||||
69,120,116,101,110,116,115,0,109,95,108,111,99,97,108,83,99,97,108,105,
|
||||
110,103,0,109,95,119,111,114,108,100,84,114,97,110,115,102,111,114,109,0,
|
||||
109,95,105,110,116,101,114,112,111,108,97,116,105,111,110,87,111,114,108,100,
|
||||
84,114,97,110,115,102,111,114,109,0,109,95,105,110,116,101,114,112,111,108,
|
||||
97,116,105,111,110,76,105,110,101,97,114,86,101,108,111,99,105,116,121,0,
|
||||
109,95,105,110,116,101,114,112,111,108,97,116,105,111,110,65,110,103,117,108,
|
||||
97,114,86,101,108,111,99,105,116,121,0,109,95,97,110,105,115,111,116,114,
|
||||
111,112,105,99,70,114,105,99,116,105,111,110,0,109,95,104,97,115,65,110,
|
||||
105,115,111,116,114,111,112,105,99,70,114,105,99,116,105,111,110,0,109,95,
|
||||
99,111,110,116,97,99,116,80,114,111,99,101,115,115,105,110,103,84,104,114,
|
||||
101,115,104,111,108,100,0,42,109,95,98,114,111,97,100,112,104,97,115,101,
|
||||
72,97,110,100,108,101,0,42,109,95,99,111,108,108,105,115,105,111,110,83,
|
||||
104,97,112,101,0,42,109,95,114,111,111,116,67,111,108,108,105,115,105,111,
|
||||
110,83,104,97,112,101,0,109,95,99,111,108,108,105,115,105,111,110,70,108,
|
||||
97,103,115,0,109,95,105,115,108,97,110,100,84,97,103,49,0,109,95,99,
|
||||
111,109,112,97,110,105,111,110,73,100,0,109,95,97,99,116,105,118,97,116,
|
||||
105,111,110,83,116,97,116,101,49,0,109,95,100,101,97,99,116,105,118,97,
|
||||
116,105,111,110,84,105,109,101,0,109,95,102,114,105,99,116,105,111,110,0,
|
||||
109,95,114,101,115,116,105,116,117,116,105,111,110,0,109,95,105,110,116,101,
|
||||
114,110,97,108,84,121,112,101,0,42,109,95,117,115,101,114,79,98,106,101,
|
||||
99,116,80,111,105,110,116,101,114,0,109,95,104,105,116,70,114,97,99,116,
|
||||
105,111,110,0,109,95,99,99,100,83,119,101,112,116,83,112,104,101,114,101,
|
||||
82,97,100,105,117,115,0,109,95,99,99,100,77,111,116,105,111,110,84,104,
|
||||
114,101,115,104,111,108,100,0,109,95,99,104,101,99,107,67,111,108,108,105,
|
||||
100,101,87,105,116,104,0,109,95,105,110,118,73,110,101,114,116,105,97,84,
|
||||
101,110,115,111,114,87,111,114,108,100,0,109,95,108,105,110,101,97,114,86,
|
||||
101,108,111,99,105,116,121,0,109,95,97,110,103,117,108,97,114,86,101,108,
|
||||
111,99,105,116,121,0,109,95,105,110,118,101,114,115,101,77,97,115,115,0,
|
||||
109,95,97,110,103,117,108,97,114,70,97,99,116,111,114,0,109,95,108,105,
|
||||
110,101,97,114,70,97,99,116,111,114,0,109,95,103,114,97,118,105,116,121,
|
||||
0,109,95,103,114,97,118,105,116,121,95,97,99,99,101,108,101,114,97,116,
|
||||
105,111,110,0,109,95,105,110,118,73,110,101,114,116,105,97,76,111,99,97,
|
||||
108,0,109,95,116,111,116,97,108,70,111,114,99,101,0,109,95,116,111,116,
|
||||
97,108,84,111,114,113,117,101,0,109,95,108,105,110,101,97,114,68,97,109,
|
||||
112,105,110,103,0,109,95,97,110,103,117,108,97,114,68,97,109,112,105,110,
|
||||
103,0,109,95,97,100,100,105,116,105,111,110,97,108,68,97,109,112,105,110,
|
||||
103,0,109,95,97,100,100,105,116,105,111,110,97,108,68,97,109,112,105,110,
|
||||
103,70,97,99,116,111,114,0,109,95,97,100,100,105,116,105,111,110,97,108,
|
||||
76,105,110,101,97,114,68,97,109,112,105,110,103,84,104,114,101,115,104,111,
|
||||
108,100,83,113,114,0,109,95,97,100,100,105,116,105,111,110,97,108,65,110,
|
||||
103,117,108,97,114,68,97,109,112,105,110,103,84,104,114,101,115,104,111,108,
|
||||
100,83,113,114,0,109,95,97,100,100,105,116,105,111,110,97,108,65,110,103,
|
||||
117,108,97,114,68,97,109,112,105,110,103,70,97,99,116,111,114,0,109,95,
|
||||
108,105,110,101,97,114,83,108,101,101,112,105,110,103,84,104,114,101,115,104,
|
||||
111,108,100,0,109,95,97,110,103,117,108,97,114,83,108,101,101,112,105,110,
|
||||
103,84,104,114,101,115,104,111,108,100,0,109,95,99,111,108,108,105,115,105,
|
||||
111,110,79,98,106,101,99,116,68,97,116,97,0,0,0,0,84,89,80,69,
|
||||
22,0,0,0,99,104,97,114,0,117,99,104,97,114,0,115,104,111,114,116,
|
||||
0,117,115,104,111,114,116,0,105,110,116,0,108,111,110,103,0,117,108,111,
|
||||
110,103,0,102,108,111,97,116,0,100,111,117,98,108,101,0,118,111,105,100,
|
||||
0,98,116,83,99,97,108,97,114,0,80,111,105,110,116,101,114,65,114,114,
|
||||
97,121,0,98,116,80,104,121,115,105,99,115,83,121,115,116,101,109,0,76,
|
||||
105,115,116,66,97,115,101,0,98,116,86,101,99,116,111,114,51,68,97,116,
|
||||
97,0,69,117,108,101,114,0,98,116,77,97,116,114,105,120,51,120,51,68,
|
||||
97,116,97,0,98,116,84,114,97,110,115,102,111,114,109,68,97,116,97,0,
|
||||
98,116,67,111,108,108,105,115,105,111,110,83,104,97,112,101,68,97,116,97,
|
||||
0,98,116,66,111,120,83,104,97,112,101,68,97,116,97,0,98,116,67,111,
|
||||
108,108,105,115,105,111,110,79,98,106,101,99,116,68,97,116,97,0,98,116,
|
||||
82,105,103,105,100,66,111,100,121,68,97,116,97,0,0,0,84,76,69,78,
|
||||
1,0,1,0,2,0,2,0,4,0,4,0,4,0,4,0,8,0,0,0,
|
||||
4,0,12,0,36,0,8,0,16,0,12,0,48,0,64,0,12,0,32,0,
|
||||
-8,0,-32,1,83,84,82,67,11,0,0,0,11,0,3,0,4,0,0,0,
|
||||
4,0,1,0,9,0,2,0,12,0,3,0,11,0,3,0,11,0,4,0,
|
||||
11,0,5,0,13,0,2,0,9,0,6,0,9,0,7,0,14,0,1,0,
|
||||
10,0,8,0,15,0,3,0,10,0,9,0,10,0,10,0,10,0,11,0,
|
||||
16,0,1,0,14,0,12,0,17,0,2,0,16,0,13,0,14,0,14,0,
|
||||
18,0,3,0,9,0,15,0,4,0,16,0,0,0,17,0,19,0,2,0,
|
||||
14,0,18,0,14,0,19,0,20,0,23,0,17,0,20,0,17,0,21,0,
|
||||
14,0,22,0,14,0,23,0,14,0,24,0,4,0,25,0,10,0,26,0,
|
||||
9,0,27,0,9,0,28,0,18,0,29,0,4,0,30,0,4,0,31,0,
|
||||
4,0,32,0,4,0,33,0,10,0,34,0,10,0,35,0,10,0,36,0,
|
||||
4,0,37,0,9,0,38,0,10,0,39,0,10,0,40,0,10,0,41,0,
|
||||
4,0,42,0,21,0,21,0,16,0,43,0,14,0,44,0,14,0,45,0,
|
||||
10,0,46,0,14,0,47,0,14,0,48,0,14,0,49,0,14,0,50,0,
|
||||
14,0,51,0,14,0,52,0,14,0,53,0,10,0,54,0,10,0,55,0,
|
||||
4,0,56,0,10,0,57,0,10,0,58,0,10,0,59,0,10,0,60,0,
|
||||
10,0,61,0,10,0,62,0,20,0,63,0,};
|
||||
int sBulletDNAlen= sizeof(sBulletDNAstr);
|
||||
@@ -18,6 +18,11 @@ subject to the following restrictions:
|
||||
|
||||
#include "btScalar.h" // has definitions like SIMD_FORCE_INLINE
|
||||
#include "btStackAlloc.h"
|
||||
#include "btHashMap.h"
|
||||
|
||||
///only the 32bit versions for now
|
||||
extern unsigned char sBulletDNAstr[];
|
||||
extern int sBulletDNAlen;
|
||||
|
||||
class btChunk
|
||||
{
|
||||
@@ -43,7 +48,15 @@ class btSerializer
|
||||
|
||||
|
||||
#define BT_HEADER_LENGTH 12
|
||||
#if defined(__sgi) || defined (__sparc) || defined (__sparc__) || defined (__PPC__) || defined (__ppc__) || defined (__BIG_ENDIAN__)
|
||||
# define MAKE_ID(a,b,c,d) ( (int)(a)<<24 | (int)(b)<<16 | (c)<<8 | (d) )
|
||||
#else
|
||||
# define MAKE_ID(a,b,c,d) ( (int)(d)<<24 | (int)(c)<<16 | (b)<<8 | (a) )
|
||||
#endif
|
||||
|
||||
#define BT_COLLISIONOBJECT_CODE MAKE_ID('C','O','B','J')
|
||||
#define BT_RIGIDBODY_CODE MAKE_ID('R','B','D','Y')
|
||||
#define BT_BOXSHAPE_CODE MAKE_ID('B','O','X','S')
|
||||
|
||||
class btDefaultSerializer
|
||||
{
|
||||
@@ -59,7 +72,7 @@ public:
|
||||
|
||||
int m_totalSize;
|
||||
unsigned char* m_buffer;
|
||||
int m_bufferPointer;
|
||||
int m_currentSize;
|
||||
|
||||
|
||||
|
||||
@@ -70,12 +83,12 @@ public:
|
||||
|
||||
btDefaultSerializer(int totalSize)
|
||||
:m_totalSize(totalSize),
|
||||
m_bufferPointer(0)
|
||||
m_currentSize(0)
|
||||
// m_dna(0),
|
||||
// m_dnaLength(0)
|
||||
{
|
||||
m_buffer = (unsigned char*)btAlignedAlloc(16,totalSize);
|
||||
m_bufferPointer += BT_HEADER_LENGTH;
|
||||
m_currentSize += BT_HEADER_LENGTH;
|
||||
|
||||
memcpy(m_buffer, "BULLET ", 7);
|
||||
int endian= 1;
|
||||
@@ -122,16 +135,16 @@ public:
|
||||
|
||||
void writeDNA()
|
||||
{
|
||||
unsigned char* dnaTarget = m_buffer+m_bufferPointer;
|
||||
unsigned char* dnaTarget = m_buffer+m_currentSize;
|
||||
memcpy(dnaTarget,m_dna,m_dnaLength);
|
||||
m_bufferPointer += m_dnaLength;
|
||||
m_currentSize += m_dnaLength;
|
||||
}
|
||||
|
||||
virtual btChunk* allocate(size_t size, int numElements)
|
||||
{
|
||||
|
||||
unsigned char* ptr = m_buffer+m_bufferPointer;
|
||||
m_bufferPointer += size*numElements+sizeof(btChunk);
|
||||
unsigned char* ptr = m_buffer+m_currentSize;
|
||||
m_currentSize += size*numElements+sizeof(btChunk);
|
||||
|
||||
unsigned char* data = ptr + sizeof(btChunk);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user