diff --git a/OpenRA.Game/GameRules/Settings.cs b/OpenRA.Game/GameRules/Settings.cs index 334571f6b2..2e8355e68a 100755 --- a/OpenRA.Game/GameRules/Settings.cs +++ b/OpenRA.Game/GameRules/Settings.cs @@ -34,9 +34,11 @@ namespace OpenRA.GameRules public class DebugSettings { public bool BotDebug = false; + public bool PerfText = false; public bool PerfGraph = false; public float LongTickThreshold = 0.001f; public bool SanityCheckUnsyncedCode = false; + public int Samples = 25; } public class GraphicSettings diff --git a/OpenRA.Game/Support/PerfHistory.cs b/OpenRA.Game/Support/PerfHistory.cs index 4eaaedfdc1..00610b9dd8 100644 --- a/OpenRA.Game/Support/PerfHistory.cs +++ b/OpenRA.Game/Support/PerfHistory.cs @@ -79,6 +79,20 @@ namespace OpenRA.Support } } + public double Average(int count) + { + int i = 0; + int n = head; + double sum = 0; + while (i < count && n != tail) + { + if (--n < 0) n = samples.Length - 1; + sum += samples[n]; + i++; + } + return sum / i; + } + public double LastValue { get diff --git a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj index beca7c62e1..b22fb2e5f3 100644 --- a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj +++ b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj @@ -83,6 +83,7 @@ + diff --git a/OpenRA.Mods.Cnc/Widgets/CncPerfDebugLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncPerfDebugLogic.cs new file mode 100644 index 0000000000..9abc3d6dbc --- /dev/null +++ b/OpenRA.Mods.Cnc/Widgets/CncPerfDebugLogic.cs @@ -0,0 +1,34 @@ +#region Copyright & License Information +/* + * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +using System; +using OpenRA.Support; +using OpenRA.Widgets; + +namespace OpenRA.Mods.Cnc.Widgets +{ + public class CncPerfDebugLogic : IWidgetDelegate + { + [ObjectCreator.UseCtor] + public CncPerfDebugLogic([ObjectCreator.Param] Widget widget) + { + // Performance info + var perfRoot = widget.GetWidget("PERFORMANCE_INFO"); + perfRoot.GetWidget("PERF_GRAPH").IsVisible = () => Game.Settings.Debug.PerfGraph; + var text = perfRoot.GetWidget("PERF_TEXT"); + text.IsVisible = () => Game.Settings.Debug.PerfText; + text.GetText = () => + "Tick {0} @ {1:F1} ms\nRender {2} @ {3:F1} ms\nBatches: {4}".F( + Game.LocalTick, PerfHistory.items["tick_time"].Average(Game.Settings.Debug.Samples), + Game.RenderFrame, PerfHistory.items["render"].Average(Game.Settings.Debug.Samples), + PerfHistory.items["batches"].LastValue); + } + } +} diff --git a/mods/cnc/chrome/ingame.yaml b/mods/cnc/chrome/ingame.yaml index c22dd86755..b3bd9d1dd7 100644 --- a/mods/cnc/chrome/ingame.yaml +++ b/mods/cnc/chrome/ingame.yaml @@ -127,4 +127,21 @@ Container@INGAME_ROOT: Y:WINDOW_BOTTOM - HEIGHT Width: 760 Height: 30 - UseContrast: yes \ No newline at end of file + UseContrast: yes + Container@PERFORMANCE_INFO: + Id:PERFORMANCE_INFO + Delegate:CncPerfDebugLogic + Children: + Label@PERF_TEXT: + Id:PERF_TEXT + X:10 + Y:45 + Width:170 + Height:40 + Contrast:true + PerfGraph@GRAPH: + Id:PERF_GRAPH + X:10 + Y:WINDOW_BOTTOM-HEIGHT-10 + Width:200 + Height:200 \ No newline at end of file diff --git a/mods/cnc/chrome/mainmenu.yaml b/mods/cnc/chrome/mainmenu.yaml index 2052396559..6b62006964 100644 --- a/mods/cnc/chrome/mainmenu.yaml +++ b/mods/cnc/chrome/mainmenu.yaml @@ -157,3 +157,28 @@ Container@MENU_BACKGROUND: Width:140 Height:35 Text:Back + Container@PERFORMANCE_INFO: + Id:PERFORMANCE_INFO + Delegate:CncPerfDebugLogic + Children: + Label@PERF_TEXT: + Id:PERF_TEXT + X:40 + Y:40 + Width:170 + Height:40 + Contrast:true + VAlign:Top + Background@GRAPH_BG: + Id:PERF_GRAPH + X:WINDOW_RIGHT-WIDTH-31 + Y:31 + Width:220 + Height:220 + Background:panel-black + Children: + PerfGraph@GRAPH: + X:10 + Y:10 + Width:200 + Height:200 \ No newline at end of file