From 01710780525bca3126764bb77805964968ed19d6 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Wed, 13 Dec 2023 17:33:24 +0900 Subject: [PATCH] Move object counts to BeatmapInfo --- osu.Game.Tournament/Models/TournamentBeatmap.cs | 6 ++++++ osu.Game/BackgroundDataStoreProcessor.cs | 11 +++++++---- osu.Game/Beatmaps/BeatmapDifficulty.cs | 9 --------- osu.Game/Beatmaps/BeatmapImporter.cs | 6 +++--- osu.Game/Beatmaps/BeatmapInfo.cs | 4 ++++ osu.Game/Beatmaps/BeatmapUpdater.cs | 4 ++-- osu.Game/Beatmaps/IBeatmapDifficultyInfo.cs | 13 ------------- osu.Game/Beatmaps/IBeatmapInfo.cs | 13 +++++++++++++ .../Online/API/Requests/Responses/APIBeatmap.cs | 8 +++++--- .../Legacy/LegacyBeatmapConversionDifficultyInfo.cs | 4 ++-- 10 files changed, 42 insertions(+), 36 deletions(-) diff --git a/osu.Game.Tournament/Models/TournamentBeatmap.cs b/osu.Game.Tournament/Models/TournamentBeatmap.cs index 7f57b6a151..a7ba5b7db1 100644 --- a/osu.Game.Tournament/Models/TournamentBeatmap.cs +++ b/osu.Game.Tournament/Models/TournamentBeatmap.cs @@ -21,6 +21,10 @@ namespace osu.Game.Tournament.Models public double StarRating { get; set; } + public int EndTimeObjectCount { get; set; } + + public int TotalObjectCount { get; set; } + public IBeatmapMetadataInfo Metadata { get; set; } = new BeatmapMetadata(); public IBeatmapDifficultyInfo Difficulty { get; set; } = new BeatmapDifficulty(); @@ -41,6 +45,8 @@ namespace osu.Game.Tournament.Models Metadata = beatmap.Metadata; Difficulty = beatmap.Difficulty; Covers = beatmap.BeatmapSet?.Covers ?? new BeatmapSetOnlineCovers(); + EndTimeObjectCount = beatmap.EndTimeObjectCount; + TotalObjectCount = beatmap.TotalObjectCount; } public bool Equals(IBeatmapInfo? other) => other is TournamentBeatmap b && this.MatchesOnlineID(b); diff --git a/osu.Game/BackgroundDataStoreProcessor.cs b/osu.Game/BackgroundDataStoreProcessor.cs index c8a108a5f6..10cc13dc29 100644 --- a/osu.Game/BackgroundDataStoreProcessor.cs +++ b/osu.Game/BackgroundDataStoreProcessor.cs @@ -20,7 +20,6 @@ using osu.Game.Rulesets; using osu.Game.Scoring; using osu.Game.Scoring.Legacy; using osu.Game.Screens.Play; -using Realms; namespace osu.Game { @@ -177,9 +176,13 @@ namespace osu.Game { Logger.Log("Querying for beatmaps with missing hitobject counts to reprocess..."); - HashSet beatmapIds = realmAccess.Run(r => new HashSet(r.All() - .Filter($"{nameof(BeatmapInfo.Difficulty)}.{nameof(BeatmapDifficulty.TotalObjectCount)} == 0") - .AsEnumerable().Select(b => b.ID))); + HashSet beatmapIds = new HashSet(); + + realmAccess.Run(r => + { + foreach (var b in r.All().Where(b => b.TotalObjectCount == 0)) + beatmapIds.Add(b.ID); + }); Logger.Log($"Found {beatmapIds.Count} beatmaps which require reprocessing."); diff --git a/osu.Game/Beatmaps/BeatmapDifficulty.cs b/osu.Game/Beatmaps/BeatmapDifficulty.cs index 785728141e..ac2267380d 100644 --- a/osu.Game/Beatmaps/BeatmapDifficulty.cs +++ b/osu.Game/Beatmaps/BeatmapDifficulty.cs @@ -21,9 +21,6 @@ namespace osu.Game.Beatmaps public double SliderMultiplier { get; set; } = 1.4; public double SliderTickRate { get; set; } = 1; - public int EndTimeObjectCount { get; set; } - public int TotalObjectCount { get; set; } - public BeatmapDifficulty() { } @@ -47,9 +44,6 @@ namespace osu.Game.Beatmaps difficulty.SliderMultiplier = SliderMultiplier; difficulty.SliderTickRate = SliderTickRate; - - difficulty.EndTimeObjectCount = EndTimeObjectCount; - difficulty.TotalObjectCount = TotalObjectCount; } public virtual void CopyFrom(IBeatmapDifficultyInfo other) @@ -61,9 +55,6 @@ namespace osu.Game.Beatmaps SliderMultiplier = other.SliderMultiplier; SliderTickRate = other.SliderTickRate; - - EndTimeObjectCount = other.EndTimeObjectCount; - TotalObjectCount = other.TotalObjectCount; } } } diff --git a/osu.Game/Beatmaps/BeatmapImporter.cs b/osu.Game/Beatmaps/BeatmapImporter.cs index 31d6b0108e..7bb52eef52 100644 --- a/osu.Game/Beatmaps/BeatmapImporter.cs +++ b/osu.Game/Beatmaps/BeatmapImporter.cs @@ -388,9 +388,7 @@ namespace osu.Game.Beatmaps OverallDifficulty = decodedDifficulty.OverallDifficulty, ApproachRate = decodedDifficulty.ApproachRate, SliderMultiplier = decodedDifficulty.SliderMultiplier, - SliderTickRate = decodedDifficulty.SliderTickRate, - EndTimeObjectCount = decoded.HitObjects.Count(h => h is IHasDuration), - TotalObjectCount = decoded.HitObjects.Count + SliderTickRate = decodedDifficulty.SliderTickRate }; var metadata = new BeatmapMetadata @@ -428,6 +426,8 @@ namespace osu.Game.Beatmaps GridSize = decodedInfo.GridSize, TimelineZoom = decodedInfo.TimelineZoom, MD5Hash = memoryStream.ComputeMD5Hash(), + EndTimeObjectCount = decoded.HitObjects.Count(h => h is IHasDuration), + TotalObjectCount = decoded.HitObjects.Count }; beatmaps.Add(beatmap); diff --git a/osu.Game/Beatmaps/BeatmapInfo.cs b/osu.Game/Beatmaps/BeatmapInfo.cs index c1aeec1f71..2d04732f91 100644 --- a/osu.Game/Beatmaps/BeatmapInfo.cs +++ b/osu.Game/Beatmaps/BeatmapInfo.cs @@ -120,6 +120,10 @@ namespace osu.Game.Beatmaps [JsonIgnore] public bool Hidden { get; set; } + public int EndTimeObjectCount { get; set; } + + public int TotalObjectCount { get; set; } + /// /// Reset any fetched online linking information (and history). /// diff --git a/osu.Game/Beatmaps/BeatmapUpdater.cs b/osu.Game/Beatmaps/BeatmapUpdater.cs index 472ac26ebe..27492b8bac 100644 --- a/osu.Game/Beatmaps/BeatmapUpdater.cs +++ b/osu.Game/Beatmaps/BeatmapUpdater.cs @@ -91,8 +91,8 @@ namespace osu.Game.Beatmaps var working = workingBeatmapCache.GetWorkingBeatmap(beatmapInfo); var beatmap = working.Beatmap; - beatmapInfo.Difficulty.EndTimeObjectCount = beatmap.HitObjects.Count(h => h is IHasDuration); - beatmapInfo.Difficulty.TotalObjectCount = beatmap.HitObjects.Count; + beatmapInfo.EndTimeObjectCount = beatmap.HitObjects.Count(h => h is IHasDuration); + beatmapInfo.TotalObjectCount = beatmap.HitObjects.Count; // And invalidate again afterwards as re-fetching the most up-to-date database metadata will be required. workingBeatmapCache.Invalidate(beatmapInfo); diff --git a/osu.Game/Beatmaps/IBeatmapDifficultyInfo.cs b/osu.Game/Beatmaps/IBeatmapDifficultyInfo.cs index 47b261d1f6..e7a3d87d0a 100644 --- a/osu.Game/Beatmaps/IBeatmapDifficultyInfo.cs +++ b/osu.Game/Beatmaps/IBeatmapDifficultyInfo.cs @@ -44,19 +44,6 @@ namespace osu.Game.Beatmaps /// double SliderTickRate { get; } - /// - /// The number of hitobjects in the beatmap with a distinct end time. - /// - /// - /// Canonically, these are hitobjects are either sliders or spinners. - /// - int EndTimeObjectCount { get; } - - /// - /// The total number of hitobjects in the beatmap. - /// - int TotalObjectCount { get; } - /// /// Maps a difficulty value [0, 10] to a two-piece linear range of values. /// diff --git a/osu.Game/Beatmaps/IBeatmapInfo.cs b/osu.Game/Beatmaps/IBeatmapInfo.cs index b8c69cc525..9dcff5ce5e 100644 --- a/osu.Game/Beatmaps/IBeatmapInfo.cs +++ b/osu.Game/Beatmaps/IBeatmapInfo.cs @@ -61,5 +61,18 @@ namespace osu.Game.Beatmaps /// The basic star rating for this beatmap (with no mods applied). /// double StarRating { get; } + + /// + /// The number of hitobjects in the beatmap with a distinct end time. + /// + /// + /// Canonically, these are hitobjects are either sliders or spinners. + /// + int EndTimeObjectCount { get; } + + /// + /// The total number of hitobjects in the beatmap. + /// + int TotalObjectCount { get; } } } diff --git a/osu.Game/Online/API/Requests/Responses/APIBeatmap.cs b/osu.Game/Online/API/Requests/Responses/APIBeatmap.cs index c1ceff7c43..e5ecfe2c99 100644 --- a/osu.Game/Online/API/Requests/Responses/APIBeatmap.cs +++ b/osu.Game/Online/API/Requests/Responses/APIBeatmap.cs @@ -41,6 +41,10 @@ namespace osu.Game.Online.API.Requests.Responses [JsonProperty(@"difficulty_rating")] public double StarRating { get; set; } + public int EndTimeObjectCount => SliderCount + SpinnerCount; + + public int TotalObjectCount => CircleCount + SliderCount + SpinnerCount; + [JsonProperty(@"drain")] public float DrainRate { get; set; } @@ -108,9 +112,7 @@ namespace osu.Game.Online.API.Requests.Responses DrainRate = DrainRate, CircleSize = CircleSize, ApproachRate = ApproachRate, - OverallDifficulty = OverallDifficulty, - EndTimeObjectCount = SliderCount + SpinnerCount, - TotalObjectCount = CircleCount + SliderCount + SpinnerCount + OverallDifficulty = OverallDifficulty }; IBeatmapSetInfo? IBeatmapInfo.BeatmapSet => BeatmapSet; diff --git a/osu.Game/Rulesets/Scoring/Legacy/LegacyBeatmapConversionDifficultyInfo.cs b/osu.Game/Rulesets/Scoring/Legacy/LegacyBeatmapConversionDifficultyInfo.cs index 2021aa127d..7d69069455 100644 --- a/osu.Game/Rulesets/Scoring/Legacy/LegacyBeatmapConversionDifficultyInfo.cs +++ b/osu.Game/Rulesets/Scoring/Legacy/LegacyBeatmapConversionDifficultyInfo.cs @@ -62,8 +62,8 @@ namespace osu.Game.Rulesets.Scoring.Legacy SourceRuleset = beatmapInfo.Ruleset, CircleSize = beatmapInfo.Difficulty.CircleSize, OverallDifficulty = beatmapInfo.Difficulty.OverallDifficulty, - EndTimeObjectCount = beatmapInfo.Difficulty.EndTimeObjectCount, - TotalObjectCount = beatmapInfo.Difficulty.TotalObjectCount + EndTimeObjectCount = beatmapInfo.EndTimeObjectCount, + TotalObjectCount = beatmapInfo.TotalObjectCount }; } }