Skip to content

Instantly share code, notes, and snippets.

@apsabelhaus
Created June 9, 2018 17:49
Show Gist options
  • Save apsabelhaus/719ca07f430105f6ddf3d98db7e366d8 to your computer and use it in GitHub Desktop.
Save apsabelhaus/719ca07f430105f6ddf3d98db7e366d8 to your computer and use it in GitHub Desktop.
Determinism patch for Bullet Physics in NTRT
--- src/BulletCollision/BroadphaseCollision/btAxisSweep3_old.h 2016-10-12 16:39:06.314991696 -0400
+++ src/BulletCollision/BroadphaseCollision/btAxisSweep3.h 2016-10-12 16:38:55.742991000 -0400
@@ -362,8 +362,8 @@
if (!m_pairCache)
{
- void* ptr = btAlignedAlloc(sizeof(btHashedOverlappingPairCache),16);
- m_pairCache = new(ptr) btHashedOverlappingPairCache();
+ void* ptr = btAlignedAlloc(sizeof(btSortedOverlappingPairCache),16);
+ m_pairCache = new(ptr) btSortedOverlappingPairCache();
m_ownsPairCache = true;
}
--- src/BulletCollision/CollisionDispatch/btSimulationIslandManager_old.cpp 2016-10-12 16:39:48.950992424 -0400
+++ src/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp 2016-10-12 16:39:36.938992000 -0400
@@ -192,10 +192,40 @@
class btPersistentManifoldSortPredicate
{
public:
+ const btCollisionObjectArray& collisionObjects;
+
+ btPersistentManifoldSortPredicate(btCollisionObjectArray& b): collisionObjects(b)
+ {
+
+ }
+
+ int body_id(const btCollisionObject* obj) const
+ {
+ int id=0;
+ while(true)
+ {
+ if(obj==collisionObjects[id])
+ return id;
+ id++;
+ }
+ }
SIMD_FORCE_INLINE bool operator() ( const btPersistentManifold* lhs, const btPersistentManifold* rhs ) const
{
- return getIslandId(lhs) < getIslandId(rhs);
+
+ if(body_id(lhs->getBody0())<body_id(rhs->getBody0()))
+ return true;
+ else if(body_id(lhs->getBody0())>body_id(rhs->getBody0()))
+ return false;
+ else
+ {
+ if(body_id(lhs->getBody1())<body_id(rhs->getBody1()))
+ return true;
+ else
+ return false;
+ }
+
+ // return getIslandId(lhs) < getIslandId(rhs);
}
};
@@ -379,7 +409,7 @@
//tried a radix sort, but quicksort/heapsort seems still faster
//@todo rewrite island management
- m_islandmanifold.quickSort(btPersistentManifoldSortPredicate());
+ m_islandmanifold.quickSort(btPersistentManifoldSortPredicate(collisionObjects));
//m_islandmanifold.heapSort(btPersistentManifoldSortPredicate());
//now process all active islands (sets of manifolds for now)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment