mirror of
https://github.com/ppy/osu.git
synced 2024-11-13 18:07:25 +08:00
Move to extension method and throw on non-legacy ruleset
This commit is contained in:
parent
4ecc4632aa
commit
0031da76ff
@ -13,6 +13,7 @@ using osu.Game.Beatmaps;
|
|||||||
using osu.Game.Beatmaps.ControlPoints;
|
using osu.Game.Beatmaps.ControlPoints;
|
||||||
using osu.Game.Rulesets.Mania.Objects;
|
using osu.Game.Rulesets.Mania.Objects;
|
||||||
using osu.Game.Rulesets.Objects;
|
using osu.Game.Rulesets.Objects;
|
||||||
|
using osu.Game.Rulesets.Objects.Legacy;
|
||||||
using osu.Game.Rulesets.Objects.Types;
|
using osu.Game.Rulesets.Objects.Types;
|
||||||
using osu.Game.Utils;
|
using osu.Game.Utils;
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ using JetBrains.Annotations;
|
|||||||
using osu.Game.Audio;
|
using osu.Game.Audio;
|
||||||
using osu.Game.Beatmaps.ControlPoints;
|
using osu.Game.Beatmaps.ControlPoints;
|
||||||
using osu.Game.Beatmaps.Formats;
|
using osu.Game.Beatmaps.Formats;
|
||||||
|
using osu.Game.Rulesets.Objects.Legacy;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Taiko.Beatmaps
|
namespace osu.Game.Rulesets.Taiko.Beatmaps
|
||||||
{
|
{
|
||||||
|
42
osu.Game/Rulesets/Objects/Legacy/LegacyRulesetExtensions.cs
Normal file
42
osu.Game/Rulesets/Objects/Legacy/LegacyRulesetExtensions.cs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using osu.Game.Beatmaps.ControlPoints;
|
||||||
|
using osu.Game.Rulesets.Objects.Types;
|
||||||
|
|
||||||
|
namespace osu.Game.Rulesets.Objects.Legacy
|
||||||
|
{
|
||||||
|
public static class LegacyRulesetExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Introduces floating-point errors to post-multiplied beat length for legacy rulesets that depend on it.
|
||||||
|
/// You should definitely not use this unless you know exactly what you're doing.
|
||||||
|
/// </summary>
|
||||||
|
public static double GetPrecisionAdjustedBeatLength(this IHasSliderVelocity hasSliderVelocity, TimingControlPoint timingControlPoint, string rulesetShortName)
|
||||||
|
{
|
||||||
|
double sliderVelocityAsBeatLength = -100 / hasSliderVelocity.SliderVelocityMultiplier;
|
||||||
|
|
||||||
|
// Note: In stable, the division occurs on floats, but with compiler optimisations turned on actually seems to occur on doubles via some .NET black magic (possibly inlining?).
|
||||||
|
double bpmMultiplier;
|
||||||
|
|
||||||
|
switch (rulesetShortName)
|
||||||
|
{
|
||||||
|
case "taiko":
|
||||||
|
case "mania":
|
||||||
|
bpmMultiplier = sliderVelocityAsBeatLength < 0 ? Math.Clamp((float)-sliderVelocityAsBeatLength, 10, 10000) / 100.0 : 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "osu":
|
||||||
|
case "fruits":
|
||||||
|
bpmMultiplier = sliderVelocityAsBeatLength < 0 ? Math.Clamp((float)-sliderVelocityAsBeatLength, 10, 1000) / 100.0 : 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new ArgumentException("Must be a legacy ruleset", nameof(rulesetShortName));
|
||||||
|
}
|
||||||
|
|
||||||
|
return timingControlPoint.BeatLength * bpmMultiplier;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Game.Beatmaps.ControlPoints;
|
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Objects.Types
|
namespace osu.Game.Rulesets.Objects.Types
|
||||||
{
|
{
|
||||||
@ -18,30 +16,5 @@ namespace osu.Game.Rulesets.Objects.Types
|
|||||||
double SliderVelocityMultiplier { get; set; }
|
double SliderVelocityMultiplier { get; set; }
|
||||||
|
|
||||||
BindableNumber<double> SliderVelocityMultiplierBindable { get; }
|
BindableNumber<double> SliderVelocityMultiplierBindable { get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Introduces floating-point errors to post-multiplied beat length for rulesets that depend on it.
|
|
||||||
/// </summary>
|
|
||||||
public double GetPrecisionAdjustedBeatLength(TimingControlPoint timingControlPoint, string rulesetShortName)
|
|
||||||
{
|
|
||||||
double sliderVelocityAsBeatLength = -100 / SliderVelocityMultiplier;
|
|
||||||
|
|
||||||
// Note: In stable, the division occurs on floats, but with compiler optimisations turned on actually seems to occur on doubles via some .NET black magic (possibly inlining?).
|
|
||||||
double bpmMultiplier;
|
|
||||||
|
|
||||||
switch (rulesetShortName)
|
|
||||||
{
|
|
||||||
case "taiko":
|
|
||||||
case "mania":
|
|
||||||
bpmMultiplier = sliderVelocityAsBeatLength < 0 ? Math.Clamp((float)-sliderVelocityAsBeatLength, 10, 10000) / 100.0 : 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
bpmMultiplier = sliderVelocityAsBeatLength < 0 ? Math.Clamp((float)-sliderVelocityAsBeatLength, 10, 1000) / 100.0 : 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return timingControlPoint.BeatLength * bpmMultiplier;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user