Beispiel #1
0
        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);
                }
            }
        }