new range circle renderer; faster minefield renderer

This commit is contained in:
Chris Forbes
2010-06-23 18:10:17 +12:00
committed by Paul Chote
parent b8093b7f6c
commit 0cf39991db
2 changed files with 16 additions and 17 deletions

View File

@@ -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)
var prev = location + Game.CellSize * range * float2.FromAngle(0);
for (var i = 1; i <= 32; i++)
{
if (selectedUnit.Owner == world.LocalPlayer)
DrawRangeCircle(Color.FromArgb(128, Color.Yellow),
selectedUnit.Location,
(int)selectedUnit.GetPrimaryWeapon().Range);
var pos = location + Game.CellSize * range * float2.FromAngle((float)(Math.PI * i) / 8);
lineRenderer.DrawLine(prev, pos, c, c);
prev = pos;
}
}
}
}

View File

@@ -54,11 +54,11 @@ namespace OpenRA.Orders
{
if (a.traits.Contains<RenderRangeCircle>())
world.WorldRenderer.DrawRangeCircle(Color.FromArgb(128, Color.Yellow),
a.Location, (int)a.GetPrimaryWeapon().Range);
a.CenterLocation, (int)a.GetPrimaryWeapon().Range);
if (a.traits.Contains<DetectCloaked>())
world.WorldRenderer.DrawRangeCircle(Color.FromArgb(128, Color.LimeGreen),
a.Location, a.Info.Traits.Get<DetectCloakedInfo>().Range);
a.CenterLocation, a.Info.Traits.Get<DetectCloakedInfo>().Range);
}
}
}