diff --git a/osu.Game.Modes.Osu/Objects/Slider.cs b/osu.Game.Modes.Osu/Objects/Slider.cs index 83a5a458c7..6c00af89b3 100644 --- a/osu.Game.Modes.Osu/Objects/Slider.cs +++ b/osu.Game.Modes.Osu/Objects/Slider.cs @@ -54,7 +54,7 @@ namespace osu.Game.Modes.Osu.Objects var baseDifficulty = beatmap.BeatmapInfo.BaseDifficulty; ControlPoint overridePoint; - ControlPoint timingPoint = beatmap.TimingPointAt(StartTime, out overridePoint); + ControlPoint timingPoint = beatmap.TimingInfo.TimingPointAt(StartTime, out overridePoint); var velocityAdjustment = overridePoint?.VelocityAdjustment ?? 1; var baseVelocity = 100 * baseDifficulty.SliderMultiplier / velocityAdjustment; diff --git a/osu.Game/Beatmaps/Beatmap.cs b/osu.Game/Beatmaps/Beatmap.cs index 6dbd605359..bf86aeea83 100644 --- a/osu.Game/Beatmaps/Beatmap.cs +++ b/osu.Game/Beatmaps/Beatmap.cs @@ -7,7 +7,6 @@ using osu.Game.Database; using osu.Game.Modes; using osu.Game.Modes.Objects; using System.Collections.Generic; -using System.Linq; namespace osu.Game.Beatmaps { @@ -18,7 +17,7 @@ namespace osu.Game.Beatmaps where T : HitObject { public BeatmapInfo BeatmapInfo; - public List ControlPoints; + public TimingInfo TimingInfo = new TimingInfo(); public readonly List ComboColors = new List { new Color4(17, 136, 170, 255), @@ -41,49 +40,40 @@ namespace osu.Game.Beatmaps public Beatmap(Beatmap original = null) { BeatmapInfo = original?.BeatmapInfo ?? BeatmapInfo; - ControlPoints = original?.ControlPoints ?? ControlPoints; + TimingInfo = original?.TimingInfo ?? TimingInfo; ComboColors = original?.ComboColors ?? ComboColors; } - public double BPMMaximum => 60000 / (ControlPoints?.Where(c => c.BeatLength != 0).OrderBy(c => c.BeatLength).FirstOrDefault() ?? ControlPoint.Default).BeatLength; - public double BPMMinimum => 60000 / (ControlPoints?.Where(c => c.BeatLength != 0).OrderByDescending(c => c.BeatLength).FirstOrDefault() ?? ControlPoint.Default).BeatLength; - public double BPMMode => BPMAt(ControlPoints.Where(c => c.BeatLength != 0).GroupBy(c => c.BeatLength).OrderByDescending(grp => grp.Count()).First().First().Time); - - public double BPMAt(double time) + /// + /// Finds the slider velocity at a time. + /// + /// The time to find the slider velocity at. + /// The slider velocity in positional length units. + public double SliderVelocityAt(double time) { - return 60000 / BeatLengthAt(time); + double scoringDistance = 100 * BeatmapInfo.BaseDifficulty.SliderMultiplier; + double beatDistance = TimingInfo.BeatDistanceAt(time); + + if (beatDistance > 0) + return scoringDistance / beatDistance * 1000; + return scoringDistance; } - public double BeatLengthAt(double time) + /// + /// Maps a difficulty value [0, 10] to a two-piece linear range of values. + /// + /// The difficulty value to be mapped. + /// Minimum of the resulting range which will be achieved by a difficulty value of 0. + /// Midpoint of the resulting range which will be achieved by a difficulty value of 5. + /// Maximum of the resulting range which will be achieved by a difficulty value of 10. + /// Value to which the difficulty value maps in the specified range. + public static double MapDifficultyRange(double difficulty, double min, double mid, double max) { - ControlPoint overridePoint; - ControlPoint timingPoint = TimingPointAt(time, out overridePoint); - return timingPoint.BeatLength; - } - - public ControlPoint TimingPointAt(double time, out ControlPoint overridePoint) - { - overridePoint = null; - - ControlPoint timingPoint = null; - foreach (var controlPoint in ControlPoints) - { - // Some beatmaps have the first timingPoint (accidentally) start after the first HitObject(s). - // This null check makes it so that the first ControlPoint that makes a timing change is used as - // the timingPoint for those HitObject(s). - if (controlPoint.Time <= time || timingPoint == null) - { - if (controlPoint.TimingChange) - { - timingPoint = controlPoint; - overridePoint = null; - } - else overridePoint = controlPoint; - } - else break; - } - - return timingPoint ?? ControlPoint.Default; + if (difficulty > 5) + return mid + (max - mid) * (difficulty - 5) / 5; + if (difficulty < 5) + return mid - (mid - min) * (5 - difficulty) / 5; + return mid; } } diff --git a/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs b/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs index ba608fb08d..88cc977f1d 100644 --- a/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs +++ b/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.IO; using osu.Game.Modes.Objects; -using osu.Game.Beatmaps.Timing; using osu.Game.Database; namespace osu.Game.Beatmaps.Formats @@ -43,7 +42,6 @@ namespace osu.Game.Beatmaps.Formats var beatmap = new Beatmap { HitObjects = new List(), - ControlPoints = new List(), BeatmapInfo = new BeatmapInfo { Metadata = new BeatmapMetadata(), diff --git a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs index 71d26b2c51..86f75de794 100644 --- a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs @@ -209,7 +209,7 @@ namespace osu.Game.Beatmaps.Formats } if (cp != null) - beatmap.ControlPoints.Add(cp); + beatmap.TimingInfo.ControlPoints.Add(cp); } private void handleColours(Beatmap beatmap, string key, string val, ref bool hasCustomColours) diff --git a/osu.Game/Beatmaps/Timing/TimingInfo.cs b/osu.Game/Beatmaps/Timing/TimingInfo.cs new file mode 100644 index 0000000000..f245a6b1aa --- /dev/null +++ b/osu.Game/Beatmaps/Timing/TimingInfo.cs @@ -0,0 +1,106 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System.Collections.Generic; +using System.Linq; + +namespace osu.Game.Beatmaps.Timing +{ + public class TimingInfo + { + public readonly List ControlPoints = new List(); + + public double BPMMaximum => 60000 / (ControlPoints?.Where(c => c.BeatLength != 0).OrderBy(c => c.BeatLength).FirstOrDefault() ?? ControlPoint.Default).BeatLength; + public double BPMMinimum => 60000 / (ControlPoints?.Where(c => c.BeatLength != 0).OrderByDescending(c => c.BeatLength).FirstOrDefault() ?? ControlPoint.Default).BeatLength; + public double BPMMode => BPMAt(ControlPoints.Where(c => c.BeatLength != 0).GroupBy(c => c.BeatLength).OrderByDescending(grp => grp.Count()).First().First().Time); + + public double BPMAt(double time) + { + return 60000 / BeatLengthAt(time); + } + + /// + /// Finds the BPM multiplier at a time. + /// + /// The time to find the BPM multiplier at. + /// The BPM multiplier. + public double BPMMultiplierAt(double time) + { + ControlPoint overridePoint; + ControlPoint timingPoint = TimingPointAt(time, out overridePoint); + + return overridePoint?.VelocityAdjustment ?? timingPoint?.VelocityAdjustment ?? 1; + } + + /// + /// Finds the beat length at a time. + /// + /// The time to find the beat length at. + /// The beat length in milliseconds. + public double BeatLengthAt(double time) + { + ControlPoint overridePoint; + ControlPoint timingPoint = TimingPointAt(time, out overridePoint); + + return timingPoint.BeatLength; + } + + /// + /// Finds the beat velocity at a time. + /// + /// The time to find the velocity at. + /// The velocity. + public double BeatVelocityAt(double time) + { + ControlPoint overridePoint; + ControlPoint timingPoint = TimingPointAt(time, out overridePoint); + + return overridePoint?.VelocityAdjustment ?? timingPoint?.VelocityAdjustment ?? 1; + } + + /// + /// Finds the beat length at a time. + /// + /// The time to find the beat length at. + /// The beat length in positional length units. + public double BeatDistanceAt(double time) + { + ControlPoint overridePoint; + ControlPoint timingPoint = TimingPointAt(time, out overridePoint); + + return (timingPoint?.BeatLength ?? 1) * (overridePoint?.VelocityAdjustment ?? timingPoint?.VelocityAdjustment ?? 1); + } + + /// + /// Finds the timing point at a time. + /// + /// The time to find the timing point at. + /// The timing point containing the velocity change of the returned timing point. + /// The timing point. + public ControlPoint TimingPointAt(double time, out ControlPoint overridePoint) + { + overridePoint = null; + + ControlPoint timingPoint = null; + foreach (var controlPoint in ControlPoints) + { + // Some beatmaps have the first timingPoint (accidentally) start after the first HitObject(s). + // This null check makes it so that the first ControlPoint that makes a timing change is used as + // the timingPoint for those HitObject(s). + if (controlPoint.Time <= time || timingPoint == null) + { + if (controlPoint.TimingChange) + { + timingPoint = controlPoint; + overridePoint = null; + } + else + overridePoint = controlPoint; + } + else break; + } + + return timingPoint ?? ControlPoint.Default; + } + } +} \ No newline at end of file diff --git a/osu.Game/Screens/Select/BeatmapInfoWedge.cs b/osu.Game/Screens/Select/BeatmapInfoWedge.cs index f82c35598a..5285d26264 100644 --- a/osu.Game/Screens/Select/BeatmapInfoWedge.cs +++ b/osu.Game/Screens/Select/BeatmapInfoWedge.cs @@ -217,12 +217,12 @@ namespace osu.Game.Screens.Select private string getBPMRange(Beatmap beatmap) { - double bpmMax = beatmap.BPMMaximum; - double bpmMin = beatmap.BPMMinimum; + double bpmMax = beatmap.TimingInfo.BPMMaximum; + double bpmMin = beatmap.TimingInfo.BPMMinimum; if (Precision.AlmostEquals(bpmMin, bpmMax)) return Math.Round(bpmMin) + "bpm"; - return Math.Round(bpmMin) + "-" + Math.Round(bpmMax) + "bpm (mostly " + Math.Round(beatmap.BPMMode) + "bpm)"; + return Math.Round(bpmMin) + "-" + Math.Round(bpmMax) + "bpm (mostly " + Math.Round(beatmap.TimingInfo.BPMMode) + "bpm)"; } public class InfoLabel : Container diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 3ec8b535c7..285937003a 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -75,6 +75,7 @@ +