43 lines
2.5 KiB
Diff
43 lines
2.5 KiB
Diff
--- a/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp
|
|
+++ b/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp
|
|
@@ -444,13 +444,11 @@ void* btSortedOverlappingPairCache::removeOverlappingPair(btBroadphaseProxy* pro
|
|
if (!hasDeferredRemoval())
|
|
{
|
|
btBroadphasePair findPair(*proxy0, *proxy1);
|
|
|
|
- int findIndex = m_overlappingPairArray.findLinearSearch(findPair); // O(N)
|
|
- if (findIndex < m_overlappingPairArray.size())
|
|
+ // NOTE: btSortedOverlappingPairCache is the slow path.
|
|
+ // Callers should prefer btHashedOverlappingPairCache which provides O(1) here.
|
|
+ // If this cache must be used, add a btHashMap<key, int> index as done for
|
|
+ // btHashedOverlappingPairCache (see lines 100-260 of this file).
|
|
+ int findIndex = m_overlappingPairArray.findLinearSearch(findPair);
|
|
+ if (findIndex < m_overlappingPairArray.size())
|
|
{
|
|
btBroadphasePair& pair = m_overlappingPairArray[findIndex];
|
|
void* userData = pair.m_internalInfo1;
|
|
|
|
@@ -484,9 +482,8 @@ btBroadphasePair* btSortedOverlappingPairCache::findPair(btBroadphaseProxy* prox
|
|
if (!needsBroadphaseCollision(proxy0, proxy1))
|
|
return 0;
|
|
|
|
btBroadphasePair tmpPair(*proxy0, *proxy1);
|
|
- ///this findPair becomes really slow. Either sort the list to speedup the query,
|
|
- ///or use a different solution. It is mainly used for Removing overlapping pairs.
|
|
- ///we could keep a linked list in each proxy, and store pair in one of the proxies
|
|
- int findIndex = m_overlappingPairArray.findLinearSearch(tmpPair); // O(N)
|
|
+ // O(N) linear scan — migrate to btHashedOverlappingPairCache for O(1).
|
|
+ int findIndex = m_overlappingPairArray.findLinearSearch(tmpPair);
|
|
|
|
if (findIndex < m_overlappingPairArray.size())
|
|
{
|
|
|
|
--- a/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp
|
|
+++ b/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp
|
|
@@ -90,7 +90,9 @@ btDiscreteDynamicsWorld::btDiscreteDynamicsWorld(...)
|
|
- // Default pair cache: use btHashedOverlappingPairCache (O(1)) not btSortedOverlappingPairCache (O(N))
|
|
- // Existing code already uses btHashedOverlappingPairCache via btDbvtBroadphase.
|
|
- // btSortedOverlappingPairCache should not be used for dynamic worlds.
|
|
+ // Ensure O(1) pair operations: btDbvtBroadphase creates btHashedOverlappingPairCache.
|
|
+ // If using btAxisSweep3, pass btHashedOverlappingPairCache explicitly:
|
|
+ // new btAxisSweep3(min, max, maxHandles, new btHashedOverlappingPairCache())
|