Exemple #1
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(new Color(.41f, .41f, .45f, 1));

            var viewMatrix       = Camera.ViewMatrix;
            var projectionMatrix = Camera.ProjectionMatrix;

            if (displayEntities)
            {
                ModelDrawer.Draw(viewMatrix, projectionMatrix);
            }

            if (displayConstraints)
            {
                ConstraintDrawer.Draw(viewMatrix, projectionMatrix);
            }

            LineDrawer.LightingEnabled    = false;
            LineDrawer.VertexColorEnabled = true;
            LineDrawer.World      = Microsoft.Xna.Framework.Matrix.Identity;
            LineDrawer.View       = MathConverter.Convert(viewMatrix);
            LineDrawer.Projection = MathConverter.Convert(projectionMatrix);

            if (displayContacts)
            {
                ContactDrawer.Draw(LineDrawer, Globals.space);
            }

            if (displayBoundingBoxes)
            {
                BoundingBoxDrawer.Draw(LineDrawer, Globals.space);
            }

            if (displaySimulationIslands)
            {
                SimulationIslandDrawer.Draw(LineDrawer, Globals.space);
            }

            base.Draw(gameTime);

            UIDrawer.Begin();
            int bottom = GraphicsDevice.Viewport.Bounds.Height;
            int right  = GraphicsDevice.Viewport.Bounds.Width;

            if (displayUI)
            {
                FPStotalSinceLast += gameTime.ElapsedGameTime.TotalSeconds;
                FPStotalFramesSinceLast++;
                if (gameTime.TotalGameTime.TotalSeconds - FPSlastTime > .25 && gameTime.ElapsedGameTime.TotalSeconds > 0)
                {
                    double avg = FPStotalSinceLast / FPStotalFramesSinceLast;
                    FPSlastTime             = gameTime.TotalGameTime.TotalSeconds;
                    FPStoDisplay            = Math.Round(1 / avg, 1);
                    averagePhysicsTime      = Math.Round(1000 * ServerSimulation.PhysicsTime, 1);
                    FPStotalSinceLast       = 0;
                    FPStotalFramesSinceLast = 0;
                }

                //Display console control terminal
                DrawControlConsole((int)averagePhysicsTime);

                DataTextDrawer.Draw("FPS: ", (int)FPStoDisplay, new Microsoft.Xna.Framework.Vector2(50, bottom - 150));
                DataTextDrawer.Draw("Physics Time (ms): ", (int)averagePhysicsTime, new Microsoft.Xna.Framework.Vector2(50, bottom - 133));
                DataTextDrawer.Draw("Collision Pairs: ", Globals.space.NarrowPhase.Pairs.Count, new Microsoft.Xna.Framework.Vector2(50, bottom - 116));
                if (displayActiveEntityCount)
                {
                    int countActive = 0;
                    for (int i = 0; i < Globals.space.Entities.Count; i++)
                    {
                        if (Globals.space.Entities[i].ActivityInformation.IsActive)
                        {
                            countActive++;
                        }
                    }
                    DataTextDrawer.Draw("Active Objects: ", countActive, new Microsoft.Xna.Framework.Vector2(50, bottom - 99));
                }
                DataTextDrawer.Draw("Press F1 to output camera postion", new Microsoft.Xna.Framework.Vector2(50, bottom - 82));

                ServerSimulation.DrawUI();
            }
            if (displayMenu)
            {
                UIDrawer.Draw(controlsMenu, new Rectangle(right / 2 - 400, bottom / 2 - 300, 800, 600), Color.White);
            }
            UIDrawer.End();
        }
Exemple #2
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(new Color(.41f, .41f, .45f, 1));

            var viewMatrix       = Camera.ViewMatrix;
            var projectionMatrix = Camera.ProjectionMatrix;

            if (displayEntities)
            {
                ModelDrawer.Draw(viewMatrix, projectionMatrix);
            }

            if (displayConstraints)
            {
                ConstraintDrawer.Draw(viewMatrix, projectionMatrix);
            }

            LineDrawer.LightingEnabled    = false;
            LineDrawer.VertexColorEnabled = true;
            LineDrawer.World      = Microsoft.Xna.Framework.Matrix.Identity;
            LineDrawer.View       = MathConverter.Convert(viewMatrix);
            LineDrawer.Projection = MathConverter.Convert(projectionMatrix);

            if (displayContacts)
            {
                ContactDrawer.Draw(LineDrawer, currentSimulation.Space);
            }

            if (displayBoundingBoxes)
            {
                BoundingBoxDrawer.Draw(LineDrawer, currentSimulation.Space);
            }

            if (displaySimulationIslands)
            {
                SimulationIslandDrawer.Draw(LineDrawer, currentSimulation.Space);
            }


            //This doesn't actually draw the elements in the demo (that's the modeldrawer's job),
            //but some demos can specify their own extra stuff to draw.
            currentSimulation.Draw();

            base.Draw(gameTime);

            #region UI Drawing

            UIDrawer.Begin();
            int bottom = GraphicsDevice.Viewport.Bounds.Height;
            int right  = GraphicsDevice.Viewport.Bounds.Width;
            if (displayUI)
            {
                FPStotalSinceLast += gameTime.ElapsedGameTime.TotalSeconds;
                FPStotalFramesSinceLast++;
                if (gameTime.TotalGameTime.TotalSeconds - FPSlastTime > .25 && gameTime.ElapsedGameTime.TotalSeconds > 0)
                {
                    double avg = FPStotalSinceLast / FPStotalFramesSinceLast;
                    FPSlastTime             = gameTime.TotalGameTime.TotalSeconds;
                    FPStoDisplay            = Math.Round(1 / avg, 1);
                    averagePhysicsTime      = Math.Round(1000 * currentSimulation.PhysicsTime, 1);
                    FPStotalSinceLast       = 0;
                    FPStotalFramesSinceLast = 0;
                }

                DataTextDrawer.Draw("FPS: ", (int)FPStoDisplay, new Microsoft.Xna.Framework.Vector2(50, bottom - 150));
                DataTextDrawer.Draw("Physics Time (ms): ", (int)averagePhysicsTime, new Microsoft.Xna.Framework.Vector2(50, bottom - 133));
                DataTextDrawer.Draw("Collision Pairs: ", currentSimulation.Space.NarrowPhase.Pairs.Count, new Microsoft.Xna.Framework.Vector2(50, bottom - 116));
                if (displayActiveEntityCount)
                {
                    int countActive = 0;
                    for (int i = 0; i < currentSimulation.Space.Entities.Count; i++)
                    {
                        if (currentSimulation.Space.Entities[i].ActivityInformation.IsActive)
                        {
                            countActive++;
                        }
                    }
                    DataTextDrawer.Draw("Active Objects: ", countActive, new Microsoft.Xna.Framework.Vector2(50, bottom - 99));
                }
#if !WINDOWS
                DataTextDrawer.Draw("Press Start for Controls", new Vector2(50, bottom - 82));
#else
                DataTextDrawer.Draw("Press F1 for Controls", new Microsoft.Xna.Framework.Vector2(50, bottom - 82));
#endif

                TinyTextDrawer.Draw("Current Simulation: ", currentSimulationIndex, new Microsoft.Xna.Framework.Vector2(right - 200, bottom - 100));
                TinyTextDrawer.Draw(currentSimulation.Name, new Microsoft.Xna.Framework.Vector2(right - 180, bottom - 86));

                currentSimulation.DrawUI();
            }
            if (displayMenu)
            {
                UIDrawer.Draw(controlsMenu, new Rectangle(right / 2 - 400, bottom / 2 - 300, 800, 600), Color.White);
            }
            UIDrawer.End();

            #endregion
        }