worked a bit more on the serialization, and added a preliminary SerializeDemo.
This commit is contained in:
@@ -1235,6 +1235,25 @@ void btCollisionWorld::debugDrawWorld()
|
||||
}
|
||||
|
||||
|
||||
void btCollisionWorld::serializeCollisionObjects(btDefaultSerializer* serializer)
|
||||
{
|
||||
int i;
|
||||
//serialize all collision objects
|
||||
for (i=0;i<m_collisionObjects.size();i++)
|
||||
{
|
||||
btCollisionObject* colObj = m_collisionObjects[i];
|
||||
if (colObj->getInternalType() == btCollisionObject::CO_COLLISION_OBJECT)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void btCollisionWorld::serialize(btDefaultSerializer* serializer)
|
||||
{
|
||||
@@ -1252,20 +1271,7 @@ void btCollisionWorld::serialize(btDefaultSerializer* serializer)
|
||||
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;
|
||||
}
|
||||
|
||||
serializeCollisionObjects(serializer);
|
||||
|
||||
#if 0
|
||||
{
|
||||
|
||||
@@ -100,6 +100,8 @@ protected:
|
||||
///it is true by default, because it is error-prone (setting the position of static objects wouldn't update their AABB)
|
||||
bool m_forceUpdateAllAabbs;
|
||||
|
||||
void serializeCollisionObjects(btDefaultSerializer* serializer);
|
||||
|
||||
public:
|
||||
|
||||
//this constructor doesn't own the dispatcher and paircache/broadphase
|
||||
@@ -422,8 +424,8 @@ 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);
|
||||
///Preliminary serialization test for Bullet 2.76. Loading those files requires a separate parser (Bullet/Demos/SerializeDemo)
|
||||
virtual void serialize(btDefaultSerializer* serializer);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -323,6 +323,7 @@ public:
|
||||
|
||||
struct btBoxShapeData
|
||||
{
|
||||
btCollisionShapeData m_collisionShapeData;
|
||||
btVector3Data m_halfExtents;
|
||||
btVector3Data m_localScaling;
|
||||
};
|
||||
@@ -338,6 +339,7 @@ SIMD_FORCE_INLINE int btBoxShape::calculateSerializeBufferSize()
|
||||
SIMD_FORCE_INLINE const char* btBoxShape::serialize(void* dataBuffer) const
|
||||
{
|
||||
btBoxShapeData* boxData = (btBoxShapeData*) dataBuffer;
|
||||
btCollisionShape::serialize(&boxData->m_collisionShapeData);
|
||||
|
||||
m_implicitShapeDimensions.serialize(boxData->m_halfExtents);
|
||||
m_localScaling.serialize(boxData->m_localScaling);
|
||||
|
||||
@@ -118,6 +118,11 @@ public:
|
||||
return m_userPointer;
|
||||
}
|
||||
|
||||
virtual int calculateSerializeBufferSize();
|
||||
|
||||
///fills the dataBuffer and returns the struct name (and 0 on failure)
|
||||
virtual const char* serialize(void* dataBuffer) const;
|
||||
|
||||
};
|
||||
|
||||
///for serialization
|
||||
@@ -128,6 +133,20 @@ struct btCollisionShapeData
|
||||
char m_padding[4];
|
||||
};
|
||||
|
||||
SIMD_FORCE_INLINE int btCollisionShape::calculateSerializeBufferSize()
|
||||
{
|
||||
return sizeof(btCollisionShapeData);
|
||||
}
|
||||
|
||||
///fills the dataBuffer and returns the struct name (and 0 on failure)
|
||||
SIMD_FORCE_INLINE const char* btCollisionShape::serialize(void* dataBuffer) const
|
||||
{
|
||||
btCollisionShapeData* shapeData = (btCollisionShapeData*) dataBuffer;
|
||||
shapeData->m_userPointer = m_userPointer;
|
||||
shapeData->m_shapeType = m_shapeType;
|
||||
//shapeData->m_padding//??
|
||||
return "btCollisionShapeData";
|
||||
}
|
||||
|
||||
#endif //COLLISION_SHAPE_H
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ subject to the following restrictions:
|
||||
#include "LinearMath/btQuickprof.h"
|
||||
#include "LinearMath/btMotionState.h"
|
||||
|
||||
|
||||
#include "LinearMath/btSerializer.h"
|
||||
|
||||
|
||||
|
||||
@@ -1078,3 +1078,47 @@ const btTypedConstraint* btDiscreteDynamicsWorld::getConstraint(int index) const
|
||||
}
|
||||
|
||||
|
||||
|
||||
void btDiscreteDynamicsWorld::serializeRigidBodies(btDefaultSerializer* serializer)
|
||||
{
|
||||
int i;
|
||||
//serialize all collision objects
|
||||
for (i=0;i<m_collisionObjects.size();i++)
|
||||
{
|
||||
btCollisionObject* colObj = m_collisionObjects[i];
|
||||
if (colObj->getInternalType() == btCollisionObject::CO_RIGID_BODY)
|
||||
{
|
||||
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_RIGIDBODY_CODE;
|
||||
chunk->m_oldPtr = colObj;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void btDiscreteDynamicsWorld::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);
|
||||
}
|
||||
|
||||
serializeRigidBodies(serializer);
|
||||
|
||||
serializeCollisionObjects(serializer);
|
||||
|
||||
serializer->writeDNA();
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ protected:
|
||||
|
||||
virtual void saveKinematicState(btScalar timeStep);
|
||||
|
||||
|
||||
void serializeRigidBodies(btDefaultSerializer* serializer);
|
||||
|
||||
public:
|
||||
|
||||
@@ -190,6 +190,9 @@ public:
|
||||
return m_synchronizeAllMotionStates;
|
||||
}
|
||||
|
||||
///Preliminary serialization test for Bullet 2.76. Loading those files requires a separate parser (see Bullet/Demos/SerializeDemo)
|
||||
virtual void serialize(btDefaultSerializer* serializer);
|
||||
|
||||
};
|
||||
|
||||
#endif //BT_DISCRETE_DYNAMICS_WORLD_H
|
||||
|
||||
@@ -326,6 +326,9 @@ int btRigidBody::calculateSerializeBufferSize() const
|
||||
const char* btRigidBody::serialize(void* dataBuffer) const
|
||||
{
|
||||
btRigidBodyData* rbd = (btRigidBodyData*) dataBuffer;
|
||||
|
||||
btCollisionObject::serialize(&rbd->m_collisionObjectData);
|
||||
|
||||
m_invInertiaTensorWorld.serialize(rbd->m_invInertiaTensorWorld);
|
||||
m_linearVelocity.serialize(rbd->m_linearVelocity);
|
||||
m_angularVelocity.serialize(rbd->m_angularVelocity);
|
||||
@@ -347,8 +350,6 @@ const char* btRigidBody::serialize(void* dataBuffer) const
|
||||
rbd->m_linearSleepingThreshold=m_linearSleepingThreshold;
|
||||
rbd->m_angularSleepingThreshold = m_angularSleepingThreshold;
|
||||
|
||||
btCollisionObject::serialize(&rbd->m_collisionObjectData);
|
||||
|
||||
return "btRigidBodyData";
|
||||
}
|
||||
|
||||
|
||||
@@ -506,6 +506,8 @@ public:
|
||||
///btRigidBodyData is used for btRigidBody serialization
|
||||
struct btRigidBodyData
|
||||
{
|
||||
btCollisionObjectData m_collisionObjectData;
|
||||
|
||||
btMatrix3x3Data m_invInertiaTensorWorld;
|
||||
btVector3Data m_linearVelocity;
|
||||
btVector3Data m_angularVelocity;
|
||||
@@ -531,8 +533,6 @@ struct btRigidBodyData
|
||||
|
||||
btScalar m_linearSleepingThreshold;
|
||||
btScalar m_angularSleepingThreshold;
|
||||
|
||||
btCollisionObjectData m_collisionObjectData;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -86,9 +86,9 @@ public:
|
||||
|
||||
btDefaultSerializer(int totalSize)
|
||||
:m_totalSize(totalSize),
|
||||
m_currentSize(0)
|
||||
// m_dna(0),
|
||||
// m_dnaLength(0)
|
||||
m_currentSize(0),
|
||||
m_dna(0),
|
||||
m_dnaLength(0)
|
||||
{
|
||||
m_buffer = (unsigned char*)btAlignedAlloc(16,totalSize);
|
||||
m_currentSize += BT_HEADER_LENGTH;
|
||||
@@ -165,6 +165,9 @@ public:
|
||||
|
||||
void initDNA(const char* bdna,int dnalen)
|
||||
{
|
||||
///was already initialized
|
||||
if (m_dna)
|
||||
return;
|
||||
|
||||
m_dna = btAlignedAlloc(dnalen,16);
|
||||
memcpy(m_dna,bdna,dnalen);
|
||||
|
||||
Reference in New Issue
Block a user