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();
}
}