public virtual bool ProcessOverlap(ref BroadphasePair pair) { SimpleBroadphaseProxy proxy0 = (SimpleBroadphaseProxy)(pair.m_pProxy0); SimpleBroadphaseProxy proxy1 = (SimpleBroadphaseProxy)(pair.m_pProxy1); return((m_targetProxy == proxy0 || m_targetProxy == proxy1)); }
private void GrowTables() { int newCapacity = m_overlappingPairArray.Capacity; if (m_hashTable.Capacity < newCapacity) { int curHashTableSize = m_hashTable.Count; m_hashTable.Capacity = newCapacity; m_next.Capacity = newCapacity; for (int i = 0; i < newCapacity; ++i) { m_hashTable[i] = BT_NULL_PAIR; } for (int i = 0; i < newCapacity; ++i) { m_next[i] = BT_NULL_PAIR; } for (int i = 0; i < curHashTableSize; i++) { BroadphasePair pair = m_overlappingPairArray[i]; int proxyId1 = pair.m_pProxy0.GetUid(); int proxyId2 = pair.m_pProxy1.GetUid(); /*if (proxyId1 > proxyId2) * btSwap(proxyId1, proxyId2);*/ int hashValue = (int)(GetHash((uint)(proxyId1), (uint)(proxyId2)) & (m_overlappingPairArray.Capacity - 1)); // New hash value with new mask m_next[i] = m_hashTable[hashValue]; m_hashTable[hashValue] = i; } int ibreak = 0; } }
public Object RemoveOverlappingPair(BroadphaseProxy proxy0, BroadphaseProxy proxy1, IDispatcher dispatcher) { if (!HasDeferredRemoval()) { BroadphasePair findPair = new BroadphasePair(proxy0, proxy1); int findIndex = m_overlappingPairArray.IndexOf(findPair); if (findIndex >= 0 && findIndex < m_overlappingPairArray.Count) { OverlappingPairCacheGlobals.gOverlappingPairs--; BroadphasePair pair = m_overlappingPairArray[findIndex]; Object userData = pair.m_internalInfo1; CleanOverlappingPair(pair, dispatcher); if (m_ghostPairCallback != null) { m_ghostPairCallback.RemoveOverlappingPair(proxy0, proxy1, dispatcher); } //BroadphasePair temp = m_overlappingPairArray[findIndex]; //m_overlappingPairArray[findIndex] = m_overlappingPairArray[m_overlappingPairArray.Count-1]; //m_overlappingPairArray[m_overlappingPairArray.Count-1] = temp; m_overlappingPairArray.RemoveAtQuick(findIndex); return(userData); } } return(null); }
public BroadphasePair(ref BroadphasePair other) { m_pProxy0 = other.m_pProxy0; m_pProxy1 = other.m_pProxy1; m_algorithm = other.m_algorithm; m_internalInfo1 = other.m_internalInfo1; }
public void CleanOverlappingPair(BroadphasePair pair, IDispatcher dispatcher) { if (pair.m_algorithm != null) { dispatcher.FreeCollisionAlgorithm(pair.m_algorithm); pair.m_algorithm = null; } }
public virtual bool ProcessOverlap(BroadphasePair pair) { if (pair != null && ((pair.m_pProxy0 == m_cleanProxy) || (pair.m_pProxy1 == m_cleanProxy))) { m_pairCache.CleanOverlappingPair(pair, m_dispatcher); } return(false); }
public void CleanOverlappingPair(BroadphasePair pair, IDispatcher dispatcher) { if (pair.m_algorithm != null) { { dispatcher.FreeCollisionAlgorithm(pair.m_algorithm); pair.m_algorithm = null; OverlappingPairCacheGlobals.gRemovePairs--; } } }
public override bool Equals(object obj) { if (this == obj) { return(true); } else { if (obj is BroadphasePair) { BroadphasePair that = (BroadphasePair)obj; return(m_pProxy0 == that.m_pProxy0 && m_pProxy1 == that.m_pProxy1); } } return(false); }
public BroadphasePair FindPair(BroadphaseProxy proxy0, BroadphaseProxy proxy1) { if (!NeedsBroadphaseCollision(proxy0, proxy1)) { return(null); } BroadphasePair tmpPair = new BroadphasePair(proxy0, proxy1); int index = m_overlappingPairArray.IndexOf(tmpPair); if (index != -1) { return(m_overlappingPairArray[index]); } return(null); }
public virtual void ProcessAllOverlappingPairs(IOverlapCallback callback, IDispatcher dispatcher) { for (int i = 0; i < m_overlappingPairArray.Count;) { BroadphasePair pair = m_overlappingPairArray[i]; if (callback.ProcessOverlap(pair)) { CleanOverlappingPair(pair, dispatcher); pair.m_pProxy0 = null; pair.m_pProxy1 = null; m_overlappingPairArray.RemoveAtQuick(i); OverlappingPairCacheGlobals.gOverlappingPairs--; } else { i++; } } }
public void NearCallback(BroadphasePair collisionPair, CollisionDispatcher dispatcher, DispatcherInfo dispatchInfo) { CollisionObject colObj0 = collisionPair.m_pProxy0.GetClientObject() as CollisionObject; CollisionObject colObj1 = collisionPair.m_pProxy1.GetClientObject() as CollisionObject; if (dispatcher.NeedsCollision(colObj0, colObj1)) { //dispatcher will keep algorithms persistent in the collision pair if (collisionPair.m_algorithm == null) { collisionPair.m_algorithm = dispatcher.FindAlgorithm(colObj0, colObj1, null); } if (collisionPair.m_algorithm != null) { ManifoldResult contactPointResult = dispatcher.GetNewManifoldResult(colObj0, colObj1); if (dispatchInfo.GetDispatchFunc() == DispatchFunc.DISPATCH_DISCRETE) { //discrete collision detection query collisionPair.m_algorithm.ProcessCollision(colObj0, colObj1, dispatchInfo, contactPointResult); } else { //continuous collision detection query, time of impact (toi) float toi = collisionPair.m_algorithm.CalculateTimeOfImpact(colObj0, colObj1, dispatchInfo, contactPointResult); if (dispatchInfo.GetTimeOfImpact() > toi) { dispatchInfo.SetTimeOfImpact(toi); } } #if DEBUG if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugDispatcher) { BulletGlobals.g_streamWriter.WriteLine("NearCallback[{0}][{1}][{2}]", contactPointResult.GetBody0Internal().GetUserPointer(), contactPointResult.GetBody1Internal().GetUserPointer(), contactPointResult.GetPersistentManifold().GetNumContacts()); } #endif dispatcher.FreeManifoldResult(contactPointResult); } } }
public static bool IsLessThen(BroadphasePair a, BroadphasePair b) { int uidA0 = a.m_pProxy0 != null?a.m_pProxy0.GetUid() : -1; int uidB0 = b.m_pProxy0 != null?b.m_pProxy0.GetUid() : -1; if (uidA0 > uidB0) { return(true); } int uidA1 = a.m_pProxy1 != null?a.m_pProxy1.GetUid() : -1; int uidB1 = b.m_pProxy1 != null?b.m_pProxy1.GetUid() : -1; int colAlgIdA = a.m_algorithm != null ? a.m_algorithm.colAgorithmId : 0; int colAlgIdB = b.m_algorithm != null ? b.m_algorithm.colAgorithmId : 0; return((a.m_pProxy0 == b.m_pProxy0 && uidA1 > uidB1) || (a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 == b.m_pProxy1) && colAlgIdA > colAlgIdB); }
public void FindUnions(IDispatcher dispatcher, CollisionWorld collisionWorld) { ObjectArray <BroadphasePair> list = collisionWorld.GetPairCache().GetOverlappingPairArray(); int length = list.Count; if (length > 0) { BroadphasePair[] rawList = list.GetRawArray(); for (int i = 0; i < length; ++i) { BroadphasePair collisionPair = rawList[i]; CollisionObject colObj0 = collisionPair.m_pProxy0.m_clientObject as CollisionObject; CollisionObject colObj1 = collisionPair.m_pProxy1.m_clientObject as CollisionObject; if (((colObj0 != null) && ((colObj0).MergesSimulationIslands())) && ((colObj1 != null) && ((colObj1).MergesSimulationIslands()))) { m_unionFind.Unite((colObj0).GetIslandTag(), (colObj1).GetIslandTag()); } } } }
public BroadphasePair AddOverlappingPair(BroadphaseProxy proxy0, BroadphaseProxy proxy1) { //don't add overlap with own Debug.Assert(proxy0 != proxy1); if (!NeedsBroadphaseCollision(proxy0, proxy1)) { return(null); } BroadphasePair pair = new BroadphasePair(proxy0, proxy1); m_overlappingPairArray.Add(pair); OverlappingPairCacheGlobals.gOverlappingPairs++; OverlappingPairCacheGlobals.gAddedPairs++; if (m_ghostPairCallback != null) { m_ghostPairCallback.AddOverlappingPair(proxy0, proxy1); } return(pair); }
public virtual void ProcessAllOverlappingPairs(IOverlapCallback callback, IDispatcher dispatcher) { #if DEBUG if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugPairCache) { BulletGlobals.g_streamWriter.WriteLine("HPC:ProcessAllOverlappingPairs overlap[{0}].", m_overlappingPairArray.Count); } #endif for (int i = 0; i < m_overlappingPairArray.Count;) { BroadphasePair pair = m_overlappingPairArray[i]; if (callback.ProcessOverlap(pair)) { RemoveOverlappingPair(pair.m_pProxy0, pair.m_pProxy1, dispatcher); OverlappingPairCacheGlobals.gOverlappingPairs--; } else { i++; } } }
public virtual bool ProcessOverlap(BroadphasePair pair) { return(pair != null && ((pair.m_pProxy0 == m_obsoleteProxy) || (pair.m_pProxy1 == m_obsoleteProxy))); }
public virtual void CleanOverlappingPair(BroadphasePair pair, IDispatcher disaptcher) { }
public virtual void CalculateOverlappingPairs(IDispatcher dispatcher) { #if DEBUG if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugBroadphase) { BulletGlobals.g_streamWriter.WriteLine("simple calculateOverlappingPairs"); } #endif //first check for new overlapping pairs if (m_numHandles > 0) { int new_largest_index = -1; for (int i = 0; i <= m_LastHandleIndex; i++) { SimpleBroadphaseProxy proxy0 = m_pHandles[i]; if (proxy0.GetClientObject() == null) { continue; } new_largest_index = i; for (int j = i + 1; j <= m_LastHandleIndex; j++) { SimpleBroadphaseProxy proxy1 = m_pHandles[j]; //btAssert(proxy0 != proxy1); if (proxy1.GetClientObject() == null) { continue; } if (AabbOverlap(proxy0, proxy1)) { if (m_pairCache.FindPair(proxy0, proxy1) == null) { m_pairCache.AddOverlappingPair(proxy0, proxy1); } } else { if (!m_pairCache.HasDeferredRemoval()) { if (m_pairCache.FindPair(proxy0, proxy1) != null) { m_pairCache.RemoveOverlappingPair(proxy0, proxy1, dispatcher); } } } } } m_LastHandleIndex = new_largest_index; if (m_ownsPairCache && m_pairCache.HasDeferredRemoval()) { IList <BroadphasePair> overlappingPairArray = m_pairCache.GetOverlappingPairArray(); //perform a sort, to find duplicates and to sort 'invalid' pairs to the end ((List <BroadphasePair>)overlappingPairArray).Sort(); //overlappingPairArray.Capacity = (overlappingPairArray.Count - m_invalidPair); m_invalidPair = 0; BroadphasePair previousPair = new BroadphasePair(); for (int i = 0; i < overlappingPairArray.Count; i++) { BroadphasePair pair = overlappingPairArray[i]; bool isDuplicate = (pair == previousPair); previousPair = pair; bool needsRemoval = false; if (!isDuplicate) { 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); } if (needsRemoval) { m_pairCache.CleanOverlappingPair(pair, dispatcher); // m_overlappingPairArray.swap(i,m_overlappingPairArray.size()-1); // m_overlappingPairArray.pop_back(); pair.m_pProxy0 = null; pair.m_pProxy1 = null; m_invalidPair++; BulletGlobals.gOverlappingPairs--; } } ///if you don't like to skip the invalid pairs in the array, execute following code: #if CLEAN_INVALID_PAIRS //perform a sort, to sort 'invalid' pairs to the end //overlappingPairArray.quickSort(new BroadphasePairSortPredicate()); ((List <BroadphasePair>)overlappingPairArray).Sort(); //overlappingPairArray.Capacity = overlappingPairArray.Count - m_invalidPair; m_invalidPair = 0; #endif//CLEAN_INVALID_PAIRS } } }
public virtual bool ProcessOverlap(BroadphasePair pair) { return(!SimpleBroadphase.AabbOverlap((SimpleBroadphaseProxy)(pair.m_pProxy0), (SimpleBroadphaseProxy)(pair.m_pProxy1))); }
private bool EqualsPair(BroadphasePair pair, int proxyId1, int proxyId2) { return(pair.m_pProxy0.m_uniqueId == proxyId1 && pair.m_pProxy1.m_uniqueId == proxyId2); }
public void Collide(IDispatcher dispatcher) { BulletGlobals.StartProfile("BroadphaseCollide"); //SPC(m_profiling.m_total); /* optimize */ m_sets[0].OptimizeIncremental(1 + (m_sets[0].m_leaves * m_dupdates) / 100); if (m_fixedleft > 0) { int count = 1 + (m_sets[1].m_leaves * m_fupdates) / 100; m_sets[1].OptimizeIncremental(1 + (m_sets[1].m_leaves * m_fupdates) / 100); m_fixedleft = Math.Max(0, m_fixedleft - count); } /* dynamic . fixed set */ m_stageCurrent = (m_stageCurrent + 1) % STAGECOUNT; DbvtProxy current = m_stageRoots[m_stageCurrent]; if (current != null) { DbvtTreeCollider collider = BulletGlobals.DbvtTreeColliderPool.Get(); collider.Initialize(this); do { DbvtProxy next = current.links[1]; ListRemove(current, ref m_stageRoots[current.stage]); ListAppend(current, ref m_stageRoots[STAGECOUNT]); #if DBVT_BP_ACCURATESLEEPING m_paircache.removeOverlappingPairsContainingProxy(current, dispatcher); collider.proxy = current; btDbvt::collideTV(m_sets[0].m_root, current.aabb, collider); btDbvt::collideTV(m_sets[1].m_root, current.aabb, collider); #endif m_sets[0].Remove(current.leaf); DbvtAabbMm curAabb = DbvtAabbMm.FromMM(ref current.m_aabbMin, ref current.m_aabbMax); current.leaf = m_sets[1].Insert(ref curAabb, current); current.stage = STAGECOUNT; current = next; } while (current != null); m_fixedleft = m_sets[1].m_leaves; BulletGlobals.DbvtTreeColliderPool.Free(collider); m_needcleanup = true; } /* collide dynamics */ { DbvtTreeCollider collider = BulletGlobals.DbvtTreeColliderPool.Get(); collider.Initialize(this); if (m_deferedcollide) { //Stopwatch fdCollideStopwatch = new Stopwatch(); //fdCollideStopwatch.Start(); //SPC(m_profiling.m_fdcollide); Dbvt.CollideTTpersistentStack(m_sets[0].m_root, m_sets[1].m_root, collider); //fdCollideStopwatch.Stop(); //m_profiling.m_fdcollide += (ulong)fdCollideStopwatch.ElapsedMilliseconds; } if (m_deferedcollide) { //Stopwatch ddCollideStopwatch = new Stopwatch(); //ddCollideStopwatch.Start(); //SPC(m_profiling.m_ddcollide); Dbvt.CollideTTpersistentStack(m_sets[0].m_root, m_sets[0].m_root, collider); //ddCollideStopwatch.Stop(); //m_profiling.m_ddcollide += (ulong)ddCollideStopwatch.ElapsedMilliseconds; } BulletGlobals.DbvtTreeColliderPool.Free(collider); } /* clean up */ if (m_needcleanup) { Stopwatch cleanupStopwatch = new Stopwatch(); cleanupStopwatch.Start(); //SPC(m_profiling.m_cleanup); IList <BroadphasePair> pairs = m_paircache.GetOverlappingPairArray(); if (pairs.Count > 0) { int ni = Math.Min(pairs.Count, Math.Max(m_newpairs, (pairs.Count * m_cupdates) / 100)); for (int i = 0; i < ni; ++i) { BroadphasePair p = pairs[(m_cid + i) % pairs.Count]; DbvtProxy pa = p.m_pProxy0 as DbvtProxy; DbvtProxy pb = p.m_pProxy1 as DbvtProxy; if (!DbvtAabbMm.Intersect(ref pa.leaf.volume, ref pb.leaf.volume)) { #if DBVT_BP_SORTPAIRS if (pa.m_uniqueId > pb.m_uniqueId) { btSwap(pa, pb); } #endif m_paircache.RemoveOverlappingPair(pa, pb, dispatcher); --ni; --i; } } if (pairs.Count > 0) { m_cid = (m_cid + ni) % pairs.Count; } else { m_cid = 0; } } cleanupStopwatch.Stop(); //m_profiling.m_cleanup += (ulong)cleanupStopwatch.ElapsedMilliseconds; } ++m_pid; m_newpairs = 1; m_needcleanup = false; if (m_updates_call > 0) { m_updates_ratio = m_updates_done / (float)m_updates_call; } else { m_updates_ratio = 0; } m_updates_done /= 2; m_updates_call /= 2; BulletGlobals.StopProfile(); }
public void PerformDeferredRemoval(IDispatcher dispatcher) { if (m_paircache.HasDeferredRemoval()) { ObjectArray <BroadphasePair> overlappingPairArray = m_paircache.GetOverlappingPairArray(); //perform a sort, to find duplicates and to sort 'invalid' pairs to the end overlappingPairArray.QuickSort(new BroadphasePairQuickSort()); int invalidPair = 0; int i; BroadphasePair previousPair = new BroadphasePair(); for (i = 0; i < overlappingPairArray.Count; i++) { BroadphasePair pair = overlappingPairArray[i]; bool isDuplicate = (pair == previousPair); previousPair = pair; bool needsRemoval = false; if (!isDuplicate) { //important to perform AABB check that is consistent with the broadphase DbvtProxy pa = pair.m_pProxy0 as DbvtProxy; DbvtProxy pb = pair.m_pProxy1 as DbvtProxy; bool hasOverlap = DbvtAabbMm.Intersect(ref pa.leaf.volume, ref pb.leaf.volume); if (hasOverlap) { needsRemoval = false; } else { needsRemoval = true; } } else { //remove duplicate needsRemoval = true; //should have no algorithm Debug.Assert(pair.m_algorithm != null); } if (needsRemoval) { m_paircache.CleanOverlappingPair(pair, dispatcher); pair.m_pProxy0 = null; pair.m_pProxy1 = null; invalidPair++; } } if (invalidPair > 0) { if (invalidPair < overlappingPairArray.Count) { int ibreak = 0; } //perform a sort, to sort 'invalid' pairs to the end overlappingPairArray.QuickSort(new BroadphasePairQuickSort()); //overlappingPairArray.resize(overlappingPairArray.size() - invalidPair); overlappingPairArray.Truncate(invalidPair); } } }
public virtual void CalculateOverlappingPairs(IDispatcher dispatcher) { if (m_pairCache.HasDeferredRemoval()) { ObjectArray <BroadphasePair> overlappingPairArray = m_pairCache.GetOverlappingPairArray(); //perform a sort, to find duplicates and to sort 'invalid' pairs to the end overlappingPairArray.QuickSort(new BroadphasePairQuickSort()); //overlappingPairArray.resize(overlappingPairArray.size() - m_invalidPair); m_invalidPair = 0; BroadphasePair previousPair = new BroadphasePair(); for (int i = 0; i < overlappingPairArray.Count; i++) { BroadphasePair pair = overlappingPairArray[i]; bool isDuplicate = pair.Equals(previousPair); // MAN - not sure if this should be a deep copy or not... previousPair = pair; bool needsRemoval = false; if (!isDuplicate) { ///important to use an AABB test that is consistent with the broadphase 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 Debug.Assert(pair.m_algorithm == null); } if (needsRemoval) { m_pairCache.CleanOverlappingPair(pair, dispatcher); // m_overlappingPairArray.swap(i,m_overlappingPairArray.size()-1); // m_overlappingPairArray.pop_back(); pair.m_pProxy0 = null; pair.m_pProxy1 = null; m_invalidPair++; OverlappingPairCacheGlobals.gOverlappingPairs--; } } ///if you don't like to skip the invalid pairs in the array, execute following code: #if CLEAN_INVALID_PAIRS overlappingPairArray.QuickSort(new BroadphasePairQuickSort()); overlappingPairArray.Resize(overlappingPairArray.Count - m_invalidPair); m_invalidPair = 0; #endif//CLEAN_INVALID_PAIRS //printf("overlappingPairArray.size()=%d\n",overlappingPairArray.size()); } }
///calculateOverlappingPairs is optional: incremental algorithms (sweep and prune) might do it during the set aabb public void CalculateOverlappingPairs(IDispatcher dispatcher) { if (!m_stopUpdating && GetOverlappingPairCache().HasDeferredRemoval()) { IList <BroadphasePair> overlappingPairArray = GetOverlappingPairCache().GetOverlappingPairArray(); ((List <BroadphasePair>)overlappingPairArray).Sort(); m_invalidPair = 0; int i; BroadphasePair previousPair = new BroadphasePair(); previousPair.m_pProxy0 = null; previousPair.m_pProxy1 = null; previousPair.m_algorithm = null; for (i = 0; i < overlappingPairArray.Count; i++) { BroadphasePair pair = overlappingPairArray[i]; MultiSapProxy aProxy0 = pair.m_pProxy0 != null ? (MultiSapProxy)pair.m_pProxy0.m_multiSapParentProxy : null; MultiSapProxy aProxy1 = pair.m_pProxy1 != null ? (MultiSapProxy)pair.m_pProxy1.m_multiSapParentProxy : null; MultiSapProxy bProxy0 = previousPair.m_pProxy0 != null ? (MultiSapProxy)previousPair.m_pProxy0.m_multiSapParentProxy : null; MultiSapProxy bProxy1 = previousPair.m_pProxy1 != null ? (MultiSapProxy)previousPair.m_pProxy1.m_multiSapParentProxy : null; bool isDuplicate = (aProxy0 == bProxy0) && (aProxy1 == bProxy1); previousPair = pair; bool needsRemoval = false; if (!isDuplicate) { 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 Debug.Assert(pair.m_algorithm == null); } if (needsRemoval) { GetOverlappingPairCache().CleanOverlappingPair(pair, dispatcher); // m_overlappingPairArray.swap(i,m_overlappingPairArray.size()-1); // m_overlappingPairArray.pop_back(); pair.m_pProxy0 = null; pair.m_pProxy1 = null; m_invalidPair++; BulletGlobals.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(btMultiSapBroadphasePairSortPredicate()); // overlappingPairArray.quickSort(btMultiSapBroadphasePairSortPredicate()); // overlappingPairArray.resize(overlappingPairArray.size() - m_invalidPair); // m_invalidPair = 0; //#endif//CLEAN_INVALID_PAIRS //printf("overlappingPairArray.size()=%d\n",overlappingPairArray.size()); } }
public virtual bool ProcessOverlap(BroadphasePair pair) { m_dispatcher.GetNearCallback().NearCallback(pair, m_dispatcher, m_dispatchInfo); return(false); }
public virtual bool ProcessOverlap(BroadphasePair pair) { //(void)pair; //btAssert(0); return(false); }
private BroadphasePair InternalAddPair(BroadphaseProxy proxy0, BroadphaseProxy proxy1) { if (proxy0.m_uniqueId > proxy1.m_uniqueId) { BroadphaseProxy temp = proxy0; proxy0 = proxy1; proxy1 = temp; } int proxyId1 = proxy0.GetUid(); int proxyId2 = proxy1.GetUid(); int hash = (int)(GetHash((uint)proxyId1, (uint)proxyId2) & (m_overlappingPairArray.Capacity - 1)); // New hash value with new mask BroadphasePair pair = InternalFindPair(proxy0, proxy1, hash); if (pair != null) { return(pair); } else { /*for(int i=0;i<m_overlappingPairArray.size();++i) * { * if( (m_overlappingPairArray[i].m_pProxy0==proxy0)&& * (m_overlappingPairArray[i].m_pProxy1==proxy1)) * { * printf("Adding duplicated %u<>%u\r\n",proxyId1,proxyId2); * internalFindPair(proxy0, proxy1, hash); * } * }*/ int count = m_overlappingPairArray.Count; int oldCapacity = m_overlappingPairArray.Capacity; // MAN - 2.76 - uses expand noninitializing....?? //void* mem = &m_overlappingPairArray.expand(); //this is where we add an actual pair, so also call the 'ghost' if (m_ghostPairCallback != null) { m_ghostPairCallback.AddOverlappingPair(proxy0, proxy1); } pair = new BroadphasePair(proxy0, proxy1); m_overlappingPairArray.Add(pair); int newCapacity = m_overlappingPairArray.Capacity; if (oldCapacity < newCapacity) { GrowTables(); //hash with new capacity hash = (int)(GetHash((uint)(proxyId1), (uint)(proxyId2)) & (m_overlappingPairArray.Capacity - 1)); } m_next[count] = m_hashTable[hash]; m_hashTable[hash] = count; return(pair); } }
public virtual Object RemoveOverlappingPair(BroadphaseProxy proxy0, BroadphaseProxy proxy1, IDispatcher dispatcher) { OverlappingPairCacheGlobals.gRemovePairs++; if (proxy0.m_uniqueId > proxy1.m_uniqueId) { BroadphaseProxy temp = proxy0; proxy0 = proxy1; proxy1 = temp; } int proxyId1 = proxy0.GetUid(); int proxyId2 = proxy1.GetUid(); int hash = (int)(GetHash((uint)(proxyId1), (uint)(proxyId2)) & (m_overlappingPairArray.Capacity - 1)); BroadphasePair pair = InternalFindPair(proxy0, proxy1, hash); if (pair == null) { return(null); } CleanOverlappingPair(pair, dispatcher); Object userData = pair.m_internalInfo1; Debug.Assert(pair.m_pProxy0.GetUid() == proxyId1); Debug.Assert(pair.m_pProxy1.GetUid() == proxyId2); //int pairIndex = m_overlappingPairArray.IndexOf(pair); // we've already found this. int pairIndex = pair.m_index; Debug.Assert(pairIndex < m_overlappingPairArray.Count); // Remove the pair from the hash table. int index = m_hashTable[hash]; Debug.Assert(index != BT_NULL_PAIR); int previous = BT_NULL_PAIR; while (index != pairIndex) { previous = index; index = m_next[index]; } if (previous != BT_NULL_PAIR) { Debug.Assert(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.Count - 1; if (m_ghostPairCallback != null) { m_ghostPairCallback.RemoveOverlappingPair(proxy0, proxy1, dispatcher); } // If the removed pair is the last pair, we are done. if (lastPairIndex == pairIndex) { m_overlappingPairArray.RemoveAt(lastPairIndex); return(userData); } // Remove the last pair from the hash table. BroadphasePair last = m_overlappingPairArray[lastPairIndex]; /* missing swap here too, Nat. */ int lastHash = (int)(GetHash((uint)(last.m_pProxy0.GetUid()), (uint)(last.m_pProxy1.GetUid())) & (m_overlappingPairArray.Capacity - 1)); index = m_hashTable[lastHash]; Debug.Assert(index != BT_NULL_PAIR); previous = BT_NULL_PAIR; while (index != lastPairIndex) { previous = index; index = m_next[index]; } if (previous != BT_NULL_PAIR) { Debug.Assert(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.RemoveAt(lastPairIndex); #if DEBUG if (BulletGlobals.g_streamWriter != null && BulletGlobals.debugPairCache) { BulletGlobals.g_streamWriter.WriteLine("HPC:RemoveOverlappingPair endSize[{0}].", m_overlappingPairArray.Count); } #endif return(userData); }