/// <summary> /// Notifies the system that a force updateable is becoming dynamic. /// </summary> /// <param name="updateable">Updateable changing state.</param> public void ForceUpdateableBecomingDynamic(IForceUpdateable updateable) { //This does not verify that it used to be kinematic. Small room for unsafety. if (updateable.ForceUpdater == this) { dynamicObjects.Add(updateable); } else { throw new ArgumentException("Updateable does not belong to this manager."); } }
///<summary> /// Adds a force updateable to the force updater. ///</summary> ///<param name="forceUpdateable">Item to add.</param> ///<exception cref="Exception">Thrown when the item already belongs to a force updater.</exception> public void Add(IForceUpdateable forceUpdateable) { if (forceUpdateable.ForceUpdater == null) { forceUpdateable.ForceUpdater = this; if (forceUpdateable.IsDynamic) { dynamicObjects.Add(forceUpdateable); } } else { throw new ArgumentException("Cannot add updateable; it already belongs to another manager."); } }
/// <summary> /// Notifies the system that a force updateable is becoming kinematic. /// </summary> /// <param name="updateable">Updateable changing state.</param> public void ForceUpdateableBecomingKinematic(IForceUpdateable updateable) { //This does not verify that it used to be dynamic. Small room for unsafety. if (updateable.ForceUpdater == this) { if (!dynamicObjects.Remove(updateable)) { throw new InvalidOperationException("Dynamic object not present in dynamic objects list; ensure that the IVelocityUpdateable was never removed from the list improperly by using VelocityUpdateableBecomingKinematic."); } } else { throw new ArgumentException("Updateable does not belong to this manager."); } }
///<summary> /// Removes a force updateable from the force updater. ///</summary> ///<param name="forceUpdateable">Item to remove.</param> ///<exception cref="Exception">Thrown when the item does not belong to this force updater or its state is corrupted.</exception> public void Remove(IForceUpdateable forceUpdateable) { if (forceUpdateable.ForceUpdater == this) { if (forceUpdateable.IsDynamic && !dynamicObjects.Remove(forceUpdateable)) { throw new InvalidOperationException("Dynamic object not present in dynamic objects list; ensure that the IForceUpdateable was never removed from the list improperly by using ForceUpdateableBecomingKinematic."); } forceUpdateable.ForceUpdater = null; } else { throw new ArgumentException("Cannot remove updateable; it does not belong to this manager."); } }
///<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); }
///<summary> /// Adds a force updateable to the force updater. ///</summary> ///<param name="forceUpdateable">Item to add.</param> ///<exception cref="Exception">Thrown when the item already belongs to a force updater.</exception> public void Add(IForceUpdateable forceUpdateable) { if (forceUpdateable.ForceUpdater == null) { forceUpdateable.ForceUpdater = this; if (forceUpdateable.IsDynamic) dynamicObjects.Add(forceUpdateable); } else throw new ArgumentException("Cannot add updateable; it already belongs to another manager."); }
/// <summary> /// Notifies the system that a force updateable is becoming kinematic. /// </summary> /// <param name="updateable">Updateable changing state.</param> public void ForceUpdateableBecomingKinematic(IForceUpdateable updateable) { //This does not verify that it used to be dynamic. Small room for unsafety. if (updateable.ForceUpdater == this) { if (!dynamicObjects.Remove(updateable)) throw new InvalidOperationException("Dynamic object not present in dynamic objects list; ensure that the IVelocityUpdateable was never removed from the list improperly by using VelocityUpdateableBecomingKinematic."); } else throw new ArgumentException("Updateable does not belong to this manager."); }
/// <summary> /// Notifies the system that a force updateable is becoming dynamic. /// </summary> /// <param name="updateable">Updateable changing state.</param> public void ForceUpdateableBecomingDynamic(IForceUpdateable updateable) { //This does not verify that it used to be kinematic. Small room for unsafety. if (updateable.ForceUpdater == this) { dynamicObjects.Add(updateable); } else throw new ArgumentException("Updateable does not belong to this manager."); }
///<summary> /// Removes a force updateable from the force updater. ///</summary> ///<param name="forceUpdateable">Item to remove.</param> ///<exception cref="Exception">Thrown when the item does not belong to this force updater or its state is corrupted.</exception> public void Remove(IForceUpdateable forceUpdateable) { if (forceUpdateable.ForceUpdater == this) { if (forceUpdateable.IsDynamic && !dynamicObjects.Remove(forceUpdateable)) throw new InvalidOperationException("Dynamic object not present in dynamic objects list; ensure that the IForceUpdateable was never removed from the list improperly by using ForceUpdateableBecomingKinematic."); forceUpdateable.ForceUpdater = null; } else throw new ArgumentException("Cannot remove updateable; it does not belong to this manager."); }