Perf debug as widgets

This commit is contained in:
Paul Chote
2010-04-11 13:49:37 +12:00
parent 5ac1d25d43
commit 559a0107fe
8 changed files with 123 additions and 52 deletions

View File

@@ -162,18 +162,6 @@ namespace OpenRA
renderer.Device.DisableScissor(); renderer.Device.DisableScissor();
if (Game.Settings.PerfText)
renderer.RegularFont.DrawText( rgbaRenderer, "RenderFrame {0} ({2:F1} ms)\nTick {4}/ Net{1} ({3:F1} ms)\n".F(
Game.RenderFrame,
Game.orderManager.FrameNumber,
PerfHistory.items["render"].LastValue,
PerfHistory.items["tick_time"].LastValue,
Game.LocalTick),
new int2(140, 15), Color.White);
if (Game.Settings.PerfGraph)
PerfHistory.Render(renderer, world.WorldRenderer.lineRenderer);
DrawRadar( world ); DrawRadar( world );
DrawPower( world ); DrawPower( world );
rgbaRenderer.DrawSprite(ChromeProvider.GetImage(renderer, chromeCollection, "moneybin"), new float2(Game.viewport.Width - 320, 0), "chrome"); rgbaRenderer.DrawSprite(ChromeProvider.GetImage(renderer, chromeCollection, "moneybin"), new float2(Game.viewport.Width - 320, 0), "chrome");

View File

@@ -297,6 +297,7 @@
<Compile Include="Widgets\Delegates\IngameChromeDelegate.cs" /> <Compile Include="Widgets\Delegates\IngameChromeDelegate.cs" />
<Compile Include="Widgets\SpecialPowerBinWidget.cs" /> <Compile Include="Widgets\SpecialPowerBinWidget.cs" />
<Compile Include="Widgets\Delegates\MusicPlayerDelegate.cs" /> <Compile Include="Widgets\Delegates\MusicPlayerDelegate.cs" />
<Compile Include="Widgets\PerfGraphWidget.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj"> <ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA. * This file is part of OpenRA.
@@ -55,31 +55,6 @@ namespace OpenRA.Support
if (item.hasNormalTick) if (item.hasNormalTick)
item.Tick(); item.Tick();
} }
public static void Render(Renderer r, LineRenderer lr)
{
float2 origin = Game.viewport.Location + new float2(330, Game.viewport.Height - 30);
float2 basis = new float2(-3, -3);
lr.DrawLine(origin, origin + new float2(100, 0) * basis, Color.White, Color.White);
lr.DrawLine(origin + new float2(100,0) * basis, origin + new float2(100,70) * basis, Color.White, Color.White);
foreach (var item in items.Values)
{
int n = 0;
item.Samples().Aggregate((a, b) =>
{
lr.DrawLine(
origin + new float2(n, (float)a) * basis,
origin + new float2(n+1, (float)b) * basis,
item.c, item.c);
++n;
return b;
});
}
lr.Flush();
}
} }
class PerfItem class PerfItem

View File

@@ -19,6 +19,8 @@
#endregion #endregion
using System; using System;
using OpenRA.FileFormats; using OpenRA.FileFormats;
using OpenRA.Support;
namespace OpenRA.Widgets.Delegates namespace OpenRA.Widgets.Delegates
{ {
public class IngameChromeDelegate : IWidgetDelegate public class IngameChromeDelegate : IWidgetDelegate
@@ -26,7 +28,8 @@ namespace OpenRA.Widgets.Delegates
public IngameChromeDelegate() public IngameChromeDelegate()
{ {
var r = Chrome.rootWidget; var r = Chrome.rootWidget;
var optionsBG = r.GetWidget("INGAME_OPTIONS_BG"); var gameRoot = r.GetWidget("INGAME_ROOT");
var optionsBG = gameRoot.GetWidget("INGAME_OPTIONS_BG");
r.GetWidget("INGAME_OPTIONS_BUTTON").OnMouseUp = mi => { r.GetWidget("INGAME_OPTIONS_BUTTON").OnMouseUp = mi => {
optionsBG.Visible = !optionsBG.Visible; optionsBG.Visible = !optionsBG.Visible;
return true; return true;
@@ -49,6 +52,21 @@ namespace OpenRA.Widgets.Delegates
return true; return true;
}; };
// Perf text
var perfText = gameRoot.GetWidget<LabelWidget>("PERFTEXT");
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 = gameRoot.GetWidget("PERFGRAPH");
perfGraph.IsVisible = () => {return (perfGraph.Visible && Game.Settings.PerfGraph);};
} }
} }
} }

View File

@@ -19,6 +19,7 @@
#endregion #endregion
using System.Drawing; using System.Drawing;
using System;
namespace OpenRA.Widgets namespace OpenRA.Widgets
{ {
@@ -26,26 +27,35 @@ namespace OpenRA.Widgets
{ {
public string Text = ""; public string Text = "";
public string Align = "Left"; public string Align = "Left";
public bool Bold = true;
public Func<string> GetText;
public override void Initialize()
{
base.Initialize();
GetText = () => {return Text;};
}
public override void Draw(World world) public override void Draw(World world)
{ {
if (!Visible) if (!IsVisible())
{ {
base.Draw(world); base.Draw(world);
return; return;
} }
Rectangle r = Bounds;
Game.chrome.renderer.Device.EnableScissor(r.Left, r.Top, r.Width, r.Height);
int2 textSize = Game.chrome.renderer.BoldFont.Measure(Text); var font = (Bold) ? Game.chrome.renderer.BoldFont : Game.chrome.renderer.RegularFont;
var text = GetText();
Rectangle r = Bounds;
Game.chrome.renderer.Device.EnableScissor(r.Left,r.Top,r.Width,r.Height);
int2 textSize = font.Measure(text);
int2 position = new int2(Bounds.X,Bounds.Y); int2 position = new int2(Bounds.X,Bounds.Y);
if (Align == "Center") if (Align == "Center")
position = new int2(Bounds.X+Bounds.Width/2, Bounds.Y+Bounds.Height/2) position = new int2(Bounds.X+Bounds.Width/2, Bounds.Y+Bounds.Height/2)
- new int2(textSize.X / 2, textSize.Y/2); - new int2(textSize.X / 2, textSize.Y/2);
Game.chrome.renderer.BoldFont.DrawText(Game.chrome.rgbaRenderer, Text, position, Color.White); font.DrawText(Game.chrome.rgbaRenderer, text, position, Color.White);
Game.chrome.rgbaRenderer.Flush(); Game.chrome.rgbaRenderer.Flush();
Game.chrome.renderer.Device.DisableScissor(); Game.chrome.renderer.Device.DisableScissor();
base.Draw(world); base.Draw(world);

View File

@@ -0,0 +1,62 @@
#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.Drawing;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Support;
namespace OpenRA.Widgets
{
class PerfGraphWidget : Widget
{
public override void Draw(World world)
{
if (!IsVisible())
{
base.Draw(world);
return;
}
float2 origin = Game.viewport.Location + new float2(Bounds.Right,Bounds.Bottom);
float2 basis = new float2(-Bounds.Width/100,-Bounds.Height/100);
Game.chrome.lineRenderer.DrawLine(origin, origin + new float2(100, 0) * basis, Color.White, Color.White);
Game.chrome.lineRenderer.DrawLine(origin + new float2(100,0) * basis, origin + new float2(100,70) * basis, Color.White, Color.White);
foreach (var item in PerfHistory.items.Values)
{
int n = 0;
item.Samples().Aggregate((a, b) =>
{
Game.chrome.lineRenderer.DrawLine(
origin + new float2(n, (float)a) * basis,
origin + new float2(n+1, (float)b) * basis,
item.c, item.c);
++n;
return b;
});
}
Game.chrome.lineRenderer.Flush();
base.Draw(world);
}
}
}

View File

@@ -48,6 +48,12 @@ namespace OpenRA.Widgets
public Widget() { InputHandler = Lazy.New(() => BindHandler(Delegate)); } public Widget() { InputHandler = Lazy.New(() => BindHandler(Delegate)); }
// Common Funcs that most widgets will want
public Func<MouseInput,bool> OnMouseDown = mi => {return false;};
public Func<MouseInput,bool> OnMouseUp = mi => {return false;};
public Func<MouseInput,bool> OnMouseMove = mi => {return false;};
public Func<bool> IsVisible;
public virtual void Initialize() public virtual void Initialize()
{ {
// Parse the YAML equations to find the widget bounds // Parse the YAML equations to find the widget bounds
@@ -69,6 +75,8 @@ namespace OpenRA.Widgets
width, width,
height); height);
// Non-static func definitions
IsVisible = () => {return Visible;};
foreach (var child in Children) foreach (var child in Children)
child.Initialize(); child.Initialize();
@@ -87,13 +95,7 @@ namespace OpenRA.Widgets
if (name == null) return null; if (name == null) return null;
return Game.CreateObject<IWidgetDelegate>(name); return Game.CreateObject<IWidgetDelegate>(name);
} }
// Common Funcs that most widgets will want
public Func<MouseInput,bool> OnMouseDown = mi => {return false;};
public Func<MouseInput,bool> OnMouseUp = mi => {return false;};
public Func<MouseInput,bool> OnMouseMove = mi => {return false;};
public virtual bool HandleInput(MouseInput mi) public virtual bool HandleInput(MouseInput mi)
{ {
// Are we able to handle this event? // Are we able to handle this event?

View File

@@ -261,6 +261,21 @@ Container:
Id:INGAME_ROOT Id:INGAME_ROOT
Visible:false Visible:false
Children: Children:
PerfGraph@PERFGRAPH:
Id:PERFGRAPH
X:10
Y:WINDOW_BOTTOM - 250
Width:200
Height:200
Delegate:IngameChromeDelegate
Label@PERFTEXT:
Id:PERFTEXT
Bold: false
X:10
Y:WINDOW_BOTTOM - 40
Width:200
Height:100
Delegate:IngameChromeDelegate
SpecialPowerBin@INGAME_POWERS_BIN: SpecialPowerBin@INGAME_POWERS_BIN:
Id:INGAME_POWERS_BIN Id:INGAME_POWERS_BIN
X:0 X:0