From 22b7c9dfa80d0f7abca40f061865c2ab3c136a74 Mon Sep 17 00:00:00 2001 From: Oussama Date: Thu, 3 Jan 2019 14:26:51 +0100 Subject: Update Bullet to the latest commit 126b676 --- .../Bullet3Serialize/Bullet2FileLoader/b3DNA.cpp | 355 ++++++++++----------- 1 file changed, 171 insertions(+), 184 deletions(-) (limited to 'thirdparty/bullet/Bullet3Serialize/Bullet2FileLoader/b3DNA.cpp') 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; jgetReverseType(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; jm_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) */ - 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 */ - 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 */ - 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