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

@@ -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);