More batch fixes
This commit is contained in:
50
OpenRA.Game/Widgets/Delegates/PerfDebugDelegate.cs
Normal file
50
OpenRA.Game/Widgets/Delegates/PerfDebugDelegate.cs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||||
|
* This file is part of OpenRA.
|
||||||
|
*
|
||||||
|
* OpenRA is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* OpenRA is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
using System;
|
||||||
|
using OpenRA.FileFormats;
|
||||||
|
using OpenRA.Support;
|
||||||
|
|
||||||
|
namespace OpenRA.Widgets.Delegates
|
||||||
|
{
|
||||||
|
public class PerfDebugDelegate : IWidgetDelegate
|
||||||
|
{
|
||||||
|
public PerfDebugDelegate()
|
||||||
|
{
|
||||||
|
var r = Chrome.rootWidget;
|
||||||
|
var perfRoot = r.GetWidget("PERF_BG");
|
||||||
|
|
||||||
|
// Perf text
|
||||||
|
var perfText = perfRoot.GetWidget<LabelWidget>("TEXT");
|
||||||
|
perfText.GetText = () => {
|
||||||
|
return "RenderFrame {0} ({2:F1} ms)\nTick {4}/ Net{1} ({3:F1} ms)".F(
|
||||||
|
Game.RenderFrame,
|
||||||
|
Game.orderManager.FrameNumber,
|
||||||
|
PerfHistory.items["render"].LastValue,
|
||||||
|
PerfHistory.items["tick_time"].LastValue,
|
||||||
|
Game.LocalTick);
|
||||||
|
};
|
||||||
|
perfText.IsVisible = () => {return (perfText.Visible && Game.Settings.PerfText);};
|
||||||
|
|
||||||
|
// Perf graph
|
||||||
|
var perfGraph = perfRoot.GetWidget("GRAPH");
|
||||||
|
perfGraph.IsVisible = () => {return (perfGraph.Visible && Game.Settings.PerfGraph);};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -45,50 +45,51 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
public static void DrawPanel(string collection, Rectangle Bounds, Action a)
|
public static void DrawPanel(string collection, Rectangle Bounds, Action a)
|
||||||
{
|
{
|
||||||
var r = Game.chrome.renderer;
|
|
||||||
var sr = Game.chrome.rgbaRenderer;
|
|
||||||
|
|
||||||
|
|
||||||
var images = new[] { "border-t", "border-b", "border-l", "border-r", "corner-tl", "corner-tr", "corner-bl", "corner-br", "background" };
|
var images = new[] { "border-t", "border-b", "border-l", "border-r", "corner-tl", "corner-tr", "corner-bl", "corner-br", "background" };
|
||||||
var ss = images.Select(i => ChromeProvider.GetImage(Game.chrome.renderer, collection, i)).ToArray();
|
var ss = images.Select(i => ChromeProvider.GetImage(Game.chrome.renderer, collection, i)).ToArray();
|
||||||
|
|
||||||
// Don't draw the background below the bottom/right borders
|
// Background
|
||||||
r.Device.EnableScissor(Bounds.Left, Bounds.Top, Bounds.Width - (int)ss[3].size.X, Bounds.Height - (int)ss[1].size.Y);
|
FillRectWithSprite(new Rectangle(Bounds.Left + (int)ss[2].size.X,
|
||||||
for (var x = Bounds.Left + (int)ss[2].size.X; x < Bounds.Right - (int)ss[3].size.X; x += (int)ss[8].size.X)
|
Bounds.Top + (int)ss[0].size.Y,
|
||||||
for (var y = Bounds.Top + (int)ss[0].size.Y; y < Bounds.Bottom - (int)ss[1].size.Y; y += (int)ss[8].size.Y)
|
Bounds.Right - (int)ss[3].size.X - Bounds.Left - (int)ss[2].size.X,
|
||||||
sr.DrawSprite(ss[8], new float2(x, y), "chrome");
|
Bounds.Bottom - (int)ss[1].size.Y - Bounds.Top - (int)ss[0].size.Y),
|
||||||
|
ss[8]);
|
||||||
|
|
||||||
|
// Left border
|
||||||
|
FillRectWithSprite(new Rectangle(Bounds.Left,
|
||||||
|
Bounds.Top + (int)ss[0].size.Y,
|
||||||
|
(int)ss[2].size.X,
|
||||||
|
Bounds.Bottom - (int)ss[1].size.Y - Bounds.Top - (int)ss[0].size.Y),
|
||||||
|
ss[2]);
|
||||||
|
|
||||||
sr.Flush(); // because the scissor is changing
|
// Right border
|
||||||
r.Device.EnableScissor(Bounds.Left, Bounds.Top, Bounds.Width, Bounds.Height - (int)ss[1].size.Y);
|
FillRectWithSprite(new Rectangle(Bounds.Right - (int)ss[3].size.X,
|
||||||
|
Bounds.Top + (int)ss[0].size.Y,
|
||||||
//draw borders
|
(int)ss[2].size.X,
|
||||||
for (var y = Bounds.Top + (int)ss[0].size.Y; y < Bounds.Bottom - (int)ss[1].size.Y; y += (int)ss[2].size.Y)
|
Bounds.Bottom - (int)ss[1].size.Y - Bounds.Top - (int)ss[0].size.Y),
|
||||||
{
|
ss[3]);
|
||||||
sr.DrawSprite(ss[2], new float2(Bounds.Left, y), "chrome");
|
|
||||||
sr.DrawSprite(ss[3], new float2(Bounds.Right - ss[3].size.X, y), "chrome");
|
// Top border
|
||||||
}
|
FillRectWithSprite(new Rectangle(Bounds.Left + (int)ss[2].size.X,
|
||||||
|
Bounds.Top,
|
||||||
sr.Flush(); // because the scissor is changing
|
Bounds.Right - (int)ss[3].size.X - Bounds.Left - (int)ss[2].size.X,
|
||||||
r.Device.EnableScissor(Bounds.Left, Bounds.Top, Bounds.Width - (int)ss[3].size.X, Bounds.Height);
|
(int)ss[0].size.Y),
|
||||||
|
ss[0]);
|
||||||
for (var x = Bounds.Left + (int)ss[2].size.X; x < Bounds.Right - (int)ss[3].size.X; x += (int)ss[0].size.X)
|
|
||||||
{
|
// Bottom border
|
||||||
sr.DrawSprite(ss[0], new float2(x, Bounds.Top), "chrome");
|
FillRectWithSprite(new Rectangle(Bounds.Left + (int)ss[2].size.X,
|
||||||
sr.DrawSprite(ss[1], new float2(x, Bounds.Bottom - ss[1].size.Y), "chrome");
|
Bounds.Bottom - (int)ss[1].size.Y,
|
||||||
}
|
Bounds.Right - (int)ss[3].size.X - Bounds.Left - (int)ss[2].size.X,
|
||||||
|
(int)ss[0].size.Y),
|
||||||
sr.Flush(); // because the scissor is changing
|
ss[1]);
|
||||||
r.Device.EnableScissor(Bounds.Left, Bounds.Top, Bounds.Width, Bounds.Height);
|
|
||||||
|
DrawRGBA(ss[4], new float2(Bounds.Left, Bounds.Top));
|
||||||
sr.DrawSprite(ss[4], new float2(Bounds.Left, Bounds.Top), "chrome");
|
DrawRGBA(ss[5], new float2(Bounds.Right - ss[5].size.X, Bounds.Top));
|
||||||
sr.DrawSprite(ss[5], new float2(Bounds.Right - ss[5].size.X, Bounds.Top), "chrome");
|
DrawRGBA(ss[6], new float2(Bounds.Left, Bounds.Bottom - ss[6].size.Y));
|
||||||
sr.DrawSprite(ss[6], new float2(Bounds.Left, Bounds.Bottom - ss[6].size.Y), "chrome");
|
DrawRGBA(ss[7], new float2(Bounds.Right - ss[7].size.X, Bounds.Bottom - ss[7].size.Y));
|
||||||
sr.DrawSprite(ss[7], new float2(Bounds.Right - ss[7].size.X, Bounds.Bottom - ss[7].size.Y), "chrome");
|
|
||||||
|
|
||||||
if (a != null) a();
|
if (a != null) a();
|
||||||
|
Game.chrome.rgbaRenderer.Flush();
|
||||||
sr.Flush(); // because the scissor is changing
|
|
||||||
r.Device.DisableScissor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void FillRectWithSprite(Rectangle r, Sprite s)
|
public static void FillRectWithSprite(Rectangle r, Sprite s)
|
||||||
@@ -189,8 +190,8 @@ namespace OpenRA.Widgets
|
|||||||
// BR corner
|
// BR corner
|
||||||
DrawRGBA(ss[7], new float2(br.X - (int)ss[7].size.X, br.Y - (int)ss[7].size.Y));
|
DrawRGBA(ss[7], new float2(br.X - (int)ss[7].size.X, br.Y - (int)ss[7].size.Y));
|
||||||
|
|
||||||
Game.chrome.rgbaRenderer.Flush();
|
|
||||||
if (a != null) a();
|
if (a != null) a();
|
||||||
|
Game.chrome.rgbaRenderer.Flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user