mirror of
https://github.com/ppy/osu
synced 2024-12-15 11:25:29 +00:00
Merge pull request #9998 from smoogipoo/fix-difficulty-manager
Reduce redundant difficulty re-calculations
This commit is contained in:
commit
4031f2d311
32
osu.Game.Tests/Beatmaps/BeatmapDifficultyManagerTest.cs
Normal file
32
osu.Game.Tests/Beatmaps/BeatmapDifficultyManagerTest.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// 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 NUnit.Framework;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Rulesets.Mods;
|
||||||
|
using osu.Game.Rulesets.Osu.Mods;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Beatmaps
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class BeatmapDifficultyManagerTest
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void TestKeyEqualsWithDifferentModInstances()
|
||||||
|
{
|
||||||
|
var key1 = new BeatmapDifficultyManager.DifficultyCacheLookup(1234, 0, new Mod[] { new OsuModHardRock(), new OsuModHidden() });
|
||||||
|
var key2 = new BeatmapDifficultyManager.DifficultyCacheLookup(1234, 0, new Mod[] { new OsuModHardRock(), new OsuModHidden() });
|
||||||
|
|
||||||
|
Assert.That(key1, Is.EqualTo(key2));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestKeyEqualsWithDifferentModOrder()
|
||||||
|
{
|
||||||
|
var key1 = new BeatmapDifficultyManager.DifficultyCacheLookup(1234, 0, new Mod[] { new OsuModHardRock(), new OsuModHidden() });
|
||||||
|
var key2 = new BeatmapDifficultyManager.DifficultyCacheLookup(1234, 0, new Mod[] { new OsuModHidden(), new OsuModHardRock() });
|
||||||
|
|
||||||
|
Assert.That(key1, Is.EqualTo(key2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -89,8 +89,14 @@ namespace osu.Game.Beatmaps
|
|||||||
if (tryGetExisting(beatmapInfo, rulesetInfo, mods, out var existing, out var key))
|
if (tryGetExisting(beatmapInfo, rulesetInfo, mods, out var existing, out var key))
|
||||||
return existing;
|
return existing;
|
||||||
|
|
||||||
return await Task.Factory.StartNew(() => computeDifficulty(key, beatmapInfo, rulesetInfo), cancellationToken,
|
return await Task.Factory.StartNew(() =>
|
||||||
TaskCreationOptions.HideScheduler | TaskCreationOptions.RunContinuationsAsynchronously, updateScheduler);
|
{
|
||||||
|
// Computation may have finished in a previous task.
|
||||||
|
if (tryGetExisting(beatmapInfo, rulesetInfo, mods, out existing, out _))
|
||||||
|
return existing;
|
||||||
|
|
||||||
|
return computeDifficulty(key, beatmapInfo, rulesetInfo);
|
||||||
|
}, cancellationToken, TaskCreationOptions.HideScheduler | TaskCreationOptions.RunContinuationsAsynchronously, updateScheduler);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -245,7 +251,7 @@ namespace osu.Game.Beatmaps
|
|||||||
updateScheduler?.Dispose();
|
updateScheduler?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly struct DifficultyCacheLookup : IEquatable<DifficultyCacheLookup>
|
public readonly struct DifficultyCacheLookup : IEquatable<DifficultyCacheLookup>
|
||||||
{
|
{
|
||||||
public readonly int BeatmapId;
|
public readonly int BeatmapId;
|
||||||
public readonly int RulesetId;
|
public readonly int RulesetId;
|
||||||
@ -261,7 +267,7 @@ namespace osu.Game.Beatmaps
|
|||||||
public bool Equals(DifficultyCacheLookup other)
|
public bool Equals(DifficultyCacheLookup other)
|
||||||
=> BeatmapId == other.BeatmapId
|
=> BeatmapId == other.BeatmapId
|
||||||
&& RulesetId == other.RulesetId
|
&& RulesetId == other.RulesetId
|
||||||
&& Mods.SequenceEqual(other.Mods);
|
&& Mods.Select(m => m.Acronym).SequenceEqual(other.Mods.Select(m => m.Acronym));
|
||||||
|
|
||||||
public override int GetHashCode()
|
public override int GetHashCode()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user