diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index 9f608f8815..f90d0b3465 100644 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -25,7 +25,7 @@ namespace OpenRA { public sealed class Actor : IScriptBindable, IScriptNotifyBind, ILuaTableBinding, ILuaEqualityBinding, ILuaToStringBinding, IEquatable, IDisposable { - internal struct SyncHash + internal readonly struct SyncHash { public readonly ISync Trait; readonly Func hashFunction; diff --git a/OpenRA.Game/CPos.cs b/OpenRA.Game/CPos.cs index 35caf2d52a..9ef4afaa98 100644 --- a/OpenRA.Game/CPos.cs +++ b/OpenRA.Game/CPos.cs @@ -16,7 +16,7 @@ using OpenRA.Scripting; namespace OpenRA { - public struct CPos : IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaEqualityBinding, ILuaTableBinding, IEquatable + public readonly struct CPos : IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaEqualityBinding, ILuaTableBinding, IEquatable { // Coordinates are packed in a 32 bit signed int // X and Y are 12 bits (signed): -2048...2047 diff --git a/OpenRA.Game/CVec.cs b/OpenRA.Game/CVec.cs index 4a7910d976..ee7e721eb8 100644 --- a/OpenRA.Game/CVec.cs +++ b/OpenRA.Game/CVec.cs @@ -17,7 +17,7 @@ using OpenRA.Scripting; namespace OpenRA { - public struct CVec : IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaUnaryMinusBinding, ILuaEqualityBinding, ILuaTableBinding, IEquatable + public readonly struct CVec : IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaUnaryMinusBinding, ILuaEqualityBinding, ILuaTableBinding, IEquatable { public readonly int X, Y; diff --git a/OpenRA.Game/Graphics/Animation.cs b/OpenRA.Game/Graphics/Animation.cs index c7e0bf61ea..63e00520d7 100644 --- a/OpenRA.Game/Graphics/Animation.cs +++ b/OpenRA.Game/Graphics/Animation.cs @@ -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); diff --git a/OpenRA.Game/Graphics/Model.cs b/OpenRA.Game/Graphics/Model.cs index 1eb3526ca7..b724c0428e 100644 --- a/OpenRA.Game/Graphics/Model.cs +++ b/OpenRA.Game/Graphics/Model.cs @@ -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; diff --git a/OpenRA.Game/Graphics/ModelAnimation.cs b/OpenRA.Game/Graphics/ModelAnimation.cs index 6bc96f060b..2485a10a81 100644 --- a/OpenRA.Game/Graphics/ModelAnimation.cs +++ b/OpenRA.Game/Graphics/ModelAnimation.cs @@ -14,7 +14,7 @@ using OpenRA.Primitives; namespace OpenRA.Graphics { - public struct ModelAnimation + public readonly struct ModelAnimation { public readonly IModel Model; public readonly Func OffsetFunc; diff --git a/OpenRA.Game/Graphics/PlatformInterfaces.cs b/OpenRA.Game/Graphics/PlatformInterfaces.cs index f4fc561b4f..0e2fd853b3 100644 --- a/OpenRA.Game/Graphics/PlatformInterfaces.cs +++ b/OpenRA.Game/Graphics/PlatformInterfaces.cs @@ -145,7 +145,7 @@ namespace OpenRA TriangleList, } - public struct Range + public readonly struct Range { public readonly T Start, End; public Range(T start, T end) { Start = start; End = end; } diff --git a/OpenRA.Game/Graphics/Renderable.cs b/OpenRA.Game/Graphics/Renderable.cs index 8935d05a7e..f3970cbf9c 100644 --- a/OpenRA.Game/Graphics/Renderable.cs +++ b/OpenRA.Game/Graphics/Renderable.cs @@ -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); diff --git a/OpenRA.Game/Graphics/SpriteRenderable.cs b/OpenRA.Game/Graphics/SpriteRenderable.cs index e478e17d44..2953a9518a 100644 --- a/OpenRA.Game/Graphics/SpriteRenderable.cs +++ b/OpenRA.Game/Graphics/SpriteRenderable.cs @@ -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) diff --git a/OpenRA.Game/Graphics/TargetLineRenderable.cs b/OpenRA.Game/Graphics/TargetLineRenderable.cs index ecc542abcd..fada77017d 100644 --- a/OpenRA.Game/Graphics/TargetLineRenderable.cs +++ b/OpenRA.Game/Graphics/TargetLineRenderable.cs @@ -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; } diff --git a/OpenRA.Game/Graphics/UISpriteRenderable.cs b/OpenRA.Game/Graphics/UISpriteRenderable.cs index 0930881138..23e57cce7b 100644 --- a/OpenRA.Game/Graphics/UISpriteRenderable.cs +++ b/OpenRA.Game/Graphics/UISpriteRenderable.cs @@ -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; } diff --git a/OpenRA.Game/Graphics/Vertex.cs b/OpenRA.Game/Graphics/Vertex.cs index 6893a3bee4..87b1a3f194 100644 --- a/OpenRA.Game/Graphics/Vertex.cs +++ b/OpenRA.Game/Graphics/Vertex.cs @@ -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; diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index 97b87baa3b..b793241ded 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -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); diff --git a/OpenRA.Game/Input/Hotkey.cs b/OpenRA.Game/Input/Hotkey.cs index 4264ae86be..b510cebaca 100644 --- a/OpenRA.Game/Input/Hotkey.cs +++ b/OpenRA.Game/Input/Hotkey.cs @@ -13,7 +13,7 @@ using System; namespace OpenRA { - public struct Hotkey : IEquatable + public readonly struct Hotkey : IEquatable { public static Hotkey Invalid = new Hotkey(Keycode.UNKNOWN, Modifiers.None); public bool IsValid() diff --git a/OpenRA.Game/MPos.cs b/OpenRA.Game/MPos.cs index 8892713223..b376311318 100644 --- a/OpenRA.Game/MPos.cs +++ b/OpenRA.Game/MPos.cs @@ -14,7 +14,7 @@ using OpenRA.Primitives; namespace OpenRA { - public struct MPos : IEquatable + public readonly struct MPos : IEquatable { public readonly int U, V; @@ -66,7 +66,7 @@ namespace OpenRA /// /// Projected map position /// - public struct PPos : IEquatable + public readonly struct PPos : IEquatable { public readonly int U, V; diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index c122c6cfa9..6bd505a182 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -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; diff --git a/OpenRA.Game/Map/MapCoordsRegion.cs b/OpenRA.Game/Map/MapCoordsRegion.cs index d4d813330e..156643faea 100644 --- a/OpenRA.Game/Map/MapCoordsRegion.cs +++ b/OpenRA.Game/Map/MapCoordsRegion.cs @@ -14,7 +14,7 @@ using System.Collections.Generic; namespace OpenRA { - public struct MapCoordsRegion : IEnumerable + public readonly struct MapCoordsRegion : IEnumerable { public struct MapCoordsEnumerator : IEnumerator { diff --git a/OpenRA.Game/Map/MapGrid.cs b/OpenRA.Game/Map/MapGrid.cs index 2e8483f153..3abab39569 100644 --- a/OpenRA.Game/Map/MapGrid.cs +++ b/OpenRA.Game/Map/MapGrid.cs @@ -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; diff --git a/OpenRA.Game/Map/TileReference.cs b/OpenRA.Game/Map/TileReference.cs index 0adfe7a047..693218f893 100644 --- a/OpenRA.Game/Map/TileReference.cs +++ b/OpenRA.Game/Map/TileReference.cs @@ -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; diff --git a/OpenRA.Game/Primitives/ActionQueue.cs b/OpenRA.Game/Primitives/ActionQueue.cs index 09bdcff491..f0489d2cf8 100644 --- a/OpenRA.Game/Primitives/ActionQueue.cs +++ b/OpenRA.Game/Primitives/ActionQueue.cs @@ -65,7 +65,7 @@ namespace OpenRA.Primitives } } - struct DelayedAction : IComparable + readonly struct DelayedAction : IComparable { public readonly long Time; public readonly Action Action; diff --git a/OpenRA.Game/Primitives/BitSet.cs b/OpenRA.Game/Primitives/BitSet.cs index 9881325441..0aa85de83a 100644 --- a/OpenRA.Game/Primitives/BitSet.cs +++ b/OpenRA.Game/Primitives/BitSet.cs @@ -75,7 +75,7 @@ namespace OpenRA.Primitives } } - public struct BitSet : IEnumerable, IEquatable> where T : class + public readonly struct BitSet : IEnumerable, IEquatable> where T : class { readonly BitSetIndex bits; diff --git a/OpenRA.Game/Primitives/Color.cs b/OpenRA.Game/Primitives/Color.cs index 13819d6b7e..72ba06d12e 100644 --- a/OpenRA.Game/Primitives/Color.cs +++ b/OpenRA.Game/Primitives/Color.cs @@ -15,7 +15,7 @@ using OpenRA.Scripting; namespace OpenRA.Primitives { - public struct Color : IEquatable, IScriptBindable + public readonly struct Color : IEquatable, IScriptBindable { readonly long argb; diff --git a/OpenRA.Game/Primitives/Int32Matrix4x4.cs b/OpenRA.Game/Primitives/Int32Matrix4x4.cs index a4117b5ed9..b6eef02a4f 100644 --- a/OpenRA.Game/Primitives/Int32Matrix4x4.cs +++ b/OpenRA.Game/Primitives/Int32Matrix4x4.cs @@ -13,7 +13,7 @@ using System; namespace OpenRA { - public struct Int32Matrix4x4 : IEquatable + public readonly struct Int32Matrix4x4 : IEquatable { public readonly int M11, M12, M13, M14, M21, M22, M23, M24, M31, M32, M33, M34, M41, M42, M43, M44; diff --git a/OpenRA.Game/Primitives/LongBitSet.cs b/OpenRA.Game/Primitives/LongBitSet.cs index ba0e958572..6e78e2bb84 100644 --- a/OpenRA.Game/Primitives/LongBitSet.cs +++ b/OpenRA.Game/Primitives/LongBitSet.cs @@ -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 : IEnumerable, IEquatable> where T : class + public readonly struct LongBitSet : IEnumerable, IEquatable> where T : class { readonly long bits; diff --git a/OpenRA.Game/Primitives/PlayerDictionary.cs b/OpenRA.Game/Primitives/PlayerDictionary.cs index 74d1cde195..d032ead5f0 100644 --- a/OpenRA.Game/Primitives/PlayerDictionary.cs +++ b/OpenRA.Game/Primitives/PlayerDictionary.cs @@ -17,7 +17,7 @@ namespace OpenRA.Primitives /// /// Provides a mapping of players to values, as well as fast lookup by player index. /// - public struct PlayerDictionary : IReadOnlyList, IReadOnlyDictionary where T : class + public readonly struct PlayerDictionary : IReadOnlyList, IReadOnlyDictionary where T : class { readonly T[] valueByPlayerIndex; readonly Dictionary valueByPlayer; diff --git a/OpenRA.Game/Primitives/Polygon.cs b/OpenRA.Game/Primitives/Polygon.cs index cf9b51b364..a4fee9b440 100644 --- a/OpenRA.Game/Primitives/Polygon.cs +++ b/OpenRA.Game/Primitives/Polygon.cs @@ -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) { diff --git a/OpenRA.Game/Primitives/Size.cs b/OpenRA.Game/Primitives/Size.cs index 06f05b2b33..36f1e3a7d4 100644 --- a/OpenRA.Game/Primitives/Size.cs +++ b/OpenRA.Game/Primitives/Size.cs @@ -13,7 +13,7 @@ using System; namespace OpenRA.Primitives { - public struct Size : IEquatable + public readonly struct Size : IEquatable { public readonly int Width; public readonly int Height; diff --git a/OpenRA.Game/Primitives/float2.cs b/OpenRA.Game/Primitives/float2.cs index bffb3d6c10..ed62e4fe46 100644 --- a/OpenRA.Game/Primitives/float2.cs +++ b/OpenRA.Game/Primitives/float2.cs @@ -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 + public readonly struct float2 : IEquatable { public readonly float X, Y; diff --git a/OpenRA.Game/Primitives/int2.cs b/OpenRA.Game/Primitives/int2.cs index 8543ca412f..b4e50105fe 100644 --- a/OpenRA.Game/Primitives/int2.cs +++ b/OpenRA.Game/Primitives/int2.cs @@ -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 + public readonly struct int2 : IEquatable { public readonly int X, Y; public int2(int x, int y) { X = x; Y = y; } diff --git a/OpenRA.Game/SelectableExts.cs b/OpenRA.Game/SelectableExts.cs index 09d509665b..ee38c4a089 100644 --- a/OpenRA.Game/SelectableExts.cs +++ b/OpenRA.Game/SelectableExts.cs @@ -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); diff --git a/OpenRA.Game/Support/PerfSample.cs b/OpenRA.Game/Support/PerfSample.cs index f7348be8ce..0137cdabd0 100644 --- a/OpenRA.Game/Support/PerfSample.cs +++ b/OpenRA.Game/Support/PerfSample.cs @@ -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; diff --git a/OpenRA.Game/Support/VariableExpression.cs b/OpenRA.Game/Support/VariableExpression.cs index df7a6584b3..09a745dc09 100644 --- a/OpenRA.Game/Support/VariableExpression.cs +++ b/OpenRA.Game/Support/VariableExpression.cs @@ -157,7 +157,7 @@ namespace OpenRA.Support Invalid = ~0 } - struct TokenTypeInfo + readonly struct TokenTypeInfo { public readonly string Symbol; public readonly Precedence Precedence; diff --git a/OpenRA.Game/TraitDictionary.cs b/OpenRA.Game/TraitDictionary.cs index 5df5bb91cf..881510dfca 100644 --- a/OpenRA.Game/TraitDictionary.cs +++ b/OpenRA.Game/TraitDictionary.cs @@ -249,7 +249,7 @@ namespace OpenRA } } - struct AllEnumerable : IEnumerable> + readonly struct AllEnumerable : IEnumerable> { readonly TraitContainer container; public AllEnumerable(TraitContainer container) { this.container = container; } diff --git a/OpenRA.Game/Traits/World/ScreenMap.cs b/OpenRA.Game/Traits/World/ScreenMap.cs index 2e4144d197..87157533ba 100644 --- a/OpenRA.Game/Traits/World/ScreenMap.cs +++ b/OpenRA.Game/Traits/World/ScreenMap.cs @@ -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; diff --git a/OpenRA.Game/WAngle.cs b/OpenRA.Game/WAngle.cs index 1ba06268b9..8f4c6e88a9 100644 --- a/OpenRA.Game/WAngle.cs +++ b/OpenRA.Game/WAngle.cs @@ -19,7 +19,7 @@ namespace OpenRA /// /// 1D angle - 1024 units = 360 degrees. /// - public struct WAngle : IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaEqualityBinding, IEquatable + public readonly struct WAngle : IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaEqualityBinding, IEquatable { public readonly int Angle; public int AngleSquared => (int)Angle * Angle; diff --git a/OpenRA.Game/WDist.cs b/OpenRA.Game/WDist.cs index b14c01cac6..1d494afdba 100644 --- a/OpenRA.Game/WDist.cs +++ b/OpenRA.Game/WDist.cs @@ -21,7 +21,7 @@ namespace OpenRA /// /// 1d world distance - 1024 units = 1 cell. /// - public struct WDist : IComparable, IComparable, IEquatable, IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaEqualityBinding, ILuaTableBinding + public readonly struct WDist : IComparable, IComparable, IEquatable, IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaEqualityBinding, ILuaTableBinding { public readonly int Length; public long LengthSquared => (long)Length * Length; diff --git a/OpenRA.Game/WPos.cs b/OpenRA.Game/WPos.cs index 3beb20ef41..0ae9c2de59 100644 --- a/OpenRA.Game/WPos.cs +++ b/OpenRA.Game/WPos.cs @@ -18,7 +18,7 @@ using OpenRA.Scripting; namespace OpenRA { - public struct WPos : IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaEqualityBinding, ILuaTableBinding, IEquatable + public readonly struct WPos : IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaEqualityBinding, ILuaTableBinding, IEquatable { 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); } /// /// Returns the linear interpolation between points 'a' and 'b' /// - 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; } /// /// Returns the linear interpolation between points 'a' and 'b' /// - 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); diff --git a/OpenRA.Game/WVec.cs b/OpenRA.Game/WVec.cs index cee6271692..f398e24fe6 100644 --- a/OpenRA.Game/WVec.cs +++ b/OpenRA.Game/WVec.cs @@ -17,7 +17,7 @@ using OpenRA.Support; namespace OpenRA { - public struct WVec : IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaUnaryMinusBinding, ILuaEqualityBinding, ILuaTableBinding, IEquatable + public readonly struct WVec : IScriptBindable, ILuaAdditionBinding, ILuaSubtractionBinding, ILuaUnaryMinusBinding, ILuaEqualityBinding, ILuaTableBinding, IEquatable { 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); diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs index e0bae82628..718ba0c274 100644 --- a/OpenRA.Game/World.cs +++ b/OpenRA.Game/World.cs @@ -576,7 +576,7 @@ namespace OpenRA } } - public struct TraitPair : IEquatable> + public readonly struct TraitPair : IEquatable> { public readonly Actor Actor; public readonly T Trait; diff --git a/OpenRA.Mods.Cnc/Activities/VoxelHarvesterDockSequence.cs b/OpenRA.Mods.Cnc/Activities/VoxelHarvesterDockSequence.cs index 072646da4f..e83d595fd9 100644 --- a/OpenRA.Mods.Cnc/Activities/VoxelHarvesterDockSequence.cs +++ b/OpenRA.Mods.Cnc/Activities/VoxelHarvesterDockSequence.cs @@ -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(); diff --git a/OpenRA.Mods.Cnc/Graphics/TeslaZapRenderable.cs b/OpenRA.Mods.Cnc/Graphics/TeslaZapRenderable.cs index 498ab09170..2a170b4f6c 100644 --- a/OpenRA.Mods.Cnc/Graphics/TeslaZapRenderable.cs +++ b/OpenRA.Mods.Cnc/Graphics/TeslaZapRenderable.cs @@ -44,7 +44,7 @@ namespace OpenRA.Mods.Cnc.Graphics WVec cachedLength; IEnumerable 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; } diff --git a/OpenRA.Mods.Common/Activities/Air/Fly.cs b/OpenRA.Mods.Common/Activities/Air/Fly.cs index c4e8239698..480bd54ada 100644 --- a/OpenRA.Mods.Common/Activities/Air/Fly.cs +++ b/OpenRA.Mods.Common/Activities/Air/Fly.cs @@ -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); diff --git a/OpenRA.Mods.Common/Activities/Air/Land.cs b/OpenRA.Mods.Common/Activities/Air/Land.cs index 4532af072d..5bfd64dc8c 100644 --- a/OpenRA.Mods.Common/Activities/Air/Land.cs +++ b/OpenRA.Mods.Common/Activities/Air/Land.cs @@ -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(); this.target = target; diff --git a/OpenRA.Mods.Common/Activities/HarvesterDockSequence.cs b/OpenRA.Mods.Common/Activities/HarvesterDockSequence.cs index bbda40ac8d..27eef65fc9 100644 --- a/OpenRA.Mods.Common/Activities/HarvesterDockSequence.cs +++ b/OpenRA.Mods.Common/Activities/HarvesterDockSequence.cs @@ -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; diff --git a/OpenRA.Mods.Common/Activities/SpriteHarvesterDockSequence.cs b/OpenRA.Mods.Common/Activities/SpriteHarvesterDockSequence.cs index afc5bc89ce..7a616a08dc 100644 --- a/OpenRA.Mods.Common/Activities/SpriteHarvesterDockSequence.cs +++ b/OpenRA.Mods.Common/Activities/SpriteHarvesterDockSequence.cs @@ -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(); diff --git a/OpenRA.Mods.Common/EditorBrushes/EditorResourceBrush.cs b/OpenRA.Mods.Common/EditorBrushes/EditorResourceBrush.cs index 9449410e71..2a04c3da0e 100644 --- a/OpenRA.Mods.Common/EditorBrushes/EditorResourceBrush.cs +++ b/OpenRA.Mods.Common/EditorBrushes/EditorResourceBrush.cs @@ -108,7 +108,7 @@ namespace OpenRA.Mods.Common.Widgets } } - struct CellResource + readonly struct CellResource { public readonly CPos Cell; public readonly ResourceTile ResourceTile; diff --git a/OpenRA.Mods.Common/FileFormats/InstallShieldCABCompression.cs b/OpenRA.Mods.Common/FileFormats/InstallShieldCABCompression.cs index ff326cf82e..6a447e75d9 100644 --- a/OpenRA.Mods.Common/FileFormats/InstallShieldCABCompression.cs +++ b/OpenRA.Mods.Common/FileFormats/InstallShieldCABCompression.cs @@ -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; diff --git a/OpenRA.Mods.Common/FileSystem/InstallShieldPackage.cs b/OpenRA.Mods.Common/FileSystem/InstallShieldPackage.cs index a9576fabf8..cb75e20e84 100644 --- a/OpenRA.Mods.Common/FileSystem/InstallShieldPackage.cs +++ b/OpenRA.Mods.Common/FileSystem/InstallShieldPackage.cs @@ -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; diff --git a/OpenRA.Mods.Common/Graphics/BeamRenderable.cs b/OpenRA.Mods.Common/Graphics/BeamRenderable.cs index 96e5a02a97..8e2bffee6d 100644 --- a/OpenRA.Mods.Common/Graphics/BeamRenderable.cs +++ b/OpenRA.Mods.Common/Graphics/BeamRenderable.cs @@ -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; } diff --git a/OpenRA.Mods.Common/Graphics/CircleAnnotationRenderable.cs b/OpenRA.Mods.Common/Graphics/CircleAnnotationRenderable.cs index c32c638d62..f2989cf6cb 100644 --- a/OpenRA.Mods.Common/Graphics/CircleAnnotationRenderable.cs +++ b/OpenRA.Mods.Common/Graphics/CircleAnnotationRenderable.cs @@ -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; } diff --git a/OpenRA.Mods.Common/Graphics/ContrailRenderable.cs b/OpenRA.Mods.Common/Graphics/ContrailRenderable.cs index c4b2e2ba8c..59dc897efb 100644 --- a/OpenRA.Mods.Common/Graphics/ContrailRenderable.cs +++ b/OpenRA.Mods.Common/Graphics/ContrailRenderable.cs @@ -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; } diff --git a/OpenRA.Mods.Common/Graphics/DetectionCircleAnnotationRenderable.cs b/OpenRA.Mods.Common/Graphics/DetectionCircleAnnotationRenderable.cs index b871192330..fa1c479f22 100644 --- a/OpenRA.Mods.Common/Graphics/DetectionCircleAnnotationRenderable.cs +++ b/OpenRA.Mods.Common/Graphics/DetectionCircleAnnotationRenderable.cs @@ -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); diff --git a/OpenRA.Mods.Common/Graphics/IsometricSelectionBarsAnnotationRenderable.cs b/OpenRA.Mods.Common/Graphics/IsometricSelectionBarsAnnotationRenderable.cs index 718f0405ac..3a36aa5203 100644 --- a/OpenRA.Mods.Common/Graphics/IsometricSelectionBarsAnnotationRenderable.cs +++ b/OpenRA.Mods.Common/Graphics/IsometricSelectionBarsAnnotationRenderable.cs @@ -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) diff --git a/OpenRA.Mods.Common/Graphics/IsometricSelectionBoxAnnotationRenderable.cs b/OpenRA.Mods.Common/Graphics/IsometricSelectionBoxAnnotationRenderable.cs index 520d7bead3..7d827e8d05 100644 --- a/OpenRA.Mods.Common/Graphics/IsometricSelectionBoxAnnotationRenderable.cs +++ b/OpenRA.Mods.Common/Graphics/IsometricSelectionBoxAnnotationRenderable.cs @@ -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; } diff --git a/OpenRA.Mods.Common/Graphics/LineAnnotationRenderable.cs b/OpenRA.Mods.Common/Graphics/LineAnnotationRenderable.cs index ffaa20b0a1..48f6827514 100644 --- a/OpenRA.Mods.Common/Graphics/LineAnnotationRenderable.cs +++ b/OpenRA.Mods.Common/Graphics/LineAnnotationRenderable.cs @@ -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; } diff --git a/OpenRA.Mods.Common/Graphics/ModelActorPreview.cs b/OpenRA.Mods.Common/Graphics/ModelActorPreview.cs index 2e2adcbbc0..fcbcfea85d 100644 --- a/OpenRA.Mods.Common/Graphics/ModelActorPreview.cs +++ b/OpenRA.Mods.Common/Graphics/ModelActorPreview.cs @@ -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) { diff --git a/OpenRA.Mods.Common/Graphics/ModelRenderable.cs b/OpenRA.Mods.Common/Graphics/ModelRenderable.cs index 7f5e3a57ef..7748f9f99f 100644 --- a/OpenRA.Mods.Common/Graphics/ModelRenderable.cs +++ b/OpenRA.Mods.Common/Graphics/ModelRenderable.cs @@ -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, diff --git a/OpenRA.Mods.Common/Graphics/PolygonAnnotationRenderable.cs b/OpenRA.Mods.Common/Graphics/PolygonAnnotationRenderable.cs index d70600596f..64ee6656f5 100644 --- a/OpenRA.Mods.Common/Graphics/PolygonAnnotationRenderable.cs +++ b/OpenRA.Mods.Common/Graphics/PolygonAnnotationRenderable.cs @@ -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; } diff --git a/OpenRA.Mods.Common/Graphics/RailgunRenderable.cs b/OpenRA.Mods.Common/Graphics/RailgunRenderable.cs index 5d6bbda416..22eebc0c8b 100644 --- a/OpenRA.Mods.Common/Graphics/RailgunRenderable.cs +++ b/OpenRA.Mods.Common/Graphics/RailgunRenderable.cs @@ -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; } diff --git a/OpenRA.Mods.Common/Graphics/RangeCircleAnnotationRenderable.cs b/OpenRA.Mods.Common/Graphics/RangeCircleAnnotationRenderable.cs index 4939e7b60e..421e05ddf6 100644 --- a/OpenRA.Mods.Common/Graphics/RangeCircleAnnotationRenderable.cs +++ b/OpenRA.Mods.Common/Graphics/RangeCircleAnnotationRenderable.cs @@ -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; } diff --git a/OpenRA.Mods.Common/Graphics/SelectionBarsAnnotationRenderable.cs b/OpenRA.Mods.Common/Graphics/SelectionBarsAnnotationRenderable.cs index 626073c0ac..4da12b435c 100644 --- a/OpenRA.Mods.Common/Graphics/SelectionBarsAnnotationRenderable.cs +++ b/OpenRA.Mods.Common/Graphics/SelectionBarsAnnotationRenderable.cs @@ -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) diff --git a/OpenRA.Mods.Common/Graphics/SelectionBoxAnnotationRenderable.cs b/OpenRA.Mods.Common/Graphics/SelectionBoxAnnotationRenderable.cs index 9ae16c64e3..d5551ca384 100644 --- a/OpenRA.Mods.Common/Graphics/SelectionBoxAnnotationRenderable.cs +++ b/OpenRA.Mods.Common/Graphics/SelectionBoxAnnotationRenderable.cs @@ -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; } diff --git a/OpenRA.Mods.Common/Graphics/TextAnnotationRenderable.cs b/OpenRA.Mods.Common/Graphics/TextAnnotationRenderable.cs index 83cb6a405e..be91b6933a 100644 --- a/OpenRA.Mods.Common/Graphics/TextAnnotationRenderable.cs +++ b/OpenRA.Mods.Common/Graphics/TextAnnotationRenderable.cs @@ -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; } diff --git a/OpenRA.Mods.Common/Graphics/UIModelRenderable.cs b/OpenRA.Mods.Common/Graphics/UIModelRenderable.cs index 8a549bb9b5..86caa3ded8 100644 --- a/OpenRA.Mods.Common/Graphics/UIModelRenderable.cs +++ b/OpenRA.Mods.Common/Graphics/UIModelRenderable.cs @@ -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 }; diff --git a/OpenRA.Mods.Common/Graphics/UITextRenderable.cs b/OpenRA.Mods.Common/Graphics/UITextRenderable.cs index 5bc02e494a..5e8486ae2a 100644 --- a/OpenRA.Mods.Common/Graphics/UITextRenderable.cs +++ b/OpenRA.Mods.Common/Graphics/UITextRenderable.cs @@ -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; } diff --git a/OpenRA.Mods.Common/HitShapes/Capsule.cs b/OpenRA.Mods.Common/HitShapes/Capsule.cs index 640a715c79..22a87038d8 100644 --- a/OpenRA.Mods.Common/HitShapes/Capsule.cs +++ b/OpenRA.Mods.Common/HitShapes/Capsule.cs @@ -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); diff --git a/OpenRA.Mods.Common/HitShapes/Circle.cs b/OpenRA.Mods.Common/HitShapes/Circle.cs index 03abb8c1c8..50f2cac8f6 100644 --- a/OpenRA.Mods.Common/HitShapes/Circle.cs +++ b/OpenRA.Mods.Common/HitShapes/Circle.cs @@ -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)); } diff --git a/OpenRA.Mods.Common/HitShapes/IHitShape.cs b/OpenRA.Mods.Common/HitShapes/IHitShape.cs index 34ee80ecde..8b02adbc4d 100644 --- a/OpenRA.Mods.Common/HitShapes/IHitShape.cs +++ b/OpenRA.Mods.Common/HitShapes/IHitShape.cs @@ -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(); diff --git a/OpenRA.Mods.Common/HitShapes/Polygon.cs b/OpenRA.Mods.Common/HitShapes/Polygon.cs index edbef8d67f..7c0d2438cc 100644 --- a/OpenRA.Mods.Common/HitShapes/Polygon.cs +++ b/OpenRA.Mods.Common/HitShapes/Polygon.cs @@ -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); diff --git a/OpenRA.Mods.Common/HitShapes/Rectangle.cs b/OpenRA.Mods.Common/HitShapes/Rectangle.cs index 6bd2da2a48..c5b4824f32 100644 --- a/OpenRA.Mods.Common/HitShapes/Rectangle.cs +++ b/OpenRA.Mods.Common/HitShapes/Rectangle.cs @@ -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), diff --git a/OpenRA.Mods.Common/Pathfinder/CellInfo.cs b/OpenRA.Mods.Common/Pathfinder/CellInfo.cs index 184c22d7bd..1200644310 100644 --- a/OpenRA.Mods.Common/Pathfinder/CellInfo.cs +++ b/OpenRA.Mods.Common/Pathfinder/CellInfo.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Pathfinder /// /// Stores information about nodes in the pathfinding graph /// - public struct CellInfo + public readonly struct CellInfo { /// /// The cost to move from the start up to this node diff --git a/OpenRA.Mods.Common/Pathfinder/PathGraph.cs b/OpenRA.Mods.Common/Pathfinder/PathGraph.cs index 4edb22fd52..54f20b72cf 100644 --- a/OpenRA.Mods.Common/Pathfinder/PathGraph.cs +++ b/OpenRA.Mods.Common/Pathfinder/PathGraph.cs @@ -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; diff --git a/OpenRA.Mods.Common/Projectiles/Missile.cs b/OpenRA.Mods.Common/Projectiles/Missile.cs index 0d9db120ee..080376a31a 100644 --- a/OpenRA.Mods.Common/Projectiles/Missile.cs +++ b/OpenRA.Mods.Common/Projectiles/Missile.cs @@ -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; diff --git a/OpenRA.Mods.Common/Scripting/ScriptTriggers.cs b/OpenRA.Mods.Common/Scripting/ScriptTriggers.cs index c670e62d79..38d2c5fe79 100644 --- a/OpenRA.Mods.Common/Scripting/ScriptTriggers.cs +++ b/OpenRA.Mods.Common/Scripting/ScriptTriggers.cs @@ -49,7 +49,7 @@ namespace OpenRA.Mods.Common.Scripting readonly List[] triggerables = Exts.MakeArray(Enum.GetValues(typeof(Trigger)).Length, _ => new List()); - struct Triggerable : IDisposable + readonly struct Triggerable : IDisposable { public readonly LuaFunction Function; public readonly ScriptContext Context; diff --git a/OpenRA.Mods.Common/Traits/BodyOrientation.cs b/OpenRA.Mods.Common/Traits/BodyOrientation.cs index edf74258cf..dfda816ec0 100644 --- a/OpenRA.Mods.Common/Traits/BodyOrientation.cs +++ b/OpenRA.Mods.Common/Traits/BodyOrientation.cs @@ -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); } diff --git a/OpenRA.Mods.Common/Traits/Conditions/ExternalCondition.cs b/OpenRA.Mods.Common/Traits/Conditions/ExternalCondition.cs index 10065dc376..807188294c 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/ExternalCondition.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/ExternalCondition.cs @@ -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; diff --git a/OpenRA.Mods.Common/Traits/HitShape.cs b/OpenRA.Mods.Common/Traits/HitShape.cs index b756bacc2d..ca7df6b2a9 100644 --- a/OpenRA.Mods.Common/Traits/HitShape.cs +++ b/OpenRA.Mods.Common/Traits/HitShape.cs @@ -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); diff --git a/OpenRA.Mods.Common/Traits/World/ActorMap.cs b/OpenRA.Mods.Common/Traits/World/ActorMap.cs index 4df65205f1..11b61b0863 100644 --- a/OpenRA.Mods.Common/Traits/World/ActorMap.cs +++ b/OpenRA.Mods.Common/Traits/World/ActorMap.cs @@ -246,7 +246,7 @@ namespace OpenRA.Mods.Common.Traits } } - struct ActorsAtEnumerable : IEnumerable + readonly struct ActorsAtEnumerable : IEnumerable { readonly InfluenceNode node; public ActorsAtEnumerable(InfluenceNode node) { this.node = node; } diff --git a/OpenRA.Mods.Common/Traits/World/Locomotor.cs b/OpenRA.Mods.Common/Traits/World/Locomotor.cs index 8fa69fb0b9..1a6bfd8264 100644 --- a/OpenRA.Mods.Common/Traits/World/Locomotor.cs +++ b/OpenRA.Mods.Common/Traits/World/Locomotor.cs @@ -126,7 +126,7 @@ namespace OpenRA.Mods.Common.Traits public class Locomotor : IWorldLoaded { - struct CellCache + readonly struct CellCache { public readonly LongBitSet Immovable; public readonly LongBitSet Crushable; diff --git a/OpenRA.Mods.Common/Traits/World/ResourceRenderer.cs b/OpenRA.Mods.Common/Traits/World/ResourceRenderer.cs index e396bbabf2..edb2e16fd7 100644 --- a/OpenRA.Mods.Common/Traits/World/ResourceRenderer.cs +++ b/OpenRA.Mods.Common/Traits/World/ResourceRenderer.cs @@ -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; diff --git a/OpenRA.Mods.Common/Traits/World/ShroudRenderer.cs b/OpenRA.Mods.Common/Traits/World/ShroudRenderer.cs index 92188bac97..e39a6d4777 100644 --- a/OpenRA.Mods.Common/Traits/World/ShroudRenderer.cs +++ b/OpenRA.Mods.Common/Traits/World/ShroudRenderer.cs @@ -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; diff --git a/OpenRA.Mods.Common/Traits/World/WeatherOverlay.cs b/OpenRA.Mods.Common/Traits/World/WeatherOverlay.cs index 0cab64f7e1..b112f0ee1c 100644 --- a/OpenRA.Mods.Common/Traits/World/WeatherOverlay.cs +++ b/OpenRA.Mods.Common/Traits/World/WeatherOverlay.cs @@ -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; diff --git a/OpenRA.Mods.D2k/PackageLoaders/D2kSoundResources.cs b/OpenRA.Mods.D2k/PackageLoaders/D2kSoundResources.cs index 0f0fe5060c..ac6c6e724b 100644 --- a/OpenRA.Mods.D2k/PackageLoaders/D2kSoundResources.cs +++ b/OpenRA.Mods.D2k/PackageLoaders/D2kSoundResources.cs @@ -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;