diff --git a/osu.Server.DifficultyCalculator/Commands/CalculatorCommand.cs b/osu.Server.DifficultyCalculator/Commands/CalculatorCommand.cs index d36a5e9..4b22d9b 100644 --- a/osu.Server.DifficultyCalculator/Commands/CalculatorCommand.cs +++ b/osu.Server.DifficultyCalculator/Commands/CalculatorCommand.cs @@ -41,6 +41,9 @@ public abstract class CalculatorCommand : CommandBase [Option(CommandOptionType.NoValue, Template = "-dry|--dry-run", Description = "Whether to run the process without writing to the database.")] public bool DryRun { get; set; } + [Option(CommandOptionType.SingleValue, Template = "--processing-mode", Description = "The mode in which to process beatmaps.")] + public ProcessingModes ProcessingMode { get; set; } = ProcessingModes.All; + private int[] threadBeatmapIds = null!; private IReporter reporter = null!; @@ -89,7 +92,21 @@ public void OnExecute(CommandLineApplication app, IConsole console) // ensure the correct online id is set beatmap.BeatmapInfo.OnlineID = beatmapId; - calc.ProcessBeatmap(beatmap); + switch (ProcessingMode) + { + case ProcessingModes.All: + calc.ProcessAll(beatmap); + break; + + case ProcessingModes.Difficulty: + calc.ProcessDifficulty(beatmap); + break; + + case ProcessingModes.ScoreAttributes: + calc.ProcessLegacyAttributes(beatmap); + break; + } + reporter.Verbose($"Difficulty updated for beatmap {beatmapId}."); } catch (Exception e) @@ -151,5 +168,12 @@ protected string CombineSqlConditions(params string?[] conditions) } protected abstract IEnumerable GetBeatmaps(); + + public enum ProcessingModes + { + All, + Difficulty, + ScoreAttributes + } } } diff --git a/osu.Server.DifficultyCalculator/ServerDifficultyCalculator.cs b/osu.Server.DifficultyCalculator/ServerDifficultyCalculator.cs index 79cfed8..d725717 100644 --- a/osu.Server.DifficultyCalculator/ServerDifficultyCalculator.cs +++ b/osu.Server.DifficultyCalculator/ServerDifficultyCalculator.cs @@ -11,6 +11,8 @@ using osu.Game.Beatmaps; using osu.Game.Beatmaps.Legacy; using osu.Game.Rulesets; +using osu.Game.Rulesets.Mods; +using osu.Game.Rulesets.Scoring.Legacy; namespace osu.Server.DifficultyCalculator { @@ -38,7 +40,17 @@ public ServerDifficultyCalculator(int[]? rulesetIds = null, bool processConverts } } - public void ProcessBeatmap(WorkingBeatmap beatmap) + public void ProcessAll(WorkingBeatmap beatmap) + { + ProcessDifficulty(beatmap); + ProcessLegacyAttributes(beatmap); + } + + public void ProcessDifficulty(WorkingBeatmap beatmap) => run(beatmap, processDifficulty); + + public void ProcessLegacyAttributes(WorkingBeatmap beatmap) => run(beatmap, processLegacyAttributes); + + private void run(WorkingBeatmap beatmap, Action callback) { int beatmapId = beatmap.BeatmapInfo.OnlineID; @@ -58,10 +70,10 @@ public void ProcessBeatmap(WorkingBeatmap beatmap) if (processConverts && beatmap.BeatmapInfo.Ruleset.OnlineID == 0) { foreach (var ruleset in processableRulesets) - computeDifficulty(beatmapId, beatmap, ruleset, conn); + callback(beatmapId, beatmap, ruleset, conn); } else if (processableRulesets.Any(r => r.RulesetInfo.OnlineID == beatmap.BeatmapInfo.Ruleset.OnlineID)) - computeDifficulty(beatmapId, beatmap, beatmap.BeatmapInfo.Ruleset.CreateInstance(), conn); + callback(beatmapId, beatmap, beatmap.BeatmapInfo.Ruleset.CreateInstance(), conn); } } catch (Exception e) @@ -70,12 +82,9 @@ public void ProcessBeatmap(WorkingBeatmap beatmap) } } - private void computeDifficulty(int beatmapId, WorkingBeatmap beatmap, Ruleset ruleset, MySqlConnection conn) + private void processDifficulty(int beatmapId, WorkingBeatmap beatmap, Ruleset ruleset, MySqlConnection conn) { - var difficultyCalculator = ruleset.CreateDifficultyCalculator(beatmap); - difficultyCalculator.ComputeLegacyScoringValues = true; - - foreach (var attribute in difficultyCalculator.CalculateAllLegacyCombinations()) + foreach (var attribute in ruleset.CreateDifficultyCalculator(beatmap).CalculateAllLegacyCombinations()) { if (dryRun) continue; @@ -153,6 +162,31 @@ private void computeDifficulty(int beatmapId, WorkingBeatmap beatmap, Ruleset ru } } + private void processLegacyAttributes(int beatmapId, WorkingBeatmap beatmap, Ruleset ruleset, MySqlConnection conn) + { + Mod? classicMod = ruleset.CreateMod(); + Mod[] mods = classicMod != null ? new[] { classicMod } : Array.Empty(); + + ILegacyScoreSimulator simulator = ((ILegacyRuleset)ruleset).CreateLegacyScoreSimulator(); + LegacyScoreAttributes attributes = simulator.Simulate(beatmap, beatmap.GetPlayableBeatmap(ruleset.RulesetInfo, mods)); + + if (dryRun) + return; + + conn.Execute( + "INSERT INTO `osu_beatmap_scoring_attribs` (`beatmap_id`, `mode`, `legacy_accuracy_score`, `legacy_combo_score`, `legacy_bonus_score_ratio`) " + + "VALUES (@BeatmapId, @Mode, @AccuracyScore, @ComboScore, @BonusScoreRatio) " + + "ON DUPLICATE KEY UPDATE `legacy_accuracy_score` = @AccuracyScore, `legacy_combo_score` = @ComboScore, `legacy_bonus_score_ratio` = @BonusScoreRatio", + new + { + BeatmapId = beatmapId, + Mode = ruleset.RulesetInfo.OnlineID, + AccuracyScore = attributes.AccuracyScore, + ComboScore = attributes.ComboScore, + BonusScoreRatio = attributes.BonusScoreRatio + }); + } + private static List getRulesets() { const string ruleset_library_prefix = "osu.Game.Rulesets"; diff --git a/osu.Server.DifficultyCalculator/osu.Server.DifficultyCalculator.csproj b/osu.Server.DifficultyCalculator/osu.Server.DifficultyCalculator.csproj index 3588352..338cbc3 100644 --- a/osu.Server.DifficultyCalculator/osu.Server.DifficultyCalculator.csproj +++ b/osu.Server.DifficultyCalculator/osu.Server.DifficultyCalculator.csproj @@ -10,18 +10,18 @@ true - + - - - - + + + + - - - - - + + + + + diff --git a/osu.Server.Queues.BeatmapProcessor/BeatmapProcessor.cs b/osu.Server.Queues.BeatmapProcessor/BeatmapProcessor.cs index b2319f0..27c2a43 100644 --- a/osu.Server.Queues.BeatmapProcessor/BeatmapProcessor.cs +++ b/osu.Server.Queues.BeatmapProcessor/BeatmapProcessor.cs @@ -34,7 +34,7 @@ protected override void ProcessResult(BeatmapItem item) // ensure the correct online id is set working.BeatmapInfo.OnlineID = (int)beatmapId; - calculator.ProcessBeatmap(working); + calculator.ProcessAll(working); } } } diff --git a/osu.Server.Queues.BeatmapProcessor/osu.Server.Queues.BeatmapProcessor.csproj b/osu.Server.Queues.BeatmapProcessor/osu.Server.Queues.BeatmapProcessor.csproj index 6667b8a..3ed014d 100644 --- a/osu.Server.Queues.BeatmapProcessor/osu.Server.Queues.BeatmapProcessor.csproj +++ b/osu.Server.Queues.BeatmapProcessor/osu.Server.Queues.BeatmapProcessor.csproj @@ -10,8 +10,8 @@ - - + +