* Adjustment: Update Bullet version to 3.24.

This commit is contained in:
Robert MacGregor 2022-06-27 10:01:08 -04:00
parent 35de012ee7
commit 4a3f31df2a
6148 changed files with 2112532 additions and 56873 deletions

View file

@ -0,0 +1,32 @@
###############################################################################
PROJECT(GEN)
FILE(GLOB cpp_SRC "*.cpp")
FILE(GLOB h_SRC "*.h")
SET(includes
.
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletFileLoader
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BlenderSerialize
${BULLET_PHYSICS_SOURCE_DIR}/src
)
LINK_LIBRARIES(
BulletFileLoader LinearMath
)
INCLUDE_DIRECTORIES(${includes})
SET(Main_LIBS LinearMath)
ADD_EXECUTABLE(HeaderGenerator ${cpp_SRC} ${h_SRC})
IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
ADD_CUSTOM_COMMAND(
TARGET HeaderGenerator
POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/HeaderGenerator/createDnaString.bat ${CMAKE_CURRENT_BINARY_DIR}/createDnaString.bat
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/HeaderGenerator/bulletGenerate.py ${CMAKE_CURRENT_BINARY_DIR}/bulletGenerate.py
)
ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)

View file

@ -0,0 +1,444 @@
/* Copyright (C) 2006 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.
*/
#include <sstream>
#include "bDNA.h"
#include "bBlenderFile.h"
#include "btBulletFile.h"
#include "LinearMath/btSerializer.h"
#include "bCommon.h"
#include <map>
#include <vector>
#include <string.h>
bool isBulletFile = true;
using namespace bParse;
typedef std::string bString;
///////////////////////////////////////////////////////////////////////////////
typedef std::map<bString, bString> bStringMap;
typedef std::vector<class bVariable> bVariableList;
typedef std::vector<bString> bStringList;
///////////////////////////////////////////////////////////////////////////////
static FILE *dump = 0;
static bDNA *mDNA = 0;
static bStringMap mStructs;
///////////////////////////////////////////////////////////////////////////////
class bVariable
{
public:
bVariable();
~bVariable();
bString dataType;
bString variableName;
bString functionName;
bString classCtor;
bString memberVariable;
bString memberDataType;
bString functionArgs;
void initialize(bString dataType, bString variable, bStringMap refDataTable);
bool isPtr;
bool isFunctionPtr;
bool isPtrToPtr;
bool isArray;
bool isCharArray;
bool isListBase;
bool isPadding;
bool isCommentedOut;
bool isGeneratedType;
bool isbString;
};
///////////////////////////////////////////////////////////////////////////////
bool dataTypeStandard(bString dataType)
{
if (dataType == "char")
return true;
if (dataType == "short")
return true;
if (dataType == "int")
return true;
if (dataType == "long")
return true;
if (dataType == "float")
return true;
if (dataType == "double")
return true;
if (dataType == "void")
return true;
if (dataType == "btScalar")
return true;
return false;
}
///////////////////////////////////////////////////////////////////////////////
void writeTemplate(short *structData)
{
bString type = mDNA->getType(structData[0]);
bString className = type;
bString prefix = isBulletFile ? "bullet_" : "blender_";
int thisLen = structData[1];
structData += 2;
bString fileName = prefix + type;
bVariableList dataTypes;
bStringMap includeFiles;
for (int dataVal = 0; dataVal < thisLen; dataVal++, structData += 2)
{
bString dataType = mDNA->getType(structData[0]);
bString dataName = mDNA->getName(structData[1]);
{
bString newDataType = "";
bString newDataName = "";
bStringMap::iterator addB = mStructs.find(dataType);
if (addB != mStructs.end())
{
newDataType = addB->second;
newDataName = dataName;
}
else
{
if (dataTypeStandard(dataType))
{
newDataType = dataType;
newDataName = dataName;
}
else
{
// Unresolved
// set it to an empty struct
// if it's not a ptr generate an error
newDataType = "bInvalidHandle";
newDataName = dataName;
if (dataName[0] != '*')
{
}
}
}
if (!newDataType.empty() && !newDataName.empty())
{
bVariable var = bVariable();
var.initialize(newDataType, newDataName, mStructs);
dataTypes.push_back(var);
}
}
bStringMap::iterator include = mStructs.find(dataType);
if (include != mStructs.end())
{
if (dataName[0] != '*')
{
if (includeFiles.find(dataType) == includeFiles.end())
{
includeFiles[dataType] = prefix + dataType;
}
}
}
}
fprintf(dump, "###############################################################\n");
fprintf(dump, "%s = bStructClass()\n", fileName.c_str());
fprintf(dump, "%s.name = '%s'\n", fileName.c_str(), className.c_str());
fprintf(dump, "%s.filename = '%s'\n", fileName.c_str(), fileName.c_str());
bVariableList::iterator vars = dataTypes.begin();
while (vars != dataTypes.end())
{
fprintf(dump, "%s.dataTypes.append('%s %s')\n", fileName.c_str(), vars->dataType.c_str(), vars->variableName.c_str());
vars++;
}
bStringMap::iterator inc = includeFiles.begin();
while (inc != includeFiles.end())
{
fprintf(dump, "%s.includes.append('%s.h')\n", fileName.c_str(), inc->second.c_str());
inc++;
}
fprintf(dump, "DataTypeList.append(%s)\n", fileName.c_str());
}
///////////////////////////////////////////////////////////////////////////////
char data[] = {
"\n"
"class bStructClass:\n"
" def __init__(self):\n"
" self.name = \"\";\n"
" self.filename = \"\";\n"
" self.includes = []\n"
" self.dataTypes = []\n"
"\n\n"
"DataTypeList = []\n"};
///////////////////////////////////////////////////////////////////////////////
int main(int argc, char **argv)
{
using namespace bParse;
dump = fopen("dump.py", "w");
if (!dump) return 0;
fprintf(dump, "%s\n", data);
#if 0
char* filename = "../../../../data/r2d2_multibody.bullet";
if (argc==2)
filename = argv[1];
bString fileStr(filename);
bString extension(".bullet");
int index2 = fileStr.find(extension);
if (index2>=0)
isBulletFile=true;
FILE* fp = fopen (filename,"rb");
if (!fp)
{
printf("error: file not found %s\n",filename);
exit(0);
}
char* memBuf = 0;
int len = 0;
long currentpos = ftell(fp); /* save current cursor position */
long newpos;
int bytesRead;
fseek(fp, 0, SEEK_END); /* seek to end */
newpos = ftell(fp); /* find position of end -- this is the length */
fseek(fp, currentpos, SEEK_SET); /* restore previous cursor position */
len = newpos;
memBuf = (char*)malloc(len);
bytesRead = fread(memBuf,len,1,fp);
bool swap = false;
if (isBulletFile)
{
btBulletFile f(memBuf,len);
swap = (f.getFlags() & FD_ENDIAN_SWAP)!=0;
} else
{
bBlenderFile f(memBuf,len);
swap = (f.getFlags() & FD_ENDIAN_SWAP)!=0;
}
#else
isBulletFile = true;
bool swap = false;
char *memBuf = sBulletDNAstr;
int len = sBulletDNAlen;
#endif
char *blenderData = memBuf;
int sdnaPos = 0;
int mDataStart = 12;
char *tempBuffer = blenderData;
for (int i = 0; i < len; i++)
{
// looking for the data's starting position
// and the start of SDNA decls
if (!mDataStart && strncmp(tempBuffer, "REND", 4) == 0)
mDataStart = i;
if (!sdnaPos && strncmp(tempBuffer, "SDNA", 4) == 0)
sdnaPos = i;
if (mDataStart && sdnaPos) break;
tempBuffer++;
}
FILE *fpdna = fopen("dnaString.txt", "w");
char buf[1024];
for (int i = 0; i < len - sdnaPos; i++)
{
int dnaval = (memBuf + sdnaPos)[i];
if ((i % 32) == 0)
{
sprintf(buf, "%d,\n", dnaval);
}
else
{
sprintf(buf, "%d,", dnaval);
}
fwrite(buf, strlen(buf), 1, fpdna);
}
fclose(fpdna);
mDNA = new bDNA();
//mDNA->initMemory();
mDNA->init(memBuf + sdnaPos, len - sdnaPos, swap);
for (int i = 0; i < mDNA->getNumStructs(); i++)
{
short *structData = mDNA->getStruct(i);
bString type = mDNA->getType(structData[0]);
bString className = type;
mStructs[type] = className;
}
for (int i = 0; i < mDNA->getNumStructs(); i++)
{
short *structData = mDNA->getStruct(i);
writeTemplate(structData);
}
delete mDNA;
fclose(dump);
return 0;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
int _getArraySize(char *str)
{
int a, mul = 1;
char stri[100], *cp = 0;
int len = (int)strlen(str);
memcpy(stri, str, len + 1);
for (a = 0; a < len; a++)
{
if (str[a] == '[')
cp = &(stri[a + 1]);
else if (str[a] == ']' && cp)
{
stri[a] = 0;
mul *= atoi(cp);
}
}
return mul;
}
///////////////////////////////////////////////////////////////////////////////
bVariable::bVariable()
: dataType("invalid"),
variableName("invalid"),
functionName(""),
classCtor(""),
memberVariable(""),
memberDataType(""),
functionArgs(""),
isPtr(false),
isFunctionPtr(false),
isPtrToPtr(false),
isArray(false),
isCharArray(false),
isListBase(false),
isPadding(false),
isCommentedOut(false),
isGeneratedType(false),
isbString(false)
{
}
///////////////////////////////////////////////////////////////////////////////
bVariable::~bVariable()
{
dataType.clear();
variableName.clear();
}
///////////////////////////////////////////////////////////////////////////////
void bVariable::initialize(bString type, bString variable, bStringMap refDataTable)
{
dataType = type;
variableName = variable;
if (variableName[0] == '*')
{
isPtr = true;
if (variableName[1] == '*')
isPtrToPtr = true;
}
if (variableName[0] == '(')
if (variableName[1] == '*')
isFunctionPtr = true;
if (variableName[variableName.size() - 1] == ']')
{
isArray = true;
if (type == "char")
isCharArray = true;
}
if (type == "ListBase")
isListBase = true;
if (variableName[0] == 'p')
{
bString sub = variableName.substr(0, 3);
if (sub == "pad")
isPadding = true;
}
if (dataType[0] == '/' && dataType[1] == '/')
isCommentedOut = true;
if (refDataTable.find(dataType) != refDataTable.end())
isGeneratedType = true;
if (!isBulletFile)
{
// replace valid float arrays
if (dataType == "float" && isArray)
{
int size = _getArraySize((char *)variableName.c_str());
if (size == 3)
{
dataType = "vec3f";
variableName = variableName.substr(0, variableName.find_first_of("["));
}
if (size == 4)
{
dataType = "vec4f";
variableName = variableName.substr(0, variableName.find_first_of("["));
}
}
}
memberDataType = dataType;
functionArgs = variableName;
}
// eof

View file

@ -0,0 +1,107 @@
import dump
header = """/* Copyright (C) 2006 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
"""
dtList = dump.DataTypeList
out = "../BlenderSerialize/autogenerated/"
spaces = 4
def addSpaces(file, space):
for i in range(0, space):
file.write(" ")
def write(file, spaces, string):
addSpaces(file, spaces)
file.write(string)
###################################################################################
blender = open(out + "blender.h", 'w')
blender.write(header)
blender.write("#ifndef __BLENDER_H__\n")
blender.write("#define __BLENDER_H__\n")
for dt in dtList:
blender.write("#include \"%s.h\"\n" % dt.filename)
blender.write("#endif//__BLENDER_H__")
blender.close()
###################################################################################
blenderC = open(out + "blender_Common.h", 'w')
blenderC.write(header)
blenderC.write("#ifndef __BLENDERCOMMON_H__\n")
blenderC.write("#define __BLENDERCOMMON_H__\n")
strUnRes = """
// put an empty struct in the case
typedef struct bInvalidHandle {
int unused;
}bInvalidHandle;
"""
blenderC.write(strUnRes)
blenderC.write("namespace Blender {\n")
for dt in dtList:
write(blenderC, 4, "class %s;\n" % dt.name)
blenderC.write("}\n")
blenderC.write("#endif//__BLENDERCOMMON_H__")
blenderC.close()
for dt in dtList:
fp = open(out + dt.filename + ".h", 'w')
fp.write(header)
strUpper = dt.filename.upper()
fp.write("#ifndef __%s__H__\n" % strUpper)
fp.write("#define __%s__H__\n" % strUpper)
fp.write("\n\n")
fp.write("// -------------------------------------------------- //\n")
fp.write("#include \"blender_Common.h\"\n")
for i in dt.includes:
fp.write("#include \"%s\"\n" % i)
fp.write("\nnamespace Blender {\n")
fp.write("\n\n")
addSpaces(fp, 4)
fp.write("// ---------------------------------------------- //\n")
write(fp, 4, "class %s\n" % dt.name)
write(fp, 4, "{\n")
write(fp, 4, "public:\n")
for i in dt.dataTypes:
write(fp, 8, i + ";\n")
write(fp, 4, "};\n")
fp.write("}\n")
fp.write("\n\n")
fp.write("#endif//__%s__H__\n" % strUpper)
fp.close()

View file

@ -0,0 +1,85 @@
import sys
sys.path.append(".")
import dump
header = """/* Copyright (C) 2011 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 Bullet/Extras/HeaderGenerator/bulletGenerate.py
"""
dtList = dump.DataTypeList
out = "autogenerated/"
spaces = 4
def addSpaces(file, space):
for i in range(0, space):
file.write(" ")
def write(file, spaces, string):
addSpaces(file, spaces)
file.write(string)
###################################################################################
blender = open(out + "bullet.h", 'w')
blender.write(header)
blender.write("#ifndef __BULLET_H__\n")
blender.write("#define __BULLET_H__\n")
#for dt in dtList:
# blender.write("struct %s;\n"%dt.filename)
###################################################################################
blender.write("namespace Bullet {\n")
strUnRes = """
// put an empty struct in the case
typedef struct bInvalidHandle {
int unused;
}bInvalidHandle;
"""
blender.write(strUnRes)
for dt in dtList:
write(blender, 4, "class %s;\n" % dt.name)
for dt in dtList:
strUpper = dt.filename.upper()
blender.write("// -------------------------------------------------- //\n")
write(blender, 4, "class %s\n" % dt.name)
write(blender, 4, "{\n")
write(blender, 4, "public:\n")
for i in dt.dataTypes:
write(blender, 8, i + ";\n")
write(blender, 4, "};\n")
blender.write("\n\n")
blender.write("}\n")
blender.write("#endif//__BULLET_H__")
blender.close()

View file

@ -0,0 +1,7 @@
delete dnaString.txt
mkdir autogenerated
Debug\HeaderGenerator.exe
python bulletGenerate.py