From 0f707603f1c4ff4d713909854753dc3462fbf4f7 Mon Sep 17 00:00:00 2001 From: "erwin.coumans" Date: Sat, 23 Jan 2010 00:04:58 +0000 Subject: [PATCH] more work on serialization, work-in-progress --- Demos/SerializeDemo/SerializeDemo.cpp | 131 +-------- .../Serialize/BulletFileLoader/CMakeLists.txt | 2 + .../BulletFileLoader/autogenerated/bullet.h | 2 + .../autogenerated/bullet_Common.h | 2 + .../bullet_btMultiSphereShapeData.h | 43 +++ .../bullet_btPositionAndRadius.h | 41 +++ .../BulletFileLoader/btBulletFileLoader.cpp | 255 ++++++++++++++++++ .../BulletFileLoader/btBulletFileLoader.h | 96 +++++++ .../CollisionDispatch/btCollisionWorld.cpp | 30 +-- .../CollisionDispatch/btCollisionWorld.h | 6 +- .../CollisionShapes/btCollisionShape.h | 6 +- .../CollisionShapes/btConvexInternalShape.h | 4 +- .../CollisionShapes/btMultiSphereShape.cpp | 30 +-- .../CollisionShapes/btMultiSphereShape.h | 13 +- .../Dynamics/btDiscreteDynamicsWorld.cpp | 23 +- .../Dynamics/btDiscreteDynamicsWorld.h | 4 +- src/LinearMath/btSerializer.cpp | 142 +++++----- src/LinearMath/btSerializer.h | 214 ++++++++++----- 18 files changed, 700 insertions(+), 344 deletions(-) create mode 100644 Extras/Serialize/BulletFileLoader/autogenerated/bullet_btMultiSphereShapeData.h create mode 100644 Extras/Serialize/BulletFileLoader/autogenerated/bullet_btPositionAndRadius.h create mode 100644 Extras/Serialize/BulletFileLoader/btBulletFileLoader.cpp create mode 100644 Extras/Serialize/BulletFileLoader/btBulletFileLoader.h diff --git a/Demos/SerializeDemo/SerializeDemo.cpp b/Demos/SerializeDemo/SerializeDemo.cpp index 8a5a8725b..320bb4ac4 100644 --- a/Demos/SerializeDemo/SerializeDemo.cpp +++ b/Demos/SerializeDemo/SerializeDemo.cpp @@ -37,6 +37,10 @@ subject to the following restrictions: #ifdef TEST_SERIALIZATION #include "LinearMath/btSerializer.h" #include "btBulletFile.h" +#include "btBulletFileLoader.h" + + + #endif //TEST_SERIALIZATION @@ -150,8 +154,8 @@ void SerializeDemo::initPhysics() // Re-using the same collision is better for memory usage and performance int numSpheres = 2; - btVector3 positions[2] = {btVector3(0.1,0.2,0.3),btVector3(0.4,0.5,0.6)}; - btScalar radii[2] = {0.3,0.4}; + btVector3 positions[2] = {btVector3(0.1f,0.2f,0.3f),btVector3(0.4f,0.5f,0.6f)}; + btScalar radii[2] = {0.3f,0.4f}; //btMultiSphereShape* colShape = new btMultiSphereShape(positions,radii,numSpheres); @@ -217,7 +221,7 @@ void SerializeDemo::initPhysics() m_dynamicsWorld->serialize(serializer); FILE* f2 = fopen("testFile.bullet","wb"); - fwrite(serializer->m_buffer,serializer->m_currentSize,1,f2); + fwrite(serializer->getBufferPointer(),serializer->getCurrentBufferSize(),1,f2); fclose(f2); exitPhysics(); @@ -225,127 +229,10 @@ void SerializeDemo::initPhysics() //now try again from the loaded file setupEmptyDynamicsWorld(); - bParse::btBulletFile* bulletFile2 = new bParse::btBulletFile("testFile.bullet"); - bool ok = (bulletFile2->getFlags()& bParse::FD_OK)!=0; - bool verboseDumpAllTypes = false; - if (ok) - bulletFile2->parse(verboseDumpAllTypes); - - if (verboseDumpAllTypes) - { - bulletFile2->dumpChunks(bulletFile2->getFileDNA()); - } + btBulletFileLoader* fileLoader = new btBulletFileLoader(m_dynamicsWorld); - int i; - btHashMap shapeMap; + fileLoader->loadFileFromMemory("testFile.bullet"); - for (i=0;im_collisionShapes.size();i++) - { - btCollisionShapeData* shapeData = (btCollisionShapeData*)bulletFile2->m_collisionShapes[i]; - switch (shapeData->m_shapeType) - { - case CYLINDER_SHAPE_PROXYTYPE: - case CAPSULE_SHAPE_PROXYTYPE: - case BOX_SHAPE_PROXYTYPE: - case SPHERE_SHAPE_PROXYTYPE: - case MULTI_SPHERE_SHAPE_PROXYTYPE: - { - btConvexInternalShapeData* bsd = (btConvexInternalShapeData*)shapeData; - btVector3 implicitShapeDimensions; - implicitShapeDimensions.deSerialize(bsd->m_implicitShapeDimensions); - btVector3 margin(bsd->m_collisionMargin,bsd->m_collisionMargin,bsd->m_collisionMargin); - btCollisionShape* shape = 0; - switch (shapeData->m_shapeType) - { - case BOX_SHAPE_PROXYTYPE: - { - shape = new btBoxShape(implicitShapeDimensions+margin); - break; - } - case SPHERE_SHAPE_PROXYTYPE: - { - shape = new btSphereShape(implicitShapeDimensions.getX()); - break; - } - case CAPSULE_SHAPE_PROXYTYPE: - { - shape = new btCapsuleShape(implicitShapeDimensions.getX(),implicitShapeDimensions.getY()); - break; - } - case CYLINDER_SHAPE_PROXYTYPE: - { - shape = new btCylinderShape(implicitShapeDimensions+margin); - break; - } - case MULTI_SPHERE_SHAPE_PROXYTYPE: - { -#if 0 - btMultiSphereShapeData* mss = (btMultiSphereShapeData*)bsd; - btVector3 pos[2]; - pos[0].deSerialize(mss->m_localPositionArrayPtr[0]); - pos[1].deSerialize(mss->m_localPositionArrayPtr[1]); - - btScalar radii[2] = {0.3,0.4}; - shape = new btMultiSphereShape(pos,radii,mss->m_localPositionArraySize); -#endif - break; - } - default: - { - printf("error: cannot create shape type (%d)\n",shapeData->m_shapeType); - } - } - - if (shape) - { - shape->setMargin(bsd->m_collisionMargin); - btVector3 localScaling; - localScaling.deSerialize(bsd->m_localScaling); - shape->setLocalScaling(localScaling); - m_collisionShapes.push_back(shape); - shapeMap.insert(shapeData,shape); - } - break; - } - default: - { - printf("unsupported shape type (%d)\n",shapeData->m_shapeType); - } - } - - } - for (i=0;im_rigidBodies.size();i++) - { - btRigidBodyData* colObjData = (btRigidBodyData*)bulletFile2->m_rigidBodies[i]; - btScalar mass = colObjData->m_inverseMass? 1.f/colObjData->m_inverseMass : 0.f; - btVector3 localInertia; - localInertia.setZero(); - btCollisionShape** shapePtr = shapeMap.find(colObjData->m_collisionObjectData.m_collisionShape); - if (shapePtr && *shapePtr) - { - btTransform startTransform; - startTransform.deSerialize(colObjData->m_collisionObjectData.m_worldTransform); - - btCollisionShape* shape = (btCollisionShape*)*shapePtr; - - if (mass) - { - shape->calculateLocalInertia(mass,localInertia); - } - - btRigidBody* body = localCreateRigidBody(mass,startTransform,shape); - - } else - { - printf("error: no shape found\n"); - } - } - - for (i=0;im_collisionObjects.size();i++) - { - btCollisionObjectData* colObjData = (btCollisionObjectData*)bulletFile2->m_collisionObjects[i]; - printf("bla"); - } #endif //TEST_SERIALIZATION diff --git a/Extras/Serialize/BulletFileLoader/CMakeLists.txt b/Extras/Serialize/BulletFileLoader/CMakeLists.txt index fefe62f92..e6208d30f 100644 --- a/Extras/Serialize/BulletFileLoader/CMakeLists.txt +++ b/Extras/Serialize/BulletFileLoader/CMakeLists.txt @@ -14,4 +14,6 @@ bFile.cpp bFile.h btBulletFile.cpp btBulletFile.h +btBulletFileLoader.cpp +btBulletFileLoader.h ) diff --git a/Extras/Serialize/BulletFileLoader/autogenerated/bullet.h b/Extras/Serialize/BulletFileLoader/autogenerated/bullet.h index 5cd5065a9..e9fe17d2d 100644 --- a/Extras/Serialize/BulletFileLoader/autogenerated/bullet.h +++ b/Extras/Serialize/BulletFileLoader/autogenerated/bullet.h @@ -27,6 +27,8 @@ #include "bullet_btTransformData.h" #include "bullet_btCollisionShapeData.h" #include "bullet_btConvexInternalShapeData.h" +#include "bullet_btPositionAndRadius.h" +#include "bullet_btMultiSphereShapeData.h" #include "bullet_btCollisionObjectData.h" #include "bullet_btRigidBodyData.h" #endif//__BULLET_H__ \ No newline at end of file diff --git a/Extras/Serialize/BulletFileLoader/autogenerated/bullet_Common.h b/Extras/Serialize/BulletFileLoader/autogenerated/bullet_Common.h index 70e32017d..60216cddf 100644 --- a/Extras/Serialize/BulletFileLoader/autogenerated/bullet_Common.h +++ b/Extras/Serialize/BulletFileLoader/autogenerated/bullet_Common.h @@ -34,6 +34,8 @@ namespace Bullet { class btTransformData; class btCollisionShapeData; class btConvexInternalShapeData; + class btPositionAndRadius; + class btMultiSphereShapeData; class btCollisionObjectData; class btRigidBodyData; } diff --git a/Extras/Serialize/BulletFileLoader/autogenerated/bullet_btMultiSphereShapeData.h b/Extras/Serialize/BulletFileLoader/autogenerated/bullet_btMultiSphereShapeData.h new file mode 100644 index 000000000..8aaf49443 --- /dev/null +++ b/Extras/Serialize/BulletFileLoader/autogenerated/bullet_btMultiSphereShapeData.h @@ -0,0 +1,43 @@ +/* Copyright (C) 2006-2009 Erwin Coumans & Charlie C +* +* This software is provided 'as-is', without any express or implied +* warranty. In no event will the authors be held liable for any damages +* arising from the use of this software. +* +* Permission is granted to anyone to use this software for any purpose, +* including commercial applications, and to alter it and redistribute it +* freely, subject to the following restrictions: +* +* 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. +* 2. Altered source versions must be plainly marked as such, and must not be +* misrepresented as being the original software. +* 3. This notice may not be removed or altered from any source distribution. +*/ +// Auto generated from makesdna dna.c +#ifndef __BULLET_BTMULTISPHERESHAPEDATA__H__ +#define __BULLET_BTMULTISPHERESHAPEDATA__H__ + + +// -------------------------------------------------- // +#include "bullet_Common.h" +#include "bullet_btConvexInternalShapeData.h" + +namespace Bullet { + + + // ---------------------------------------------- // + class btMultiSphereShapeData + { + public: + btConvexInternalShapeData m_convexInternalShapeData; + btPositionAndRadius *m_localPositionArrayPtr; + int m_localPositionArraySize; + char m_padding[4]; + }; +} + + +#endif//__BULLET_BTMULTISPHERESHAPEDATA__H__ diff --git a/Extras/Serialize/BulletFileLoader/autogenerated/bullet_btPositionAndRadius.h b/Extras/Serialize/BulletFileLoader/autogenerated/bullet_btPositionAndRadius.h new file mode 100644 index 000000000..ad3703d93 --- /dev/null +++ b/Extras/Serialize/BulletFileLoader/autogenerated/bullet_btPositionAndRadius.h @@ -0,0 +1,41 @@ +/* Copyright (C) 2006-2009 Erwin Coumans & Charlie C +* +* This software is provided 'as-is', without any express or implied +* warranty. In no event will the authors be held liable for any damages +* arising from the use of this software. +* +* Permission is granted to anyone to use this software for any purpose, +* including commercial applications, and to alter it and redistribute it +* freely, subject to the following restrictions: +* +* 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. +* 2. Altered source versions must be plainly marked as such, and must not be +* misrepresented as being the original software. +* 3. This notice may not be removed or altered from any source distribution. +*/ +// Auto generated from makesdna dna.c +#ifndef __BULLET_BTPOSITIONANDRADIUS__H__ +#define __BULLET_BTPOSITIONANDRADIUS__H__ + + +// -------------------------------------------------- // +#include "bullet_Common.h" +#include "bullet_btVector3Data.h" + +namespace Bullet { + + + // ---------------------------------------------- // + class btPositionAndRadius + { + public: + btVector3Data m_pos; + btScalar m_radius; + }; +} + + +#endif//__BULLET_BTPOSITIONANDRADIUS__H__ diff --git a/Extras/Serialize/BulletFileLoader/btBulletFileLoader.cpp b/Extras/Serialize/BulletFileLoader/btBulletFileLoader.cpp new file mode 100644 index 000000000..d041bc6ec --- /dev/null +++ b/Extras/Serialize/BulletFileLoader/btBulletFileLoader.cpp @@ -0,0 +1,255 @@ + +#include "btBulletFileLoader.h" +#include "btBulletFile.h" + +#include "btBulletDynamicsCommon.h" + +btBulletFileLoader::btBulletFileLoader(btDynamicsWorld* world) +:m_dynamicsWorld(world), +m_verboseDumpAllTypes(false) +{ +} + +bool btBulletFileLoader::loadFileFromMemory( char* fileName) +{ + bParse::btBulletFile* bulletFile2 = new bParse::btBulletFile("testFile.bullet"); + + bool result = loadFileFromMemory(bulletFile2); + + delete bulletFile2; + + return result; + +} + + + +bool btBulletFileLoader::loadFileFromMemory( char* memoryBuffer, int len) +{ + bParse::btBulletFile* bulletFile2 = new bParse::btBulletFile(memoryBuffer,len); + + bool result = loadFileFromMemory(bulletFile2); + + delete bulletFile2; + + return result; +} + + +bool btBulletFileLoader::loadFileFromMemory( bParse::btBulletFile* bulletFile2) +{ + + + bool ok = (bulletFile2->getFlags()& bParse::FD_OK)!=0; + + if (ok) + bulletFile2->parse(m_verboseDumpAllTypes); + else + return false; + + if (m_verboseDumpAllTypes) + { + bulletFile2->dumpChunks(bulletFile2->getFileDNA()); + } + + int i; + btHashMap shapeMap; + + for (i=0;im_collisionShapes.size();i++) + { + btCollisionShapeData* shapeData = (btCollisionShapeData*)bulletFile2->m_collisionShapes[i]; + switch (shapeData->m_shapeType) + { + case CYLINDER_SHAPE_PROXYTYPE: + case CAPSULE_SHAPE_PROXYTYPE: + case BOX_SHAPE_PROXYTYPE: + case SPHERE_SHAPE_PROXYTYPE: + case MULTI_SPHERE_SHAPE_PROXYTYPE: + { + btConvexInternalShapeData* bsd = (btConvexInternalShapeData*)shapeData; + btVector3 implicitShapeDimensions; + implicitShapeDimensions.deSerialize(bsd->m_implicitShapeDimensions); + btVector3 margin(bsd->m_collisionMargin,bsd->m_collisionMargin,bsd->m_collisionMargin); + btCollisionShape* shape = 0; + switch (shapeData->m_shapeType) + { + case BOX_SHAPE_PROXYTYPE: + { + shape = createBoxShape(implicitShapeDimensions+margin); + break; + } + case SPHERE_SHAPE_PROXYTYPE: + { + shape = createSphereShape(implicitShapeDimensions.getX()); + break; + } + case CAPSULE_SHAPE_PROXYTYPE: + { + shape = createCapsuleShape(implicitShapeDimensions.getX(),implicitShapeDimensions.getY()); + break; + } + case CYLINDER_SHAPE_PROXYTYPE: + { + btVector3 halfExtents = implicitShapeDimensions+margin; + + shape = createCylinderShapeY(halfExtents.getX(),halfExtents.getY()); + break; + } + case MULTI_SPHERE_SHAPE_PROXYTYPE: + { +#if 1 + btMultiSphereShapeData* mss = (btMultiSphereShapeData*)bsd; + int numSpheres = mss->m_localPositionArraySize; + + btAlignedObjectArray tmpPos; + btAlignedObjectArray radii; + radii.resize(numSpheres); + tmpPos.resize(numSpheres); + + for (int i=0;im_localPositionArrayPtr[i].m_pos); + radii[i] = mss->m_localPositionArrayPtr[i].m_radius; + } + + + shape = new btMultiSphereShape(&tmpPos[0],&radii[0],numSpheres); +#endif + break; + } + default: + { + printf("error: cannot create shape type (%d)\n",shapeData->m_shapeType); + } + } + + if (shape) + { + shape->setMargin(bsd->m_collisionMargin); + btVector3 localScaling; + localScaling.deSerialize(bsd->m_localScaling); + shape->setLocalScaling(localScaling); + + shapeMap.insert(shapeData,shape); + } + break; + } + default: + { + printf("unsupported shape type (%d)\n",shapeData->m_shapeType); + } + } + + } + for (i=0;im_rigidBodies.size();i++) + { + btRigidBodyData* colObjData = (btRigidBodyData*)bulletFile2->m_rigidBodies[i]; + btScalar mass = colObjData->m_inverseMass? 1.f/colObjData->m_inverseMass : 0.f; + btVector3 localInertia; + localInertia.setZero(); + btCollisionShape** shapePtr = shapeMap.find(colObjData->m_collisionObjectData.m_collisionShape); + if (shapePtr && *shapePtr) + { + btTransform startTransform; + startTransform.deSerialize(colObjData->m_collisionObjectData.m_worldTransform); + + btCollisionShape* shape = (btCollisionShape*)*shapePtr; + + if (mass) + { + shape->calculateLocalInertia(mass,localInertia); + } + + bool isDynamic = mass!=0.f; + createRigidBody(isDynamic,mass,startTransform,shape); + + } else + { + printf("error: no shape found\n"); + } + } + + for (i=0;im_collisionObjects.size();i++) + { + btCollisionObjectData* colObjData = (btCollisionObjectData*)bulletFile2->m_collisionObjects[i]; + printf("bla"); + } + return false; +} + +btTypedConstraint* btBulletFileLoader::createUniversalD6Constraint(class btRigidBody* body0,class btRigidBody* otherBody, + btTransform& localAttachmentFrameRef, + btTransform& localAttachmentOther, + const btVector3& linearMinLimits, + const btVector3& linearMaxLimits, + const btVector3& angularMinLimits, + const btVector3& angularMaxLimits, + bool disableCollisionsBetweenLinkedBodies) +{ + return 0; +} + +btRigidBody* btBulletFileLoader::createRigidBody(bool isDynamic, float mass, const btTransform& startTransform,btCollisionShape* shape) +{ + btVector3 localInertia; + + if (mass) + shape->calculateLocalInertia(mass,localInertia); + + btRigidBody* body = new btRigidBody(mass,0,shape,localInertia); + body->setWorldTransform(startTransform); + + m_dynamicsWorld->addRigidBody(body); + + return body; +} + +btCollisionShape* btBulletFileLoader::createPlaneShape(const btVector3& planeNormal,btScalar planeConstant) +{ + return 0; +} +btCollisionShape* btBulletFileLoader::createBoxShape(const btVector3& halfExtents) +{ + return new btBoxShape(halfExtents); +} +btCollisionShape* btBulletFileLoader::createSphereShape(btScalar radius) +{ + return new btSphereShape(radius); +} + +btCollisionShape* btBulletFileLoader::createCapsuleShape(btScalar radius, btScalar height) +{ + return new btCapsuleShape(radius,height); +} + + + +btCollisionShape* btBulletFileLoader::createCylinderShapeY(btScalar radius,btScalar height) +{ + return new btCylinderShape(btVector3(radius,height,radius)); +} +btTriangleMesh* btBulletFileLoader::createTriangleMeshContainer() +{ + return 0; +} +btCollisionShape* btBulletFileLoader::createBvhTriangleMeshShape(btTriangleMesh* trimesh) +{ + return 0; +} +btCollisionShape* btBulletFileLoader::createConvexTriangleMeshShape(btTriangleMesh* trimesh) +{ + return 0; +} +btCollisionShape* btBulletFileLoader::createGimpactShape(btTriangleMesh* trimesh) +{ + return 0; +} +btConvexHullShape* btBulletFileLoader::createConvexHullShape() +{ + return 0; +} + +btCompoundShape* btBulletFileLoader::createCompoundShape() +{ + return 0; +} \ No newline at end of file diff --git a/Extras/Serialize/BulletFileLoader/btBulletFileLoader.h b/Extras/Serialize/BulletFileLoader/btBulletFileLoader.h new file mode 100644 index 000000000..5afd51640 --- /dev/null +++ b/Extras/Serialize/BulletFileLoader/btBulletFileLoader.h @@ -0,0 +1,96 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2010 Erwin Coumans http://continuousphysics.com/Bullet/ + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +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. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + + +#ifndef BULLET_FILE_LOADER_H +#define BULLET_FILE_LOADER_H + +#include "LinearMath/btTransform.h" +#include "LinearMath/btVector3.h" +#include "LinearMath/btAlignedObjectArray.h" +#include "LinearMath/btHashMap.h" + +class btBulletFile; +class btCollisionShape; +class btRigidBody; +class btTypedConstraint; +class btDynamicsWorld; +struct ConstraintInput; +class btRigidBodyColladaInfo; + +namespace bParse +{ + class btBulletFile; +}; + + +class btBulletFileLoader +{ + btDynamicsWorld* m_dynamicsWorld; + + bool m_verboseDumpAllTypes; + +public: + + btBulletFileLoader(btDynamicsWorld* world); + + bool loadFileFromMemory(char* fileName); + + bool loadFileFromMemory(char *memoryBuffer, int len); + + bool loadFileFromMemory(bParse::btBulletFile* file); + + void setVerboseMode(bool verboseDumpAllTypes) + { + m_verboseDumpAllTypes = verboseDumpAllTypes; + } + + bool getVerboseMode() const + { + return m_verboseDumpAllTypes; + } + + ///those virtuals are called by load + virtual btTypedConstraint* createUniversalD6Constraint( + class btRigidBody* body0,class btRigidBody* otherBody, + btTransform& localAttachmentFrameRef, + btTransform& localAttachmentOther, + const btVector3& linearMinLimits, + const btVector3& linearMaxLimits, + const btVector3& angularMinLimits, + const btVector3& angularMaxLimits, + bool disableCollisionsBetweenLinkedBodies + ); + + virtual btRigidBody* createRigidBody(bool isDynamic, + float mass, + const btTransform& startTransform, + btCollisionShape* shape); + + virtual btCollisionShape* createPlaneShape(const btVector3& planeNormal,btScalar planeConstant); + virtual btCollisionShape* createBoxShape(const btVector3& halfExtents); + virtual btCollisionShape* createSphereShape(btScalar radius); + virtual btCollisionShape* createCapsuleShape(btScalar radius, btScalar height); + virtual btCollisionShape* createCylinderShapeY(btScalar radius,btScalar height); + virtual class btTriangleMesh* createTriangleMeshContainer(); + virtual btCollisionShape* createBvhTriangleMeshShape(btTriangleMesh* trimesh); + virtual btCollisionShape* createConvexTriangleMeshShape(btTriangleMesh* trimesh); + virtual btCollisionShape* createGimpactShape(btTriangleMesh* trimesh); + virtual class btConvexHullShape* createConvexHullShape(); + virtual class btCompoundShape* createCompoundShape(); + +}; + +#endif //BULLET_FILE_LOADER_H \ No newline at end of file diff --git a/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp b/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp index f3012b646..831f319f3 100644 --- a/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp +++ b/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp @@ -1235,7 +1235,7 @@ void btCollisionWorld::debugDrawWorld() } -void btCollisionWorld::serializeCollisionObjects(btDefaultSerializer* serializer) +void btCollisionWorld::serializeCollisionObjects(btSerializer* serializer) { int i; //serialize all collision objects @@ -1244,12 +1244,9 @@ void btCollisionWorld::serializeCollisionObjects(btDefaultSerializer* serializer btCollisionObject* colObj = m_collisionObjects[i]; if (colObj->getInternalType() == btCollisionObject::CO_COLLISION_OBJECT) { - int len = colObj->calculateSerializeBufferSize(); - btChunk* chunk = serializer->allocate(len,1); + btChunk* chunk = serializer->allocate(colObj->calculateSerializeBufferSize(),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; + serializer->finalizeChunk(chunk,structType,BT_COLLISIONOBJECT_CODE,colObj); } } @@ -1268,33 +1265,18 @@ void btCollisionWorld::serializeCollisionObjects(btDefaultSerializer* serializer int len = shape->calculateSerializeBufferSize(); btChunk* chunk = serializer->allocate(len,1); const char* structType = shape->serialize(chunk->m_oldPtr, serializer); - chunk->m_dna_nr = serializer->getReverseType(structType); - chunk->m_chunkCode = BT_SHAPE_CODE; - chunk->m_oldPtr = shape; + serializer->finalizeChunk(chunk,structType,BT_SHAPE_CODE,shape); } } } -void btCollisionWorld::serialize(btDefaultSerializer* serializer) +void btCollisionWorld::serialize(btSerializer* 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); - } - serializeCollisionObjects(serializer); - serializer->writeDNA(); + serializer->finishSerialization(); } diff --git a/src/BulletCollision/CollisionDispatch/btCollisionWorld.h b/src/BulletCollision/CollisionDispatch/btCollisionWorld.h index 4cda91b7b..f199a66cd 100644 --- a/src/BulletCollision/CollisionDispatch/btCollisionWorld.h +++ b/src/BulletCollision/CollisionDispatch/btCollisionWorld.h @@ -68,7 +68,7 @@ class btStackAlloc; class btCollisionShape; class btConvexShape; class btBroadphaseInterface; -class btDefaultSerializer; +class btSerializer; #include "LinearMath/btVector3.h" #include "LinearMath/btTransform.h" @@ -100,7 +100,7 @@ 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); + void serializeCollisionObjects(btSerializer* serializer); public: @@ -425,7 +425,7 @@ public: } ///Preliminary serialization test for Bullet 2.76. Loading those files requires a separate parser (Bullet/Demos/SerializeDemo) - virtual void serialize(btDefaultSerializer* serializer); + virtual void serialize(btSerializer* serializer); }; diff --git a/src/BulletCollision/CollisionShapes/btCollisionShape.h b/src/BulletCollision/CollisionShapes/btCollisionShape.h index 5205bf014..afcd25193 100644 --- a/src/BulletCollision/CollisionShapes/btCollisionShape.h +++ b/src/BulletCollision/CollisionShapes/btCollisionShape.h @@ -20,7 +20,7 @@ subject to the following restrictions: #include "LinearMath/btVector3.h" #include "LinearMath/btMatrix3x3.h" #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" //for the shape types -class btDefaultSerializer; +class btSerializer; ///The btCollisionShape class provides an interface for collision shapes that can be shared among btCollisionObjects. @@ -121,7 +121,7 @@ public: virtual int calculateSerializeBufferSize(); ///fills the dataBuffer and returns the struct name (and 0 on failure) - virtual const char* serialize(void* dataBuffer, btDefaultSerializer* serializer) const; + virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; }; @@ -139,7 +139,7 @@ SIMD_FORCE_INLINE int btCollisionShape::calculateSerializeBufferSize() } ///fills the dataBuffer and returns the struct name (and 0 on failure) -SIMD_FORCE_INLINE const char* btCollisionShape::serialize(void* dataBuffer, btDefaultSerializer* serializer) const +SIMD_FORCE_INLINE const char* btCollisionShape::serialize(void* dataBuffer, btSerializer* serializer) const { btCollisionShapeData* shapeData = (btCollisionShapeData*) dataBuffer; shapeData->m_userPointer = m_userPointer; diff --git a/src/BulletCollision/CollisionShapes/btConvexInternalShape.h b/src/BulletCollision/CollisionShapes/btConvexInternalShape.h index ae34b2e48..fc99740c4 100644 --- a/src/BulletCollision/CollisionShapes/btConvexInternalShape.h +++ b/src/BulletCollision/CollisionShapes/btConvexInternalShape.h @@ -112,7 +112,7 @@ public: virtual int calculateSerializeBufferSize(); ///fills the dataBuffer and returns the struct name (and 0 on failure) - virtual const char* serialize(void* dataBuffer, btDefaultSerializer* serializer) const; + virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; }; @@ -142,7 +142,7 @@ SIMD_FORCE_INLINE int btConvexInternalShape::calculateSerializeBufferSize() } ///fills the dataBuffer and returns the struct name (and 0 on failure) -SIMD_FORCE_INLINE const char* btConvexInternalShape::serialize(void* dataBuffer, btDefaultSerializer* serializer) const +SIMD_FORCE_INLINE const char* btConvexInternalShape::serialize(void* dataBuffer, btSerializer* serializer) const { btConvexInternalShapeData* shapeData = (btConvexInternalShapeData*) dataBuffer; btCollisionShape::serialize(&shapeData->m_collisionShapeData, serializer); diff --git a/src/BulletCollision/CollisionShapes/btMultiSphereShape.cpp b/src/BulletCollision/CollisionShapes/btMultiSphereShape.cpp index 83f428e09..207bda077 100644 --- a/src/BulletCollision/CollisionShapes/btMultiSphereShape.cpp +++ b/src/BulletCollision/CollisionShapes/btMultiSphereShape.cpp @@ -140,39 +140,27 @@ void btMultiSphereShape::calculateLocalInertia(btScalar mass,btVector3& inertia) ///fills the dataBuffer and returns the struct name (and 0 on failure) -const char* btMultiSphereShape::serialize(void* dataBuffer, btDefaultSerializer* serializer) const +const char* btMultiSphereShape::serialize(void* dataBuffer, btSerializer* serializer) const { btMultiSphereShapeData* shapeData = (btMultiSphereShapeData*) dataBuffer; btConvexInternalShape::serialize(&shapeData->m_convexInternalShapeData, serializer); - shapeData->m_localPositionArrayPtr = 0; int numElem = m_localPositionArray.size(); + shapeData->m_localPositionArrayPtr = numElem ? (btPositionAndRadius*)&m_localPositionArray[0]: 0; - shapeData->m_localPositionArraySize = numElem; if (numElem) { - void* oldPtr = (void*)&m_localPositionArray[0].getX(); - shapeData->m_localPositionArrayPtr = (btVector3Data*)oldPtr; - - int sz = sizeof(btVector3Data); - - btChunk* chunk = serializer->allocate(sz,numElem); - const char* structType = "btVector3Data"; - btVector3Data* memPtr = (btVector3Data*)chunk->m_oldPtr; - for (int i=0;iallocate(sizeof(btPositionAndRadius),numElem); + btPositionAndRadius* memPtr = (btPositionAndRadius*)chunk->m_oldPtr; + for (int i=0;im_pos); + memPtr->m_radius = m_radiArray[i]; } - chunk->m_dna_nr = serializer->getReverseType("btVector3Data"); - chunk->m_chunkCode = BT_VECTOR3_CODE; - chunk->m_oldPtr = oldPtr; + serializer->finalizeChunk(chunk,"btVector3Data",BT_ARRAY_CODE,(void*)&m_localPositionArray[0]); } - - shapeData->m_radiArrayPtr = 0; - shapeData->m_radiArraySize = 0; - + return "btMultiSphereShapeData"; } diff --git a/src/BulletCollision/CollisionShapes/btMultiSphereShape.h b/src/BulletCollision/CollisionShapes/btMultiSphereShape.h index 8673da461..bfad948c5 100644 --- a/src/BulletCollision/CollisionShapes/btMultiSphereShape.h +++ b/src/BulletCollision/CollisionShapes/btMultiSphereShape.h @@ -64,19 +64,24 @@ public: virtual int calculateSerializeBufferSize(); ///fills the dataBuffer and returns the struct name (and 0 on failure) - virtual const char* serialize(void* dataBuffer, btDefaultSerializer* serializer) const; + virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; }; +struct btPositionAndRadius +{ + btVector3Data m_pos; + btScalar m_radius; +}; + struct btMultiSphereShapeData { btConvexInternalShapeData m_convexInternalShapeData; - btVector3Data *m_localPositionArrayPtr; - btScalar *m_radiArrayPtr; + btPositionAndRadius *m_localPositionArrayPtr; int m_localPositionArraySize; - int m_radiArraySize; + char m_padding[4]; }; diff --git a/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp b/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp index b37e39355..97412d428 100644 --- a/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp +++ b/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp @@ -1079,7 +1079,7 @@ const btTypedConstraint* btDiscreteDynamicsWorld::getConstraint(int index) const -void btDiscreteDynamicsWorld::serializeRigidBodies(btDefaultSerializer* serializer) +void btDiscreteDynamicsWorld::serializeRigidBodies(btSerializer* serializer) { int i; //serialize all collision objects @@ -1091,34 +1091,21 @@ void btDiscreteDynamicsWorld::serializeRigidBodies(btDefaultSerializer* serializ 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; + serializer->finalizeChunk(chunk,structType,BT_RIGIDBODY_CODE,colObj); } } } -void btDiscreteDynamicsWorld::serialize(btDefaultSerializer* serializer) +void btDiscreteDynamicsWorld::serialize(btSerializer* 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); - } + serializer->startSerialization(); serializeRigidBodies(serializer); serializeCollisionObjects(serializer); - serializer->writeDNA(); + serializer->finishSerialization(); } diff --git a/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h b/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h index f1249ecd4..df47c2904 100644 --- a/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h +++ b/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h @@ -77,7 +77,7 @@ protected: virtual void saveKinematicState(btScalar timeStep); - void serializeRigidBodies(btDefaultSerializer* serializer); + void serializeRigidBodies(btSerializer* serializer); public: @@ -191,7 +191,7 @@ public: } ///Preliminary serialization test for Bullet 2.76. Loading those files requires a separate parser (see Bullet/Demos/SerializeDemo) - virtual void serialize(btDefaultSerializer* serializer); + virtual void serialize(btSerializer* serializer); }; diff --git a/src/LinearMath/btSerializer.cpp b/src/LinearMath/btSerializer.cpp index 7d5a52eda..8974c2a1d 100644 --- a/src/LinearMath/btSerializer.cpp +++ b/src/LinearMath/btSerializer.cpp @@ -12,58 +12,57 @@ unsigned char sBulletDNAstr[]= { 109,95,108,111,99,97,108,83,99,97,108,105,110,103,0,109,95,105,109,112, 108,105,99,105,116,83,104,97,112,101,68,105,109,101,110,115,105,111,110,115, 0,109,95,99,111,108,108,105,115,105,111,110,77,97,114,103,105,110,0,109, -95,99,111,110,118,101,120,73,110,116,101,114,110,97,108,83,104,97,112,101, -68,97,116,97,0,42,109,95,108,111,99,97,108,80,111,115,105,116,105,111, -110,65,114,114,97,121,80,116,114,0,42,109,95,114,97,100,105,65,114,114, -97,121,80,116,114,0,109,95,108,111,99,97,108,80,111,115,105,116,105,111, -110,65,114,114,97,121,83,105,122,101,0,109,95,114,97,100,105,65,114,114, -97,121,83,105,122,101,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,99,111,108,108,105,115,105, -111,110,79,98,106,101,99,116,68,97,116,97,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,0,0,0, -84,89,80,69,22,0,0,0,99,104,97,114,0,117,99,104,97,114,0,115, +95,112,111,115,0,109,95,114,97,100,105,117,115,0,109,95,99,111,110,118, +101,120,73,110,116,101,114,110,97,108,83,104,97,112,101,68,97,116,97,0, +42,109,95,108,111,99,97,108,80,111,115,105,116,105,111,110,65,114,114,97, +121,80,116,114,0,109,95,108,111,99,97,108,80,111,115,105,116,105,111,110, +65,114,114,97,121,83,105,122,101,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,99,111,108,108, +105,115,105,111,110,79,98,106,101,99,116,68,97,116,97,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, +84,89,80,69,23,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, @@ -73,27 +72,28 @@ unsigned char sBulletDNAstr[]= { 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,67,111,110,118,101,120,73,110,116,101,114,110,97,108,83,104,97,112,101, -68,97,116,97,0,98,116,77,117,108,116,105,83,112,104,101,114,101,83,104, +68,97,116,97,0,98,116,80,111,115,105,116,105,111,110,65,110,100,82,97, +100,105,117,115,0,98,116,77,117,108,116,105,83,112,104,101,114,101,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,48,0,64,0,12,0,52,0,68,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,1,0, -14,0,9,0,16,0,2,0,15,0,10,0,14,0,11,0,17,0,3,0, -9,0,12,0,4,0,13,0,0,0,14,0,18,0,5,0,17,0,15,0, -14,0,16,0,14,0,17,0,10,0,18,0,0,0,14,0,19,0,5,0, -18,0,19,0,14,0,20,0,10,0,21,0,4,0,22,0,4,0,23,0, -20,0,23,0,16,0,24,0,16,0,25,0,14,0,26,0,14,0,27,0, -14,0,28,0,4,0,29,0,10,0,30,0,9,0,31,0,9,0,32,0, -17,0,33,0,4,0,34,0,4,0,35,0,4,0,36,0,4,0,37,0, -10,0,38,0,10,0,39,0,10,0,40,0,4,0,41,0,9,0,42,0, -10,0,43,0,10,0,44,0,10,0,45,0,4,0,46,0,21,0,21,0, -20,0,47,0,15,0,48,0,14,0,49,0,14,0,50,0,10,0,51,0, -14,0,52,0,14,0,53,0,14,0,54,0,14,0,55,0,14,0,56,0, -14,0,57,0,14,0,58,0,10,0,59,0,10,0,60,0,4,0,61,0, -10,0,62,0,10,0,63,0,10,0,64,0,10,0,65,0,10,0,66,0, -10,0,67,0,}; +16,0,48,0,64,0,12,0,52,0,20,0,64,0,-8,0,-32,1,0,0, +83,84,82,67,12,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,1,0,14,0,9,0,16,0,2,0,15,0,10,0,14,0,11,0, +17,0,3,0,9,0,12,0,4,0,13,0,0,0,14,0,18,0,5,0, +17,0,15,0,14,0,16,0,14,0,17,0,10,0,18,0,0,0,14,0, +19,0,2,0,14,0,19,0,10,0,20,0,20,0,4,0,18,0,21,0, +19,0,22,0,4,0,23,0,0,0,14,0,21,0,23,0,16,0,24,0, +16,0,25,0,14,0,26,0,14,0,27,0,14,0,28,0,4,0,29,0, +10,0,30,0,9,0,31,0,9,0,32,0,17,0,33,0,4,0,34,0, +4,0,35,0,4,0,36,0,4,0,37,0,10,0,38,0,10,0,39,0, +10,0,40,0,4,0,41,0,9,0,42,0,10,0,43,0,10,0,44,0, +10,0,45,0,4,0,46,0,22,0,21,0,21,0,47,0,15,0,48,0, +14,0,49,0,14,0,50,0,10,0,51,0,14,0,52,0,14,0,53,0, +14,0,54,0,14,0,55,0,14,0,56,0,14,0,57,0,14,0,58,0, +10,0,59,0,10,0,60,0,4,0,61,0,10,0,62,0,10,0,63,0, +10,0,64,0,10,0,65,0,10,0,66,0,10,0,67,0,}; int sBulletDNAlen= sizeof(sBulletDNAstr); diff --git a/src/LinearMath/btSerializer.h b/src/LinearMath/btSerializer.h index d9105be21..1f73b9019 100644 --- a/src/LinearMath/btSerializer.h +++ b/src/LinearMath/btSerializer.h @@ -37,6 +37,25 @@ public: int m_number; }; +class btSerializer +{ + +public: + + virtual const unsigned char* getBufferPointer() const = 0; + + virtual int getCurrentBufferSize() const = 0; + + virtual btChunk* allocate(size_t size, int numElements) = 0; + + virtual void finalizeChunk(btChunk* chunk, const char* structType, int chunkCode,void* oldPtr) const = 0; + + virtual void startSerialization() = 0; + + virtual void finishSerialization() = 0; + +}; + #define BT_HEADER_LENGTH 12 @@ -50,11 +69,11 @@ public: #define BT_RIGIDBODY_CODE MAKE_ID('R','B','D','Y') #define BT_BOXSHAPE_CODE MAKE_ID('B','O','X','S') #define BT_SHAPE_CODE MAKE_ID('S','H','A','P') -#define BT_VECTOR3_CODE MAKE_ID('V','E','C','3') +#define BT_ARRAY_CODE MAKE_ID('A','R','A','Y') -class btDefaultSerializer +class btDefaultSerializer : public btSerializer { -public: + btAlignedObjectArray mTypes; btAlignedObjectArray mStructs; @@ -68,52 +87,13 @@ public: unsigned char* m_buffer; int m_currentSize; - - +protected: - void* m_dna; - int m_dnaLength; - - - btDefaultSerializer(int totalSize) - :m_totalSize(totalSize), - m_currentSize(0), - m_dna(0), - m_dnaLength(0) + void writeDNA() { - m_buffer = (unsigned char*)btAlignedAlloc(16,totalSize); - m_currentSize += BT_HEADER_LENGTH; - - memcpy(m_buffer, "BULLET ", 7); - int endian= 1; - endian= ((char*)&endian)[0]; - - if (endian) - { - m_buffer[7] = '_'; - } else - { - m_buffer[7] = '-'; - } - if (sizeof(void*)==8) - { - m_buffer[8]='V'; - } else - { - m_buffer[8]='v'; - } - - m_buffer[9] = '2'; - m_buffer[10] = '7'; - m_buffer[11] = '5'; - - - - } - - virtual ~btDefaultSerializer() - { - btAlignedFree(m_buffer); + unsigned char* dnaTarget = m_buffer+m_currentSize; + memcpy(dnaTarget,m_dna,m_dnaLength); + m_currentSize += m_dnaLength; } int getReverseType(const char *type) const @@ -127,33 +107,6 @@ public: return -1; } - void writeDNA() - { - unsigned char* dnaTarget = m_buffer+m_currentSize; - memcpy(dnaTarget,m_dna,m_dnaLength); - m_currentSize += m_dnaLength; - } - - virtual btChunk* allocate(size_t size, int numElements) - { - - unsigned char* ptr = m_buffer+m_currentSize; - m_currentSize += size*numElements+sizeof(btChunk); - - unsigned char* data = ptr + sizeof(btChunk); - - btChunk* chunk = (btChunk*)ptr; - chunk->m_chunkCode = 0; - chunk->m_oldPtr = data; - chunk->m_length = size*numElements; - chunk->m_number = numElements; - - m_chunkPtrs.push_back(chunk); - - return chunk; - } - - void initDNA(const char* bdna,int dnalen) { ///was already initialized @@ -291,6 +244,119 @@ public: } } +public: + + + void* m_dna; + int m_dnaLength; + + + btDefaultSerializer(int totalSize) + :m_totalSize(totalSize), + m_currentSize(0), + m_dna(0), + m_dnaLength(0) + { + m_buffer = (unsigned char*)btAlignedAlloc(16,totalSize); + + const bool VOID_IS_8 = ((sizeof(void*)==8)); + + if (VOID_IS_8) + { + //64bit not yet supported (soon) + btAssert(0); + return; + } else + { + initDNA((const char*)sBulletDNAstr,sBulletDNAlen); + } + + } + + virtual ~btDefaultSerializer() + { + btAlignedFree(m_buffer); + } + + virtual void startSerialization() + { + m_currentSize = BT_HEADER_LENGTH; + + memcpy(m_buffer, "BULLET ", 7); + int endian= 1; + endian= ((char*)&endian)[0]; + + if (endian) + { + m_buffer[7] = '_'; + } else + { + m_buffer[7] = '-'; + } + if (sizeof(void*)==8) + { + m_buffer[8]='V'; + } else + { + m_buffer[8]='v'; + } + + m_buffer[9] = '2'; + m_buffer[10] = '7'; + m_buffer[11] = '5'; + + + } + + virtual void finishSerialization() + { + writeDNA(); + } + + + virtual const unsigned char* getBufferPointer() const + { + return m_buffer; + } + + virtual int getCurrentBufferSize() const + { + return m_currentSize; + } + + virtual void finalizeChunk(btChunk* chunk, const char* structType, int chunkCode,void* oldPtr) const + { + chunk->m_dna_nr = getReverseType(structType); + chunk->m_chunkCode = chunkCode; + chunk->m_oldPtr = oldPtr; + } + + + + + + virtual btChunk* allocate(size_t size, int numElements) + { + + unsigned char* ptr = m_buffer+m_currentSize; + m_currentSize += size*numElements+sizeof(btChunk); + + unsigned char* data = ptr + sizeof(btChunk); + + btChunk* chunk = (btChunk*)ptr; + chunk->m_chunkCode = 0; + chunk->m_oldPtr = data; + chunk->m_length = size*numElements; + chunk->m_number = numElements; + + m_chunkPtrs.push_back(chunk); + + return chunk; + } + + + + };