Merge pull request #10711 from peppy/rename-cache-classes

Rename cache classes in line with their function (and share a base implementation)
This commit is contained in:
Dan Balasescu
2020-11-06 14:34:47 +09:00
committed by GitHub
15 changed files with 121 additions and 101 deletions

View File

@ -14,8 +14,8 @@ namespace osu.Game.Tests.Beatmaps
[Test] [Test]
public void TestKeyEqualsWithDifferentModInstances() public void TestKeyEqualsWithDifferentModInstances()
{ {
var key1 = new BeatmapDifficultyManager.DifficultyCacheLookup(1234, 0, new Mod[] { new OsuModHardRock(), new OsuModHidden() }); var key1 = new BeatmapDifficultyCache.DifficultyCacheLookup(1234, 0, new Mod[] { new OsuModHardRock(), new OsuModHidden() });
var key2 = new BeatmapDifficultyManager.DifficultyCacheLookup(1234, 0, new Mod[] { new OsuModHardRock(), new OsuModHidden() }); var key2 = new BeatmapDifficultyCache.DifficultyCacheLookup(1234, 0, new Mod[] { new OsuModHardRock(), new OsuModHidden() });
Assert.That(key1, Is.EqualTo(key2)); Assert.That(key1, Is.EqualTo(key2));
} }
@ -23,8 +23,8 @@ namespace osu.Game.Tests.Beatmaps
[Test] [Test]
public void TestKeyEqualsWithDifferentModOrder() public void TestKeyEqualsWithDifferentModOrder()
{ {
var key1 = new BeatmapDifficultyManager.DifficultyCacheLookup(1234, 0, new Mod[] { new OsuModHardRock(), new OsuModHidden() }); var key1 = new BeatmapDifficultyCache.DifficultyCacheLookup(1234, 0, new Mod[] { new OsuModHardRock(), new OsuModHidden() });
var key2 = new BeatmapDifficultyManager.DifficultyCacheLookup(1234, 0, new Mod[] { new OsuModHidden(), new OsuModHardRock() }); var key2 = new BeatmapDifficultyCache.DifficultyCacheLookup(1234, 0, new Mod[] { new OsuModHidden(), new OsuModHardRock() });
Assert.That(key1, Is.EqualTo(key2)); Assert.That(key1, Is.EqualTo(key2));
} }
@ -47,7 +47,7 @@ namespace osu.Game.Tests.Beatmaps
[TestCase(8.3, DifficultyRating.ExpertPlus)] [TestCase(8.3, DifficultyRating.ExpertPlus)]
public void TestDifficultyRatingMapping(double starRating, DifficultyRating expectedBracket) public void TestDifficultyRatingMapping(double starRating, DifficultyRating expectedBracket)
{ {
var actualBracket = BeatmapDifficultyManager.GetDifficultyRating(starRating); var actualBracket = BeatmapDifficultyCache.GetDifficultyRating(starRating);
Assert.AreEqual(expectedBracket, actualBracket); Assert.AreEqual(expectedBracket, actualBracket);
} }

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
@ -11,25 +10,25 @@ using System.Threading.Tasks;
using JetBrains.Annotations; using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics.Containers;
using osu.Framework.Lists; using osu.Framework.Lists;
using osu.Framework.Logging; using osu.Framework.Logging;
using osu.Framework.Threading; using osu.Framework.Threading;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Database;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Difficulty;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
namespace osu.Game.Beatmaps namespace osu.Game.Beatmaps
{ {
public class BeatmapDifficultyManager : CompositeDrawable /// <summary>
/// A component which performs and acts as a central cache for difficulty calculations of beatmap/ruleset/mod combinations.
/// Currently not persisted between game sessions.
/// </summary>
public class BeatmapDifficultyCache : MemoryCachingComponent<BeatmapDifficultyCache.DifficultyCacheLookup, StarDifficulty>
{ {
// Too many simultaneous updates can lead to stutters. One thread seems to work fine for song select display purposes. // Too many simultaneous updates can lead to stutters. One thread seems to work fine for song select display purposes.
private readonly ThreadedTaskScheduler updateScheduler = new ThreadedTaskScheduler(1, nameof(BeatmapDifficultyManager)); private readonly ThreadedTaskScheduler updateScheduler = new ThreadedTaskScheduler(1, nameof(BeatmapDifficultyCache));
// A permanent cache to prevent re-computations.
private readonly ConcurrentDictionary<DifficultyCacheLookup, StarDifficulty> difficultyCache = new ConcurrentDictionary<DifficultyCacheLookup, StarDifficulty>();
// All bindables that should be updated along with the current ruleset + mods. // All bindables that should be updated along with the current ruleset + mods.
private readonly LockedWeakList<BindableStarDifficulty> trackedBindables = new LockedWeakList<BindableStarDifficulty>(); private readonly LockedWeakList<BindableStarDifficulty> trackedBindables = new LockedWeakList<BindableStarDifficulty>();
@ -239,7 +238,7 @@ namespace osu.Game.Beatmaps
var calculator = ruleset.CreateDifficultyCalculator(beatmapManager.GetWorkingBeatmap(beatmapInfo)); var calculator = ruleset.CreateDifficultyCalculator(beatmapManager.GetWorkingBeatmap(beatmapInfo));
var attributes = calculator.Calculate(key.Mods); var attributes = calculator.Calculate(key.Mods);
return difficultyCache[key] = new StarDifficulty(attributes); return Cache[key] = new StarDifficulty(attributes);
} }
catch (BeatmapInvalidForRulesetException e) catch (BeatmapInvalidForRulesetException e)
{ {
@ -250,7 +249,7 @@ namespace osu.Game.Beatmaps
if (rulesetInfo.Equals(beatmapInfo.Ruleset)) if (rulesetInfo.Equals(beatmapInfo.Ruleset))
{ {
Logger.Error(e, $"Failed to convert {beatmapInfo.OnlineBeatmapID} to the beatmap's default ruleset ({beatmapInfo.Ruleset})."); Logger.Error(e, $"Failed to convert {beatmapInfo.OnlineBeatmapID} to the beatmap's default ruleset ({beatmapInfo.Ruleset}).");
return difficultyCache[key] = new StarDifficulty(); return Cache[key] = new StarDifficulty();
} }
// Check the cache first because this is now a different ruleset than the one previously guarded against. // Check the cache first because this is now a different ruleset than the one previously guarded against.
@ -261,7 +260,7 @@ namespace osu.Game.Beatmaps
} }
catch catch
{ {
return difficultyCache[key] = new StarDifficulty(); return Cache[key] = new StarDifficulty();
} }
} }
@ -290,7 +289,7 @@ namespace osu.Game.Beatmaps
} }
key = new DifficultyCacheLookup(beatmapInfo.ID, rulesetInfo.ID.Value, mods); key = new DifficultyCacheLookup(beatmapInfo.ID, rulesetInfo.ID.Value, mods);
return difficultyCache.TryGetValue(key, out existingDifficulty); return Cache.TryGetValue(key, out existingDifficulty);
} }
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)
@ -344,49 +343,4 @@ namespace osu.Game.Beatmaps
} }
} }
} }
public readonly struct StarDifficulty
{
/// <summary>
/// The star difficulty rating for the given beatmap.
/// </summary>
public readonly double Stars;
/// <summary>
/// The maximum combo achievable on the given beatmap.
/// </summary>
public readonly int MaxCombo;
/// <summary>
/// The difficulty attributes computed for the given beatmap.
/// Might not be available if the star difficulty is associated with a beatmap that's not locally available.
/// </summary>
[CanBeNull]
public readonly DifficultyAttributes Attributes;
/// <summary>
/// Creates a <see cref="StarDifficulty"/> structure based on <see cref="DifficultyAttributes"/> computed
/// by a <see cref="DifficultyCalculator"/>.
/// </summary>
public StarDifficulty([NotNull] DifficultyAttributes attributes)
{
Stars = attributes.StarRating;
MaxCombo = attributes.MaxCombo;
Attributes = attributes;
// Todo: Add more members (BeatmapInfo.DifficultyRating? Attributes? Etc...)
}
/// <summary>
/// Creates a <see cref="StarDifficulty"/> structure with a pre-populated star difficulty and max combo
/// in scenarios where computing <see cref="DifficultyAttributes"/> is not feasible (i.e. when working with online sources).
/// </summary>
public StarDifficulty(double starDifficulty, int maxCombo)
{
Stars = starDifficulty;
MaxCombo = maxCombo;
Attributes = null;
}
public DifficultyRating DifficultyRating => BeatmapDifficultyManager.GetDifficultyRating(Stars);
}
} }

View File

@ -136,7 +136,7 @@ namespace osu.Game.Beatmaps
public List<ScoreInfo> Scores { get; set; } public List<ScoreInfo> Scores { get; set; }
[JsonIgnore] [JsonIgnore]
public DifficultyRating DifficultyRating => BeatmapDifficultyManager.GetDifficultyRating(StarDifficulty); public DifficultyRating DifficultyRating => BeatmapDifficultyCache.GetDifficultyRating(StarDifficulty);
public string[] SearchableTerms => new[] public string[] SearchableTerms => new[]
{ {

View File

@ -142,7 +142,7 @@ namespace osu.Game.Beatmaps.Drawables
private CancellationTokenSource difficultyCancellation; private CancellationTokenSource difficultyCancellation;
[Resolved] [Resolved]
private BeatmapDifficultyManager difficultyManager { get; set; } private BeatmapDifficultyCache difficultyCache { get; set; }
public DifficultyRetriever(BeatmapInfo beatmap, RulesetInfo ruleset, IReadOnlyList<Mod> mods) public DifficultyRetriever(BeatmapInfo beatmap, RulesetInfo ruleset, IReadOnlyList<Mod> mods)
{ {
@ -158,8 +158,8 @@ namespace osu.Game.Beatmaps.Drawables
{ {
difficultyCancellation = new CancellationTokenSource(); difficultyCancellation = new CancellationTokenSource();
localStarDifficulty = ruleset != null localStarDifficulty = ruleset != null
? difficultyManager.GetBindableDifficulty(beatmap, ruleset, mods, difficultyCancellation.Token) ? difficultyCache.GetBindableDifficulty(beatmap, ruleset, mods, difficultyCancellation.Token)
: difficultyManager.GetBindableDifficulty(beatmap, difficultyCancellation.Token); : difficultyCache.GetBindableDifficulty(beatmap, difficultyCancellation.Token);
localStarDifficulty.BindValueChanged(difficulty => StarDifficulty.Value = difficulty.NewValue); localStarDifficulty.BindValueChanged(difficulty => StarDifficulty.Value = difficulty.NewValue);
} }

View File

@ -0,0 +1,53 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using JetBrains.Annotations;
using osu.Game.Rulesets.Difficulty;
namespace osu.Game.Beatmaps
{
public readonly struct StarDifficulty
{
/// <summary>
/// The star difficulty rating for the given beatmap.
/// </summary>
public readonly double Stars;
/// <summary>
/// The maximum combo achievable on the given beatmap.
/// </summary>
public readonly int MaxCombo;
/// <summary>
/// The difficulty attributes computed for the given beatmap.
/// Might not be available if the star difficulty is associated with a beatmap that's not locally available.
/// </summary>
[CanBeNull]
public readonly DifficultyAttributes Attributes;
/// <summary>
/// Creates a <see cref="StarDifficulty"/> structure based on <see cref="DifficultyAttributes"/> computed
/// by a <see cref="DifficultyCalculator"/>.
/// </summary>
public StarDifficulty([NotNull] DifficultyAttributes attributes)
{
Stars = attributes.StarRating;
MaxCombo = attributes.MaxCombo;
Attributes = attributes;
// Todo: Add more members (BeatmapInfo.DifficultyRating? Attributes? Etc...)
}
/// <summary>
/// Creates a <see cref="StarDifficulty"/> structure with a pre-populated star difficulty and max combo
/// in scenarios where computing <see cref="DifficultyAttributes"/> is not feasible (i.e. when working with online sources).
/// </summary>
public StarDifficulty(double starDifficulty, int maxCombo)
{
Stars = starDifficulty;
MaxCombo = maxCombo;
Attributes = null;
}
public DifficultyRating DifficultyRating => BeatmapDifficultyCache.GetDifficultyRating(Stars);
}
}

View File

@ -0,0 +1,17 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Concurrent;
using osu.Framework.Graphics;
namespace osu.Game.Database
{
/// <summary>
/// A component which performs lookups (or calculations) and caches the results.
/// Currently not persisted between game sessions.
/// </summary>
public abstract class MemoryCachingComponent<TLookup, TValue> : Component
{
protected readonly ConcurrentDictionary<TLookup, TValue> Cache = new ConcurrentDictionary<TLookup, TValue>();
}
}

View File

@ -59,7 +59,7 @@ namespace osu.Game
protected ScoreManager ScoreManager; protected ScoreManager ScoreManager;
protected BeatmapDifficultyManager DifficultyManager; protected BeatmapDifficultyCache DifficultyCache;
protected SkinManager SkinManager; protected SkinManager SkinManager;
@ -202,7 +202,7 @@ namespace osu.Game
dependencies.Cache(FileStore = new FileStore(contextFactory, Storage)); dependencies.Cache(FileStore = new FileStore(contextFactory, Storage));
// ordering is important here to ensure foreign keys rules are not broken in ModelStore.Cleanup() // ordering is important here to ensure foreign keys rules are not broken in ModelStore.Cleanup()
dependencies.Cache(ScoreManager = new ScoreManager(RulesetStore, () => BeatmapManager, Storage, API, contextFactory, Host, () => DifficultyManager, LocalConfig)); dependencies.Cache(ScoreManager = new ScoreManager(RulesetStore, () => BeatmapManager, Storage, API, contextFactory, Host, () => DifficultyCache, LocalConfig));
dependencies.Cache(BeatmapManager = new BeatmapManager(Storage, contextFactory, RulesetStore, API, Audio, Host, defaultBeatmap, true)); dependencies.Cache(BeatmapManager = new BeatmapManager(Storage, contextFactory, RulesetStore, API, Audio, Host, defaultBeatmap, true));
// this should likely be moved to ArchiveModelManager when another case appers where it is necessary // this should likely be moved to ArchiveModelManager when another case appers where it is necessary
@ -226,10 +226,10 @@ namespace osu.Game
ScoreManager.Undelete(getBeatmapScores(item), true); ScoreManager.Undelete(getBeatmapScores(item), true);
}); });
dependencies.Cache(DifficultyManager = new BeatmapDifficultyManager()); dependencies.Cache(DifficultyCache = new BeatmapDifficultyCache());
AddInternal(DifficultyManager); AddInternal(DifficultyCache);
var scorePerformanceManager = new ScorePerformanceManager(); var scorePerformanceManager = new ScorePerformanceCache();
dependencies.Cache(scorePerformanceManager); dependencies.Cache(scorePerformanceManager);
AddInternal(scorePerformanceManager); AddInternal(scorePerformanceManager);

View File

@ -37,13 +37,13 @@ namespace osu.Game.Scoring
private readonly Func<BeatmapManager> beatmaps; private readonly Func<BeatmapManager> beatmaps;
[CanBeNull] [CanBeNull]
private readonly Func<BeatmapDifficultyManager> difficulties; private readonly Func<BeatmapDifficultyCache> difficulties;
[CanBeNull] [CanBeNull]
private readonly OsuConfigManager configManager; private readonly OsuConfigManager configManager;
public ScoreManager(RulesetStore rulesets, Func<BeatmapManager> beatmaps, Storage storage, IAPIProvider api, IDatabaseContextFactory contextFactory, IIpcHost importHost = null, public ScoreManager(RulesetStore rulesets, Func<BeatmapManager> beatmaps, Storage storage, IAPIProvider api, IDatabaseContextFactory contextFactory, IIpcHost importHost = null,
Func<BeatmapDifficultyManager> difficulties = null, OsuConfigManager configManager = null) Func<BeatmapDifficultyCache> difficulties = null, OsuConfigManager configManager = null)
: base(storage, contextFactory, api, new ScoreStore(contextFactory, storage), importHost) : base(storage, contextFactory, api, new ScoreStore(contextFactory, storage), importHost)
{ {
this.rulesets = rulesets; this.rulesets = rulesets;
@ -121,14 +121,14 @@ namespace osu.Game.Scoring
public readonly Bindable<ScoringMode> ScoringMode = new Bindable<ScoringMode>(); public readonly Bindable<ScoringMode> ScoringMode = new Bindable<ScoringMode>();
private readonly ScoreInfo score; private readonly ScoreInfo score;
private readonly Func<BeatmapDifficultyManager> difficulties; private readonly Func<BeatmapDifficultyCache> difficulties;
/// <summary> /// <summary>
/// Creates a new <see cref="TotalScoreBindable"/>. /// Creates a new <see cref="TotalScoreBindable"/>.
/// </summary> /// </summary>
/// <param name="score">The <see cref="ScoreInfo"/> to provide the total score of.</param> /// <param name="score">The <see cref="ScoreInfo"/> to provide the total score of.</param>
/// <param name="difficulties">A function to retrieve the <see cref="BeatmapDifficultyManager"/>.</param> /// <param name="difficulties">A function to retrieve the <see cref="BeatmapDifficultyCache"/>.</param>
public TotalScoreBindable(ScoreInfo score, Func<BeatmapDifficultyManager> difficulties) public TotalScoreBindable(ScoreInfo score, Func<BeatmapDifficultyCache> difficulties)
{ {
this.score = score; this.score = score;
this.difficulties = difficulties; this.difficulties = difficulties;

View File

@ -2,27 +2,23 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Collections.Concurrent;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using JetBrains.Annotations; using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Database;
namespace osu.Game.Scoring namespace osu.Game.Scoring
{ {
/// <summary> /// <summary>
/// A global component which calculates and caches results of performance calculations for locally databased scores. /// A component which performs and acts as a central cache for performance calculations of locally databased scores.
/// Currently not persisted between game sessions.
/// </summary> /// </summary>
public class ScorePerformanceManager : Component public class ScorePerformanceCache : MemoryCachingComponent<ScorePerformanceCache.PerformanceCacheLookup, double>
{ {
// this cache will grow indefinitely per session and should be considered temporary.
// this whole component should likely be replaced with database persistence.
private readonly ConcurrentDictionary<PerformanceCacheLookup, double> performanceCache = new ConcurrentDictionary<PerformanceCacheLookup, double>();
[Resolved] [Resolved]
private BeatmapDifficultyManager difficultyManager { get; set; } private BeatmapDifficultyCache difficultyCache { get; set; }
/// <summary> /// <summary>
/// Calculates performance for the given <see cref="ScoreInfo"/>. /// Calculates performance for the given <see cref="ScoreInfo"/>.
@ -33,7 +29,7 @@ namespace osu.Game.Scoring
{ {
var lookupKey = new PerformanceCacheLookup(score); var lookupKey = new PerformanceCacheLookup(score);
if (performanceCache.TryGetValue(lookupKey, out double performance)) if (Cache.TryGetValue(lookupKey, out double performance))
return Task.FromResult((double?)performance); return Task.FromResult((double?)performance);
return computePerformanceAsync(score, lookupKey, token); return computePerformanceAsync(score, lookupKey, token);
@ -41,7 +37,7 @@ namespace osu.Game.Scoring
private async Task<double?> computePerformanceAsync(ScoreInfo score, PerformanceCacheLookup lookupKey, CancellationToken token = default) private async Task<double?> computePerformanceAsync(ScoreInfo score, PerformanceCacheLookup lookupKey, CancellationToken token = default)
{ {
var attributes = await difficultyManager.GetDifficultyAsync(score.Beatmap, score.Ruleset, score.Mods, token); var attributes = await difficultyCache.GetDifficultyAsync(score.Beatmap, score.Ruleset, score.Mods, token);
// Performance calculation requires the beatmap and ruleset to be locally available. If not, return a default value. // Performance calculation requires the beatmap and ruleset to be locally available. If not, return a default value.
if (attributes.Attributes == null) if (attributes.Attributes == null)
@ -53,7 +49,7 @@ namespace osu.Game.Scoring
var total = calculator?.Calculate(); var total = calculator?.Calculate();
if (total.HasValue) if (total.HasValue)
performanceCache[lookupKey] = total.Value; Cache[lookupKey] = total.Value;
return total; return total;
} }

View File

@ -56,7 +56,7 @@ namespace osu.Game.Screens.Ranking.Expanded
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(BeatmapDifficultyManager beatmapDifficultyManager) private void load(BeatmapDifficultyCache beatmapDifficultyCache)
{ {
var beatmap = score.Beatmap; var beatmap = score.Beatmap;
var metadata = beatmap.BeatmapSet?.Metadata ?? beatmap.Metadata; var metadata = beatmap.BeatmapSet?.Metadata ?? beatmap.Metadata;
@ -143,7 +143,7 @@ namespace osu.Game.Screens.Ranking.Expanded
Spacing = new Vector2(5, 0), Spacing = new Vector2(5, 0),
Children = new Drawable[] Children = new Drawable[]
{ {
new StarRatingDisplay(beatmapDifficultyManager.GetDifficulty(beatmap, score.Ruleset, score.Mods)) new StarRatingDisplay(beatmapDifficultyCache.GetDifficulty(beatmap, score.Ruleset, score.Mods))
{ {
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft Origin = Anchor.CentreLeft

View File

@ -34,7 +34,7 @@ namespace osu.Game.Screens.Ranking.Expanded
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours, BeatmapDifficultyManager difficultyManager) private void load(OsuColour colours, BeatmapDifficultyCache difficultyCache)
{ {
AutoSizeAxes = Axes.Both; AutoSizeAxes = Axes.Both;

View File

@ -28,7 +28,7 @@ namespace osu.Game.Screens.Ranking.Expanded.Statistics
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(ScorePerformanceManager performanceManager) private void load(ScorePerformanceCache performanceCache)
{ {
if (score.PP.HasValue) if (score.PP.HasValue)
{ {
@ -36,8 +36,8 @@ namespace osu.Game.Screens.Ranking.Expanded.Statistics
} }
else else
{ {
performanceManager.CalculatePerformanceAsync(score, cancellationTokenSource.Token) performanceCache.CalculatePerformanceAsync(score, cancellationTokenSource.Token)
.ContinueWith(t => Schedule(() => setPerformanceValue(t.Result)), cancellationTokenSource.Token); .ContinueWith(t => Schedule(() => setPerformanceValue(t.Result)), cancellationTokenSource.Token);
} }
} }

View File

@ -41,7 +41,7 @@ namespace osu.Game.Screens.Select
private readonly IBindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>(); private readonly IBindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
[Resolved] [Resolved]
private BeatmapDifficultyManager difficultyManager { get; set; } private BeatmapDifficultyCache difficultyCache { get; set; }
private IBindable<StarDifficulty> beatmapDifficulty; private IBindable<StarDifficulty> beatmapDifficulty;
@ -100,7 +100,7 @@ namespace osu.Game.Screens.Select
cancellationSource = new CancellationTokenSource(); cancellationSource = new CancellationTokenSource();
beatmapDifficulty?.UnbindAll(); beatmapDifficulty?.UnbindAll();
beatmapDifficulty = difficultyManager.GetBindableDifficulty(beatmap.BeatmapInfo, cancellationSource.Token); beatmapDifficulty = difficultyCache.GetBindableDifficulty(beatmap.BeatmapInfo, cancellationSource.Token);
beatmapDifficulty.BindValueChanged(_ => updateDisplay()); beatmapDifficulty.BindValueChanged(_ => updateDisplay());
updateDisplay(); updateDisplay();

View File

@ -55,7 +55,7 @@ namespace osu.Game.Screens.Select.Carousel
private BeatmapSetOverlay beatmapOverlay { get; set; } private BeatmapSetOverlay beatmapOverlay { get; set; }
[Resolved] [Resolved]
private BeatmapDifficultyManager difficultyManager { get; set; } private BeatmapDifficultyCache difficultyCache { get; set; }
[Resolved(CanBeNull = true)] [Resolved(CanBeNull = true)]
private CollectionManager collectionManager { get; set; } private CollectionManager collectionManager { get; set; }
@ -216,7 +216,7 @@ namespace osu.Game.Screens.Select.Carousel
if (Item.State.Value != CarouselItemState.Collapsed) if (Item.State.Value != CarouselItemState.Collapsed)
{ {
// We've potentially cancelled the computation above so a new bindable is required. // We've potentially cancelled the computation above so a new bindable is required.
starDifficultyBindable = difficultyManager.GetBindableDifficulty(beatmap, (starDifficultyCancellationSource = new CancellationTokenSource()).Token); starDifficultyBindable = difficultyCache.GetBindableDifficulty(beatmap, (starDifficultyCancellationSource = new CancellationTokenSource()).Token);
starDifficultyBindable.BindValueChanged(d => starCounter.Current = (float)d.NewValue.Stars, true); starDifficultyBindable.BindValueChanged(d => starCounter.Current = (float)d.NewValue.Stars, true);
} }

View File

@ -32,7 +32,7 @@ namespace osu.Game.Screens.Select.Details
private IBindable<RulesetInfo> ruleset { get; set; } private IBindable<RulesetInfo> ruleset { get; set; }
[Resolved] [Resolved]
private BeatmapDifficultyManager difficultyManager { get; set; } private BeatmapDifficultyCache difficultyCache { get; set; }
protected readonly StatisticRow FirstValue, HpDrain, Accuracy, ApproachRate; protected readonly StatisticRow FirstValue, HpDrain, Accuracy, ApproachRate;
private readonly StatisticRow starDifficulty; private readonly StatisticRow starDifficulty;
@ -161,8 +161,8 @@ namespace osu.Game.Screens.Select.Details
starDifficultyCancellationSource = new CancellationTokenSource(); starDifficultyCancellationSource = new CancellationTokenSource();
normalStarDifficulty = difficultyManager.GetBindableDifficulty(Beatmap, ruleset.Value, null, starDifficultyCancellationSource.Token); normalStarDifficulty = difficultyCache.GetBindableDifficulty(Beatmap, ruleset.Value, null, starDifficultyCancellationSource.Token);
moddedStarDifficulty = difficultyManager.GetBindableDifficulty(Beatmap, ruleset.Value, mods.Value, starDifficultyCancellationSource.Token); moddedStarDifficulty = difficultyCache.GetBindableDifficulty(Beatmap, ruleset.Value, mods.Value, starDifficultyCancellationSource.Token);
normalStarDifficulty.BindValueChanged(_ => updateDisplay()); normalStarDifficulty.BindValueChanged(_ => updateDisplay());
moddedStarDifficulty.BindValueChanged(_ => updateDisplay(), true); moddedStarDifficulty.BindValueChanged(_ => updateDisplay(), true);