Beispiel #1
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)
 {
     Monitor.DrawCalled();
     GraphicsDevice.Clear(Color.Transparent);
     if (xMenu != null)
     {
         xMenu.Draw(spriteBatch);
     }
     spriteBatch.Begin();
     spriteBatch.Draw(pixelText, new Rectangle(MouseInput.MousePosition, new Point(3, 3)), Color.Red);
     spriteBatch.DrawString(font, "UpdateRate: " + Monitor.UpdateRate, new Vector2(10, 10), Color.Red, 0, new Vector2(0, 0), 0.25f, SpriteEffects.None, 1);
     spriteBatch.DrawString(font, "DrawRate: " + Monitor.FrameRate, new Vector2(10, 30), Color.Red, 0, new Vector2(0, 0), 0.25f, SpriteEffects.None, 1);
     spriteBatch.End();
     // TODO: Add your drawing code here
     base.Draw(gameTime);
 }
Beispiel #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)
        {
            bool found = false;

            MonoMenu.Engine.Monitor.DrawCalled();

            MatrixD  cameraTransf = Camera.Instance.Transform;
            Vector3D transl       = cameraTransf.Translation;
            Vector2D mClkPos      = new Vector2D(clickPos.X - GraphicsDevice.PresentationParameters.BackBufferWidth / 2, clickPos.Y - GraphicsDevice.PresentationParameters.BackBufferHeight / 2);

            mClkPos /= Camera.Instance.Zoom;
            mClkPos += Camera.Instance.Position;
            string fps = "FPS: " + (1 / gameTime.ElapsedGameTime.TotalSeconds);
            string bods = "Bodies: " + (Galaxy.Instance.Stars.Count + Galaxy.Instance.Planets.Count);
            string markedToRemove = "Marked to be removed: " + Galaxy.Instance.ToRemove;
            string iterations = "Iterations: " + Galaxy.Instance.Iterations;
            string memoryusg = "Memory Usage: " + (MonoMenu.Engine.Monitor.MemoryUsage / 10e5);
            string camerapos = "Camera position: " + (int)Camera.Instance.Position.X + " " + (int)Camera.Instance.Position.Y;
            string mousepos = "Mouse position: " + (int)mClkPos.X + " " + (int)mClkPos.Y;
            string zoomlvl = "Zoom level: " + Camera.Instance.Zoom;
            string following = string.Empty, mass = string.Empty, pxpy = string.Empty, vxvy = string.Empty;

            if (Camera.Instance.Following != null)
            {
                following = "Following: " + Camera.Instance.Following.id;
                if (Camera.Instance.Following is Star)
                {
                    double m = Camera.Instance.Following.mass / Constants.SUN_MASS;
                    mass = "Mass: " + m.ToString("0.##E+0", CultureInfo.InvariantCulture) + " SM";
                }
                else
                {
                    double m = Camera.Instance.Following.mass / Constants.EARTH_SIZE;
                    mass       = "Mass: " + m.ToString("0.##E+0", CultureInfo.InvariantCulture) + " EM + Size: " + Camera.Instance.Following.size;
                    following += " Star: " + (Camera.Instance.Following as Planet).Star.id;
                }
                pxpy = "pX: " + Camera.Instance.Following.posX + " - pY: " + Camera.Instance.Following.posY;
                vxvy = "vX: " + Camera.Instance.Following.vX + " - vY: " + Camera.Instance.Following.vY;
            }
            Menu["fpsRect"].Text    = fps;
            Menu["bodsRect"].Text   = bods;
            Menu["markedRect"].Text = markedToRemove;
            Menu["itRect"].Text     = iterations;
            Menu["memRect"].Text    = memoryusg;
            Menu["camRect"].Text    = camerapos;
            Menu["mouseRect"].Text  = mousepos;
            Menu["zoomRect"].Text   = zoomlvl;
            Menu["followRect"].Text = following;
            Menu["massRect"].Text   = mass;
            Menu["pxpyRect"].Text   = pxpy;
            Menu["vxvyRect"].Text   = vxvy;
            Menu.Draw(spriteBatch, monoRenderTarget);


            GraphicsDevice.SetRenderTarget(preProcessRenderTarget);
            // TODO: Add your drawing code here
            spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, null);

            GraphicsDevice.Clear(Color.Black);
            if (Camera.Instance.Zoom * Constants.SUN_SIZE * 10 >= 1)
            {
                while (!System.Threading.Monitor.TryEnter(Galaxy.Instance.starListLock))
                {
                    ;
                }
                foreach (Star body in Galaxy.Instance.Stars)
                {
                    RectangleD destRect = new RectangleD(body.posX - body.size / 2, body.posY - body.size / 2, body.size, body.size);
                    if (Camera.Instance.VisibleArea.Contains(destRect) || Camera.Instance.VisibleArea.Intersects(destRect))
                    {
                        if (destRect.Contains(mClkPos) && leftMousePressed)
                        {
                            found = true;
                            Camera.Instance.Follow(body);
                        }
                        Color  color = GetStarColor(body);
                        double size  = body.size * Camera.Instance.Zoom;
                        double posX  = (body.posX * Camera.Instance.Zoom) + transl.X - size / 2;
                        double posY  = (body.posY * Camera.Instance.Zoom) + transl.Y - size / 2;
                        spriteBatch.Draw(circle.CircleText, new Rectangle((int)posX, (int)posY, (int)size, (int)size), color);
                        //spriteBatch.Draw(circle.CircleText, new Microsoft.Xna.Framework.Rectangle((int)(body.Position.X + graphics.PreferredBackBufferWidth / 2 - 2.5), (int)(body.Position.Y + graphics.PreferredBackBufferHeight / 2 - 2.5), 5, 5), Color.Red);
                    }
                }
                System.Threading.Monitor.Exit(Galaxy.Instance.starListLock);
            }
            spriteBatch.End();

            Texture2D bloom = bloomFilter.Draw(preProcessRenderTarget, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);

            GraphicsDevice.SetRenderTarget(planetRenderTarget);

            spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, null);
            GraphicsDevice.Clear(Color.Black);

            while (!System.Threading.Monitor.TryEnter(Galaxy.Instance.planetListLock))
            {
                ;
            }
            foreach (Planet body in Galaxy.Instance.Planets)
            {
                RectangleD destRect = new RectangleD(body.posX - body.size / 2, body.posY - body.size / 2, body.size, body.size);
                if (Camera.Instance.VisibleArea.Contains(destRect) || Camera.Instance.VisibleArea.Intersects(destRect))
                {
                    if (destRect.Contains(mClkPos) && leftMousePressed)
                    {
                        found = true;
                        Camera.Instance.Follow(body);
                    }
                    Color  color = GetPlanetColor(body);
                    double size  = body.size * Camera.Instance.Zoom;
                    double posX  = (body.posX * Camera.Instance.Zoom) + transl.X - size / 2;
                    double posY  = (body.posY * Camera.Instance.Zoom) + transl.Y - size / 2;
                    spriteBatch.Draw(circle.CircleText, new Rectangle((int)Math.Round(posX), (int)Math.Round(posY), (int)Math.Round(size), (int)Math.Round(size)), color);
                    //spriteBatch.Draw(circle.CircleText, new Microsoft.Xna.Framework.Rectangle((int)(body.Position.X + graphics.PreferredBackBufferWidth / 2 - 2.5), (int)(body.Position.Y + graphics.PreferredBackBufferHeight / 2 - 2.5), 5, 5), Color.Red);
                }
            }
            System.Threading.Monitor.Exit(Galaxy.Instance.planetListLock);
            if (leftMousePressed && !found)
            {
                Camera.Instance.Follow(null);
            }

            spriteBatch.End();

            #region Draw quad outline
            if (pause)
            {
                while (!System.Threading.Monitor.TryEnter(Galaxy.Instance.quadLock))
                {
                }
                GraphicsDevice.SetRenderTarget(gridRenderTarget);
                spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, null, null, null);
                Galaxy.Instance.root.DrawOutline(spriteBatch, pixel, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight, Camera.Instance.VisibleArea, transl);
                System.Threading.Monitor.Exit(Galaxy.Instance.quadLock);
                spriteBatch.End();
            }
            #endregion


            GraphicsDevice.SetRenderTarget(null);
            spriteBatch.Begin(SpriteSortMode.Texture, BlendState.Additive);
            spriteBatch.Draw(preProcessRenderTarget, new Vector2(0, 0), Color.White);
            spriteBatch.Draw(bloom, new Vector2(-3f, -3f), Color.White);
            spriteBatch.Draw(planetRenderTarget, new Vector2(0, 0), Color.White);
            if (pause)
            {
                spriteBatch.Draw(gridRenderTarget, new Vector2(0, 0), Color.White);
            }
            spriteBatch.Draw(pixel, new Rectangle(new Point(MouseInput.MousePosition.X - 2, MouseInput.MousePosition.Y - 2), new Point(4, 4)), Color.Red);
            spriteBatch.Draw(monoRenderTarget, new Rectangle(0, 0, monoRenderTarget.Width, monoRenderTarget.Height), Color.White);
            spriteBatch.End();
            base.Draw(gameTime);
            leftMousePressed = false;
        }