summaryrefslogtreecommitdiff
path: root/thirdparty/bullet/Bullet3Serialize/Bullet2FileLoader/b3DNA.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'thirdparty/bullet/Bullet3Serialize/Bullet2FileLoader/b3DNA.cpp')
-rw-r--r--thirdparty/bullet/Bullet3Serialize/Bullet2FileLoader/b3DNA.cpp355
1 files changed, 171 insertions, 184 deletions
diff --git a/thirdparty/bullet/Bullet3Serialize/Bullet2FileLoader/b3DNA.cpp b/thirdparty/bullet/Bullet3Serialize/Bullet2FileLoader/b3DNA.cpp
index 0fe5056922..09c8f23859 100644
--- a/thirdparty/bullet/Bullet3Serialize/Bullet2FileLoader/b3DNA.cpp
+++ b/thirdparty/bullet/Bullet3Serialize/Bullet2FileLoader/b3DNA.cpp
@@ -23,13 +23,11 @@ subject to the following restrictions:
//this define will force traversal of structures, to check backward (and forward) compatibility
//#define TEST_BACKWARD_FORWARD_COMPATIBILITY
-
using namespace bParse;
-
// ----------------------------------------------------- //
bDNA::bDNA()
- : mPtrLen(0)
+ : mPtrLen(0)
{
// --
}
@@ -43,7 +41,7 @@ bDNA::~bDNA()
// ----------------------------------------------------- //
bool bDNA::lessThan(bDNA *file)
{
- return ( m_Names.size() < file->m_Names.size());
+ return (m_Names.size() < file->m_Names.size());
}
// ----------------------------------------------------- //
@@ -53,36 +51,31 @@ char *bDNA::getName(int ind)
return m_Names[ind].m_name;
}
-
// ----------------------------------------------------- //
char *bDNA::getType(int ind)
{
- assert(ind<= (int)mTypes.size());
+ assert(ind <= (int)mTypes.size());
return mTypes[ind];
}
-
// ----------------------------------------------------- //
short *bDNA::getStruct(int ind)
{
- assert(ind <= (int)mStructs.size());
+ assert(ind <= (int)mStructs.size());
return mStructs[ind];
}
-
// ----------------------------------------------------- //
short bDNA::getLength(int ind)
{
- assert(ind <= (int)mTlens.size());
+ assert(ind <= (int)mTlens.size());
return mTlens[ind];
}
-
// ----------------------------------------------------- //
int bDNA::getReverseType(short type)
{
-
- int* intPtr = mStructReverse.find(type);
+ int *intPtr = mStructReverse.find(type);
if (intPtr)
return *intPtr;
@@ -92,12 +85,11 @@ int bDNA::getReverseType(short type)
// ----------------------------------------------------- //
int bDNA::getReverseType(const char *type)
{
-
b3HashString key(type);
- int* valuePtr = mTypeLookup.find(key);
+ int *valuePtr = mTypeLookup.find(key);
if (valuePtr)
return *valuePtr;
-
+
return -1;
}
@@ -110,22 +102,22 @@ int bDNA::getNumStructs()
// ----------------------------------------------------- //
bool bDNA::flagNotEqual(int dna_nr)
{
- assert(dna_nr <= (int)mCMPFlags.size());
+ assert(dna_nr <= (int)mCMPFlags.size());
return mCMPFlags[dna_nr] == FDF_STRUCT_NEQU;
}
// ----------------------------------------------------- //
bool bDNA::flagEqual(int dna_nr)
{
- assert(dna_nr <= (int)mCMPFlags.size());
+ assert(dna_nr <= (int)mCMPFlags.size());
int flag = mCMPFlags[dna_nr];
- return flag == FDF_STRUCT_EQU;
+ return flag == FDF_STRUCT_EQU;
}
// ----------------------------------------------------- //
bool bDNA::flagNone(int dna_nr)
{
- assert(dna_nr <= (int)mCMPFlags.size());
+ assert(dna_nr <= (int)mCMPFlags.size());
return mCMPFlags[dna_nr] == FDF_NONE;
}
@@ -143,15 +135,15 @@ void bDNA::initRecurseCmpFlags(int iter)
short *oldStrc = mStructs[iter];
short type = oldStrc[0];
- for (int i=0; i<(int)mStructs.size(); i++)
+ for (int i = 0; i < (int)mStructs.size(); i++)
{
- if (i != iter && mCMPFlags[i] == FDF_STRUCT_EQU )
+ if (i != iter && mCMPFlags[i] == FDF_STRUCT_EQU)
{
short *curStruct = mStructs[i];
int eleLen = curStruct[1];
- curStruct+=2;
+ curStruct += 2;
- for (int j=0; j<eleLen; j++, curStruct+=2)
+ for (int j = 0; j < eleLen; j++, curStruct += 2)
{
if (curStruct[0] == type)
{
@@ -171,18 +163,14 @@ void bDNA::initRecurseCmpFlags(int iter)
// ----------------------------------------------------- //
void bDNA::initCmpFlags(bDNA *memDNA)
{
-
- // compare the file to memory
+ // compare the file to memory
// this ptr should be the file data
-
- assert(!(m_Names.size() == 0));// && "SDNA empty!");
+ assert(!(m_Names.size() == 0)); // && "SDNA empty!");
mCMPFlags.resize(mStructs.size(), FDF_NONE);
-
-
int i;
- for ( i=0; i<(int)mStructs.size(); i++)
+ for (i = 0; i < (int)mStructs.size(); i++)
{
short *oldStruct = mStructs[i];
@@ -196,7 +184,7 @@ void bDNA::initCmpFlags(bDNA *memDNA)
//#define SLOW_FORWARD_COMPATIBLE 1
#ifdef SLOW_FORWARD_COMPATIBLE
- char* typeName = mTypes[oldLookup];
+ char *typeName = mTypes[oldLookup];
int newLookup = memDNA->getReverseType(typeName);
if (newLookup == -1)
{
@@ -210,71 +198,61 @@ void bDNA::initCmpFlags(bDNA *memDNA)
if (oldLookup < memDNA->mStructs.size())
{
short *curStruct = memDNA->mStructs[oldLookup];
-#endif
-
-
+#endif
- // rebuild...
- mCMPFlags[i] = FDF_STRUCT_NEQU;
+ // rebuild...
+ mCMPFlags[i] = FDF_STRUCT_NEQU;
#ifndef TEST_BACKWARD_FORWARD_COMPATIBILITY
- if (curStruct[1] == oldStruct[1])
+ if (curStruct[1] == oldStruct[1])
+ {
+ // type len same ...
+ if (mTlens[oldStruct[0]] == memDNA->mTlens[curStruct[0]])
{
- // type len same ...
- if (mTlens[oldStruct[0]] == memDNA->mTlens[curStruct[0]])
- {
- bool isSame = true;
- int elementLength = oldStruct[1];
-
+ bool isSame = true;
+ int elementLength = oldStruct[1];
- curStruct+=2;
- oldStruct+=2;
+ curStruct += 2;
+ oldStruct += 2;
+ for (int j = 0; j < elementLength; j++, curStruct += 2, oldStruct += 2)
+ {
+ // type the same
+ //const char* typeFileDNA = mTypes[oldStruct[0]];
+ //const char* typeMemDNA = mTypes[curStruct[0]];
+ if (strcmp(mTypes[oldStruct[0]], memDNA->mTypes[curStruct[0]]) != 0)
+ {
+ isSame = false;
+ break;
+ }
- for (int j=0; j<elementLength; j++, curStruct+=2, oldStruct+=2)
+ // name the same
+ if (strcmp(m_Names[oldStruct[1]].m_name, memDNA->m_Names[curStruct[1]].m_name) != 0)
{
- // type the same
- //const char* typeFileDNA = mTypes[oldStruct[0]];
- //const char* typeMemDNA = mTypes[curStruct[0]];
- if (strcmp(mTypes[oldStruct[0]], memDNA->mTypes[curStruct[0]])!=0)
- {
- isSame=false;
- break;
- }
-
- // name the same
- if (strcmp(m_Names[oldStruct[1]].m_name, memDNA->m_Names[curStruct[1]].m_name)!=0)
- {
- isSame=false;
- break;
- }
+ isSame = false;
+ break;
}
- // flag valid ==
- if (isSame)
- mCMPFlags[i] = FDF_STRUCT_EQU;
}
+ // flag valid ==
+ if (isSame)
+ mCMPFlags[i] = FDF_STRUCT_EQU;
}
-#endif
}
- }
-
-
-
-
-
- // recurse in
- for ( i=0; i<(int)mStructs.size(); i++)
- {
- if (mCMPFlags[i] == FDF_STRUCT_NEQU)
- initRecurseCmpFlags(i);
+#endif
}
}
+// recurse in
+for (i = 0; i < (int)mStructs.size(); i++)
+{
+ if (mCMPFlags[i] == FDF_STRUCT_NEQU)
+ initRecurseCmpFlags(i);
+}
+}
-
-
-static int name_is_array(char* name, int* dim1, int* dim2) {
+static int name_is_array(char *name, int *dim1, int *dim2)
+{
int len = strlen(name);
/*fprintf(stderr,"[%s]",name);*/
/*if (len >= 1) {
@@ -284,58 +262,77 @@ static int name_is_array(char* name, int* dim1, int* dim2) {
return 0;*/
char *bp;
int num;
- if (dim1) {
+ if (dim1)
+ {
*dim1 = 1;
}
- if (dim2) {
+ if (dim2)
+ {
*dim2 = 1;
}
bp = strchr(name, '[');
- if (!bp) {
+ if (!bp)
+ {
return 0;
}
num = 0;
- while (++bp < name+len-1) {
+ while (++bp < name + len - 1)
+ {
const char c = *bp;
- if (c == ']') {
+ if (c == ']')
+ {
break;
}
- if (c <= '9' && c >= '0') {
+ if (c <= '9' && c >= '0')
+ {
num *= 10;
num += (c - '0');
- } else {
+ }
+ else
+ {
printf("array parse error.\n");
return 0;
}
}
- if (dim2) {
+ if (dim2)
+ {
*dim2 = num;
}
/* find second dim, if any. */
bp = strchr(bp, '[');
- if (!bp) {
+ if (!bp)
+ {
return 1; /* at least we got the first dim. */
}
num = 0;
- while (++bp < name+len-1) {
+ while (++bp < name + len - 1)
+ {
const char c = *bp;
- if (c == ']') {
+ if (c == ']')
+ {
break;
}
- if (c <= '9' && c >= '0') {
+ if (c <= '9' && c >= '0')
+ {
num *= 10;
num += (c - '0');
- } else {
+ }
+ else
+ {
printf("array2 parse error.\n");
return 1;
}
}
- if (dim1) {
- if (dim2) {
+ if (dim1)
+ {
+ if (dim2)
+ {
*dim1 = *dim2;
*dim2 = num;
- } else {
+ }
+ else
+ {
*dim1 = num;
}
}
@@ -343,14 +340,15 @@ static int name_is_array(char* name, int* dim1, int* dim2) {
return 1;
}
-
// ----------------------------------------------------- //
void bDNA::init(char *data, int len, bool swap)
{
- int *intPtr=0;short *shtPtr=0;
- char *cp = 0;int dataLen =0;
+ int *intPtr = 0;
+ short *shtPtr = 0;
+ char *cp = 0;
+ int dataLen = 0;
//long nr=0;
- intPtr = (int*)data;
+ intPtr = (int *)data;
/*
SDNA (4 bytes) (magic number)
@@ -360,38 +358,35 @@ void bDNA::init(char *data, int len, bool swap)
<string>
*/
- if (strncmp(data, "SDNA", 4)==0)
+ if (strncmp(data, "SDNA", 4) == 0)
{
// skip ++ NAME
- intPtr++; intPtr++;
+ intPtr++;
+ intPtr++;
}
-
-
// Parse names
- if (swap)
+ if (swap)
{
*intPtr = ChunkUtils::swapInt(*intPtr);
}
dataLen = *intPtr;
intPtr++;
- cp = (char*)intPtr;
+ cp = (char *)intPtr;
int i;
- for ( i=0; i<dataLen; i++)
+ for (i = 0; i < dataLen; i++)
{
bNameInfo info;
info.m_name = cp;
info.m_isPointer = (info.m_name[0] == '*') || (info.m_name[1] == '*');
- name_is_array(info.m_name,&info.m_dim0,&info.m_dim1);
+ name_is_array(info.m_name, &info.m_dim0, &info.m_dim1);
m_Names.push_back(info);
- while (*cp)cp++;
+ while (*cp) cp++;
cp++;
}
-
- cp = b3AlignPointer(cp,4);
-
+ cp = b3AlignPointer(cp, 4);
/*
TYPE (4 bytes)
@@ -400,26 +395,26 @@ void bDNA::init(char *data, int len, bool swap)
<string>
*/
- intPtr = (int*)cp;
- assert(strncmp(cp, "TYPE", 4)==0); intPtr++;
+ intPtr = (int *)cp;
+ assert(strncmp(cp, "TYPE", 4) == 0);
+ intPtr++;
- if (swap)
+ if (swap)
{
*intPtr = ChunkUtils::swapInt(*intPtr);
}
dataLen = *intPtr;
intPtr++;
- cp = (char*)intPtr;
- for ( i=0; i<dataLen; i++)
+ cp = (char *)intPtr;
+ for (i = 0; i < dataLen; i++)
{
mTypes.push_back(cp);
- while (*cp)cp++;
+ while (*cp) cp++;
cp++;
}
-
- cp = b3AlignPointer(cp,4);
+ cp = b3AlignPointer(cp, 4);
/*
TLEN (4 bytes)
@@ -428,13 +423,14 @@ void bDNA::init(char *data, int len, bool swap)
*/
// Parse type lens
- intPtr = (int*)cp;
- assert(strncmp(cp, "TLEN", 4)==0); intPtr++;
+ intPtr = (int *)cp;
+ assert(strncmp(cp, "TLEN", 4) == 0);
+ intPtr++;
dataLen = (int)mTypes.size();
- shtPtr = (short*)intPtr;
- for ( i=0; i<dataLen; i++, shtPtr++)
+ shtPtr = (short *)intPtr;
+ for (i = 0; i < dataLen; i++, shtPtr++)
{
if (swap)
shtPtr[0] = ChunkUtils::swapShort(shtPtr[0]);
@@ -454,94 +450,89 @@ void bDNA::init(char *data, int len, bool swap)
<namenr>
*/
- intPtr = (int*)shtPtr;
- cp = (char*)intPtr;
- assert(strncmp(cp, "STRC", 4)==0); intPtr++;
+ intPtr = (int *)shtPtr;
+ cp = (char *)intPtr;
+ assert(strncmp(cp, "STRC", 4) == 0);
+ intPtr++;
- if (swap)
+ if (swap)
{
*intPtr = ChunkUtils::swapInt(*intPtr);
}
dataLen = *intPtr;
intPtr++;
-
- shtPtr = (short*)intPtr;
- for ( i=0; i<dataLen; i++)
+ shtPtr = (short *)intPtr;
+ for (i = 0; i < dataLen; i++)
{
- mStructs.push_back (shtPtr);
+ mStructs.push_back(shtPtr);
if (swap)
{
- shtPtr[0]= ChunkUtils::swapShort(shtPtr[0]);
- shtPtr[1]= ChunkUtils::swapShort(shtPtr[1]);
+ shtPtr[0] = ChunkUtils::swapShort(shtPtr[0]);
+ shtPtr[1] = ChunkUtils::swapShort(shtPtr[1]);
int len = shtPtr[1];
- shtPtr+= 2;
+ shtPtr += 2;
- for (int a=0; a<len; a++, shtPtr+=2)
+ for (int a = 0; a < len; a++, shtPtr += 2)
{
- shtPtr[0]= ChunkUtils::swapShort(shtPtr[0]);
- shtPtr[1]= ChunkUtils::swapShort(shtPtr[1]);
+ shtPtr[0] = ChunkUtils::swapShort(shtPtr[0]);
+ shtPtr[1] = ChunkUtils::swapShort(shtPtr[1]);
}
}
else
- shtPtr+= (2*shtPtr[1])+2;
+ shtPtr += (2 * shtPtr[1]) + 2;
}
-
// build reverse lookups
- for ( i=0; i<(int)mStructs.size(); i++)
+ for (i = 0; i < (int)mStructs.size(); i++)
{
short *strc = mStructs.at(i);
- if (!mPtrLen && strcmp(mTypes[strc[0]],"ListBase")==0)
+ if (!mPtrLen && strcmp(mTypes[strc[0]], "ListBase") == 0)
{
- mPtrLen = mTlens[strc[0]]/2;
+ mPtrLen = mTlens[strc[0]] / 2;
}
mStructReverse.insert(strc[0], i);
- mTypeLookup.insert(b3HashString(mTypes[strc[0]]),i);
+ mTypeLookup.insert(b3HashString(mTypes[strc[0]]), i);
}
}
-
// ----------------------------------------------------- //
-int bDNA::getArraySize(char* string)
+int bDNA::getArraySize(char *string)
{
int ret = 1;
int len = strlen(string);
-
- char* next = 0;
- for (int i=0; i<len; i++)
+ char *next = 0;
+ for (int i = 0; i < len; i++)
{
char c = string[i];
if (c == '[')
- next = &string[i+1];
- else if (c==']')
+ next = &string[i + 1];
+ else if (c == ']')
if (next)
ret *= atoi(next);
}
-// print (string << ' ' << ret);
+ // print (string << ' ' << ret);
return ret;
}
-
void bDNA::dumpTypeDefinitions()
{
int i;
int numTypes = mTypes.size();
-
- for (i=0;i<numTypes;i++)
- {
+ for (i = 0; i < numTypes; i++)
+ {
}
- for ( 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];
int oldLookup = getReverseType(oldStruct[0]);
@@ -551,44 +542,46 @@ void bDNA::dumpTypeDefinitions()
continue;
}
- short* newStruct = mStructs[oldLookup];
- char* typeName = mTypes[newStruct[0]];
- printf("%3d: %s ",i,typeName);
-
+ short *newStruct = mStructs[oldLookup];
+ char *typeName = mTypes[newStruct[0]];
+ printf("%3d: %s ", i, typeName);
+
//char *name = mNames[oldStruct[1]];
int len = oldStruct[1];
- printf(" (%d fields) ",len);
- oldStruct+=2;
+ printf(" (%d fields) ", len);
+ oldStruct += 2;
printf("{");
int j;
- for (j=0; j<len; ++j,oldStruct+=2) {
- const char* name = m_Names[oldStruct[1]].m_name;
- printf("%s %s", mTypes[oldStruct[0]],name);
- int elemNumBytes= 0;
+ for (j = 0; j < len; ++j, oldStruct += 2)
+ {
+ const char *name = m_Names[oldStruct[1]].m_name;
+ printf("%s %s", mTypes[oldStruct[0]], name);
+ int elemNumBytes = 0;
int arrayDimensions = getArraySizeNew(oldStruct[1]);
if (m_Names[oldStruct[1]].m_isPointer)
{
elemNumBytes = VOID_IS_8 ? 8 : 4;
- } else
+ }
+ else
{
elemNumBytes = getLength(oldStruct[0]);
}
- printf(" /* %d bytes */",elemNumBytes*arrayDimensions);
-
- if (j == len-1) {
+ printf(" /* %d bytes */", elemNumBytes * arrayDimensions);
+
+ if (j == len - 1)
+ {
printf(";}");
- } else {
+ }
+ else
+ {
printf("; ");
}
- totalBytes+=elemNumBytes*arrayDimensions;
+ totalBytes += elemNumBytes * arrayDimensions;
}
- printf("\ntotalBytes=%d\n\n",totalBytes);
-
+ printf("\ntotalBytes=%d\n\n", totalBytes);
}
-
-
#if 0
/* dump out display of types and their sizes */
@@ -618,12 +611,6 @@ void bDNA::dumpTypeDefinitions()
}
}
#endif
-
}
-
-
-
//eof
-
-