From b284a159d18955e2fa1f8da1f0371a9be48fd703 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 21 May 2024 11:31:33 +0800 Subject: [PATCH] Revert "Apply generic math-related changes #27965" --- osu.Game/Graphics/UserInterface/ExpandableSlider.cs | 8 ++++---- osu.Game/Graphics/UserInterface/OsuSliderBar.cs | 9 ++++----- osu.Game/Graphics/UserInterface/RoundedSliderBar.cs | 5 ++--- osu.Game/Graphics/UserInterface/ShearedSliderBar.cs | 5 ++--- osu.Game/Graphics/UserInterfaceV2/LabelledSliderBar.cs | 4 ++-- .../Graphics/UserInterfaceV2/SliderWithTextBoxInput.cs | 8 ++++---- osu.Game/Overlays/Settings/Sections/SizeSlider.cs | 3 +-- osu.Game/Overlays/Settings/SettingsPercentageSlider.cs | 4 ++-- osu.Game/Overlays/Settings/SettingsSlider.cs | 6 +++--- osu.Game/Rulesets/Mods/DifficultyBindable.cs | 2 +- .../Rulesets/Scoring/LegacyDrainingHealthProcessor.cs | 7 ------- .../Edit/Timing/IndeterminateSliderWithTextBoxInput.cs | 8 ++++---- osu.Game/Screens/Play/PlayerSettings/PlayerSliderBar.cs | 4 ++-- 13 files changed, 31 insertions(+), 42 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/ExpandableSlider.cs b/osu.Game/Graphics/UserInterface/ExpandableSlider.cs index a7a8561b9474..121a1eef4916 100644 --- a/osu.Game/Graphics/UserInterface/ExpandableSlider.cs +++ b/osu.Game/Graphics/UserInterface/ExpandableSlider.cs @@ -1,7 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Numerics; +using System; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -10,7 +10,7 @@ using osu.Framework.Localisation; using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; -using Vector2 = osuTK.Vector2; +using osuTK; namespace osu.Game.Graphics.UserInterface { @@ -18,7 +18,7 @@ namespace osu.Game.Graphics.UserInterface /// An implementation for the UI slider bar control. /// public partial class ExpandableSlider : CompositeDrawable, IExpandable, IHasCurrentValue - where T : struct, INumber, IMinMaxValue + where T : struct, IEquatable, IComparable, IConvertible where TSlider : RoundedSliderBar, new() { private readonly OsuSpriteText label; @@ -129,7 +129,7 @@ protected override void LoadComplete() /// An implementation for the UI slider bar control. /// public partial class ExpandableSlider : ExpandableSlider> - where T : struct, INumber, IMinMaxValue + where T : struct, IEquatable, IComparable, IConvertible { } } diff --git a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs index 9cb6356cabd1..191a7ca24639 100644 --- a/osu.Game/Graphics/UserInterface/OsuSliderBar.cs +++ b/osu.Game/Graphics/UserInterface/OsuSliderBar.cs @@ -2,7 +2,6 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Numerics; using System.Globalization; using osu.Framework.Allocation; using osu.Framework.Audio; @@ -16,7 +15,7 @@ namespace osu.Game.Graphics.UserInterface { public abstract partial class OsuSliderBar : SliderBar, IHasTooltip - where T : struct, INumber, IMinMaxValue + where T : struct, IEquatable, IComparable, IConvertible { public bool PlaySamplesOnAdjust { get; set; } = true; @@ -86,11 +85,11 @@ private void playSample(T value) private LocalisableString getTooltipText(T value) { if (CurrentNumber.IsInteger) - return int.CreateTruncating(value).ToString("N0"); + return value.ToInt32(NumberFormatInfo.InvariantInfo).ToString("N0"); - double floatValue = double.CreateTruncating(value); + double floatValue = value.ToDouble(NumberFormatInfo.InvariantInfo); - decimal decimalPrecision = normalise(decimal.CreateTruncating(CurrentNumber.Precision), max_decimal_digits); + decimal decimalPrecision = normalise(CurrentNumber.Precision.ToDecimal(NumberFormatInfo.InvariantInfo), max_decimal_digits); // Find the number of significant digits (we could have less than 5 after normalize()) int significantDigits = FormatUtils.FindPrecision(decimalPrecision); diff --git a/osu.Game/Graphics/UserInterface/RoundedSliderBar.cs b/osu.Game/Graphics/UserInterface/RoundedSliderBar.cs index 56047173bb0b..0981881ead81 100644 --- a/osu.Game/Graphics/UserInterface/RoundedSliderBar.cs +++ b/osu.Game/Graphics/UserInterface/RoundedSliderBar.cs @@ -2,7 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Numerics; +using osuTK; using osuTK.Graphics; using osu.Framework.Allocation; using osu.Framework.Extensions.Color4Extensions; @@ -11,12 +11,11 @@ using osu.Framework.Graphics.Shapes; using osu.Framework.Input.Events; using osu.Game.Overlays; -using Vector2 = osuTK.Vector2; namespace osu.Game.Graphics.UserInterface { public partial class RoundedSliderBar : OsuSliderBar - where T : struct, INumber, IMinMaxValue + where T : struct, IEquatable, IComparable, IConvertible { protected readonly Nub Nub; protected readonly Box LeftBox; diff --git a/osu.Game/Graphics/UserInterface/ShearedSliderBar.cs b/osu.Game/Graphics/UserInterface/ShearedSliderBar.cs index 0df1c1d20463..60a667049213 100644 --- a/osu.Game/Graphics/UserInterface/ShearedSliderBar.cs +++ b/osu.Game/Graphics/UserInterface/ShearedSliderBar.cs @@ -2,7 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Numerics; +using osuTK; using osuTK.Graphics; using osu.Framework.Allocation; using osu.Framework.Extensions.Color4Extensions; @@ -12,12 +12,11 @@ using osu.Framework.Input.Events; using osu.Game.Overlays; using static osu.Game.Graphics.UserInterface.ShearedNub; -using Vector2 = osuTK.Vector2; namespace osu.Game.Graphics.UserInterface { public partial class ShearedSliderBar : OsuSliderBar - where T : struct, INumber, IMinMaxValue + where T : struct, IEquatable, IComparable, IConvertible { protected readonly ShearedNub Nub; protected readonly Box LeftBox; diff --git a/osu.Game/Graphics/UserInterfaceV2/LabelledSliderBar.cs b/osu.Game/Graphics/UserInterfaceV2/LabelledSliderBar.cs index 4912a21fabef..4585d3a4c98f 100644 --- a/osu.Game/Graphics/UserInterfaceV2/LabelledSliderBar.cs +++ b/osu.Game/Graphics/UserInterfaceV2/LabelledSliderBar.cs @@ -1,14 +1,14 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Numerics; +using System; using osu.Framework.Graphics; using osu.Game.Overlays.Settings; namespace osu.Game.Graphics.UserInterfaceV2 { public partial class LabelledSliderBar : LabelledComponent, TNumber> - where TNumber : struct, INumber, IMinMaxValue + where TNumber : struct, IEquatable, IComparable, IConvertible { public LabelledSliderBar() : base(true) diff --git a/osu.Game/Graphics/UserInterfaceV2/SliderWithTextBoxInput.cs b/osu.Game/Graphics/UserInterfaceV2/SliderWithTextBoxInput.cs index abd828e98fb9..e5ba7f61bfde 100644 --- a/osu.Game/Graphics/UserInterfaceV2/SliderWithTextBoxInput.cs +++ b/osu.Game/Graphics/UserInterfaceV2/SliderWithTextBoxInput.cs @@ -1,7 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Numerics; +using System; using System.Globalization; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -10,12 +10,12 @@ using osu.Framework.Localisation; using osu.Game.Overlays.Settings; using osu.Game.Utils; -using Vector2 = osuTK.Vector2; +using osuTK; namespace osu.Game.Graphics.UserInterfaceV2 { public partial class SliderWithTextBoxInput : CompositeDrawable, IHasCurrentValue - where T : struct, INumber, IMinMaxValue + where T : struct, IEquatable, IComparable, IConvertible { /// /// A custom step value for each key press which actuates a change on this control. @@ -138,7 +138,7 @@ private void updateTextBoxFromSlider(ValueChangedEvent _) { if (updatingFromTextBox) return; - decimal decimalValue = decimal.CreateTruncating(slider.Current.Value); + decimal decimalValue = slider.Current.Value.ToDecimal(NumberFormatInfo.InvariantInfo); textBox.Text = decimalValue.ToString($@"N{FormatUtils.FindPrecision(decimalValue)}"); } } diff --git a/osu.Game/Overlays/Settings/Sections/SizeSlider.cs b/osu.Game/Overlays/Settings/Sections/SizeSlider.cs index 14ef58ff8876..c73831d8d1ae 100644 --- a/osu.Game/Overlays/Settings/Sections/SizeSlider.cs +++ b/osu.Game/Overlays/Settings/Sections/SizeSlider.cs @@ -2,7 +2,6 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Numerics; using System.Globalization; using osu.Framework.Localisation; using osu.Game.Graphics.UserInterface; @@ -13,7 +12,7 @@ namespace osu.Game.Overlays.Settings.Sections /// A slider intended to show a "size" multiplier number, where 1x is 1.0. /// public partial class SizeSlider : RoundedSliderBar - where T : struct, INumber, IMinMaxValue, IFormattable + where T : struct, IEquatable, IComparable, IConvertible, IFormattable { public override LocalisableString TooltipText => Current.Value.ToString(@"0.##x", NumberFormatInfo.CurrentInfo); } diff --git a/osu.Game/Overlays/Settings/SettingsPercentageSlider.cs b/osu.Game/Overlays/Settings/SettingsPercentageSlider.cs index d7a09d3392f2..fa59d18de120 100644 --- a/osu.Game/Overlays/Settings/SettingsPercentageSlider.cs +++ b/osu.Game/Overlays/Settings/SettingsPercentageSlider.cs @@ -1,7 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Numerics; +using System; using osu.Framework.Graphics; using osu.Game.Configuration; using osu.Game.Graphics.UserInterface; @@ -13,7 +13,7 @@ namespace osu.Game.Overlays.Settings /// Mostly provided for convenience of use with . /// public partial class SettingsPercentageSlider : SettingsSlider - where TValue : struct, INumber, IMinMaxValue + where TValue : struct, IEquatable, IComparable, IConvertible { protected override Drawable CreateControl() => ((RoundedSliderBar)base.CreateControl()).With(sliderBar => sliderBar.DisplayAsPercentage = true); } diff --git a/osu.Game/Overlays/Settings/SettingsSlider.cs b/osu.Game/Overlays/Settings/SettingsSlider.cs index 2460d780994a..6c81fece13a8 100644 --- a/osu.Game/Overlays/Settings/SettingsSlider.cs +++ b/osu.Game/Overlays/Settings/SettingsSlider.cs @@ -1,7 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Numerics; +using System; using osu.Framework.Graphics; using osu.Framework.Graphics.UserInterface; using osu.Game.Graphics.UserInterface; @@ -9,12 +9,12 @@ namespace osu.Game.Overlays.Settings { public partial class SettingsSlider : SettingsSlider> - where T : struct, INumber, IMinMaxValue + where T : struct, IEquatable, IComparable, IConvertible { } public partial class SettingsSlider : SettingsItem - where TValue : struct, INumber, IMinMaxValue + where TValue : struct, IEquatable, IComparable, IConvertible where TSlider : RoundedSliderBar, new() { protected override Drawable CreateControl() => new TSlider diff --git a/osu.Game/Rulesets/Mods/DifficultyBindable.cs b/osu.Game/Rulesets/Mods/DifficultyBindable.cs index 5f6fd21860ca..a207048882ba 100644 --- a/osu.Game/Rulesets/Mods/DifficultyBindable.cs +++ b/osu.Game/Rulesets/Mods/DifficultyBindable.cs @@ -48,7 +48,7 @@ public float MinValue } } - private float maxValue = 10; // matches default max value of `CurrentNumber` + private float maxValue; public float MaxValue { diff --git a/osu.Game/Rulesets/Scoring/LegacyDrainingHealthProcessor.cs b/osu.Game/Rulesets/Scoring/LegacyDrainingHealthProcessor.cs index 25c5b3643af6..7cee5ebecf09 100644 --- a/osu.Game/Rulesets/Scoring/LegacyDrainingHealthProcessor.cs +++ b/osu.Game/Rulesets/Scoring/LegacyDrainingHealthProcessor.cs @@ -129,13 +129,6 @@ protected override double ComputeDrainRate() OnIterationFail?.Invoke($"FAILED drop {testDrop}: recovery too low ({recovery} < {hpRecoveryAvailable})"); } - if (!fail && double.IsInfinity(HpMultiplierNormal)) - { - OnIterationSuccess?.Invoke("Drain computation algorithm diverged to infinity. PASSING with zero drop, resetting HP multiplier to 1."); - HpMultiplierNormal = 1; - return 0; - } - if (!fail) { OnIterationSuccess?.Invoke($"PASSED drop {testDrop}"); diff --git a/osu.Game/Screens/Edit/Timing/IndeterminateSliderWithTextBoxInput.cs b/osu.Game/Screens/Edit/Timing/IndeterminateSliderWithTextBoxInput.cs index 26f374ba85e1..151d46941528 100644 --- a/osu.Game/Screens/Edit/Timing/IndeterminateSliderWithTextBoxInput.cs +++ b/osu.Game/Screens/Edit/Timing/IndeterminateSliderWithTextBoxInput.cs @@ -1,7 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Numerics; +using System; using System.Globalization; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -12,7 +12,7 @@ using osu.Game.Graphics.UserInterfaceV2; using osu.Game.Overlays.Settings; using osu.Game.Utils; -using Vector2 = osuTK.Vector2; +using osuTK; namespace osu.Game.Screens.Edit.Timing { @@ -22,7 +22,7 @@ namespace osu.Game.Screens.Edit.Timing /// by providing an "indeterminate state". /// public partial class IndeterminateSliderWithTextBoxInput : CompositeDrawable, IHasCurrentValue - where T : struct, INumber, IMinMaxValue + where T : struct, IEquatable, IComparable, IConvertible { /// /// A custom step value for each key press which actuates a change on this control. @@ -136,7 +136,7 @@ private void updateState() slider.Current.Value = nonNullValue; // use the value from the slider to ensure that any precision/min/max set on it via the initial indeterminate value have been applied correctly. - decimal decimalValue = decimal.CreateTruncating(slider.Current.Value); + decimal decimalValue = slider.Current.Value.ToDecimal(NumberFormatInfo.InvariantInfo); textBox.Text = decimalValue.ToString($@"N{FormatUtils.FindPrecision(decimalValue)}"); textBox.PlaceholderText = string.Empty; } diff --git a/osu.Game/Screens/Play/PlayerSettings/PlayerSliderBar.cs b/osu.Game/Screens/Play/PlayerSettings/PlayerSliderBar.cs index 1fc1155c0b38..88b778fafb66 100644 --- a/osu.Game/Screens/Play/PlayerSettings/PlayerSliderBar.cs +++ b/osu.Game/Screens/Play/PlayerSettings/PlayerSliderBar.cs @@ -1,7 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Numerics; +using System; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Game.Graphics; @@ -11,7 +11,7 @@ namespace osu.Game.Screens.Play.PlayerSettings { public partial class PlayerSliderBar : SettingsSlider - where T : struct, INumber, IMinMaxValue + where T : struct, IEquatable, IComparable, IConvertible { public RoundedSliderBar Bar => (RoundedSliderBar)Control;