Example #1
0
        ///<summary>
        /// Constructs a new space for things to live in.
        ///</summary>
        public Space()
        {
            NarrowPhaseHelper.CollisionManagers = NarrowPhaseHelper.CollisionManagers; //Forces the NarrowPhaseHelper to run the static constructor.  Better to do it now instead of mid-simulation.

            timeStepSettings = new TimeStepSettings();

#if !WINDOWS
            threadManager = new SpecializedThreadManager();
#else
            threadManager = new SpecializedThreadManager();
#endif

            SpaceObjectBuffer      = new SpaceObjectBuffer(this);
            EntityStateWriteBuffer = new EntityStateWriteBuffer();
            DeactivationManager    = new DeactivationManager(TimeStepSettings, ThreadManager);
            ForceUpdater           = new ForceUpdater(TimeStepSettings, ThreadManager);
            BoundingBoxUpdater     = new BoundingBoxUpdater(TimeStepSettings, ThreadManager);
            BroadPhase             = new DynamicHierarchy(ThreadManager);
            NarrowPhase            = new NarrowPhase(TimeStepSettings, BroadPhase.Overlaps, ThreadManager);
            Solver                  = new Solver(TimeStepSettings, DeactivationManager, ThreadManager);
            NarrowPhase.Solver      = Solver;
            PositionUpdater         = new ContinuousPositionUpdater(TimeStepSettings, ThreadManager);
            BufferedStates          = new BufferedStatesManager(ThreadManager);
            DeferredEventDispatcher = new DeferredEventDispatcher();

            DuringForcesUpdateables         = new DuringForcesUpdateableManager(timeStepSettings, ThreadManager);
            BeforeNarrowPhaseUpdateables    = new BeforeNarrowPhaseUpdateableManager(timeStepSettings, ThreadManager);
            BeforeSolverUpdateables         = new BeforeSolverUpdateableManager(timeStepSettings, ThreadManager);
            BeforePositionUpdateUpdateables = new BeforePositionUpdateUpdateableManager(timeStepSettings, ThreadManager);
            EndOfTimeStepUpdateables        = new EndOfTimeStepUpdateableManager(timeStepSettings, ThreadManager);
            EndOfFrameUpdateables           = new EndOfFrameUpdateableManager(timeStepSettings, ThreadManager);
        }
Example #2
0
        ///<summary>
        /// Constructs a new space for things to live in.
        ///</summary>
        ///<param name="parallelLooper">Used by the space to perform multithreaded updates. Pass null if multithreading is not required.</param>
        public Space(IParallelLooper parallelLooper)
        {
            timeStepSettings = new TimeStepSettings();

            this.parallelLooper = parallelLooper;

            SpaceObjectBuffer      = new SpaceObjectBuffer(this);
            EntityStateWriteBuffer = new EntityStateWriteBuffer();
            DeactivationManager    = new DeactivationManager(TimeStepSettings, ParallelLooper);
            ForceUpdater           = new ForceUpdater(TimeStepSettings, ParallelLooper);
            BoundingBoxUpdater     = new BoundingBoxUpdater(TimeStepSettings, ParallelLooper);
            BroadPhase             = new DynamicHierarchy(ParallelLooper);
            NarrowPhase            = new NarrowPhase(TimeStepSettings, BroadPhase.Overlaps, ParallelLooper);
            Solver                  = new Solver(TimeStepSettings, DeactivationManager, ParallelLooper);
            NarrowPhase.Solver      = Solver;
            PositionUpdater         = new ContinuousPositionUpdater(TimeStepSettings, ParallelLooper);
            BufferedStates          = new BufferedStatesManager(ParallelLooper);
            DeferredEventDispatcher = new DeferredEventDispatcher();

            DuringForcesUpdateables         = new DuringForcesUpdateableManager(timeStepSettings, ParallelLooper);
            BeforeNarrowPhaseUpdateables    = new BeforeNarrowPhaseUpdateableManager(timeStepSettings, ParallelLooper);
            BeforeSolverUpdateables         = new BeforeSolverUpdateableManager(timeStepSettings, ParallelLooper);
            BeforePositionUpdateUpdateables = new BeforePositionUpdateUpdateableManager(timeStepSettings, ParallelLooper);
            EndOfTimeStepUpdateables        = new EndOfTimeStepUpdateableManager(timeStepSettings, ParallelLooper);
            EndOfFrameUpdateables           = new EndOfFrameUpdateableManager(timeStepSettings, ParallelLooper);
        }
Example #3
0
        void DoTimeStep()
        {
#if PROFILE
            start = Stopwatch.GetTimestamp();
#endif
            SpaceObjectBuffer.Update();
            EntityStateWriteBuffer.Update();
            DeactivationManager.Update();
            ForceUpdater.Update();
            DuringForcesUpdateables.Update();
            BoundingBoxUpdater.Update();
            BroadPhase.Update();
            BeforeNarrowPhaseUpdateables.Update();
            NarrowPhase.Update();
            BeforeSolverUpdateables.Update();
            Solver.Update();
            BeforePositionUpdateUpdateables.Update();
            PositionUpdater.Update();
            BufferedStates.ReadBuffers.Update();
            DeferredEventDispatcher.Update();
            EndOfTimeStepUpdateables.Update();
#if PROFILE
            end = Stopwatch.GetTimestamp();
#endif
        }
Example #4
0
        ///<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");
            }
        }
Example #5
0
 ///<summary>
 /// Constructs a Solver.
 ///</summary>
 ///<param name="timeStepSettings">Time step settings used by the solver.</param>
 ///<param name="deactivationManager">Deactivation manager used by the solver.</param>
 /// <param name="parallelLooper">Parallel loop provider used by the solver.</param>
 public Solver(TimeStepSettings timeStepSettings, DeactivationManager deactivationManager,
               IParallelLooper parallelLooper)
     : this(timeStepSettings, deactivationManager)
 {
     ParallelLooper      = parallelLooper;
     AllowMultithreading = true;
 }
Example #6
0
 ///<summary>
 /// Constructs a Solver.
 ///</summary>
 ///<param name="timeStepSettings">Time step settings used by the solver.</param>
 ///<param name="deactivationManager">Deactivation manager used by the solver.</param>
 public Solver(TimeStepSettings timeStepSettings, DeactivationManager deactivationManager)
 {
     TimeStepSettings               = timeStepSettings;
     DeactivationManager            = deactivationManager;
     multithreadedPrestepDelegate   = MultithreadedPrestep;
     multithreadedIterationDelegate = MultithreadedIteration;
     Enabled = true;
 }
Example #7
0
 ///<summary>
 /// Constructs a Solver.
 ///</summary>
 ///<param name="timeStepSettings">Time step settings used by the solver.</param>
 ///<param name="deactivationManager">Deactivation manager used by the solver.</param>
 public Solver(TimeStepSettings timeStepSettings, DeactivationManager deactivationManager)
 {
     TimeStepSettings                     = timeStepSettings;
     DeactivationManager                  = deactivationManager;
     multithreadedPrestepDelegate         = MultithreadedPrestep;
     multithreadedExclusiveUpdateDelegate = MultithreadedExclusiveUpdate;
     multithreadedIterationDelegate       = MultithreadedIteration;
     Enabled           = true;
     PermutationMapper = new PermutationMapper();
 }
Example #8
0
 ///<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;
         item.solverIndex = solverUpdateables.Count;
         solverUpdateables.Add(item);
         DeactivationManager.Add(item.simulationIslandConnection);
         item.OnAdditionToSolver(this);
     }
     else
     {
         throw new ArgumentException("Solver updateable already belongs to something; it can't be added.", "item");
     }
 }
Example #9
0
 void DoTimeStep()
 {
     SpaceObjectBuffer.Update();
     EntityStateWriteBuffer.Update();
     DeactivationManager.Update();
     ForceUpdater.Update();
     DuringForcesUpdateables.Update();
     BoundingBoxUpdater.Update();
     BroadPhase.Update();
     BeforeNarrowPhaseUpdateables.Update();
     NarrowPhase.Update();
     BeforeSolverUpdateables.Update();
     NarrowPhase.FlushGeneratedSolverUpdateables();
     Solver.Update();
     BeforePositionUpdateUpdateables.Update();
     PositionUpdater.Update();
     BufferedStates.ReadBuffers.Update();
     DeferredEventDispatcher.Update();
     EndOfTimeStepUpdateables.Update();
 }
Example #10
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);
        }
Example #11
0
 ///<summary>
 /// Constructs a Solver.
 ///</summary>
 ///<param name="timeStepSettings">Time step settings used by the solver.</param>
 ///<param name="deactivationManager">Deactivation manager used by the solver.</param>
 /// <param name="threadManager">Thread manager used by the solver.</param>
 public Solver(TimeStepSettings timeStepSettings, DeactivationManager deactivationManager, IThreadManager threadManager)
     : this(timeStepSettings, deactivationManager)
 {
     ThreadManager       = threadManager;
     AllowMultithreading = true;
 }
Example #12
0
 private void initializeManagers(string organizationName, string providerName, string deactivationName)
 {
     orgManager = new OrganizationManager(organizationName);
     proManager = new ProviderManager(providerName);
     deaManager = new DeactivationManager(deactivationName);
 }