From 1e3f365cf2f1a274b50e0865ce79d6d7cd894216 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sat, 12 Mar 2011 19:33:16 +1300 Subject: [PATCH] move all the Game.Exts junk either down into FileFormats or into WorldUtils --- OpenRA.FileFormats/Exts.cs | 38 +++++++++- OpenRA.Game/Exts.cs | 70 ------------------- OpenRA.Game/OpenRA.Game.csproj | 3 +- OpenRA.Game/World.cs | 3 +- OpenRA.Game/WorldUtils.cs | 16 ++++- .../Delegates/ServerBrowserDelegate.cs | 3 +- 6 files changed, 55 insertions(+), 78 deletions(-) delete mode 100755 OpenRA.Game/Exts.cs diff --git a/OpenRA.FileFormats/Exts.cs b/OpenRA.FileFormats/Exts.cs index d2b9f4aaa6..ac8cd971d3 100755 --- a/OpenRA.FileFormats/Exts.cs +++ b/OpenRA.FileFormats/Exts.cs @@ -105,6 +105,42 @@ namespace OpenRA public static bool Contains(this RectangleF r, int2 p) { return r.Contains(p.ToPointF()); - } + } + + public static bool HasModifier(this Modifiers k, Modifiers mod) + { + return (k & mod) == mod; + } + + public static V GetOrAdd(this Dictionary d, K k) + where V : new() + { + return d.GetOrAdd(k, _ => new V()); + } + + public static V GetOrAdd(this Dictionary d, K k, Func createFn) + { + V ret; + if (!d.TryGetValue(k, out ret)) + d.Add(k, ret = createFn(k)); + return ret; + } + + public static T Random(this IEnumerable ts, Thirdparty.Random r) + { + var xs = ts.ToArray(); + return xs[r.Next(xs.Length)]; + } + + public static float Product(this IEnumerable xs) + { + return xs.Aggregate(1f, (a, x) => a * x); + } + + public static IEnumerable SymmetricDifference(this IEnumerable xs, IEnumerable ys) + { + // this is probably a shockingly-slow way to do this, but it's concise. + return xs.Except(ys).Concat(ys.Except(xs)); + } } } diff --git a/OpenRA.Game/Exts.cs b/OpenRA.Game/Exts.cs deleted file mode 100755 index 956d289090..0000000000 --- a/OpenRA.Game/Exts.cs +++ /dev/null @@ -1,70 +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.Generic; -using System.Linq; -using OpenRA.Support; - -namespace OpenRA -{ - public static class Exts - { - public static bool HasModifier(this Modifiers k, Modifiers mod) - { - return (k & mod) == mod; - } - - public static IEnumerable SymmetricDifference(this IEnumerable xs, IEnumerable ys) - { - // this is probably a shockingly-slow way to do this, but it's concise. - return xs.Except(ys).Concat(ys.Except(xs)); - } - - public static float Product(this IEnumerable xs) - { - return xs.Aggregate(1f, (a, x) => a * x); - } - - public static V GetOrAdd(this Dictionary d, K k) - where V : new() - { - return d.GetOrAdd(k, _ => new V()); - } - - public static V GetOrAdd(this Dictionary d, K k, Func createFn) - { - V ret; - if (!d.TryGetValue(k, out ret)) - d.Add(k, ret = createFn(k)); - return ret; - } - - public static T Random(this IEnumerable ts, Thirdparty.Random r) - { - var xs = ts.ToArray(); - return xs[r.Next(xs.Length)]; - } - - public static void DoTimed(this IEnumerable e, Action a, string text, double time) - { - var sw = new Stopwatch(); - - e.Do(x => - { - var t = sw.ElapsedTime(); - a(x); - var dt = sw.ElapsedTime() - t; - if (dt > time) - Log.Write("perf", text, x, dt * 1000, Game.LocalTick); - }); - } - } -} diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 5f48fe50f4..fc48a7f449 100755 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -1,4 +1,4 @@ - + Debug @@ -87,7 +87,6 @@ - diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs index f44fbad5cb..bee8eeac44 100644 --- a/OpenRA.Game/World.cs +++ b/OpenRA.Game/World.cs @@ -15,8 +15,7 @@ using OpenRA.Effects; using OpenRA.FileFormats; using OpenRA.Network; using OpenRA.Orders; -using OpenRA.Traits; -using OpenRA.Widgets; +using OpenRA.Traits; using XRandom = OpenRA.Thirdparty.Random; namespace OpenRA diff --git a/OpenRA.Game/WorldUtils.cs b/OpenRA.Game/WorldUtils.cs index 764216857b..dbc82cb8c4 100755 --- a/OpenRA.Game/WorldUtils.cs +++ b/OpenRA.Game/WorldUtils.cs @@ -137,6 +137,20 @@ namespace OpenRA o.Subject, o.Subject.Owner.Country.Race)) return; } - } + } + + public static void DoTimed(this IEnumerable e, Action a, string text, double time) + { + var sw = new Stopwatch(); + + e.Do(x => + { + var t = sw.ElapsedTime(); + a(x); + var dt = sw.ElapsedTime() - t; + if (dt > time) + Log.Write("perf", text, x, dt * 1000, Game.LocalTick); + }); + } } } diff --git a/OpenRA.Mods.RA/Widgets/Delegates/ServerBrowserDelegate.cs b/OpenRA.Mods.RA/Widgets/Delegates/ServerBrowserDelegate.cs index c8d88e6e63..76946e0db8 100644 --- a/OpenRA.Mods.RA/Widgets/Delegates/ServerBrowserDelegate.cs +++ b/OpenRA.Mods.RA/Widgets/Delegates/ServerBrowserDelegate.cs @@ -8,8 +8,7 @@ */ #endregion -using System.Collections.Generic; -using System.Drawing; +using System.Collections.Generic; using System.Linq; using OpenRA.FileFormats; using OpenRA.Server;