Skip to content

Commit

Permalink
Remove filtering in all unnecessary cases
Browse files Browse the repository at this point in the history
  • Loading branch information
smoogipoo committed Oct 13, 2024
1 parent 98d9675 commit 8ebeeaf
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ public override void Execute()
private Result processBeatmap(WorkingBeatmap beatmap)
{
var ruleset = LegacyHelper.GetRulesetFromLegacyID(Ruleset ?? beatmap.BeatmapInfo.Ruleset.OnlineID);

var mods = LegacyHelper.FilterLegacyMods(beatmap.BeatmapInfo, ruleset, getMods(ruleset));
var mods = getMods(ruleset);

var legacyRuleset = (ILegacyRuleset)ruleset;
var simulator = legacyRuleset.CreateLegacyScoreSimulator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public virtual void OnExecute(CommandLineApplication app, IConsole console)
var ruleset = LegacyHelper.GetRulesetFromLegacyID(Ruleset);

var workingBeatmap = ProcessorWorkingBeatmap.FromFileOrId(Beatmap);
Mod[] mods = [ruleset.CreateMod<ModClassic>(), .. LegacyHelper.FilterLegacyMods(workingBeatmap.BeatmapInfo, ruleset, getMods(ruleset))];
Mod[] mods = [ruleset.CreateMod<ModClassic>(), .. getMods(ruleset)];

var beatmap = workingBeatmap.GetPlayableBeatmap(ruleset.RulesetInfo, mods);

Expand Down
26 changes: 0 additions & 26 deletions PerformanceCalculator/LegacyHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Linq;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Legacy;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Catch;
using osu.Game.Rulesets.Catch.Difficulty;
using osu.Game.Rulesets.Difficulty;
using osu.Game.Rulesets.Mania;
using osu.Game.Rulesets.Mania.Difficulty;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Difficulty;
using osu.Game.Rulesets.Taiko;
Expand Down Expand Up @@ -63,28 +59,6 @@ public static string GetRulesetShortNameFromId(int id)
}
}

/// <summary>
/// Transforms a given <see cref="Mod"/> combination into one which is applicable to legacy scores.
/// This is used to match osu!stable/osu!web calculations for the time being, until such a point that these mods do get considered.
/// </summary>
public static LegacyMods ConvertToLegacyMods(BeatmapInfo beatmapInfo, Ruleset ruleset, Mod[] mods)
{
var legacyMods = ruleset.ConvertToLegacyMods(mods);

// mods that are not represented in `LegacyMods` (but we can approximate them well enough with others)
if (mods.Any(mod => mod is ModDaycore))
legacyMods |= LegacyMods.HalfTime;

return legacyMods;
}

/// <summary>
/// Transforms a given <see cref="Mod"/> combination into one which is applicable to legacy scores.
/// This is used to match osu!stable/osu!web calculations for the time being, until such a point that these mods do get considered.
/// </summary>
public static Mod[] FilterLegacyMods(BeatmapInfo beatmapInfo, Ruleset ruleset, Mod[] mods)
=> ruleset.ConvertFromLegacyMods(ConvertToLegacyMods(beatmapInfo, ruleset, mods)).ToArray();

public static DifficultyAttributes CreateDifficultyAttributes(int legacyId)
{
switch (legacyId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public override void Execute()

if (score.ScoreInfo.IsLegacyScore)
{
difficultyMods = LegacyHelper.FilterLegacyMods(workingBeatmap.BeatmapInfo, ruleset, difficultyMods);
score.ScoreInfo.LegacyTotalScore = (int)score.ScoreInfo.TotalScore;
LegacyScoreDecoder.PopulateMaximumStatistics(score.ScoreInfo, workingBeatmap);
StandardisedScoreMigrationTools.UpdateFromLegacy(
Expand Down
44 changes: 43 additions & 1 deletion PerformanceCalculator/Performance/ScorePerformanceCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using osu.Game.Rulesets.Catch.Difficulty;
using osu.Game.Rulesets.Difficulty;
using osu.Game.Rulesets.Mania.Difficulty;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Difficulty;
using osu.Game.Rulesets.Taiko.Difficulty;
using osu.Game.Scoring;
Expand Down Expand Up @@ -46,7 +47,7 @@ public override void Execute()

if (OnlineAttributes)
{
LegacyMods legacyMods = LegacyHelper.ConvertToLegacyMods(workingBeatmap.BeatmapInfo, ruleset, score.Mods);
LegacyMods legacyMods = convertToLegacyMods(workingBeatmap.BeatmapInfo, ruleset, score.Mods);
attributes = queryApiAttributes(apiScore.BeatmapID, apiScore.RulesetID, legacyMods);
}
else
Expand Down Expand Up @@ -121,6 +122,47 @@ DifficultyAttributes getMergedAttributes<TAttributes>(APIBeatmap apiBeatmap)
}
}

/// <summary>
/// Transforms a given <see cref="Mod"/> combination into one which is applicable to legacy scores.
/// This should only be used to match performance calculations using databased attributes.
/// </summary>
private static LegacyMods convertToLegacyMods(BeatmapInfo beatmapInfo, Ruleset ruleset, Mod[] mods)
{
var legacyMods = ruleset.ConvertToLegacyMods(mods);

// mods that are not represented in `LegacyMods` (but we can approximate them well enough with others)
if (mods.Any(mod => mod is ModDaycore))
legacyMods |= LegacyMods.HalfTime;

// See: https://github.com/ppy/osu-queue-score-statistics/blob/2264bfa68e14bb16ec71a7cac2072bdcfaf565b6/osu.Server.Queues.ScoreStatisticsProcessor/Helpers/LegacyModsHelper.cs
static LegacyMods maskRelevantMods(LegacyMods mods, bool isConvertedBeatmap, int rulesetId)
{
const LegacyMods key_mods = LegacyMods.Key1 | LegacyMods.Key2 | LegacyMods.Key3 | LegacyMods.Key4 | LegacyMods.Key5 | LegacyMods.Key6 | LegacyMods.Key7 | LegacyMods.Key8
| LegacyMods.Key9 | LegacyMods.KeyCoop;

LegacyMods relevantMods = LegacyMods.DoubleTime | LegacyMods.HalfTime | LegacyMods.HardRock | LegacyMods.Easy;

switch (rulesetId)
{
case 0:
if ((mods & LegacyMods.Flashlight) > 0)
relevantMods |= LegacyMods.Flashlight | LegacyMods.Hidden | LegacyMods.TouchDevice;
else
relevantMods |= LegacyMods.Flashlight | LegacyMods.TouchDevice;
break;

case 3:
if (isConvertedBeatmap)
relevantMods |= key_mods;
break;
}

return mods & relevantMods;
}

return maskRelevantMods(legacyMods, ruleset.RulesetInfo.OnlineID != beatmapInfo.Ruleset.OnlineID, ruleset.RulesetInfo.OnlineID);
}

[JsonObject(MemberSerialization.OptIn)]
private class AttributesResponse<T>
where T : DifficultyAttributes
Expand Down

0 comments on commit 8ebeeaf

Please sign in to comment.