public void Generate(Block[,,] blocks, ChunkInfo info) { while (RuntimeGame.DeviceForStateValidationOutput == null) continue; lock (RuntimeGame.LockForStateValidationOutput) { Console.Write("Locked graphics. Rendering graph to file..."); RainfallInformation rainfall = info.Objects.First(val => val is RainfallInformation) as RainfallInformation; TemperatureInformation temperature = info.Objects.First(val => val is TemperatureInformation) as TemperatureInformation; PresentationParameters pp = RuntimeGame.DeviceForStateValidationOutput.PresentationParameters; RenderTarget2D renderTarget = new RenderTarget2D(RuntimeGame.DeviceForStateValidationOutput, 200, 200, true, RuntimeGame.DeviceForStateValidationOutput.DisplayMode.Format, DepthFormat.Depth24); RuntimeGame.DeviceForStateValidationOutput.SetRenderTarget(renderTarget); RuntimeGame.ContextForStateValidationOutput.SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone);//, SaveStateMode.None, Matrix.Identity); //graphics.GraphicsDevice.SamplerStates[0].MagFilter = TextureFilter.Point; //graphics.GraphicsDevice.SamplerStates[0].MinFilter = TextureFilter.Point; //graphics.GraphicsDevice.SamplerStates[0].MipFilter = TextureFilter.Point; XnaGraphics graphics = new XnaGraphics(RuntimeGame.ContextForStateValidationOutput); if (File.Exists("state.png")) { using (StreamReader reader = new StreamReader("state.png")) { Texture2D tex = Texture2D.FromStream(RuntimeGame.DeviceForStateValidationOutput, reader.BaseStream); RuntimeGame.ContextForStateValidationOutput.SpriteBatch.Draw(tex, new Rectangle(0, 0, 200, 200), Color.White); } } else { graphics.FillRectangle(0, 0, 200, 200, Color.Red); graphics.FillRectangle(0, 0, 100, 100, Color.White); } for (int x = 0; x < info.Bounds.Width; x++) for (int y = 0; y < info.Bounds.Height; y++) { int r = 100 - (int)(rainfall.Rainfall[x, y] * 100); int t = 100 - (int)(temperature.Temperature[x, y] * 100); graphics.DrawLine(r, t, r + 1, t + 1, 1, new Color(0f, 0f, 0f, 0.1f).ToPremultiplied()); } RuntimeGame.ContextForStateValidationOutput.SpriteBatch.End(); RuntimeGame.DeviceForStateValidationOutput.SetRenderTarget(null); using (StreamWriter writer = new StreamWriter("state.png")) { renderTarget.SaveAsPng(writer.BaseStream, 200, 200); } Console.WriteLine(" done."); } }
public void Render(GameContext context, XnaGraphics xna) { Point center = this.m_FieldOfView.World.GetCenter(); for (int x = 0; x < this.m_FieldOfView.BroadphaseGrid.GetLength(0); x++) for (int y = 0; y < this.m_FieldOfView.BroadphaseGrid.GetLength(1); y++) { if (!this.m_FieldOfView.BroadphaseGrid[x, y]) xna.FillRectangle(new Rectangle(x * Seperation, y * Seperation, Seperation, Seperation), new Color(0f, 0f, 0f, 0.4f).ToPremultiplied()); if (x == center.X && y == center.Y) xna.FillRectangle(new Rectangle(x * Seperation, y * Seperation, Seperation, Seperation), new Color(1f, 0f, 0f, 1).ToPremultiplied()); //xna.DrawStringLeft(x * Seperation, y * Seperation, this.m_FieldOfView.m_BroadphaseHeightGrid[x, y].ToString()); int deg = (int)MathHelper.ToDegrees(this.m_FieldOfView.m_BroadphaseAngleGrid[x, y]); xna.DrawStringLeft(x * Seperation, y * Seperation, deg.ToString(), "SmallArial"); /*if (deg < -100) xna.DrawStringLeft(x * Seperation, y * Seperation, Math.Abs(deg + 100).ToString()); else if (deg < 0) xna.DrawStringLeft(x * Seperation, y * Seperation, Math.Abs(deg).ToString()); else if (deg < 100) xna.DrawStringLeft(x * Seperation, y * Seperation, (deg).ToString()); else if (deg < 200) xna.DrawStringLeft(x * Seperation, y * Seperation, (deg - 100).ToString());*/ } }
public void Process(XnaGraphics xna, MouseState mouse) { if (this.m_PulseValue >= 1) this.m_PulseModeUp = false; else if (this.m_PulseValue <= 0) this.m_PulseModeUp = true; this.m_PulseValue += this.m_PulseModeUp ? 0.01 : -0.01; if (this.m_Area.Contains(mouse.X, mouse.Y) && mouse.LeftButton == ButtonState.Pressed) this.m_OnClick(); if (this.m_Area.Contains(mouse.X, mouse.Y)) xna.FillRectangle(this.m_Area, new Color(1f, 1f, 1f, 0.25f + (float)(this.m_PulseValue / 2.0)).ToPremultiplied()); else xna.FillRectangle(this.m_Area, new Color(1f, 1f, 1f, 0.1f + (float)(this.m_PulseValue / 32.0)).ToPremultiplied()); xna.DrawStringCentered(this.m_Area.X + this.m_Area.Width / 2, this.m_Area.Y + 4, this.m_Text, "ButtonFont"); }
public override void DrawAbove(GameContext context) { // Are we waiting for players? #if MULTIPLAYER if (this.m_GlobalSession.Waiting || (this.m_GlobalSession.LoadingInitialData && !LocalNode.Singleton.IsServer)) #else if (this.m_GlobalSession.Waiting) #endif { XnaGraphics graphics = new XnaGraphics(context); graphics.FillRectangle(new Rectangle(0, 0, context.Graphics.GraphicsDevice.Viewport.Width, context.Graphics.GraphicsDevice.Viewport.Height), Color.Black); int dialogX = context.Graphics.GraphicsDevice.Viewport.X + context.Graphics.GraphicsDevice.Viewport.Width / 2 - 300; int dialogY = context.Graphics.GraphicsDevice.Viewport.Y + context.Graphics.GraphicsDevice.Viewport.Height / 2 - 200; graphics.FillRectangle(new Rectangle(dialogX, dialogY, 600, 400), Color.DarkSlateGray); graphics.DrawStringCentered(dialogX + 300, dialogY + 8, this.m_GlobalSession.LobbyMessage, "BigArial"); graphics.DrawStringCentered(dialogX + 300, dialogY + 32, "Press enter to toggle ready status."); int a = 0; for (int i = 0; i < this.m_GlobalSession.Players.Count; i++) { Player p = this.m_GlobalSession.Players[i]; if (p.Ready) graphics.DrawStringLeft(dialogX + 8, dialogY + 48 + a * 16, "Player " + a + " (" + p.PlayerID + ") ready."); else graphics.DrawStringLeft(dialogX + 8, dialogY + 48 + a * 16, "Player " + a + " (" + p.PlayerID + ") not ready."); a++; } return; } // Handle game normally. if (this.m_ActiveLevel != null) this.m_ActiveLevel.DrawAbove(context); this.m_UiManager.Draw(this, context, new XnaGraphics(context)); }