void FlushSplits()
{
//Only do a portion of the total splits.
int maxAttempts = Math.Max(minimumSplitAttempts, (int)(splitAttempts.Count * maximumSplitAttemptsFraction));
int attempts = 0;
while (attempts < maxAttempts && splitAttempts.Count > 0)
{
var attempt = splitAttempts.Dequeue();
if (attempt.SlatedForRemoval) //If it was re-added, don't split!
{
attempt.SlatedForRemoval = false; //Reset the removal state so that future adds will add back references, since we're about to remove them.
attempt.RemoveReferencesFromConnectedMembers();
bool triedToSplit = false;
for (int i = 0; i < attempt.entries.Count; i++)
{
for (int j = i + 1; j < attempt.entries.Count; j++)
{
triedToSplit |= TryToSplit(attempt.entries.Elements[i].Member, attempt.entries.Elements[j].Member);
}
}
//Only count the split if it does any work.
if (triedToSplit)
attempts++;
if (attempt.Owner == null)
{
//It's an orphan connection. No one owns it, and now that it's been dequeued from the deactivation manager,
//it has no home at all.
//Don't let it rot- return it to the pool!
PhysicsResources.GiveBack(attempt);
//This occurs when a constraint changes members.
//Because connections need to be immutable for this scheme to work,
//the old connection is orphaned and put into the deactivation manager's removal queue
//while a new one from the pool takes its place.
}
}
}
}