public void Commit()
{
int removeCount = 0;
Proxy[] proxies = _broadPhase._proxyPool;
for (int i = 0; i < _pairBufferCount; ++i)
{
Pair pair = Find(_pairBuffer[i].ProxyId1, _pairBuffer[i].ProxyId2);
Box2DXDebug.Assert(pair.IsBuffered());
pair.ClearBuffered();
Box2DXDebug.Assert(pair.ProxyId1 < Settings.MaxProxies && pair.ProxyId2 < Settings.MaxProxies);
Proxy proxy1 = proxies[pair.ProxyId1];
Proxy proxy2 = proxies[pair.ProxyId2];
Box2DXDebug.Assert(proxy1.IsValid);
Box2DXDebug.Assert(proxy2.IsValid);
if (pair.IsRemoved())
{
// It is possible a pair was added then removed before a commit. Therefore,
// we should be careful not to tell the user the pair was removed when the
// the user didn't receive a matching add.
if (pair.IsFinal() == true)
{
_callback.PairRemoved(proxy1.UserData, proxy2.UserData, pair.UserData);
}
// Store the ids so we can actually remove the pair below.
_pairBuffer[removeCount].ProxyId1 = pair.ProxyId1;
_pairBuffer[removeCount].ProxyId2 = pair.ProxyId2;
++removeCount;
}
else
{
Box2DXDebug.Assert(_broadPhase.TestOverlap(proxy1, proxy2) == true);
if (pair.IsFinal() == false)
{
pair.UserData = _callback.PairAdded(proxy1.UserData, proxy2.UserData);
pair.SetFinal();
}
}
}
for (int i = 0; i < removeCount; ++i)
{
RemovePair(_pairBuffer[i].ProxyId1, _pairBuffer[i].ProxyId2);
}
_pairBufferCount = 0;
if (BroadPhase.IsValidate)
{
ValidateTable();
}
}