Beispiel #1
0
        /// <summary>
        /// Handle any bookkeeping needed when the entities involved in this SolverUpdateable change.
        /// </summary>
        protected internal virtual void OnInvolvedEntitiesChanged()
        {
            //First verify that something really changed.
            bool             entitiesChanged     = false;
            RawList <Entity> newInvolvedEntities = PhysicsResources.GetEntityRawList();

            CollectInvolvedEntities(newInvolvedEntities);
            if (newInvolvedEntities.Count == involvedEntities.Count)
            {
                for (int i = 0; i < newInvolvedEntities.Count; i++)
                {
                    if (newInvolvedEntities.Elements[i] != involvedEntities.Elements[i])
                    {
                        entitiesChanged = true;
                        break;
                    }
                }
            }
            else
            {
                entitiesChanged = true;
            }

            if (entitiesChanged)
            {
                //Probably need to wake things up given that such a significant change was made.

                for (int i = 0; i < involvedEntities.Count; i++)
                {
                    Entity e = involvedEntities.Elements[i];
                    if (e.isDynamic)
                    {
                        e.activityInformation.Activate();
                        break;//Don't bother activating other entities; they are all a part of the same simulation island.
                    }
                }

                //CollectInvolvedEntities will give the updateable a new simulationIslandConnection and get rid of the old one.
                CollectInvolvedEntities();



                if (SolverGroup != null)
                {
                    SolverGroup.OnInvolvedEntitiesChanged();
                }

                //We woke up the FORMER involved entities, now wake up the current involved entities.
                for (int i = 0; i < involvedEntities.Count; i++)
                {
                    Entity e = involvedEntities.Elements[i];
                    if (e.isDynamic)
                    {
                        e.activityInformation.Activate();
                        break; //Don't bother activating other entities; they are all a part of the same simulation island.
                    }
                }
            }
            PhysicsResources.GiveBack(newInvolvedEntities);
        }