protected internal void UnsafeSolveIteration(SolverUpdateable updateable)
        {
            if (updateable.isActiveInSolver)
            {
                SolverSettings solverSettings = updateable.solverSettings;


                solverSettings.currentIterations++;
                if (solverSettings.currentIterations <= iterationLimit &&
                    solverSettings.currentIterations <= solverSettings.maximumIterationCount)
                {
                    if (updateable.SolveIteration() < solverSettings.minimumImpulse)
                    {
                        solverSettings.iterationsAtZeroImpulse++;
                        if (solverSettings.iterationsAtZeroImpulse > solverSettings.minimumIterationCount)
                        {
                            updateable.isActiveInSolver = false;
                        }
                    }
                    else
                    {
                        solverSettings.iterationsAtZeroImpulse = 0;
                    }
                }
                else
                {
                    updateable.isActiveInSolver = false;
                }
            }
        }
 protected internal void UnsafeExclusiveUpdate(SolverUpdateable updateable)
 {
     if (updateable.isActiveInSolver)
     {
         updateable.ExclusiveUpdate();
     }
 }
        ///<summary>
        /// Removes a solver updateable from the solver.
        ///</summary>
        ///<param name="item">Updateable to remove.</param>
        ///<exception cref="ArgumentException">Thrown when the item does not belong to the solver.</exception>
        public void Remove(SolverUpdateable item)
        {
            if (item.Solver == this)
            {
                item.Solver = null;


                addRemoveLocker.Enter();
                solverUpdateables.Count--;
                if (item.solverIndex < solverUpdateables.Count)
                {
                    //The solver updateable isn't the last element, so put the last element in its place.
                    solverUpdateables.Elements[item.solverIndex] = solverUpdateables.Elements[solverUpdateables.Count];
                    //Update the replacement's solver index to its new location.
                    solverUpdateables.Elements[item.solverIndex].solverIndex = item.solverIndex;
                }
                solverUpdateables.Elements[solverUpdateables.Count] = null;
                addRemoveLocker.Exit();

                DeactivationManager.Remove(item.simulationIslandConnection);
                item.OnRemovalFromSolver(this);
            }

            else
            {
                throw new ArgumentException("Solver updateable doesn't belong to this solver; it can't be removed.", "item");
            }
        }
 protected internal void UnsafePrestep(SolverUpdateable updateable)
 {
     updateable.UpdateSolverActivity();
     if (updateable.isActiveInSolver)
     {
         SolverSettings solverSettings = updateable.solverSettings;
         solverSettings.currentIterations       = 0;
         solverSettings.iterationsAtZeroImpulse = 0;
         updateable.Update(timeStepSettings.TimeStepDuration);
     }
 }
        ///<summary>
        /// Adds a solver updateable to the solver.
        ///</summary>
        ///<param name="item">Updateable to add.</param>
        ///<exception cref="ArgumentException">Thrown when the item already belongs to a solver.</exception>
        public void Add(SolverUpdateable item)
        {
            if (item.Solver == null)
            {
                item.Solver = this;

                addRemoveLocker.Enter();
                item.solverIndex = solverUpdateables.Count;
                solverUpdateables.Add(item);
                addRemoveLocker.Exit();

                DeactivationManager.Add(item.simulationIslandConnection);
                item.OnAdditionToSolver(this);
            }
            else
            {
                throw new ArgumentException("Solver updateable already belongs to something; it can't be added.", "item");
            }
        }