make Bullet compile on Visual Studio 6

This commit is contained in:
erwin.coumans
2010-01-30 23:10:12 +00:00
parent 788f48643b
commit e57f03599a
12 changed files with 515 additions and 481 deletions

View File

@@ -36,7 +36,7 @@ ADD_DEFINITIONS( -DUSE_GRAPHICAL_BENCHMARK)
ENDIF (USE_GRAPHICAL_BENCHMARK) ENDIF (USE_GRAPHICAL_BENCHMARK)
IF (WIN32) IF (WIN32)
OPTION(USE_GLUT "Use Glut" OFF) OPTION(USE_GLUT "Use Glut" ON)
ADD_DEFINITIONS( -D_IRR_STATIC_LIB_ ) ADD_DEFINITIONS( -D_IRR_STATIC_LIB_ )
ADD_DEFINITIONS( -D_CRT_SECURE_NO_WARNINGS ) ADD_DEFINITIONS( -D_CRT_SECURE_NO_WARNINGS )
ADD_DEFINITIONS( -D_CRT_SECURE_NO_DEPRECATE ) ADD_DEFINITIONS( -D_CRT_SECURE_NO_DEPRECATE )

View File

@@ -254,7 +254,7 @@ void CollisionInterfaceDemo::clientResetScene()
{ {
objects[0].getWorldTransform().setOrigin(btVector3(0.0f,3.f,0.f)); objects[0].getWorldTransform().setOrigin(btVector3(0.0f,3.f,0.f));
btQuaternion rotA(0.739,-0.204,0.587,0.257); btQuaternion rotA(0.739f,-0.204f,0.587f,0.257f);
rotA.normalize(); rotA.normalize();
objects[0].getWorldTransform().setRotation(rotA); objects[0].getWorldTransform().setRotation(rotA);

View File

@@ -97,9 +97,9 @@ btScalar(0.)));
// Setup some damping on the m_bodies // Setup some damping on the m_bodies
for (int i = 0; i < BODYPART_COUNT; ++i) for (int i = 0; i < BODYPART_COUNT; ++i)
{ {
m_bodies[i]->setDamping(0.05, 0.85); m_bodies[i]->setDamping(0.05f, 0.85f);
m_bodies[i]->setDeactivationTime(0.8); m_bodies[i]->setDeactivationTime(0.8f);
m_bodies[i]->setSleepingThresholds(1.6, 2.5); m_bodies[i]->setSleepingThresholds(1.6f, 2.5f);
} }
///////////////////////////// SETTING THE CONSTRAINTS /////////////////////////////////////////////7777 ///////////////////////////// SETTING THE CONSTRAINTS /////////////////////////////////////////////7777
@@ -191,7 +191,7 @@ btScalar(0.)));
joint6DOF->setAngularUpperLimit(btVector3(SIMD_EPSILON,SIMD_EPSILON,SIMD_EPSILON)); joint6DOF->setAngularUpperLimit(btVector3(SIMD_EPSILON,SIMD_EPSILON,SIMD_EPSILON));
#else #else
joint6DOF->setAngularLowerLimit(btVector3(-SIMD_EPSILON,-SIMD_EPSILON,-SIMD_EPSILON)); joint6DOF->setAngularLowerLimit(btVector3(-SIMD_EPSILON,-SIMD_EPSILON,-SIMD_EPSILON));
joint6DOF->setAngularUpperLimit(btVector3(SIMD_PI*0.7,SIMD_EPSILON,SIMD_EPSILON)); joint6DOF->setAngularUpperLimit(btVector3(SIMD_PI*0.7f,SIMD_EPSILON,SIMD_EPSILON));
#endif #endif
m_joints[JOINT_LEFT_ELBOW] = joint6DOF; m_joints[JOINT_LEFT_ELBOW] = joint6DOF;
m_ownerWorld->addConstraint(m_joints[JOINT_LEFT_ELBOW], true); m_ownerWorld->addConstraint(m_joints[JOINT_LEFT_ELBOW], true);

View File

@@ -110,7 +110,9 @@ void GL_DialogDynamicsWorld::setScreenSize(int width, int height)
{ {
for (int i=0;i<m_dynamicsWorld->getCollisionObjectArray().size();i++) int i;
for ( i=0;i<m_dynamicsWorld->getCollisionObjectArray().size();i++)
{ {
btCollisionObject* colObj = m_dynamicsWorld->getCollisionObjectArray()[i]; btCollisionObject* colObj = m_dynamicsWorld->getCollisionObjectArray()[i];
btRigidBody* body = btRigidBody::upcast(colObj); btRigidBody* body = btRigidBody::upcast(colObj);
@@ -129,7 +131,7 @@ void GL_DialogDynamicsWorld::setScreenSize(int width, int height)
} }
} }
for (int i=0;i<m_dialogs.size();i++) for ( i=0;i<m_dialogs.size();i++)
{ {
m_dialogs[i]->setScreenSize(width,height); m_dialogs[i]->setScreenSize(width,height);
} }

View File

@@ -10,6 +10,7 @@
# You shouldn't have to modify anything below this line # You shouldn't have to modify anything below this line
######################################################## ########################################################
IF (USE_GLUT)
INCLUDE_DIRECTORIES( INCLUDE_DIRECTORIES(
@@ -25,3 +26,22 @@ ADD_EXECUTABLE(AppSoftBodyDemo
SoftDemo.cpp SoftDemo.cpp
) )
IF (WIN32)
IF (CMAKE_CL_64)
ADD_CUSTOM_COMMAND(
TARGET AppSoftBodyDemo
POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/glut64.dll ${CMAKE_CURRENT_BINARY_DIR}
)
ELSE(CMAKE_CL_64)
ADD_CUSTOM_COMMAND(
TARGET AppSoftBodyDemo
POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/GLUT32.DLL ${CMAKE_CURRENT_BINARY_DIR}
)
ENDIF(CMAKE_CL_64)
ENDIF(WIN32)
ELSE(USE_GLUT)
ENDIF (USE_GLUT)

View File

@@ -218,7 +218,7 @@ void SoftDemo::clientMoveAndDisplay()
#endif //PRINT_CONTACT_STATISTICS #endif //PRINT_CONTACT_STATISTICS
glutSwapBuffers(); swapBuffers();
} }
@@ -232,7 +232,7 @@ void SoftDemo::displayCallback(void) {
renderme(); renderme();
glFlush(); glFlush();
glutSwapBuffers(); swapBuffers();
} }

View File

@@ -19,7 +19,13 @@ subject to the following restrictions:
#ifndef SOFT_DEMO_H #ifndef SOFT_DEMO_H
#define SOFT_DEMO_H #define SOFT_DEMO_H
#ifdef _WINDOWS
#include "Win32DemoApplication.h"
#define PlatformDemoApplication Win32DemoApplication
#else
#include "GlutDemoApplication.h" #include "GlutDemoApplication.h"
#define PlatformDemoApplication GlutDemoApplication
#endif
#include "LinearMath/btAlignedObjectArray.h" #include "LinearMath/btAlignedObjectArray.h"
#include "BulletSoftBody/btSoftBody.h" #include "BulletSoftBody/btSoftBody.h"
@@ -41,7 +47,7 @@ class btSoftRigidDynamicsWorld;
///CcdPhysicsDemo shows basic stacking using Bullet physics, and allows toggle of Ccd (using key '1') ///CcdPhysicsDemo shows basic stacking using Bullet physics, and allows toggle of Ccd (using key '1')
class SoftDemo : public GlutDemoApplication class SoftDemo : public PlatformDemoApplication
{ {
public: public:

View File

@@ -177,7 +177,8 @@ void bDNA::initCmpFlags(bDNA *memDNA)
for (int i=0; i<(int)mStructs.size(); i++) int i;
for ( i=0; i<(int)mStructs.size(); i++)
{ {
short *oldStruct = mStructs[i]; short *oldStruct = mStructs[i];
@@ -258,7 +259,7 @@ void bDNA::initCmpFlags(bDNA *memDNA)
// recurse in // recurse in
for (int i=0; i<(int)mStructs.size(); i++) for ( i=0; i<(int)mStructs.size(); i++)
{ {
if (mCMPFlags[i] == FDF_STRUCT_NEQU) if (mCMPFlags[i] == FDF_STRUCT_NEQU)
initRecurseCmpFlags(i); initRecurseCmpFlags(i);
@@ -368,7 +369,8 @@ void bDNA::init(char *data, int len, bool swap)
intPtr++; intPtr++;
cp = (char*)intPtr; cp = (char*)intPtr;
for (int i=0; i<dataLen; i++) int i;
for ( i=0; i<dataLen; i++)
{ {
bNameInfo info; bNameInfo info;
info.m_name = cp; info.m_name = cp;
@@ -406,7 +408,7 @@ void bDNA::init(char *data, int len, bool swap)
intPtr++; intPtr++;
cp = (char*)intPtr; cp = (char*)intPtr;
for (int i=0; i<dataLen; i++) for ( i=0; i<dataLen; i++)
{ {
mTypes.push_back(cp); mTypes.push_back(cp);
while (*cp)cp++; while (*cp)cp++;
@@ -437,7 +439,7 @@ void bDNA::init(char *data, int len, bool swap)
dataLen = (int)mTypes.size(); dataLen = (int)mTypes.size();
shtPtr = (short*)intPtr; shtPtr = (short*)intPtr;
for (int i=0; i<dataLen; i++, shtPtr++) for ( i=0; i<dataLen; i++, shtPtr++)
{ {
if (swap) if (swap)
shtPtr[0] = ChunkUtils::swapShort(shtPtr[0]); shtPtr[0] = ChunkUtils::swapShort(shtPtr[0]);
@@ -467,7 +469,7 @@ void bDNA::init(char *data, int len, bool swap)
shtPtr = (short*)intPtr; shtPtr = (short*)intPtr;
for (int i=0; i<dataLen; i++) for ( i=0; i<dataLen; i++)
{ {
mStructs.push_back (shtPtr); mStructs.push_back (shtPtr);
if (swap) if (swap)
@@ -490,7 +492,7 @@ void bDNA::init(char *data, int len, bool swap)
// build reverse lookups // build reverse lookups
for (int i=0; i<(int)mStructs.size(); i++) for ( i=0; i<(int)mStructs.size(); i++)
{ {
short *strc = mStructs.at(i); short *strc = mStructs.at(i);
if (!mPtrLen && strcmp(mTypes[strc[0]],"ListBase")==0) if (!mPtrLen && strcmp(mTypes[strc[0]],"ListBase")==0)
@@ -539,7 +541,7 @@ void bDNA::dumpTypeDefinitions()
} }
for (int i=0; i<(int)mStructs.size(); i++) for ( i=0; i<(int)mStructs.size(); i++)
{ {
int totalBytes=0; int totalBytes=0;
short *oldStruct = mStructs[i]; short *oldStruct = mStructs[i];

View File

@@ -855,14 +855,15 @@ void bFile::resolvePointersStructRecursive(char *strcPtr, int dna_nr, bool verbo
dbPtr = &dbarray[0]; dbPtr = &dbarray[0];
if (dbPtr) if (dbPtr)
{ {
int i;
getElement(arrayLen, newtype,memType, tmp, (char*)dbPtr); getElement(arrayLen, newtype,memType, tmp, (char*)dbPtr);
for (int i=0;i<recursion;i++) for (i=0;i<recursion;i++)
printf(" "); printf(" ");
if (arrayLen==1) if (arrayLen==1)
printf("<%s type=\"%s\">",memName,memType); printf("<%s type=\"%s\">",memName,memType);
else else
printf("<%s type=\"%s\" count=%d>",memName,memType,arrayLen); printf("<%s type=\"%s\" count=%d>",memName,memType,arrayLen);
for (int i=0;i<arrayLen;i++) for (i=0;i<arrayLen;i++)
printf(" %d ",dbPtr[i]); printf(" %d ",dbPtr[i]);
printf("</%s>\n",memName); printf("</%s>\n",memName);
} }
@@ -875,14 +876,15 @@ void bFile::resolvePointersStructRecursive(char *strcPtr, int dna_nr, bool verbo
dbPtr = &dbarray[0]; dbPtr = &dbarray[0];
if (dbPtr) if (dbPtr)
{ {
int i;
getElement(arrayLen, newtype,memType, tmp, (char*)dbPtr); getElement(arrayLen, newtype,memType, tmp, (char*)dbPtr);
for (int i=0;i<recursion;i++) for (i=0;i<recursion;i++)
printf(" "); printf(" ");
if (arrayLen==1) if (arrayLen==1)
printf("<%s type=\"%s\">",memName,memType); printf("<%s type=\"%s\">",memName,memType);
else else
printf("<%s type=\"%s\" count=%d>",memName,memType,arrayLen); printf("<%s type=\"%s\" count=%d>",memName,memType,arrayLen);
for (int i=0;i<arrayLen;i++) for (i=0;i<arrayLen;i++)
printf(" %f ",dbPtr[i]); printf(" %f ",dbPtr[i]);
printf("</%s>\n",memName); printf("</%s>\n",memName);
} }

View File

@@ -216,7 +216,8 @@ btCollisionShape* btBulletWorldImporter::convertCollisionShape( btCollisionShap
btAlignedObjectArray<btScalar> radii; btAlignedObjectArray<btScalar> radii;
radii.resize(numSpheres); radii.resize(numSpheres);
tmpPos.resize(numSpheres); tmpPos.resize(numSpheres);
for (int i=0;i<numSpheres;i++) int i;
for ( i=0;i<numSpheres;i++)
{ {
tmpPos[i].deSerializeFloat(mss->m_localPositionArrayPtr[i].m_pos); tmpPos[i].deSerializeFloat(mss->m_localPositionArrayPtr[i].m_pos);
radii[i] = mss->m_localPositionArrayPtr[i].m_radius; radii[i] = mss->m_localPositionArrayPtr[i].m_radius;
@@ -234,7 +235,8 @@ btCollisionShape* btBulletWorldImporter::convertCollisionShape( btCollisionShap
btAlignedObjectArray<btVector3> tmpPoints; btAlignedObjectArray<btVector3> tmpPoints;
tmpPoints.resize(numPoints); tmpPoints.resize(numPoints);
for (int i=0;i<numPoints;i++) int i;
for ( i=0;i<numPoints;i++)
{ {
#ifdef BT_USE_DOUBLE_PRECISION #ifdef BT_USE_DOUBLE_PRECISION
if (convexData->m_unscaledPointsDoublePtr) if (convexData->m_unscaledPointsDoublePtr)
@@ -249,7 +251,7 @@ btCollisionShape* btBulletWorldImporter::convertCollisionShape( btCollisionShap
#endif //BT_USE_DOUBLE_PRECISION #endif //BT_USE_DOUBLE_PRECISION
} }
btConvexHullShape* hullShape = createConvexHullShape(); btConvexHullShape* hullShape = createConvexHullShape();
for (int i=0;i<numPoints;i++) for (i=0;i<numPoints;i++)
{ {
hullShape->addPoint(tmpPoints[i]); hullShape->addPoint(tmpPoints[i]);
} }

View File

@@ -135,14 +135,13 @@ static int ClipSegmentToLine(ClipVertex vOut[2], ClipVertex vIn[2],
static btScalar EdgeSeparation(const btBox2dShape* poly1, const btTransform& xf1, int edge1, static btScalar EdgeSeparation(const btBox2dShape* poly1, const btTransform& xf1, int edge1,
const btBox2dShape* poly2, const btTransform& xf2) const btBox2dShape* poly2, const btTransform& xf2)
{ {
//int count1 = poly1->getVertexCount();
const btVector3* vertices1 = poly1->getVertices(); const btVector3* vertices1 = poly1->getVertices();
const btVector3* normals1 = poly1->getNormals(); const btVector3* normals1 = poly1->getNormals();
int count2 = poly2->getVertexCount(); int count2 = poly2->getVertexCount();
const btVector3* vertices2 = poly2->getVertices(); const btVector3* vertices2 = poly2->getVertices();
btAssert(0 <= edge1 && edge1 < count1); btAssert(0 <= edge1 && edge1 < poly1->getVertexCount());
// Convert normal from poly1's frame into poly2's frame. // Convert normal from poly1's frame into poly2's frame.
btVector3 normal1World = b2Mul(xf1.getBasis(), normals1[edge1]); btVector3 normal1World = b2Mul(xf1.getBasis(), normals1[edge1]);
@@ -271,14 +270,13 @@ static void FindIncidentEdge(ClipVertex c[2],
const btBox2dShape* poly1, const btTransform& xf1, int edge1, const btBox2dShape* poly1, const btTransform& xf1, int edge1,
const btBox2dShape* poly2, const btTransform& xf2) const btBox2dShape* poly2, const btTransform& xf2)
{ {
//int count1 = poly1->getVertexCount();
const btVector3* normals1 = poly1->getNormals(); const btVector3* normals1 = poly1->getNormals();
int count2 = poly2->getVertexCount(); int count2 = poly2->getVertexCount();
const btVector3* vertices2 = poly2->getVertices(); const btVector3* vertices2 = poly2->getVertices();
const btVector3* normals2 = poly2->getNormals(); const btVector3* normals2 = poly2->getNormals();
btAssert(0 <= edge1 && edge1 < count1); btAssert(0 <= edge1 && edge1 < poly1->getVertexCount());
// Get the normal of the reference edge in poly2's frame. // Get the normal of the reference edge in poly2's frame.
btVector3 normal1 = b2MulT(xf2.getBasis(), b2Mul(xf1.getBasis(), normals1[edge1])); btVector3 normal1 = b2MulT(xf2.getBasis(), b2Mul(xf1.getBasis(), normals1[edge1]));

View File

@@ -1,451 +1,453 @@
/* /*
Bullet Continuous Collision Detection and Physics Library Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
This software is provided 'as-is', without any express or implied warranty. 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. 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, Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely, including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions: 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. 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. 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. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef BT_SERIALIZER_H #ifndef BT_SERIALIZER_H
#define BT_SERIALIZER_H #define BT_SERIALIZER_H
#include "btScalar.h" // has definitions like SIMD_FORCE_INLINE #include "btScalar.h" // has definitions like SIMD_FORCE_INLINE
#include "btStackAlloc.h" #include "btStackAlloc.h"
#include "btHashMap.h" #include "btHashMap.h"
#include <memory.h> #include <memory.h>
#include <string.h> #include <string.h>
///only the 32bit versions for now ///only the 32bit versions for now
extern unsigned char sBulletDNAstr[]; extern unsigned char sBulletDNAstr[];
extern int sBulletDNAlen; extern int sBulletDNAlen;
extern unsigned char sBulletDNAstr64[]; extern unsigned char sBulletDNAstr64[];
extern int sBulletDNAlen64; extern int sBulletDNAlen64;
class btChunk class btChunk
{ {
public: public:
int m_chunkCode; int m_chunkCode;
int m_length; int m_length;
void *m_oldPtr; void *m_oldPtr;
int m_dna_nr; int m_dna_nr;
int m_number; int m_number;
}; };
class btSerializer class btSerializer
{ {
public: public:
virtual const unsigned char* getBufferPointer() const = 0; virtual const unsigned char* getBufferPointer() const = 0;
virtual int getCurrentBufferSize() const = 0; virtual int getCurrentBufferSize() const = 0;
virtual btChunk* allocate(size_t size, int numElements) = 0; virtual btChunk* allocate(size_t size, int numElements) = 0;
virtual void finalizeChunk(btChunk* chunk, const char* structType, int chunkCode,void* oldPtr)= 0; virtual void finalizeChunk(btChunk* chunk, const char* structType, int chunkCode,void* oldPtr)= 0;
virtual void* findPointer(void* oldPtr) = 0; virtual void* findPointer(void* oldPtr) = 0;
virtual void startSerialization() = 0; virtual void startSerialization() = 0;
virtual void finishSerialization() = 0; virtual void finishSerialization() = 0;
}; };
#define BT_HEADER_LENGTH 12 #define BT_HEADER_LENGTH 12
#if defined(__sgi) || defined (__sparc) || defined (__sparc__) || defined (__PPC__) || defined (__ppc__) || defined (__BIG_ENDIAN__) #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) ) # define MAKE_ID(a,b,c,d) ( (int)(a)<<24 | (int)(b)<<16 | (c)<<8 | (d) )
#else #else
# define MAKE_ID(a,b,c,d) ( (int)(d)<<24 | (int)(c)<<16 | (b)<<8 | (a) ) # define MAKE_ID(a,b,c,d) ( (int)(d)<<24 | (int)(c)<<16 | (b)<<8 | (a) )
#endif #endif
#define BT_COLLISIONOBJECT_CODE MAKE_ID('C','O','B','J') #define BT_COLLISIONOBJECT_CODE MAKE_ID('C','O','B','J')
#define BT_RIGIDBODY_CODE MAKE_ID('R','B','D','Y') #define BT_RIGIDBODY_CODE MAKE_ID('R','B','D','Y')
#define BT_CONSTRAINT_CODE MAKE_ID('C','O','N','S') #define BT_CONSTRAINT_CODE MAKE_ID('C','O','N','S')
#define BT_BOXSHAPE_CODE MAKE_ID('B','O','X','S') #define BT_BOXSHAPE_CODE MAKE_ID('B','O','X','S')
#define BT_SHAPE_CODE MAKE_ID('S','H','A','P') #define BT_SHAPE_CODE MAKE_ID('S','H','A','P')
#define BT_ARRAY_CODE MAKE_ID('A','R','A','Y') #define BT_ARRAY_CODE MAKE_ID('A','R','A','Y')
class btDefaultSerializer : public btSerializer class btDefaultSerializer : public btSerializer
{ {
btAlignedObjectArray<char*> mTypes; btAlignedObjectArray<char*> mTypes;
btAlignedObjectArray<short*> mStructs; btAlignedObjectArray<short*> mStructs;
btAlignedObjectArray<short> mTlens; btAlignedObjectArray<short> mTlens;
btHashMap<btHashInt, int> mStructReverse; btHashMap<btHashInt, int> mStructReverse;
btHashMap<btHashString,int> mTypeLookup; btHashMap<btHashString,int> mTypeLookup;
btHashMap<btHashPtr,void*> m_chunkP; btHashMap<btHashPtr,void*> m_chunkP;
int m_totalSize; int m_totalSize;
unsigned char* m_buffer; unsigned char* m_buffer;
int m_currentSize; int m_currentSize;
btAlignedObjectArray<btChunk*> m_chunkPtrs; btAlignedObjectArray<btChunk*> m_chunkPtrs;
protected: protected:
virtual void* findPointer(void* oldPtr) virtual void* findPointer(void* oldPtr)
{ {
void** ptr = m_chunkP.find(oldPtr); void** ptr = m_chunkP.find(oldPtr);
if (ptr && *ptr) if (ptr && *ptr)
return *ptr; return *ptr;
return 0; return 0;
} }
void writeDNA() void writeDNA()
{ {
unsigned char* dnaTarget = m_buffer+m_currentSize; unsigned char* dnaTarget = m_buffer+m_currentSize;
memcpy(dnaTarget,m_dna,m_dnaLength); memcpy(dnaTarget,m_dna,m_dnaLength);
m_currentSize += m_dnaLength; m_currentSize += m_dnaLength;
} }
int getReverseType(const char *type) const int getReverseType(const char *type) const
{ {
btHashString key(type); btHashString key(type);
const int* valuePtr = mTypeLookup.find(key); const int* valuePtr = mTypeLookup.find(key);
if (valuePtr) if (valuePtr)
return *valuePtr; return *valuePtr;
return -1; return -1;
} }
void initDNA(const char* bdnaOrg,int dnalen) void initDNA(const char* bdnaOrg,int dnalen)
{ {
///was already initialized ///was already initialized
if (m_dna) if (m_dna)
return; return;
int littleEndian= 1; int littleEndian= 1;
littleEndian= ((char*)&littleEndian)[0]; littleEndian= ((char*)&littleEndian)[0];
m_dna = btAlignedAlloc(dnalen,16); m_dna = btAlignedAlloc(dnalen,16);
memcpy(m_dna,bdnaOrg,dnalen); memcpy(m_dna,bdnaOrg,dnalen);
m_dnaLength = dnalen; m_dnaLength = dnalen;
int *intPtr=0; int *intPtr=0;
short *shtPtr=0; short *shtPtr=0;
char *cp = 0;int dataLen =0;long nr=0; char *cp = 0;int dataLen =0;long nr=0;
intPtr = (int*)m_dna; intPtr = (int*)m_dna;
/* /*
SDNA (4 bytes) (magic number) SDNA (4 bytes) (magic number)
NAME (4 bytes) NAME (4 bytes)
<nr> (4 bytes) amount of names (int) <nr> (4 bytes) amount of names (int)
<string> <string>
<string> <string>
*/ */
if (strncmp((const char*)m_dna, "SDNA", 4)==0) if (strncmp((const char*)m_dna, "SDNA", 4)==0)
{ {
// skip ++ NAME // skip ++ NAME
intPtr++; intPtr++; intPtr++; intPtr++;
} }
// Parse names // Parse names
if (!littleEndian) if (!littleEndian)
*intPtr = btSwapEndian(*intPtr); *intPtr = btSwapEndian(*intPtr);
dataLen = *intPtr; dataLen = *intPtr;
intPtr++; intPtr++;
cp = (char*)intPtr; cp = (char*)intPtr;
for (int i=0; i<dataLen; i++) int i;
{ for ( i=0; i<dataLen; i++)
{
while (*cp)cp++;
cp++; while (*cp)cp++;
} cp++;
{ }
nr= (long)cp; {
// long mask=3; nr= (long)cp;
nr= ((nr+3)&~3)-nr; // long mask=3;
while (nr--) nr= ((nr+3)&~3)-nr;
{ while (nr--)
cp++; {
} cp++;
} }
}
/*
TYPE (4 bytes) /*
<nr> amount of types (int) TYPE (4 bytes)
<string> <nr> amount of types (int)
<string> <string>
*/ <string>
*/
intPtr = (int*)cp;
assert(strncmp(cp, "TYPE", 4)==0); intPtr++; intPtr = (int*)cp;
assert(strncmp(cp, "TYPE", 4)==0); intPtr++;
if (!littleEndian)
*intPtr = btSwapEndian(*intPtr); if (!littleEndian)
*intPtr = btSwapEndian(*intPtr);
dataLen = *intPtr;
intPtr++; dataLen = *intPtr;
intPtr++;
cp = (char*)intPtr;
for (int i=0; i<dataLen; i++)
{ cp = (char*)intPtr;
mTypes.push_back(cp); for (i=0; i<dataLen; i++)
while (*cp)cp++; {
cp++; mTypes.push_back(cp);
} while (*cp)cp++;
cp++;
{ }
nr= (long)cp;
// long mask=3; {
nr= ((nr+3)&~3)-nr; nr= (long)cp;
while (nr--) // long mask=3;
{ nr= ((nr+3)&~3)-nr;
cp++; while (nr--)
} {
} cp++;
}
}
/*
TLEN (4 bytes)
<len> (short) the lengths of types /*
<len> TLEN (4 bytes)
*/ <len> (short) the lengths of types
<len>
// Parse type lens */
intPtr = (int*)cp;
assert(strncmp(cp, "TLEN", 4)==0); intPtr++; // Parse type lens
intPtr = (int*)cp;
dataLen = (int)mTypes.size(); assert(strncmp(cp, "TLEN", 4)==0); intPtr++;
shtPtr = (short*)intPtr; dataLen = (int)mTypes.size();
for (int i=0; i<dataLen; i++, shtPtr++)
{ shtPtr = (short*)intPtr;
if (!littleEndian) for (i=0; i<dataLen; i++, shtPtr++)
shtPtr[0] = btSwapEndian(shtPtr[0]); {
mTlens.push_back(shtPtr[0]); if (!littleEndian)
} shtPtr[0] = btSwapEndian(shtPtr[0]);
mTlens.push_back(shtPtr[0]);
if (dataLen & 1) shtPtr++; }
/* if (dataLen & 1) shtPtr++;
STRC (4 bytes)
<nr> amount of structs (int) /*
<typenr> STRC (4 bytes)
<nr_of_elems> <nr> amount of structs (int)
<typenr> <typenr>
<namenr> <nr_of_elems>
<typenr> <typenr>
<namenr> <namenr>
*/ <typenr>
<namenr>
intPtr = (int*)shtPtr; */
cp = (char*)intPtr;
assert(strncmp(cp, "STRC", 4)==0); intPtr++; intPtr = (int*)shtPtr;
cp = (char*)intPtr;
if (!littleEndian) assert(strncmp(cp, "STRC", 4)==0); intPtr++;
*intPtr = btSwapEndian(*intPtr);
dataLen = *intPtr ; if (!littleEndian)
intPtr++; *intPtr = btSwapEndian(*intPtr);
dataLen = *intPtr ;
intPtr++;
shtPtr = (short*)intPtr;
for (int i=0; i<dataLen; i++)
{ shtPtr = (short*)intPtr;
mStructs.push_back (shtPtr); for (i=0; i<dataLen; i++)
{
if (!littleEndian) mStructs.push_back (shtPtr);
{
shtPtr[0]= btSwapEndian(shtPtr[0]); if (!littleEndian)
shtPtr[1]= btSwapEndian(shtPtr[1]); {
shtPtr[0]= btSwapEndian(shtPtr[0]);
int len = shtPtr[1]; shtPtr[1]= btSwapEndian(shtPtr[1]);
shtPtr+= 2;
int len = shtPtr[1];
for (int a=0; a<len; a++, shtPtr+=2) shtPtr+= 2;
{
shtPtr[0]= btSwapEndian(shtPtr[0]); for (int a=0; a<len; a++, shtPtr+=2)
shtPtr[1]= btSwapEndian(shtPtr[1]); {
} shtPtr[0]= btSwapEndian(shtPtr[0]);
shtPtr[1]= btSwapEndian(shtPtr[1]);
} else }
{
shtPtr+= (2*shtPtr[1])+2; } else
} {
} shtPtr+= (2*shtPtr[1])+2;
}
// build reverse lookups }
for (int i=0; i<(int)mStructs.size(); i++)
{ // build reverse lookups
short *strc = mStructs.at(i); for (i=0; i<(int)mStructs.size(); i++)
mStructReverse.insert(strc[0], i); {
mTypeLookup.insert(btHashString(mTypes[strc[0]]),i); short *strc = mStructs.at(i);
} mStructReverse.insert(strc[0], i);
} mTypeLookup.insert(btHashString(mTypes[strc[0]]),i);
}
public: }
public:
void* m_dna;
int m_dnaLength;
void* m_dna;
int m_dnaLength;
btDefaultSerializer(int totalSize)
:m_totalSize(totalSize),
m_currentSize(0), btDefaultSerializer(int totalSize)
m_dna(0), :m_totalSize(totalSize),
m_dnaLength(0) m_currentSize(0),
{ m_dna(0),
m_buffer = (unsigned char*)btAlignedAlloc(totalSize, 16); m_dnaLength(0)
{
const bool VOID_IS_8 = ((sizeof(void*)==8)); m_buffer = (unsigned char*)btAlignedAlloc(totalSize, 16);
#ifdef BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES const bool VOID_IS_8 = ((sizeof(void*)==8));
if (VOID_IS_8)
{ #ifdef BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES
#if _WIN64 if (VOID_IS_8)
initDNA((const char*)sBulletDNAstr64,sBulletDNAlen64); {
#else #if _WIN64
btAssert(0); initDNA((const char*)sBulletDNAstr64,sBulletDNAlen64);
#endif #else
} else btAssert(0);
{ #endif
#ifndef _WIN64 } else
initDNA((const char*)sBulletDNAstr,sBulletDNAlen); {
#else #ifndef _WIN64
btAssert(0); initDNA((const char*)sBulletDNAstr,sBulletDNAlen);
#endif #else
} btAssert(0);
#endif
#else //BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES }
if (VOID_IS_8)
{ #else //BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES
initDNA((const char*)sBulletDNAstr64,sBulletDNAlen64); if (VOID_IS_8)
} else {
{ initDNA((const char*)sBulletDNAstr64,sBulletDNAlen64);
initDNA((const char*)sBulletDNAstr,sBulletDNAlen); } else
} {
#endif //BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES initDNA((const char*)sBulletDNAstr,sBulletDNAlen);
}
} #endif //BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES
virtual ~btDefaultSerializer() }
{
btAlignedFree(m_buffer); virtual ~btDefaultSerializer()
} {
btAlignedFree(m_buffer);
virtual void startSerialization() }
{
m_currentSize = BT_HEADER_LENGTH; virtual void startSerialization()
{
#ifdef BT_USE_DOUBLE_PRECISION m_currentSize = BT_HEADER_LENGTH;
memcpy(m_buffer, "BULLETd", 7);
#else #ifdef BT_USE_DOUBLE_PRECISION
memcpy(m_buffer, "BULLETf", 7); memcpy(m_buffer, "BULLETd", 7);
#endif //BT_USE_DOUBLE_PRECISION #else
memcpy(m_buffer, "BULLETf", 7);
int littleEndian= 1; #endif //BT_USE_DOUBLE_PRECISION
littleEndian= ((char*)&littleEndian)[0];
int littleEndian= 1;
if (sizeof(void*)==8) littleEndian= ((char*)&littleEndian)[0];
{
m_buffer[7] = '-'; if (sizeof(void*)==8)
} else {
{ m_buffer[7] = '-';
m_buffer[7] = '_'; } else
} {
m_buffer[7] = '_';
if (littleEndian) }
{
m_buffer[8]='v'; if (littleEndian)
} else {
{ m_buffer[8]='v';
m_buffer[8]='V'; } else
} {
m_buffer[8]='V';
}
m_buffer[9] = '2';
m_buffer[10] = '7';
m_buffer[11] = '6'; m_buffer[9] = '2';
m_buffer[10] = '7';
m_buffer[11] = '6';
}
virtual void finishSerialization() }
{
writeDNA(); virtual void finishSerialization()
} {
writeDNA();
}
virtual const unsigned char* getBufferPointer() const
{
return m_buffer; virtual const unsigned char* getBufferPointer() const
} {
return m_buffer;
virtual int getCurrentBufferSize() const }
{
return m_currentSize; virtual int getCurrentBufferSize() const
} {
return m_currentSize;
virtual void finalizeChunk(btChunk* chunk, const char* structType, int chunkCode,void* oldPtr) }
{
btAssert(!findPointer(oldPtr)); virtual void finalizeChunk(btChunk* chunk, const char* structType, int chunkCode,void* oldPtr)
{
chunk->m_dna_nr = getReverseType(structType); btAssert(!findPointer(oldPtr));
chunk->m_chunkCode = chunkCode; chunk->m_dna_nr = getReverseType(structType);
m_chunkP.insert(oldPtr,chunk->m_oldPtr);
chunk->m_oldPtr = oldPtr; chunk->m_chunkCode = chunkCode;
m_chunkP.insert(oldPtr,chunk->m_oldPtr);
} chunk->m_oldPtr = oldPtr;
}
virtual btChunk* allocate(size_t size, int numElements)
{
virtual btChunk* allocate(size_t size, int numElements)
unsigned char* ptr = m_buffer+m_currentSize; {
m_currentSize += int(size)*numElements+sizeof(btChunk);
btAssert(m_currentSize<m_totalSize); unsigned char* ptr = m_buffer+m_currentSize;
m_currentSize += int(size)*numElements+sizeof(btChunk);
unsigned char* data = ptr + sizeof(btChunk); btAssert(m_currentSize<m_totalSize);
btChunk* chunk = (btChunk*)ptr; unsigned char* data = ptr + sizeof(btChunk);
chunk->m_chunkCode = 0;
chunk->m_oldPtr = data; btChunk* chunk = (btChunk*)ptr;
chunk->m_length = int(size)*numElements; chunk->m_chunkCode = 0;
chunk->m_number = numElements; chunk->m_oldPtr = data;
chunk->m_length = int(size)*numElements;
m_chunkPtrs.push_back(chunk); chunk->m_number = numElements;
m_chunkPtrs.push_back(chunk);
return chunk;
}
return chunk;
}
};
};
#endif //BT_SERIALIZER_H
#endif //BT_SERIALIZER_H