// Buffer a pair for removal. 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(); } }
/* * As proxies are created and moved, many pairs are created and destroyed. Even worse, the same * pair may be added and removed multiple times in a single time step of the physics engine. To reduce * traffic in the pair manager, we try to avoid destroying pairs in the pair manager until the * end of the physics step. This is done by buffering all the RemovePair requests. AddPair * requests are processed immediately because we need the hash table entry for quick lookup. * * All user user callbacks are delayed until the buffered pairs are confirmed in Commit. * This is very important because the user callbacks may be very expensive and client logic * may be harmed if pairs are added and removed within the same time step. * * Buffer a pair for addition. * We may add a pair that is not in the pair manager or pair buffer. * We may add a pair that is already in the pair manager and pair buffer. * If the added pair is not a new pair, then it must be in the pair buffer (because RemovePair was called). */ public void AddBufferedPair(int id1, int id2) { Box2DXDebug.Assert(id1 != PairManager.NullProxy && id2 != PairManager.NullProxy); Box2DXDebug.Assert(_pairBufferCount < Settings.MaxPairs); Pair pair = AddPair(id1, id2); // If this pair is not in the pair buffer ... if (pair.IsBuffered() == false) { // This must be a newly added pair. Box2DXDebug.Assert(pair.IsFinal() == false); // Add it to the pair buffer. pair.SetBuffered(); _pairBuffer[_pairBufferCount].ProxyId1 = pair.ProxyId1; _pairBuffer[_pairBufferCount].ProxyId2 = pair.ProxyId2; ++_pairBufferCount; Box2DXDebug.Assert(_pairBufferCount <= _pairCount); } // Confirm this pair for the subsequent call to Commit. pair.ClearRemoved(); if (BroadPhase.IsValidate) { ValidateBuffer(); } }
public void AddBufferedPair(int id1, int id2) { Box2DXDebug.Assert(id1 != (int)PairManager.NullProxy && id2 != (int)PairManager.NullProxy); Box2DXDebug.Assert(this._pairBufferCount < Settings.MaxPairs); Pair pair = this.AddPair(id1, id2); if (!pair.IsBuffered()) { Box2DXDebug.Assert(!pair.IsFinal()); pair.SetBuffered(); this._pairBuffer[this._pairBufferCount].ProxyId1 = pair.ProxyId1; this._pairBuffer[this._pairBufferCount].ProxyId2 = pair.ProxyId2; this._pairBufferCount++; Box2DXDebug.Assert(this._pairBufferCount <= this._pairCount); } pair.ClearRemoved(); if (BroadPhase.IsValidate) { this.ValidateBuffer(); } }