void* b3SortedOverlappingPairCache::removeOverlappingPair(int proxy0,int proxy1, b3Dispatcher* dispatcher ) { if (!hasDeferredRemoval()) { b3BroadphasePair findPair(proxy0,proxy1); int findIndex = m_overlappingPairArray.findLinearSearch(findPair); if (findIndex < m_overlappingPairArray.size()) { b3g_overlappingPairs--; b3BroadphasePair& pair = m_overlappingPairArray[findIndex]; cleanOverlappingPair(pair,dispatcher); //if (m_ghostPairCallback) // m_ghostPairCallback->removeOverlappingPair(proxy0, proxy1,dispatcher); m_overlappingPairArray.swap(findIndex,m_overlappingPairArray.capacity()-1); m_overlappingPairArray.pop_back(); return 0; } } return 0; }
void btSortedOverlappingPairCache::processAllOverlappingPairs(btOverlapCallback* callback,btDispatcher* dispatcher) { int i; for (i=0;i<m_overlappingPairArray.size();) { btBroadphasePair* pair = &m_overlappingPairArray[i]; if (callback->processOverlap(*pair)) { cleanOverlappingPair(*pair,dispatcher); pair->m_pProxy0 = 0; pair->m_pProxy1 = 0; m_overlappingPairArray.swap(i,m_overlappingPairArray.size()-1); m_overlappingPairArray.pop_back(); } else { i++; } } }
void b3SortedOverlappingPairCache::processAllOverlappingPairs(b3OverlapCallback* callback,b3Dispatcher* dispatcher) { int i; for (i=0;i<m_overlappingPairArray.size();) { b3BroadphasePair* pair = &m_overlappingPairArray[i]; if (callback->processOverlap(*pair)) { cleanOverlappingPair(*pair,dispatcher); pair->x = -1; pair->y = -1; m_overlappingPairArray.swap(i,m_overlappingPairArray.size()-1); m_overlappingPairArray.pop_back(); b3g_overlappingPairs--; } else { i++; } } }
void* btSortedOverlappingPairCache::removeOverlappingPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1, btDispatcher* dispatcher ) { if (!hasDeferredRemoval()) { btBroadphasePair findPair(*proxy0,*proxy1); int findIndex = m_overlappingPairArray.findLinearSearch(findPair); if (findIndex < m_overlappingPairArray.size()) { btBroadphasePair& pair = m_overlappingPairArray[findIndex]; void* userData = pair.m_internalInfo1; cleanOverlappingPair(pair,dispatcher); if (m_ghostPairCallback) m_ghostPairCallback->removeOverlappingPair(proxy0, proxy1,dispatcher); m_overlappingPairArray.swap(findIndex,m_overlappingPairArray.capacity()-1); m_overlappingPairArray.pop_back(); return userData; } } return 0; }
void* btHashedOverlappingPairCache::removeOverlappingPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1,btDispatcher* dispatcher) { gRemovePairs++; if(proxy0->m_uniqueId>proxy1->m_uniqueId) btSwap(proxy0,proxy1); int proxyId1 = proxy0->getUid(); int proxyId2 = proxy1->getUid(); /*if (proxyId1 > proxyId2) btSwap(proxyId1, proxyId2);*/ int hash = static_cast<int>(getHash(static_cast<unsigned int>(proxyId1),static_cast<unsigned int>(proxyId2)) & (m_overlappingPairArray.capacity()-1)); btBroadphasePair* pair = internalFindPair(proxy0, proxy1, hash); if (pair == NULL) { return 0; } cleanOverlappingPair(*pair,dispatcher); void* userData = pair->m_internalInfo1; btAssert(pair->m_pProxy0->getUid() == proxyId1); btAssert(pair->m_pProxy1->getUid() == proxyId2); int pairIndex = int(pair - &m_overlappingPairArray[0]); btAssert(pairIndex < m_overlappingPairArray.size()); // Remove the pair from the hash table. int index = m_hashTable[hash]; btAssert(index != BT_NULL_PAIR); int previous = BT_NULL_PAIR; while (index != pairIndex) { previous = index; index = m_next[index]; } if (previous != BT_NULL_PAIR) { btAssert(m_next[previous] == pairIndex); m_next[previous] = m_next[pairIndex]; } else { m_hashTable[hash] = m_next[pairIndex]; } // We now move the last pair into spot of the // pair being removed. We need to fix the hash // table indices to support the move. int lastPairIndex = m_overlappingPairArray.size() - 1; if (m_ghostPairCallback) m_ghostPairCallback->removeOverlappingPair(proxy0, proxy1,dispatcher); // If the removed pair is the last pair, we are done. if (lastPairIndex == pairIndex) { m_overlappingPairArray.pop_back(); return userData; } // Remove the last pair from the hash table. const btBroadphasePair* last = &m_overlappingPairArray[lastPairIndex]; /* missing swap here too, Nat. */ int lastHash = static_cast<int>(getHash(static_cast<unsigned int>(last->m_pProxy0->getUid()), static_cast<unsigned int>(last->m_pProxy1->getUid())) & (m_overlappingPairArray.capacity()-1)); index = m_hashTable[lastHash]; btAssert(index != BT_NULL_PAIR); previous = BT_NULL_PAIR; while (index != lastPairIndex) { previous = index; index = m_next[index]; } if (previous != BT_NULL_PAIR) { btAssert(m_next[previous] == lastPairIndex); m_next[previous] = m_next[lastPairIndex]; } else { m_hashTable[lastHash] = m_next[lastPairIndex]; } // Copy the last pair into the remove pair's spot. m_overlappingPairArray[pairIndex] = m_overlappingPairArray[lastPairIndex]; // Insert the last pair into the hash table m_next[pairIndex] = m_hashTable[lastHash]; m_hashTable[lastHash] = pairIndex; m_overlappingPairArray.pop_back(); return userData; }