Example #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);
                }
            }
        }
Example #2
0
        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());
            }
        }