From 0cf39991db1209f4d69f09d5ed70a86f7f345e95 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Wed, 23 Jun 2010 18:10:17 +1200 Subject: [PATCH] new range circle renderer; faster minefield renderer --- OpenRA.Game/Graphics/WorldRenderer.cs | 29 ++++++++++++------------ OpenRA.Game/Orders/UnitOrderGenerator.cs | 4 ++-- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index 2299bc4753..425b74d4db 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -353,34 +353,33 @@ namespace OpenRA.Graphics public void DrawLocus(Color c, int2[] cells) { - foreach (var t in cells) + var dict = cells.ToDictionary(a => a, a => 0); + foreach (var t in dict.Keys) { - if (!cells.Contains(t + new int2(-1, 0))) + if (!dict.ContainsKey(t + new int2(-1, 0))) lineRenderer.DrawLine(Game.CellSize * t, Game.CellSize * (t + new int2(0, 1)), c, c); - if (!cells.Contains(t + new int2(1, 0))) + if (!dict.ContainsKey(t + new int2(1, 0))) lineRenderer.DrawLine(Game.CellSize * (t + new int2(1, 0)), Game.CellSize * (t + new int2(1, 1)), c, c); - if (!cells.Contains(t + new int2(0, -1))) + if (!dict.ContainsKey(t + new int2(0, -1))) lineRenderer.DrawLine(Game.CellSize * t, Game.CellSize * (t + new int2(1, 0)), c, c); - if (!cells.Contains(t + new int2(0, 1))) + if (!dict.ContainsKey(t + new int2(0, 1))) lineRenderer.DrawLine(Game.CellSize * (t + new int2(0, 1)), Game.CellSize * (t + new int2(1, 1)), c, c); } } - public void DrawRangeCircle(Color c, int2 location, int range) + public void DrawRangeCircle(Color c, float2 location, int range) { - DrawLocus(c, world.FindTilesInCircle(location, range).ToArray()); - } - - public void DrawRangeCircle(Actor selectedUnit) - { - if (selectedUnit.Owner == world.LocalPlayer) - DrawRangeCircle(Color.FromArgb(128, Color.Yellow), - selectedUnit.Location, - (int)selectedUnit.GetPrimaryWeapon().Range); + var prev = location + Game.CellSize * range * float2.FromAngle(0); + for (var i = 1; i <= 32; i++) + { + var pos = location + Game.CellSize * range * float2.FromAngle((float)(Math.PI * i) / 8); + lineRenderer.DrawLine(prev, pos, c, c); + prev = pos; + } } } } diff --git a/OpenRA.Game/Orders/UnitOrderGenerator.cs b/OpenRA.Game/Orders/UnitOrderGenerator.cs index 5e7b484e7b..9407e8ce9b 100644 --- a/OpenRA.Game/Orders/UnitOrderGenerator.cs +++ b/OpenRA.Game/Orders/UnitOrderGenerator.cs @@ -54,11 +54,11 @@ namespace OpenRA.Orders { if (a.traits.Contains()) world.WorldRenderer.DrawRangeCircle(Color.FromArgb(128, Color.Yellow), - a.Location, (int)a.GetPrimaryWeapon().Range); + a.CenterLocation, (int)a.GetPrimaryWeapon().Range); if (a.traits.Contains()) world.WorldRenderer.DrawRangeCircle(Color.FromArgb(128, Color.LimeGreen), - a.Location, a.Info.Traits.Get().Range); + a.CenterLocation, a.Info.Traits.Get().Range); } } }