From c28faffa45df6e798f95cd611027f454be1e755e Mon Sep 17 00:00:00 2001 From: Pavlos Touboulidis Date: Sat, 26 Apr 2014 23:49:21 +0300 Subject: [PATCH] Remove custom Stopwatch wrapper Remove the redirection (that doesn't offer any new functionality) and replace it with the familiar System.Diagnostics.Stopwatch. --- OpenRA.Game/Game.cs | 3 ++- OpenRA.Game/OpenRA.Game.csproj | 1 - OpenRA.Game/Support/PerfHistory.cs | 3 ++- OpenRA.Game/Support/PerfTimer.cs | 3 ++- OpenRA.Game/Support/Stopwatch.cs | 32 ----------------------------- OpenRA.Game/Traits/Util.cs | 3 ++- OpenRA.Game/WorldUtils.cs | 3 ++- OpenRA.Mods.Cnc/CncLoadScreen.cs | 5 +++-- OpenRA.Mods.RA/DefaultLoadScreen.cs | 5 +++-- OpenRA.Mods.RA/World/DomainIndex.cs | 3 ++- 10 files changed, 18 insertions(+), 43 deletions(-) delete mode 100755 OpenRA.Game/Support/Stopwatch.cs diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index b01405c989..a218d42a71 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -10,6 +10,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; @@ -484,7 +485,7 @@ namespace OpenRA { if (Settings.Graphics.CapFramerate) { - var sw = new Stopwatch(); + var sw = Stopwatch.StartNew(); Tick(orderManager); diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index ac769c9f9b..2832ef2ba7 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -291,7 +291,6 @@ - diff --git a/OpenRA.Game/Support/PerfHistory.cs b/OpenRA.Game/Support/PerfHistory.cs index a226904483..3812b94c86 100644 --- a/OpenRA.Game/Support/PerfHistory.cs +++ b/OpenRA.Game/Support/PerfHistory.cs @@ -10,6 +10,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; using OpenRA.Primitives; @@ -106,7 +107,7 @@ namespace OpenRA.Support public class PerfSample : IDisposable { - readonly Stopwatch sw = new Stopwatch(); + readonly Stopwatch sw = Stopwatch.StartNew(); readonly string Item; public PerfSample(string item) diff --git a/OpenRA.Game/Support/PerfTimer.cs b/OpenRA.Game/Support/PerfTimer.cs index 8fdb4ea5a7..772adf92c5 100755 --- a/OpenRA.Game/Support/PerfTimer.cs +++ b/OpenRA.Game/Support/PerfTimer.cs @@ -9,6 +9,7 @@ #endregion using System; +using System.Diagnostics; using System.Linq; using System.Threading; @@ -16,7 +17,7 @@ namespace OpenRA.Support { public class PerfTimer : IDisposable { - readonly Stopwatch sw = new Stopwatch(); + readonly Stopwatch sw = Stopwatch.StartNew(); readonly string Name; // diff --git a/OpenRA.Game/Support/Stopwatch.cs b/OpenRA.Game/Support/Stopwatch.cs deleted file mode 100755 index 76d2e5b3ae..0000000000 --- a/OpenRA.Game/Support/Stopwatch.cs +++ /dev/null @@ -1,32 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2014 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 - -namespace OpenRA.Support -{ - public class Stopwatch - { - System.Diagnostics.Stopwatch sw; - - public Stopwatch() - { - Reset(); - } - - public System.TimeSpan Elapsed - { - get { return this.sw.Elapsed; } - } - - public void Reset() - { - sw = System.Diagnostics.Stopwatch.StartNew(); - } - } -} diff --git a/OpenRA.Game/Traits/Util.cs b/OpenRA.Game/Traits/Util.cs index 0b347d4e67..4c6daa490a 100755 --- a/OpenRA.Game/Traits/Util.cs +++ b/OpenRA.Game/Traits/Util.cs @@ -10,6 +10,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using OpenRA.Support; @@ -81,7 +82,7 @@ namespace OpenRA.Traits { var prev = act; - var sw = new Stopwatch(); + var sw = Stopwatch.StartNew(); act = act.Tick(self); var dt = sw.Elapsed; if (dt > Game.Settings.Debug.LongTickThreshold) diff --git a/OpenRA.Game/WorldUtils.cs b/OpenRA.Game/WorldUtils.cs index 23141fef10..61d66035ab 100755 --- a/OpenRA.Game/WorldUtils.cs +++ b/OpenRA.Game/WorldUtils.cs @@ -10,6 +10,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; using System.Linq; using OpenRA.FileFormats; @@ -173,7 +174,7 @@ namespace OpenRA public static void DoTimed(this IEnumerable e, Action a, string text, TimeSpan time) { - var sw = new Stopwatch(); + var sw = Stopwatch.StartNew(); e.Do(x => { diff --git a/OpenRA.Mods.Cnc/CncLoadScreen.cs b/OpenRA.Mods.Cnc/CncLoadScreen.cs index 069768d494..28f41fbc88 100644 --- a/OpenRA.Mods.Cnc/CncLoadScreen.cs +++ b/OpenRA.Mods.Cnc/CncLoadScreen.cs @@ -10,6 +10,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; using System.Linq; using OpenRA.FileSystem; @@ -22,7 +23,7 @@ namespace OpenRA.Mods.Cnc public class CncLoadScreen : ILoadScreen { Dictionary loadInfo; - Stopwatch loadTimer = new Stopwatch(); + Stopwatch loadTimer = Stopwatch.StartNew(); Sprite[] ss; int loadTick; float2 nodPos, gdiPos, evaPos; @@ -79,7 +80,7 @@ namespace OpenRA.Mods.Cnc if (r == null || loadTimer.Elapsed.TotalSeconds < 0.25) return; - loadTimer.Reset(); + loadTimer.Restart(); loadTick = ++loadTick % 8; r.BeginFrame(float2.Zero, 1f); diff --git a/OpenRA.Mods.RA/DefaultLoadScreen.cs b/OpenRA.Mods.RA/DefaultLoadScreen.cs index ef9427ff1a..a2920218e6 100644 --- a/OpenRA.Mods.RA/DefaultLoadScreen.cs +++ b/OpenRA.Mods.RA/DefaultLoadScreen.cs @@ -10,6 +10,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; using System.Linq; using OpenRA.FileSystem; @@ -23,7 +24,7 @@ namespace OpenRA.Mods.RA public class DefaultLoadScreen : ILoadScreen { Dictionary info; - Stopwatch lastUpdate = new Stopwatch(); + Stopwatch lastUpdate = Stopwatch.StartNew(); Renderer r; Rectangle stripeRect; @@ -61,7 +62,7 @@ namespace OpenRA.Mods.RA if (r.Fonts == null) return; - lastUpdate.Reset(); + lastUpdate.Restart(); var text = messages.Random(Game.CosmeticRandom); var textSize = r.Fonts["Bold"].Measure(text); diff --git a/OpenRA.Mods.RA/World/DomainIndex.cs b/OpenRA.Mods.RA/World/DomainIndex.cs index 1b9dfec858..64b655bbbe 100644 --- a/OpenRA.Mods.RA/World/DomainIndex.cs +++ b/OpenRA.Mods.RA/World/DomainIndex.cs @@ -9,6 +9,7 @@ #endregion using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; using System.Linq; using OpenRA.Graphics; @@ -187,7 +188,7 @@ namespace OpenRA.Mods.RA void BuildDomains(World world) { - var timer = new Stopwatch(); + var timer = Stopwatch.StartNew(); var map = world.Map; var domain = 1;