diff --git a/osu.Game.Modes.Catch/CatchDifficultyCalculator.cs b/osu.Game.Modes.Catch/CatchDifficultyCalculator.cs index 47fe1774bd..ccc4097d59 100644 --- a/osu.Game.Modes.Catch/CatchDifficultyCalculator.cs +++ b/osu.Game.Modes.Catch/CatchDifficultyCalculator.cs @@ -19,7 +19,7 @@ namespace osu.Game.Modes.Catch protected override HitObjectConverter Converter => new CatchConverter(); - protected override double ComputeDifficulty(Dictionary categoryDifficulty) + protected override double CalculateInternal(Dictionary categoryDifficulty) { return 0; } diff --git a/osu.Game.Modes.Mania/ManiaDifficultyCalculator.cs b/osu.Game.Modes.Mania/ManiaDifficultyCalculator.cs index 5075c44db6..975b78c215 100644 --- a/osu.Game.Modes.Mania/ManiaDifficultyCalculator.cs +++ b/osu.Game.Modes.Mania/ManiaDifficultyCalculator.cs @@ -22,7 +22,7 @@ namespace osu.Game.Modes.Mania protected override HitObjectConverter Converter => new ManiaConverter(columns); - protected override double ComputeDifficulty(Dictionary categoryDifficulty) + protected override double CalculateInternal(Dictionary categoryDifficulty) { return 0; } diff --git a/osu.Game.Modes.Osu/OsuDifficultyCalculator.cs b/osu.Game.Modes.Osu/OsuDifficultyCalculator.cs index 24648b1726..9e2a311021 100644 --- a/osu.Game.Modes.Osu/OsuDifficultyCalculator.cs +++ b/osu.Game.Modes.Osu/OsuDifficultyCalculator.cs @@ -34,7 +34,7 @@ namespace osu.Game.Modes.Osu ((Slider)h).Curve.Calculate(); } - protected override double ComputeDifficulty(Dictionary categoryDifficulty) + protected override double CalculateInternal(Dictionary categoryDifficulty) { // Fill our custom DifficultyHitObject class, that carries additional information DifficultyHitObjects.Clear(); diff --git a/osu.Game.Modes.Taiko/TaikoDifficultyCalculator.cs b/osu.Game.Modes.Taiko/TaikoDifficultyCalculator.cs index 69b86a86af..5067cef2b3 100644 --- a/osu.Game.Modes.Taiko/TaikoDifficultyCalculator.cs +++ b/osu.Game.Modes.Taiko/TaikoDifficultyCalculator.cs @@ -19,7 +19,7 @@ namespace osu.Game.Modes.Taiko protected override HitObjectConverter Converter => new TaikoConverter(); - protected override double ComputeDifficulty(Dictionary categoryDifficulty) + protected override double CalculateInternal(Dictionary categoryDifficulty) { return 0; } diff --git a/osu.Game/Beatmaps/Beatmap.cs b/osu.Game/Beatmaps/Beatmap.cs index a55e9fa80d..d92e340e72 100644 --- a/osu.Game/Beatmaps/Beatmap.cs +++ b/osu.Game/Beatmaps/Beatmap.cs @@ -7,6 +7,7 @@ using OpenTK.Graphics; using osu.Game.Beatmaps.Timing; using osu.Game.Database; using osu.Game.Modes.Objects; +using osu.Game.Modes; namespace osu.Game.Beatmaps { @@ -57,5 +58,7 @@ namespace osu.Game.Beatmaps return timingPoint ?? ControlPoint.Default; } + + public double CalculateStarDifficulty() => Ruleset.GetRuleset(BeatmapInfo.Mode).CreateDifficultyCalculator(this).Calculate(); } } diff --git a/osu.Game/Beatmaps/DifficultyCalculator.cs b/osu.Game/Beatmaps/DifficultyCalculator.cs index 14b6ce3e96..8214496363 100644 --- a/osu.Game/Beatmaps/DifficultyCalculator.cs +++ b/osu.Game/Beatmaps/DifficultyCalculator.cs @@ -14,7 +14,7 @@ namespace osu.Game.Beatmaps protected double TimeRate = 1; - protected abstract double ComputeDifficulty(Dictionary categoryDifficulty); + protected abstract double CalculateInternal(Dictionary categoryDifficulty); private void loadTiming() { @@ -23,10 +23,10 @@ namespace osu.Game.Beatmaps TimeRate = audioRate / 100.0; } - public double GetDifficulty(Dictionary categoryDifficulty = null) + public double Calculate(Dictionary categoryDifficulty = null) { loadTiming(); - double difficulty = ComputeDifficulty(categoryDifficulty); + double difficulty = CalculateInternal(categoryDifficulty); return difficulty; } } diff --git a/osu.Game/Beatmaps/Drawables/BeatmapGroup.cs b/osu.Game/Beatmaps/Drawables/BeatmapGroup.cs index 192a383fdf..36c042ac30 100644 --- a/osu.Game/Beatmaps/Drawables/BeatmapGroup.cs +++ b/osu.Game/Beatmaps/Drawables/BeatmapGroup.cs @@ -59,16 +59,21 @@ namespace osu.Game.Beatmaps.Drawables } } - public BeatmapGroup(WorkingBeatmap beatmap) + public BeatmapGroup(BeatmapSetInfo beatmapSet, BeatmapDatabase database) { + BeatmapSet = beatmapSet; + WorkingBeatmap beatmap = database.GetWorkingBeatmap(BeatmapSet.Beatmaps.FirstOrDefault()); + foreach (var b in BeatmapSet.Beatmaps) + b.StarDifficulty = (float)database.GetWorkingBeatmap(b).Beatmap.CalculateStarDifficulty(); + Header = new BeatmapSetHeader(beatmap) { GainedSelection = headerGainedSelection, RelativeSizeAxes = Axes.X, }; - - BeatmapSet = beatmap.BeatmapSetInfo; - BeatmapPanels = beatmap.BeatmapSetInfo.Beatmaps.Select(b => new BeatmapPanel(b) + + BeatmapSet.Beatmaps = BeatmapSet.Beatmaps.OrderBy(b => b.StarDifficulty).ToList(); + BeatmapPanels = BeatmapSet.Beatmaps.Select(b => new BeatmapPanel(b) { Alpha = 0, GainedSelection = panelGainedSelection, diff --git a/osu.Game/Database/BeatmapInfo.cs b/osu.Game/Database/BeatmapInfo.cs index 9622b73108..c97b6653e0 100644 --- a/osu.Game/Database/BeatmapInfo.cs +++ b/osu.Game/Database/BeatmapInfo.cs @@ -73,7 +73,6 @@ namespace osu.Game.Database // Metadata public string Version { get; set; } - //todo: background threaded computation of this private float starDifficulty = -1; public float StarDifficulty { @@ -85,11 +84,6 @@ namespace osu.Game.Database set { starDifficulty = value; } } - internal void ComputeDifficulty(BeatmapDatabase database) - { - StarDifficulty = (float)Ruleset.GetRuleset(Mode).CreateDifficultyCalculator(database.GetWorkingBeatmap(this).Beatmap).GetDifficulty(); - } - public bool Equals(BeatmapInfo other) { return ID == other?.ID; diff --git a/osu.Game/Screens/Select/PlaySongSelect.cs b/osu.Game/Screens/Select/PlaySongSelect.cs index 3911b26b00..ff8bf24ec6 100644 --- a/osu.Game/Screens/Select/PlaySongSelect.cs +++ b/osu.Game/Screens/Select/PlaySongSelect.cs @@ -325,11 +325,7 @@ namespace osu.Game.Screens.Select if (b.Metadata == null) b.Metadata = beatmapSet.Metadata; }); - foreach (var b in beatmapSet.Beatmaps) - b.ComputeDifficulty(database); - beatmapSet.Beatmaps = beatmapSet.Beatmaps.OrderBy(b => b.StarDifficulty).ToList(); - - var group = new BeatmapGroup(database.GetWorkingBeatmap(beatmapSet.Beatmaps.FirstOrDefault())) + var group = new BeatmapGroup(beatmapSet, database) { SelectionChanged = selectionChanged, StartRequested = b => footer.StartButton.TriggerClick()