Cache rotation matrices used by WorldRenderer.DrawRangeCircle.

This commit is contained in:
RoosterDragon
2015-07-09 20:35:08 +01:00
parent 7dc654a5ad
commit 6113892276
2 changed files with 13 additions and 4 deletions

View File

@@ -21,6 +21,10 @@ namespace OpenRA.Graphics
public static readonly Func<IRenderable, int> RenderableScreenZPositionComparisonKey = public static readonly Func<IRenderable, int> RenderableScreenZPositionComparisonKey =
r => ZPosition(r.Pos, r.ZOffset); r => ZPosition(r.Pos, r.ZOffset);
const int RangeCircleSegments = 32;
static readonly int[][] RangeCircleStartRotations = Exts.MakeArray(RangeCircleSegments, i => WRot.FromFacing(8 * i).AsMatrix());
static readonly int[][] RangeCircleEndRotations = Exts.MakeArray(RangeCircleSegments, i => WRot.FromFacing(8 * i + 6).AsMatrix());
public readonly World World; public readonly World World;
public readonly Theater Theater; public readonly Theater Theater;
public Viewport Viewport { get; private set; } public Viewport Viewport { get; private set; }
@@ -197,10 +201,10 @@ namespace OpenRA.Graphics
public void DrawRangeCircle(WPos pos, WDist range, Color c) public void DrawRangeCircle(WPos pos, WDist range, Color c)
{ {
var offset = new WVec(range.Length, 0, 0); var offset = new WVec(range.Length, 0, 0);
for (var i = 0; i < 32; i++) for (var i = 0; i < RangeCircleSegments; i++)
{ {
var pa = pos + offset.Rotate(WRot.FromFacing(8 * i)); var pa = pos + offset.Rotate(RangeCircleStartRotations[i]);
var pb = pos + offset.Rotate(WRot.FromFacing(8 * i + 6)); var pb = pos + offset.Rotate(RangeCircleEndRotations[i]);
Game.Renderer.WorldLineRenderer.DrawLine(ScreenPosition(pa), ScreenPosition(pb), c); Game.Renderer.WorldLineRenderer.DrawLine(ScreenPosition(pa), ScreenPosition(pb), c);
} }
} }

View File

@@ -43,7 +43,12 @@ namespace OpenRA
public WVec Rotate(WRot rot) public WVec Rotate(WRot rot)
{ {
var mtx = rot.AsMatrix(); return Rotate(rot.AsMatrix());
}
public WVec Rotate(int[] rotationMatrix)
{
var mtx = rotationMatrix;
var lx = (long)X; var lx = (long)X;
var ly = (long)Y; var ly = (long)Y;
var lz = (long)Z; var lz = (long)Z;