diff --git a/src/BulletCollision/BroadphaseCollision/btAxisSweep3.h b/src/BulletCollision/BroadphaseCollision/btAxisSweep3.h index 5a09c8747..494a37966 100644 --- a/src/BulletCollision/BroadphaseCollision/btAxisSweep3.h +++ b/src/BulletCollision/BroadphaseCollision/btAxisSweep3.h @@ -464,7 +464,7 @@ template void btAxisSweep3Internal::calculateOverlappingPairs(btDispatcher* dispatcher) { - if (m_ownsPairCache && m_pairCache->hasDeferredRemoval()) + if (m_pairCache->hasDeferredRemoval()) { btBroadphasePairArray& overlappingPairArray = m_pairCache->getOverlappingPairArray(); diff --git a/src/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.cpp b/src/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.cpp index f9acbf949..fa96e19cc 100644 --- a/src/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.cpp +++ b/src/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.cpp @@ -64,6 +64,7 @@ btMultiSapBroadphase::~btMultiSapBroadphase() { if (m_ownsPairCache) { + m_overlappingPairs->~btOverlappingPairCache(); btAlignedFree(m_overlappingPairs); } } @@ -115,81 +116,83 @@ void btMultiSapBroadphase::calculateOverlappingPairs(btDispatcher* dispatcher) { m_simpleBroadphase->calculateOverlappingPairs(dispatcher); -#ifndef USE_HASH_PAIRCACHE - - btBroadphasePairArray& overlappingPairArray = m_overlappingPairs->getOverlappingPairArray(); - - //perform a sort, to find duplicates and to sort 'invalid' pairs to the end - overlappingPairArray.heapSort(btBroadphasePairSortPredicate()); - - overlappingPairArray.resize(overlappingPairArray.size() - m_invalidPair); - m_invalidPair = 0; - - - btBroadphasePair previousPair; - previousPair.m_pProxy0 = 0; - previousPair.m_pProxy1 = 0; - previousPair.m_algorithm = 0; - - int i; - - for (i=0;ihasDeferredRemoval()) { - - btBroadphasePair& pair = overlappingPairArray[i]; - bool isDuplicate = (pair == previousPair); - previousPair = pair; + btBroadphasePairArray& overlappingPairArray = m_overlappingPairs->getOverlappingPairArray(); + + //perform a sort, to find duplicates and to sort 'invalid' pairs to the end + overlappingPairArray.heapSort(btBroadphasePairSortPredicate()); - bool needsRemoval = false; + overlappingPairArray.resize(overlappingPairArray.size() - m_invalidPair); + m_invalidPair = 0; - if (!isDuplicate) + + btBroadphasePair previousPair; + previousPair.m_pProxy0 = 0; + previousPair.m_pProxy1 = 0; + previousPair.m_algorithm = 0; + + int i; + + for (i=0;iprocessOverlap(pair); + bool hasOverlap = testAabbOverlap(pair.m_pProxy0,pair.m_pProxy1); + + if (hasOverlap) + { + needsRemoval = false;//callback->processOverlap(pair); + } else + { + needsRemoval = true; + } } else { + //remove duplicate needsRemoval = true; + //should have no algorithm + btAssert(!pair.m_algorithm); } - } else - { - //remove duplicate - needsRemoval = true; - //should have no algorithm - btAssert(!pair.m_algorithm); + + if (needsRemoval) + { + m_overlappingPairs->cleanOverlappingPair(pair,dispatcher); + + // m_overlappingPairArray.swap(i,m_overlappingPairArray.size()-1); + // m_overlappingPairArray.pop_back(); + pair.m_pProxy0 = 0; + pair.m_pProxy1 = 0; + m_invalidPair++; + gOverlappingPairs--; + } + } - - if (needsRemoval) - { - m_overlappingPairs->cleanOverlappingPair(pair,dispatcher); - // m_overlappingPairArray.swap(i,m_overlappingPairArray.size()-1); - // m_overlappingPairArray.pop_back(); - pair.m_pProxy0 = 0; - pair.m_pProxy1 = 0; - m_invalidPair++; - gOverlappingPairs--; - } - + ///if you don't like to skip the invalid pairs in the array, execute following code: + #define CLEAN_INVALID_PAIRS 1 + #ifdef CLEAN_INVALID_PAIRS + + //perform a sort, to sort 'invalid' pairs to the end + overlappingPairArray.heapSort(btBroadphasePairSortPredicate()); + + overlappingPairArray.resize(overlappingPairArray.size() - m_invalidPair); + m_invalidPair = 0; + #endif//CLEAN_INVALID_PAIRS + } -///if you don't like to skip the invalid pairs in the array, execute following code: -#define CLEAN_INVALID_PAIRS 1 -#ifdef CLEAN_INVALID_PAIRS - - //perform a sort, to sort 'invalid' pairs to the end - overlappingPairArray.heapSort(btBroadphasePairSortPredicate()); - - overlappingPairArray.resize(overlappingPairArray.size() - m_invalidPair); - m_invalidPair = 0; -#endif//CLEAN_INVALID_PAIRS - -#endif //USE_HASH_PAIRCACHE - } diff --git a/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp b/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp index 560b7db6f..d5daa5f1a 100644 --- a/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp +++ b/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp @@ -204,12 +204,13 @@ void btSimpleBroadphase::calculateOverlappingPairs(btDispatcher* dispatcher) } } else { - #ifdef USE_HASH_PAIRCACHE + if (!m_pairCache->hasDeferredRemoval()) + { if ( m_pairCache->findPair(proxy0,proxy1)) { m_pairCache->removeOverlappingPair(proxy0,proxy1,dispatcher); } - #endif //USE_HASH_PAIRCACHE + } } } @@ -220,9 +221,7 @@ void btSimpleBroadphase::calculateOverlappingPairs(btDispatcher* dispatcher) } - #ifndef USE_HASH_PAIRCACHE - - if (m_ownsPairCache) + if (m_ownsPairCache && m_pairCache->hasDeferredRemoval()) { btBroadphasePairArray& overlappingPairArray = m_pairCache->getOverlappingPairArray(); @@ -296,7 +295,6 @@ void btSimpleBroadphase::calculateOverlappingPairs(btDispatcher* dispatcher) #endif//CLEAN_INVALID_PAIRS } - #endif //USE_HASH_PAIRCACHE } }