Fix IDE0032

This commit is contained in:
RoosterDragon
2023-02-19 11:19:28 +00:00
committed by Pavel Penev
parent e64c0a35c5
commit 98c4eaca83
52 changed files with 460 additions and 567 deletions

View File

@@ -17,8 +17,6 @@ namespace OpenRA.Mods.Common.Graphics
public enum BeamRenderableShape { Cylindrical, Flat }
public class BeamRenderable : IRenderable, IFinalizedRenderable
{
readonly WPos pos;
readonly int zOffset;
readonly WVec length;
readonly BeamRenderableShape shape;
readonly WDist width;
@@ -26,20 +24,20 @@ namespace OpenRA.Mods.Common.Graphics
public BeamRenderable(WPos pos, int zOffset, in WVec length, BeamRenderableShape shape, WDist width, Color color)
{
this.pos = pos;
this.zOffset = zOffset;
Pos = pos;
ZOffset = zOffset;
this.length = length;
this.shape = shape;
this.width = width;
this.color = color;
}
public WPos Pos => pos;
public int ZOffset => zOffset;
public WPos Pos { get; }
public int ZOffset { get; }
public bool IsDecoration => true;
public IRenderable WithZOffset(int newOffset) { return new BeamRenderable(pos, zOffset, length, shape, width, color); }
public IRenderable OffsetBy(in WVec vec) { return new BeamRenderable(pos + vec, zOffset, length, shape, width, color); }
public IRenderable WithZOffset(int newOffset) { return new BeamRenderable(Pos, ZOffset, length, shape, width, color); }
public IRenderable OffsetBy(in WVec vec) { return new BeamRenderable(Pos + vec, ZOffset, length, shape, width, color); }
public IRenderable AsDecoration() { return this; }
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }
@@ -53,16 +51,16 @@ namespace OpenRA.Mods.Common.Graphics
{
var delta = length * width.Length / (2 * vecLength);
var corner = new WVec(-delta.Y, delta.X, delta.Z);
var a = wr.Screen3DPosition(pos - corner);
var b = wr.Screen3DPosition(pos + corner);
var c = wr.Screen3DPosition(pos + corner + length);
var d = wr.Screen3DPosition(pos - corner + length);
var a = wr.Screen3DPosition(Pos - corner);
var b = wr.Screen3DPosition(Pos + corner);
var c = wr.Screen3DPosition(Pos + corner + length);
var d = wr.Screen3DPosition(Pos - corner + length);
Game.Renderer.WorldRgbaColorRenderer.FillRect(a, b, c, d, color);
}
else
{
var start = wr.Screen3DPosition(pos);
var end = wr.Screen3DPosition(pos + length);
var start = wr.Screen3DPosition(Pos);
var end = wr.Screen3DPosition(Pos + length);
var screenWidth = wr.ScreenVector(new WVec(width, WDist.Zero, WDist.Zero))[0];
Game.Renderer.WorldRgbaColorRenderer.DrawLine(start, end, screenWidth, color);
}

View File

@@ -18,8 +18,6 @@ namespace OpenRA.Mods.Common.Graphics
{
const int CircleSegments = 32;
static readonly WVec[] FacingOffsets = Exts.MakeArray(CircleSegments, i => new WVec(1024, 0, 0).Rotate(WRot.FromFacing(i * 256 / CircleSegments)));
readonly WPos centerPosition;
readonly WDist radius;
readonly int width;
readonly Color color;
@@ -27,19 +25,19 @@ namespace OpenRA.Mods.Common.Graphics
public CircleAnnotationRenderable(WPos centerPosition, WDist radius, int width, Color color, bool filled = false)
{
this.centerPosition = centerPosition;
Pos = centerPosition;
this.radius = radius;
this.width = width;
this.color = color;
this.filled = filled;
}
public WPos Pos => centerPosition;
public WPos Pos { get; }
public int ZOffset => 0;
public bool IsDecoration => true;
public IRenderable WithZOffset(int newOffset) { return new CircleAnnotationRenderable(centerPosition, radius, width, color, filled); }
public IRenderable OffsetBy(in WVec vec) { return new CircleAnnotationRenderable(centerPosition + vec, radius, width, color, filled); }
public IRenderable WithZOffset(int newOffset) { return new CircleAnnotationRenderable(Pos, radius, width, color, filled); }
public IRenderable OffsetBy(in WVec vec) { return new CircleAnnotationRenderable(Pos + vec, radius, width, color, filled); }
public IRenderable AsDecoration() { return this; }
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }
@@ -49,18 +47,18 @@ namespace OpenRA.Mods.Common.Graphics
if (filled)
{
var offset = new WVec(radius.Length, radius.Length, 0);
var tl = wr.Viewport.WorldToViewPx(wr.ScreenPosition(centerPosition - offset));
var br = wr.Viewport.WorldToViewPx(wr.ScreenPosition(centerPosition + offset));
var tl = wr.Viewport.WorldToViewPx(wr.ScreenPosition(Pos - offset));
var br = wr.Viewport.WorldToViewPx(wr.ScreenPosition(Pos + offset));
cr.FillEllipse(tl, br, color);
}
else
{
var r = radius.Length;
var a = wr.Viewport.WorldToViewPx(wr.ScreenPosition(centerPosition + r * FacingOffsets[CircleSegments - 1] / 1024));
var a = wr.Viewport.WorldToViewPx(wr.ScreenPosition(Pos + r * FacingOffsets[CircleSegments - 1] / 1024));
for (var i = 0; i < CircleSegments; i++)
{
var b = wr.Viewport.WorldToViewPx(wr.ScreenPosition(centerPosition + r * FacingOffsets[i] / 1024));
var b = wr.Viewport.WorldToViewPx(wr.ScreenPosition(Pos + r * FacingOffsets[i] / 1024));
cr.DrawLine(a, b, width, color);
a = b;
}

View File

@@ -24,7 +24,6 @@ namespace OpenRA.Mods.Common.Graphics
readonly World world;
readonly Color startcolor;
readonly Color endcolor;
readonly int zOffset;
// Store trail positions in a circular buffer
readonly WPos[] trail;
@@ -46,11 +45,11 @@ namespace OpenRA.Mods.Common.Graphics
this.skip = skip;
this.startcolor = startcolor;
this.endcolor = endcolor;
this.zOffset = zOffset;
ZOffset = zOffset;
}
public WPos Pos => trail[Index(next - 1)];
public int ZOffset => zOffset;
public int ZOffset { get; }
public bool IsDecoration => true;
public IRenderable WithZOffset(int newOffset) { return new ContrailRenderable(world, (WPos[])trail.Clone(), width, next, length, skip, startcolor, endcolor, newOffset); }
@@ -58,7 +57,7 @@ namespace OpenRA.Mods.Common.Graphics
{
// Lambdas can't use 'in' variables, so capture a copy for later
var offset = vec;
return new ContrailRenderable(world, trail.Select(pos => pos + offset).ToArray(), width, next, length, skip, startcolor, endcolor, zOffset);
return new ContrailRenderable(world, trail.Select(pos => pos + offset).ToArray(), width, next, length, skip, startcolor, endcolor, ZOffset);
}
public IRenderable AsDecoration() { return this; }

View File

@@ -16,9 +16,7 @@ namespace OpenRA.Mods.Common.Graphics
{
public class DetectionCircleAnnotationRenderable : IRenderable, IFinalizedRenderable
{
readonly WPos centerPosition;
readonly WDist radius;
readonly int zOffset;
readonly int trailCount;
readonly WAngle trailSeparation;
readonly WAngle trailAngle;
@@ -30,9 +28,9 @@ namespace OpenRA.Mods.Common.Graphics
public DetectionCircleAnnotationRenderable(WPos centerPosition, WDist radius, int zOffset,
int lineTrails, WAngle trailSeparation, WAngle trailAngle, Color color, float width, Color borderColor, float borderWidth)
{
this.centerPosition = centerPosition;
Pos = centerPosition;
this.radius = radius;
this.zOffset = zOffset;
ZOffset = zOffset;
trailCount = lineTrails;
this.trailSeparation = trailSeparation;
this.trailAngle = trailAngle;
@@ -42,19 +40,19 @@ namespace OpenRA.Mods.Common.Graphics
this.borderWidth = borderWidth;
}
public WPos Pos => centerPosition;
public int ZOffset => zOffset;
public WPos Pos { get; }
public int ZOffset { get; }
public bool IsDecoration => true;
public IRenderable WithZOffset(int newOffset)
{
return new DetectionCircleAnnotationRenderable(centerPosition, radius, newOffset,
return new DetectionCircleAnnotationRenderable(Pos, radius, newOffset,
trailCount, trailSeparation, trailAngle, color, width, borderColor, borderWidth);
}
public IRenderable OffsetBy(in WVec vec)
{
return new DetectionCircleAnnotationRenderable(centerPosition + vec, radius, zOffset,
return new DetectionCircleAnnotationRenderable(Pos + vec, radius, ZOffset,
trailCount, trailSeparation, trailAngle, color, width, borderColor, borderWidth);
}
@@ -64,19 +62,19 @@ namespace OpenRA.Mods.Common.Graphics
public void Render(WorldRenderer wr)
{
var cr = Game.Renderer.RgbaColorRenderer;
var center = wr.Viewport.WorldToViewPx(wr.Screen3DPosition(centerPosition));
var center = wr.Viewport.WorldToViewPx(wr.Screen3DPosition(Pos));
for (var i = 0; i < trailCount; i++)
{
var angle = trailAngle - new WAngle(i * (trailSeparation.Angle <= 512 ? 1 : -1));
var length = radius.Length * new WVec(angle.Cos(), angle.Sin(), 0) / 1024;
var end = wr.Viewport.WorldToViewPx(wr.Screen3DPosition(centerPosition + length));
var end = wr.Viewport.WorldToViewPx(wr.Screen3DPosition(Pos + length));
var alpha = color.A - i * color.A / trailCount;
cr.DrawLine(center, end, borderWidth, Color.FromArgb(alpha, borderColor));
cr.DrawLine(center, end, width, Color.FromArgb(alpha, color));
}
RangeCircleAnnotationRenderable.DrawRangeCircle(wr, centerPosition, radius, width, color, borderWidth, borderColor);
RangeCircleAnnotationRenderable.DrawRangeCircle(wr, Pos, radius, width, color, borderWidth, borderColor);
}
public void RenderDebugGeometry(WorldRenderer wr) { }

View File

@@ -25,36 +25,32 @@ namespace OpenRA.Mods.Common.Graphics
static readonly Color DarkEmptyColor = Color.FromArgb(160, 15, 15, 15);
static readonly Color DarkenColor = Color.FromArgb(24, 0, 0, 0);
static readonly Color LightenColor = Color.FromArgb(24, 255, 255, 255);
readonly WPos pos;
readonly Actor actor;
readonly bool displayHealth;
readonly bool displayExtra;
readonly Polygon bounds;
public IsometricSelectionBarsAnnotationRenderable(Actor actor, Polygon bounds, bool displayHealth, bool displayExtra)
: this(actor.CenterPosition, actor, bounds)
{
this.displayHealth = displayHealth;
this.displayExtra = displayExtra;
DisplayHealth = displayHealth;
DisplayExtra = displayExtra;
}
public IsometricSelectionBarsAnnotationRenderable(WPos pos, Actor actor, Polygon bounds)
{
this.pos = pos;
Pos = pos;
this.actor = actor;
this.bounds = bounds;
}
public WPos Pos => pos;
public bool DisplayHealth => displayHealth;
public bool DisplayExtra => displayExtra;
public WPos Pos { get; }
public bool DisplayHealth { get; }
public bool DisplayExtra { get; }
public int ZOffset => 0;
public bool IsDecoration => true;
public IRenderable WithZOffset(int newOffset) { return this; }
public IRenderable OffsetBy(in WVec vec) { return new IsometricSelectionBarsAnnotationRenderable(pos + vec, actor, bounds); }
public IRenderable OffsetBy(in WVec vec) { return new IsometricSelectionBarsAnnotationRenderable(Pos + vec, actor, bounds); }
public IRenderable AsDecoration() { return this; }
void DrawExtraBars(WorldRenderer wr)

View File

@@ -29,32 +29,30 @@ namespace OpenRA.Mods.Common.Graphics
-TROffset, TOffset, TLOffset,
TLOffset, -TOffset, -TROffset
};
readonly WPos pos;
readonly Polygon bounds;
readonly Color color;
public IsometricSelectionBoxAnnotationRenderable(Actor actor, in Polygon bounds, Color color)
{
pos = actor.CenterPosition;
Pos = actor.CenterPosition;
this.bounds = bounds;
this.color = color;
}
public IsometricSelectionBoxAnnotationRenderable(WPos pos, in Polygon bounds, Color color)
{
this.pos = pos;
Pos = pos;
this.bounds = bounds;
this.color = color;
}
public WPos Pos => pos;
public WPos Pos { get; }
public int ZOffset => 0;
public bool IsDecoration => true;
public IRenderable WithZOffset(int newOffset) { return this; }
public IRenderable OffsetBy(in WVec vec) { return new IsometricSelectionBoxAnnotationRenderable(pos + vec, bounds, color); }
public IRenderable OffsetBy(in WVec vec) { return new IsometricSelectionBoxAnnotationRenderable(Pos + vec, bounds, color); }
public IRenderable AsDecoration() { return this; }
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }

View File

@@ -16,7 +16,6 @@ namespace OpenRA.Mods.Common.Graphics
{
public class LineAnnotationRenderable : IRenderable, IFinalizedRenderable
{
readonly WPos start;
readonly WPos end;
readonly float width;
readonly Color startColor;
@@ -24,7 +23,7 @@ namespace OpenRA.Mods.Common.Graphics
public LineAnnotationRenderable(WPos start, WPos end, float width, Color color)
{
this.start = start;
Pos = start;
this.end = end;
this.width = width;
startColor = endColor = color;
@@ -32,26 +31,26 @@ namespace OpenRA.Mods.Common.Graphics
public LineAnnotationRenderable(WPos start, WPos end, float width, Color startColor, Color endColor)
{
this.start = start;
Pos = start;
this.end = end;
this.width = width;
this.startColor = startColor;
this.endColor = endColor;
}
public WPos Pos => start;
public WPos Pos { get; }
public int ZOffset => 0;
public bool IsDecoration => true;
public IRenderable WithZOffset(int newOffset) { return new LineAnnotationRenderable(start, end, width, startColor, endColor); }
public IRenderable OffsetBy(in WVec vec) { return new LineAnnotationRenderable(start + vec, end + vec, width, startColor, endColor); }
public IRenderable WithZOffset(int newOffset) { return new LineAnnotationRenderable(Pos, end, width, startColor, endColor); }
public IRenderable OffsetBy(in WVec vec) { return new LineAnnotationRenderable(Pos + vec, end + vec, width, startColor, endColor); }
public IRenderable AsDecoration() { return this; }
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }
public void Render(WorldRenderer wr)
{
Game.Renderer.RgbaColorRenderer.DrawLine(
wr.Viewport.WorldToViewPx(wr.ScreenPosition(start)),
wr.Viewport.WorldToViewPx(wr.ScreenPosition(Pos)),
wr.Viewport.WorldToViewPx(wr.Screen3DPosition(end)),
width, startColor, endColor);
}

View File

@@ -20,19 +20,13 @@ namespace OpenRA.Mods.Common.Graphics
public class ModelRenderable : IPalettedRenderable, IModifyableRenderable
{
readonly IEnumerable<ModelAnimation> models;
readonly WPos pos;
readonly int zOffset;
readonly WRot camera;
readonly WRot lightSource;
readonly float[] lightAmbientColor;
readonly float[] lightDiffuseColor;
readonly PaletteReference palette;
readonly PaletteReference normalsPalette;
readonly PaletteReference shadowPalette;
readonly float scale;
readonly float alpha;
readonly float3 tint;
readonly TintModifiers tintModifiers;
public ModelRenderable(
IEnumerable<ModelAnimation> models, WPos pos, int zOffset, in WRot camera, float scale,
@@ -50,52 +44,52 @@ namespace OpenRA.Mods.Common.Graphics
float alpha, in float3 tint, TintModifiers tintModifiers)
{
this.models = models;
this.pos = pos;
this.zOffset = zOffset;
Pos = pos;
ZOffset = zOffset;
this.scale = scale;
this.camera = camera;
this.lightSource = lightSource;
this.lightAmbientColor = lightAmbientColor;
this.lightDiffuseColor = lightDiffuseColor;
palette = color;
Palette = color;
normalsPalette = normals;
shadowPalette = shadow;
this.alpha = alpha;
this.tint = tint;
this.tintModifiers = tintModifiers;
Alpha = alpha;
Tint = tint;
TintModifiers = tintModifiers;
}
public WPos Pos => pos;
public PaletteReference Palette => palette;
public int ZOffset => zOffset;
public WPos Pos { get; }
public PaletteReference Palette { get; }
public int ZOffset { get; }
public bool IsDecoration => false;
public float Alpha => alpha;
public float3 Tint => tint;
public TintModifiers TintModifiers => tintModifiers;
public float Alpha { get; }
public float3 Tint { get; }
public TintModifiers TintModifiers { get; }
public IPalettedRenderable WithPalette(PaletteReference newPalette)
{
return new ModelRenderable(
models, pos, zOffset, camera, scale,
models, Pos, ZOffset, camera, scale,
lightSource, lightAmbientColor, lightDiffuseColor,
newPalette, normalsPalette, shadowPalette, alpha, tint, tintModifiers);
newPalette, normalsPalette, shadowPalette, Alpha, Tint, TintModifiers);
}
public IRenderable WithZOffset(int newOffset)
{
return new ModelRenderable(
models, pos, newOffset, camera, scale,
models, Pos, newOffset, camera, scale,
lightSource, lightAmbientColor, lightDiffuseColor,
palette, normalsPalette, shadowPalette, alpha, tint, tintModifiers);
Palette, normalsPalette, shadowPalette, Alpha, Tint, TintModifiers);
}
public IRenderable OffsetBy(in WVec vec)
{
return new ModelRenderable(
models, pos + vec, zOffset, camera, scale,
models, Pos + vec, ZOffset, camera, scale,
lightSource, lightAmbientColor, lightDiffuseColor,
palette, normalsPalette, shadowPalette, alpha, tint, tintModifiers);
Palette, normalsPalette, shadowPalette, Alpha, Tint, TintModifiers);
}
public IRenderable AsDecoration() { return this; }
@@ -103,17 +97,17 @@ namespace OpenRA.Mods.Common.Graphics
public IModifyableRenderable WithAlpha(float newAlpha)
{
return new ModelRenderable(
models, pos, zOffset, camera, scale,
models, Pos, ZOffset, camera, scale,
lightSource, lightAmbientColor, lightDiffuseColor,
palette, normalsPalette, shadowPalette, newAlpha, tint, tintModifiers);
Palette, normalsPalette, shadowPalette, newAlpha, Tint, TintModifiers);
}
public IModifyableRenderable WithTint(in float3 newTint, TintModifiers newTintModifiers)
{
return new ModelRenderable(
models, pos, zOffset, camera, scale,
models, Pos, ZOffset, camera, scale,
lightSource, lightAmbientColor, lightDiffuseColor,
palette, normalsPalette, shadowPalette, alpha, newTint, newTintModifiers);
Palette, normalsPalette, shadowPalette, Alpha, newTint, newTintModifiers);
}
public IFinalizedRenderable PrepareRender(WorldRenderer wr)
@@ -132,21 +126,21 @@ namespace OpenRA.Mods.Common.Graphics
var draw = model.models.Where(v => v.IsVisible);
var map = wr.World.Map;
var groundOrientation = map.TerrainOrientation(map.CellContaining(model.pos));
var groundOrientation = map.TerrainOrientation(map.CellContaining(model.Pos));
renderProxy = Game.Renderer.WorldModelRenderer.RenderAsync(
wr, draw, model.camera, model.scale, groundOrientation, model.lightSource,
model.lightAmbientColor, model.lightDiffuseColor,
model.palette, model.normalsPalette, model.shadowPalette);
model.Palette, model.normalsPalette, model.shadowPalette);
}
public void Render(WorldRenderer wr)
{
var map = wr.World.Map;
var groundPos = model.pos - new WVec(0, 0, map.DistanceAboveTerrain(model.pos).Length);
var groundPos = model.Pos - new WVec(0, 0, map.DistanceAboveTerrain(model.Pos).Length);
var tileScale = map.Grid.Type == MapGridType.RectangularIsometric ? 1448f : 1024f;
var groundZ = map.Grid.TileSize.Height * (groundPos.Z - model.pos.Z) / tileScale;
var pxOrigin = wr.Screen3DPosition(model.pos);
var groundZ = map.Grid.TileSize.Height * (groundPos.Z - model.Pos.Z) / tileScale;
var pxOrigin = wr.Screen3DPosition(model.Pos);
// HACK: We don't have enough texture channels to pass the depth data to the shader
// so for now just offset everything forward so that the back corner is rendered at pos.
@@ -154,7 +148,7 @@ namespace OpenRA.Mods.Common.Graphics
// HACK: The previous hack isn't sufficient for the ramp type that is half flat and half
// sloped towards the camera. Offset it by another half cell to avoid clipping.
var cell = map.CellContaining(model.pos);
var cell = map.CellContaining(model.Pos);
if (map.Ramp.Contains(cell) && map.Ramp[cell] == 7)
pxOrigin += new float3(0, 0, 0.5f * map.Grid.TileSize.Height);
@@ -167,13 +161,13 @@ namespace OpenRA.Mods.Common.Graphics
var sd = shadowOrigin + psb[3];
var wrsr = Game.Renderer.WorldRgbaSpriteRenderer;
var t = model.tint;
if (wr.TerrainLighting != null && (model.tintModifiers & TintModifiers.IgnoreWorldTint) == 0)
t *= wr.TerrainLighting.TintAt(model.pos);
var t = model.Tint;
if (wr.TerrainLighting != null && (model.TintModifiers & TintModifiers.IgnoreWorldTint) == 0)
t *= wr.TerrainLighting.TintAt(model.Pos);
// Shader interprets negative alpha as a flag to use the tint colour directly instead of multiplying the sprite colour
var a = model.alpha;
if ((model.tintModifiers & TintModifiers.ReplaceColor) != 0)
var a = model.Alpha;
if ((model.TintModifiers & TintModifiers.ReplaceColor) != 0)
a *= -1;
wrsr.DrawSprite(renderProxy.ShadowSprite, sa, sb, sc, sd, t, a);
@@ -182,9 +176,9 @@ namespace OpenRA.Mods.Common.Graphics
public void RenderDebugGeometry(WorldRenderer wr)
{
var groundPos = model.pos - new WVec(0, 0, wr.World.Map.DistanceAboveTerrain(model.pos).Length);
var groundZ = wr.World.Map.Grid.TileSize.Height * (groundPos.Z - model.pos.Z) / 1024f;
var pxOrigin = wr.Screen3DPosition(model.pos);
var groundPos = model.Pos - new WVec(0, 0, wr.World.Map.DistanceAboveTerrain(model.Pos).Length);
var groundZ = wr.World.Map.Grid.TileSize.Height * (groundPos.Z - model.Pos.Z) / 1024f;
var pxOrigin = wr.Screen3DPosition(model.Pos);
var shadowOrigin = pxOrigin - groundZ * new float2(renderProxy.ShadowDirection, 1);
// Draw sprite rect
@@ -256,7 +250,7 @@ namespace OpenRA.Mods.Common.Graphics
(Rectangle Bounds, float2 Z) Screen3DBounds(WorldRenderer wr)
{
var pxOrigin = wr.ScreenPosition(model.pos);
var pxOrigin = wr.ScreenPosition(model.Pos);
var draw = model.models.Where(v => v.IsVisible);
var scaleTransform = OpenRA.Graphics.Util.ScaleMatrix(model.scale, model.scale, model.scale);
var cameraTransform = OpenRA.Graphics.Util.MakeFloatMatrix(model.camera.AsMatrix());

View File

@@ -18,29 +18,28 @@ namespace OpenRA.Mods.Common.Graphics
public class PolygonAnnotationRenderable : IRenderable, IFinalizedRenderable
{
readonly WPos[] vertices;
readonly WPos effectivePos;
readonly int width;
readonly Color color;
public PolygonAnnotationRenderable(WPos[] vertices, WPos effectivePos, int width, Color color)
{
this.vertices = vertices;
this.effectivePos = effectivePos;
Pos = effectivePos;
this.width = width;
this.color = color;
}
public WPos Pos => effectivePos;
public WPos Pos { get; }
public int ZOffset => 0;
public bool IsDecoration => true;
public IRenderable WithZOffset(int newOffset) { return new PolygonAnnotationRenderable(vertices, effectivePos, width, color); }
public IRenderable WithZOffset(int newOffset) { return new PolygonAnnotationRenderable(vertices, Pos, width, color); }
public IRenderable OffsetBy(in WVec vec)
{
// Lambdas can't use 'in' variables, so capture a copy for later
var offset = vec;
return new PolygonAnnotationRenderable(vertices.Select(v => v + offset).ToArray(), effectivePos + vec, width, color);
return new PolygonAnnotationRenderable(vertices.Select(v => v + offset).ToArray(), Pos + vec, width, color);
}
public IRenderable AsDecoration() { return this; }

View File

@@ -17,8 +17,6 @@ namespace OpenRA.Mods.Common.Graphics
{
public class RailgunHelixRenderable : IRenderable, IFinalizedRenderable
{
readonly WPos pos;
readonly int zOffset;
readonly Railgun railgun;
readonly RailgunInfo info;
readonly WDist helixRadius;
@@ -29,8 +27,8 @@ namespace OpenRA.Mods.Common.Graphics
public RailgunHelixRenderable(WPos pos, int zOffset, Railgun railgun, RailgunInfo railgunInfo, int ticks)
{
this.pos = pos;
this.zOffset = zOffset;
Pos = pos;
ZOffset = zOffset;
this.railgun = railgun;
info = railgunInfo;
this.ticks = ticks;
@@ -40,12 +38,12 @@ namespace OpenRA.Mods.Common.Graphics
angle = new WAngle(ticks * info.HelixAngleDeltaPerTick.Angle);
}
public WPos Pos => pos;
public int ZOffset => zOffset;
public WPos Pos { get; }
public int ZOffset { get; }
public bool IsDecoration => true;
public IRenderable WithZOffset(int newOffset) { return new RailgunHelixRenderable(pos, newOffset, railgun, info, ticks); }
public IRenderable OffsetBy(in WVec vec) { return new RailgunHelixRenderable(pos + vec, zOffset, railgun, info, ticks); }
public IRenderable WithZOffset(int newOffset) { return new RailgunHelixRenderable(Pos, newOffset, railgun, info, ticks); }
public IRenderable OffsetBy(in WVec vec) { return new RailgunHelixRenderable(Pos + vec, ZOffset, railgun, info, ticks); }
public IRenderable AsDecoration() { return this; }
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }
@@ -57,7 +55,7 @@ namespace OpenRA.Mods.Common.Graphics
var screenWidth = wr.ScreenVector(new WVec(info.HelixThickness.Length, 0, 0))[0];
// Move forward from self to target to draw helix
var centerPos = pos;
var centerPos = Pos;
var points = new float3[railgun.CycleCount * info.QuantizationCount];
for (var i = points.Length - 1; i >= 0; i--)
{

View File

@@ -19,10 +19,7 @@ namespace OpenRA.Mods.Common.Graphics
const int RangeCircleSegments = 32;
static readonly Int32Matrix4x4[] RangeCircleStartRotations = Exts.MakeArray(RangeCircleSegments, i => WRot.FromFacing(8 * i).AsMatrix());
static readonly Int32Matrix4x4[] RangeCircleEndRotations = Exts.MakeArray(RangeCircleSegments, i => WRot.FromFacing(8 * i + 6).AsMatrix());
readonly WPos centerPosition;
readonly WDist radius;
readonly int zOffset;
readonly Color color;
readonly float width;
readonly Color borderColor;
@@ -30,27 +27,27 @@ namespace OpenRA.Mods.Common.Graphics
public RangeCircleAnnotationRenderable(WPos centerPosition, WDist radius, int zOffset, Color color, float width, Color borderColor, float borderWidth)
{
this.centerPosition = centerPosition;
Pos = centerPosition;
this.radius = radius;
this.zOffset = zOffset;
ZOffset = zOffset;
this.color = color;
this.width = width;
this.borderColor = borderColor;
this.borderWidth = borderWidth;
}
public WPos Pos => centerPosition;
public int ZOffset => zOffset;
public WPos Pos { get; }
public int ZOffset { get; }
public bool IsDecoration => true;
public IRenderable WithZOffset(int newOffset) { return new RangeCircleAnnotationRenderable(centerPosition, radius, newOffset, color, width, borderColor, borderWidth); }
public IRenderable OffsetBy(in WVec vec) { return new RangeCircleAnnotationRenderable(centerPosition + vec, radius, zOffset, color, width, borderColor, borderWidth); }
public IRenderable WithZOffset(int newOffset) { return new RangeCircleAnnotationRenderable(Pos, radius, newOffset, color, width, borderColor, borderWidth); }
public IRenderable OffsetBy(in WVec vec) { return new RangeCircleAnnotationRenderable(Pos + vec, radius, ZOffset, color, width, borderColor, borderWidth); }
public IRenderable AsDecoration() { return this; }
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }
public void Render(WorldRenderer wr)
{
DrawRangeCircle(wr, centerPosition, radius, width, color, borderWidth, borderColor);
DrawRangeCircle(wr, Pos, radius, width, color, borderWidth, borderColor);
}
public static void DrawRangeCircle(WorldRenderer wr, WPos centerPosition, WDist radius,

View File

@@ -17,35 +17,32 @@ namespace OpenRA.Mods.Common.Graphics
{
public class SelectionBarsAnnotationRenderable : IRenderable, IFinalizedRenderable
{
readonly WPos pos;
readonly Actor actor;
readonly bool displayHealth;
readonly bool displayExtra;
readonly Rectangle decorationBounds;
public SelectionBarsAnnotationRenderable(Actor actor, Rectangle decorationBounds, bool displayHealth, bool displayExtra)
: this(actor.CenterPosition, actor, decorationBounds)
{
this.displayHealth = displayHealth;
this.displayExtra = displayExtra;
DisplayHealth = displayHealth;
DisplayExtra = displayExtra;
}
public SelectionBarsAnnotationRenderable(WPos pos, Actor actor, Rectangle decorationBounds)
{
this.pos = pos;
Pos = pos;
this.actor = actor;
this.decorationBounds = decorationBounds;
}
public WPos Pos => pos;
public bool DisplayHealth => displayHealth;
public bool DisplayExtra => displayExtra;
public WPos Pos { get; }
public bool DisplayHealth { get; }
public bool DisplayExtra { get; }
public int ZOffset => 0;
public bool IsDecoration => true;
public IRenderable WithZOffset(int newOffset) { return this; }
public IRenderable OffsetBy(in WVec vec) { return new SelectionBarsAnnotationRenderable(pos + vec, actor, decorationBounds); }
public IRenderable OffsetBy(in WVec vec) { return new SelectionBarsAnnotationRenderable(Pos + vec, actor, decorationBounds); }
public IRenderable AsDecoration() { return this; }
void DrawExtraBars(float2 start, float2 end)

View File

@@ -16,7 +16,6 @@ namespace OpenRA.Mods.Common.Graphics
{
public class SelectionBoxAnnotationRenderable : IRenderable, IFinalizedRenderable
{
readonly WPos pos;
readonly Rectangle decorationBounds;
readonly Color color;
@@ -25,18 +24,18 @@ namespace OpenRA.Mods.Common.Graphics
public SelectionBoxAnnotationRenderable(WPos pos, Rectangle decorationBounds, Color color)
{
this.pos = pos;
Pos = pos;
this.decorationBounds = decorationBounds;
this.color = color;
}
public WPos Pos => pos;
public WPos Pos { get; }
public int ZOffset => 0;
public bool IsDecoration => true;
public IRenderable WithZOffset(int newOffset) { return this; }
public IRenderable OffsetBy(in WVec vec) { return new SelectionBoxAnnotationRenderable(pos + vec, decorationBounds, color); }
public IRenderable OffsetBy(in WVec vec) { return new SelectionBoxAnnotationRenderable(Pos + vec, decorationBounds, color); }
public IRenderable AsDecoration() { return this; }
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }

View File

@@ -18,8 +18,6 @@ namespace OpenRA.Mods.Common.Graphics
public class TextAnnotationRenderable : IRenderable, IFinalizedRenderable
{
readonly SpriteFont font;
readonly WPos pos;
readonly int zOffset;
readonly Color color;
readonly Color bgDark;
readonly Color bgLight;
@@ -28,8 +26,8 @@ namespace OpenRA.Mods.Common.Graphics
public TextAnnotationRenderable(SpriteFont font, WPos pos, int zOffset, Color color, Color bgDark, Color bgLight, string text)
{
this.font = font;
this.pos = pos;
this.zOffset = zOffset;
Pos = pos;
ZOffset = zOffset;
this.color = color;
this.bgDark = bgDark;
this.bgLight = bgLight;
@@ -42,25 +40,25 @@ namespace OpenRA.Mods.Common.Graphics
ChromeMetrics.Get<Color>("TextContrastColorLight"),
text) { }
public WPos Pos => pos;
public int ZOffset => zOffset;
public WPos Pos { get; }
public int ZOffset { get; }
public bool IsDecoration => true;
public IRenderable WithZOffset(int newOffset) { return new TextAnnotationRenderable(font, pos, zOffset, color, text); }
public IRenderable OffsetBy(in WVec vec) { return new TextAnnotationRenderable(font, pos + vec, zOffset, color, text); }
public IRenderable WithZOffset(int newOffset) { return new TextAnnotationRenderable(font, Pos, ZOffset, color, text); }
public IRenderable OffsetBy(in WVec vec) { return new TextAnnotationRenderable(font, Pos + vec, ZOffset, color, text); }
public IRenderable AsDecoration() { return this; }
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }
public void Render(WorldRenderer wr)
{
var screenPos = wr.Viewport.WorldToViewPx(wr.ScreenPosition(pos)) - 0.5f * font.Measure(text).ToFloat2();
var screenPos = wr.Viewport.WorldToViewPx(wr.ScreenPosition(Pos)) - 0.5f * font.Measure(text).ToFloat2();
font.DrawTextWithContrast(text, screenPos, color, bgDark, bgLight, 1);
}
public void RenderDebugGeometry(WorldRenderer wr)
{
var size = font.Measure(text).ToFloat2();
var screenPos = wr.Viewport.WorldToViewPx(wr.ScreenPosition(pos));
var screenPos = wr.Viewport.WorldToViewPx(wr.ScreenPosition(Pos));
Game.Renderer.RgbaColorRenderer.DrawRect(screenPos - 0.5f * size, screenPos + 0.5f * size, 1, Color.Red);
}

View File

@@ -20,14 +20,11 @@ namespace OpenRA.Mods.Common.Graphics
public class UIModelRenderable : IRenderable, IPalettedRenderable
{
readonly IEnumerable<ModelAnimation> models;
readonly WPos effectiveWorldPos;
readonly int2 screenPos;
readonly int zOffset;
readonly WRot camera;
readonly WRot lightSource;
readonly float[] lightAmbientColor;
readonly float[] lightDiffuseColor;
readonly PaletteReference palette;
readonly PaletteReference normalsPalette;
readonly PaletteReference shadowPalette;
readonly float scale;
@@ -38,28 +35,28 @@ namespace OpenRA.Mods.Common.Graphics
PaletteReference color, PaletteReference normals, PaletteReference shadow)
{
this.models = models;
this.effectiveWorldPos = effectiveWorldPos;
Pos = effectiveWorldPos;
this.screenPos = screenPos;
this.zOffset = zOffset;
ZOffset = zOffset;
this.scale = scale;
this.camera = camera;
this.lightSource = lightSource;
this.lightAmbientColor = lightAmbientColor;
this.lightDiffuseColor = lightDiffuseColor;
palette = color;
Palette = color;
normalsPalette = normals;
shadowPalette = shadow;
}
public WPos Pos => effectiveWorldPos;
public PaletteReference Palette => palette;
public int ZOffset => zOffset;
public WPos Pos { get; }
public PaletteReference Palette { get; }
public int ZOffset { get; }
public bool IsDecoration => false;
public IPalettedRenderable WithPalette(PaletteReference newPalette)
{
return new UIModelRenderable(
models, effectiveWorldPos, screenPos, zOffset, camera, scale,
models, Pos, screenPos, ZOffset, camera, scale,
lightSource, lightAmbientColor, lightDiffuseColor,
newPalette, normalsPalette, shadowPalette);
}
@@ -86,7 +83,7 @@ namespace OpenRA.Mods.Common.Graphics
renderProxy = Game.Renderer.WorldModelRenderer.RenderAsync(
wr, draw, model.camera, model.scale, WRot.None, model.lightSource,
model.lightAmbientColor, model.lightDiffuseColor,
model.palette, model.normalsPalette, model.shadowPalette);
model.Palette, model.normalsPalette, model.shadowPalette);
}
public void Render(WorldRenderer wr)

View File

@@ -18,9 +18,7 @@ namespace OpenRA.Mods.Common.Graphics
public class UITextRenderable : IRenderable, IFinalizedRenderable
{
readonly SpriteFont font;
readonly WPos effectiveWorldPos;
readonly int2 screenPos;
readonly int zOffset;
readonly Color color;
readonly Color bgDark;
readonly Color bgLight;
@@ -29,9 +27,9 @@ namespace OpenRA.Mods.Common.Graphics
public UITextRenderable(SpriteFont font, WPos effectiveWorldPos, int2 screenPos, int zOffset, Color color, Color bgDark, Color bgLight, string text)
{
this.font = font;
this.effectiveWorldPos = effectiveWorldPos;
Pos = effectiveWorldPos;
this.screenPos = screenPos;
this.zOffset = zOffset;
ZOffset = zOffset;
this.color = color;
this.bgDark = bgDark;
this.bgLight = bgLight;
@@ -44,12 +42,12 @@ namespace OpenRA.Mods.Common.Graphics
ChromeMetrics.Get<Color>("TextContrastColorLight"),
text) { }
public WPos Pos => effectiveWorldPos;
public int ZOffset => zOffset;
public WPos Pos { get; }
public int ZOffset { get; }
public bool IsDecoration => true;
public IRenderable WithZOffset(int newOffset) { return new UITextRenderable(font, effectiveWorldPos, screenPos, zOffset, color, text); }
public IRenderable OffsetBy(in WVec vec) { return new UITextRenderable(font, effectiveWorldPos + vec, screenPos, zOffset, color, text); }
public IRenderable WithZOffset(int newOffset) { return new UITextRenderable(font, Pos, screenPos, ZOffset, color, text); }
public IRenderable OffsetBy(in WVec vec) { return new UITextRenderable(font, Pos + vec, screenPos, ZOffset, color, text); }
public IRenderable AsDecoration() { return this; }
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }