From fb5bcd3889c32bc08a6c13dd35d2891d5143edd0 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 26 Jul 2015 15:55:49 +0100 Subject: [PATCH] Extract MapCoordsRegion from CellRegion. --- OpenRA.Game/Map/CellRegion.cs | 72 +----------------------- OpenRA.Game/Map/MapCoordsRegion.cs | 89 ++++++++++++++++++++++++++++++ OpenRA.Game/OpenRA.Game.csproj | 1 + 3 files changed, 91 insertions(+), 71 deletions(-) create mode 100644 OpenRA.Game/Map/MapCoordsRegion.cs diff --git a/OpenRA.Game/Map/CellRegion.cs b/OpenRA.Game/Map/CellRegion.cs index 7920498a0a..fb41ed60a9 100644 --- a/OpenRA.Game/Map/CellRegion.cs +++ b/OpenRA.Game/Map/CellRegion.cs @@ -87,7 +87,7 @@ namespace OpenRA public MapCoordsRegion MapCoords { - get { return new MapCoordsRegion(this); } + get { return new MapCoordsRegion(mapTopLeft, mapBottomRight); } } public CellRegionEnumerator GetEnumerator() @@ -151,75 +151,5 @@ namespace OpenRA object IEnumerator.Current { get { return Current; } } public void Dispose() { } } - - public struct MapCoordsRegion : IEnumerable - { - public struct MapCoordsEnumerator : IEnumerator - { - readonly CellRegion r; - MPos current; - - public MapCoordsEnumerator(CellRegion region) - : this() - { - r = region; - Reset(); - } - - public bool MoveNext() - { - var u = current.U + 1; - var v = current.V; - - // Check for column overflow - if (u > r.mapBottomRight.U) - { - v += 1; - u = r.mapTopLeft.U; - - // Check for row overflow - if (v > r.mapBottomRight.V) - return false; - } - - current = new MPos(u, v); - return true; - } - - public void Reset() - { - current = new MPos(r.mapTopLeft.U - 1, r.mapTopLeft.V); - } - - public MPos Current { get { return current; } } - object IEnumerator.Current { get { return Current; } } - public void Dispose() { } - } - - readonly CellRegion r; - - public MapCoordsRegion(CellRegion region) - { - r = region; - } - - public MapCoordsEnumerator GetEnumerator() - { - return new MapCoordsEnumerator(r); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - - public MPos TopLeft { get { return r.mapTopLeft; } } - public MPos BottomRight { get { return r.mapBottomRight; } } - } } } diff --git a/OpenRA.Game/Map/MapCoordsRegion.cs b/OpenRA.Game/Map/MapCoordsRegion.cs new file mode 100644 index 0000000000..a7540b4e01 --- /dev/null +++ b/OpenRA.Game/Map/MapCoordsRegion.cs @@ -0,0 +1,89 @@ +#region Copyright & License Information +/* + * Copyright 2007-2015 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; +using System.Linq; + +namespace OpenRA +{ + public struct MapCoordsRegion : IEnumerable + { + public struct MapCoordsEnumerator : IEnumerator + { + readonly MapCoordsRegion r; + MPos current; + + public MapCoordsEnumerator(MapCoordsRegion region) + : this() + { + r = region; + Reset(); + } + + public bool MoveNext() + { + var u = current.U + 1; + var v = current.V; + + // Check for column overflow + if (u > r.bottomRight.U) + { + v += 1; + u = r.topLeft.U; + + // Check for row overflow + if (v > r.bottomRight.V) + return false; + } + + current = new MPos(u, v); + return true; + } + + public void Reset() + { + current = new MPos(r.topLeft.U - 1, r.topLeft.V); + } + + public MPos Current { get { return current; } } + object IEnumerator.Current { get { return Current; } } + public void Dispose() { } + } + + readonly MPos topLeft; + readonly MPos bottomRight; + + public MapCoordsRegion(MPos mapTopLeft, MPos mapBottomRight) + { + this.topLeft = mapTopLeft; + this.bottomRight = mapBottomRight; + } + + public MapCoordsEnumerator GetEnumerator() + { + return new MapCoordsEnumerator(this); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public MPos TopLeft { get { return topLeft; } } + public MPos BottomRight { get { return bottomRight; } } + } +} diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 035ddf3832..d5daabd551 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -248,6 +248,7 @@ +