public void Add(SimulationIslandConnection connection)
{
//DO A MERGE IF NECESSARY
if (connection.DeactivationManager == null)
{
connection.DeactivationManager = this;
if (connection.entries.Count > 0)
{
var island = connection.entries.Elements[0].Member.SimulationIsland;
for (int i = 1; i < connection.entries.Count; i++)
{
SimulationIsland opposingIsland;
if (island != (opposingIsland = connection.entries.Elements[i].Member.SimulationIsland))
{
//Need to do a merge between the two islands.
//Note that this merge may eliminate the need for a merge with subsequent connection if they belong to the same island.
island = Merge(island, opposingIsland);
}
}
if (connection.SlatedForRemoval)
connection.SlatedForRemoval = false; //If it was slated for removal, that means connections are still present. Just set the flag and the removal system will ignore the removal order.
else
connection.AddReferencesToConnectedMembers();
//debugConnections.Add(connection);
}
}
else
{
throw new ArgumentException("Cannot add connection to deactivation manager; it already belongs to one.");
}
}