public void Remove(SimulationIslandConnection connection)
{
if (connection.DeactivationManager == this)
{
connection.DeactivationManager = null; //TODO: Should it remove here, or in the deferred final case? probably here, since otherwise Add-Remove-Add would throw an exception!
//Try to split by examining the connections and breadth-first searching outward.
//If it is determined that a split is required, grab a new island and add it.
//This is a little tricky because it's a theoretically N-way split.
//For two members which have the same simulation island (they will initially), try to split.
//debugConnections.Remove(connection);
connection.SlatedForRemoval = true;
//Don't immediately do the removal.
//Defer them!
splitAttempts.Enqueue(connection);
//connection.RemoveReferencesFromConnectedMembers();
//for (int i = 0; i < connection.members.count; i++)
//{
// for (int j = i + 1; j < connection.members.count; j++)
// {
// //Notice that the splits are not performed immediately! They are deferred and spread over multiple frames.
// //Split operations aren't cheap, and overdoing them can lead to pointless re-merging and re-splitting.
// splitAttempts.Enqueue(new SplitAttempt() { a = connection.members.Elements[i], b = connection.members.Elements[j] });
// //TryToSplit(connection.ConnectedMembers[i], connection.ConnectedMembers[j]);
// }
//}
}
else
{
throw new ArgumentException("Cannot remove connection from activity manager; it is owned by a different or no activity manager.");
}
}