From 275f6683c69ac9689cdb936fba9334816c4cdc46 Mon Sep 17 00:00:00 2001 From: Pavlos Touboulidis Date: Sat, 26 Apr 2014 23:28:23 +0300 Subject: [PATCH 1/3] Remove unused and obsolete Cached.cs This was similar to Lazy --- OpenRA.Game/OpenRA.Game.csproj | 1 - OpenRA.Game/Primitives/Cached.cs | 55 -------------------------------- 2 files changed, 56 deletions(-) delete mode 100644 OpenRA.Game/Primitives/Cached.cs diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 3447fecd9c..ac769c9f9b 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -281,7 +281,6 @@ - diff --git a/OpenRA.Game/Primitives/Cached.cs b/OpenRA.Game/Primitives/Cached.cs deleted file mode 100644 index 269a074aeb..0000000000 --- a/OpenRA.Game/Primitives/Cached.cs +++ /dev/null @@ -1,55 +0,0 @@ -#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; - -namespace OpenRA.Primitives -{ - public class Cached - { - Func p; - T value; - bool hasValue; - - public Cached(Func p) - { - if (p == null) - throw new ArgumentNullException(); - - this.p = p; - } - - public T Value - { - get - { - if (hasValue) - return value; - - value = p(); - hasValue = true; - return value; - } - } - - public T Force() { return Value; } - - public void Invalidate() - { - hasValue = false; - } - } - - public static class Cached - { - public static Cached New(Func p) { return new Cached(p); } - } -} - From c28faffa45df6e798f95cd611027f454be1e755e Mon Sep 17 00:00:00 2001 From: Pavlos Touboulidis Date: Sat, 26 Apr 2014 23:49:21 +0300 Subject: [PATCH 2/3] 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; From 45944a053c71af229bc42c9a50de6a1b893f9732 Mon Sep 17 00:00:00 2001 From: Pavlos Touboulidis Date: Sun, 27 Apr 2014 00:01:33 +0300 Subject: [PATCH 3/3] Replace (and remove) custom Set with HashSet --- OpenRA.Game/OpenRA.Game.csproj | 1 - OpenRA.Game/Primitives/Set.cs | 56 ---------------------------------- OpenRA.Game/World.cs | 2 +- 3 files changed, 1 insertion(+), 58 deletions(-) delete mode 100755 OpenRA.Game/Primitives/Set.cs diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 2832ef2ba7..2271cc2038 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -289,7 +289,6 @@ - diff --git a/OpenRA.Game/Primitives/Set.cs b/OpenRA.Game/Primitives/Set.cs deleted file mode 100755 index 43c76648eb..0000000000 --- a/OpenRA.Game/Primitives/Set.cs +++ /dev/null @@ -1,56 +0,0 @@ -#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 System.Collections; -using System.Collections.Generic; - -namespace OpenRA.Primitives -{ - public class Set : IEnumerable - { - Dictionary data = new Dictionary(); - - public void Add( T obj ) - { - data.Add( obj, false ); - if( OnAdd != null ) - OnAdd( obj ); - } - - public void Remove( T obj ) - { - data.Remove( obj ); - if( OnRemove != null ) - OnRemove( obj ); - } - - public event Action OnAdd; - public event Action OnRemove; - - public IEnumerator GetEnumerator() - { - return data.Keys.GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - - public bool Contains( T obj ) { return data.ContainsKey(obj); } - - public Set( params T[] ts ) - { - foreach( var t in ts ) - Add(t); - } - } -} diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs index 1d1d12213a..09edb42db5 100644 --- a/OpenRA.Game/World.cs +++ b/OpenRA.Game/World.cs @@ -27,7 +27,7 @@ namespace OpenRA public class World { internal TraitDictionary traitDict = new TraitDictionary(); - Set actors = new Set(); + HashSet actors = new HashSet(); List effects = new List(); Queue> frameEndActions = new Queue>();