From 8986290b123ed1f77a2a2f105b76b2fe278f739e Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Fri, 18 Apr 2025 18:43:42 +0300 Subject: [PATCH 01/16] Use exact component value equality checks in equality comparisons (cherry picked from commit 2cddf3de97943844512b2d84aa6be122c6f0d409) --- Source/Engine/Animations/Curve.h | 8 ++-- Source/Engine/Core/Math/BoundingBox.cs | 12 +++--- Source/Engine/Core/Math/BoundingSphere.cs | 12 +++--- Source/Engine/Core/Math/Color.cs | 25 ++++++------- Source/Engine/Core/Math/Double2.cs | 12 +++--- Source/Engine/Core/Math/Double3.cs | 10 ++--- Source/Engine/Core/Math/Double4.cs | 8 ++-- Source/Engine/Core/Math/Float2.cs | 12 +++--- Source/Engine/Core/Math/Float3.cs | 10 ++--- Source/Engine/Core/Math/Float4.cs | 8 ++-- Source/Engine/Core/Math/Matrix.cpp | 2 +- Source/Engine/Core/Math/Matrix.cs | 37 +++++++++---------- Source/Engine/Core/Math/Matrix2x2.cs | 4 +- Source/Engine/Core/Math/Matrix3x3.cpp | 19 +++++----- Source/Engine/Core/Math/Matrix3x3.cs | 30 +++++---------- .../Engine/Core/Math/OrientedBoundingBox.cs | 2 +- Source/Engine/Core/Math/Plane.cs | 17 ++++----- Source/Engine/Core/Math/Quaternion.cs | 12 ++---- Source/Engine/Core/Math/Quaternion.h | 4 +- Source/Engine/Core/Math/Ray.cs | 12 +++--- Source/Engine/Core/Math/Rectangle.cs | 8 ++-- Source/Engine/Core/Math/Vector2.cs | 12 +++--- Source/Engine/Core/Math/Vector3.cs | 10 ++--- Source/Engine/Core/Math/Vector4.cs | 8 ++-- Source/Engine/Core/Math/Viewport.cs | 12 +++--- Source/Engine/Core/Types/Variant.cpp | 4 +- Source/Engine/Foliage/FoliageInstance.h | 2 +- .../Engine/Graphics/Materials/MaterialInfo.cs | 4 +- .../Graphics/Materials/MaterialParams.cpp | 12 +++--- .../Textures/GPUSamplerDescription.cs | 6 +-- Source/Engine/Navigation/Navigation.cpp | 6 +-- Source/Engine/Physics/Joints/HingeJoint.h | 2 +- Source/Engine/Render2D/TextLayoutOptions.h | 4 +- Source/Engine/UI/GUI/Margin.cs | 8 ++-- 34 files changed, 164 insertions(+), 190 deletions(-) diff --git a/Source/Engine/Animations/Curve.h b/Source/Engine/Animations/Curve.h index 11142d1e4..8508d8751 100644 --- a/Source/Engine/Animations/Curve.h +++ b/Source/Engine/Animations/Curve.h @@ -58,7 +58,7 @@ public: bool operator==(const StepCurveKeyframe& other) const { - return Math::NearEqual(Time, other.Time) && Math::NearEqual(Value, other.Value); + return Time == other.Time && Value == other.Value; } } PACK_END(); @@ -113,7 +113,7 @@ public: bool operator==(const LinearCurveKeyframe& other) const { - return Math::NearEqual(Time, other.Time) && Math::NearEqual(Value, other.Value); + return Time == other.Time && Value == other.Value; } } PACK_END(); @@ -188,7 +188,7 @@ public: bool operator==(const HermiteCurveKeyframe& other) const { - return Math::NearEqual(Time, other.Time) && Math::NearEqual(Value, other.Value) && Math::NearEqual(TangentIn, other.TangentIn) && Math::NearEqual(TangentOut, other.TangentOut); + return Time == other.Time && Value == other.Value && TangentIn == other.TangentIn && TangentOut == other.TangentOut; } } PACK_END(); @@ -276,7 +276,7 @@ public: bool operator==(const BezierCurveKeyframe& other) const { - return Math::NearEqual(Time, other.Time) && Math::NearEqual(Value, other.Value) && Math::NearEqual(TangentIn, other.TangentIn) && Math::NearEqual(TangentOut, other.TangentOut); + return Time == other.Time && Value == other.Value && TangentIn == other.TangentIn && TangentOut == other.TangentOut; } } PACK_END(); diff --git a/Source/Engine/Core/Math/BoundingBox.cs b/Source/Engine/Core/Math/BoundingBox.cs index e0abe7e03..cd702d531 100644 --- a/Source/Engine/Core/Math/BoundingBox.cs +++ b/Source/Engine/Core/Math/BoundingBox.cs @@ -673,23 +673,23 @@ namespace FlaxEngine /// /// Determines whether the specified is equal to this instance. /// - /// The to compare with this instance. + /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(ref BoundingBox value) + public bool Equals(ref BoundingBox other) { - return Minimum == value.Minimum && Maximum == value.Maximum; + return Minimum == other.Minimum && Maximum == other.Maximum; } /// /// Determines whether the specified is equal to this instance. /// - /// The to compare with this instance. + /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(BoundingBox value) + public bool Equals(BoundingBox other) { - return Equals(ref value); + return Equals(ref other); } /// diff --git a/Source/Engine/Core/Math/BoundingSphere.cs b/Source/Engine/Core/Math/BoundingSphere.cs index 1a03967f4..b57177d77 100644 --- a/Source/Engine/Core/Math/BoundingSphere.cs +++ b/Source/Engine/Core/Math/BoundingSphere.cs @@ -487,23 +487,23 @@ namespace FlaxEngine /// /// Determines whether the specified is equal to this instance. /// - /// The to compare with this instance. + /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(ref BoundingSphere value) + public bool Equals(ref BoundingSphere other) { - return (Center == value.Center) && (Radius == value.Radius); + return Center == other.Center && Radius == other.Radius; } /// /// Determines whether the specified is equal to this instance. /// - /// The to compare with this instance. + /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(BoundingSphere value) + public bool Equals(BoundingSphere other) { - return Equals(ref value); + return Equals(ref other); } /// diff --git a/Source/Engine/Core/Math/Color.cs b/Source/Engine/Core/Math/Color.cs index ee7190b53..2d779dcfa 100644 --- a/Source/Engine/Core/Math/Color.cs +++ b/Source/Engine/Core/Math/Color.cs @@ -197,12 +197,9 @@ namespace FlaxEngine } /// - public override bool Equals(object other) + public override bool Equals(object value) { - if (!(other is Color)) - return false; - var color = (Color)other; - return Equals(ref color); + return value is Color other && Equals(ref other); } /// @@ -213,7 +210,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(ref Color other) { - return Mathf.NearEqual(other.R, R) && Mathf.NearEqual(other.G, G) && Mathf.NearEqual(other.B, B) && Mathf.NearEqual(other.A, A); + return R == other.R && G == other.G && B == other.B && A == other.A; } /// @@ -661,23 +658,23 @@ namespace FlaxEngine /// /// Compares two colors. /// - /// The left. - /// The right. + /// The left. + /// The right. /// True if colors are equal, otherwise false. - public static bool operator ==(Color lhs, Color rhs) + public static bool operator ==(Color left, Color right) { - return lhs.Equals(ref rhs); + return left.Equals(ref right); } /// /// Compares two colors. /// - /// The left. - /// The right. + /// The left. + /// The right. /// True if colors are not equal, otherwise false. - public static bool operator !=(Color lhs, Color rhs) + public static bool operator !=(Color left, Color right) { - return !lhs.Equals(ref rhs); + return !left.Equals(ref right); } /// diff --git a/Source/Engine/Core/Math/Double2.cs b/Source/Engine/Core/Math/Double2.cs index b6ef33146..9594b22cb 100644 --- a/Source/Engine/Core/Math/Double2.cs +++ b/Source/Engine/Core/Math/Double2.cs @@ -1464,7 +1464,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Double2 left, Double2 right) { - return Mathd.NearEqual(left.X, right.X) && Mathd.NearEqual(left.Y, right.Y); + return left.Equals(ref right); } /// @@ -1476,7 +1476,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Double2 left, Double2 right) { - return !Mathd.NearEqual(left.X, right.X) || !Mathd.NearEqual(left.Y, right.Y); + return !left.Equals(ref right); } /// @@ -1582,7 +1582,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(ref Double2 other) { - return Mathd.NearEqual(other.X, X) && Mathd.NearEqual(other.Y, Y); + return X == other.X && Y == other.Y; } /// @@ -1590,7 +1590,7 @@ namespace FlaxEngine /// public static bool Equals(ref Double2 a, ref Double2 b) { - return Mathd.NearEqual(a.X, b.X) && Mathd.NearEqual(a.Y, b.Y); + return a.Equals(ref b); } /// @@ -1601,7 +1601,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Double2 other) { - return Mathd.NearEqual(other.X, X) && Mathd.NearEqual(other.Y, Y); + return Equals(ref other); } /// @@ -1611,7 +1611,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is Double2 other && Mathd.NearEqual(other.X, X) && Mathd.NearEqual(other.Y, Y); + return value is Double2 other && Equals(ref other); } } } diff --git a/Source/Engine/Core/Math/Double3.cs b/Source/Engine/Core/Math/Double3.cs index 0271612f4..cb26cf071 100644 --- a/Source/Engine/Core/Math/Double3.cs +++ b/Source/Engine/Core/Math/Double3.cs @@ -1759,7 +1759,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Double3 left, Double3 right) { - return Mathd.NearEqual(left.X, right.X) && Mathd.NearEqual(left.Y, right.Y) && Mathd.NearEqual(left.Z, right.Z); + return left.Equals(ref right); } /// @@ -1771,7 +1771,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Double3 left, Double3 right) { - return !Mathd.NearEqual(left.X, right.X) || !Mathd.NearEqual(left.Y, right.Y) || !Mathd.NearEqual(left.Z, right.Z); + return !left.Equals(ref right); } /// @@ -1880,7 +1880,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(ref Double3 other) { - return Mathd.NearEqual(other.X, X) && Mathd.NearEqual(other.Y, Y) && Mathd.NearEqual(other.Z, Z); + return X == other.X && Y == other.Y && Z == other.Z; } /// @@ -1891,7 +1891,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Double3 other) { - return Mathd.NearEqual(other.X, X) && Mathd.NearEqual(other.Y, Y) && Mathd.NearEqual(other.Z, Z); + return Equals(ref other); } /// @@ -1901,7 +1901,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is Double3 other && Mathd.NearEqual(other.X, X) && Mathd.NearEqual(other.Y, Y) && Mathd.NearEqual(other.Z, Z); + return value is Double3 other && Equals(ref other); } } } diff --git a/Source/Engine/Core/Math/Double4.cs b/Source/Engine/Core/Math/Double4.cs index f9f79069c..70d27cb28 100644 --- a/Source/Engine/Core/Math/Double4.cs +++ b/Source/Engine/Core/Math/Double4.cs @@ -1258,7 +1258,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Double4 left, Double4 right) { - return Mathd.NearEqual(left.X, right.X) && Mathd.NearEqual(left.Y, right.Y) && Mathd.NearEqual(left.Z, right.Z) && Mathd.NearEqual(left.W, right.W); + return left.Equals(ref right); } /// @@ -1379,7 +1379,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public bool Equals(ref Double4 other) { - return Mathd.NearEqual(other.X, X) && Mathd.NearEqual(other.Y, Y) && Mathd.NearEqual(other.Z, Z) && Mathd.NearEqual(other.W, W); + return X == other.X && Y == other.Y && Z == other.Z && W == other.W; } /// @@ -1390,7 +1390,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Double4 other) { - return Mathd.NearEqual(other.X, X) && Mathd.NearEqual(other.Y, Y) && Mathd.NearEqual(other.Z, Z) && Mathd.NearEqual(other.W, W); + return Equals(ref other); } /// @@ -1400,7 +1400,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is Double4 other && Mathd.NearEqual(other.X, X) && Mathd.NearEqual(other.Y, Y) && Mathd.NearEqual(other.Z, Z) && Mathd.NearEqual(other.W, W); + return value is Double4 other && Equals(ref other); } } } diff --git a/Source/Engine/Core/Math/Float2.cs b/Source/Engine/Core/Math/Float2.cs index 0da460889..1b70dd0a6 100644 --- a/Source/Engine/Core/Math/Float2.cs +++ b/Source/Engine/Core/Math/Float2.cs @@ -1540,7 +1540,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Float2 left, Float2 right) { - return Mathf.NearEqual(left.X, right.X) && Mathf.NearEqual(left.Y, right.Y); + return left.Equals(ref right); } /// @@ -1552,7 +1552,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Float2 left, Float2 right) { - return !Mathf.NearEqual(left.X, right.X) || !Mathf.NearEqual(left.Y, right.Y); + return !left.Equals(ref right); } /// @@ -1658,7 +1658,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(ref Float2 other) { - return Mathf.NearEqual(other.X, X) && Mathf.NearEqual(other.Y, Y); + return X == other.X && Y == other.Y; } /// @@ -1666,7 +1666,7 @@ namespace FlaxEngine /// public static bool Equals(ref Float2 a, ref Float2 b) { - return Mathf.NearEqual(a.X, b.X) && Mathf.NearEqual(a.Y, b.Y); + return a.Equals(ref b); } /// @@ -1677,7 +1677,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Float2 other) { - return Mathf.NearEqual(other.X, X) && Mathf.NearEqual(other.Y, Y); + return Equals(ref other); } /// @@ -1687,7 +1687,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is Float2 other && Mathf.NearEqual(other.X, X) && Mathf.NearEqual(other.Y, Y); + return value is Float2 other && Equals(ref other); } } } diff --git a/Source/Engine/Core/Math/Float3.cs b/Source/Engine/Core/Math/Float3.cs index 659e6562a..5e8dceed6 100644 --- a/Source/Engine/Core/Math/Float3.cs +++ b/Source/Engine/Core/Math/Float3.cs @@ -1791,7 +1791,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Float3 left, Float3 right) { - return Mathf.NearEqual(left.X, right.X) && Mathf.NearEqual(left.Y, right.Y) && Mathf.NearEqual(left.Z, right.Z); + return left.Equals(ref right); } /// @@ -1803,7 +1803,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Float3 left, Float3 right) { - return !Mathf.NearEqual(left.X, right.X) || !Mathf.NearEqual(left.Y, right.Y) || !Mathf.NearEqual(left.Z, right.Z); + return !left.Equals(ref right); } /// @@ -1912,7 +1912,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(ref Float3 other) { - return Mathf.NearEqual(other.X, X) && Mathf.NearEqual(other.Y, Y) && Mathf.NearEqual(other.Z, Z); + return X == other.X && Y == other.Y && Z == other.Z; } /// @@ -1923,7 +1923,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Float3 other) { - return Mathf.NearEqual(other.X, X) && Mathf.NearEqual(other.Y, Y) && Mathf.NearEqual(other.Z, Z); + return Equals(ref other); } /// @@ -1933,7 +1933,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is Float3 other && Mathf.NearEqual(other.X, X) && Mathf.NearEqual(other.Y, Y) && Mathf.NearEqual(other.Z, Z); + return value is Float3 other && Equals(ref other); } } } diff --git a/Source/Engine/Core/Math/Float4.cs b/Source/Engine/Core/Math/Float4.cs index 2e48c9d7f..b6eb6dd9e 100644 --- a/Source/Engine/Core/Math/Float4.cs +++ b/Source/Engine/Core/Math/Float4.cs @@ -1288,7 +1288,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Float4 left, Float4 right) { - return Mathf.NearEqual(left.X, right.X) && Mathf.NearEqual(left.Y, right.Y) && Mathf.NearEqual(left.Z, right.Z) && Mathf.NearEqual(left.W, right.W); + return left.Equals(ref right); } /// @@ -1419,7 +1419,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public bool Equals(ref Float4 other) { - return Mathf.NearEqual(other.X, X) && Mathf.NearEqual(other.Y, Y) && Mathf.NearEqual(other.Z, Z) && Mathf.NearEqual(other.W, W); + return X == other.X && Y == other.Y && Z == other.Z && W == other.W; } /// @@ -1430,7 +1430,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Float4 other) { - return Mathf.NearEqual(other.X, X) && Mathf.NearEqual(other.Y, Y) && Mathf.NearEqual(other.Z, Z) && Mathf.NearEqual(other.W, W); + return Equals(ref other); } /// @@ -1440,7 +1440,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is Float4 other && Mathf.NearEqual(other.X, X) && Mathf.NearEqual(other.Y, Y) && Mathf.NearEqual(other.Z, Z) && Mathf.NearEqual(other.W, W); + return value is Float4 other && Equals(ref other); } } } diff --git a/Source/Engine/Core/Math/Matrix.cpp b/Source/Engine/Core/Math/Matrix.cpp index dea1d77d2..4a73323d3 100644 --- a/Source/Engine/Core/Math/Matrix.cpp +++ b/Source/Engine/Core/Math/Matrix.cpp @@ -163,7 +163,7 @@ bool Matrix::operator==(const Matrix& other) const { for (int32 i = 0; i < 16; i++) { - if (Math::NotNearEqual(other.Raw[i], Raw[i])) + if (other.Raw[i] != Raw[i]) return false; } return true; diff --git a/Source/Engine/Core/Math/Matrix.cs b/Source/Engine/Core/Math/Matrix.cs index 9fe1bdc49..07ab2dea9 100644 --- a/Source/Engine/Core/Math/Matrix.cs +++ b/Source/Engine/Core/Math/Matrix.cs @@ -3236,22 +3236,22 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public bool Equals(ref Matrix other) { - return Mathf.NearEqual(other.M11, M11) && - Mathf.NearEqual(other.M12, M12) && - Mathf.NearEqual(other.M13, M13) && - Mathf.NearEqual(other.M14, M14) && - Mathf.NearEqual(other.M21, M21) && - Mathf.NearEqual(other.M22, M22) && - Mathf.NearEqual(other.M23, M23) && - Mathf.NearEqual(other.M24, M24) && - Mathf.NearEqual(other.M31, M31) && - Mathf.NearEqual(other.M32, M32) && - Mathf.NearEqual(other.M33, M33) && - Mathf.NearEqual(other.M34, M34) && - Mathf.NearEqual(other.M41, M41) && - Mathf.NearEqual(other.M42, M42) && - Mathf.NearEqual(other.M43, M43) && - Mathf.NearEqual(other.M44, M44); + return other.M11 == M11 && + other.M12 == M12 && + other.M13 == M13 && + other.M14 == M14 && + other.M21 == M21 && + other.M22 == M22 && + other.M23 == M23 && + other.M24 == M24 && + other.M31 == M31 && + other.M32 == M32 && + other.M33 == M33 && + other.M34 == M34 && + other.M41 == M41 && + other.M42 == M42 && + other.M43 == M43 && + other.M44 == M44; } /// @@ -3272,10 +3272,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - if (!(value is Matrix)) - return false; - var v = (Matrix)value; - return Equals(ref v); + return value is Matrix other && Equals(ref other); } } } diff --git a/Source/Engine/Core/Math/Matrix2x2.cs b/Source/Engine/Core/Math/Matrix2x2.cs index 250789e80..7244d41bd 100644 --- a/Source/Engine/Core/Math/Matrix2x2.cs +++ b/Source/Engine/Core/Math/Matrix2x2.cs @@ -483,7 +483,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public bool Equals(ref Matrix2x2 other) { - return Mathf.NearEqual(other.M11, M11) && Mathf.NearEqual(other.M12, M12) && Mathf.NearEqual(other.M21, M21) && Mathf.NearEqual(other.M22, M22); + return M11 == other.M11 && M12 == other.M12 && M21 == other.M21 && M22 == other.M22; } /// @@ -502,7 +502,7 @@ namespace FlaxEngine /// public static bool Equals(ref Matrix2x2 a, ref Matrix2x2 b) { - return Mathf.NearEqual(a.M11, b.M11) && Mathf.NearEqual(a.M12, b.M12) && Mathf.NearEqual(a.M21, b.M21) && Mathf.NearEqual(a.M22, b.M22); + return a.Equals(ref b); } /// diff --git a/Source/Engine/Core/Math/Matrix3x3.cpp b/Source/Engine/Core/Math/Matrix3x3.cpp index 8478b2ca1..218f2dad6 100644 --- a/Source/Engine/Core/Math/Matrix3x3.cpp +++ b/Source/Engine/Core/Math/Matrix3x3.cpp @@ -242,14 +242,13 @@ void Matrix3x3::Decompose(Float3& scale, Quaternion& rotation) const bool Matrix3x3::operator==(const Matrix3x3& other) const { - return - Math::NearEqual(M11, other.M11) && - Math::NearEqual(M12, other.M12) && - Math::NearEqual(M13, other.M13) && - Math::NearEqual(M21, other.M21) && - Math::NearEqual(M22, other.M22) && - Math::NearEqual(M23, other.M23) && - Math::NearEqual(M31, other.M31) && - Math::NearEqual(M32, other.M32) && - Math::NearEqual(M33, other.M33); + return M11 == other.M11 && + M12 == other.M12 && + M13 == other.M13 && + M21 == other.M21 && + M22 == other.M22 && + M23 == other.M23 && + M31 == other.M31 && + M32 == other.M32 && + M33 == other.M33; } diff --git a/Source/Engine/Core/Math/Matrix3x3.cs b/Source/Engine/Core/Math/Matrix3x3.cs index 9522c4087..76e10ed1a 100644 --- a/Source/Engine/Core/Math/Matrix3x3.cs +++ b/Source/Engine/Core/Math/Matrix3x3.cs @@ -2125,15 +2125,15 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public bool Equals(ref Matrix3x3 other) { - return (Mathf.NearEqual(other.M11, M11) && - Mathf.NearEqual(other.M12, M12) && - Mathf.NearEqual(other.M13, M13) && - Mathf.NearEqual(other.M21, M21) && - Mathf.NearEqual(other.M22, M22) && - Mathf.NearEqual(other.M23, M23) && - Mathf.NearEqual(other.M31, M31) && - Mathf.NearEqual(other.M32, M32) && - Mathf.NearEqual(other.M33, M33)); + return M11 == other.M11 && + M12 == other.M12 && + M13 == other.M13 && + M21 == other.M21 && + M22 == other.M22 && + M23 == other.M23 && + M31 == other.M31 && + M32 == other.M32 && + M33 == other.M33; } /// @@ -2152,17 +2152,7 @@ namespace FlaxEngine /// public static bool Equals(ref Matrix3x3 a, ref Matrix3x3 b) { - return - Mathf.NearEqual(a.M11, b.M11) && - Mathf.NearEqual(a.M12, b.M12) && - Mathf.NearEqual(a.M13, b.M13) && - Mathf.NearEqual(a.M21, b.M21) && - Mathf.NearEqual(a.M22, b.M22) && - Mathf.NearEqual(a.M23, b.M23) && - Mathf.NearEqual(a.M31, b.M31) && - Mathf.NearEqual(a.M32, b.M32) && - Mathf.NearEqual(a.M33, b.M33) - ; + return a.Equals(ref b); } /// diff --git a/Source/Engine/Core/Math/OrientedBoundingBox.cs b/Source/Engine/Core/Math/OrientedBoundingBox.cs index 8171247e6..59ffd0009 100644 --- a/Source/Engine/Core/Math/OrientedBoundingBox.cs +++ b/Source/Engine/Core/Math/OrientedBoundingBox.cs @@ -397,7 +397,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(ref OrientedBoundingBox value) { - return (Extents == value.Extents) && (Transformation == value.Transformation); + return Extents == value.Extents && Transformation == value.Transformation; } /// diff --git a/Source/Engine/Core/Math/Plane.cs b/Source/Engine/Core/Math/Plane.cs index dc565b054..7156f4562 100644 --- a/Source/Engine/Core/Math/Plane.cs +++ b/Source/Engine/Core/Math/Plane.cs @@ -582,23 +582,23 @@ namespace FlaxEngine /// /// Determines whether the specified is equal to this instance. /// - /// The to compare with this instance. + /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(ref Plane value) + public bool Equals(ref Plane other) { - return Normal == value.Normal && D == value.D; + return Normal == other.Normal && D == other.D; } /// /// Determines whether the specified is equal to this instance. /// - /// The to compare with this instance. + /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(Plane value) + public bool Equals(Plane other) { - return Equals(ref value); + return Equals(ref other); } /// @@ -608,10 +608,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - if (!(value is Plane)) - return false; - var strongValue = (Plane)value; - return Equals(ref strongValue); + return value is Plane other && Equals(ref other); } } } diff --git a/Source/Engine/Core/Math/Quaternion.cs b/Source/Engine/Core/Math/Quaternion.cs index 935354354..354ee83fb 100644 --- a/Source/Engine/Core/Math/Quaternion.cs +++ b/Source/Engine/Core/Math/Quaternion.cs @@ -1602,7 +1602,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Quaternion left, Quaternion right) { - return Dot(ref left, ref right) > Tolerance; + return left.Equals(ref right); } /// @@ -1614,7 +1614,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Quaternion left, Quaternion right) { - return Dot(ref left, ref right) <= Tolerance; + return !left.Equals(ref right); } /// @@ -1714,8 +1714,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(ref Quaternion other) { - //return Dot(ref this, ref other) > Tolerance; - return Mathf.NearEqual(other.X, X) && Mathf.NearEqual(other.Y, Y) && Mathf.NearEqual(other.Z, Z) && Mathf.NearEqual(other.W, W); + return X == other.X && Y == other.Y && Z == other.Z && W == other.W; } /// @@ -1736,10 +1735,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - if (!(value is Quaternion)) - return false; - var strongValue = (Quaternion)value; - return Equals(ref strongValue); + return value is Quaternion other && Equals(ref other); } } } diff --git a/Source/Engine/Core/Math/Quaternion.h b/Source/Engine/Core/Math/Quaternion.h index 2e300811a..965f92078 100644 --- a/Source/Engine/Core/Math/Quaternion.h +++ b/Source/Engine/Core/Math/Quaternion.h @@ -348,7 +348,7 @@ public: /// true if the specified is equal to this instance; otherwise, false. FORCE_INLINE bool operator==(const Quaternion& other) const { - return Dot(*this, other) > Tolerance; + return X == other.X && Y == other.Y && Z == other.Z && W == other.W; } /// @@ -358,7 +358,7 @@ public: /// true if the specified isn't equal to this instance; otherwise, false. FORCE_INLINE bool operator!=(const Quaternion& other) const { - return Dot(*this, other) < Tolerance; + return X != other.X || Y != other.Y || Z != other.Z || W != other.W; } public: diff --git a/Source/Engine/Core/Math/Ray.cs b/Source/Engine/Core/Math/Ray.cs index 3f5bde0e6..36203cbf7 100644 --- a/Source/Engine/Core/Math/Ray.cs +++ b/Source/Engine/Core/Math/Ray.cs @@ -428,23 +428,23 @@ namespace FlaxEngine /// /// Determines whether the specified is equal to this instance. /// - /// The to compare with this instance. + /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(ref Ray value) + public bool Equals(ref Ray other) { - return (Position == value.Position) && (Direction == value.Direction); + return Position == other.Position && Direction == other.Direction; } /// /// Determines whether the specified is equal to this instance. /// - /// The to compare with this instance. + /// The to compare with this instance. /// true if the specified is equal to this instance; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(Ray value) + public bool Equals(Ray other) { - return Equals(ref value); + return Equals(ref other); } /// diff --git a/Source/Engine/Core/Math/Rectangle.cs b/Source/Engine/Core/Math/Rectangle.cs index ee2a1703c..81c689d48 100644 --- a/Source/Engine/Core/Math/Rectangle.cs +++ b/Source/Engine/Core/Math/Rectangle.cs @@ -499,21 +499,19 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(ref Rectangle other) { - return Location.Equals(ref other.Location) && Size.Equals(ref other.Size); + return Location == other.Location && Size == other.Size; } /// public bool Equals(Rectangle other) { - return Location.Equals(ref other.Location) && Size.Equals(ref other.Size); + return Equals(ref other); } /// public override bool Equals(object obj) { - if (ReferenceEquals(null, obj)) - return false; - return obj is Rectangle && Equals((Rectangle)obj); + return obj is Rectangle other && Equals(ref other); } /// diff --git a/Source/Engine/Core/Math/Vector2.cs b/Source/Engine/Core/Math/Vector2.cs index ae317897b..8e1599513 100644 --- a/Source/Engine/Core/Math/Vector2.cs +++ b/Source/Engine/Core/Math/Vector2.cs @@ -1654,7 +1654,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Vector2 left, Vector2 right) { - return Mathr.NearEqual(left.X, right.X) && Mathr.NearEqual(left.Y, right.Y); + return left.Equals(ref right); } /// @@ -1666,7 +1666,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Vector2 left, Vector2 right) { - return !Mathr.NearEqual(left.X, right.X) || !Mathr.NearEqual(left.Y, right.Y); + return !left.Equals(ref right); } /// @@ -1782,7 +1782,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(ref Vector2 other) { - return Mathr.NearEqual(other.X, X) && Mathr.NearEqual(other.Y, Y); + return X == other.X && Y == other.Y; } /// @@ -1790,7 +1790,7 @@ namespace FlaxEngine /// public static bool Equals(ref Vector2 a, ref Vector2 b) { - return Mathr.NearEqual(a.X, b.X) && Mathr.NearEqual(a.Y, b.Y); + return a.Equals(ref b); } /// @@ -1801,7 +1801,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Vector2 other) { - return Mathr.NearEqual(other.X, X) && Mathr.NearEqual(other.Y, Y); + return Equals(ref other); } /// @@ -1811,7 +1811,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is Vector2 other && Mathr.NearEqual(other.X, X) && Mathr.NearEqual(other.Y, Y); + return value is Vector2 other && Equals(ref other); } } } diff --git a/Source/Engine/Core/Math/Vector3.cs b/Source/Engine/Core/Math/Vector3.cs index 845cf2f97..5e01a7a6c 100644 --- a/Source/Engine/Core/Math/Vector3.cs +++ b/Source/Engine/Core/Math/Vector3.cs @@ -2010,7 +2010,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Vector3 left, Vector3 right) { - return Mathr.NearEqual(left.X, right.X) && Mathr.NearEqual(left.Y, right.Y) && Mathr.NearEqual(left.Z, right.Z); + return left.Equals(ref right); } /// @@ -2022,7 +2022,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(Vector3 left, Vector3 right) { - return !Mathr.NearEqual(left.X, right.X) || !Mathr.NearEqual(left.Y, right.Y) || !Mathr.NearEqual(left.Z, right.Z); + return !left.Equals(ref right); } /// @@ -2141,7 +2141,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(ref Vector3 other) { - return Mathr.NearEqual(other.X, X) && Mathr.NearEqual(other.Y, Y) && Mathr.NearEqual(other.Z, Z); + return X == other.X && Y == other.Y && Z == other.Z; } /// @@ -2152,7 +2152,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Vector3 other) { - return Mathr.NearEqual(other.X, X) && Mathr.NearEqual(other.Y, Y) && Mathr.NearEqual(other.Z, Z); + return Equals(ref other); } /// @@ -2162,7 +2162,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is Vector3 other && Mathr.NearEqual(other.X, X) && Mathr.NearEqual(other.Y, Y) && Mathr.NearEqual(other.Z, Z); + return value is Vector3 other && Equals(ref other); } } } diff --git a/Source/Engine/Core/Math/Vector4.cs b/Source/Engine/Core/Math/Vector4.cs index 1564a9ee0..e50d03ca0 100644 --- a/Source/Engine/Core/Math/Vector4.cs +++ b/Source/Engine/Core/Math/Vector4.cs @@ -1362,7 +1362,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Vector4 left, Vector4 right) { - return Mathr.NearEqual(left.X, right.X) && Mathr.NearEqual(left.Y, right.Y) && Mathr.NearEqual(left.Z, right.Z) && Mathr.NearEqual(left.W, right.W); + return left.Equals(ref right); } /// @@ -1493,7 +1493,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public bool Equals(ref Vector4 other) { - return Mathr.NearEqual(other.X, X) && Mathr.NearEqual(other.Y, Y) && Mathr.NearEqual(other.Z, Z) && Mathr.NearEqual(other.W, W); + return X == other.X && Y == other.Y && Z == other.Z && W == other.W; } /// @@ -1504,7 +1504,7 @@ namespace FlaxEngine [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Vector4 other) { - return Mathr.NearEqual(other.X, X) && Mathr.NearEqual(other.Y, Y) && Mathr.NearEqual(other.Z, Z) && Mathr.NearEqual(other.W, W); + return Equals(ref other); } /// @@ -1514,7 +1514,7 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public override bool Equals(object value) { - return value is Vector4 other && Mathr.NearEqual(other.X, X) && Mathr.NearEqual(other.Y, Y) && Mathr.NearEqual(other.Z, Z) && Mathr.NearEqual(other.W, W); + return value is Vector4 other && Equals(ref other); } } } diff --git a/Source/Engine/Core/Math/Viewport.cs b/Source/Engine/Core/Math/Viewport.cs index f2be10457..f42c1f22a 100644 --- a/Source/Engine/Core/Math/Viewport.cs +++ b/Source/Engine/Core/Math/Viewport.cs @@ -173,12 +173,12 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public bool Equals(ref Viewport other) { - return Mathf.NearEqual(X, other.X) && - Mathf.NearEqual(Y, other.Y) && - Mathf.NearEqual(Width, other.Width) && - Mathf.NearEqual(Height, other.Height) && - Mathf.NearEqual(MinDepth, other.MinDepth) && - Mathf.NearEqual(MaxDepth, other.MaxDepth); + return X == other.X && + Y == other.Y && + Width == other.Width && + Height == other.Height && + MinDepth == other.MinDepth && + MaxDepth == other.MaxDepth; } /// diff --git a/Source/Engine/Core/Types/Variant.cpp b/Source/Engine/Core/Types/Variant.cpp index f45856443..a8a3b6b9f 100644 --- a/Source/Engine/Core/Types/Variant.cpp +++ b/Source/Engine/Core/Types/Variant.cpp @@ -1162,9 +1162,9 @@ bool Variant::operator==(const Variant& other) const case VariantType::Enum: return AsEnum == other.AsEnum; case VariantType::Float: - return Math::NearEqual(AsFloat, other.AsFloat); + return AsFloat == other.AsFloat; case VariantType::Double: - return Math::Abs(AsDouble - other.AsDouble) < ZeroTolerance; + return AsDouble == other.AsDouble; case VariantType::Pointer: return AsPointer == other.AsPointer; case VariantType::String: diff --git a/Source/Engine/Foliage/FoliageInstance.h b/Source/Engine/Foliage/FoliageInstance.h index 5022d12be..76037f0f4 100644 --- a/Source/Engine/Foliage/FoliageInstance.h +++ b/Source/Engine/Foliage/FoliageInstance.h @@ -52,7 +52,7 @@ API_STRUCT(NoPod) struct FLAXENGINE_API FoliageInstance public: bool operator==(const FoliageInstance& v) const { - return Type == v.Type && Math::NearEqual(Random, v.Random) && Transform == v.Transform; + return Type == v.Type && Random == v.Random && Transform == v.Transform; } /// diff --git a/Source/Engine/Graphics/Materials/MaterialInfo.cs b/Source/Engine/Graphics/Materials/MaterialInfo.cs index a8ff82665..b0a78a6eb 100644 --- a/Source/Engine/Graphics/Materials/MaterialInfo.cs +++ b/Source/Engine/Graphics/Materials/MaterialInfo.cs @@ -64,8 +64,8 @@ namespace FlaxEngine && DecalBlendingMode == other.DecalBlendingMode && TransparentLightingMode == other.TransparentLightingMode && PostFxLocation == other.PostFxLocation - && Mathf.NearEqual(MaskThreshold, other.MaskThreshold) - && Mathf.NearEqual(OpacityThreshold, other.OpacityThreshold) + && MaskThreshold == other.MaskThreshold + && OpacityThreshold == other.OpacityThreshold && TessellationMode == other.TessellationMode && MaxTessellationFactor == other.MaxTessellationFactor; } diff --git a/Source/Engine/Graphics/Materials/MaterialParams.cpp b/Source/Engine/Graphics/Materials/MaterialParams.cpp index e31697f77..d2a4855b5 100644 --- a/Source/Engine/Graphics/Materials/MaterialParams.cpp +++ b/Source/Engine/Graphics/Materials/MaterialParams.cpp @@ -24,8 +24,8 @@ bool MaterialInfo8::operator==(const MaterialInfo8& other) const && TransparentLighting == other.TransparentLighting && DecalBlendingMode == other.DecalBlendingMode && PostFxLocation == other.PostFxLocation - && Math::NearEqual(MaskThreshold, other.MaskThreshold) - && Math::NearEqual(OpacityThreshold, other.OpacityThreshold) + && MaskThreshold == other.MaskThreshold + && OpacityThreshold == other.OpacityThreshold && Flags == other.Flags && TessellationMode == other.TessellationMode && MaxTessellationFactor == other.MaxTessellationFactor; @@ -89,8 +89,8 @@ bool MaterialInfo9::operator==(const MaterialInfo9& other) const && DecalBlendingMode == other.DecalBlendingMode && PostFxLocation == other.PostFxLocation && CullMode == other.CullMode - && Math::NearEqual(MaskThreshold, other.MaskThreshold) - && Math::NearEqual(OpacityThreshold, other.OpacityThreshold) + && MaskThreshold == other.MaskThreshold + && OpacityThreshold == other.OpacityThreshold && TessellationMode == other.TessellationMode && MaxTessellationFactor == other.MaxTessellationFactor; } @@ -123,8 +123,8 @@ bool MaterialInfo::operator==(const MaterialInfo& other) const && TransparentLightingMode == other.TransparentLightingMode && PostFxLocation == other.PostFxLocation && CullMode == other.CullMode - && Math::NearEqual(MaskThreshold, other.MaskThreshold) - && Math::NearEqual(OpacityThreshold, other.OpacityThreshold) + && MaskThreshold == other.MaskThreshold + && OpacityThreshold == other.OpacityThreshold && TessellationMode == other.TessellationMode && MaxTessellationFactor == other.MaxTessellationFactor; } diff --git a/Source/Engine/Graphics/Textures/GPUSamplerDescription.cs b/Source/Engine/Graphics/Textures/GPUSamplerDescription.cs index 6a49ce49d..425f28fe6 100644 --- a/Source/Engine/Graphics/Textures/GPUSamplerDescription.cs +++ b/Source/Engine/Graphics/Textures/GPUSamplerDescription.cs @@ -40,9 +40,9 @@ namespace FlaxEngine AddressU == other.AddressU && AddressV == other.AddressV && AddressW == other.AddressW && - Mathf.NearEqual(MipBias, other.MipBias) && - Mathf.NearEqual(MinMipLevel, other.MinMipLevel) && - Mathf.NearEqual(MaxMipLevel, other.MaxMipLevel) && + MipBias == other.MipBias && + MinMipLevel == other.MinMipLevel && + MaxMipLevel == other.MaxMipLevel && MaxAnisotropy == other.MaxAnisotropy && BorderColor == other.BorderColor && ComparisonFunction == other.ComparisonFunction; diff --git a/Source/Engine/Navigation/Navigation.cpp b/Source/Engine/Navigation/Navigation.cpp index 446464634..570db86c7 100644 --- a/Source/Engine/Navigation/Navigation.cpp +++ b/Source/Engine/Navigation/Navigation.cpp @@ -107,7 +107,7 @@ Color NavMeshRuntime::NavAreasColors[64]; bool NavAgentProperties::operator==(const NavAgentProperties& other) const { - return Math::NearEqual(Radius, other.Radius) && Math::NearEqual(Height, other.Height) && Math::NearEqual(StepHeight, other.StepHeight) && Math::NearEqual(MaxSlopeAngle, other.MaxSlopeAngle) && Math::NearEqual(MaxSpeed, other.MaxSpeed) && Math::NearEqual(CrowdSeparationWeight, other.CrowdSeparationWeight); + return Radius == other.Radius && Height == other.Height && StepHeight == other.StepHeight && MaxSlopeAngle == other.MaxSlopeAngle && MaxSpeed == other.MaxSpeed && CrowdSeparationWeight == other.CrowdSeparationWeight; } bool NavAgentMask::IsAgentSupported(int32 agentIndex) const @@ -148,12 +148,12 @@ bool NavAgentMask::operator==(const NavAgentMask& other) const bool NavAreaProperties::operator==(const NavAreaProperties& other) const { - return Name == other.Name && Id == other.Id && Math::NearEqual(Cost, other.Cost); + return Name == other.Name && Id == other.Id && Cost == other.Cost; } bool NavMeshProperties::operator==(const NavMeshProperties& other) const { - return Name == other.Name && Quaternion::NearEqual(Rotation, other.Rotation, 0.001f) && Agent == other.Agent && Vector3::NearEqual(DefaultQueryExtent, other.DefaultQueryExtent); + return Name == other.Name && Rotation == other.Rotation && Agent == other.Agent && DefaultQueryExtent == other.DefaultQueryExtent; } class NavigationService : public EngineService diff --git a/Source/Engine/Physics/Joints/HingeJoint.h b/Source/Engine/Physics/Joints/HingeJoint.h index 82a42edef..e3fdbe719 100644 --- a/Source/Engine/Physics/Joints/HingeJoint.h +++ b/Source/Engine/Physics/Joints/HingeJoint.h @@ -59,7 +59,7 @@ API_STRUCT() struct HingeJointDrive public: bool operator==(const HingeJointDrive& other) const { - return Math::NearEqual(Velocity, other.Velocity) && Math::NearEqual(ForceLimit, other.ForceLimit) && Math::NearEqual(GearRatio, other.GearRatio) && FreeSpin == other.FreeSpin; + return Velocity == other.Velocity && ForceLimit == other.ForceLimit && GearRatio == other.GearRatio && FreeSpin == other.FreeSpin; } }; diff --git a/Source/Engine/Render2D/TextLayoutOptions.h b/Source/Engine/Render2D/TextLayoutOptions.h index 75e3b1ea2..5aa84fe5a 100644 --- a/Source/Engine/Render2D/TextLayoutOptions.h +++ b/Source/Engine/Render2D/TextLayoutOptions.h @@ -108,8 +108,8 @@ DECLARE_SCRIPTING_TYPE_MINIMAL(TextLayoutOptions); && HorizontalAlignment == other.HorizontalAlignment && VerticalAlignment == other.VerticalAlignment && TextWrapping == other.TextWrapping - && Math::NearEqual(Scale, other.Scale) - && Math::NearEqual(BaseLinesGapScale, other.BaseLinesGapScale); + && Scale == other.Scale + && BaseLinesGapScale == other.BaseLinesGapScale; } FORCE_INLINE bool operator!=(const TextLayoutOptions& other) const diff --git a/Source/Engine/UI/GUI/Margin.cs b/Source/Engine/UI/GUI/Margin.cs index c19d06f09..f04e13b0a 100644 --- a/Source/Engine/UI/GUI/Margin.cs +++ b/Source/Engine/UI/GUI/Margin.cs @@ -251,10 +251,10 @@ namespace FlaxEngine.GUI /// true if the specified is equal to this instance; otherwise, false. public bool Equals(ref Margin other) { - return Mathf.NearEqual(other.Left, Left) && - Mathf.NearEqual(other.Right, Right) && - Mathf.NearEqual(other.Top, Top) && - Mathf.NearEqual(other.Bottom, Bottom); + return other.Left == Left && + other.Right == Right && + other.Top == Top && + other.Bottom == Bottom; } /// From f09fd7ad34dc7c7d5429468d7395d56d8f9ba8ae Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Fri, 18 Apr 2025 18:45:48 +0300 Subject: [PATCH 02/16] Use exact value comparison in caching related functions (cherry picked from commit 9d7c6b26422e127719836944d8d473910190e7d4) --- Source/Editor/Content/GUI/ContentView.cs | 2 +- .../Editor/CustomEditors/GUI/PropertiesList.cs | 2 +- Source/Editor/GUI/CurveEditor.cs | 2 +- Source/Editor/GUI/Input/DoubleValueBox.cs | 4 ++-- Source/Editor/GUI/Input/FloatValueBox.cs | 4 ++-- Source/Editor/GUI/Input/SliderControl.cs | 6 +++--- Source/Editor/GUI/Table.cs | 2 +- .../Editor/GUI/Timeline/GUI/KeyframesEditor.cs | 2 +- Source/Editor/GUI/Timeline/Timeline.cs | 4 ++-- Source/Editor/GUI/Timeline/Tracks/AudioTrack.cs | 2 +- Source/Editor/GUI/Tree/TreeNode.cs | 2 +- Source/Editor/Tools/Foliage/FoliageTypesTab.cs | 6 +++--- .../Viewport/Previews/CubeTexturePreview.cs | 2 +- .../Viewport/Previews/ParticleEmitterPreview.cs | 2 +- .../Editor/Viewport/Previews/TexturePreview.cs | 2 +- Source/Engine/Audio/Audio.cpp | 2 +- Source/Engine/Audio/AudioSource.cpp | 14 +++++++------- .../Engine/ContentImporters/CreateMaterial.cpp | 2 +- Source/Engine/Foliage/Foliage.cpp | 2 +- Source/Engine/Input/Input.cpp | 2 +- Source/Engine/Level/Actor.cpp | 16 ++++++++-------- Source/Engine/Level/Actors/BoxBrush.cpp | 4 ++-- Source/Engine/Level/Actors/BoxVolume.cpp | 2 +- Source/Engine/Level/Actors/Camera.cpp | 12 ++++++------ Source/Engine/Level/Actors/EnvironmentProbe.cpp | 2 +- Source/Engine/Level/Actors/PointLight.cpp | 2 +- Source/Engine/Level/Actors/SkyLight.cpp | 2 +- Source/Engine/Level/Actors/SplineModel.cpp | 4 ++-- Source/Engine/Level/Actors/SpotLight.cpp | 6 +++--- Source/Engine/Level/Actors/StaticModel.cpp | 2 +- Source/Engine/Navigation/NavMeshRuntime.cpp | 2 +- Source/Engine/Physics/Actors/RigidBody.cpp | 14 +++++++------- Source/Engine/Physics/Colliders/BoxCollider.cpp | 2 +- .../Engine/Physics/Colliders/CapsuleCollider.cpp | 4 ++-- .../Physics/Colliders/CharacterController.cpp | 10 +++++----- Source/Engine/Physics/Colliders/Collider.cpp | 6 +++--- .../Engine/Physics/Colliders/SphereCollider.cpp | 2 +- Source/Engine/Physics/Joints/DistanceJoint.cpp | 6 +++--- Source/Engine/Physics/Joints/Joint.cpp | 6 +++--- Source/Engine/Renderer/ShadowsPass.cpp | 12 ++++++------ Source/Engine/Terrain/Terrain.cpp | 4 ++-- Source/Engine/UI/GUI/CanvasScaler.cs | 8 ++++---- Source/Engine/UI/GUI/Common/ProgressBar.cs | 2 +- Source/Engine/UI/GUI/Common/Slider.cs | 2 +- Source/Engine/UI/GUI/Control.Bounds.cs | 9 ++++----- Source/Engine/UI/GUI/Panels/DropPanel.cs | 2 +- Source/Engine/UI/GUI/Panels/Panel.cs | 2 +- Source/Engine/UI/GUI/Panels/PanelWithMargins.cs | 12 ++++++------ Source/Engine/UI/GUI/Panels/ScrollBar.cs | 6 +++--- Source/Engine/UI/GUI/Panels/SplitPanel.cs | 2 +- Source/Engine/Video/VideoPlayer.cpp | 8 ++++---- 51 files changed, 119 insertions(+), 120 deletions(-) diff --git a/Source/Editor/Content/GUI/ContentView.cs b/Source/Editor/Content/GUI/ContentView.cs index b56672f44..4928722b6 100644 --- a/Source/Editor/Content/GUI/ContentView.cs +++ b/Source/Editor/Content/GUI/ContentView.cs @@ -145,7 +145,7 @@ namespace FlaxEditor.Content.GUI set { value = Mathf.Clamp(value, 0.3f, 3.0f); - if (!Mathf.NearEqual(value, _viewScale)) + if (value != _viewScale) { _viewScale = value; ViewScaleChanged?.Invoke(); diff --git a/Source/Editor/CustomEditors/GUI/PropertiesList.cs b/Source/Editor/CustomEditors/GUI/PropertiesList.cs index 02efbb2a3..624f3d798 100644 --- a/Source/Editor/CustomEditors/GUI/PropertiesList.cs +++ b/Source/Editor/CustomEditors/GUI/PropertiesList.cs @@ -45,7 +45,7 @@ namespace FlaxEditor.CustomEditors.GUI set { value = Mathf.Clamp(value, 0.05f, 0.95f); - if (!Mathf.NearEqual(_splitterValue, value)) + if (_splitterValue != value) { _splitterValue = value; UpdateSplitRect(); diff --git a/Source/Editor/GUI/CurveEditor.cs b/Source/Editor/GUI/CurveEditor.cs index 706d07b32..de83151ab 100644 --- a/Source/Editor/GUI/CurveEditor.cs +++ b/Source/Editor/GUI/CurveEditor.cs @@ -385,7 +385,7 @@ namespace FlaxEditor.GUI get => _fps; set { - if (_fps.HasValue == value.HasValue && (!value.HasValue || Mathf.NearEqual(_fps.Value, value.Value))) + if (_fps.HasValue == value.HasValue && (!value.HasValue || _fps.Value == value.Value)) return; _fps = value; diff --git a/Source/Editor/GUI/Input/DoubleValueBox.cs b/Source/Editor/GUI/Input/DoubleValueBox.cs index 7399f4621..a50fa86cc 100644 --- a/Source/Editor/GUI/Input/DoubleValueBox.cs +++ b/Source/Editor/GUI/Input/DoubleValueBox.cs @@ -41,7 +41,7 @@ namespace FlaxEditor.GUI.Input get => _min; set { - if (!Mathd.NearEqual(_min, value)) + if (_min != value) { if (value > _max) throw new ArgumentException(); @@ -58,7 +58,7 @@ namespace FlaxEditor.GUI.Input get => _max; set { - if (!Mathd.NearEqual(_max, value)) + if (_max != value) { if (value < _min) throw new ArgumentException(); diff --git a/Source/Editor/GUI/Input/FloatValueBox.cs b/Source/Editor/GUI/Input/FloatValueBox.cs index 46e9e6502..d49f277d3 100644 --- a/Source/Editor/GUI/Input/FloatValueBox.cs +++ b/Source/Editor/GUI/Input/FloatValueBox.cs @@ -38,7 +38,7 @@ namespace FlaxEditor.GUI.Input get => _min; set { - if (!Mathf.NearEqual(_min, value)) + if (_min != value) { if (value > _max) throw new ArgumentException(); @@ -54,7 +54,7 @@ namespace FlaxEditor.GUI.Input get => _max; set { - if (!Mathf.NearEqual(_max, value)) + if (_max != value) { if (value < _min) throw new ArgumentException(); diff --git a/Source/Editor/GUI/Input/SliderControl.cs b/Source/Editor/GUI/Input/SliderControl.cs index bc2523ae5..8e3efe956 100644 --- a/Source/Editor/GUI/Input/SliderControl.cs +++ b/Source/Editor/GUI/Input/SliderControl.cs @@ -54,7 +54,7 @@ namespace FlaxEditor.GUI.Input set { value = Mathf.Clamp(value, Minimum, Maximum); - if (!Mathf.NearEqual(value, _value)) + if (value != _value) { _value = value; @@ -311,7 +311,7 @@ namespace FlaxEditor.GUI.Input get => _min; set { - if (!Mathf.NearEqual(_min, value)) + if (_min != value) { if (value > _max) throw new ArgumentException(); @@ -330,7 +330,7 @@ namespace FlaxEditor.GUI.Input get => _max; set { - if (!Mathf.NearEqual(_max, value)) + if (_max != value) { if (value < _min) throw new ArgumentException(); diff --git a/Source/Editor/GUI/Table.cs b/Source/Editor/GUI/Table.cs index 71b01aa0f..3e2de92c5 100644 --- a/Source/Editor/GUI/Table.cs +++ b/Source/Editor/GUI/Table.cs @@ -28,7 +28,7 @@ namespace FlaxEditor.GUI set { value = Mathf.Max(value, 1); - if (!Mathf.NearEqual(value, _headerHeight)) + if (value != _headerHeight) { _headerHeight = value; PerformLayout(); diff --git a/Source/Editor/GUI/Timeline/GUI/KeyframesEditor.cs b/Source/Editor/GUI/Timeline/GUI/KeyframesEditor.cs index d6fa0e076..f02936b8f 100644 --- a/Source/Editor/GUI/Timeline/GUI/KeyframesEditor.cs +++ b/Source/Editor/GUI/Timeline/GUI/KeyframesEditor.cs @@ -692,7 +692,7 @@ namespace FlaxEditor.GUI get => _fps; set { - if (_fps.HasValue == value.HasValue && (!value.HasValue || Mathf.NearEqual(_fps.Value, value.Value))) + if (_fps.HasValue == value.HasValue && (!value.HasValue || _fps.Value == value.Value)) return; _fps = value; diff --git a/Source/Editor/GUI/Timeline/Timeline.cs b/Source/Editor/GUI/Timeline/Timeline.cs index 15e7eb953..fb6e4cf07 100644 --- a/Source/Editor/GUI/Timeline/Timeline.cs +++ b/Source/Editor/GUI/Timeline/Timeline.cs @@ -319,7 +319,7 @@ namespace FlaxEditor.GUI.Timeline set { value = Mathf.Clamp(value, 0.1f, 1000.0f); - if (Mathf.NearEqual(_framesPerSecond, value)) + if (_framesPerSecond == value) return; Undo?.AddAction(new EditFpsAction(this, _framesPerSecond, value)); @@ -508,7 +508,7 @@ namespace FlaxEditor.GUI.Timeline set { value = Mathf.Clamp(value, 0.00001f, 1000.0f); - if (Mathf.NearEqual(_zoom, value)) + if (_zoom == value) return; _zoom = value; diff --git a/Source/Editor/GUI/Timeline/Tracks/AudioTrack.cs b/Source/Editor/GUI/Timeline/Tracks/AudioTrack.cs index 75c5788a7..b17c18b8c 100644 --- a/Source/Editor/GUI/Timeline/Tracks/AudioTrack.cs +++ b/Source/Editor/GUI/Timeline/Tracks/AudioTrack.cs @@ -41,7 +41,7 @@ namespace FlaxEditor.GUI.Timeline.Tracks get => Preview.ViewOffset; set { - if (Mathf.NearEqual(Preview.ViewOffset, value)) + if (Preview.ViewOffset == value) return; Preview.ViewOffset = value; Timeline?.MarkAsEdited(); diff --git a/Source/Editor/GUI/Tree/TreeNode.cs b/Source/Editor/GUI/Tree/TreeNode.cs index eb7f345cf..0894ac2e5 100644 --- a/Source/Editor/GUI/Tree/TreeNode.cs +++ b/Source/Editor/GUI/Tree/TreeNode.cs @@ -214,7 +214,7 @@ namespace FlaxEditor.GUI.Tree get => _headerHeight; set { - if (!Mathf.NearEqual(_headerHeight, value)) + if (_headerHeight != value) { _headerHeight = value; PerformLayout(); diff --git a/Source/Editor/Tools/Foliage/FoliageTypesTab.cs b/Source/Editor/Tools/Foliage/FoliageTypesTab.cs index 3094d2a77..0d3b1ec95 100644 --- a/Source/Editor/Tools/Foliage/FoliageTypesTab.cs +++ b/Source/Editor/Tools/Foliage/FoliageTypesTab.cs @@ -107,7 +107,7 @@ namespace FlaxEditor.Tools.Foliage get => _type.CullDistance; set { - if (Mathf.NearEqual(_type.CullDistance, value)) + if (_type.CullDistance == value) return; _type.CullDistance = value; Foliage.UpdateCullDistance(); @@ -120,7 +120,7 @@ namespace FlaxEditor.Tools.Foliage get => _type.CullDistanceRandomRange; set { - if (Mathf.NearEqual(_type.CullDistanceRandomRange, value)) + if (_type.CullDistanceRandomRange == value) return; _type.CullDistanceRandomRange = value; Foliage.UpdateCullDistance(); @@ -174,7 +174,7 @@ namespace FlaxEditor.Tools.Foliage get => _type.DensityScalingScale; set { - if (Mathf.NearEqual(_type.DensityScalingScale, value)) + if (_type.DensityScalingScale == value) return; _type.DensityScalingScale = value; Foliage.RebuildClusters(); diff --git a/Source/Editor/Viewport/Previews/CubeTexturePreview.cs b/Source/Editor/Viewport/Previews/CubeTexturePreview.cs index f0b05c8e6..9c7c9e6e9 100644 --- a/Source/Editor/Viewport/Previews/CubeTexturePreview.cs +++ b/Source/Editor/Viewport/Previews/CubeTexturePreview.cs @@ -95,7 +95,7 @@ namespace FlaxEditor.Viewport.Previews get => _mipLevel; set { - if (!Mathf.NearEqual(_mipLevel, value)) + if (_mipLevel == value) { _mipLevel = value; _previewMaterial.SetParameterValue("Mip", value); diff --git a/Source/Editor/Viewport/Previews/ParticleEmitterPreview.cs b/Source/Editor/Viewport/Previews/ParticleEmitterPreview.cs index 023bd121f..cb05016b9 100644 --- a/Source/Editor/Viewport/Previews/ParticleEmitterPreview.cs +++ b/Source/Editor/Viewport/Previews/ParticleEmitterPreview.cs @@ -42,7 +42,7 @@ namespace FlaxEditor.Viewport.Previews set { value = Mathf.Clamp(value, 0.1f, 100000000000.0f); - if (Mathf.NearEqual(_playbackDuration, value)) + if (_playbackDuration == value) return; _playbackDuration = value; diff --git a/Source/Editor/Viewport/Previews/TexturePreview.cs b/Source/Editor/Viewport/Previews/TexturePreview.cs index 709bc953e..b8f801035 100644 --- a/Source/Editor/Viewport/Previews/TexturePreview.cs +++ b/Source/Editor/Viewport/Previews/TexturePreview.cs @@ -303,7 +303,7 @@ namespace FlaxEditor.Viewport.Previews get => _mipLevel; set { - if (!Mathf.NearEqual(_mipLevel, value)) + if (_mipLevel != value) { _mipLevel = value; _previewMaterial.SetParameterValue("Mip", value); diff --git a/Source/Engine/Audio/Audio.cpp b/Source/Engine/Audio/Audio.cpp index e19efabf1..2a2d30d5c 100644 --- a/Source/Engine/Audio/Audio.cpp +++ b/Source/Engine/Audio/Audio.cpp @@ -219,7 +219,7 @@ void AudioService::Update() // Mute audio if app has no user focus masterVolume = 0.0f; } - if (Math::NotNearEqual(Volume, masterVolume)) + if (Volume != masterVolume) { Volume = masterVolume; AudioBackend::SetVolume(masterVolume); diff --git a/Source/Engine/Audio/AudioSource.cpp b/Source/Engine/Audio/AudioSource.cpp index cff89e7e1..ab17910fd 100644 --- a/Source/Engine/Audio/AudioSource.cpp +++ b/Source/Engine/Audio/AudioSource.cpp @@ -29,7 +29,7 @@ AudioSource::AudioSource(const SpawnParams& params) void AudioSource::SetVolume(float value) { value = Math::Saturate(value); - if (Math::NearEqual(_volume, value)) + if (_volume == value) return; _volume = value; if (SourceID) @@ -39,7 +39,7 @@ void AudioSource::SetVolume(float value) void AudioSource::SetPitch(float value) { value = Math::Clamp(value, 0.5f, 2.0f); - if (Math::NearEqual(_pitch, value)) + if (_pitch == value) return; _pitch = value; if (SourceID) @@ -49,7 +49,7 @@ void AudioSource::SetPitch(float value) void AudioSource::SetPan(float value) { value = Math::Clamp(value, -1.0f, 1.0f); - if (Math::NearEqual(_pan, value)) + if (_pan == value) return; _pan = value; if (SourceID) @@ -80,7 +80,7 @@ void AudioSource::SetStartTime(float value) void AudioSource::SetMinDistance(float value) { value = Math::Max(0.0f, value); - if (Math::NearEqual(_minDistance, value)) + if (_minDistance == value) return; _minDistance = value; if (SourceID) @@ -90,7 +90,7 @@ void AudioSource::SetMinDistance(float value) void AudioSource::SetAttenuation(float value) { value = Math::Max(0.0f, value); - if (Math::NearEqual(_attenuation, value)) + if (_attenuation == value) return; _attenuation = value; if (SourceID) @@ -100,7 +100,7 @@ void AudioSource::SetAttenuation(float value) void AudioSource::SetDopplerFactor(float value) { value = Math::Max(0.0f, value); - if (Math::NearEqual(_dopplerFactor, value)) + if (_dopplerFactor == value) return; _dopplerFactor = value; if (SourceID) @@ -401,7 +401,7 @@ void AudioSource::Update() _startingToPlay = false; } - if (!UseStreaming() && Math::NearEqual(GetTime(), 0.0f) && _isActuallyPlayingSth && !_startingToPlay) + if (!UseStreaming() && GetTime() == 0.0f && _isActuallyPlayingSth && !_startingToPlay) { int32 queuedBuffers; AudioBackend::Source::GetQueuedBuffersCount(SourceID, queuedBuffers); diff --git a/Source/Engine/ContentImporters/CreateMaterial.cpp b/Source/Engine/ContentImporters/CreateMaterial.cpp index 3991585a3..4cedf0c85 100644 --- a/Source/Engine/ContentImporters/CreateMaterial.cpp +++ b/Source/Engine/ContentImporters/CreateMaterial.cpp @@ -20,7 +20,7 @@ namespace template ShaderGraphNode<>* AddValueNode(MaterialLayer* layer, const float& value, const float& defaultValue) { - if (Math::NearEqual(value, defaultValue)) + if (value == defaultValue) return nullptr; auto& node = layer->Graph.Nodes.AddOne(); node.ID = layer->Graph.Nodes.Count(); diff --git a/Source/Engine/Foliage/Foliage.cpp b/Source/Engine/Foliage/Foliage.cpp index a1cd046ae..051450297 100644 --- a/Source/Engine/Foliage/Foliage.cpp +++ b/Source/Engine/Foliage/Foliage.cpp @@ -1013,7 +1013,7 @@ bool UpdateFoliageDensityScaling(Actor* actor) void Foliage::SetGlobalDensityScale(float value) { value = Math::Saturate(value); - if (Math::NearEqual(value, GlobalDensityScale)) + if (value == GlobalDensityScale) return; PROFILE_CPU(); diff --git a/Source/Engine/Input/Input.cpp b/Source/Engine/Input/Input.cpp index 7a4d0592c..f3f8b2883 100644 --- a/Source/Engine/Input/Input.cpp +++ b/Source/Engine/Input/Input.cpp @@ -1216,7 +1216,7 @@ void InputService::Update() { for (auto i = Axes.Begin(); i.IsNotEnd(); ++i) { - if (Math::NotNearEqual(i->Value.Value, i->Value.PrevValue)) + if (i->Value.Value != i->Value.PrevValue) { Input::AxisValueChanged(i->Key); } diff --git a/Source/Engine/Level/Actor.cpp b/Source/Engine/Level/Actor.cpp index 4989f2c49..b96db3925 100644 --- a/Source/Engine/Level/Actor.cpp +++ b/Source/Engine/Level/Actor.cpp @@ -660,7 +660,7 @@ void Actor::SetStaticFlags(StaticFlags value) void Actor::SetTransform(const Transform& value) { CHECK(!value.IsNanOrInfinity()); - if (!(Vector3::NearEqual(_transform.Translation, value.Translation) && Quaternion::NearEqual(_transform.Orientation, value.Orientation, ACTOR_ORIENTATION_EPSILON) && Float3::NearEqual(_transform.Scale, value.Scale))) + if (_transform.Translation != value.Translation && _transform.Orientation != value.Orientation && _transform.Scale != value.Scale) { if (_parent) _parent->_transform.WorldToLocal(value, _localTransform); @@ -673,7 +673,7 @@ void Actor::SetTransform(const Transform& value) void Actor::SetPosition(const Vector3& value) { CHECK(!value.IsNanOrInfinity()); - if (!Vector3::NearEqual(_transform.Translation, value)) + if (_transform.Translation != value) { if (_parent) _localTransform.Translation = _parent->_transform.WorldToLocal(value); @@ -686,7 +686,7 @@ void Actor::SetPosition(const Vector3& value) void Actor::SetOrientation(const Quaternion& value) { CHECK(!value.IsNanOrInfinity()); - if (!Quaternion::NearEqual(_transform.Orientation, value, ACTOR_ORIENTATION_EPSILON)) + if (_transform.Orientation != value) { if (_parent) _parent->_transform.WorldToLocal(value, _localTransform.Orientation); @@ -699,7 +699,7 @@ void Actor::SetOrientation(const Quaternion& value) void Actor::SetScale(const Float3& value) { CHECK(!value.IsNanOrInfinity()); - if (!Float3::NearEqual(_transform.Scale, value)) + if (_transform.Scale != value) { if (_parent) Float3::Divide(value, _parent->_transform.Scale, _localTransform.Scale); @@ -748,7 +748,7 @@ void Actor::ResetLocalTransform() void Actor::SetLocalTransform(const Transform& value) { CHECK(!value.IsNanOrInfinity()); - if (!(Vector3::NearEqual(_localTransform.Translation, value.Translation) && Quaternion::NearEqual(_localTransform.Orientation, value.Orientation, ACTOR_ORIENTATION_EPSILON) && Float3::NearEqual(_localTransform.Scale, value.Scale))) + if (_localTransform.Translation != value.Translation || _localTransform.Orientation != value.Orientation || _localTransform.Scale != value.Scale) { _localTransform = value; OnTransformChanged(); @@ -758,7 +758,7 @@ void Actor::SetLocalTransform(const Transform& value) void Actor::SetLocalPosition(const Vector3& value) { CHECK(!value.IsNanOrInfinity()); - if (!Vector3::NearEqual(_localTransform.Translation, value)) + if (_localTransform.Translation != value) { _localTransform.Translation = value; OnTransformChanged(); @@ -770,7 +770,7 @@ void Actor::SetLocalOrientation(const Quaternion& value) CHECK(!value.IsNanOrInfinity()); Quaternion v = value; v.Normalize(); - if (!Quaternion::NearEqual(_localTransform.Orientation, v, ACTOR_ORIENTATION_EPSILON)) + if (_localTransform.Orientation != value) { _localTransform.Orientation = v; OnTransformChanged(); @@ -780,7 +780,7 @@ void Actor::SetLocalOrientation(const Quaternion& value) void Actor::SetLocalScale(const Float3& value) { CHECK(!value.IsNanOrInfinity()); - if (!Float3::NearEqual(_localTransform.Scale, value)) + if (_localTransform.Scale != value) { _localTransform.Scale = value; OnTransformChanged(); diff --git a/Source/Engine/Level/Actors/BoxBrush.cpp b/Source/Engine/Level/Actors/BoxBrush.cpp index 64f4d208a..06bc047bc 100644 --- a/Source/Engine/Level/Actors/BoxBrush.cpp +++ b/Source/Engine/Level/Actors/BoxBrush.cpp @@ -65,7 +65,7 @@ void BoxBrush::SetMode(BrushMode value) void BoxBrush::SetCenter(const Vector3& value) { - if (Vector3::NearEqual(value, _center)) + if (value == _center) return; _center = value; @@ -77,7 +77,7 @@ void BoxBrush::SetCenter(const Vector3& value) void BoxBrush::SetSize(const Vector3& value) { - if (Vector3::NearEqual(value, _size)) + if (value == _size) return; _size = value; diff --git a/Source/Engine/Level/Actors/BoxVolume.cpp b/Source/Engine/Level/Actors/BoxVolume.cpp index bbce7db28..505f18dd5 100644 --- a/Source/Engine/Level/Actors/BoxVolume.cpp +++ b/Source/Engine/Level/Actors/BoxVolume.cpp @@ -12,7 +12,7 @@ BoxVolume::BoxVolume(const SpawnParams& params) void BoxVolume::SetSize(const Vector3& value) { - if (!Vector3::NearEqual(value, _size)) + if (value != _size) { const auto prevBounds = _box; _size = value; diff --git a/Source/Engine/Level/Actors/Camera.cpp b/Source/Engine/Level/Actors/Camera.cpp index 9851b21b0..4b78e8edc 100644 --- a/Source/Engine/Level/Actors/Camera.cpp +++ b/Source/Engine/Level/Actors/Camera.cpp @@ -70,7 +70,7 @@ float Camera::GetFieldOfView() const void Camera::SetFieldOfView(float value) { value = Math::Clamp(value, 1.0f, 179.9f); - if (Math::NotNearEqual(_fov, value)) + if (_fov != value) { _fov = value; UpdateCache(); @@ -85,7 +85,7 @@ float Camera::GetCustomAspectRatio() const void Camera::SetCustomAspectRatio(float value) { value = Math::Clamp(value, 0.0f, 100.0f); - if (Math::NotNearEqual(_customAspectRatio, value)) + if (_customAspectRatio != value) { _customAspectRatio = value; UpdateCache(); @@ -100,7 +100,7 @@ float Camera::GetNearPlane() const void Camera::SetNearPlane(float value) { value = Math::Clamp(value, 0.001f, _far - 1.0f); - if (Math::NotNearEqual(_near, value)) + if (_near != value) { _near = value; UpdateCache(); @@ -115,7 +115,7 @@ float Camera::GetFarPlane() const void Camera::SetFarPlane(float value) { value = Math::Max(value, _near + 1.0f); - if (Math::NotNearEqual(_far, value)) + if (_far != value) { _far = value; UpdateCache(); @@ -130,7 +130,7 @@ float Camera::GetOrthographicSize() const void Camera::SetOrthographicSize(float value) { value = Math::Clamp(value, 0.0f, 1000000.0f); - if (Math::NotNearEqual(_orthoSize, value)) + if (_orthoSize != value) { _orthoSize = value; UpdateCache(); @@ -145,7 +145,7 @@ float Camera::GetOrthographicScale() const void Camera::SetOrthographicScale(float value) { value = Math::Clamp(value, 0.0001f, 1000000.0f); - if (Math::NotNearEqual(_orthoScale, value)) + if (_orthoScale != value) { _orthoScale = value; UpdateCache(); diff --git a/Source/Engine/Level/Actors/EnvironmentProbe.cpp b/Source/Engine/Level/Actors/EnvironmentProbe.cpp index 9e6827ff7..3c49611d4 100644 --- a/Source/Engine/Level/Actors/EnvironmentProbe.cpp +++ b/Source/Engine/Level/Actors/EnvironmentProbe.cpp @@ -41,7 +41,7 @@ float EnvironmentProbe::GetRadius() const void EnvironmentProbe::SetRadius(float value) { value = Math::Max(0.0f, value); - if (Math::NearEqual(value, _radius)) + if (value == _radius) return; _radius = value; diff --git a/Source/Engine/Level/Actors/PointLight.cpp b/Source/Engine/Level/Actors/PointLight.cpp index 94f1e77c6..607bf1bc4 100644 --- a/Source/Engine/Level/Actors/PointLight.cpp +++ b/Source/Engine/Level/Actors/PointLight.cpp @@ -49,7 +49,7 @@ float PointLight::GetScaledRadius() const void PointLight::SetRadius(float value) { value = Math::Max(0.0f, value); - if (Math::NearEqual(value, _radius)) + if (value == _radius) return; _radius = value; diff --git a/Source/Engine/Level/Actors/SkyLight.cpp b/Source/Engine/Level/Actors/SkyLight.cpp index 498d28663..4e1c0e58c 100644 --- a/Source/Engine/Level/Actors/SkyLight.cpp +++ b/Source/Engine/Level/Actors/SkyLight.cpp @@ -26,7 +26,7 @@ SkyLight::SkyLight(const SpawnParams& params) void SkyLight::SetRadius(float value) { value = Math::Max(0.0f, value); - if (Math::NearEqual(value, _radius)) + if (value == _radius) return; _radius = value; diff --git a/Source/Engine/Level/Actors/SplineModel.cpp b/Source/Engine/Level/Actors/SplineModel.cpp index e4fcff857..8680fb8d5 100644 --- a/Source/Engine/Level/Actors/SplineModel.cpp +++ b/Source/Engine/Level/Actors/SplineModel.cpp @@ -59,7 +59,7 @@ float SplineModel::GetQuality() const void SplineModel::SetQuality(float value) { value = Math::Clamp(value, 0.0f, 100.0f); - if (Math::NearEqual(value, _quality)) + if (value == _quality) return; _quality = value; OnSplineUpdated(); @@ -72,7 +72,7 @@ float SplineModel::GetBoundsScale() const void SplineModel::SetBoundsScale(float value) { - if (Math::NearEqual(_boundsScale, value)) + if (_boundsScale == value) return; _boundsScale = value; OnSplineUpdated(); diff --git a/Source/Engine/Level/Actors/SpotLight.cpp b/Source/Engine/Level/Actors/SpotLight.cpp index ca577c41f..85b77647a 100644 --- a/Source/Engine/Level/Actors/SpotLight.cpp +++ b/Source/Engine/Level/Actors/SpotLight.cpp @@ -57,7 +57,7 @@ float SpotLight::GetScaledRadius() const void SpotLight::SetRadius(float value) { value = Math::Max(0.0f, value); - if (Math::NearEqual(value, _radius)) + if (value == _radius) return; _radius = value; @@ -70,7 +70,7 @@ void SpotLight::SetOuterConeAngle(float value) value = Math::Clamp(value, 0.0f, 89.0f); // Check if value will change - if (!Math::NearEqual(value, _outerConeAngle)) + if (value != _outerConeAngle) { // Change values _innerConeAngle = Math::Min(_innerConeAngle, value - ZeroTolerance); @@ -86,7 +86,7 @@ void SpotLight::SetInnerConeAngle(float value) value = Math::Clamp(value, 0.0f, 89.0f); // Check if value will change - if (!Math::NearEqual(value, _innerConeAngle)) + if (value != _innerConeAngle) { // Change values _innerConeAngle = value; diff --git a/Source/Engine/Level/Actors/StaticModel.cpp b/Source/Engine/Level/Actors/StaticModel.cpp index f944da26b..38c1eed90 100644 --- a/Source/Engine/Level/Actors/StaticModel.cpp +++ b/Source/Engine/Level/Actors/StaticModel.cpp @@ -60,7 +60,7 @@ float StaticModel::GetBoundsScale() const void StaticModel::SetBoundsScale(float value) { - if (Math::NearEqual(_boundsScale, value)) + if (_boundsScale == value) return; _boundsScale = value; diff --git a/Source/Engine/Navigation/NavMeshRuntime.cpp b/Source/Engine/Navigation/NavMeshRuntime.cpp index baa8b0320..37e09294d 100644 --- a/Source/Engine/Navigation/NavMeshRuntime.cpp +++ b/Source/Engine/Navigation/NavMeshRuntime.cpp @@ -292,7 +292,7 @@ void NavMeshRuntime::SetTileSize(float tileSize) ScopeLock lock(Locker); // Skip if the same or invalid - if (Math::NearEqual(_tileSize, tileSize) || tileSize < 1) + if (_tileSize == tileSize || tileSize < 1) return; // Dispose the existing mesh (its invalid) diff --git a/Source/Engine/Physics/Actors/RigidBody.cpp b/Source/Engine/Physics/Actors/RigidBody.cpp index 23b32598e..a58911dfb 100644 --- a/Source/Engine/Physics/Actors/RigidBody.cpp +++ b/Source/Engine/Physics/Actors/RigidBody.cpp @@ -44,7 +44,7 @@ void RigidBody::SetIsKinematic(const bool value) void RigidBody::SetLinearDamping(float value) { - if (Math::NearEqual(value, _linearDamping)) + if (value == _linearDamping) return; _linearDamping = value; if (_actor) @@ -53,7 +53,7 @@ void RigidBody::SetLinearDamping(float value) void RigidBody::SetAngularDamping(float value) { - if (Math::NearEqual(value, _angularDamping)) + if (value == _angularDamping) return; _angularDamping = value; if (_actor) @@ -108,7 +108,7 @@ void RigidBody::SetUpdateMassWhenScaleChanges(bool value) void RigidBody::SetMaxAngularVelocity(float value) { - if (Math::NearEqual(value, _maxAngularVelocity)) + if (value == _maxAngularVelocity) return; _maxAngularVelocity = value; if (_actor) @@ -135,7 +135,7 @@ float RigidBody::GetMass() const void RigidBody::SetMass(float value) { - if (Math::NearEqual(value, _mass)) + if (value == _mass) return; _mass = value; _overrideMass = true; @@ -149,7 +149,7 @@ float RigidBody::GetMassScale() const void RigidBody::SetMassScale(float value) { - if (Math::NearEqual(value, _massScale)) + if (value == _massScale) return; _massScale = value; UpdateMass(); @@ -157,7 +157,7 @@ void RigidBody::SetMassScale(float value) void RigidBody::SetCenterOfMassOffset(const Float3& value) { - if (Float3::NearEqual(value, _centerOfMassOffset)) + if (value == _centerOfMassOffset) return; _centerOfMassOffset = value; if (_actor) @@ -380,7 +380,7 @@ void RigidBody::UpdateBounds() void RigidBody::UpdateScale() { const Float3 scale = GetScale(); - if (Float3::NearEqual(_cachedScale, scale)) + if (_cachedScale == scale) return; _cachedScale = scale; diff --git a/Source/Engine/Physics/Colliders/BoxCollider.cpp b/Source/Engine/Physics/Colliders/BoxCollider.cpp index 78e9e4207..0bc6dcc68 100644 --- a/Source/Engine/Physics/Colliders/BoxCollider.cpp +++ b/Source/Engine/Physics/Colliders/BoxCollider.cpp @@ -12,7 +12,7 @@ BoxCollider::BoxCollider(const SpawnParams& params) void BoxCollider::SetSize(const Float3& value) { - if (Float3::NearEqual(value, _size)) + if (value == _size) return; _size = value; diff --git a/Source/Engine/Physics/Colliders/CapsuleCollider.cpp b/Source/Engine/Physics/Colliders/CapsuleCollider.cpp index e85c7075d..78820d0a6 100644 --- a/Source/Engine/Physics/Colliders/CapsuleCollider.cpp +++ b/Source/Engine/Physics/Colliders/CapsuleCollider.cpp @@ -11,7 +11,7 @@ CapsuleCollider::CapsuleCollider(const SpawnParams& params) void CapsuleCollider::SetRadius(const float value) { - if (Math::NearEqual(value, _radius)) + if (value == _radius) return; _radius = value; @@ -22,7 +22,7 @@ void CapsuleCollider::SetRadius(const float value) void CapsuleCollider::SetHeight(const float value) { - if (Math::NearEqual(value, _height)) + if (value == _height) return; _height = value; diff --git a/Source/Engine/Physics/Colliders/CharacterController.cpp b/Source/Engine/Physics/Colliders/CharacterController.cpp index 6bfe1514c..57e0a92a2 100644 --- a/Source/Engine/Physics/Colliders/CharacterController.cpp +++ b/Source/Engine/Physics/Colliders/CharacterController.cpp @@ -33,7 +33,7 @@ float CharacterController::GetRadius() const void CharacterController::SetRadius(const float value) { - if (Math::NearEqual(value, _radius)) + if (value == _radius) return; _radius = value; @@ -49,7 +49,7 @@ float CharacterController::GetHeight() const void CharacterController::SetHeight(const float value) { - if (Math::NearEqual(value, _height)) + if (value == _height) return; _height = value; @@ -66,7 +66,7 @@ float CharacterController::GetSlopeLimit() const void CharacterController::SetSlopeLimit(float value) { value = Math::Clamp(value, 0.0f, 89.0f); - if (Math::NearEqual(value, _slopeLimit)) + if (value == _slopeLimit) return; _slopeLimit = value; if (_controller) @@ -94,7 +94,7 @@ float CharacterController::GetStepOffset() const void CharacterController::SetStepOffset(float value) { - if (Math::NearEqual(value, _stepOffset)) + if (value == _stepOffset) return; _stepOffset = value; @@ -384,7 +384,7 @@ void CharacterController::OnTransformChanged() { PhysicsBackend::SetControllerPosition(_controller, position); const Float3 scale = GetScale(); - if (!Float3::NearEqual(_cachedScale, scale)) + if (_cachedScale != scale) UpdateGeometry(); UpdateBounds(); } diff --git a/Source/Engine/Physics/Colliders/Collider.cpp b/Source/Engine/Physics/Colliders/Collider.cpp index 39ef47686..04fe0a2a8 100644 --- a/Source/Engine/Physics/Colliders/Collider.cpp +++ b/Source/Engine/Physics/Colliders/Collider.cpp @@ -49,7 +49,7 @@ void Collider::SetIsTrigger(bool value) void Collider::SetCenter(const Vector3& value) { - if (Vector3::NearEqual(value, _center)) + if (value == _center) return; _center = value; if (_staticActor) @@ -62,7 +62,7 @@ void Collider::SetCenter(const Vector3& value) void Collider::SetContactOffset(float value) { value = Math::Clamp(value, 0.0f, 100.0f); - if (Math::NearEqual(value, _contactOffset)) + if (value == _contactOffset) return; _contactOffset = value; if (_shape) @@ -428,7 +428,7 @@ void Collider::OnTransformChanged() } const Float3 scale = GetScale(); - if (!Float3::NearEqual(_cachedScale, scale)) + if (_cachedScale != scale) UpdateGeometry(); UpdateBounds(); } diff --git a/Source/Engine/Physics/Colliders/SphereCollider.cpp b/Source/Engine/Physics/Colliders/SphereCollider.cpp index 3c5e78350..897a34a51 100644 --- a/Source/Engine/Physics/Colliders/SphereCollider.cpp +++ b/Source/Engine/Physics/Colliders/SphereCollider.cpp @@ -10,7 +10,7 @@ SphereCollider::SphereCollider(const SpawnParams& params) void SphereCollider::SetRadius(const float value) { - if (Math::NearEqual(value, _radius)) + if (value == _radius) return; _radius = value; diff --git a/Source/Engine/Physics/Joints/DistanceJoint.cpp b/Source/Engine/Physics/Joints/DistanceJoint.cpp index 8bb45ce5b..b17c6b135 100644 --- a/Source/Engine/Physics/Joints/DistanceJoint.cpp +++ b/Source/Engine/Physics/Joints/DistanceJoint.cpp @@ -25,7 +25,7 @@ void DistanceJoint::SetFlags(DistanceJointFlag value) void DistanceJoint::SetMinDistance(float value) { value = Math::Clamp(value, 0.0f, _maxDistance); - if (Math::NearEqual(value, _minDistance)) + if (value == _minDistance) return; _minDistance = value; if (_joint) @@ -35,7 +35,7 @@ void DistanceJoint::SetMinDistance(float value) void DistanceJoint::SetMaxDistance(float value) { value = Math::Max(_minDistance, value); - if (Math::NearEqual(value, _maxDistance)) + if (value == _maxDistance) return; _maxDistance = value; if (_joint) @@ -45,7 +45,7 @@ void DistanceJoint::SetMaxDistance(float value) void DistanceJoint::SetTolerance(float value) { value = Math::Max(0.1f, value); - if (Math::NearEqual(value, _tolerance)) + if (value == _tolerance) return; _tolerance = value; if (_joint) diff --git a/Source/Engine/Physics/Joints/Joint.cpp b/Source/Engine/Physics/Joints/Joint.cpp index e4dceab86..950f2d146 100644 --- a/Source/Engine/Physics/Joints/Joint.cpp +++ b/Source/Engine/Physics/Joints/Joint.cpp @@ -24,7 +24,7 @@ Joint::Joint(const SpawnParams& params) void Joint::SetBreakForce(float value) { - if (Math::NearEqual(value, _breakForce)) + if (value == _breakForce) return; _breakForce = value; if (_joint) @@ -33,7 +33,7 @@ void Joint::SetBreakForce(float value) void Joint::SetBreakTorque(float value) { - if (Math::NearEqual(value, _breakTorque)) + if (value == _breakTorque) return; _breakTorque = value; if (_joint) @@ -61,7 +61,7 @@ void Joint::SetEnableAutoAnchor(bool value) void Joint::SetTargetAnchor(const Vector3& value) { - if (Vector3::NearEqual(value, _targetAnchor)) + if (value == _targetAnchor) return; _targetAnchor = value; if (_joint && !_enableAutoAnchor) diff --git a/Source/Engine/Renderer/ShadowsPass.cpp b/Source/Engine/Renderer/ShadowsPass.cpp index 3937f8554..374b26347 100644 --- a/Source/Engine/Renderer/ShadowsPass.cpp +++ b/Source/Engine/Renderer/ShadowsPass.cpp @@ -236,9 +236,9 @@ struct ShadowAtlasLight { if (!Cache.StaticValid || !Cache.DynamicValid) return; - if (!Math::NearEqual(Cache.Distance, light.ShadowsDistance) || - !Math::NearEqual(Cache.ShadowsUpdateRate, light.ShadowsUpdateRate) || - !Math::NearEqual(Cache.ShadowsUpdateRateAtDistance, light.ShadowsUpdateRateAtDistance) || + if (Cache.Distance != light.ShadowsDistance || + Cache.ShadowsUpdateRate != light.ShadowsUpdateRate || + Cache.ShadowsUpdateRateAtDistance != light.ShadowsUpdateRateAtDistance || Cache.ShadowFrame != light.ShadowFrame || Cache.ShadowsResolution != light.ShadowsResolution || Float3::Dot(Cache.Direction, light.Direction) < SHADOWS_ROTATION_ERROR) @@ -250,7 +250,7 @@ struct ShadowAtlasLight { // Sun if (!Float3::NearEqual(Cache.Position, view.Position, SHADOWS_POSITION_ERROR) || - !Float4::NearEqual(Cache.CascadeSplits, CascadeSplits) || + Cache.CascadeSplits != CascadeSplits || Float3::Dot(Cache.ViewDirection, view.Direction) < SHADOWS_ROTATION_ERROR) { // Invalidate @@ -262,12 +262,12 @@ struct ShadowAtlasLight // Local light const auto& localLight = (const RenderLocalLightData&)light; if (!Float3::NearEqual(Cache.Position, light.Position, SHADOWS_POSITION_ERROR) || - !Math::NearEqual(Cache.Radius, localLight.Radius)) + Cache.Radius != localLight.Radius) { // Invalidate Cache.StaticValid = false; } - if (light.IsSpotLight && !Math::NearEqual(Cache.OuterConeAngle, ((const RenderSpotLightData&)light).OuterConeAngle)) + if (light.IsSpotLight && Cache.OuterConeAngle != ((const RenderSpotLightData&)light).OuterConeAngle) { // Invalidate Cache.StaticValid = false; diff --git a/Source/Engine/Terrain/Terrain.cpp b/Source/Engine/Terrain/Terrain.cpp index b39b7ef2f..d6930c711 100644 --- a/Source/Engine/Terrain/Terrain.cpp +++ b/Source/Engine/Terrain/Terrain.cpp @@ -260,7 +260,7 @@ void Terrain::SetScaleInLightmap(float value) void Terrain::SetBoundsExtent(const Vector3& value) { - if (Vector3::NearEqual(_boundsExtent, value)) + if (_boundsExtent == value) return; _boundsExtent = value; @@ -891,7 +891,7 @@ void Terrain::OnTransformChanged() auto patch = _patches[i]; patch->UpdateTransform(); } - if (!Float3::NearEqual(_cachedScale, _transform.Scale)) + if (_cachedScale != _transform.Scale) { _cachedScale = _transform.Scale; for (int32 i = 0; i < _patches.Count(); i++) diff --git a/Source/Engine/UI/GUI/CanvasScaler.cs b/Source/Engine/UI/GUI/CanvasScaler.cs index 6bd18ea51..463e13237 100644 --- a/Source/Engine/UI/GUI/CanvasScaler.cs +++ b/Source/Engine/UI/GUI/CanvasScaler.cs @@ -132,7 +132,7 @@ namespace FlaxEngine.GUI get => _scaleFactor; set { - if (Mathf.NearEqual(_scaleFactor, value)) + if (_scaleFactor == value) return; _scaleFactor = value; PerformLayout(); @@ -175,7 +175,7 @@ namespace FlaxEngine.GUI get => _physicalUnitSize; set { - if (Mathf.NearEqual(_physicalUnitSize, value)) + if (_physicalUnitSize == value) return; _physicalUnitSize = value; PerformLayout(); @@ -212,7 +212,7 @@ namespace FlaxEngine.GUI set { value = Float2.Max(value, Float2.One); - if (Float2.NearEqual(ref _resolutionMin, ref value)) + if (_resolutionMin == value) return; _resolutionMin = value; PerformLayout(); @@ -231,7 +231,7 @@ namespace FlaxEngine.GUI set { value = Float2.Max(value, Float2.One); - if (Float2.NearEqual(ref _resolutionMax, ref value)) + if (_resolutionMax == value) return; _resolutionMax = value; PerformLayout(); diff --git a/Source/Engine/UI/GUI/Common/ProgressBar.cs b/Source/Engine/UI/GUI/Common/ProgressBar.cs index d569c3f4c..8abb87cc8 100644 --- a/Source/Engine/UI/GUI/Common/ProgressBar.cs +++ b/Source/Engine/UI/GUI/Common/ProgressBar.cs @@ -140,7 +140,7 @@ namespace FlaxEngine.GUI set { value = Mathf.Clamp(value, _minimum, _maximum); - if (!Mathf.NearEqual(value, _value)) + if (value != _value) { _value = value; if (!UseSmoothing || _firstUpdate) diff --git a/Source/Engine/UI/GUI/Common/Slider.cs b/Source/Engine/UI/GUI/Common/Slider.cs index c1e7cd9f6..8bf6f867a 100644 --- a/Source/Engine/UI/GUI/Common/Slider.cs +++ b/Source/Engine/UI/GUI/Common/Slider.cs @@ -114,7 +114,7 @@ public class Slider : ContainerControl value = Mathf.Clamp(value, Minimum, Maximum); if (WholeNumbers) value = Mathf.RoundToInt(value); - if (!Mathf.NearEqual(value, _value)) + if (value != _value) { _value = value; diff --git a/Source/Engine/UI/GUI/Control.Bounds.cs b/Source/Engine/UI/GUI/Control.Bounds.cs index 62bffd6f7..2b517a9f0 100644 --- a/Source/Engine/UI/GUI/Control.Bounds.cs +++ b/Source/Engine/UI/GUI/Control.Bounds.cs @@ -189,7 +189,7 @@ namespace FlaxEngine.GUI get => _bounds.Size.X; set { - if (Mathf.NearEqual(_bounds.Size.X, value)) + if (_bounds.Size.X == value) return; var bounds = new Rectangle(_bounds.Location, value, _bounds.Size.Y); if (_pivotRelativeSizing) @@ -210,7 +210,7 @@ namespace FlaxEngine.GUI get => _bounds.Size.Y; set { - if (Mathf.NearEqual(_bounds.Size.Y, value)) + if (_bounds.Size.Y == value) return; var bounds = new Rectangle(_bounds.Location, _bounds.Size.X, value); if (_pivotRelativeSizing) @@ -412,7 +412,7 @@ namespace FlaxEngine.GUI get => _rotation; set { - if (!Mathf.NearEqual(_rotation, value)) + if (_rotation != value) { SetRotationInternal(value); } @@ -598,8 +598,7 @@ namespace FlaxEngine.GUI var anchorMin = AnchorPresetsData[i].Min; var anchorMax = AnchorPresetsData[i].Max; var bounds = _bounds; - if (!Float2.NearEqual(ref _anchorMin, ref anchorMin) || - !Float2.NearEqual(ref _anchorMax, ref anchorMax)) + if (_anchorMin != anchorMin || _anchorMax != anchorMax) { // Disable scrolling for anchored controls (by default but can be manually restored) if (!anchorMin.IsZero || !anchorMax.IsZero) diff --git a/Source/Engine/UI/GUI/Panels/DropPanel.cs b/Source/Engine/UI/GUI/Panels/DropPanel.cs index ff9d3df2d..33052f004 100644 --- a/Source/Engine/UI/GUI/Panels/DropPanel.cs +++ b/Source/Engine/UI/GUI/Panels/DropPanel.cs @@ -71,7 +71,7 @@ namespace FlaxEngine.GUI get => _headerHeight; set { - if (!Mathf.NearEqual(_headerHeight, value)) + if (_headerHeight != value) { _headerHeight = value; PerformLayout(); diff --git a/Source/Engine/UI/GUI/Panels/Panel.cs b/Source/Engine/UI/GUI/Panels/Panel.cs index 01c3bb61d..d4029b6de 100644 --- a/Source/Engine/UI/GUI/Panels/Panel.cs +++ b/Source/Engine/UI/GUI/Panels/Panel.cs @@ -129,7 +129,7 @@ namespace FlaxEngine.GUI get => _scrollBarsSize; set { - if (Mathf.NearEqual(_scrollBarsSize, value)) + if (_scrollBarsSize == value) return; _scrollBarsSize = value; PerformLayout(); diff --git a/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs b/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs index 52222946e..c613eb71e 100644 --- a/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs +++ b/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs @@ -44,7 +44,7 @@ namespace FlaxEngine.GUI get => _margin.Left; set { - if (!Mathf.NearEqual(_margin.Left, value)) + if (_margin.Left != value) { _margin.Left = value; PerformLayout(); @@ -61,7 +61,7 @@ namespace FlaxEngine.GUI get => _margin.Right; set { - if (!Mathf.NearEqual(_margin.Right, value)) + if (_margin.Right != value) { _margin.Right = value; PerformLayout(); @@ -78,7 +78,7 @@ namespace FlaxEngine.GUI get => _margin.Top; set { - if (!Mathf.NearEqual(_margin.Top, value)) + if (_margin.Top != value) { _margin.Top = value; PerformLayout(); @@ -95,7 +95,7 @@ namespace FlaxEngine.GUI get => _margin.Bottom; set { - if (!Mathf.NearEqual(_margin.Bottom, value)) + if (_margin.Bottom != value) { _margin.Bottom = value; PerformLayout(); @@ -112,7 +112,7 @@ namespace FlaxEngine.GUI get => _spacing; set { - if (!Mathf.NearEqual(_spacing, value)) + if (_spacing != value) { _spacing = value; PerformLayout(); @@ -129,7 +129,7 @@ namespace FlaxEngine.GUI get => _offset; set { - if (!Float2.NearEqual(ref _offset, ref value)) + if (_offset != value) { _offset = value; PerformLayout(); diff --git a/Source/Engine/UI/GUI/Panels/ScrollBar.cs b/Source/Engine/UI/GUI/Panels/ScrollBar.cs index 756c698c5..9381dd0bb 100644 --- a/Source/Engine/UI/GUI/Panels/ScrollBar.cs +++ b/Source/Engine/UI/GUI/Panels/ScrollBar.cs @@ -132,7 +132,7 @@ namespace FlaxEngine.GUI set { value = Mathf.Clamp(value, _minimum, _maximum); - if (!Mathf.NearEqual(value, _targetValue)) + if (value != _targetValue) { _targetValue = value; _startValue = _value; @@ -163,7 +163,7 @@ namespace FlaxEngine.GUI set { value = Mathf.Clamp(value, _minimum, _maximum); - if (!Mathf.NearEqual(value, _targetValue)) + if (value != _targetValue) { _targetValue = value; _value = value; @@ -237,7 +237,7 @@ namespace FlaxEngine.GUI /// public void FastScroll() { - if (!Mathf.NearEqual(_value, _targetValue)) + if (_value != _targetValue) { _value = _targetValue = _startValue; _scrollAnimationProgress = 0f; diff --git a/Source/Engine/UI/GUI/Panels/SplitPanel.cs b/Source/Engine/UI/GUI/Panels/SplitPanel.cs index 060459723..cfa6acf25 100644 --- a/Source/Engine/UI/GUI/Panels/SplitPanel.cs +++ b/Source/Engine/UI/GUI/Panels/SplitPanel.cs @@ -67,7 +67,7 @@ namespace FlaxEngine.GUI set { value = Mathf.Saturate(value); - if (!Mathf.NearEqual(_splitterValue, value)) + if (_splitterValue != value) { // Set new value _splitterValue = value; diff --git a/Source/Engine/Video/VideoPlayer.cpp b/Source/Engine/Video/VideoPlayer.cpp index 59f8d2438..dba1f0000 100644 --- a/Source/Engine/Video/VideoPlayer.cpp +++ b/Source/Engine/Video/VideoPlayer.cpp @@ -42,7 +42,7 @@ void VideoPlayer::SetIsAudioSpatial(bool value) void VideoPlayer::SetAudioVolume(float value) { value = Math::Saturate(value); - if (Math::NearEqual(_volume, value)) + if (_volume == value) return; _volume = value; UpdateInfo(); @@ -51,7 +51,7 @@ void VideoPlayer::SetAudioVolume(float value) void VideoPlayer::SetAudioPan(float value) { value = Math::Clamp(value, -1.0f, 1.0f); - if (Math::NearEqual(_pan, value)) + if (_pan == value) return; _pan = value; UpdateInfo(); @@ -60,7 +60,7 @@ void VideoPlayer::SetAudioPan(float value) void VideoPlayer::SetAudioMinDistance(float value) { value = Math::Max(0.0f, value); - if (Math::NearEqual(_minDistance, value)) + if (_minDistance == value) return; _minDistance = value; UpdateInfo(); @@ -69,7 +69,7 @@ void VideoPlayer::SetAudioMinDistance(float value) void VideoPlayer::SetAudioAttenuation(float value) { value = Math::Max(0.0f, value); - if (Math::NearEqual(_attenuation, value)) + if (_attenuation == value) return; _attenuation = value; UpdateInfo(); From 12dbf09164a7d83c37b1aaba19f95d5689fe871c Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Sat, 19 Apr 2025 02:58:46 +0300 Subject: [PATCH 03/16] Fix tests --- Source/Engine/Tests/TestFloatR10G10B10A2.cs | 14 ++++---- Source/Engine/Tests/TestFloatR11G11B10.cs | 14 ++++---- Source/Engine/Tests/TestQuaternion.cs | 10 +++--- Source/Engine/Tests/TestTransform.cs | 36 ++++++++++----------- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/Source/Engine/Tests/TestFloatR10G10B10A2.cs b/Source/Engine/Tests/TestFloatR10G10B10A2.cs index e67272b41..1435f305e 100644 --- a/Source/Engine/Tests/TestFloatR10G10B10A2.cs +++ b/Source/Engine/Tests/TestFloatR10G10B10A2.cs @@ -11,13 +11,13 @@ namespace FlaxEngine.Tests [Test] public void TestConversion() { - Assert.AreEqual(Float4.Zero, new FloatR10G10B10A2(Float4.Zero).ToFloat4()); - Assert.AreEqual(Float4.One, new FloatR10G10B10A2(Float4.One).ToFloat4()); - Assert.AreEqual(new Float4(0.5004888f, 0.5004888f, 0.5004888f, 0.666667f), new FloatR10G10B10A2(new Float4(0.5f)).ToFloat4()); - Assert.AreEqual(new Float4(1, 0, 0, 0), new FloatR10G10B10A2(new Float4(1, 0, 0, 0)).ToFloat4()); - Assert.AreEqual(new Float4(0, 1, 0, 0), new FloatR10G10B10A2(new Float4(0, 1, 0, 0)).ToFloat4()); - Assert.AreEqual(new Float4(0, 0, 1, 0), new FloatR10G10B10A2(new Float4(0, 0, 1, 0)).ToFloat4()); - Assert.AreEqual(new Float4(0, 0, 0, 1), new FloatR10G10B10A2(new Float4(0, 0, 0, 1)).ToFloat4()); + Assert.IsTrue(Float4.NearEqual(Float4.Zero, new FloatR10G10B10A2(Float4.Zero).ToFloat4())); + Assert.IsTrue(Float4.NearEqual(Float4.One, new FloatR10G10B10A2(Float4.One).ToFloat4())); + Assert.IsTrue(Float4.NearEqual(new Float4(0.5004888f, 0.5004888f, 0.5004888f, 0.666667f), new FloatR10G10B10A2(new Float4(0.5f)).ToFloat4())); + Assert.IsTrue(Float4.NearEqual(new Float4(1, 0, 0, 0), new FloatR10G10B10A2(new Float4(1, 0, 0, 0)).ToFloat4())); + Assert.IsTrue(Float4.NearEqual(new Float4(0, 1, 0, 0), new FloatR10G10B10A2(new Float4(0, 1, 0, 0)).ToFloat4())); + Assert.IsTrue(Float4.NearEqual(new Float4(0, 0, 1, 0), new FloatR10G10B10A2(new Float4(0, 0, 1, 0)).ToFloat4())); + Assert.IsTrue(Float4.NearEqual(new Float4(0, 0, 0, 1), new FloatR10G10B10A2(new Float4(0, 0, 0, 1)).ToFloat4())); } } } diff --git a/Source/Engine/Tests/TestFloatR11G11B10.cs b/Source/Engine/Tests/TestFloatR11G11B10.cs index 593989710..2fd080594 100644 --- a/Source/Engine/Tests/TestFloatR11G11B10.cs +++ b/Source/Engine/Tests/TestFloatR11G11B10.cs @@ -11,13 +11,13 @@ namespace FlaxEngine.Tests [Test] public void TestConversion() { - Assert.AreEqual(Float3.Zero, new FloatR11G11B10(Float3.Zero).ToFloat3()); - Assert.AreEqual(Float3.One, new FloatR11G11B10(Float3.One).ToFloat3()); - Assert.AreEqual(new Float3(0.5f, 0.5f, 0.5f), new FloatR11G11B10(new Float3(0.5f)).ToFloat3()); - Assert.AreEqual(new Float3(1, 0, 0), new FloatR11G11B10(new Float3(1, 0, 0)).ToFloat3()); - Assert.AreEqual(new Float3(0, 1, 0), new FloatR11G11B10(new Float3(0, 1, 0)).ToFloat3()); - Assert.AreEqual(new Float3(0, 0, 1), new FloatR11G11B10(new Float3(0, 0, 1)).ToFloat3()); - Assert.AreEqual(new Float3(10, 11, 12), new FloatR11G11B10(new Float3(10, 11, 12)).ToFloat3()); + Assert.IsTrue(Float3.NearEqual(Float3.Zero, new FloatR11G11B10(Float3.Zero).ToFloat3())); + Assert.IsTrue(Float3.NearEqual(Float3.One, new FloatR11G11B10(Float3.One).ToFloat3())); + Assert.IsTrue(Float3.NearEqual(new Float3(0.5f, 0.5f, 0.5f), new FloatR11G11B10(new Float3(0.5f)).ToFloat3())); + Assert.IsTrue(Float3.NearEqual(new Float3(1, 0, 0), new FloatR11G11B10(new Float3(1, 0, 0)).ToFloat3())); + Assert.IsTrue(Float3.NearEqual(new Float3(0, 1, 0), new FloatR11G11B10(new Float3(0, 1, 0)).ToFloat3())); + Assert.IsTrue(Float3.NearEqual(new Float3(0, 0, 1), new FloatR11G11B10(new Float3(0, 0, 1)).ToFloat3())); + Assert.IsTrue(Float3.NearEqual(new Float3(10, 11, 12), new FloatR11G11B10(new Float3(10, 11, 12)).ToFloat3())); } } } diff --git a/Source/Engine/Tests/TestQuaternion.cs b/Source/Engine/Tests/TestQuaternion.cs index bafa1b3e5..749f7ee81 100644 --- a/Source/Engine/Tests/TestQuaternion.cs +++ b/Source/Engine/Tests/TestQuaternion.cs @@ -17,10 +17,10 @@ namespace FlaxEngine.Tests [Test] public void TestEuler() { - Assert.AreEqual(Quaternion.Euler(90, 0, 0), new Quaternion(0.7071068f, 0, 0, 0.7071068f)); - Assert.AreEqual(Quaternion.Euler(25, 0, 10), new Quaternion(0.215616f, -0.018864f, 0.0850898f, 0.9725809f)); - Assert.AreEqual(new Float3(25, 0, 10), Quaternion.Euler(25, 0, 10).EulerAngles); - Assert.AreEqual(new Float3(25, -5, 10), Quaternion.Euler(25, -5, 10).EulerAngles); + Assert.IsTrue(Quaternion.NearEqual(Quaternion.Euler(90, 0, 0), new Quaternion(0.7071068f, 0, 0, 0.7071068f))); + Assert.IsTrue(Quaternion.NearEqual(Quaternion.Euler(25, 0, 10), new Quaternion(0.215616f, -0.018864f, 0.0850898f, 0.9725809f))); + Assert.IsTrue(Float3.NearEqual(new Float3(25, 0, 10), Quaternion.Euler(25, 0, 10).EulerAngles, 0.00001f)); + Assert.IsTrue(Float3.NearEqual(new Float3(25, -5, 10), Quaternion.Euler(25, -5, 10).EulerAngles, 0.00001f)); } /// @@ -33,7 +33,7 @@ namespace FlaxEngine.Tests var delta = Quaternion.Euler(0, 10, 0); for (int i = 0; i < 9; i++) q *= delta; - Assert.AreEqual(Quaternion.Euler(0, 90, 0), q); + Assert.IsTrue(Quaternion.NearEqual(Quaternion.Euler(0, 90, 0), q)); } } } diff --git a/Source/Engine/Tests/TestTransform.cs b/Source/Engine/Tests/TestTransform.cs index 24edcb989..a3f3b2f03 100644 --- a/Source/Engine/Tests/TestTransform.cs +++ b/Source/Engine/Tests/TestTransform.cs @@ -68,9 +68,9 @@ namespace FlaxEngine.Tests t1.LocalToWorld(new Vector3[1] { t2.Translation }, a4T); Vector3 a4 = a4T[0]; - Assert.AreEqual(a1.Translation, a2); - Assert.AreEqual(a2, a3); - Assert.AreEqual(a2, a4); + Assert.IsTrue(Vector3.NearEqual(a1.Translation, a2)); + Assert.IsTrue(Vector3.NearEqual(a2, a3)); + Assert.IsTrue(Vector3.NearEqual(a2, a4)); } /// @@ -100,9 +100,9 @@ namespace FlaxEngine.Tests t1.WorldToLocal(new Vector3[1] { t2.Translation }, a4T); Float3 a4 = a4T[0]; - Assert.AreEqual((Float3)a1.Translation, a2); - Assert.AreEqual(a2, a3); - Assert.AreEqual(a2, a4); + Assert.IsTrue(Float3.NearEqual((Float3)a1.Translation, a2)); + Assert.IsTrue(Float3.NearEqual(a2, a3, 0.0001f)); + Assert.IsTrue(Float3.NearEqual(a2, a4)); } /// @@ -113,28 +113,28 @@ namespace FlaxEngine.Tests { Transform trans = new Transform(new Vector3(1, 2, 3)); - Assert.AreEqual(new Float3(1, 2, 3), (Float3)trans.LocalToWorld(new Float3(0, 0, 0))); - Assert.AreEqual(new Float3(4, 4, 4), (Float3)trans.LocalToWorld(new Float3(3, 2, 1))); - Assert.AreEqual(new Float3(-1, -2, -3), (Float3)trans.WorldToLocal(new Float3(0, 0, 0))); - Assert.AreEqual(new Float3(0, 0, 0), (Float3)trans.WorldToLocal(new Float3(1, 2, 3))); + Assert.IsTrue(Float3.NearEqual(new Float3(1, 2, 3), (Float3)trans.LocalToWorld(new Float3(0, 0, 0)))); + Assert.IsTrue(Float3.NearEqual(new Float3(4, 4, 4), (Float3)trans.LocalToWorld(new Float3(3, 2, 1)))); + Assert.IsTrue(Float3.NearEqual(new Float3(-1, -2, -3), (Float3)trans.WorldToLocal(new Float3(0, 0, 0)))); + Assert.IsTrue(Float3.NearEqual(new Float3(0, 0, 0), (Float3)trans.WorldToLocal(new Float3(1, 2, 3)))); trans = new Transform(Vector3.Zero, Quaternion.Euler(0, 90, 0)); - Assert.AreEqual(new Float3(0, 2, -1), (Float3)trans.LocalToWorld(new Float3(1, 2, 0))); + Assert.IsTrue(Float3.NearEqual(new Float3(0, 2, -1), (Float3)trans.LocalToWorld(new Float3(1, 2, 0)))); trans.Translation = new Vector3(1, 0, 0); trans.Orientation = Quaternion.RotationX((float)Math.PI * 0.5f); trans.Scale = new Vector3(2, 2, 2); - Assert.AreEqual(new Float3(1, 0, 2), (Float3)trans.LocalToWorld(new Float3(0, 1, 0))); + Assert.IsTrue(Float3.NearEqual(new Float3(1, 0, 2), (Float3)trans.LocalToWorld(new Float3(0, 1, 0)))); Transform t1 = trans.LocalToWorld(Transform.Identity); - Assert.AreEqual(new Float3(1.0f, 0, 0), (Float3)t1.Translation); - Assert.AreEqual(Quaternion.RotationX((float)Math.PI * 0.5f), t1.Orientation); - Assert.AreEqual(new Float3(2.0f, 2.0f, 2.0f), t1.Scale); + Assert.IsTrue(Float3.NearEqual(new Float3(1.0f, 0, 0), (Float3)t1.Translation)); + Assert.IsTrue(Quaternion.NearEqual(Quaternion.RotationX((float)Math.PI * 0.5f), t1.Orientation)); + Assert.IsTrue(Float3.NearEqual(new Float3(2.0f, 2.0f, 2.0f), t1.Scale)); Transform t2 = trans.WorldToLocal(Transform.Identity); - Assert.AreEqual(new Float3(-0.5f, 0, 0), (Float3)t2.Translation); - Assert.AreEqual(Quaternion.RotationX((float)Math.PI * -0.5f), t2.Orientation); - Assert.AreEqual(new Float3(0.5f, 0.5f, 0.5f), t2.Scale); + Assert.IsTrue(Float3.NearEqual(new Float3(-0.5f, 0, 0), (Float3)t2.Translation)); + Assert.IsTrue(Quaternion.NearEqual(Quaternion.RotationX((float)Math.PI * -0.5f), t2.Orientation)); + Assert.IsTrue(Float3.NearEqual(new Float3(0.5f, 0.5f, 0.5f), t2.Scale)); var rand = new Random(10); for (int i = 0; i < 10; i++) From fd8a8b5a4dd9cde88d3da8b47633758c989d9e9f Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 2 Jun 2025 18:02:34 +0200 Subject: [PATCH 04/16] Fix missing default value of localized string in editor --- Source/Editor/CustomEditors/Editors/StringEditor.cs | 2 +- Source/Engine/UI/GUI/Common/TextBox.cs | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Source/Editor/CustomEditors/Editors/StringEditor.cs b/Source/Editor/CustomEditors/Editors/StringEditor.cs index 12cd29b8b..7eaf26186 100644 --- a/Source/Editor/CustomEditors/Editors/StringEditor.cs +++ b/Source/Editor/CustomEditors/Editors/StringEditor.cs @@ -35,7 +35,7 @@ namespace FlaxEditor.CustomEditors.Editors } _element = layout.TextBox(isMultiLine); - _defaultWatermarkColor = _element.TextBox.WatermarkTextColor; + _watermarkColor = _defaultWatermarkColor = _element.TextBox.WatermarkTextColor; if (watermarkAttribute is WatermarkAttribute watermark) { _watermarkText = watermark.WatermarkText; diff --git a/Source/Engine/UI/GUI/Common/TextBox.cs b/Source/Engine/UI/GUI/Common/TextBox.cs index 76727cc07..9ee052581 100644 --- a/Source/Engine/UI/GUI/Common/TextBox.cs +++ b/Source/Engine/UI/GUI/Common/TextBox.cs @@ -298,9 +298,13 @@ namespace FlaxEngine.GUI color *= 0.85f; Render2D.DrawText(font, text, color, ref _layout, TextMaterial); } - else if (!string.IsNullOrEmpty(_watermarkText)) + else { - Render2D.DrawText(font, _watermarkText, WatermarkTextColor, ref _layout, TextMaterial); + text = _watermarkText; + if (text.Length > 0) + { + Render2D.DrawText(font, _watermarkText, WatermarkTextColor, ref _layout, TextMaterial); + } } // Caret From 7da69f18d4b838061c21eab70a275087650d725d Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 2 Jun 2025 22:01:06 +0200 Subject: [PATCH 05/16] Add button to quickly jump into Localized String Table that contains it #3301 --- .../Editors/LocalizedStringEditor.cs | 62 ++++++++++++++++--- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/Source/Editor/CustomEditors/Editors/LocalizedStringEditor.cs b/Source/Editor/CustomEditors/Editors/LocalizedStringEditor.cs index 76ceb7488..221bfd7a9 100644 --- a/Source/Editor/CustomEditors/Editors/LocalizedStringEditor.cs +++ b/Source/Editor/CustomEditors/Editors/LocalizedStringEditor.cs @@ -21,6 +21,7 @@ namespace FlaxEditor.CustomEditors.Editors public sealed class LocalizedStringEditor : GenericEditor { private TextBoxElement _idElement, _valueElement; + private Button _viewStringButton; /// public override DisplayStyle Style => DisplayStyle.Inline; @@ -70,6 +71,21 @@ namespace FlaxEditor.CustomEditors.Editors }; addString.SetAnchorPreset(AnchorPresets.MiddleRight, false, true); addString.ButtonClicked += OnAddStringClicked; + + var viewString = new Button + { + Visible = false, + Width = 16.0f, + BackgroundColor = Color.White, + BackgroundColorHighlighted = Color.Gray, + BackgroundBrush = new SpriteBrush(Editor.Instance.Icons.Search12), + TooltipText = "Find localized text in Localized String Table asset for the current locale...", + Parent = valueElement.TextBox, + }; + viewString.SetAnchorPreset(AnchorPresets.MiddleRight, false, true); + viewString.LocalX -= 16.0f; + viewString.ButtonClicked += OnViewStringClicked; + _viewStringButton = viewString; } /// @@ -80,6 +96,7 @@ namespace FlaxEditor.CustomEditors.Editors if (_valueElement != null) { _valueElement.TextBox.WatermarkText = Localization.GetString(_idElement.Text); + _viewStringButton.Visible = !string.IsNullOrEmpty(_valueElement.TextBox.WatermarkText); } } @@ -92,14 +109,21 @@ namespace FlaxEditor.CustomEditors.Editors _valueElement = null; } - private void OnSelectStringClicked(Button button) + private bool GetSettings(out LocalizationSettings settings) { - var settings = GameSettings.Load(); + settings = GameSettings.Load(); if (settings?.LocalizedStringTables == null || settings.LocalizedStringTables.Length == 0) { MessageBox.Show("No valid localization settings setup."); - return; + return true; } + return false; + } + + private void OnSelectStringClicked(Button button) + { + if (GetSettings(out var settings)) + return; Profiler.BeginEvent("LocalizedStringEditor.OnSelectStringClicked"); var allKeys = new HashSet(); for (int i = 0; i < settings.LocalizedStringTables.Length; i++) @@ -136,6 +160,7 @@ namespace FlaxEditor.CustomEditors.Editors { menu.Hide(); _idElement.TextBox.SetTextAsUser(after[0].Text); + _valueElement.TextBox.SetTextAsUser(string.Empty); } }; searchBox.TextChanged += delegate @@ -158,12 +183,8 @@ namespace FlaxEditor.CustomEditors.Editors private void OnAddStringClicked(Button button) { - var settings = GameSettings.Load(); - if (settings?.LocalizedStringTables == null || settings.LocalizedStringTables.Length == 0) - { - MessageBox.Show("No valid localization settings setup."); + if (GetSettings(out var settings)) return; - } Profiler.BeginEvent("LocalizedStringEditor.OnAddStringClicked"); var allKeys = new HashSet(); for (int i = 0; i < settings.LocalizedStringTables.Length; i++) @@ -231,5 +252,30 @@ namespace FlaxEditor.CustomEditors.Editors _idElement.TextBox.SetTextAsUser(newKey); Profiler.EndEvent(); } + + private void OnViewStringClicked(Button button) + { + if (GetSettings(out var settings)) + return; + var id = _idElement.TextBox.Text; + var value = _valueElement.TextBox.WatermarkText; + for (int i = 0; i < settings.LocalizedStringTables.Length; i++) + { + var table = settings.LocalizedStringTables[i]; + if (table && !table.WaitForLoaded()) + { + var entries = table.Entries; + if (entries.TryGetValue(id, out var messages)) + { + if (messages.Length != 0 && messages[0] == value) + { + Editor.Instance.ContentEditing.Open(table); + return; + } + } + } + } + MessageBox.Show("Unable to find localized string table."); + } } } From 077f7a3cd16d33fe3de73be0af8c6600887984b8 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 3 Jun 2025 11:18:03 +0200 Subject: [PATCH 06/16] Add `PositionFormat` and `TexCoordFormat` to model import option for mesh data encoding --- Source/Engine/Content/Assets/ModelBase.cpp | 33 ++++++++++++++++----- Source/Engine/Graphics/Models/ModelData.h | 15 ++++++++++ Source/Engine/Tools/ModelTool/ModelTool.cpp | 10 +++++++ Source/Engine/Tools/ModelTool/ModelTool.h | 30 +++++++++++++++++++ 4 files changed, 80 insertions(+), 8 deletions(-) diff --git a/Source/Engine/Content/Assets/ModelBase.cpp b/Source/Engine/Content/Assets/ModelBase.cpp index 243e429a5..e993bbec6 100644 --- a/Source/Engine/Content/Assets/ModelBase.cpp +++ b/Source/Engine/Content/Assets/ModelBase.cpp @@ -665,6 +665,8 @@ bool ModelBase::SaveLOD(WriteStream& stream, const ModelData& modelData, int32 l Array> vbElements; const bool useSeparatePositions = !isSkinned; const bool useSeparateColors = !isSkinned; + PixelFormat positionsFormat = modelData.PositionFormat == ModelData::PositionFormats::Float32 ? PixelFormat::R32G32B32_Float : PixelFormat::R16G16B16A16_Float; + PixelFormat texCoordsFormat = modelData.TexCoordFormat == ModelData::TexCoordFormats::Float16 ? PixelFormat::R16G16_Float : PixelFormat::R8G8_UNorm; PixelFormat blendIndicesFormat = PixelFormat::R8G8B8A8_UInt; PixelFormat blendWeightsFormat = PixelFormat::R8G8B8A8_UNorm; for (const Int4& indices : mesh.BlendIndices) @@ -677,14 +679,13 @@ bool ModelBase::SaveLOD(WriteStream& stream, const ModelData& modelData, int32 l } { byte vbIndex = 0; - // TODO: add option to quantize vertex positions (eg. 16-bit) // TODO: add option to quantize vertex attributes (eg. 8-bit blend weights, 8-bit texcoords) // Position if (useSeparatePositions) { auto& vb0 = vbElements.AddOne(); - vb0.Add({ VertexElement::Types::Position, vbIndex, 0, 0, PixelFormat::R32G32B32_Float }); + vb0.Add({ VertexElement::Types::Position, vbIndex, 0, 0, positionsFormat }); vbIndex++; } @@ -692,13 +693,13 @@ bool ModelBase::SaveLOD(WriteStream& stream, const ModelData& modelData, int32 l { auto& vb = vbElements.AddOne(); if (!useSeparatePositions) - vb.Add({ VertexElement::Types::Position, vbIndex, 0, 0, PixelFormat::R32G32B32_Float }); + vb.Add({ VertexElement::Types::Position, vbIndex, 0, 0, positionsFormat }); for (int32 channelIdx = 0; channelIdx < mesh.UVs.Count(); channelIdx++) { auto& channel = mesh.UVs.Get()[channelIdx]; if (channel.HasItems()) { - vb.Add({ (VertexElement::Types)((int32)VertexElement::Types::TexCoord0 + channelIdx), vbIndex, 0, 0, PixelFormat::R16G16_Float }); + vb.Add({ (VertexElement::Types)((int32)VertexElement::Types::TexCoord0 + channelIdx), vbIndex, 0, 0, texCoordsFormat }); } } vb.Add({ VertexElement::Types::Normal, vbIndex, 0, 0, PixelFormat::R10G10B10A2_UNorm }); @@ -733,7 +734,7 @@ bool ModelBase::SaveLOD(WriteStream& stream, const ModelData& modelData, int32 l // Write vertex buffers for (int32 vbIndex = 0; vbIndex < vbCount; vbIndex++) { - if (useSeparatePositions && vbIndex == 0) + if (useSeparatePositions && vbIndex == 0 && positionsFormat == PixelFormat::R32G32B32_Float) { // Fast path for vertex positions of static models using the first buffer stream.WriteBytes(mesh.Positions.Get(), sizeof(Float3) * vertices); @@ -751,7 +752,15 @@ bool ModelBase::SaveLOD(WriteStream& stream, const ModelData& modelData, int32 l case VertexElement::Types::Position: { const Float3 position = mesh.Positions.Get()[vertex]; - stream.Write(position); + if (positionsFormat == PixelFormat::R16G16B16A16_Float) + { + const Half4 positionEnc(Float4(position, 0.0f)); + stream.Write(positionEnc); + } + else //if (positionsFormat == PixelFormat::R32G32B32_Float) + { + stream.Write(position); + } break; } case VertexElement::Types::Color: @@ -817,8 +826,16 @@ bool ModelBase::SaveLOD(WriteStream& stream, const ModelData& modelData, int32 l { const int32 channelIdx = (int32)element.Type - (int32)VertexElement::Types::TexCoord0; const Float2 uv = mesh.UVs.Get()[channelIdx].Get()[vertex]; - const Half2 uvEnc(uv); - stream.Write(uvEnc); + if (texCoordsFormat == PixelFormat::R8G8_UNorm) + { + stream.Write((uint8)Math::Clamp((int32)(uv.X * 255), 0, 255)); + stream.Write((uint8)Math::Clamp((int32)(uv.Y * 255), 0, 255)); + } + else //if (texCoordsFormat == PixelFormat::R16G16_Float) + { + const Half2 uvEnc(uv); + stream.Write(uvEnc); + } break; } default: diff --git a/Source/Engine/Graphics/Models/ModelData.h b/Source/Engine/Graphics/Models/ModelData.h index 4566e764b..8e401b973 100644 --- a/Source/Engine/Graphics/Models/ModelData.h +++ b/Source/Engine/Graphics/Models/ModelData.h @@ -428,6 +428,21 @@ public: /// Array Animations; +public: + // See ModelTool::PositionFormat + enum class PositionFormats + { + Float32, + Float16, + } PositionFormat = PositionFormats::Float32; + + // See ModelTool::TexCoordFormats + enum class TexCoordFormats + { + Float16, + UNorm8, + } TexCoordFormat = TexCoordFormats::Float16; + public: /// /// Automatically calculates the screen size for every model LOD for a proper transitions. diff --git a/Source/Engine/Tools/ModelTool/ModelTool.cpp b/Source/Engine/Tools/ModelTool/ModelTool.cpp index 51584504d..795b69452 100644 --- a/Source/Engine/Tools/ModelTool/ModelTool.cpp +++ b/Source/Engine/Tools/ModelTool/ModelTool.cpp @@ -676,6 +676,9 @@ void ModelTool::Options::Serialize(SerializeStream& stream, const void* otherObj SERIALIZE(CalculateBoneOffsetMatrices); SERIALIZE(LightmapUVsSource); SERIALIZE(CollisionMeshesPrefix); + SERIALIZE(CollisionType); + SERIALIZE(PositionFormat); + SERIALIZE(TexCoordFormat); SERIALIZE(Scale); SERIALIZE(Rotation); SERIALIZE(Translation); @@ -727,6 +730,9 @@ void ModelTool::Options::Deserialize(DeserializeStream& stream, ISerializeModifi DESERIALIZE(CalculateBoneOffsetMatrices); DESERIALIZE(LightmapUVsSource); DESERIALIZE(CollisionMeshesPrefix); + DESERIALIZE(CollisionType); + DESERIALIZE(PositionFormat); + DESERIALIZE(TexCoordFormat); DESERIALIZE(Scale); DESERIALIZE(Rotation); DESERIALIZE(Translation); @@ -1137,6 +1143,10 @@ bool ModelTool::ImportModel(const String& path, ModelData& data, Options& option if (ImportData(path, data, options, errorMsg)) return true; + // Copy over data format options + data.PositionFormat = (ModelData::PositionFormats)options.PositionFormat; + data.TexCoordFormat = (ModelData::TexCoordFormats)options.TexCoordFormat; + // Validate result data if (EnumHasAnyFlags(options.ImportTypes, ImportDataTypes::Geometry)) { diff --git a/Source/Engine/Tools/ModelTool/ModelTool.h b/Source/Engine/Tools/ModelTool/ModelTool.h index 7e0587c3d..b09583471 100644 --- a/Source/Engine/Tools/ModelTool/ModelTool.h +++ b/Source/Engine/Tools/ModelTool/ModelTool.h @@ -142,6 +142,28 @@ public: ExtractCenterOfMass = 2, }; + /// + /// Declares the imported vertex positions data formats. + /// + API_ENUM(Attributes="HideInEditor") enum class PositionFormat + { + // XYZ channels with 32-bit precision (12 bytes per vertex). + Float32, + // XYZ(W) channels with 12-bit precision (8 bytes per vertex). + Float16, + }; + + /// + /// Declares the imported vertex texture coordinates data formats. + /// + API_ENUM(Attributes="HideInEditor") enum class TexCoordFormats + { + // XY channels with 16-bit precision (4 bytes per vertex). + Float16, + // XY channels with 8-bit precision (2 bytes per vertex). Valid only for normalized UVs within range [0; 1], scaled or negative UVs won't work. + UNorm8, + }; + /// /// Model import options. /// @@ -201,6 +223,14 @@ public: API_FIELD(Attributes="EditorOrder(105), EditorDisplay(\"Geometry\"), VisibleIf(nameof(ShowGeometry))") CollisionDataType CollisionType = CollisionDataType::ConvexMesh; + public: + // The imported vertex positions data format to use by meshes. Changing this affects memory usage of the mesh data, performance and overall quality. + API_FIELD(Attributes = "EditorOrder(200), EditorDisplay(\"Data Format\"), VisibleIf(nameof(ShowGeometry))") + PositionFormat PositionFormat = PositionFormat::Float32; + // The imported vertex texture coordinates data format to use by meshes. Changing this affects memory usage of the mesh data, performance and overall quality. + API_FIELD(Attributes = "EditorOrder(205), EditorDisplay(\"Data Format\"), VisibleIf(nameof(ShowGeometry))") + TexCoordFormats TexCoordFormat = TexCoordFormats::Float16; + public: // Transform // Custom uniform import scale. From 2fd9b4a62ace0014cad2b8f518a945022c69ab8b Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 3 Jun 2025 12:28:17 +0200 Subject: [PATCH 07/16] Fix loading models with no meshes --- Source/Editor/Windows/Assets/ModelBaseWindow.cs | 3 ++- Source/Engine/Content/Assets/Model.cpp | 4 ++-- Source/Engine/Content/Assets/SkinnedModel.cpp | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Source/Editor/Windows/Assets/ModelBaseWindow.cs b/Source/Editor/Windows/Assets/ModelBaseWindow.cs index 1214e9427..14344ef71 100644 --- a/Source/Editor/Windows/Assets/ModelBaseWindow.cs +++ b/Source/Editor/Windows/Assets/ModelBaseWindow.cs @@ -254,7 +254,8 @@ namespace FlaxEditor.Windows.Assets if (lodIndex >= countLODs - loadedLODs) { var mesh = lod.GetMesh(0); - vertexLayout = mesh.VertexLayout; + if (mesh != null) + vertexLayout = mesh.VertexLayout; if (vertexLayout != null && vertexLayout.Elements.Length != 0) break; vertexLayout = null; diff --git a/Source/Engine/Content/Assets/Model.cpp b/Source/Engine/Content/Assets/Model.cpp index 1f5768e6c..246bee3b4 100644 --- a/Source/Engine/Content/Assets/Model.cpp +++ b/Source/Engine/Content/Assets/Model.cpp @@ -324,7 +324,7 @@ bool Model::Init(const Span& meshesCountPerLod) lod.Link(this, lodIndex); lod.ScreenSize = 1.0f; const int32 meshesCount = meshesCountPerLod[lodIndex]; - if (meshesCount <= 0 || meshesCount > MODEL_MAX_MESHES) + if (meshesCount < 0 || meshesCount > MODEL_MAX_MESHES) return true; lod.Meshes.Resize(meshesCount); @@ -362,7 +362,7 @@ bool Model::LoadHeader(ReadStream& stream, byte& headerVersion) // Meshes uint16 meshesCount; stream.ReadUint16(&meshesCount); - if (meshesCount == 0 || meshesCount > MODEL_MAX_MESHES) + if (meshesCount > MODEL_MAX_MESHES) return true; ASSERT(lodIndex == 0 || LODs[0].Meshes.Count() >= meshesCount); lod.Meshes.Resize(meshesCount, false); diff --git a/Source/Engine/Content/Assets/SkinnedModel.cpp b/Source/Engine/Content/Assets/SkinnedModel.cpp index 5271df723..9ca530a53 100644 --- a/Source/Engine/Content/Assets/SkinnedModel.cpp +++ b/Source/Engine/Content/Assets/SkinnedModel.cpp @@ -476,7 +476,7 @@ bool SkinnedModel::Init(const Span& meshesCountPerLod) lod._lodIndex = lodIndex; lod.ScreenSize = 1.0f; const int32 meshesCount = meshesCountPerLod[lodIndex]; - if (meshesCount <= 0 || meshesCount > MODEL_MAX_MESHES) + if (meshesCount < 0 || meshesCount > MODEL_MAX_MESHES) return true; lod.Meshes.Resize(meshesCount); From 6fece4ca38b7f7e3449070da80f5b87dd9121b53 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 3 Jun 2025 12:48:31 +0200 Subject: [PATCH 08/16] Fix automatic collision importing from mode to remove unused material slots #3475 --- Source/Engine/Tools/ModelTool/ModelTool.cpp | 34 +++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Source/Engine/Tools/ModelTool/ModelTool.cpp b/Source/Engine/Tools/ModelTool/ModelTool.cpp index 795b69452..fe268c350 100644 --- a/Source/Engine/Tools/ModelTool/ModelTool.cpp +++ b/Source/Engine/Tools/ModelTool/ModelTool.cpp @@ -1931,9 +1931,43 @@ bool ModelTool::ImportModel(const String& path, ModelData& data, Options& option auto mesh = lod.Meshes[i]; if (mesh->Name.StartsWith(options.CollisionMeshesPrefix, StringSearchCase::IgnoreCase)) { + // Remove material slot used by this mesh (if no other mesh else uses it) + int32 materialSlotUsageCount = 0; + for (const auto& e : data.LODs) + { + for (const MeshData* q : e.Meshes) + { + if (q->MaterialSlotIndex == mesh->MaterialSlotIndex) + materialSlotUsageCount++; + } + } + if (materialSlotUsageCount == 1) + { + data.Materials.RemoveAt(mesh->MaterialSlotIndex); + + // Fixup linkage of other meshes to materials + for (auto& e : data.LODs) + { + for (MeshData* q : e.Meshes) + { + if (q->MaterialSlotIndex > mesh->MaterialSlotIndex) + { + q->MaterialSlotIndex--; + } + } + } + } + + // Remove data linkage + mesh->NodeIndex = 0; + mesh->MaterialSlotIndex = 0; + + // Add mesh to collision if (collisionModel.LODs.Count() == 0) collisionModel.LODs.AddOne(); collisionModel.LODs[0].Meshes.Add(mesh); + + // Remove mesh from model lod.Meshes.RemoveAtKeepOrder(i); if (lod.Meshes.IsEmpty()) break; From 55b441e9fa4f7746c6484a556ee9a53c6da621db Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 3 Jun 2025 12:55:54 +0200 Subject: [PATCH 09/16] Fix transparency-related material options when using material with deferred shading --- Source/Editor/Windows/Assets/MaterialWindow.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Source/Editor/Windows/Assets/MaterialWindow.cs b/Source/Editor/Windows/Assets/MaterialWindow.cs index c6fb5675a..df227c733 100644 --- a/Source/Editor/Windows/Assets/MaterialWindow.cs +++ b/Source/Editor/Windows/Assets/MaterialWindow.cs @@ -76,29 +76,29 @@ namespace FlaxEditor.Windows.Assets // Transparency - [EditorOrder(200), DefaultValue(MaterialTransparentLightingMode.Surface), VisibleIf(nameof(IsStandard)), EditorDisplay("Transparency"), Tooltip("Transparent material lighting mode.")] + [EditorOrder(200), DefaultValue(MaterialTransparentLightingMode.Surface), VisibleIf(nameof(IsForward)), EditorDisplay("Transparency"), Tooltip("Transparent material lighting mode.")] public MaterialTransparentLightingMode TransparentLightingMode; - [EditorOrder(205), DefaultValue(true), VisibleIf(nameof(IsStandard)), EditorDisplay("Transparency"), Tooltip("Enables reflections when rendering material.")] + [EditorOrder(205), DefaultValue(true), VisibleIf(nameof(IsForward)), EditorDisplay("Transparency"), Tooltip("Enables reflections when rendering material.")] public bool EnableReflections; [VisibleIf(nameof(EnableReflections))] - [EditorOrder(210), DefaultValue(false), VisibleIf(nameof(IsStandard)), EditorDisplay("Transparency"), Tooltip("Enables Screen Space Reflections when rendering material.")] + [EditorOrder(210), DefaultValue(false), VisibleIf(nameof(IsForward)), EditorDisplay("Transparency"), Tooltip("Enables Screen Space Reflections when rendering material.")] public bool EnableScreenSpaceReflections; - [EditorOrder(210), DefaultValue(true), VisibleIf(nameof(IsStandard)), EditorDisplay("Transparency"), Tooltip("Enables fog effects when rendering material.")] + [EditorOrder(210), DefaultValue(true), VisibleIf(nameof(IsForward)), EditorDisplay("Transparency"), Tooltip("Enables fog effects when rendering material.")] public bool EnableFog; - [EditorOrder(220), DefaultValue(true), VisibleIf(nameof(IsStandard)), EditorDisplay("Transparency"), Tooltip("Enables distortion effect when rendering.")] + [EditorOrder(220), DefaultValue(true), VisibleIf(nameof(IsForward)), EditorDisplay("Transparency"), Tooltip("Enables distortion effect when rendering.")] public bool EnableDistortion; - [EditorOrder(224), DefaultValue(false), VisibleIf(nameof(IsStandard)), EditorDisplay("Transparency"), Tooltip("Enables sampling Global Illumination in material (eg. light probes or volumetric lightmap).")] + [EditorOrder(224), DefaultValue(false), VisibleIf(nameof(IsForward)), EditorDisplay("Transparency"), Tooltip("Enables sampling Global Illumination in material (eg. light probes or volumetric lightmap).")] public bool EnableGlobalIllumination; - [EditorOrder(225), DefaultValue(false), VisibleIf(nameof(IsStandard)), EditorDisplay("Transparency"), Tooltip("Enables refraction offset based on the difference between the per-pixel normal and the per-vertex normal. Useful for large water-like surfaces.")] + [EditorOrder(225), DefaultValue(false), VisibleIf(nameof(IsForward)), EditorDisplay("Transparency"), Tooltip("Enables refraction offset based on the difference between the per-pixel normal and the per-vertex normal. Useful for large water-like surfaces.")] public bool PixelNormalOffsetRefraction; - [EditorOrder(230), DefaultValue(0.12f), VisibleIf(nameof(IsStandard)), EditorDisplay("Transparency"), Tooltip("Controls opacity values clipping point."), Limit(0.0f, 1.0f, 0.01f)] + [EditorOrder(230), DefaultValue(0.12f), VisibleIf(nameof(IsForward)), EditorDisplay("Transparency"), Tooltip("Controls opacity values clipping point."), Limit(0.0f, 1.0f, 0.01f)] public float OpacityThreshold; // Tessellation @@ -146,6 +146,7 @@ namespace FlaxEditor.Windows.Assets private bool IsDecal => Domain == MaterialDomain.Decal; private bool IsGUI => Domain == MaterialDomain.GUI; private bool IsStandard => Domain == MaterialDomain.Surface || Domain == MaterialDomain.Terrain || Domain == MaterialDomain.Particle || Domain == MaterialDomain.Deformable; + private bool IsForward => Domain == MaterialDomain.Particle || ((Domain == MaterialDomain.Deformable || Domain == MaterialDomain.Surface) && BlendMode != MaterialBlendMode.Opaque); private bool IsStandardOrGUI => IsStandard || IsGUI; /// From f2aaad004830e91ce8a075b774de708529a28228 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 3 Jun 2025 14:50:47 +0200 Subject: [PATCH 10/16] Add viewport icons scale relative to the distance and editor control over it #2944 #2644 --- Source/Editor/SceneGraph/ActorNodeWithIcon.cs | 3 ++- .../Utilities/ViewportIconsRenderer.cpp | 22 ++++++++++++++----- .../Editor/Utilities/ViewportIconsRenderer.h | 13 +++++++++++ Source/Editor/Viewport/EditorViewport.cs | 12 ++++++++++ 4 files changed, 43 insertions(+), 7 deletions(-) diff --git a/Source/Editor/SceneGraph/ActorNodeWithIcon.cs b/Source/Editor/SceneGraph/ActorNodeWithIcon.cs index 9e66f5d5a..f9820bb55 100644 --- a/Source/Editor/SceneGraph/ActorNodeWithIcon.cs +++ b/Source/Editor/SceneGraph/ActorNodeWithIcon.cs @@ -35,7 +35,8 @@ namespace FlaxEditor.SceneGraph return false; } - BoundingSphere sphere = new BoundingSphere(Transform.Translation, 7.0f); + var center = _actor.Transform.Translation; + ViewportIconsRenderer.GetBounds(ref center, ref ray.Ray.Position, out var sphere); return CollisionsHelper.RayIntersectsSphere(ref ray.Ray, ref sphere, out distance); } } diff --git a/Source/Editor/Utilities/ViewportIconsRenderer.cpp b/Source/Editor/Utilities/ViewportIconsRenderer.cpp index 2562c9bf5..ccfa876bd 100644 --- a/Source/Editor/Utilities/ViewportIconsRenderer.cpp +++ b/Source/Editor/Utilities/ViewportIconsRenderer.cpp @@ -23,8 +23,6 @@ #include "Engine/Level/Actors/SpotLight.h" #include "Engine/Video/VideoPlayer.h" -#define ICON_RADIUS 7.0f - enum class IconTypes { PointLight, @@ -66,6 +64,16 @@ public: }; ViewportIconsRendererService ViewportIconsRendererServiceInstance; +float ViewportIconsRenderer::Scale = 1.0f; + +void ViewportIconsRenderer::GetBounds(const Vector3& position, const Vector3& viewPosition, BoundingSphere& bounds) +{ + constexpr float minSize = 7.0f; + constexpr float maxSize = 30.0f; + Real scale = Math::Square(Vector3::Distance(position, viewPosition) / 1000.0f); + Real radius = minSize + Math::Min(scale, 1.0f) * (maxSize - minSize); + bounds = BoundingSphere(position, radius * Scale); +} void ViewportIconsRenderer::DrawIcons(RenderContext& renderContext, Actor* actor) { @@ -133,7 +141,8 @@ void ViewportIconsRendererService::DrawIcons(RenderContext& renderContext, Scene AssetReference texture; for (Actor* icon : icons) { - BoundingSphere sphere(icon->GetPosition() - renderContext.View.Origin, ICON_RADIUS); + BoundingSphere sphere; + ViewportIconsRenderer::GetBounds(icon->GetPosition() - renderContext.View.Origin, renderContext.View.Position, sphere); if (!frustum.Intersects(sphere)) continue; IconTypes iconType; @@ -173,7 +182,7 @@ void ViewportIconsRendererService::DrawIcons(RenderContext& renderContext, Scene if (draw.Buffer) { // Create world matrix - Matrix::Scaling(ICON_RADIUS * 2.0f, m2); + Matrix::Scaling(sphere.Radius * 2.0f, m2); Matrix::RotationY(PI, world); Matrix::Multiply(m2, world, m1); Matrix::Billboard(sphere.Center, view.Position, Vector3::Up, view.Direction, m2); @@ -193,14 +202,15 @@ void ViewportIconsRendererService::DrawIcons(RenderContext& renderContext, Actor auto& view = renderContext.View; const BoundingFrustum frustum = view.Frustum; Matrix m1, m2, world; - BoundingSphere sphere(actor->GetPosition() - renderContext.View.Origin, ICON_RADIUS); + BoundingSphere sphere; + ViewportIconsRenderer::GetBounds(actor->GetPosition() - renderContext.View.Origin, renderContext.View.Position, sphere); IconTypes iconType; AssetReference texture; if (frustum.Intersects(sphere) && ActorTypeToIconType.TryGet(actor->GetTypeHandle(), iconType)) { // Create world matrix - Matrix::Scaling(ICON_RADIUS * 2.0f, m2); + Matrix::Scaling(sphere.Radius * 2.0f, m2); Matrix::RotationY(PI, world); Matrix::Multiply(m2, world, m1); Matrix::Billboard(sphere.Center, view.Position, Vector3::Up, view.Direction, m2); diff --git a/Source/Editor/Utilities/ViewportIconsRenderer.h b/Source/Editor/Utilities/ViewportIconsRenderer.h index 8dab1bbf4..c7bf7e1c3 100644 --- a/Source/Editor/Utilities/ViewportIconsRenderer.h +++ b/Source/Editor/Utilities/ViewportIconsRenderer.h @@ -17,6 +17,19 @@ API_CLASS(Static, Namespace="FlaxEditor") class FLAXENGINE_API ViewportIconsRend DECLARE_SCRIPTING_TYPE_NO_SPAWN(ViewportIconsRenderer); public: + /// + /// Global scale of the icons. + /// + API_FIELD() static float Scale; + + /// + /// Draws the icons for the actors in the given scene (or actor tree). + /// + /// The icon position. + /// The viewer position. + /// The computed bounds for the icon. + API_FUNCTION() static void GetBounds(API_PARAM(Ref) const Vector3& position, API_PARAM(Ref) const Vector3& viewPosition, API_PARAM(Out) BoundingSphere& bounds); + /// /// Draws the icons for the actors in the given scene (or actor tree). /// diff --git a/Source/Editor/Viewport/EditorViewport.cs b/Source/Editor/Viewport/EditorViewport.cs index b2bf0f64e..b4af43281 100644 --- a/Source/Editor/Viewport/EditorViewport.cs +++ b/Source/Editor/Viewport/EditorViewport.cs @@ -1002,6 +1002,18 @@ namespace FlaxEditor.Viewport ViewWidgetButtonMenu.VisibleChanged += control => resolutionValue.Value = ResolutionScale; } + // Icons Scale + { + var icons = ViewWidgetButtonMenu.AddButton("Icons"); + icons.CloseMenuOnClick = false; + var iconsValue = new FloatValueBox(ViewportIconsRenderer.Scale, xLocationForExtras, 2, 70.0f, 0.01f, 100.0f, 0.001f) + { + Parent = icons + }; + iconsValue.ValueChanged += () => ViewportIconsRenderer.Scale = iconsValue.Value; + ViewWidgetButtonMenu.VisibleChanged += control => iconsValue.Value = ViewportIconsRenderer.Scale; + } + #endregion View mode widget } From 13b8863f0c926ec431b434fc5515b86fa5146e6f Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 3 Jun 2025 14:51:04 +0200 Subject: [PATCH 11/16] Fix some material nodes height --- Source/Editor/Surface/Archetypes/Material.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Editor/Surface/Archetypes/Material.cs b/Source/Editor/Surface/Archetypes/Material.cs index 37d6801a4..e46b1c6fb 100644 --- a/Source/Editor/Surface/Archetypes/Material.cs +++ b/Source/Editor/Surface/Archetypes/Material.cs @@ -534,7 +534,7 @@ namespace FlaxEditor.Surface.Archetypes Title = "Tangent Vector", Description = "World space tangent vector", Flags = NodeFlags.MaterialGraph, - Size = new Float2(160, 40), + Size = new Float2(160, 30), Elements = new[] { NodeElementArchetype.Factory.Output(0, "Tangent", typeof(Float3), 0), @@ -546,7 +546,7 @@ namespace FlaxEditor.Surface.Archetypes Title = "Bitangent Vector", Description = "World space bitangent vector", Flags = NodeFlags.MaterialGraph, - Size = new Float2(160, 40), + Size = new Float2(160, 30), Elements = new[] { NodeElementArchetype.Factory.Output(0, "Bitangent", typeof(Float3), 0), @@ -558,7 +558,7 @@ namespace FlaxEditor.Surface.Archetypes Title = "Camera Position", Description = "World space camera location", Flags = NodeFlags.MaterialGraph, - Size = new Float2(160, 40), + Size = new Float2(160, 30), Elements = new[] { NodeElementArchetype.Factory.Output(0, "XYZ", typeof(Float3), 0), @@ -570,7 +570,7 @@ namespace FlaxEditor.Surface.Archetypes Title = "Per Instance Random", Description = "Per object instance random value (normalized to range 0-1)", Flags = NodeFlags.MaterialGraph, - Size = new Float2(200, 40), + Size = new Float2(200, 30), Elements = new[] { NodeElementArchetype.Factory.Output(0, "", typeof(float), 0), From 6a0c734cecbb94bcb6ad4b14a9c86e8a665d4048 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 3 Jun 2025 14:51:31 +0200 Subject: [PATCH 12/16] Fix Visject surface select with Control to toggle selection of the node --- Source/Editor/Surface/VisjectSurface.Input.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Source/Editor/Surface/VisjectSurface.Input.cs b/Source/Editor/Surface/VisjectSurface.Input.cs index 95610b73c..a874db681 100644 --- a/Source/Editor/Surface/VisjectSurface.Input.cs +++ b/Source/Editor/Surface/VisjectSurface.Input.cs @@ -488,11 +488,9 @@ namespace FlaxEditor.Surface // Check if user is pressing control if (Root.GetKey(KeyboardKeys.Control)) { - // Add to selection - if (!controlUnderMouse.IsSelected) - { - AddToSelection(controlUnderMouse); - } + // Add/remove from selection + controlUnderMouse.IsSelected = !controlUnderMouse.IsSelected; + SelectionChanged?.Invoke(); } // Check if node isn't selected else if (!controlUnderMouse.IsSelected) From 6f5308126b49f6c9dde3a6f347b5f92f927db891 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 3 Jun 2025 14:52:45 +0200 Subject: [PATCH 13/16] Fix focus issue after closing context menu --- Source/Editor/GUI/ContextMenu/ContextMenuBase.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Source/Editor/GUI/ContextMenu/ContextMenuBase.cs b/Source/Editor/GUI/ContextMenu/ContextMenuBase.cs index d1cffa75d..d7534b15b 100644 --- a/Source/Editor/GUI/ContextMenu/ContextMenuBase.cs +++ b/Source/Editor/GUI/ContextMenu/ContextMenuBase.cs @@ -285,6 +285,17 @@ namespace FlaxEditor.GUI.ContextMenu } } + private static void ForceDefocus(ContainerControl c) + { + foreach (var cc in c.Children) + { + if (cc.ContainsFocus) + cc.Defocus(); + if (cc is ContainerControl ccc) + ForceDefocus(ccc); + } + } + /// /// Hide popup menu and all child menus. /// @@ -299,6 +310,9 @@ namespace FlaxEditor.GUI.ContextMenu // Close child HideChild(); + // Force defocus + ForceDefocus(this); + // Unlink from window Parent = null; From 1946caac6e3e52c3e319673cef0cdb80a0de9f9c Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 3 Jun 2025 17:26:04 +0200 Subject: [PATCH 14/16] Fix compilation with Large Worlds --- Source/Editor/Utilities/ViewportIconsRenderer.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/Editor/Utilities/ViewportIconsRenderer.cpp b/Source/Editor/Utilities/ViewportIconsRenderer.cpp index ccfa876bd..1f721d289 100644 --- a/Source/Editor/Utilities/ViewportIconsRenderer.cpp +++ b/Source/Editor/Utilities/ViewportIconsRenderer.cpp @@ -68,10 +68,10 @@ float ViewportIconsRenderer::Scale = 1.0f; void ViewportIconsRenderer::GetBounds(const Vector3& position, const Vector3& viewPosition, BoundingSphere& bounds) { - constexpr float minSize = 7.0f; - constexpr float maxSize = 30.0f; + constexpr Real minSize = 7.0; + constexpr Real maxSize = 30.0; Real scale = Math::Square(Vector3::Distance(position, viewPosition) / 1000.0f); - Real radius = minSize + Math::Min(scale, 1.0f) * (maxSize - minSize); + Real radius = minSize + Math::Min(scale, 1.0f) * (maxSize - minSize); bounds = BoundingSphere(position, radius * Scale); } @@ -182,7 +182,7 @@ void ViewportIconsRendererService::DrawIcons(RenderContext& renderContext, Scene if (draw.Buffer) { // Create world matrix - Matrix::Scaling(sphere.Radius * 2.0f, m2); + Matrix::Scaling((float)sphere.Radius * 2.0f, m2); Matrix::RotationY(PI, world); Matrix::Multiply(m2, world, m1); Matrix::Billboard(sphere.Center, view.Position, Vector3::Up, view.Direction, m2); @@ -210,7 +210,7 @@ void ViewportIconsRendererService::DrawIcons(RenderContext& renderContext, Actor if (frustum.Intersects(sphere) && ActorTypeToIconType.TryGet(actor->GetTypeHandle(), iconType)) { // Create world matrix - Matrix::Scaling(sphere.Radius * 2.0f, m2); + Matrix::Scaling((float)sphere.Radius * 2.0f, m2); Matrix::RotationY(PI, world); Matrix::Multiply(m2, world, m1); Matrix::Billboard(sphere.Center, view.Position, Vector3::Up, view.Direction, m2); From 8b88def9d05a1d9a8295777ab928dfe95821ec39 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 3 Jun 2025 17:43:01 +0200 Subject: [PATCH 15/16] Revert some changes from #3389 that are not relevant for world units --- Source/Editor/CustomEditors/GUI/PropertiesList.cs | 2 +- Source/Editor/GUI/CurveEditor.cs | 2 +- Source/Editor/GUI/Table.cs | 2 +- Source/Editor/GUI/Timeline/GUI/KeyframesEditor.cs | 2 +- Source/Editor/GUI/Timeline/Timeline.cs | 4 ++-- Source/Editor/GUI/Timeline/Tracks/AudioTrack.cs | 2 +- Source/Editor/GUI/Tree/TreeNode.cs | 2 +- Source/Editor/Tools/Foliage/FoliageTypesTab.cs | 6 +++--- .../Editor/Viewport/Previews/CubeTexturePreview.cs | 2 +- .../Viewport/Previews/ParticleEmitterPreview.cs | 2 +- Source/Editor/Viewport/Previews/TexturePreview.cs | 2 +- Source/Engine/Animations/Curve.h | 8 ++++---- Source/Engine/Audio/Audio.cpp | 2 +- Source/Engine/Audio/AudioSource.cpp | 14 +++++++------- Source/Engine/ContentImporters/CreateMaterial.cpp | 2 +- Source/Engine/Core/Math/Viewport.cs | 12 ++++++------ Source/Engine/Foliage/Foliage.cpp | 2 +- Source/Engine/Graphics/Materials/MaterialInfo.cs | 4 ++-- .../Engine/Graphics/Materials/MaterialParams.cpp | 12 ++++++------ .../Graphics/Textures/GPUSamplerDescription.cs | 6 +++--- Source/Engine/Render2D/TextLayoutOptions.h | 4 ++-- Source/Engine/Renderer/ShadowsPass.cpp | 12 ++++++------ Source/Engine/UI/GUI/CanvasScaler.cs | 8 ++++---- Source/Engine/UI/GUI/Common/ProgressBar.cs | 2 +- Source/Engine/UI/GUI/Common/Slider.cs | 2 +- Source/Engine/UI/GUI/Control.Bounds.cs | 9 +++++---- Source/Engine/UI/GUI/Margin.cs | 8 ++++---- Source/Engine/UI/GUI/Panels/DropPanel.cs | 2 +- Source/Engine/UI/GUI/Panels/Panel.cs | 2 +- Source/Engine/UI/GUI/Panels/PanelWithMargins.cs | 12 ++++++------ Source/Engine/UI/GUI/Panels/ScrollBar.cs | 6 +++--- Source/Engine/UI/GUI/Panels/SplitPanel.cs | 2 +- Source/Engine/Video/VideoPlayer.cpp | 8 ++++---- 33 files changed, 84 insertions(+), 83 deletions(-) diff --git a/Source/Editor/CustomEditors/GUI/PropertiesList.cs b/Source/Editor/CustomEditors/GUI/PropertiesList.cs index f9e6318b4..ef90fc706 100644 --- a/Source/Editor/CustomEditors/GUI/PropertiesList.cs +++ b/Source/Editor/CustomEditors/GUI/PropertiesList.cs @@ -38,7 +38,7 @@ namespace FlaxEditor.CustomEditors.GUI set { value = Mathf.Clamp(value, 0.05f, 0.95f); - if (_splitterValue != value) + if (!Mathf.NearEqual(_splitterValue, value)) { _splitterValue = value; UpdateSplitRect(); diff --git a/Source/Editor/GUI/CurveEditor.cs b/Source/Editor/GUI/CurveEditor.cs index de83151ab..706d07b32 100644 --- a/Source/Editor/GUI/CurveEditor.cs +++ b/Source/Editor/GUI/CurveEditor.cs @@ -385,7 +385,7 @@ namespace FlaxEditor.GUI get => _fps; set { - if (_fps.HasValue == value.HasValue && (!value.HasValue || _fps.Value == value.Value)) + if (_fps.HasValue == value.HasValue && (!value.HasValue || Mathf.NearEqual(_fps.Value, value.Value))) return; _fps = value; diff --git a/Source/Editor/GUI/Table.cs b/Source/Editor/GUI/Table.cs index 3e2de92c5..71b01aa0f 100644 --- a/Source/Editor/GUI/Table.cs +++ b/Source/Editor/GUI/Table.cs @@ -28,7 +28,7 @@ namespace FlaxEditor.GUI set { value = Mathf.Max(value, 1); - if (value != _headerHeight) + if (!Mathf.NearEqual(value, _headerHeight)) { _headerHeight = value; PerformLayout(); diff --git a/Source/Editor/GUI/Timeline/GUI/KeyframesEditor.cs b/Source/Editor/GUI/Timeline/GUI/KeyframesEditor.cs index f02936b8f..d6fa0e076 100644 --- a/Source/Editor/GUI/Timeline/GUI/KeyframesEditor.cs +++ b/Source/Editor/GUI/Timeline/GUI/KeyframesEditor.cs @@ -692,7 +692,7 @@ namespace FlaxEditor.GUI get => _fps; set { - if (_fps.HasValue == value.HasValue && (!value.HasValue || _fps.Value == value.Value)) + if (_fps.HasValue == value.HasValue && (!value.HasValue || Mathf.NearEqual(_fps.Value, value.Value))) return; _fps = value; diff --git a/Source/Editor/GUI/Timeline/Timeline.cs b/Source/Editor/GUI/Timeline/Timeline.cs index fb6e4cf07..15e7eb953 100644 --- a/Source/Editor/GUI/Timeline/Timeline.cs +++ b/Source/Editor/GUI/Timeline/Timeline.cs @@ -319,7 +319,7 @@ namespace FlaxEditor.GUI.Timeline set { value = Mathf.Clamp(value, 0.1f, 1000.0f); - if (_framesPerSecond == value) + if (Mathf.NearEqual(_framesPerSecond, value)) return; Undo?.AddAction(new EditFpsAction(this, _framesPerSecond, value)); @@ -508,7 +508,7 @@ namespace FlaxEditor.GUI.Timeline set { value = Mathf.Clamp(value, 0.00001f, 1000.0f); - if (_zoom == value) + if (Mathf.NearEqual(_zoom, value)) return; _zoom = value; diff --git a/Source/Editor/GUI/Timeline/Tracks/AudioTrack.cs b/Source/Editor/GUI/Timeline/Tracks/AudioTrack.cs index b17c18b8c..75c5788a7 100644 --- a/Source/Editor/GUI/Timeline/Tracks/AudioTrack.cs +++ b/Source/Editor/GUI/Timeline/Tracks/AudioTrack.cs @@ -41,7 +41,7 @@ namespace FlaxEditor.GUI.Timeline.Tracks get => Preview.ViewOffset; set { - if (Preview.ViewOffset == value) + if (Mathf.NearEqual(Preview.ViewOffset, value)) return; Preview.ViewOffset = value; Timeline?.MarkAsEdited(); diff --git a/Source/Editor/GUI/Tree/TreeNode.cs b/Source/Editor/GUI/Tree/TreeNode.cs index a46d9ef96..40c276bf4 100644 --- a/Source/Editor/GUI/Tree/TreeNode.cs +++ b/Source/Editor/GUI/Tree/TreeNode.cs @@ -214,7 +214,7 @@ namespace FlaxEditor.GUI.Tree get => _headerHeight; set { - if (_headerHeight != value) + if (!Mathf.NearEqual(_headerHeight, value)) { _headerHeight = value; PerformLayout(); diff --git a/Source/Editor/Tools/Foliage/FoliageTypesTab.cs b/Source/Editor/Tools/Foliage/FoliageTypesTab.cs index 0d3b1ec95..3094d2a77 100644 --- a/Source/Editor/Tools/Foliage/FoliageTypesTab.cs +++ b/Source/Editor/Tools/Foliage/FoliageTypesTab.cs @@ -107,7 +107,7 @@ namespace FlaxEditor.Tools.Foliage get => _type.CullDistance; set { - if (_type.CullDistance == value) + if (Mathf.NearEqual(_type.CullDistance, value)) return; _type.CullDistance = value; Foliage.UpdateCullDistance(); @@ -120,7 +120,7 @@ namespace FlaxEditor.Tools.Foliage get => _type.CullDistanceRandomRange; set { - if (_type.CullDistanceRandomRange == value) + if (Mathf.NearEqual(_type.CullDistanceRandomRange, value)) return; _type.CullDistanceRandomRange = value; Foliage.UpdateCullDistance(); @@ -174,7 +174,7 @@ namespace FlaxEditor.Tools.Foliage get => _type.DensityScalingScale; set { - if (_type.DensityScalingScale == value) + if (Mathf.NearEqual(_type.DensityScalingScale, value)) return; _type.DensityScalingScale = value; Foliage.RebuildClusters(); diff --git a/Source/Editor/Viewport/Previews/CubeTexturePreview.cs b/Source/Editor/Viewport/Previews/CubeTexturePreview.cs index 9c7c9e6e9..f0b05c8e6 100644 --- a/Source/Editor/Viewport/Previews/CubeTexturePreview.cs +++ b/Source/Editor/Viewport/Previews/CubeTexturePreview.cs @@ -95,7 +95,7 @@ namespace FlaxEditor.Viewport.Previews get => _mipLevel; set { - if (_mipLevel == value) + if (!Mathf.NearEqual(_mipLevel, value)) { _mipLevel = value; _previewMaterial.SetParameterValue("Mip", value); diff --git a/Source/Editor/Viewport/Previews/ParticleEmitterPreview.cs b/Source/Editor/Viewport/Previews/ParticleEmitterPreview.cs index cb05016b9..023bd121f 100644 --- a/Source/Editor/Viewport/Previews/ParticleEmitterPreview.cs +++ b/Source/Editor/Viewport/Previews/ParticleEmitterPreview.cs @@ -42,7 +42,7 @@ namespace FlaxEditor.Viewport.Previews set { value = Mathf.Clamp(value, 0.1f, 100000000000.0f); - if (_playbackDuration == value) + if (Mathf.NearEqual(_playbackDuration, value)) return; _playbackDuration = value; diff --git a/Source/Editor/Viewport/Previews/TexturePreview.cs b/Source/Editor/Viewport/Previews/TexturePreview.cs index b8f801035..709bc953e 100644 --- a/Source/Editor/Viewport/Previews/TexturePreview.cs +++ b/Source/Editor/Viewport/Previews/TexturePreview.cs @@ -303,7 +303,7 @@ namespace FlaxEditor.Viewport.Previews get => _mipLevel; set { - if (_mipLevel != value) + if (!Mathf.NearEqual(_mipLevel, value)) { _mipLevel = value; _previewMaterial.SetParameterValue("Mip", value); diff --git a/Source/Engine/Animations/Curve.h b/Source/Engine/Animations/Curve.h index 8508d8751..11142d1e4 100644 --- a/Source/Engine/Animations/Curve.h +++ b/Source/Engine/Animations/Curve.h @@ -58,7 +58,7 @@ public: bool operator==(const StepCurveKeyframe& other) const { - return Time == other.Time && Value == other.Value; + return Math::NearEqual(Time, other.Time) && Math::NearEqual(Value, other.Value); } } PACK_END(); @@ -113,7 +113,7 @@ public: bool operator==(const LinearCurveKeyframe& other) const { - return Time == other.Time && Value == other.Value; + return Math::NearEqual(Time, other.Time) && Math::NearEqual(Value, other.Value); } } PACK_END(); @@ -188,7 +188,7 @@ public: bool operator==(const HermiteCurveKeyframe& other) const { - return Time == other.Time && Value == other.Value && TangentIn == other.TangentIn && TangentOut == other.TangentOut; + return Math::NearEqual(Time, other.Time) && Math::NearEqual(Value, other.Value) && Math::NearEqual(TangentIn, other.TangentIn) && Math::NearEqual(TangentOut, other.TangentOut); } } PACK_END(); @@ -276,7 +276,7 @@ public: bool operator==(const BezierCurveKeyframe& other) const { - return Time == other.Time && Value == other.Value && TangentIn == other.TangentIn && TangentOut == other.TangentOut; + return Math::NearEqual(Time, other.Time) && Math::NearEqual(Value, other.Value) && Math::NearEqual(TangentIn, other.TangentIn) && Math::NearEqual(TangentOut, other.TangentOut); } } PACK_END(); diff --git a/Source/Engine/Audio/Audio.cpp b/Source/Engine/Audio/Audio.cpp index 2a2d30d5c..e19efabf1 100644 --- a/Source/Engine/Audio/Audio.cpp +++ b/Source/Engine/Audio/Audio.cpp @@ -219,7 +219,7 @@ void AudioService::Update() // Mute audio if app has no user focus masterVolume = 0.0f; } - if (Volume != masterVolume) + if (Math::NotNearEqual(Volume, masterVolume)) { Volume = masterVolume; AudioBackend::SetVolume(masterVolume); diff --git a/Source/Engine/Audio/AudioSource.cpp b/Source/Engine/Audio/AudioSource.cpp index ab17910fd..cff89e7e1 100644 --- a/Source/Engine/Audio/AudioSource.cpp +++ b/Source/Engine/Audio/AudioSource.cpp @@ -29,7 +29,7 @@ AudioSource::AudioSource(const SpawnParams& params) void AudioSource::SetVolume(float value) { value = Math::Saturate(value); - if (_volume == value) + if (Math::NearEqual(_volume, value)) return; _volume = value; if (SourceID) @@ -39,7 +39,7 @@ void AudioSource::SetVolume(float value) void AudioSource::SetPitch(float value) { value = Math::Clamp(value, 0.5f, 2.0f); - if (_pitch == value) + if (Math::NearEqual(_pitch, value)) return; _pitch = value; if (SourceID) @@ -49,7 +49,7 @@ void AudioSource::SetPitch(float value) void AudioSource::SetPan(float value) { value = Math::Clamp(value, -1.0f, 1.0f); - if (_pan == value) + if (Math::NearEqual(_pan, value)) return; _pan = value; if (SourceID) @@ -80,7 +80,7 @@ void AudioSource::SetStartTime(float value) void AudioSource::SetMinDistance(float value) { value = Math::Max(0.0f, value); - if (_minDistance == value) + if (Math::NearEqual(_minDistance, value)) return; _minDistance = value; if (SourceID) @@ -90,7 +90,7 @@ void AudioSource::SetMinDistance(float value) void AudioSource::SetAttenuation(float value) { value = Math::Max(0.0f, value); - if (_attenuation == value) + if (Math::NearEqual(_attenuation, value)) return; _attenuation = value; if (SourceID) @@ -100,7 +100,7 @@ void AudioSource::SetAttenuation(float value) void AudioSource::SetDopplerFactor(float value) { value = Math::Max(0.0f, value); - if (_dopplerFactor == value) + if (Math::NearEqual(_dopplerFactor, value)) return; _dopplerFactor = value; if (SourceID) @@ -401,7 +401,7 @@ void AudioSource::Update() _startingToPlay = false; } - if (!UseStreaming() && GetTime() == 0.0f && _isActuallyPlayingSth && !_startingToPlay) + if (!UseStreaming() && Math::NearEqual(GetTime(), 0.0f) && _isActuallyPlayingSth && !_startingToPlay) { int32 queuedBuffers; AudioBackend::Source::GetQueuedBuffersCount(SourceID, queuedBuffers); diff --git a/Source/Engine/ContentImporters/CreateMaterial.cpp b/Source/Engine/ContentImporters/CreateMaterial.cpp index 4cedf0c85..3991585a3 100644 --- a/Source/Engine/ContentImporters/CreateMaterial.cpp +++ b/Source/Engine/ContentImporters/CreateMaterial.cpp @@ -20,7 +20,7 @@ namespace template ShaderGraphNode<>* AddValueNode(MaterialLayer* layer, const float& value, const float& defaultValue) { - if (value == defaultValue) + if (Math::NearEqual(value, defaultValue)) return nullptr; auto& node = layer->Graph.Nodes.AddOne(); node.ID = layer->Graph.Nodes.Count(); diff --git a/Source/Engine/Core/Math/Viewport.cs b/Source/Engine/Core/Math/Viewport.cs index f42c1f22a..f2be10457 100644 --- a/Source/Engine/Core/Math/Viewport.cs +++ b/Source/Engine/Core/Math/Viewport.cs @@ -173,12 +173,12 @@ namespace FlaxEngine /// true if the specified is equal to this instance; otherwise, false. public bool Equals(ref Viewport other) { - return X == other.X && - Y == other.Y && - Width == other.Width && - Height == other.Height && - MinDepth == other.MinDepth && - MaxDepth == other.MaxDepth; + return Mathf.NearEqual(X, other.X) && + Mathf.NearEqual(Y, other.Y) && + Mathf.NearEqual(Width, other.Width) && + Mathf.NearEqual(Height, other.Height) && + Mathf.NearEqual(MinDepth, other.MinDepth) && + Mathf.NearEqual(MaxDepth, other.MaxDepth); } /// diff --git a/Source/Engine/Foliage/Foliage.cpp b/Source/Engine/Foliage/Foliage.cpp index 051450297..a1cd046ae 100644 --- a/Source/Engine/Foliage/Foliage.cpp +++ b/Source/Engine/Foliage/Foliage.cpp @@ -1013,7 +1013,7 @@ bool UpdateFoliageDensityScaling(Actor* actor) void Foliage::SetGlobalDensityScale(float value) { value = Math::Saturate(value); - if (value == GlobalDensityScale) + if (Math::NearEqual(value, GlobalDensityScale)) return; PROFILE_CPU(); diff --git a/Source/Engine/Graphics/Materials/MaterialInfo.cs b/Source/Engine/Graphics/Materials/MaterialInfo.cs index b0a78a6eb..a8ff82665 100644 --- a/Source/Engine/Graphics/Materials/MaterialInfo.cs +++ b/Source/Engine/Graphics/Materials/MaterialInfo.cs @@ -64,8 +64,8 @@ namespace FlaxEngine && DecalBlendingMode == other.DecalBlendingMode && TransparentLightingMode == other.TransparentLightingMode && PostFxLocation == other.PostFxLocation - && MaskThreshold == other.MaskThreshold - && OpacityThreshold == other.OpacityThreshold + && Mathf.NearEqual(MaskThreshold, other.MaskThreshold) + && Mathf.NearEqual(OpacityThreshold, other.OpacityThreshold) && TessellationMode == other.TessellationMode && MaxTessellationFactor == other.MaxTessellationFactor; } diff --git a/Source/Engine/Graphics/Materials/MaterialParams.cpp b/Source/Engine/Graphics/Materials/MaterialParams.cpp index d2a4855b5..e31697f77 100644 --- a/Source/Engine/Graphics/Materials/MaterialParams.cpp +++ b/Source/Engine/Graphics/Materials/MaterialParams.cpp @@ -24,8 +24,8 @@ bool MaterialInfo8::operator==(const MaterialInfo8& other) const && TransparentLighting == other.TransparentLighting && DecalBlendingMode == other.DecalBlendingMode && PostFxLocation == other.PostFxLocation - && MaskThreshold == other.MaskThreshold - && OpacityThreshold == other.OpacityThreshold + && Math::NearEqual(MaskThreshold, other.MaskThreshold) + && Math::NearEqual(OpacityThreshold, other.OpacityThreshold) && Flags == other.Flags && TessellationMode == other.TessellationMode && MaxTessellationFactor == other.MaxTessellationFactor; @@ -89,8 +89,8 @@ bool MaterialInfo9::operator==(const MaterialInfo9& other) const && DecalBlendingMode == other.DecalBlendingMode && PostFxLocation == other.PostFxLocation && CullMode == other.CullMode - && MaskThreshold == other.MaskThreshold - && OpacityThreshold == other.OpacityThreshold + && Math::NearEqual(MaskThreshold, other.MaskThreshold) + && Math::NearEqual(OpacityThreshold, other.OpacityThreshold) && TessellationMode == other.TessellationMode && MaxTessellationFactor == other.MaxTessellationFactor; } @@ -123,8 +123,8 @@ bool MaterialInfo::operator==(const MaterialInfo& other) const && TransparentLightingMode == other.TransparentLightingMode && PostFxLocation == other.PostFxLocation && CullMode == other.CullMode - && MaskThreshold == other.MaskThreshold - && OpacityThreshold == other.OpacityThreshold + && Math::NearEqual(MaskThreshold, other.MaskThreshold) + && Math::NearEqual(OpacityThreshold, other.OpacityThreshold) && TessellationMode == other.TessellationMode && MaxTessellationFactor == other.MaxTessellationFactor; } diff --git a/Source/Engine/Graphics/Textures/GPUSamplerDescription.cs b/Source/Engine/Graphics/Textures/GPUSamplerDescription.cs index 425f28fe6..6a49ce49d 100644 --- a/Source/Engine/Graphics/Textures/GPUSamplerDescription.cs +++ b/Source/Engine/Graphics/Textures/GPUSamplerDescription.cs @@ -40,9 +40,9 @@ namespace FlaxEngine AddressU == other.AddressU && AddressV == other.AddressV && AddressW == other.AddressW && - MipBias == other.MipBias && - MinMipLevel == other.MinMipLevel && - MaxMipLevel == other.MaxMipLevel && + Mathf.NearEqual(MipBias, other.MipBias) && + Mathf.NearEqual(MinMipLevel, other.MinMipLevel) && + Mathf.NearEqual(MaxMipLevel, other.MaxMipLevel) && MaxAnisotropy == other.MaxAnisotropy && BorderColor == other.BorderColor && ComparisonFunction == other.ComparisonFunction; diff --git a/Source/Engine/Render2D/TextLayoutOptions.h b/Source/Engine/Render2D/TextLayoutOptions.h index 5aa84fe5a..75e3b1ea2 100644 --- a/Source/Engine/Render2D/TextLayoutOptions.h +++ b/Source/Engine/Render2D/TextLayoutOptions.h @@ -108,8 +108,8 @@ DECLARE_SCRIPTING_TYPE_MINIMAL(TextLayoutOptions); && HorizontalAlignment == other.HorizontalAlignment && VerticalAlignment == other.VerticalAlignment && TextWrapping == other.TextWrapping - && Scale == other.Scale - && BaseLinesGapScale == other.BaseLinesGapScale; + && Math::NearEqual(Scale, other.Scale) + && Math::NearEqual(BaseLinesGapScale, other.BaseLinesGapScale); } FORCE_INLINE bool operator!=(const TextLayoutOptions& other) const diff --git a/Source/Engine/Renderer/ShadowsPass.cpp b/Source/Engine/Renderer/ShadowsPass.cpp index 374b26347..3937f8554 100644 --- a/Source/Engine/Renderer/ShadowsPass.cpp +++ b/Source/Engine/Renderer/ShadowsPass.cpp @@ -236,9 +236,9 @@ struct ShadowAtlasLight { if (!Cache.StaticValid || !Cache.DynamicValid) return; - if (Cache.Distance != light.ShadowsDistance || - Cache.ShadowsUpdateRate != light.ShadowsUpdateRate || - Cache.ShadowsUpdateRateAtDistance != light.ShadowsUpdateRateAtDistance || + if (!Math::NearEqual(Cache.Distance, light.ShadowsDistance) || + !Math::NearEqual(Cache.ShadowsUpdateRate, light.ShadowsUpdateRate) || + !Math::NearEqual(Cache.ShadowsUpdateRateAtDistance, light.ShadowsUpdateRateAtDistance) || Cache.ShadowFrame != light.ShadowFrame || Cache.ShadowsResolution != light.ShadowsResolution || Float3::Dot(Cache.Direction, light.Direction) < SHADOWS_ROTATION_ERROR) @@ -250,7 +250,7 @@ struct ShadowAtlasLight { // Sun if (!Float3::NearEqual(Cache.Position, view.Position, SHADOWS_POSITION_ERROR) || - Cache.CascadeSplits != CascadeSplits || + !Float4::NearEqual(Cache.CascadeSplits, CascadeSplits) || Float3::Dot(Cache.ViewDirection, view.Direction) < SHADOWS_ROTATION_ERROR) { // Invalidate @@ -262,12 +262,12 @@ struct ShadowAtlasLight // Local light const auto& localLight = (const RenderLocalLightData&)light; if (!Float3::NearEqual(Cache.Position, light.Position, SHADOWS_POSITION_ERROR) || - Cache.Radius != localLight.Radius) + !Math::NearEqual(Cache.Radius, localLight.Radius)) { // Invalidate Cache.StaticValid = false; } - if (light.IsSpotLight && Cache.OuterConeAngle != ((const RenderSpotLightData&)light).OuterConeAngle) + if (light.IsSpotLight && !Math::NearEqual(Cache.OuterConeAngle, ((const RenderSpotLightData&)light).OuterConeAngle)) { // Invalidate Cache.StaticValid = false; diff --git a/Source/Engine/UI/GUI/CanvasScaler.cs b/Source/Engine/UI/GUI/CanvasScaler.cs index 463e13237..6bd18ea51 100644 --- a/Source/Engine/UI/GUI/CanvasScaler.cs +++ b/Source/Engine/UI/GUI/CanvasScaler.cs @@ -132,7 +132,7 @@ namespace FlaxEngine.GUI get => _scaleFactor; set { - if (_scaleFactor == value) + if (Mathf.NearEqual(_scaleFactor, value)) return; _scaleFactor = value; PerformLayout(); @@ -175,7 +175,7 @@ namespace FlaxEngine.GUI get => _physicalUnitSize; set { - if (_physicalUnitSize == value) + if (Mathf.NearEqual(_physicalUnitSize, value)) return; _physicalUnitSize = value; PerformLayout(); @@ -212,7 +212,7 @@ namespace FlaxEngine.GUI set { value = Float2.Max(value, Float2.One); - if (_resolutionMin == value) + if (Float2.NearEqual(ref _resolutionMin, ref value)) return; _resolutionMin = value; PerformLayout(); @@ -231,7 +231,7 @@ namespace FlaxEngine.GUI set { value = Float2.Max(value, Float2.One); - if (_resolutionMax == value) + if (Float2.NearEqual(ref _resolutionMax, ref value)) return; _resolutionMax = value; PerformLayout(); diff --git a/Source/Engine/UI/GUI/Common/ProgressBar.cs b/Source/Engine/UI/GUI/Common/ProgressBar.cs index 8abb87cc8..d569c3f4c 100644 --- a/Source/Engine/UI/GUI/Common/ProgressBar.cs +++ b/Source/Engine/UI/GUI/Common/ProgressBar.cs @@ -140,7 +140,7 @@ namespace FlaxEngine.GUI set { value = Mathf.Clamp(value, _minimum, _maximum); - if (value != _value) + if (!Mathf.NearEqual(value, _value)) { _value = value; if (!UseSmoothing || _firstUpdate) diff --git a/Source/Engine/UI/GUI/Common/Slider.cs b/Source/Engine/UI/GUI/Common/Slider.cs index 8bf6f867a..c1e7cd9f6 100644 --- a/Source/Engine/UI/GUI/Common/Slider.cs +++ b/Source/Engine/UI/GUI/Common/Slider.cs @@ -114,7 +114,7 @@ public class Slider : ContainerControl value = Mathf.Clamp(value, Minimum, Maximum); if (WholeNumbers) value = Mathf.RoundToInt(value); - if (value != _value) + if (!Mathf.NearEqual(value, _value)) { _value = value; diff --git a/Source/Engine/UI/GUI/Control.Bounds.cs b/Source/Engine/UI/GUI/Control.Bounds.cs index 2b517a9f0..62bffd6f7 100644 --- a/Source/Engine/UI/GUI/Control.Bounds.cs +++ b/Source/Engine/UI/GUI/Control.Bounds.cs @@ -189,7 +189,7 @@ namespace FlaxEngine.GUI get => _bounds.Size.X; set { - if (_bounds.Size.X == value) + if (Mathf.NearEqual(_bounds.Size.X, value)) return; var bounds = new Rectangle(_bounds.Location, value, _bounds.Size.Y); if (_pivotRelativeSizing) @@ -210,7 +210,7 @@ namespace FlaxEngine.GUI get => _bounds.Size.Y; set { - if (_bounds.Size.Y == value) + if (Mathf.NearEqual(_bounds.Size.Y, value)) return; var bounds = new Rectangle(_bounds.Location, _bounds.Size.X, value); if (_pivotRelativeSizing) @@ -412,7 +412,7 @@ namespace FlaxEngine.GUI get => _rotation; set { - if (_rotation != value) + if (!Mathf.NearEqual(_rotation, value)) { SetRotationInternal(value); } @@ -598,7 +598,8 @@ namespace FlaxEngine.GUI var anchorMin = AnchorPresetsData[i].Min; var anchorMax = AnchorPresetsData[i].Max; var bounds = _bounds; - if (_anchorMin != anchorMin || _anchorMax != anchorMax) + if (!Float2.NearEqual(ref _anchorMin, ref anchorMin) || + !Float2.NearEqual(ref _anchorMax, ref anchorMax)) { // Disable scrolling for anchored controls (by default but can be manually restored) if (!anchorMin.IsZero || !anchorMax.IsZero) diff --git a/Source/Engine/UI/GUI/Margin.cs b/Source/Engine/UI/GUI/Margin.cs index f04e13b0a..c19d06f09 100644 --- a/Source/Engine/UI/GUI/Margin.cs +++ b/Source/Engine/UI/GUI/Margin.cs @@ -251,10 +251,10 @@ namespace FlaxEngine.GUI /// true if the specified is equal to this instance; otherwise, false. public bool Equals(ref Margin other) { - return other.Left == Left && - other.Right == Right && - other.Top == Top && - other.Bottom == Bottom; + return Mathf.NearEqual(other.Left, Left) && + Mathf.NearEqual(other.Right, Right) && + Mathf.NearEqual(other.Top, Top) && + Mathf.NearEqual(other.Bottom, Bottom); } /// diff --git a/Source/Engine/UI/GUI/Panels/DropPanel.cs b/Source/Engine/UI/GUI/Panels/DropPanel.cs index 5e0bdb010..0bfa799c2 100644 --- a/Source/Engine/UI/GUI/Panels/DropPanel.cs +++ b/Source/Engine/UI/GUI/Panels/DropPanel.cs @@ -76,7 +76,7 @@ namespace FlaxEngine.GUI get => _headerHeight; set { - if (_headerHeight != value) + if (!Mathf.NearEqual(_headerHeight, value)) { _headerHeight = value; PerformLayout(); diff --git a/Source/Engine/UI/GUI/Panels/Panel.cs b/Source/Engine/UI/GUI/Panels/Panel.cs index 4a1cdffa2..ff5483d0f 100644 --- a/Source/Engine/UI/GUI/Panels/Panel.cs +++ b/Source/Engine/UI/GUI/Panels/Panel.cs @@ -130,7 +130,7 @@ namespace FlaxEngine.GUI get => _scrollBarsSize; set { - if (_scrollBarsSize == value) + if (Mathf.NearEqual(_scrollBarsSize, value)) return; _scrollBarsSize = value; PerformLayout(); diff --git a/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs b/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs index c613eb71e..52222946e 100644 --- a/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs +++ b/Source/Engine/UI/GUI/Panels/PanelWithMargins.cs @@ -44,7 +44,7 @@ namespace FlaxEngine.GUI get => _margin.Left; set { - if (_margin.Left != value) + if (!Mathf.NearEqual(_margin.Left, value)) { _margin.Left = value; PerformLayout(); @@ -61,7 +61,7 @@ namespace FlaxEngine.GUI get => _margin.Right; set { - if (_margin.Right != value) + if (!Mathf.NearEqual(_margin.Right, value)) { _margin.Right = value; PerformLayout(); @@ -78,7 +78,7 @@ namespace FlaxEngine.GUI get => _margin.Top; set { - if (_margin.Top != value) + if (!Mathf.NearEqual(_margin.Top, value)) { _margin.Top = value; PerformLayout(); @@ -95,7 +95,7 @@ namespace FlaxEngine.GUI get => _margin.Bottom; set { - if (_margin.Bottom != value) + if (!Mathf.NearEqual(_margin.Bottom, value)) { _margin.Bottom = value; PerformLayout(); @@ -112,7 +112,7 @@ namespace FlaxEngine.GUI get => _spacing; set { - if (_spacing != value) + if (!Mathf.NearEqual(_spacing, value)) { _spacing = value; PerformLayout(); @@ -129,7 +129,7 @@ namespace FlaxEngine.GUI get => _offset; set { - if (_offset != value) + if (!Float2.NearEqual(ref _offset, ref value)) { _offset = value; PerformLayout(); diff --git a/Source/Engine/UI/GUI/Panels/ScrollBar.cs b/Source/Engine/UI/GUI/Panels/ScrollBar.cs index 9381dd0bb..756c698c5 100644 --- a/Source/Engine/UI/GUI/Panels/ScrollBar.cs +++ b/Source/Engine/UI/GUI/Panels/ScrollBar.cs @@ -132,7 +132,7 @@ namespace FlaxEngine.GUI set { value = Mathf.Clamp(value, _minimum, _maximum); - if (value != _targetValue) + if (!Mathf.NearEqual(value, _targetValue)) { _targetValue = value; _startValue = _value; @@ -163,7 +163,7 @@ namespace FlaxEngine.GUI set { value = Mathf.Clamp(value, _minimum, _maximum); - if (value != _targetValue) + if (!Mathf.NearEqual(value, _targetValue)) { _targetValue = value; _value = value; @@ -237,7 +237,7 @@ namespace FlaxEngine.GUI /// public void FastScroll() { - if (_value != _targetValue) + if (!Mathf.NearEqual(_value, _targetValue)) { _value = _targetValue = _startValue; _scrollAnimationProgress = 0f; diff --git a/Source/Engine/UI/GUI/Panels/SplitPanel.cs b/Source/Engine/UI/GUI/Panels/SplitPanel.cs index cfa6acf25..060459723 100644 --- a/Source/Engine/UI/GUI/Panels/SplitPanel.cs +++ b/Source/Engine/UI/GUI/Panels/SplitPanel.cs @@ -67,7 +67,7 @@ namespace FlaxEngine.GUI set { value = Mathf.Saturate(value); - if (_splitterValue != value) + if (!Mathf.NearEqual(_splitterValue, value)) { // Set new value _splitterValue = value; diff --git a/Source/Engine/Video/VideoPlayer.cpp b/Source/Engine/Video/VideoPlayer.cpp index dba1f0000..59f8d2438 100644 --- a/Source/Engine/Video/VideoPlayer.cpp +++ b/Source/Engine/Video/VideoPlayer.cpp @@ -42,7 +42,7 @@ void VideoPlayer::SetIsAudioSpatial(bool value) void VideoPlayer::SetAudioVolume(float value) { value = Math::Saturate(value); - if (_volume == value) + if (Math::NearEqual(_volume, value)) return; _volume = value; UpdateInfo(); @@ -51,7 +51,7 @@ void VideoPlayer::SetAudioVolume(float value) void VideoPlayer::SetAudioPan(float value) { value = Math::Clamp(value, -1.0f, 1.0f); - if (_pan == value) + if (Math::NearEqual(_pan, value)) return; _pan = value; UpdateInfo(); @@ -60,7 +60,7 @@ void VideoPlayer::SetAudioPan(float value) void VideoPlayer::SetAudioMinDistance(float value) { value = Math::Max(0.0f, value); - if (_minDistance == value) + if (Math::NearEqual(_minDistance, value)) return; _minDistance = value; UpdateInfo(); @@ -69,7 +69,7 @@ void VideoPlayer::SetAudioMinDistance(float value) void VideoPlayer::SetAudioAttenuation(float value) { value = Math::Max(0.0f, value); - if (_attenuation == value) + if (Math::NearEqual(_attenuation, value)) return; _attenuation = value; UpdateInfo(); From e97d683545964f155461ed043bc036c5b4347ecf Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 3 Jun 2025 23:37:37 +0200 Subject: [PATCH 16/16] Fix regression from #3389 --- Source/Engine/Level/Actor.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Source/Engine/Level/Actor.cpp b/Source/Engine/Level/Actor.cpp index b96db3925..0c0a98e14 100644 --- a/Source/Engine/Level/Actor.cpp +++ b/Source/Engine/Level/Actor.cpp @@ -36,8 +36,6 @@ #define CHECK_EXECUTE_IN_EDITOR #endif -#define ACTOR_ORIENTATION_EPSILON 0.000000001f - // Start loop over actor children/scripts from the beginning to account for any newly added or removed actors. #define ACTOR_LOOP_START_MODIFIED_HIERARCHY() _isHierarchyDirty = false #define ACTOR_LOOP_CHECK_MODIFIED_HIERARCHY() if (_isHierarchyDirty) { _isHierarchyDirty = false; i = -1; } @@ -660,7 +658,7 @@ void Actor::SetStaticFlags(StaticFlags value) void Actor::SetTransform(const Transform& value) { CHECK(!value.IsNanOrInfinity()); - if (_transform.Translation != value.Translation && _transform.Orientation != value.Orientation && _transform.Scale != value.Scale) + if (_transform.Translation != value.Translation || _transform.Orientation != value.Orientation || _transform.Scale != value.Scale) { if (_parent) _parent->_transform.WorldToLocal(value, _localTransform);