예제 #1
0
        protected override void LoadContent()
        {
            dataFont = Content.Load <SpriteFont>("DataFont");
            tinyFont = Content.Load <SpriteFont>("TinyFont");

            controlsMenu = Content.Load <Texture2D>("bepuphysicscontrols");

            IsFixedTimeStep = false;

            LineDrawer = new BasicEffect(GraphicsDevice);

            UIDrawer = new SpriteBatch(GraphicsDevice);

            DataTextDrawer = new TextDrawer(UIDrawer, dataFont, Color.White);
            TinyTextDrawer = new TextDrawer(UIDrawer, tinyFont, Color.White);

            Mouse.SetPosition(200, 200);

            ModelDrawer.Clear();
            ConstraintDrawer.Clear();

            if (ServerSimulation != null)
            {
                ServerSimulation.CleanUp();
            }

            Type SimulationType = typeof(WorldSimulator);

            Globals.world    = (WorldSimulator)Activator.CreateInstance(SimulationType, new object[] { this });
            ServerSimulation = Globals.world;

            foreach (Entity e in Globals.space.Entities)
            {
                if ((string)e.Tag != "noDisplayObject")
                {
                    ModelDrawer.Add(e);
                }
                else
                {
                    e.Tag = null;
                }
            }
            for (int i = 0; i < Globals.space.Solver.SolverUpdateables.Count; i++)
            {
                //Add the solver updateable and match up the activity setting.
                LineDisplayObjectBase objectAdded = ConstraintDrawer.Add(Globals.space.Solver.SolverUpdateables[i]);
                if (objectAdded != null)
                {
                    objectAdded.IsDrawing = Globals.space.Solver.SolverUpdateables[i].IsActive;
                }
            }

            GC.Collect();
        }
예제 #2
0
        /// <summary>
        /// Manages the switch to a new physics engine simulation.
        /// </summary>
        /// <param name="sim">Index of the simulation to switch to.</param>
        public void SwitchSimulation(int sim)
        {
            currentSimulationIndex = sim;

            //Clear out any old rendering stuff.
            ModelDrawer.Clear();
            ConstraintDrawer.Clear();

            //Tell the previous simulation it's done.
            if (currentSimulation != null)
            {
                currentSimulation.CleanUp();
            }
            //Create the new demo.
            Type demoType = demoTypes[currentSimulationIndex - 1];

#if !WINDOWS
            currentSimulation = (Demo)demoType.GetConstructor(new[] { typeof(DemosGame) }).Invoke(new object[] { this });
#else
            currentSimulation = (Demo)Activator.CreateInstance(demoType, new object[] { this });
#endif
            #region DisplayObject creation
            foreach (Entity e in currentSimulation.Space.Entities)
            {
                if ((string)e.Tag != "noDisplayObject")
                {
                    ModelDrawer.Add(e);
                }
                else //Remove the now unnecessary tag.
                {
                    e.Tag = null;
                }
            }
            for (int i = 0; i < currentSimulation.Space.Solver.SolverUpdateables.Count; i++)
            {
                //Add the solver updateable and match up the activity setting.
                LineDisplayObjectBase objectAdded = ConstraintDrawer.Add(currentSimulation.Space.Solver.SolverUpdateables[i]);
                if (objectAdded != null)
                {
                    objectAdded.IsDrawing = currentSimulation.Space.Solver.SolverUpdateables[i].IsActive;
                }
            }

            #endregion

            GC.Collect();
        }