From fd4d3b40d0fbb025ecb54b21dd6366f72e430f11 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 20 Jun 2014 15:45:36 +1200 Subject: [PATCH] Simplify shroud range checks. --- OpenRA.Game/Map/Map.cs | 6 +++--- OpenRA.Game/Traits/World/Shroud.cs | 13 +++++-------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index 608e4d52a5..9c1e13bd4d 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -633,12 +633,12 @@ namespace OpenRA if (range >= TilesByDistance.Length) throw new InvalidOperationException("FindTilesInCircle supports queries for only <= {0}".F(MaxTilesInCircleRange)); - for(var i = 0; i <= range; i++) + for (var i = 0; i <= range; i++) { - foreach(var offset in TilesByDistance[i]) + foreach (var offset in TilesByDistance[i]) { var t = offset + center; - if (Bounds.Contains(t.X, t.Y)) + if (IsInMap(t)) yield return t; } } diff --git a/OpenRA.Game/Traits/World/Shroud.cs b/OpenRA.Game/Traits/World/Shroud.cs index a608302fb5..73c7afd13e 100644 --- a/OpenRA.Game/Traits/World/Shroud.cs +++ b/OpenRA.Game/Traits/World/Shroud.cs @@ -66,15 +66,12 @@ namespace OpenRA.Traits static IEnumerable FindVisibleTiles(World world, CPos position, WRange radius) { var r = (radius.Range + 1023) / 1024; - var min = (position - new CVec(r, r)).Clamp(world.Map.Bounds); - var max = (position + new CVec(r, r)).Clamp(world.Map.Bounds); - - var circleArea = radius.Range * radius.Range; + var limit = radius.Range * radius.Range; var pos = position.CenterPosition; - for (var j = min.Y; j <= max.Y; j++) - for (var i = min.X; i <= max.X; i++) - if (circleArea >= (new CPos(i, j).CenterPosition - pos).LengthSquared) - yield return new CPos(i, j); + + foreach (var cell in world.Map.FindTilesInCircle(position, r)) + if ((cell.CenterPosition - pos).HorizontalLengthSquared <= limit) + yield return cell; } void AddVisibility(Actor a)