Skip to content

Commit

Permalink
bullet: Sync with upstream 3.17
Browse files Browse the repository at this point in the history
Stop include Bullet headers using `-isystem` for GCC/Clang as it misleads
SCons into not properly rebuilding all files when headers change.

This means we also need to make sure Bullet builds without warning, and
current version fares fairly well, there were just a couple to fix (patch
included).

Increase minimum version for distro packages to 2.90 (this was never released
as the "next" version after 2.89 was 3.05... but that covers it too).
  • Loading branch information
akien-mga committed Sep 29, 2021
1 parent 9b4e62d commit b7901c7
Show file tree
Hide file tree
Showing 107 changed files with 10,812 additions and 6,117 deletions.
12 changes: 4 additions & 8 deletions modules/bullet/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ env_bullet = env_modules.Clone()
thirdparty_obj = []

if env["builtin_bullet"]:
# Build only version 2 for now (as of 2.89)
# Build only "Bullet2" API (not "Bullet3" folders).
# Sync file list with relevant upstream CMakeLists.txt for each folder.
thirdparty_dir = "#thirdparty/bullet/"

Expand Down Expand Up @@ -177,6 +177,7 @@ if env["builtin_bullet"]:
"BulletSoftBody/btDeformableContactProjection.cpp",
"BulletSoftBody/btDeformableMultiBodyDynamicsWorld.cpp",
"BulletSoftBody/btDeformableContactConstraint.cpp",
"BulletSoftBody/poly34.cpp",
# clew
"clew/clew.c",
# LinearMath
Expand All @@ -186,6 +187,7 @@ if env["builtin_bullet"]:
"LinearMath/btGeometryUtil.cpp",
"LinearMath/btPolarDecomposition.cpp",
"LinearMath/btQuickprof.cpp",
"LinearMath/btReducedVector.cpp",
"LinearMath/btSerializer.cpp",
"LinearMath/btSerializer64.cpp",
"LinearMath/btThreads.cpp",
Expand All @@ -197,13 +199,7 @@ if env["builtin_bullet"]:

thirdparty_sources = [thirdparty_dir + file for file in bullet2_src]

# Treat Bullet headers as system headers to avoid raising warnings. Not supported on MSVC.
if not env.msvc:
env_bullet.Append(CPPFLAGS=["-isystem", Dir(thirdparty_dir).path])
else:
env_bullet.Prepend(CPPPATH=[thirdparty_dir])
# if env['target'] == "debug" or env['target'] == "release_debug":
# env_bullet.Append(CPPDEFINES=['BT_DEBUG'])
env_bullet.Prepend(CPPPATH=[thirdparty_dir])

env_bullet.Append(CPPDEFINES=["BT_USE_OLD_DAMPING_METHOD"])

Expand Down
8 changes: 5 additions & 3 deletions platform/server/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,17 @@ def configure(env):
env.ParseConfig("pkg-config libpng16 --cflags --libs")

if not env["builtin_bullet"]:
# We need at least version 2.89
# We need at least version 2.90
min_bullet_version = "2.90"

import subprocess

bullet_version = subprocess.check_output(["pkg-config", "bullet", "--modversion"]).strip()
if str(bullet_version) < "2.89":
if str(bullet_version) < min_bullet_version:
# Abort as system bullet was requested but too old
print(
"Bullet: System version {0} does not match minimal requirements ({1}). Aborting.".format(
bullet_version, "2.89"
bullet_version, min_bullet_version
)
)
sys.exit(255)
Expand Down
8 changes: 5 additions & 3 deletions platform/x11/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,17 @@ def configure(env):
env.ParseConfig("pkg-config libpng16 --cflags --libs")

if not env["builtin_bullet"]:
# We need at least version 2.89
# We need at least version 2.90
min_bullet_version = "2.90"

import subprocess

bullet_version = subprocess.check_output(["pkg-config", "bullet", "--modversion"]).strip()
if str(bullet_version) < "2.89":
if str(bullet_version) < min_bullet_version:
# Abort as system bullet was requested but too old
print(
"Bullet: System version {0} does not match minimal requirements ({1}). Aborting.".format(
bullet_version, "2.89"
bullet_version, min_bullet_version
)
)
sys.exit(255)
Expand Down
8 changes: 5 additions & 3 deletions thirdparty/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ readability.
## bullet

- Upstream: https://github.com/bulletphysics/bullet3
- Version: 2.89 (830f0a9565b1829a07e21e2f16be2aa9966bd28c, 2019)
- Version: 3.17 (ebe1916b90acae8b13cd8c6b637d8327cdc64e94, 2021)
- License: zlib

Files extracted from upstream source:

- src/* apart from CMakeLists.txt and premake4.lua files
- LICENSE.txt
- `src/*` apart from CMakeLists.txt and premake4.lua files
- `LICENSE.txt`, and `VERSION` as `VERSION.txt`

Includes a warning fix which should be upstreamed soon (see patch in `patches`).


## certs
Expand Down
34 changes: 0 additions & 34 deletions thirdparty/bullet/0001-old-damping-def.patch

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,20 @@ void b3OptimizedBvh::updateBvhNodes(b3StridingMeshInterface* meshInterface, int
meshInterface->getLockedReadOnlyVertexIndexBase(&vertexbase, numverts, type, stride, &indexbase, indexstride, numfaces, indicestype, nodeSubPart);

curNodeSubPart = nodeSubPart;
b3Assert(indicestype == PHY_INTEGER || indicestype == PHY_SHORT);
}
//triangles->getLockedReadOnlyVertexIndexBase(vertexBase,numVerts,

unsigned int* gfxbase = (unsigned int*)(indexbase + nodeTriangleIndex * indexstride);

for (int j = 2; j >= 0; j--)
{
int graphicsindex = indicestype == PHY_SHORT ? ((unsigned short*)gfxbase)[j] : gfxbase[j];
int graphicsindex;
switch (indicestype) {
case PHY_INTEGER: graphicsindex = gfxbase[j]; break;
case PHY_SHORT: graphicsindex = ((unsigned short*)gfxbase)[j]; break;
case PHY_UCHAR: graphicsindex = ((unsigned char*)gfxbase)[j]; break;
default: b3Assert(0);
}
if (type == PHY_FLOAT)
{
float* graphicsbase = (float*)(vertexbase + graphicsindex * stride);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -851,12 +851,12 @@ void bFile::swapData(char *data, short type, int arraySize, bool ignoreEndianFla

void bFile::safeSwapPtr(char *dst, const char *src)
{
if (!src || !dst)
return;

int ptrFile = mFileDNA->getPointerSize();
int ptrMem = mMemoryDNA->getPointerSize();

if (!src && !dst)
return;

if (ptrFile == ptrMem)
{
memcpy(dst, src, ptrMem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ struct btDbvntNode

btDbvntNode(const btDbvtNode* n)
: volume(n->volume)
, angle(0)
, normal(0,0,0)
, angle(0)
, data(n->data)
{
childs[0] = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class btOverlappingPairCache : public btOverlappingPairCallback
virtual void cleanOverlappingPair(btBroadphasePair& pair, btDispatcher* dispatcher) = 0;

virtual int getNumOverlappingPairs() const = 0;

virtual bool needsBroadphaseCollision(btBroadphaseProxy * proxy0, btBroadphaseProxy * proxy1) const = 0;
virtual btOverlapFilterCallback* getOverlapFilterCallback() = 0;
virtual void cleanProxyFromPairs(btBroadphaseProxy* proxy, btDispatcher* dispatcher) = 0;

virtual void setOverlapFilterCallback(btOverlapFilterCallback* callback) = 0;
Expand Down Expand Up @@ -380,6 +381,14 @@ class btNullPairCache : public btOverlappingPairCache
{
}

bool needsBroadphaseCollision(btBroadphaseProxy*, btBroadphaseProxy*) const
{
return true;
}
btOverlapFilterCallback* getOverlapFilterCallback()
{
return 0;
}
virtual void setOverlapFilterCallback(btOverlapFilterCallback* /*callback*/)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,6 @@ void btQuantizedBvh::reportAabbOverlappingNodex(btNodeOverlapCallback* nodeCallb
}
}

int maxIterations = 0;

void btQuantizedBvh::walkStacklessTree(btNodeOverlapCallback* nodeCallback, const btVector3& aabbMin, const btVector3& aabbMax) const
{
btAssert(!m_useQuantization);
Expand Down Expand Up @@ -387,8 +385,6 @@ void btQuantizedBvh::walkStacklessTree(btNodeOverlapCallback* nodeCallback, cons
curIndex += escapeIndex;
}
}
if (maxIterations < walkIterations)
maxIterations = walkIterations;
}

/*
Expand Down Expand Up @@ -468,7 +464,7 @@ void btQuantizedBvh::walkStacklessTreeAgainstRay(btNodeOverlapCallback* nodeCall

#ifdef RAYAABB2
btVector3 rayDir = (rayTarget - raySource);
rayDir.normalize();
rayDir.safeNormalize();// stephengold changed normalize to safeNormalize 2020-02-17
lambda_max = rayDir.dot(rayTarget - raySource);
///what about division by zero? --> just set rayDirection[i] to 1.0
btVector3 rayDirectionInverse;
Expand Down Expand Up @@ -529,8 +525,6 @@ void btQuantizedBvh::walkStacklessTreeAgainstRay(btNodeOverlapCallback* nodeCall
curIndex += escapeIndex;
}
}
if (maxIterations < walkIterations)
maxIterations = walkIterations;
}

void btQuantizedBvh::walkStacklessQuantizedTreeAgainstRay(btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin, const btVector3& aabbMax, int startNodeIndex, int endNodeIndex) const
Expand All @@ -554,7 +548,7 @@ void btQuantizedBvh::walkStacklessQuantizedTreeAgainstRay(btNodeOverlapCallback*

#ifdef RAYAABB2
btVector3 rayDirection = (rayTarget - raySource);
rayDirection.normalize();
rayDirection.safeNormalize();// stephengold changed normalize to safeNormalize 2020-02-17
lambda_max = rayDirection.dot(rayTarget - raySource);
///what about division by zero? --> just set rayDirection[i] to 1.0
rayDirection[0] = rayDirection[0] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDirection[0];
Expand Down Expand Up @@ -654,8 +648,6 @@ void btQuantizedBvh::walkStacklessQuantizedTreeAgainstRay(btNodeOverlapCallback*
curIndex += escapeIndex;
}
}
if (maxIterations < walkIterations)
maxIterations = walkIterations;
}

void btQuantizedBvh::walkStacklessQuantizedTree(btNodeOverlapCallback* nodeCallback, unsigned short int* quantizedQueryAabbMin, unsigned short int* quantizedQueryAabbMax, int startNodeIndex, int endNodeIndex) const
Expand Down Expand Up @@ -718,8 +710,6 @@ void btQuantizedBvh::walkStacklessQuantizedTree(btNodeOverlapCallback* nodeCallb
curIndex += escapeIndex;
}
}
if (maxIterations < walkIterations)
maxIterations = walkIterations;
}

//This traversal can be called from Playstation 3 SPU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ class btCollisionDispatcher : public btDispatcher

btAlignedObjectArray<btPersistentManifold*> m_manifoldsPtr;

btManifoldResult m_defaultManifoldResult;

btNearCallback m_nearCallback;

btPoolAllocator* m_collisionAlgorithmPoolAllocator;
Expand Down Expand Up @@ -95,11 +93,15 @@ class btCollisionDispatcher : public btDispatcher

btPersistentManifold* getManifoldByIndexInternal(int index)
{
btAssert(index>=0);
btAssert(index<m_manifoldsPtr.size());
return m_manifoldsPtr[index];
}

const btPersistentManifold* getManifoldByIndexInternal(int index) const
{
btAssert(index>=0);
btAssert(index<m_manifoldsPtr.size());
return m_manifoldsPtr[index];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ subject to the following restrictions:
btCollisionDispatcherMt::btCollisionDispatcherMt(btCollisionConfiguration* config, int grainSize)
: btCollisionDispatcher(config)
{
m_batchManifoldsPtr.resize(btGetTaskScheduler()->getNumThreads());
m_batchUpdating = false;
m_grainSize = grainSize; // iterations per task
}
Expand Down Expand Up @@ -65,6 +66,10 @@ btPersistentManifold* btCollisionDispatcherMt::getNewManifold(const btCollisionO
manifold->m_index1a = m_manifoldsPtr.size();
m_manifoldsPtr.push_back(manifold);
}
else
{
m_batchManifoldsPtr[btGetCurrentThreadIndex()].push_back(manifold);
}

return manifold;
}
Expand Down Expand Up @@ -121,7 +126,7 @@ struct CollisionDispatcherUpdater : public btIParallelForBody

void btCollisionDispatcherMt::dispatchAllCollisionPairs(btOverlappingPairCache* pairCache, const btDispatcherInfo& info, btDispatcher* dispatcher)
{
int pairCount = pairCache->getNumOverlappingPairs();
const int pairCount = pairCache->getNumOverlappingPairs();
if (pairCount == 0)
{
return;
Expand All @@ -136,16 +141,17 @@ void btCollisionDispatcherMt::dispatchAllCollisionPairs(btOverlappingPairCache*
btParallelFor(0, pairCount, m_grainSize, updater);
m_batchUpdating = false;

// reconstruct the manifolds array to ensure determinism
m_manifoldsPtr.resizeNoInitialize(0);

btBroadphasePair* pairs = pairCache->getOverlappingPairArrayPtr();
for (int i = 0; i < pairCount; ++i)
// merge new manifolds, if any
for (int i = 0; i < m_batchManifoldsPtr.size(); ++i)
{
if (btCollisionAlgorithm* algo = pairs[i].m_algorithm)
btAlignedObjectArray<btPersistentManifold*>& batchManifoldsPtr = m_batchManifoldsPtr[i];

for (int j = 0; j < batchManifoldsPtr.size(); ++j)
{
algo->getAllContactManifolds(m_manifoldsPtr);
m_manifoldsPtr.push_back(batchManifoldsPtr[j]);
}

batchManifoldsPtr.resizeNoInitialize(0);
}

// update the indices (used when releasing manifolds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class btCollisionDispatcherMt : public btCollisionDispatcher
virtual void dispatchAllCollisionPairs(btOverlappingPairCache* pairCache, const btDispatcherInfo& info, btDispatcher* dispatcher) BT_OVERRIDE;

protected:
btAlignedObjectArray<btAlignedObjectArray<btPersistentManifold*> > m_batchManifoldsPtr;
bool m_batchUpdating;
int m_grainSize;
};
Expand Down
Loading

0 comments on commit b7901c7

Please sign in to comment.