示例#1
0
        ///<summary>
        /// Adds a simulation island connection to the deactivation manager.
        ///</summary>
        ///<param name="connection">Connection to add.</param>
        ///<exception cref="ArgumentException">Thrown if the connection already belongs to a manager.</exception>
        public void Add(SimulationIslandConnection connection)
        {
            //DO A MERGE IF NECESSARY
            if (connection.DeactivationManager == null)
            {
                addLocker.Enter();
                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 it was slated for removal, that means the flush stage will try to split it.
                    //Since it was just added back, splitting is known to be pointless.
                    //Just set the flag and the flush will ignore the split attempt.
                    if (connection.SlatedForRemoval)
                    {
                        connection.SlatedForRemoval = false;
                    }
                    else
                    {
                        //If the connection was NOT slated for removal, that means the reference don't currently exist.
                        //(If the connection was slated for removal, that would imply the connection existed previously, so it must have had references.)
                        connection.AddReferencesToConnectedMembers();
                    }
                }

                addLocker.Exit();
            }
            else
            {
                throw new ArgumentException("Cannot add connection to deactivation manager; it already belongs to one.");
            }
        }