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

@@ -79,13 +79,12 @@ namespace OpenRA.Mods.Common.AudioLoaders
public class StreamAbstraction : TagLib.File.IFileAbstraction
{
readonly Stream s;
public StreamAbstraction(Stream s)
{
this.s = s;
ReadStream = s;
}
public Stream ReadStream => s;
public Stream ReadStream { get; }
public Stream WriteStream => throw new NotImplementedException();

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; }

View File

@@ -37,9 +37,10 @@ namespace OpenRA.Mods.Common.Terrain
{
readonly Dictionary<ushort, TheaterTemplate> templates = new Dictionary<ushort, TheaterTemplate>();
readonly Cache<SheetType, SheetBuilder> sheetBuilders;
readonly Sprite missingTile;
readonly MersenneTwister random;
public Sprite MissingTile { get; }
public DefaultTileCache(DefaultTerrain terrainInfo, Action<uint, string> onMissingImage = null)
{
sheetBuilders = new Cache<SheetType, SheetBuilder>(t => new SheetBuilder(t, terrainInfo.SheetSize));
@@ -154,30 +155,28 @@ namespace OpenRA.Mods.Common.Terrain
missingSheetType = SheetType.BGRA;
}
missingTile = sheetBuilders[missingSheetType].Add(new byte[missingDataLength], missingFrameType, new Size(1, 1));
MissingTile = sheetBuilders[missingSheetType].Add(new byte[missingDataLength], missingFrameType, new Size(1, 1));
foreach (var sb in sheetBuilders.Values)
sb.Current.ReleaseBuffer();
}
public bool HasTileSprite(TerrainTile r, int? variant = null)
{
return TileSprite(r, variant) != missingTile;
return TileSprite(r, variant) != MissingTile;
}
public Sprite TileSprite(TerrainTile r, int? variant = null)
{
if (!templates.TryGetValue(r.Type, out var template))
return missingTile;
return MissingTile;
if (r.Index >= template.Stride)
return missingTile;
return MissingTile;
var start = template.Variants > 1 ? variant ?? random.Next(template.Variants) : 0;
return template.Sprites[start * template.Stride + r.Index];
}
public Sprite MissingTile => missingTile;
public void Dispose()
{
foreach (var sb in sheetBuilders.Values)

View File

@@ -235,28 +235,26 @@ namespace OpenRA.Mods.Common.Traits
INotifyCenterPositionChanged[] notifyCenterPositionChanged;
IOverrideAircraftLanding overrideAircraftLanding;
WRot orientation;
[Sync]
public WAngle Facing
{
get => orientation.Yaw;
set => orientation = orientation.WithYaw(value);
get => Orientation.Yaw;
set => Orientation = Orientation.WithYaw(value);
}
public WAngle Pitch
{
get => orientation.Pitch;
set => orientation = orientation.WithPitch(value);
get => Orientation.Pitch;
set => Orientation = Orientation.WithPitch(value);
}
public WAngle Roll
{
get => orientation.Roll;
set => orientation = orientation.WithRoll(value);
get => Orientation.Roll;
set => Orientation = Orientation.WithRoll(value);
}
public WRot Orientation => orientation;
public WRot Orientation { get; private set; }
[Sync]
public WPos CenterPosition { get; private set; }

View File

@@ -109,8 +109,6 @@ namespace OpenRA.Mods.Common.Traits
{
public readonly WeaponInfo Weapon;
public readonly Barrel[] Barrels;
readonly Actor self;
Turreted turret;
BodyOrientation coords;
INotifyBurstComplete[] notifyBurstComplete;
@@ -136,7 +134,7 @@ namespace OpenRA.Mods.Common.Traits
public Armament(Actor self, ArmamentInfo info)
: base(info)
{
this.self = self;
Actor = self;
Weapon = info.WeaponInfo;
Burst = Weapon.Burst;
@@ -400,6 +398,6 @@ namespace OpenRA.Mods.Common.Traits
return WRot.FromYaw(b.Yaw).Rotate(turret?.WorldOrientation ?? self.Orientation);
}
public Actor Actor => self;
public Actor Actor { get; }
}
}

View File

@@ -135,15 +135,13 @@ namespace OpenRA.Mods.Common.Traits
[Sync]
int nextScanTime = 0;
public UnitStance Stance => stance;
public UnitStance Stance { get; private set; }
[Sync]
public Actor Aggressor;
// NOT SYNCED: do not refer to this anywhere other than UI code
public UnitStance PredictedStance;
UnitStance stance;
IOverrideAutoTarget[] overrideAutoTarget;
INotifyStanceChanged[] notifyStanceChanged;
IEnumerable<AutoTargetPriorityInfo> activeTargetPriorities;
@@ -151,19 +149,19 @@ namespace OpenRA.Mods.Common.Traits
public void SetStance(Actor self, UnitStance value)
{
if (stance == value)
if (Stance == value)
return;
var oldStance = stance;
stance = value;
var oldStance = Stance;
Stance = value;
ApplyStanceCondition(self);
foreach (var nsc in notifyStanceChanged)
nsc.StanceChanged(self, this, oldStance, stance);
nsc.StanceChanged(self, this, oldStance, Stance);
if (self.CurrentActivity != null)
foreach (var a in self.CurrentActivity.ActivitiesImplementing<IActivityNotifyStanceChanged>())
a.StanceChanged(self, this, oldStance, stance);
a.StanceChanged(self, this, oldStance, Stance);
}
void ApplyStanceCondition(Actor self)
@@ -171,7 +169,7 @@ namespace OpenRA.Mods.Common.Traits
if (conditionToken != Actor.InvalidConditionToken)
conditionToken = self.RevokeCondition(conditionToken);
if (Info.ConditionByStance.TryGetValue(stance, out var condition))
if (Info.ConditionByStance.TryGetValue(Stance, out var condition))
conditionToken = self.GrantCondition(condition);
}
@@ -181,9 +179,9 @@ namespace OpenRA.Mods.Common.Traits
var self = init.Self;
ActiveAttackBases = self.TraitsImplementing<AttackBase>().ToArray().Where(t => !t.IsTraitDisabled);
stance = init.GetValue<StanceInit, UnitStance>(self.Owner.IsBot || !self.Owner.Playable ? info.InitialStanceAI : info.InitialStance);
Stance = init.GetValue<StanceInit, UnitStance>(self.Owner.IsBot || !self.Owner.Playable ? info.InitialStanceAI : info.InitialStance);
PredictedStance = stance;
PredictedStance = Stance;
allowMovement = Info.AllowMovement && self.TraitOrDefault<IMove>() != null;
}

View File

@@ -146,7 +146,7 @@ namespace OpenRA.Mods.Common.Traits
return randomConstructionYard?.Location ?? initialBaseCenter;
}
public CPos DefenseCenter => defenseCenter;
public CPos DefenseCenter { get; private set; }
readonly World world;
readonly Player player;
@@ -155,8 +155,6 @@ namespace OpenRA.Mods.Common.Traits
IResourceLayer resourceLayer;
IBotPositionsUpdated[] positionsUpdatedModules;
CPos initialBaseCenter;
CPos defenseCenter;
readonly List<BaseBuilderQueueManager> builders = new List<BaseBuilderQueueManager>();
public BaseBuilderBotModule(Actor self, BaseBuilderBotModuleInfo info)
@@ -189,7 +187,7 @@ namespace OpenRA.Mods.Common.Traits
void IBotPositionsUpdated.UpdatedDefenseCenter(CPos newLocation)
{
defenseCenter = newLocation;
DefenseCenter = newLocation;
}
bool IBotRequestPauseUnitProduction.PauseUnitProduction => !IsTraitDisabled && !HasAdequateRefineryCount;
@@ -273,7 +271,7 @@ namespace OpenRA.Mods.Common.Traits
return new List<MiniYamlNode>()
{
new MiniYamlNode("InitialBaseCenter", FieldSaver.FormatValue(initialBaseCenter)),
new MiniYamlNode("DefenseCenter", FieldSaver.FormatValue(defenseCenter))
new MiniYamlNode("DefenseCenter", FieldSaver.FormatValue(DefenseCenter))
};
}
@@ -288,7 +286,7 @@ namespace OpenRA.Mods.Common.Traits
var defenseCenterNode = data.FirstOrDefault(n => n.Key == "DefenseCenter");
if (defenseCenterNode != null)
defenseCenter = FieldLoader.GetValue<CPos>("DefenseCenter", defenseCenterNode.Value.Value);
DefenseCenter = FieldLoader.GetValue<CPos>("DefenseCenter", defenseCenterNode.Value.Value);
}
}
}

View File

@@ -94,20 +94,18 @@ namespace OpenRA.Mods.Common.Traits
{
readonly Actor self;
readonly bool checkTerrainType;
DeployState deployState;
INotifyDeployTriggered[] notify;
int deployedToken = Actor.InvalidConditionToken;
int undeployedToken = Actor.InvalidConditionToken;
public DeployState DeployState => deployState;
public DeployState DeployState { get; private set; }
public GrantConditionOnDeploy(ActorInitializer init, GrantConditionOnDeployInfo info)
: base(info)
{
self = init.Self;
checkTerrainType = info.AllowedTerrainTypes.Count > 0;
deployState = init.GetValue<DeployStateInit, DeployState>(DeployState.Undeployed);
DeployState = init.GetValue<DeployStateInit, DeployState>(DeployState.Undeployed);
}
protected override void Created(Actor self)
@@ -115,14 +113,14 @@ namespace OpenRA.Mods.Common.Traits
notify = self.TraitsImplementing<INotifyDeployTriggered>().ToArray();
base.Created(self);
if (Info.Facing.HasValue && deployState != DeployState.Undeployed)
if (Info.Facing.HasValue && DeployState != DeployState.Undeployed)
{
var facing = self.TraitOrDefault<IFacing>();
if (facing != null)
facing.Facing = Info.Facing.Value;
}
switch (deployState)
switch (DeployState)
{
case DeployState.Undeployed:
OnUndeployCompleted();
@@ -153,10 +151,10 @@ namespace OpenRA.Mods.Common.Traits
bool IDelayCarryallPickup.TryLockForPickup(Actor self, Actor carrier)
{
if (!Info.UndeployOnPickup || deployState == DeployState.Undeployed || IsTraitDisabled)
if (!Info.UndeployOnPickup || DeployState == DeployState.Undeployed || IsTraitDisabled)
return true;
if (deployState == DeployState.Deployed && !IsTraitPaused)
if (DeployState == DeployState.Deployed && !IsTraitPaused)
Undeploy();
return false;
@@ -208,7 +206,7 @@ namespace OpenRA.Mods.Common.Traits
if (IsTraitPaused || IsTraitDisabled)
return false;
return IsValidTerrain(self.Location) || (deployState == DeployState.Deployed);
return IsValidTerrain(self.Location) || (DeployState == DeployState.Deployed);
}
public bool IsValidTerrain(CPos location)
@@ -253,7 +251,7 @@ namespace OpenRA.Mods.Common.Traits
void Deploy(bool init)
{
// Something went wrong, most likely due to deploy order spam and the fact that this is a delayed action.
if (!init && deployState != DeployState.Undeployed)
if (!init && DeployState != DeployState.Undeployed)
return;
if (!IsValidTerrain(self.Location))
@@ -280,7 +278,7 @@ namespace OpenRA.Mods.Common.Traits
void Undeploy(bool init)
{
// Something went wrong, most likely due to deploy order spam and the fact that this is a delayed action.
if (!init && deployState != DeployState.Deployed)
if (!init && DeployState != DeployState.Deployed)
return;
if (Info.UndeploySounds != null && Info.UndeploySounds.Length > 0)
@@ -303,7 +301,7 @@ namespace OpenRA.Mods.Common.Traits
if (undeployedToken != Actor.InvalidConditionToken)
undeployedToken = self.RevokeCondition(undeployedToken);
deployState = DeployState.Deploying;
DeployState = DeployState.Deploying;
}
void OnDeployCompleted()
@@ -311,7 +309,7 @@ namespace OpenRA.Mods.Common.Traits
if (deployedToken == Actor.InvalidConditionToken)
deployedToken = self.GrantCondition(Info.DeployedCondition);
deployState = DeployState.Deployed;
DeployState = DeployState.Deployed;
}
void OnUndeployStarted()
@@ -319,7 +317,7 @@ namespace OpenRA.Mods.Common.Traits
if (deployedToken != Actor.InvalidConditionToken)
deployedToken = self.RevokeCondition(deployedToken);
deployState = DeployState.Deploying;
DeployState = DeployState.Deploying;
}
void OnUndeployCompleted()
@@ -327,7 +325,7 @@ namespace OpenRA.Mods.Common.Traits
if (undeployedToken == Actor.InvalidConditionToken)
undeployedToken = self.GrantCondition(Info.UndeployedCondition);
deployState = DeployState.Undeployed;
DeployState = DeployState.Undeployed;
}
}

View File

@@ -67,16 +67,14 @@ namespace OpenRA.Mods.Common.Traits
[Sync]
public WPos CenterPosition { get; private set; }
WRot orientation;
[Sync]
public WAngle Facing
{
get => orientation.Yaw;
set => orientation = orientation.WithYaw(value);
get => Orientation.Yaw;
set => Orientation = Orientation.WithYaw(value);
}
public WRot Orientation => orientation;
public WRot Orientation { get; private set; }
public WAngle TurnSpeed => WAngle.Zero;

View File

@@ -194,7 +194,6 @@ namespace OpenRA.Mods.Common.Traits
WAngle oldFacing;
WRot orientation;
WPos oldPos;
CPos fromCell, toCell;
public SubCell FromSubCell, ToSubCell;
INotifyCustomLayerChanged[] notifyCustomLayerChanged;
@@ -226,10 +225,10 @@ namespace OpenRA.Mods.Common.Traits
#endregion
[Sync]
public CPos FromCell => fromCell;
public CPos FromCell { get; private set; }
[Sync]
public CPos ToCell => toCell;
public CPos ToCell { get; private set; }
public Locomotor Locomotor { get; private set; }
@@ -274,7 +273,7 @@ namespace OpenRA.Mods.Common.Traits
var locationInit = init.GetOrDefault<LocationInit>();
if (locationInit != null)
{
fromCell = toCell = locationInit.Value;
FromCell = ToCell = locationInit.Value;
SetCenterPosition(self, init.World.Map.CenterOfSubCell(FromCell, FromSubCell));
}
@@ -499,7 +498,7 @@ namespace OpenRA.Mods.Common.Traits
return;
foreach (var n in notifyCenterPositionChanged)
n.CenterPositionChanged(self, fromCell.Layer, toCell.Layer);
n.CenterPositionChanged(self, FromCell.Layer, ToCell.Layer);
}
public void SetTerrainRampOrientation(WRot orientation)
@@ -510,7 +509,7 @@ namespace OpenRA.Mods.Common.Traits
public bool IsLeavingCell(CPos location, SubCell subCell = SubCell.Any)
{
return ToCell != location && fromCell == location
return ToCell != location && FromCell == location
&& (subCell == SubCell.Any || FromSubCell == subCell || subCell == SubCell.FullCell || FromSubCell == SubCell.FullCell);
}
@@ -545,25 +544,25 @@ namespace OpenRA.Mods.Common.Traits
return;
RemoveInfluence();
fromCell = from;
toCell = to;
FromCell = from;
ToCell = to;
FromSubCell = fromSub;
ToSubCell = toSub;
AddInfluence();
IsBlocking = false;
// Most custom layer conditions are added/removed when starting the transition between layers.
if (toCell.Layer != fromCell.Layer)
if (ToCell.Layer != FromCell.Layer)
foreach (var n in notifyCustomLayerChanged)
n.CustomLayerChanged(self, fromCell.Layer, toCell.Layer);
n.CustomLayerChanged(self, FromCell.Layer, ToCell.Layer);
}
public void FinishedMoving(Actor self)
{
// Need to check both fromCell and toCell because FinishedMoving is called multiple times during the move
if (fromCell.Layer == toCell.Layer)
if (FromCell.Layer == ToCell.Layer)
foreach (var n in notifyFinishedMoving)
n.FinishedMoving(self, fromCell.Layer, toCell.Layer);
n.FinishedMoving(self, FromCell.Layer, ToCell.Layer);
// Only crush actors on having landed
if (!self.IsAtGroundLevel())

View File

@@ -126,7 +126,6 @@ namespace OpenRA.Mods.Common.Traits
public class ProductionQueue : IResolveOrder, ITick, ITechTreeElement, INotifyOwnerChanged, INotifyKilled, INotifySold, ISync, INotifyTransform, INotifyCreated
{
public readonly ProductionQueueInfo Info;
readonly Actor self;
// A list of things we could possibly build
protected readonly Dictionary<ActorInfo, ProductionState> Producible = new Dictionary<ActorInfo, ProductionState>();
@@ -142,7 +141,7 @@ namespace OpenRA.Mods.Common.Traits
protected DeveloperMode developerMode;
protected TechTree techTree;
public Actor Actor => self;
public Actor Actor { get; }
[Sync]
public bool Enabled { get; protected set; }
@@ -154,10 +153,10 @@ namespace OpenRA.Mods.Common.Traits
public ProductionQueue(ActorInitializer init, ProductionQueueInfo info)
{
self = init.Self;
Actor = init.Self;
Info = info;
Faction = init.GetValue<FactionInit, string>(self.Owner.Faction.InternalName);
Faction = init.GetValue<FactionInit, string>(Actor.Owner.Faction.InternalName);
IsValidFaction = info.Factions.Count == 0 || info.Factions.Contains(Faction);
Enabled = IsValidFaction;
@@ -205,7 +204,7 @@ namespace OpenRA.Mods.Common.Traits
techTree.Update();
}
void INotifyKilled.Killed(Actor killed, AttackInfo e) { if (killed == self) { ClearQueue(); Enabled = false; } }
void INotifyKilled.Killed(Actor killed, AttackInfo e) { if (killed == Actor) { ClearQueue(); Enabled = false; } }
void INotifySold.Selling(Actor self) { ClearQueue(); Enabled = false; }
void INotifySold.Sold(Actor self) { }
@@ -230,7 +229,7 @@ namespace OpenRA.Mods.Common.Traits
IEnumerable<ActorInfo> AllBuildables(string category)
{
return self.World.Map.Rules.Actors.Values
return Actor.World.Map.Rules.Actors.Values
.Where(x =>
x.Name[0] != '^' &&
x.HasTraitInfo<BuildableInfo>() &&
@@ -239,22 +238,22 @@ namespace OpenRA.Mods.Common.Traits
public void PrerequisitesAvailable(string key)
{
Producible[self.World.Map.Rules.Actors[key]].Buildable = true;
Producible[Actor.World.Map.Rules.Actors[key]].Buildable = true;
}
public void PrerequisitesUnavailable(string key)
{
Producible[self.World.Map.Rules.Actors[key]].Buildable = false;
Producible[Actor.World.Map.Rules.Actors[key]].Buildable = false;
}
public void PrerequisitesItemHidden(string key)
{
Producible[self.World.Map.Rules.Actors[key]].Visible = false;
Producible[Actor.World.Map.Rules.Actors[key]].Visible = false;
}
public void PrerequisitesItemVisible(string key)
{
Producible[self.World.Map.Rules.Actors[key]].Visible = true;
Producible[Actor.World.Map.Rules.Actors[key]].Visible = true;
}
public virtual bool IsProducing(ProductionItem item)
@@ -381,8 +380,8 @@ namespace OpenRA.Mods.Common.Traits
if (bi.BuildLimit > 0)
{
var owned = self.Owner.World.ActorsHavingTrait<Buildable>()
.Count(a => a.Info.Name == actor.Name && a.Owner == self.Owner);
var owned = Actor.Owner.World.ActorsHavingTrait<Buildable>()
.Count(a => a.Info.Name == actor.Name && a.Owner == Actor.Owner);
if (queueCount + owned >= bi.BuildLimit)
return false;
}
@@ -591,7 +590,7 @@ namespace OpenRA.Mods.Common.Traits
{
var traits = productionTraits.Where(p => !p.IsTraitDisabled && p.Info.Produces.Contains(Info.Type));
var unpaused = traits.FirstOrDefault(a => !a.IsTraitPaused);
return new TraitPair<Production>(self, unpaused ?? traits.FirstOrDefault());
return new TraitPair<Production>(Actor, unpaused ?? traits.FirstOrDefault());
}
// Builds a unit from the actor that holds this queue (1 queue per building)
@@ -601,7 +600,7 @@ namespace OpenRA.Mods.Common.Traits
var mostLikelyProducerTrait = MostLikelyProducer().Trait;
// Cannot produce if I'm dead or trait is disabled
if (!self.IsInWorld || self.IsDead || mostLikelyProducerTrait == null)
if (!Actor.IsInWorld || Actor.IsDead || mostLikelyProducerTrait == null)
{
CancelProduction(unit.Name, 1);
return false;
@@ -609,14 +608,14 @@ namespace OpenRA.Mods.Common.Traits
var inits = new TypeDictionary
{
new OwnerInit(self.Owner),
new OwnerInit(Actor.Owner),
new FactionInit(BuildableInfo.GetInitialFaction(unit, Faction))
};
var bi = unit.TraitInfo<BuildableInfo>();
var type = developerMode.AllTech ? Info.Type : (bi.BuildAtProductionType ?? Info.Type);
var item = Queue.First(i => i.Done && i.Item == unit.Name);
if (!mostLikelyProducerTrait.IsTraitPaused && mostLikelyProducerTrait.Produce(self, unit, type, inits, item.TotalCost))
if (!mostLikelyProducerTrait.IsTraitPaused && mostLikelyProducerTrait.Produce(Actor, unit, type, inits, item.TotalCost))
{
EndProduction(item);
return true;

View File

@@ -27,11 +27,10 @@ namespace OpenRA.Mods.Common.Traits
public class TechTree
{
readonly List<Watcher> watchers = new List<Watcher>();
readonly Player player;
public TechTree(ActorInitializer init)
{
player = init.Self.Owner;
Owner = init.Self.Owner;
init.World.ActorAdded += ActorChanged;
init.World.ActorRemoved += ActorChanged;
}
@@ -39,13 +38,13 @@ namespace OpenRA.Mods.Common.Traits
public void ActorChanged(Actor a)
{
var bi = a.Info.TraitInfoOrDefault<BuildableInfo>();
if (a.Owner == player && (a.Info.HasTraitInfo<ITechTreePrerequisiteInfo>() || (bi != null && bi.BuildLimit > 0)))
if (a.Owner == Owner && (a.Info.HasTraitInfo<ITechTreePrerequisiteInfo>() || (bi != null && bi.BuildLimit > 0)))
Update();
}
public void Update()
{
var ownedPrerequisites = GatherOwnedPrerequisites(player);
var ownedPrerequisites = GatherOwnedPrerequisites(Owner);
foreach (var w in watchers)
w.Update(ownedPrerequisites);
}
@@ -67,7 +66,7 @@ namespace OpenRA.Mods.Common.Traits
public bool HasPrerequisites(IEnumerable<string> prerequisites)
{
var ownedPrereqs = GatherOwnedPrerequisites(player);
var ownedPrereqs = GatherOwnedPrerequisites(Owner);
return prerequisites.All(p => !(p.Replace("~", "").StartsWith("!", StringComparison.Ordinal)
^ !ownedPrereqs.ContainsKey(p.Replace("!", "").Replace("~", ""))));
}
@@ -109,16 +108,15 @@ namespace OpenRA.Mods.Common.Traits
return ret;
}
public Player Owner => player;
public Player Owner { get; }
class Watcher
{
public readonly string Key;
public ITechTreeElement RegisteredBy => watcher;
public ITechTreeElement RegisteredBy { get; }
// Strings may be either actor type, or "alternate name" key
readonly string[] prerequisites;
readonly ITechTreeElement watcher;
bool hasPrerequisites;
readonly int limit;
bool hidden;
@@ -128,7 +126,7 @@ namespace OpenRA.Mods.Common.Traits
{
Key = key;
this.prerequisites = prerequisites;
this.watcher = watcher;
RegisteredBy = watcher;
hasPrerequisites = false;
this.limit = limit;
hidden = false;
@@ -179,16 +177,16 @@ namespace OpenRA.Mods.Common.Traits
// Hide the item from the UI if a prereq annotated with '~' is not met.
if (nowHidden && !hidden)
watcher.PrerequisitesItemHidden(Key);
RegisteredBy.PrerequisitesItemHidden(Key);
if (!nowHidden && hidden)
watcher.PrerequisitesItemVisible(Key);
RegisteredBy.PrerequisitesItemVisible(Key);
if (nowHasPrerequisites && !hasPrerequisites)
watcher.PrerequisitesAvailable(Key);
RegisteredBy.PrerequisitesAvailable(Key);
if (!nowHasPrerequisites && hasPrerequisites)
watcher.PrerequisitesUnavailable(Key);
RegisteredBy.PrerequisitesUnavailable(Key);
hidden = nowHidden;
hasPrerequisites = nowHasPrerequisites;

View File

@@ -121,10 +121,9 @@ namespace OpenRA.Mods.Common.Traits
readonly SpawnActorPower power;
readonly SpawnActorPowerInfo info;
readonly SupportPowerManager manager;
readonly string order;
readonly MouseButton expectedButton;
public string OrderKey { get { return order; } }
public string OrderKey { get; }
public SelectSpawnActorPowerTarget(string order, SupportPowerManager manager, SpawnActorPower power, MouseButton button)
{
@@ -134,7 +133,7 @@ namespace OpenRA.Mods.Common.Traits
this.manager = manager;
this.power = power;
this.order = order;
OrderKey = order;
expectedButton = button;
info = (SpawnActorPowerInfo)power.Info;
@@ -148,13 +147,13 @@ namespace OpenRA.Mods.Common.Traits
yield break;
if (mi.Button == expectedButton)
yield return new Order(order, manager.Self, Target.FromCell(world, cell), false) { SuppressVisualFeedback = true };
yield return new Order(OrderKey, manager.Self, Target.FromCell(world, cell), false) { SuppressVisualFeedback = true };
}
protected override void Tick(World world)
{
// Cancel the OG if we can't use the power
if (!manager.Powers.ContainsKey(order))
if (!manager.Powers.ContainsKey(OrderKey))
world.CancelInputMode();
}

View File

@@ -279,11 +279,10 @@ namespace OpenRA.Mods.Common.Traits
public class SelectGenericPowerTarget : OrderGenerator
{
readonly SupportPowerManager manager;
readonly string order;
readonly string cursor;
readonly MouseButton expectedButton;
public string OrderKey => order;
public string OrderKey { get; }
public SelectGenericPowerTarget(string order, SupportPowerManager manager, string cursor, MouseButton button)
{
@@ -292,7 +291,7 @@ namespace OpenRA.Mods.Common.Traits
manager.Self.World.Selection.Clear();
this.manager = manager;
this.order = order;
OrderKey = order;
this.cursor = cursor;
expectedButton = button;
}
@@ -301,13 +300,13 @@ namespace OpenRA.Mods.Common.Traits
{
world.CancelInputMode();
if (mi.Button == expectedButton && world.Map.Contains(cell))
yield return new Order(order, manager.Self, Target.FromCell(world, cell), false) { SuppressVisualFeedback = true };
yield return new Order(OrderKey, manager.Self, Target.FromCell(world, cell), false) { SuppressVisualFeedback = true };
}
protected override void Tick(World world)
{
// Cancel the OG if we can't use the power
if (!manager.Powers.TryGetValue(order, out var p) || !p.Active || !p.Ready)
if (!manager.Powers.TryGetValue(OrderKey, out var p) || !p.Active || !p.Ready)
world.CancelInputMode();
}

View File

@@ -229,24 +229,23 @@ namespace OpenRA.Mods.Common.Traits
struct ActorsAtEnumerator : IEnumerator<Actor>
{
InfluenceNode node;
Actor current;
public ActorsAtEnumerator(InfluenceNode node)
{
this.node = node;
current = null;
Current = null;
}
public void Reset() { throw new NotSupportedException(); }
public Actor Current => current;
public Actor Current { get; private set; }
object IEnumerator.Current => current;
object IEnumerator.Current => Current;
public void Dispose() { }
public bool MoveNext()
{
while (node != null)
{
current = node.Actor;
Current = node.Actor;
node = node.Next;
return true;
}

View File

@@ -26,19 +26,17 @@ namespace OpenRA.Mods.Common.Widgets
public bool DrawOverlay = true;
public bool Skippable = true;
public bool Paused => paused;
public IVideo Video => video;
public bool Paused { get; private set; }
public IVideo Video { get; private set; } = null;
Sprite videoSprite, overlaySprite;
Sheet overlaySheet;
IVideo video = null;
string cachedVideoFileName;
float invLength;
float2 videoOrigin, videoSize;
float2 overlayOrigin, overlaySize;
float overlayScale;
bool stopped;
bool paused;
int textureSize;
Action onComplete;
@@ -110,13 +108,13 @@ namespace OpenRA.Mods.Common.Widgets
/// <param name="video">An <see cref="IVideo"/> instance.</param>
public void Play(IVideo video)
{
this.video = video;
Video = video;
if (video == null)
return;
stopped = true;
paused = true;
Paused = true;
Game.Sound.StopVideo();
onComplete = () => { };
@@ -148,34 +146,34 @@ namespace OpenRA.Mods.Common.Widgets
public override void Draw()
{
if (video == null)
if (Video == null)
return;
if (!stopped && !paused)
if (!stopped && !Paused)
{
int nextFrame;
if (video.HasAudio && !Game.Sound.DummyEngine)
nextFrame = (int)float2.Lerp(0, video.FrameCount, Game.Sound.VideoSeekPosition * invLength);
if (Video.HasAudio && !Game.Sound.DummyEngine)
nextFrame = (int)float2.Lerp(0, Video.FrameCount, Game.Sound.VideoSeekPosition * invLength);
else
nextFrame = video.CurrentFrameIndex + 1;
nextFrame = Video.CurrentFrameIndex + 1;
// Without the 2nd check the sound playback sometimes ends before the final frame is displayed which causes the player to be stuck on the first frame
if (nextFrame > video.FrameCount || nextFrame < video.CurrentFrameIndex)
if (nextFrame > Video.FrameCount || nextFrame < Video.CurrentFrameIndex)
{
Stop();
return;
}
var skippedFrames = 0;
while (nextFrame > video.CurrentFrameIndex)
while (nextFrame > Video.CurrentFrameIndex)
{
video.AdvanceFrame();
videoSprite.Sheet.GetTexture().SetData(video.CurrentFrameData, textureSize, textureSize);
Video.AdvanceFrame();
videoSprite.Sheet.GetTexture().SetData(Video.CurrentFrameData, textureSize, textureSize);
skippedFrames++;
}
if (skippedFrames > 1)
Log.Write("perf", $"{nameof(VideoPlayerWidget)}: {cachedVideoFileName} skipped {skippedFrames} frames at position {video.CurrentFrameIndex}");
Log.Write("perf", $"{nameof(VideoPlayerWidget)}: {cachedVideoFileName} skipped {skippedFrames} frames at position {Video.CurrentFrameIndex}");
}
WidgetUtils.DrawSprite(videoSprite, videoOrigin, videoSize);
@@ -196,7 +194,7 @@ namespace OpenRA.Mods.Common.Widgets
// Calculate the scan line height by converting the video scale (copied from Open()) to screen
// pixels, halving it (scan lines cover half the pixel height), and rounding to the nearest integer.
var videoScale = Math.Min((float)RenderBounds.Width / video.Width, RenderBounds.Height / (video.Height * AspectRatio));
var videoScale = Math.Min((float)RenderBounds.Width / Video.Width, RenderBounds.Height / (Video.Height * AspectRatio));
var halfRowHeight = (int)(videoScale * scale / 2 + 0.5f);
// If the video is "too tightly packed" into the player and there is no room for drawing an overlay disable it.
@@ -255,37 +253,37 @@ namespace OpenRA.Mods.Common.Widgets
public void PlayThen(Action after)
{
if (video == null)
if (Video == null)
return;
onComplete = after;
if (stopped && video.HasAudio)
Game.Sound.PlayVideo(video.AudioData, video.AudioChannels, video.SampleBits, video.SampleRate);
if (stopped && Video.HasAudio)
Game.Sound.PlayVideo(Video.AudioData, Video.AudioChannels, Video.SampleBits, Video.SampleRate);
else
Game.Sound.PlayVideo();
stopped = paused = false;
stopped = Paused = false;
}
public void Pause()
{
if (stopped || paused || video == null)
if (stopped || Paused || Video == null)
return;
paused = true;
Paused = true;
Game.Sound.PauseVideo();
}
public void Stop()
{
if (stopped || video == null)
if (stopped || Video == null)
return;
stopped = true;
paused = true;
Paused = true;
Game.Sound.StopVideo();
video.Reset();
videoSprite.Sheet.GetTexture().SetData(video.CurrentFrameData, textureSize, textureSize);
Video.Reset();
videoSprite.Sheet.GetTexture().SetData(Video.CurrentFrameData, textureSize, textureSize);
Game.RunAfterTick(() =>
{
if (onComplete != null)
@@ -299,7 +297,7 @@ namespace OpenRA.Mods.Common.Widgets
public void CloseVideo()
{
Stop();
video = null;
Video = null;
}
}
}