From 377ba2673aa1f6869e7bca74de95df2e99717365 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 22 Nov 2021 16:52:54 +0900 Subject: [PATCH 1/2] Use `Ruleset`'s `ShortName` for mod caching purposes --- osu.Game/Rulesets/Ruleset.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index ade763eed8..a252bd4786 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -39,7 +39,7 @@ namespace osu.Game.Rulesets { public RulesetInfo RulesetInfo { get; internal set; } - private static readonly ConcurrentDictionary mod_reference_cache = new ConcurrentDictionary(); + private static readonly ConcurrentDictionary mod_reference_cache = new ConcurrentDictionary(); /// /// A queryable source containing all available mods. @@ -49,11 +49,8 @@ namespace osu.Game.Rulesets { get { - if (!(RulesetInfo.ID is int id)) - return CreateAllMods(); - - if (!mod_reference_cache.TryGetValue(id, out var mods)) - mod_reference_cache[id] = mods = CreateAllMods().Cast().ToArray(); + if (!mod_reference_cache.TryGetValue(ShortName, out var mods)) + mod_reference_cache[ShortName] = mods = CreateAllMods().Cast().ToArray(); return mods; } From 6c36770eb388fe80f079b6001e7f4899bc1f20c9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 22 Nov 2021 21:41:09 +0900 Subject: [PATCH 2/2] Add back allowance for tests scenes using empty `ShortName` --- osu.Game/Rulesets/Ruleset.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index a252bd4786..31ebcfd600 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -49,6 +49,10 @@ namespace osu.Game.Rulesets { get { + // Is the case for many test usages. + if (string.IsNullOrEmpty(ShortName)) + return CreateAllMods(); + if (!mod_reference_cache.TryGetValue(ShortName, out var mods)) mod_reference_cache[ShortName] = mods = CreateAllMods().Cast().ToArray();