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:
erwin.coumans
2010-01-20 01:00:39 +00:00
parent 677a0ca700
commit 50a3c32a5f
7 changed files with 212 additions and 22 deletions

View File

@@ -31,6 +31,7 @@ subject to the following restrictions:
#include "LinearMath/btAabbUtil2.h"
#include "LinearMath/btQuickprof.h"
#include "LinearMath/btStackAlloc.h"
#include "LinearMath/btSerializer.h"
//#define USE_BRUTEFORCE_RAYBROADPHASE 1
//RECALCULATE_AABB is slower, but benefit is that you don't need to call 'stepSimulation' or 'updateAabbs' before using a rayTest
@@ -1228,4 +1229,52 @@ void btCollisionWorld::debugDrawWorld()
}
}
}
void btCollisionWorld::serialize(btDefaultSerializer* serializer)
{
const bool VOID_IS_8 = ((sizeof(void*)==8));
if (VOID_IS_8)
{
//64bit not yet supported (soon)
btAssert(0);
return;
} else
{
serializer->initDNA((const char*)sBulletDNAstr,sBulletDNAlen);
}
int i;
//serialize all collision objects
for (i=0;i<m_collisionObjects.size();i++)
{
btCollisionObject* colObj = m_collisionObjects[i];
int len = colObj->calculateSerializeBufferSize();
btChunk* chunk = serializer->allocate(len,1);
const char* structType = colObj->serialize(chunk->m_oldPtr);
chunk->m_dna_nr = serializer->getReverseType(structType);
chunk->m_chunkCode = BT_COLLISIONOBJECT_CODE;
chunk->m_oldPtr = colObj;
}
#if 0
{
//serialize all collision shapes
int len = boxShape->calculateSerializeBufferSize();
btChunk* chunk = serializer->allocate(len,1);
const char* structType = boxShape->serialize(chunk->m_oldPtr);
chunk->m_dna_nr = serializer->getReverseType(structType);
chunk->m_chunkCode = BT_BOXSHAPE_CODE;
chunk->m_oldPtr = boxShape;
}
#endif
serializer->writeDNA();
}

View File

@@ -68,6 +68,8 @@ class btStackAlloc;
class btCollisionShape;
class btConvexShape;
class btBroadphaseInterface;
class btDefaultSerializer;
#include "LinearMath/btVector3.h"
#include "LinearMath/btTransform.h"
#include "btCollisionObject.h"
@@ -420,6 +422,9 @@ public:
m_forceUpdateAllAabbs = forceUpdateAllAabbs;
}
///Preliminary serialization test for Bullet 2.76. Loading those files requires a separate parser (to be added in the Bullet/Extras)
void serialize(btDefaultSerializer* serializer);
};