Add readonly to structs

This commit is contained in:
teinarss
2021-01-29 16:56:11 +01:00
committed by abcdefg30
parent 65c796dec7
commit 6b74093c04
83 changed files with 146 additions and 125 deletions

View File

@@ -25,7 +25,7 @@ namespace OpenRA
{
public sealed class Actor : IScriptBindable, IScriptNotifyBind, ILuaTableBinding, ILuaEqualityBinding, ILuaToStringBinding, IEquatable<Actor>, IDisposable
{
internal struct SyncHash
internal readonly struct SyncHash
{
public readonly ISync Trait;
readonly Func<object, int> hashFunction;

View File

@@ -16,7 +16,7 @@ using OpenRA.Scripting;
namespace OpenRA
{
public struct CPos : IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaEqualityBinding, ILuaTableBinding, IEquatable<CPos>
public readonly struct CPos : IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaEqualityBinding, ILuaTableBinding, IEquatable<CPos>
{
// Coordinates are packed in a 32 bit signed int
// X and Y are 12 bits (signed): -2048...2047

View File

@@ -17,7 +17,7 @@ using OpenRA.Scripting;
namespace OpenRA
{
public struct CVec : IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaUnaryMinusBinding, ILuaEqualityBinding, ILuaTableBinding, IEquatable<CVec>
public readonly struct CVec : IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaUnaryMinusBinding, ILuaEqualityBinding, ILuaTableBinding, IEquatable<CVec>
{
public readonly int X, Y;

View File

@@ -52,7 +52,7 @@ namespace OpenRA.Graphics
public int CurrentFrame => backwards ? CurrentSequence.Length - frame - 1 : frame;
public Sprite Image => CurrentSequence.GetSprite(CurrentFrame, facingFunc());
public IRenderable[] Render(WPos pos, WVec offset, int zOffset, PaletteReference palette)
public IRenderable[] Render(WPos pos, in WVec offset, int zOffset, PaletteReference palette)
{
var tintModifiers = CurrentSequence.IgnoreWorldTint ? TintModifiers.IgnoreWorldTint : TintModifiers.None;
var alpha = CurrentSequence.GetAlpha(CurrentFrame);
@@ -68,7 +68,7 @@ namespace OpenRA.Graphics
return new IRenderable[] { imageRenderable };
}
public IRenderable[] RenderUI(WorldRenderer wr, int2 pos, WVec offset, int zOffset, PaletteReference palette, float scale = 1f)
public IRenderable[] RenderUI(WorldRenderer wr, int2 pos, in WVec offset, int zOffset, PaletteReference palette, float scale = 1f)
{
scale *= CurrentSequence.Scale;
var screenOffset = (scale * wr.ScreenVectorComponents(offset)).XY.ToInt2();
@@ -87,7 +87,7 @@ namespace OpenRA.Graphics
return new IRenderable[] { imageRenderable };
}
public Rectangle ScreenBounds(WorldRenderer wr, WPos pos, WVec offset)
public Rectangle ScreenBounds(WorldRenderer wr, WPos pos, in WVec offset)
{
var scale = CurrentSequence.Scale;
var xy = wr.ScreenPxPosition(pos) + wr.ScreenPxOffset(offset);

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Graphics
Rectangle AggregateBounds { get; }
}
public struct ModelRenderData
public readonly struct ModelRenderData
{
public readonly int Start;
public readonly int Count;

View File

@@ -14,7 +14,7 @@ using OpenRA.Primitives;
namespace OpenRA.Graphics
{
public struct ModelAnimation
public readonly struct ModelAnimation
{
public readonly IModel Model;
public readonly Func<WVec> OffsetFunc;

View File

@@ -145,7 +145,7 @@ namespace OpenRA
TriangleList,
}
public struct Range<T>
public readonly struct Range<T>
{
public readonly T Start, End;
public Range(T start, T end) { Start = start; End = end; }

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Graphics
bool IsDecoration { get; }
IRenderable WithZOffset(int newOffset);
IRenderable OffsetBy(WVec offset);
IRenderable OffsetBy(in WVec offset);
IRenderable AsDecoration();
IFinalizedRenderable PrepareRender(WorldRenderer wr);

View File

@@ -55,7 +55,7 @@ namespace OpenRA.Graphics
public IPalettedRenderable WithPalette(PaletteReference newPalette) { return new SpriteRenderable(sprite, pos, offset, zOffset, newPalette, scale, alpha, tint, tintModifiers, isDecoration); }
public IRenderable WithZOffset(int newOffset) { return new SpriteRenderable(sprite, pos, offset, newOffset, palette, scale, alpha, tint, tintModifiers, isDecoration); }
public IRenderable OffsetBy(WVec vec) { return new SpriteRenderable(sprite, pos + vec, offset, zOffset, palette, scale, alpha, tint, tintModifiers, isDecoration); }
public IRenderable OffsetBy(in WVec vec) { return new SpriteRenderable(sprite, pos + vec, offset, zOffset, palette, scale, alpha, tint, tintModifiers, isDecoration); }
public IRenderable AsDecoration() { return new SpriteRenderable(sprite, pos, offset, zOffset, palette, scale, alpha, tint, tintModifiers, true); }
public IModifyableRenderable WithAlpha(float newAlpha)

View File

@@ -35,7 +35,14 @@ namespace OpenRA.Graphics
public bool IsDecoration => true;
public IRenderable WithZOffset(int newOffset) { return new TargetLineRenderable(waypoints, color); }
public IRenderable OffsetBy(WVec vec) { return new TargetLineRenderable(waypoints.Select(w => w + vec), color); }
public IRenderable OffsetBy(in WVec vec)
{
// Lambdas can't use 'in' variables, so capture a copy for later
var offset = vec;
return new TargetLineRenderable(waypoints.Select(w => w + offset), color);
}
public IRenderable AsDecoration() { return this; }
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }

View File

@@ -44,7 +44,7 @@ namespace OpenRA.Graphics
public IPalettedRenderable WithPalette(PaletteReference newPalette) { return new UISpriteRenderable(sprite, effectiveWorldPos, screenPos, zOffset, newPalette, scale, alpha); }
public IRenderable WithZOffset(int newOffset) { return this; }
public IRenderable OffsetBy(WVec vec) { return this; }
public IRenderable OffsetBy(in WVec vec) { return this; }
public IRenderable AsDecoration() { return this; }
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }

View File

@@ -14,7 +14,7 @@ using System.Runtime.InteropServices;
namespace OpenRA.Graphics
{
[StructLayout(LayoutKind.Sequential)]
public struct Vertex
public readonly struct Vertex
{
// 3d position
public readonly float X, Y, Z;

View File

@@ -373,7 +373,7 @@ namespace OpenRA.Graphics
}
// For scaling vectors to pixel sizes in the model renderer
public float3 ScreenVectorComponents(WVec vec)
public float3 ScreenVectorComponents(in WVec vec)
{
return new float3(
(float)TileSize.Width * vec.X / TileScale,
@@ -382,13 +382,13 @@ namespace OpenRA.Graphics
}
// For scaling vectors to pixel sizes in the model renderer
public float[] ScreenVector(WVec vec)
public float[] ScreenVector(in WVec vec)
{
var xyz = ScreenVectorComponents(vec);
return new[] { xyz.X, xyz.Y, xyz.Z, 1f };
}
public int2 ScreenPxOffset(WVec vec)
public int2 ScreenPxOffset(in WVec vec)
{
// Round to nearest pixel
var xyz = ScreenVectorComponents(vec);

View File

@@ -13,7 +13,7 @@ using System;
namespace OpenRA
{
public struct Hotkey : IEquatable<Hotkey>
public readonly struct Hotkey : IEquatable<Hotkey>
{
public static Hotkey Invalid = new Hotkey(Keycode.UNKNOWN, Modifiers.None);
public bool IsValid()

View File

@@ -14,7 +14,7 @@ using OpenRA.Primitives;
namespace OpenRA
{
public struct MPos : IEquatable<MPos>
public readonly struct MPos : IEquatable<MPos>
{
public readonly int U, V;
@@ -66,7 +66,7 @@ namespace OpenRA
/// <summary>
/// Projected map position
/// </summary>
public struct PPos : IEquatable<PPos>
public readonly struct PPos : IEquatable<PPos>
{
public readonly int U, V;

View File

@@ -24,7 +24,7 @@ using OpenRA.Traits;
namespace OpenRA
{
struct BinaryDataHeader
readonly struct BinaryDataHeader
{
public readonly byte Format;
public readonly uint TilesOffset;
@@ -1225,7 +1225,7 @@ namespace OpenRA
return AllEdgeCells.Random(rand);
}
public WDist DistanceToEdge(WPos pos, WVec dir)
public WDist DistanceToEdge(WPos pos, in WVec dir)
{
var projectedPos = pos - new WVec(0, pos.Z, pos.Z);
var x = dir.X == 0 ? int.MaxValue : ((dir.X < 0 ? ProjectedTopLeft.X : ProjectedBottomRight.X) - projectedPos.X) / dir.X;

View File

@@ -14,7 +14,7 @@ using System.Collections.Generic;
namespace OpenRA
{
public struct MapCoordsRegion : IEnumerable<MPos>
public readonly struct MapCoordsRegion : IEnumerable<MPos>
{
public struct MapCoordsEnumerator : IEnumerator<MPos>
{

View File

@@ -22,7 +22,7 @@ namespace OpenRA
public enum RampSplit { Flat, X, Y }
public enum RampCornerHeight { Low = 0, Half = 1, Full = 2 }
public struct CellRamp
public readonly struct CellRamp
{
public readonly int CenterHeightOffset;
public readonly WVec[] Corners;

View File

@@ -11,7 +11,7 @@
namespace OpenRA
{
public struct TerrainTile
public readonly struct TerrainTile
{
public readonly ushort Type;
public readonly byte Index;
@@ -27,7 +27,7 @@ namespace OpenRA
public override string ToString() { return Type + "," + Index; }
}
public struct ResourceTile
public readonly struct ResourceTile
{
public readonly byte Type;
public readonly byte Index;

View File

@@ -65,7 +65,7 @@ namespace OpenRA.Primitives
}
}
struct DelayedAction : IComparable<DelayedAction>
readonly struct DelayedAction : IComparable<DelayedAction>
{
public readonly long Time;
public readonly Action Action;

View File

@@ -75,7 +75,7 @@ namespace OpenRA.Primitives
}
}
public struct BitSet<T> : IEnumerable<string>, IEquatable<BitSet<T>> where T : class
public readonly struct BitSet<T> : IEnumerable<string>, IEquatable<BitSet<T>> where T : class
{
readonly BitSetIndex bits;

View File

@@ -15,7 +15,7 @@ using OpenRA.Scripting;
namespace OpenRA.Primitives
{
public struct Color : IEquatable<Color>, IScriptBindable
public readonly struct Color : IEquatable<Color>, IScriptBindable
{
readonly long argb;

View File

@@ -13,7 +13,7 @@ using System;
namespace OpenRA
{
public struct Int32Matrix4x4 : IEquatable<Int32Matrix4x4>
public readonly struct Int32Matrix4x4 : IEquatable<Int32Matrix4x4>
{
public readonly int M11, M12, M13, M14, M21, M22, M23, M24, M31, M32, M33, M34, M41, M42, M43, M44;

View File

@@ -92,7 +92,7 @@ namespace OpenRA.Primitives
}
// Opitmized BitSet to be used only when guaranteed to be no more than 64 values.
public struct LongBitSet<T> : IEnumerable<string>, IEquatable<LongBitSet<T>> where T : class
public readonly struct LongBitSet<T> : IEnumerable<string>, IEquatable<LongBitSet<T>> where T : class
{
readonly long bits;

View File

@@ -17,7 +17,7 @@ namespace OpenRA.Primitives
/// <summary>
/// Provides a mapping of players to values, as well as fast lookup by player index.
/// </summary>
public struct PlayerDictionary<T> : IReadOnlyList<T>, IReadOnlyDictionary<Player, T> where T : class
public readonly struct PlayerDictionary<T> : IReadOnlyList<T>, IReadOnlyDictionary<Player, T> where T : class
{
readonly T[] valueByPlayerIndex;
readonly Dictionary<Player, T> valueByPlayer;

View File

@@ -14,13 +14,13 @@ using System.Linq;
namespace OpenRA.Primitives
{
public struct Polygon
public readonly struct Polygon
{
public static readonly Polygon Empty = new Polygon(Rectangle.Empty);
public readonly Rectangle BoundingRect;
public readonly int2[] Vertices;
bool isRectangle;
readonly bool isRectangle;
public Polygon(Rectangle bounds)
{

View File

@@ -13,7 +13,7 @@ using System;
namespace OpenRA.Primitives
{
public struct Size : IEquatable<Size>
public readonly struct Size : IEquatable<Size>
{
public readonly int Width;
public readonly int Height;

View File

@@ -18,7 +18,7 @@ namespace OpenRA
{
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:ElementMustBeginWithUpperCaseLetter", Justification = "Mimic a built-in type alias.")]
[StructLayout(LayoutKind.Sequential)]
public struct float2 : IEquatable<float2>
public readonly struct float2 : IEquatable<float2>
{
public readonly float X, Y;

View File

@@ -16,7 +16,7 @@ using OpenRA.Primitives;
namespace OpenRA
{
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:ElementMustBeginWithUpperCaseLetter", Justification = "Mimic a built-in type alias.")]
public struct int2 : IEquatable<int2>
public readonly struct int2 : IEquatable<int2>
{
public readonly int X, Y;
public int2(int x, int y) { X = x; Y = y; }

View File

@@ -73,7 +73,7 @@ namespace OpenRA.Traits
return actors.MaxByOrDefault(a => CalculateActorSelectionPriority(a.Info, a.MouseBounds, selectionPixel, modifiers));
}
static long CalculateActorSelectionPriority(ActorInfo info, Polygon bounds, int2 selectionPixel, Modifiers modifiers)
static long CalculateActorSelectionPriority(ActorInfo info, in Polygon bounds, int2 selectionPixel, Modifiers modifiers)
{
if (bounds.IsEmpty)
return info.SelectionPriority(modifiers);

View File

@@ -14,7 +14,7 @@ using System.Diagnostics;
namespace OpenRA.Support
{
public struct PerfSample : IDisposable
public readonly struct PerfSample : IDisposable
{
readonly string item;
readonly long ticks;

View File

@@ -157,7 +157,7 @@ namespace OpenRA.Support
Invalid = ~0
}
struct TokenTypeInfo
readonly struct TokenTypeInfo
{
public readonly string Symbol;
public readonly Precedence Precedence;

View File

@@ -249,7 +249,7 @@ namespace OpenRA
}
}
struct AllEnumerable : IEnumerable<TraitPair<T>>
readonly struct AllEnumerable : IEnumerable<TraitPair<T>>
{
readonly TraitContainer<T> container;
public AllEnumerable(TraitContainer<T> container) { this.container = container; }

View File

@@ -18,7 +18,7 @@ using OpenRA.Primitives;
namespace OpenRA.Traits
{
public struct ActorBoundsPair
public readonly struct ActorBoundsPair
{
public readonly Actor Actor;
public readonly Polygon Bounds;

View File

@@ -19,7 +19,7 @@ namespace OpenRA
/// <summary>
/// 1D angle - 1024 units = 360 degrees.
/// </summary>
public struct WAngle : IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaEqualityBinding, IEquatable<WAngle>
public readonly struct WAngle : IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaEqualityBinding, IEquatable<WAngle>
{
public readonly int Angle;
public int AngleSquared => (int)Angle * Angle;

View File

@@ -21,7 +21,7 @@ namespace OpenRA
/// <summary>
/// 1d world distance - 1024 units = 1 cell.
/// </summary>
public struct WDist : IComparable, IComparable<WDist>, IEquatable<WDist>, IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaEqualityBinding, ILuaTableBinding
public readonly struct WDist : IComparable, IComparable<WDist>, IEquatable<WDist>, IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaEqualityBinding, ILuaTableBinding
{
public readonly int Length;
public long LengthSquared => (long)Length * Length;

View File

@@ -18,7 +18,7 @@ using OpenRA.Scripting;
namespace OpenRA
{
public struct WPos : IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaEqualityBinding, ILuaTableBinding, IEquatable<WPos>
public readonly struct WPos : IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaEqualityBinding, ILuaTableBinding, IEquatable<WPos>
{
public readonly int X, Y, Z;
@@ -27,24 +27,24 @@ namespace OpenRA
public static readonly WPos Zero = new WPos(0, 0, 0);
public static explicit operator WVec(WPos a) { return new WVec(a.X, a.Y, a.Z); }
public static explicit operator WVec(in WPos a) { return new WVec(a.X, a.Y, a.Z); }
public static WPos operator +(WPos a, WVec b) { return new WPos(a.X + b.X, a.Y + b.Y, a.Z + b.Z); }
public static WPos operator -(WPos a, WVec b) { return new WPos(a.X - b.X, a.Y - b.Y, a.Z - b.Z); }
public static WVec operator -(WPos a, WPos b) { return new WVec(a.X - b.X, a.Y - b.Y, a.Z - b.Z); }
public static WPos operator +(in WPos a, in WVec b) { return new WPos(a.X + b.X, a.Y + b.Y, a.Z + b.Z); }
public static WPos operator -(in WPos a, in WVec b) { return new WPos(a.X - b.X, a.Y - b.Y, a.Z - b.Z); }
public static WVec operator -(in WPos a, in WPos b) { return new WVec(a.X - b.X, a.Y - b.Y, a.Z - b.Z); }
public static bool operator ==(WPos me, WPos other) { return me.X == other.X && me.Y == other.Y && me.Z == other.Z; }
public static bool operator !=(WPos me, WPos other) { return !(me == other); }
public static bool operator ==(in WPos me, in WPos other) { return me.X == other.X && me.Y == other.Y && me.Z == other.Z; }
public static bool operator !=(in WPos me, in WPos other) { return !(me == other); }
/// <summary>
/// Returns the linear interpolation between points 'a' and 'b'
/// </summary>
public static WPos Lerp(WPos a, WPos b, int mul, int div) { return a + (b - a) * mul / div; }
public static WPos Lerp(in WPos a, in WPos b, int mul, int div) { return a + (b - a) * mul / div; }
/// <summary>
/// Returns the linear interpolation between points 'a' and 'b'
/// </summary>
public static WPos Lerp(WPos a, WPos b, long mul, long div)
public static WPos Lerp(in WPos a, in WPos b, long mul, long div)
{
// The intermediate variables may need more precision than
// an int can provide, so we can't use WPos.
@@ -55,7 +55,7 @@ namespace OpenRA
return new WPos(x, y, z);
}
public static WPos LerpQuadratic(WPos a, WPos b, WAngle pitch, int mul, int div)
public static WPos LerpQuadratic(in WPos a, in WPos b, WAngle pitch, int mul, int div)
{
// Start with a linear lerp between the points
var ret = Lerp(a, b, mul, div);

View File

@@ -17,7 +17,7 @@ using OpenRA.Support;
namespace OpenRA
{
public struct WVec : IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaUnaryMinusBinding, ILuaEqualityBinding, ILuaTableBinding, IEquatable<WVec>
public readonly struct WVec : IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaUnaryMinusBinding, ILuaEqualityBinding, ILuaTableBinding, IEquatable<WVec>
{
public readonly int X, Y, Z;
@@ -26,17 +26,17 @@ namespace OpenRA
public static readonly WVec Zero = new WVec(0, 0, 0);
public static WVec operator +(WVec a, WVec b) { return new WVec(a.X + b.X, a.Y + b.Y, a.Z + b.Z); }
public static WVec operator -(WVec a, WVec b) { return new WVec(a.X - b.X, a.Y - b.Y, a.Z - b.Z); }
public static WVec operator -(WVec a) { return new WVec(-a.X, -a.Y, -a.Z); }
public static WVec operator /(WVec a, int b) { return new WVec(a.X / b, a.Y / b, a.Z / b); }
public static WVec operator *(int a, WVec b) { return new WVec(a * b.X, a * b.Y, a * b.Z); }
public static WVec operator *(WVec a, int b) { return b * a; }
public static WVec operator +(in WVec a, in WVec b) { return new WVec(a.X + b.X, a.Y + b.Y, a.Z + b.Z); }
public static WVec operator -(in WVec a, in WVec b) { return new WVec(a.X - b.X, a.Y - b.Y, a.Z - b.Z); }
public static WVec operator -(in WVec a) { return new WVec(-a.X, -a.Y, -a.Z); }
public static WVec operator /(in WVec a, int b) { return new WVec(a.X / b, a.Y / b, a.Z / b); }
public static WVec operator *(int a, in WVec b) { return new WVec(a * b.X, a * b.Y, a * b.Z); }
public static WVec operator *(in WVec a, int b) { return b * a; }
public static bool operator ==(WVec me, WVec other) { return me.X == other.X && me.Y == other.Y && me.Z == other.Z; }
public static bool operator !=(WVec me, WVec other) { return !(me == other); }
public static bool operator ==(in WVec me, in WVec other) { return me.X == other.X && me.Y == other.Y && me.Z == other.Z; }
public static bool operator !=(in WVec me, in WVec other) { return !(me == other); }
public static int Dot(WVec a, WVec b) { return a.X * b.X + a.Y * b.Y + a.Z * b.Z; }
public static int Dot(in WVec a, in WVec b) { return a.X * b.X + a.Y * b.Y + a.Z * b.Z; }
public long LengthSquared => (long)X * X + (long)Y * Y + (long)Z * Z;
public int Length => (int)Exts.ISqrt(LengthSquared);
public long HorizontalLengthSquared => (long)X * X + (long)Y * Y;
@@ -73,9 +73,9 @@ namespace OpenRA
}
}
public static WVec Lerp(WVec a, WVec b, int mul, int div) { return a + (b - a) * mul / div; }
public static WVec Lerp(in WVec a, in WVec b, int mul, int div) { return a + (b - a) * mul / div; }
public static WVec LerpQuadratic(WVec a, WVec b, WAngle pitch, int mul, int div)
public static WVec LerpQuadratic(in WVec a, in WVec b, WAngle pitch, int mul, int div)
{
// Start with a linear lerp between the points
var ret = Lerp(a, b, mul, div);

View File

@@ -576,7 +576,7 @@ namespace OpenRA
}
}
public struct TraitPair<T> : IEquatable<TraitPair<T>>
public readonly struct TraitPair<T> : IEquatable<TraitPair<T>>
{
public readonly Actor Actor;
public readonly T Trait;

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Mods.Cnc.Activities
readonly WithVoxelUnloadBody body;
readonly WithDockingOverlay spriteOverlay;
public VoxelHarvesterDockSequence(Actor self, Actor refinery, WAngle dockAngle, bool isDragRequired, WVec dragOffset, int dragLength)
public VoxelHarvesterDockSequence(Actor self, Actor refinery, WAngle dockAngle, bool isDragRequired, in WVec dragOffset, int dragLength)
: base(self, refinery, dockAngle, isDragRequired, dragOffset, dragLength)
{
body = self.Trait<WithVoxelUnloadBody>();

View File

@@ -44,7 +44,7 @@ namespace OpenRA.Mods.Cnc.Graphics
WVec cachedLength;
IEnumerable<IFinalizedRenderable> cache;
public TeslaZapRenderable(WPos pos, int zOffset, WVec length, string image, string brightSequence, int brightZaps, string dimSequence, int dimZaps, string palette)
public TeslaZapRenderable(WPos pos, int zOffset, in WVec length, string image, string brightSequence, int brightZaps, string dimSequence, int dimZaps, string palette)
{
this.pos = pos;
this.zOffset = zOffset;
@@ -72,7 +72,7 @@ namespace OpenRA.Mods.Cnc.Graphics
}
public IRenderable WithZOffset(int newOffset) { return new TeslaZapRenderable(pos, zOffset, length, image, brightSequence, brightZaps, dimSequence, dimZaps, palette); }
public IRenderable OffsetBy(WVec vec) { return new TeslaZapRenderable(pos + vec, zOffset, length, image, brightSequence, brightZaps, dimSequence, dimZaps, palette); }
public IRenderable OffsetBy(in WVec vec) { return new TeslaZapRenderable(pos + vec, zOffset, length, image, brightSequence, brightZaps, dimSequence, dimZaps, palette); }
public IRenderable AsDecoration() { return this; }
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }

View File

@@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Activities
this.minRange = minRange;
}
public static void FlyTick(Actor self, Aircraft aircraft, WAngle desiredFacing, WDist desiredAltitude, WVec moveOverride, bool idleTurn = false)
public static void FlyTick(Actor self, Aircraft aircraft, WAngle desiredFacing, WDist desiredAltitude, in WVec moveOverride, bool idleTurn = false)
{
var dat = self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition);
var move = aircraft.Info.CanSlide ? aircraft.FlyStep(desiredFacing) : aircraft.FlyStep(aircraft.Facing);

View File

@@ -46,10 +46,10 @@ namespace OpenRA.Mods.Common.Activities
public Land(Actor self, in Target target, WDist landRange, WAngle? facing = null, Color? targetLineColor = null)
: this(self, target, landRange, WVec.Zero, facing, targetLineColor: targetLineColor) { }
public Land(Actor self, in Target target, WVec offset, WAngle? facing = null, Color? targetLineColor = null)
public Land(Actor self, in Target target, in WVec offset, WAngle? facing = null, Color? targetLineColor = null)
: this(self, target, WDist.Zero, offset, facing, targetLineColor: targetLineColor) { }
public Land(Actor self, in Target target, WDist landRange, WVec offset, WAngle? facing = null, CPos[] clearCells = null, Color? targetLineColor = null)
public Land(Actor self, in Target target, WDist landRange, in WVec offset, WAngle? facing = null, CPos[] clearCells = null, Color? targetLineColor = null)
{
aircraft = self.Trait<Aircraft>();
this.target = target;

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Activities
protected DockingState dockingState;
public HarvesterDockSequence(Actor self, Actor refinery, WAngle dockAngle, bool isDragRequired, WVec dragOffset, int dragLength)
public HarvesterDockSequence(Actor self, Actor refinery, WAngle dockAngle, bool isDragRequired, in WVec dragOffset, int dragLength)
{
dockingState = DockingState.Turn;
Refinery = refinery;

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Mods.Common.Activities
readonly WithDockingAnimationInfo wda;
protected bool dockAnimPlayed;
public SpriteHarvesterDockSequence(Actor self, Actor refinery, WAngle dockAngle, bool isDragRequired, WVec dragOffset, int dragLength)
public SpriteHarvesterDockSequence(Actor self, Actor refinery, WAngle dockAngle, bool isDragRequired, in WVec dragOffset, int dragLength)
: base(self, refinery, dockAngle, isDragRequired, dragOffset, dragLength)
{
wsb = self.Trait<WithSpriteBody>();

View File

@@ -108,7 +108,7 @@ namespace OpenRA.Mods.Common.Widgets
}
}
struct CellResource
readonly struct CellResource
{
public readonly CPos Cell;
public readonly ResourceTile ResourceTile;

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.FileFormats
Next = 0x2
}
struct FileGroup
readonly struct FileGroup
{
public readonly string Name;
public readonly uint FirstFile;
@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.FileFormats
}
}
struct CabDescriptor
readonly struct CabDescriptor
{
public readonly long FileTableOffset;
public readonly uint FileTableSize;
@@ -78,7 +78,7 @@ namespace OpenRA.Mods.Common.FileFormats
}
}
struct DirectoryDescriptor
readonly struct DirectoryDescriptor
{
public readonly string Name;
@@ -94,7 +94,7 @@ namespace OpenRA.Mods.Common.FileFormats
}
}
struct FileDescriptor
readonly struct FileDescriptor
{
public readonly uint Index;
public readonly CABFlags Flags;
@@ -142,7 +142,7 @@ namespace OpenRA.Mods.Common.FileFormats
}
}
struct CommonHeader
readonly struct CommonHeader
{
public const long Size = 16;
public readonly uint Version;
@@ -159,7 +159,7 @@ namespace OpenRA.Mods.Common.FileFormats
}
}
struct VolumeHeader
readonly struct VolumeHeader
{
public readonly uint DataOffset;
public readonly uint DataOffsetHigh;

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.FileSystem
{
public sealed class InstallShieldPackage : IReadOnlyPackage
{
public struct Entry
public readonly struct Entry
{
public readonly uint Offset;
public readonly uint Length;

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Graphics
readonly WDist width;
readonly Color color;
public BeamRenderable(WPos pos, int zOffset, WVec length, BeamRenderableShape shape, WDist width, Color color)
public BeamRenderable(WPos pos, int zOffset, in WVec length, BeamRenderableShape shape, WDist width, Color color)
{
this.pos = pos;
this.zOffset = zOffset;
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Graphics
public bool IsDecoration => true;
public IRenderable WithZOffset(int newOffset) { return new BeamRenderable(pos, zOffset, length, shape, width, color); }
public IRenderable OffsetBy(WVec vec) { return new BeamRenderable(pos + vec, 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; }

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Graphics
public bool IsDecoration => true;
public IRenderable WithZOffset(int newOffset) { return new CircleAnnotationRenderable(centerPosition, radius, width, color, filled); }
public IRenderable OffsetBy(WVec vec) { return new CircleAnnotationRenderable(centerPosition + vec, radius, width, color, filled); }
public IRenderable OffsetBy(in WVec vec) { return new CircleAnnotationRenderable(centerPosition + vec, radius, width, color, filled); }
public IRenderable AsDecoration() { return this; }
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }

View File

@@ -50,7 +50,14 @@ namespace OpenRA.Mods.Common.Graphics
public bool IsDecoration => true;
public IRenderable WithZOffset(int newOffset) { return new ContrailRenderable(world, (WPos[])trail.Clone(), width, next, length, skip, color, newOffset); }
public IRenderable OffsetBy(WVec vec) { return new ContrailRenderable(world, trail.Select(pos => pos + vec).ToArray(), width, next, length, skip, color, zOffset); }
public IRenderable OffsetBy(in WVec vec)
{
// 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, color, zOffset);
}
public IRenderable AsDecoration() { return this; }
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }

View File

@@ -52,7 +52,7 @@ namespace OpenRA.Mods.Common.Graphics
trailCount, trailSeparation, trailAngle, color, width, borderColor, borderWidth);
}
public IRenderable OffsetBy(WVec vec)
public IRenderable OffsetBy(in WVec vec)
{
return new DetectionCircleAnnotationRenderable(centerPosition + vec, radius, zOffset,
trailCount, trailSeparation, trailAngle, color, width, borderColor, borderWidth);

View File

@@ -54,7 +54,7 @@ namespace OpenRA.Mods.Common.Graphics
public bool IsDecoration => true;
public IRenderable WithZOffset(int newOffset) { return this; }
public IRenderable OffsetBy(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

@@ -34,14 +34,14 @@ namespace OpenRA.Mods.Common.Graphics
readonly Polygon bounds;
readonly Color color;
public IsometricSelectionBoxAnnotationRenderable(Actor actor, Polygon bounds, Color color)
public IsometricSelectionBoxAnnotationRenderable(Actor actor, in Polygon bounds, Color color)
{
pos = actor.CenterPosition;
this.bounds = bounds;
this.color = color;
}
public IsometricSelectionBoxAnnotationRenderable(WPos pos, Polygon bounds, Color color)
public IsometricSelectionBoxAnnotationRenderable(WPos pos, in Polygon bounds, Color color)
{
this.pos = pos;
this.bounds = bounds;
@@ -54,7 +54,7 @@ namespace OpenRA.Mods.Common.Graphics
public bool IsDecoration => true;
public IRenderable WithZOffset(int newOffset) { return this; }
public IRenderable OffsetBy(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

@@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Graphics
public bool IsDecoration => true;
public IRenderable WithZOffset(int newOffset) { return new LineAnnotationRenderable(start, end, width, startColor, endColor); }
public IRenderable OffsetBy(WVec vec) { return new LineAnnotationRenderable(start + vec, end + vec, width, startColor, endColor); }
public IRenderable OffsetBy(in WVec vec) { return new LineAnnotationRenderable(start + vec, end + vec, width, startColor, endColor); }
public IRenderable AsDecoration() { return this; }
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Graphics
readonly WVec offset;
readonly int zOffset;
public ModelPreview(ModelAnimation[] components, WVec offset, int zOffset, float scale, WAngle lightPitch, WAngle lightYaw,
public ModelPreview(ModelAnimation[] components, in WVec offset, int zOffset, float scale, WAngle lightPitch, WAngle lightYaw,
float[] lightAmbientColor, float[] lightDiffuseColor, WAngle cameraPitch,
PaletteReference colorPalette, PaletteReference normalsPalette, PaletteReference shadowPalette)
{

View File

@@ -90,7 +90,7 @@ namespace OpenRA.Mods.Common.Graphics
palette, normalsPalette, shadowPalette, alpha, tint, tintModifiers);
}
public IRenderable OffsetBy(WVec vec)
public IRenderable OffsetBy(in WVec vec)
{
return new ModelRenderable(
models, pos + vec, zOffset, camera, scale,

View File

@@ -35,7 +35,14 @@ namespace OpenRA.Mods.Common.Graphics
public bool IsDecoration => true;
public IRenderable WithZOffset(int newOffset) { return new PolygonAnnotationRenderable(vertices, effectivePos, width, color); }
public IRenderable OffsetBy(WVec vec) { return new PolygonAnnotationRenderable(vertices.Select(v => v + vec).ToArray(), effectivePos + vec, 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);
}
public IRenderable AsDecoration() { return this; }
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }

View File

@@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.Graphics
public bool IsDecoration => true;
public IRenderable WithZOffset(int newOffset) { return new RailgunHelixRenderable(pos, newOffset, railgun, info, ticks); }
public IRenderable OffsetBy(WVec vec) { return new RailgunHelixRenderable(pos + vec, zOffset, 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; }

View File

@@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Graphics
public bool IsDecoration => true;
public IRenderable WithZOffset(int newOffset) { return new RangeCircleAnnotationRenderable(centerPosition, radius, newOffset, color, width, borderColor, borderWidth); }
public IRenderable OffsetBy(WVec vec) { return new RangeCircleAnnotationRenderable(centerPosition + vec, radius, zOffset, color, width, borderColor, borderWidth); }
public IRenderable OffsetBy(in WVec vec) { return new RangeCircleAnnotationRenderable(centerPosition + vec, radius, zOffset, color, width, borderColor, borderWidth); }
public IRenderable AsDecoration() { return this; }
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }

View File

@@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.Graphics
public bool IsDecoration => true;
public IRenderable WithZOffset(int newOffset) { return this; }
public IRenderable OffsetBy(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(WorldRenderer wr, float2 start, float2 end)

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Graphics
public bool IsDecoration => true;
public IRenderable WithZOffset(int newOffset) { return this; }
public IRenderable OffsetBy(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

@@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Graphics
public bool IsDecoration => true;
public IRenderable WithZOffset(int newOffset) { return new TextAnnotationRenderable(font, pos, zOffset, color, text); }
public IRenderable OffsetBy(WVec vec) { return new TextAnnotationRenderable(font, pos + vec, 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; }

View File

@@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Graphics
}
public IRenderable WithZOffset(int newOffset) { return this; }
public IRenderable OffsetBy(WVec vec) { return this; }
public IRenderable OffsetBy(in WVec vec) { return this; }
public IRenderable AsDecoration() { return this; }
static readonly float[] GroundNormal = { 0, 0, 1, 1 };

View File

@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Common.Graphics
public bool IsDecoration => true;
public IRenderable WithZOffset(int newOffset) { return new UITextRenderable(font, effectiveWorldPos, screenPos, zOffset, color, text); }
public IRenderable OffsetBy(WVec vec) { return new UITextRenderable(font, effectiveWorldPos + vec, screenPos, zOffset, color, text); }
public IRenderable OffsetBy(in WVec vec) { return new UITextRenderable(font, effectiveWorldPos + vec, screenPos, zOffset, color, text); }
public IRenderable AsDecoration() { return this; }
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }

View File

@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.HitShapes
OuterRadius = Radius + new WDist(Math.Max(PointA.Length, PointB.Length));
}
public WDist DistanceFromEdge(WVec v)
public WDist DistanceFromEdge(in WVec v)
{
var p = new int2(v.X, v.Y);

View File

@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.HitShapes
throw new YamlException("VerticalTopOffset must be equal to or higher than VerticalBottomOffset.");
}
public WDist DistanceFromEdge(WVec v)
public WDist DistanceFromEdge(in WVec v)
{
return new WDist(Math.Max(0, v.Length - Radius.Length));
}

View File

@@ -18,7 +18,7 @@ namespace OpenRA.Mods.Common.HitShapes
{
WDist OuterRadius { get; }
WDist DistanceFromEdge(WVec v);
WDist DistanceFromEdge(in WVec v);
WDist DistanceFromEdge(WPos pos, WPos origin, WRot orientation);
void Initialize();

View File

@@ -81,7 +81,7 @@ namespace OpenRA.Mods.Common.HitShapes
return (ac - ap).LengthSquared;
}
public WDist DistanceFromEdge(WVec v)
public WDist DistanceFromEdge(in WVec v)
{
var p = new int2(v.X, v.Y);
var z = Math.Abs(v.Z);

View File

@@ -103,7 +103,7 @@ namespace OpenRA.Mods.Common.HitShapes
};
}
public WDist DistanceFromEdge(WVec v)
public WDist DistanceFromEdge(in WVec v)
{
var r = new WVec(
Math.Max(Math.Abs(v.X - center.X) - quadrantSize.X, 0),

View File

@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Pathfinder
/// <summary>
/// Stores information about nodes in the pathfinding graph
/// </summary>
public struct CellInfo
public readonly struct CellInfo
{
/// <summary>
/// The cost to move from the start up to this node

View File

@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Common.Pathfinder
Actor Actor { get; }
}
public struct GraphConnection
public readonly struct GraphConnection
{
public static readonly CostComparer ConnectionCostComparer = CostComparer.Instance;

View File

@@ -739,7 +739,7 @@ namespace OpenRA.Mods.Common.Projectiles
return desiredVFacing;
}
WVec HomingTick(World world, WVec tarDistVec, int relTarHorDist)
WVec HomingTick(World world, in WVec tarDistVec, int relTarHorDist)
{
int predClfHgt = 0;
int predClfDist = 0;

View File

@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Common.Scripting
readonly List<Triggerable>[] triggerables = Exts.MakeArray(Enum.GetValues(typeof(Trigger)).Length, _ => new List<Triggerable>());
struct Triggerable : IDisposable
readonly struct Triggerable : IDisposable
{
public readonly LuaFunction Function;
public readonly ScriptContext Context;

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Fudge the coordinate system angles to simulate non-top-down perspective in mods with square cells.")]
public readonly bool UseClassicPerspectiveFudge = true;
public WVec LocalToWorld(WVec vec)
public WVec LocalToWorld(in WVec vec)
{
// Rotate by 90 degrees
if (!UseClassicPerspectiveFudge)
@@ -96,7 +96,7 @@ namespace OpenRA.Mods.Common.Traits
public WAngle CameraPitch => info.CameraPitch;
public WVec LocalToWorld(WVec vec)
public WVec LocalToWorld(in WVec vec)
{
return info.LocalToWorld(vec);
}

View File

@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Traits
public class ExternalCondition : ITick, INotifyCreated
{
struct TimedToken
readonly struct TimedToken
{
public readonly int Expires;
public readonly int Token;

View File

@@ -108,7 +108,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
WVec CalculateTargetableOffset(Actor self, WVec offset)
WVec CalculateTargetableOffset(Actor self, in WVec offset)
{
var localOffset = offset;
var quantizedBodyOrientation = orientation.QuantizeOrientation(self, self.Orientation);

View File

@@ -246,7 +246,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
struct ActorsAtEnumerable : IEnumerable<Actor>
readonly struct ActorsAtEnumerable : IEnumerable<Actor>
{
readonly InfluenceNode node;
public ActorsAtEnumerable(InfluenceNode node) { this.node = node; }

View File

@@ -126,7 +126,7 @@ namespace OpenRA.Mods.Common.Traits
public class Locomotor : IWorldLoaded
{
struct CellCache
readonly struct CellCache
{
public readonly LongBitSet<PlayerBitMask> Immovable;
public readonly LongBitSet<PlayerBitMask> Crushable;

View File

@@ -200,7 +200,7 @@ namespace OpenRA.Mods.Common.Traits
public ResourceType GetRenderedResourceType(CPos cell) { return RenderContent[cell].Type; }
public struct RendererCellContents
public readonly struct RendererCellContents
{
public readonly string Variant;
public readonly ResourceType Type;

View File

@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Traits
All = Top | Right | Bottom | Left
}
struct TileInfo
readonly struct TileInfo
{
public readonly float3 ScreenPosition;
public readonly byte Variant;

View File

@@ -73,7 +73,7 @@ namespace OpenRA.Mods.Common.Traits
public class WeatherOverlay : ITick, IRenderAboveWorld, INotifyViewportZoomExtentsChanged
{
struct Particle
readonly struct Particle
{
public readonly float2 Pos;
public readonly int Size;
@@ -103,7 +103,7 @@ namespace OpenRA.Mods.Common.Traits
TailColor = Color.FromArgb(info.LineTailAlphaValue, Color.R, Color.G, Color.B);
}
Particle(Particle source)
Particle(in Particle source)
{
Pos = source.Pos;
Size = source.Size;
@@ -117,13 +117,13 @@ namespace OpenRA.Mods.Common.Traits
TailColor = source.TailColor;
}
public Particle(Particle source, float2 pos)
public Particle(in Particle source, float2 pos)
: this(source)
{
Pos = pos;
}
public Particle(Particle source, float2 pos, int swingDirection, float swingOffset)
public Particle(in Particle source, float2 pos, int swingDirection, float swingOffset)
: this(source)
{
Pos = pos;

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Mods.D2k.PackageLoaders
{
sealed class D2kSoundResources : IReadOnlyPackage
{
struct Entry
readonly struct Entry
{
public readonly uint Offset;
public readonly uint Length;