Merge branch 'csharp_warning_fix' of https://github.com/GoaLitiuM/FlaxEngine into GoaLitiuM-csharp_warning_fix

This commit is contained in:
Wojtek Figat
2024-07-25 08:40:22 +02:00
5 changed files with 49 additions and 61 deletions

View File

@@ -58,10 +58,10 @@ namespace FlaxEngine.Tools
FieldInfo[] fields = typeof(CustomMaxSizes).GetFields(); FieldInfo[] fields = typeof(CustomMaxSizes).GetFields();
for (int i = 0; i < fields.Length; i++) for (int i = 0; i < fields.Length; i++)
{ {
var field = fields[i]; var @field = fields[i];
if (field.Name.Equals("value__")) if (@field.Name.Equals("value__"))
continue; continue;
if (value == (int)field.GetRawConstantValue()) if (value == (int)@field.GetRawConstantValue())
return (CustomMaxSizes)value; return (CustomMaxSizes)value;
} }
return CustomMaxSizes._8192; return CustomMaxSizes._8192;

View File

@@ -51,12 +51,12 @@ namespace FlaxEditor.Scripting
int standardToken = _managed?.MetadataToken ?? _custom?.MetadataToken ?? 0; int standardToken = _managed?.MetadataToken ?? _custom?.MetadataToken ?? 0;
if (_managed is PropertyInfo && _managed.DeclaringType != null) if (_managed is PropertyInfo && _managed.DeclaringType != null)
{ {
var field = _managed.DeclaringType.GetField(string.Format("<{0}>k__BackingField", Name), BindingFlags.Instance | BindingFlags.NonPublic); var backingField = _managed.DeclaringType.GetField(string.Format("<{0}>k__BackingField", Name), BindingFlags.Instance | BindingFlags.NonPublic);
if (field == null || field.MetadataToken == 0) if (backingField == null || backingField.MetadataToken == 0)
{ {
return standardToken; return standardToken;
} }
return field.MetadataToken; return backingField.MetadataToken;
} }
return standardToken; return standardToken;
} }

View File

@@ -12,7 +12,7 @@ namespace FlaxEngine
[StructLayout(LayoutKind.Sequential, Pack = 4)] [StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct FloatR10G10B10A2 public struct FloatR10G10B10A2
{ {
private uint value; private uint rawValue;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref = "T:FlaxEngine.FloatR10G10B10A2" /> structure. /// Initializes a new instance of the <see cref = "T:FlaxEngine.FloatR10G10B10A2" /> structure.
@@ -23,7 +23,7 @@ namespace FlaxEngine
/// <param name="w">The floating point value that should be stored in A component (2 bit format).</param> /// <param name="w">The floating point value that should be stored in A component (2 bit format).</param>
public FloatR10G10B10A2(float x, float y, float z, float w) public FloatR10G10B10A2(float x, float y, float z, float w)
{ {
value = Pack(x, y, z, w); rawValue = Pack(x, y, z, w);
} }
/// <summary> /// <summary>
@@ -33,7 +33,7 @@ namespace FlaxEngine
/// <param name="w">The floating point value that should be stored in alpha component (2 bit format).</param> /// <param name="w">The floating point value that should be stored in alpha component (2 bit format).</param>
public FloatR10G10B10A2(Float3 value, float w = 0) public FloatR10G10B10A2(Float3 value, float w = 0)
{ {
this.value = Pack(value.X, value.Y, value.Z, w); rawValue = Pack(value.X, value.Y, value.Z, w);
} }
/// <summary> /// <summary>
@@ -42,37 +42,33 @@ namespace FlaxEngine
/// <param name = "value">The floating point value that should be stored in 10 bit format.</param> /// <param name = "value">The floating point value that should be stored in 10 bit format.</param>
public FloatR10G10B10A2(Float4 value) public FloatR10G10B10A2(Float4 value)
{ {
this.value = Pack(value.X, value.Y, value.Z, value.W); rawValue = Pack(value.X, value.Y, value.Z, value.W);
} }
/// <summary> /// <summary>
/// Gets or sets the raw 32 bit value used to back this vector. /// Gets or sets the raw 32 bit value used to back this vector.
/// </summary> /// </summary>
public uint RawValue public uint RawValue => rawValue;
{
get => value;
set => this.value = value;
}
/// <summary> /// <summary>
/// Gets the R component. /// Gets the R component.
/// </summary> /// </summary>
public float R => (value & 0x3FF) / 1023.0f; public float R => (rawValue & 0x3FF) / 1023.0f;
/// <summary> /// <summary>
/// Gets the G component. /// Gets the G component.
/// </summary> /// </summary>
public float G => ((value >> 10) & 0x3FF) / 1023.0f; public float G => ((rawValue >> 10) & 0x3FF) / 1023.0f;
/// <summary> /// <summary>
/// Gets the B component. /// Gets the B component.
/// </summary> /// </summary>
public float B => ((value >> 20) & 0x3FF) / 1023.0f; public float B => ((rawValue >> 20) & 0x3FF) / 1023.0f;
/// <summary> /// <summary>
/// Gets the A component. /// Gets the A component.
/// </summary> /// </summary>
public float A => (value >> 30) / 3.0f; public float A => (rawValue >> 30) / 3.0f;
/// <summary> /// <summary>
/// Performs an explicit conversion from <see cref = "T:FlaxEngine.Float4" /> to <see cref = "T:FlaxEngine.FloatR10G10B10A2" />. /// Performs an explicit conversion from <see cref = "T:FlaxEngine.Float4" /> to <see cref = "T:FlaxEngine.FloatR10G10B10A2" />.
@@ -102,7 +98,7 @@ namespace FlaxEngine
/// <returns><c>true</c> if <paramref name="left" /> has the same value as <paramref name="right" />; otherwise, <c>false</c>.</returns> /// <returns><c>true</c> if <paramref name="left" /> has the same value as <paramref name="right" />; otherwise, <c>false</c>.</returns>
public static bool operator ==(FloatR10G10B10A2 left, FloatR10G10B10A2 right) public static bool operator ==(FloatR10G10B10A2 left, FloatR10G10B10A2 right)
{ {
return left.value == right.value; return left.rawValue == right.rawValue;
} }
/// <summary> /// <summary>
@@ -113,7 +109,7 @@ namespace FlaxEngine
/// <returns><c>true</c> if <paramref name="left" /> has a different value than <paramref name="right" />; otherwise, <c>false</c>.</returns> /// <returns><c>true</c> if <paramref name="left" /> has a different value than <paramref name="right" />; otherwise, <c>false</c>.</returns>
public static bool operator !=(FloatR10G10B10A2 left, FloatR10G10B10A2 right) public static bool operator !=(FloatR10G10B10A2 left, FloatR10G10B10A2 right)
{ {
return left.value != right.value; return left.rawValue != right.rawValue;
} }
/// <summary> /// <summary>
@@ -131,7 +127,7 @@ namespace FlaxEngine
/// <returns>A 32-bit signed integer hash code.</returns> /// <returns>A 32-bit signed integer hash code.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return value.GetHashCode(); return rawValue.GetHashCode();
} }
/// <summary> /// <summary>
@@ -142,7 +138,7 @@ namespace FlaxEngine
/// <returns><c>true</c> if <paramref name = "value1" /> is the same instance as <paramref name = "value2" /> or if both are <c>null</c> references or if <c>value1.Equals(value2)</c> returns <c>true</c>; otherwise, <c>false</c>.</returns> /// <returns><c>true</c> if <paramref name = "value1" /> is the same instance as <paramref name = "value2" /> or if both are <c>null</c> references or if <c>value1.Equals(value2)</c> returns <c>true</c>; otherwise, <c>false</c>.</returns>
public static bool Equals(ref FloatR10G10B10A2 value1, ref FloatR10G10B10A2 value2) public static bool Equals(ref FloatR10G10B10A2 value1, ref FloatR10G10B10A2 value2)
{ {
return value1.value == value2.value; return value1.rawValue == value2.rawValue;
} }
/// <summary> /// <summary>
@@ -152,7 +148,7 @@ namespace FlaxEngine
/// <returns><c>true</c> if the current instance is equal to the specified object; <c>false</c> otherwise.</returns> /// <returns><c>true</c> if the current instance is equal to the specified object; <c>false</c> otherwise.</returns>
public bool Equals(FloatR10G10B10A2 other) public bool Equals(FloatR10G10B10A2 other)
{ {
return other.value == value; return other.rawValue == rawValue;
} }
/// <summary> /// <summary>
@@ -162,7 +158,7 @@ namespace FlaxEngine
/// <returns><c>true</c> if the current instance is equal to the specified object; <c>false</c> otherwise.</returns> /// <returns><c>true</c> if the current instance is equal to the specified object; <c>false</c> otherwise.</returns>
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
return obj is FloatR10G10B10A2 other && value == other.value; return obj is FloatR10G10B10A2 other && rawValue == other.rawValue;
} }
private static uint Pack(float x, float y, float z, float w) private static uint Pack(float x, float y, float z, float w)
@@ -191,11 +187,11 @@ namespace FlaxEngine
{ {
Float3 vectorOut; Float3 vectorOut;
uint tmp = value & 0x3FF; uint tmp = rawValue & 0x3FF;
vectorOut.X = tmp / 1023.0f; vectorOut.X = tmp / 1023.0f;
tmp = (value >> 10) & 0x3FF; tmp = (rawValue >> 10) & 0x3FF;
vectorOut.Y = tmp / 1023.0f; vectorOut.Y = tmp / 1023.0f;
tmp = (value >> 20) & 0x3FF; tmp = (rawValue >> 20) & 0x3FF;
vectorOut.Z = tmp / 1023.0f; vectorOut.Z = tmp / 1023.0f;
return vectorOut; return vectorOut;
@@ -209,13 +205,13 @@ namespace FlaxEngine
{ {
Float4 vectorOut; Float4 vectorOut;
uint tmp = value & 0x3FF; uint tmp = rawValue & 0x3FF;
vectorOut.X = tmp / 1023.0f; vectorOut.X = tmp / 1023.0f;
tmp = (value >> 10) & 0x3FF; tmp = (rawValue >> 10) & 0x3FF;
vectorOut.Y = tmp / 1023.0f; vectorOut.Y = tmp / 1023.0f;
tmp = (value >> 20) & 0x3FF; tmp = (rawValue >> 20) & 0x3FF;
vectorOut.Z = tmp / 1023.0f; vectorOut.Z = tmp / 1023.0f;
vectorOut.W = (value >> 30) / 3.0f; vectorOut.W = (rawValue >> 30) / 3.0f;
return vectorOut; return vectorOut;
} }

View File

@@ -21,7 +21,7 @@ namespace FlaxEngine
{ {
// Reference: [https://github.com/Microsoft/DirectXMath/blob/master/Inc/DirectXPackedVector.h] // Reference: [https://github.com/Microsoft/DirectXMath/blob/master/Inc/DirectXPackedVector.h]
private uint value; private uint rawValue;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref = "T:FlaxEngine.FloatR11G11B10" /> structure. /// Initializes a new instance of the <see cref = "T:FlaxEngine.FloatR11G11B10" /> structure.
@@ -31,7 +31,7 @@ namespace FlaxEngine
/// <param name="z">The floating point value that should be stored in B component (10 bits format).</param> /// <param name="z">The floating point value that should be stored in B component (10 bits format).</param>
public FloatR11G11B10(float x, float y, float z) public FloatR11G11B10(float x, float y, float z)
{ {
value = Pack(x, y, z); rawValue = Pack(x, y, z);
} }
/// <summary> /// <summary>
@@ -40,17 +40,13 @@ namespace FlaxEngine
/// <param name="value">The floating point value that should be stored in compressed format.</param> /// <param name="value">The floating point value that should be stored in compressed format.</param>
public FloatR11G11B10(Float3 value) public FloatR11G11B10(Float3 value)
{ {
this.value = Pack(value.X, value.Y, value.Z); rawValue = Pack(value.X, value.Y, value.Z);
} }
/// <summary> /// <summary>
/// Gets or sets the raw 32 bit value used to back this vector. /// Gets or sets the raw 32 bit value used to back this vector.
/// </summary> /// </summary>
public uint RawValue public uint RawValue => rawValue;
{
get => value;
set => this.value = value;
}
/// <summary> /// <summary>
/// Performs an explicit conversion from <see cref = "T:FlaxEngine.Float3" /> to <see cref = "T:FlaxEngine.FloatR11G11B10" />. /// Performs an explicit conversion from <see cref = "T:FlaxEngine.Float3" /> to <see cref = "T:FlaxEngine.FloatR11G11B10" />.
@@ -80,7 +76,7 @@ namespace FlaxEngine
/// <returns><c>true</c> if <paramref name="left" /> has the same value as <paramref name="right" />; otherwise, <c>false</c>.</returns> /// <returns><c>true</c> if <paramref name="left" /> has the same value as <paramref name="right" />; otherwise, <c>false</c>.</returns>
public static bool operator ==(FloatR11G11B10 left, FloatR11G11B10 right) public static bool operator ==(FloatR11G11B10 left, FloatR11G11B10 right)
{ {
return left.value == right.value; return left.rawValue == right.rawValue;
} }
/// <summary> /// <summary>
@@ -91,7 +87,7 @@ namespace FlaxEngine
/// <returns><c>true</c> if <paramref name="left" /> has a different value than <paramref name="right" />; otherwise, <c>false</c>.</returns> /// <returns><c>true</c> if <paramref name="left" /> has a different value than <paramref name="right" />; otherwise, <c>false</c>.</returns>
public static bool operator !=(FloatR11G11B10 left, FloatR11G11B10 right) public static bool operator !=(FloatR11G11B10 left, FloatR11G11B10 right)
{ {
return left.value != right.value; return left.rawValue != right.rawValue;
} }
/// <summary> /// <summary>
@@ -109,7 +105,7 @@ namespace FlaxEngine
/// <returns>A 32-bit signed integer hash code.</returns> /// <returns>A 32-bit signed integer hash code.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return value.GetHashCode(); return rawValue.GetHashCode();
} }
/// <summary> /// <summary>
@@ -120,7 +116,7 @@ namespace FlaxEngine
/// <returns><c>true</c> if <paramref name="value1" /> is the same instance as <paramref name="value2" /> or if both are <c>null</c> references or if <c>value1.Equals(value2)</c> returns <c>true</c>; otherwise, <c>false</c>.</returns> /// <returns><c>true</c> if <paramref name="value1" /> is the same instance as <paramref name="value2" /> or if both are <c>null</c> references or if <c>value1.Equals(value2)</c> returns <c>true</c>; otherwise, <c>false</c>.</returns>
public static bool Equals(ref FloatR11G11B10 value1, ref FloatR11G11B10 value2) public static bool Equals(ref FloatR11G11B10 value1, ref FloatR11G11B10 value2)
{ {
return value1.value == value2.value; return value1.rawValue == value2.rawValue;
} }
/// <summary> /// <summary>
@@ -130,7 +126,7 @@ namespace FlaxEngine
/// <returns><c>true</c> if the current instance is equal to the specified object; <c>false</c> otherwise.</returns> /// <returns><c>true</c> if the current instance is equal to the specified object; <c>false</c> otherwise.</returns>
public bool Equals(FloatR11G11B10 other) public bool Equals(FloatR11G11B10 other)
{ {
return other.value == value; return other.rawValue == rawValue;
} }
/// <summary> /// <summary>
@@ -140,7 +136,7 @@ namespace FlaxEngine
/// <returns><c>true</c> if the current instance is equal to the specified object; <c>false</c> otherwise.</returns> /// <returns><c>true</c> if the current instance is equal to the specified object; <c>false</c> otherwise.</returns>
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
return obj is FloatR11G11B10 other && value == other.value; return obj is FloatR11G11B10 other && rawValue == other.rawValue;
} }
private static unsafe uint Pack(float x, float y, float z) private static unsafe uint Pack(float x, float y, float z)
@@ -288,7 +284,7 @@ namespace FlaxEngine
{ {
int zeroExponent = -112; int zeroExponent = -112;
Packed packed = new Packed(value); Packed packed = new Packed(rawValue);
uint* result = stackalloc uint[4]; uint* result = stackalloc uint[4];
uint exponent; uint exponent;

View File

@@ -38,7 +38,7 @@ namespace FlaxEngine
[StructLayout(LayoutKind.Sequential, Pack = 2)] [StructLayout(LayoutKind.Sequential, Pack = 2)]
public struct Half public struct Half
{ {
private ushort value; private ushort rawValue;
/// <summary> /// <summary>
/// Number of decimal digits of precision. /// Number of decimal digits of precision.
@@ -111,17 +111,13 @@ namespace FlaxEngine
/// <param name = "value">The floating point value that should be stored in 16 bit format.</param> /// <param name = "value">The floating point value that should be stored in 16 bit format.</param>
public Half(float value) public Half(float value)
{ {
this.value = HalfUtils.Pack(value); rawValue = HalfUtils.Pack(value);
} }
/// <summary> /// <summary>
/// Gets or sets the raw 16 bit value used to back this half-float. /// Gets or sets the raw 16 bit value used to back this half-float.
/// </summary> /// </summary>
public ushort RawValue public ushort RawValue => rawValue;
{
get => value;
set => this.value = value;
}
/// <summary> /// <summary>
/// Converts an array of half precision values into full precision values. /// Converts an array of half precision values into full precision values.
@@ -166,7 +162,7 @@ namespace FlaxEngine
/// <returns>The converted value.</returns> /// <returns>The converted value.</returns>
public static implicit operator float(Half value) public static implicit operator float(Half value)
{ {
return HalfUtils.Unpack(value.value); return HalfUtils.Unpack(value.rawValue);
} }
/// <summary> /// <summary>
@@ -177,7 +173,7 @@ namespace FlaxEngine
/// <returns><c>true</c> if <paramref name = "left" /> has the same value as <paramref name = "right" />; otherwise, <c>false</c>.</returns> /// <returns><c>true</c> if <paramref name = "left" /> has the same value as <paramref name = "right" />; otherwise, <c>false</c>.</returns>
public static bool operator ==(Half left, Half right) public static bool operator ==(Half left, Half right)
{ {
return left.value == right.value; return left.rawValue == right.rawValue;
} }
/// <summary> /// <summary>
@@ -188,7 +184,7 @@ namespace FlaxEngine
/// <returns><c>true</c> if <paramref name = "left" /> has a different value than <paramref name = "right" />; otherwise, <c>false</c>.</returns> /// <returns><c>true</c> if <paramref name = "left" /> has a different value than <paramref name = "right" />; otherwise, <c>false</c>.</returns>
public static bool operator !=(Half left, Half right) public static bool operator !=(Half left, Half right)
{ {
return left.value != right.value; return left.rawValue != right.rawValue;
} }
/// <summary> /// <summary>
@@ -207,7 +203,7 @@ namespace FlaxEngine
/// <returns>A 32-bit signed integer hash code.</returns> /// <returns>A 32-bit signed integer hash code.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
ushort num = value; ushort num = rawValue;
return (((num * 3) / 2) ^ num); return (((num * 3) / 2) ^ num);
} }
@@ -219,7 +215,7 @@ namespace FlaxEngine
/// <returns><c>true</c> if <paramref name = "value1" /> is the same instance as <paramref name = "value2" /> or if both are <c>null</c> references or if <c>value1.Equals(value2)</c> returns <c>true</c>; otherwise, <c>false</c>.</returns> /// <returns><c>true</c> if <paramref name = "value1" /> is the same instance as <paramref name = "value2" /> or if both are <c>null</c> references or if <c>value1.Equals(value2)</c> returns <c>true</c>; otherwise, <c>false</c>.</returns>
public static bool Equals(ref Half value1, ref Half value2) public static bool Equals(ref Half value1, ref Half value2)
{ {
return value1.value == value2.value; return value1.rawValue == value2.rawValue;
} }
/// <summary> /// <summary>
@@ -229,7 +225,7 @@ namespace FlaxEngine
/// <returns><c>true</c> if the current instance is equal to the specified object; <c>false</c> otherwise.</returns> /// <returns><c>true</c> if the current instance is equal to the specified object; <c>false</c> otherwise.</returns>
public bool Equals(Half other) public bool Equals(Half other)
{ {
return other.value == value; return other.rawValue == rawValue;
} }
/// <summary> /// <summary>
@@ -248,7 +244,7 @@ namespace FlaxEngine
return false; return false;
} }
Half half = (Half)obj; Half half = (Half)obj;
return half.value == value; return half.rawValue == rawValue;
} }
static Half() static Half()