Beispiel #1
0
        protected override void DispatchEvents()
        {
            //Go through all children and dispatch events.
            //They won't be touched by the primary event manager otherwise.
            CompoundCollidable compound = owner as CompoundCollidable;

            if (compound != null)
            {
                foreach (CompoundChild child in compound.children)
                {
                    IDeferredEventCreator deferredEventCreator =
                        child.CollisionInformation.events as IDeferredEventCreator;
                    if (deferredEventCreator.IsActive)
                    {
                        deferredEventCreator.DispatchEvents();
                    }
                }
            }
            else
            {
                throw new InvalidOperationException(
                          "Cannot use a CompoundEventManager with anything but a CompoundCollidable.");
            }

            base.DispatchEvents();
        }
 /// <summary>
 /// Removes an event creator.
 /// </summary>
 /// <param name="creator">Creator to remove.</param>
 public void RemoveEventCreator(IDeferredEventCreator creator)
 {
     if (creator.DeferredEventDispatcher == this)
     {
         creator.DeferredEventDispatcher = null;
         if (creator.IsActive)
             activeEventCreators.Remove(creator);
     }
     else
         throw new ArgumentException("The event creator is managed by a different dispatcher; it cannot be removed.", "creator");
 }
Beispiel #3
0
 /// <summary>
 /// Removes an event creator.
 /// </summary>
 /// <param name="creator">Creator to remove.</param>
 public void RemoveEventCreator(IDeferredEventCreator creator)
 {
     if (creator.DeferredEventDispatcher == this)
     {
         creator.DeferredEventDispatcher = null;
         if (creator.IsActive)
             activeEventCreators.Remove(creator);
     }
     else
         throw new ArgumentException("The event creator is managed by a different dispatcher; it cannot be removed.", "creator");
 }
 ///<summary>
 /// Notifies the dispatcher that the event activity of a creator has changed.
 ///</summary>
 ///<param name="creator">Cretor whose activity has changed.</param>
 ///<exception cref="ArgumentException">Thrown when the event creator's state hasn't changed.</exception>
 public void CreatorActivityChanged(IDeferredEventCreator creator)
 {
     //This is a pretty rarely called method.  It's okay to do a little extra verification at the cost of performance.
     if (creator.IsActive)
         if (!activeEventCreators.Contains(creator))
             activeEventCreators.Add(creator);
         else
             throw new ArgumentException("The event creator was already active in the dispatcher; make sure the CreatorActivityChanged function is only called when the state actually changes.", "creator");
     else
         if (!activeEventCreators.Remove(creator))
             throw new ArgumentException("The event creator not active in the dispatcher; make sure the CreatorActivityChanged function is only called when the state actually changes.", "creator");
 }
Beispiel #5
0
 ///<summary>
 /// Notifies the dispatcher that the event activity of a creator has changed.
 ///</summary>
 ///<param name="creator">Cretor whose activity has changed.</param>
 ///<exception cref="ArgumentException">Thrown when the event creator's state hasn't changed.</exception>
 public void CreatorActivityChanged(IDeferredEventCreator creator)
 {
     //This is a pretty rarely called method.  It's okay to do a little extra verification at the cost of performance.
     if (creator.IsActive)
         if (!activeEventCreators.Contains(creator))
             activeEventCreators.Add(creator);
         else
             throw new ArgumentException("The event creator was already active in the dispatcher; make sure the CreatorActivityChanged function is only called when the state actually changes.", "creator");
     else
         if (!activeEventCreators.Remove(creator))
             throw new ArgumentException("The event creator not active in the dispatcher; make sure the CreatorActivityChanged function is only called when the state actually changes.", "creator");
 }
 ///<summary>
 /// Adds an event creator.
 ///</summary>
 ///<param name="creator">Creator to add.</param>
 ///<exception cref="ArgumentException">Thrown when the creator is already managed by a dispatcher.</exception>
 public void AddEventCreator(IDeferredEventCreator creator)
 {
     if (creator.DeferredEventDispatcher == null)
     {
         creator.DeferredEventDispatcher = this;
         //If it already has events attached, add it to the active event creators list.
         //Otherwise, don't bother adding it until it has some.
         //It is up to the creator to notify the dispatcher of the change.
         if (creator.IsActive)
             activeEventCreators.Add(creator);
     }
     else
         throw new ArgumentException("The event creator is already managed by a dispatcher; it cannot be added.", "creator");
 }
Beispiel #7
0
 ///<summary>
 /// Adds an event creator.
 ///</summary>
 ///<param name="creator">Creator to add.</param>
 ///<exception cref="ArgumentException">Thrown when the creator is already managed by a dispatcher.</exception>
 public void AddEventCreator(IDeferredEventCreator creator)
 {
     if (creator.DeferredEventDispatcher == null)
     {
         creator.DeferredEventDispatcher = this;
         //If it already has events attached, add it to the active event creators list.
         //Otherwise, don't bother adding it until it has some.
         //It is up to the creator to notify the dispatcher of the change.
         if (creator.IsActive)
             activeEventCreators.Add(creator);
     }
     else
         throw new ArgumentException("The event creator is already managed by a dispatcher; it cannot be added.", "creator");
 }
Beispiel #8
0
        ///<summary>
        /// Removes a space object from the simulation.
        ///</summary>
        ///<param name="spaceObject">Space object to remove.</param>
        public void Remove(ISpaceObject spaceObject)
        {
            if (spaceObject.Space != this)
            {
                throw new ArgumentException("The object does not belong to this space; cannot remove it.");
            }

            SimulationIslandMember simulationIslandMember = spaceObject as SimulationIslandMember;

            if (simulationIslandMember != null)
            {
                DeactivationManager.Remove(simulationIslandMember);
            }

            ISimulationIslandMemberOwner simulationIslandMemberOwner = spaceObject as ISimulationIslandMemberOwner;

            if (simulationIslandMemberOwner != null)
            {
                DeactivationManager.Remove(simulationIslandMemberOwner.ActivityInformation);
            }

            //Go through each stage, removing the space object from it if necessary.
            IForceUpdateable velocityUpdateable = spaceObject as IForceUpdateable;

            if (velocityUpdateable != null)
            {
                ForceUpdater.Remove(velocityUpdateable);
            }

            MobileCollidable boundingBoxUpdateable = spaceObject as MobileCollidable;

            if (boundingBoxUpdateable != null)
            {
                BoundingBoxUpdater.Remove(boundingBoxUpdateable);
            }

            BroadPhaseEntry broadPhaseEntry = spaceObject as BroadPhaseEntry;

            if (broadPhaseEntry != null)
            {
                BroadPhase.Remove(broadPhaseEntry);
            }

            //Entites own collision proxies, but are not entries themselves.
            IBroadPhaseEntryOwner broadPhaseEntryOwner = spaceObject as IBroadPhaseEntryOwner;

            if (broadPhaseEntryOwner != null)
            {
                BroadPhase.Remove(broadPhaseEntryOwner.Entry);
                boundingBoxUpdateable = broadPhaseEntryOwner.Entry as MobileCollidable;
                if (boundingBoxUpdateable != null)
                {
                    BoundingBoxUpdater.Remove(boundingBoxUpdateable);
                }
            }

            SolverUpdateable solverUpdateable = spaceObject as SolverUpdateable;

            if (solverUpdateable != null)
            {
                Solver.Remove(solverUpdateable);
            }

            IPositionUpdateable integrable = spaceObject as IPositionUpdateable;

            if (integrable != null)
            {
                PositionUpdater.Remove(integrable);
            }

            Entity entity = spaceObject as Entity;

            if (entity != null)
            {
                BufferedStates.Remove(entity);
            }

            IDeferredEventCreator deferredEventCreator = spaceObject as IDeferredEventCreator;

            if (deferredEventCreator != null)
            {
                DeferredEventDispatcher.RemoveEventCreator(deferredEventCreator);
            }

            IDeferredEventCreatorOwner deferredEventCreatorOwner = spaceObject as IDeferredEventCreatorOwner;

            if (deferredEventCreatorOwner != null)
            {
                DeferredEventDispatcher.RemoveEventCreator(deferredEventCreatorOwner.EventCreator);
            }

            //Updateable stages.
            IDuringForcesUpdateable duringForcesUpdateable = spaceObject as IDuringForcesUpdateable;

            if (duringForcesUpdateable != null)
            {
                DuringForcesUpdateables.Remove(duringForcesUpdateable);
            }

            IBeforeNarrowPhaseUpdateable beforeNarrowPhaseUpdateable = spaceObject as IBeforeNarrowPhaseUpdateable;

            if (beforeNarrowPhaseUpdateable != null)
            {
                BeforeNarrowPhaseUpdateables.Remove(beforeNarrowPhaseUpdateable);
            }

            IBeforeSolverUpdateable beforeSolverUpdateable = spaceObject as IBeforeSolverUpdateable;

            if (beforeSolverUpdateable != null)
            {
                BeforeSolverUpdateables.Remove(beforeSolverUpdateable);
            }


            IBeforePositionUpdateUpdateable beforePositionUpdateUpdateable = spaceObject as IBeforePositionUpdateUpdateable;

            if (beforePositionUpdateUpdateable != null)
            {
                BeforePositionUpdateUpdateables.Remove(beforePositionUpdateUpdateable);
            }

            IEndOfTimeStepUpdateable endOfStepUpdateable = spaceObject as IEndOfTimeStepUpdateable;

            if (endOfStepUpdateable != null)
            {
                EndOfTimeStepUpdateables.Remove(endOfStepUpdateable);
            }

            IEndOfFrameUpdateable endOfFrameUpdateable = spaceObject as IEndOfFrameUpdateable;

            if (endOfFrameUpdateable != null)
            {
                EndOfFrameUpdateables.Remove(endOfFrameUpdateable);
            }

            spaceObject.Space = null;
            spaceObject.OnRemovalFromSpace(this);
        }