Box2DX.Collision.PairManager.RemoveBufferedPair C# (CSharp) Метод

RemoveBufferedPair() публичный Метод

public RemoveBufferedPair ( int id1, int id2 ) : void
id1 int
id2 int
Результат void
		public void RemoveBufferedPair(int id1, int id2)
		{
			Box2DXDebug.Assert(id1 != PairManager.NullProxy && id2 != PairManager.NullProxy);
			Box2DXDebug.Assert(_pairBufferCount < Settings.MaxPairs);

			Pair pair = Find(id1, id2);

			if (pair == null)
			{
				// The pair never existed. This is legal (due to collision filtering).
				return;
			}

			// If this pair is not in the pair buffer ...
			if (pair.IsBuffered() == false)
			{
				// This must be an old pair.
				Box2DXDebug.Assert(pair.IsFinal() == true);

				pair.SetBuffered();
				_pairBuffer[_pairBufferCount].ProxyId1 = pair.ProxyId1;
				_pairBuffer[_pairBufferCount].ProxyId2 = pair.ProxyId2;
				++_pairBufferCount;

				Box2DXDebug.Assert(_pairBufferCount <= _pairCount);
			}

			pair.SetRemoved();

			if (BroadPhase.IsValidate)
			{
				ValidateBuffer();
			}
		}

Usage Example

Пример #1
0
        public void DestroyProxy(int proxyId)
        {
            Box2DXDebug.Assert(0 < _proxyCount && _proxyCount <= Settings.MaxProxies);
            Proxy proxy = _proxyPool[proxyId];

            Box2DXDebug.Assert(proxy.IsValid);

            int boundCount = 2 * _proxyCount;

            for (int axis = 0; axis < 2; ++axis)
            {
                Bound[] bounds = _bounds[axis];

                int    lowerIndex = proxy.LowerBounds[axis];
                int    upperIndex = proxy.UpperBounds[axis];
                ushort lowerValue = bounds[lowerIndex].Value;
                ushort upperValue = bounds[upperIndex].Value;

#warning "Check this"
                //memmove(bounds + lowerIndex, bounds + lowerIndex + 1, (upperIndex - lowerIndex - 1) * sizeof(b2Bound));
                Bound[] tmp = new Bound[upperIndex - lowerIndex - 1];
                for (int i = 0; i < (upperIndex - lowerIndex - 1); i++)
                {
                    tmp[i] = bounds[lowerIndex + 1 + i].Clone();
                }
                for (int i = 0; i < (upperIndex - lowerIndex - 1); i++)
                {
                    bounds[lowerIndex + i] = tmp[i];
                }

                //memmove(bounds + upperIndex - 1, bounds + upperIndex + 1, (boundCount - upperIndex - 1) * sizeof(b2Bound));
                tmp = new Bound[boundCount - upperIndex - 1];
                for (int i = 0; i < (boundCount - upperIndex - 1); i++)
                {
                    tmp[i] = bounds[upperIndex + 1 + i].Clone();
                }
                for (int i = 0; i < (boundCount - upperIndex - 1); i++)
                {
                    bounds[upperIndex - 1 + i] = tmp[i];
                }

                // Fix bound indices.
                for (int index = lowerIndex; index < boundCount - 2; ++index)
                {
                    Proxy proxy_ = _proxyPool[bounds[index].ProxyId];
                    if (bounds[index].IsLower)
                    {
                        proxy_.LowerBounds[axis] = (ushort)index;
                    }
                    else
                    {
                        proxy_.UpperBounds[axis] = (ushort)index;
                    }
                }

                // Fix stabbing count.
                for (int index = lowerIndex; index < upperIndex - 1; ++index)
                {
                    --bounds[index].StabbingCount;
                }

                // Query for pairs to be removed. lowerIndex and upperIndex are not needed.
                Query(out lowerIndex, out upperIndex, lowerValue, upperValue, bounds, boundCount - 2, axis);
            }

            Box2DXDebug.Assert(_queryResultCount < Settings.MaxProxies);

            for (int i = 0; i < _queryResultCount; ++i)
            {
                Box2DXDebug.Assert(_proxyPool[_queryResults[i]].IsValid);
                _pairManager.RemoveBufferedPair(proxyId, _queryResults[i]);
            }

            _pairManager.Commit();

            // Prepare for next query.
            _queryResultCount = 0;
            IncrementTimeStamp();

            // Return the proxy to the pool.
            proxy.UserData       = null;
            proxy.OverlapCount   = BroadPhase.Invalid;
            proxy.LowerBounds[0] = BroadPhase.Invalid;
            proxy.LowerBounds[1] = BroadPhase.Invalid;
            proxy.UpperBounds[0] = BroadPhase.Invalid;
            proxy.UpperBounds[1] = BroadPhase.Invalid;

            proxy.Next = _freeProxy;
            _freeProxy = (ushort)proxyId;
            --_proxyCount;

            if (IsValidate)
            {
                Validate();
            }
        }