/* * 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) { Box2DNetDebug.Assert(id1 != PairManager.NullProxy && id2 != PairManager.NullProxy); Box2DNetDebug.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. Box2DNetDebug.Assert(pair.IsFinal() == false); // Add it to the pair buffer. pair.SetBuffered(); _pairBuffer[_pairBufferCount].ProxyId1 = pair.ProxyId1; _pairBuffer[_pairBufferCount].ProxyId2 = pair.ProxyId2; ++_pairBufferCount; Box2DNetDebug.Assert(_pairBufferCount <= _pairCount); } // Confirm this pair for the subsequent call to Commit. pair.ClearRemoved(); 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) { 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. // Add it to the pair buffer. pair.SetBuffered(); _pairBuffer[_pairBufferCount].ProxyId1 = pair.ProxyId1; _pairBuffer[_pairBufferCount].ProxyId2 = pair.ProxyId2; ++_pairBufferCount; } // Confirm this pair for the subsequent call to Commit. pair.ClearRemoved(); if (BroadPhase.IsValidate) { ValidateBuffer(); } }