mirror of
https://github.com/osukey/osukey.git
synced 2025-05-29 17:37:23 +09:00
Add test beatmap difficulty cache with calc. blocking support
This commit is contained in:
parent
e0728a6e19
commit
db361efecf
@ -4,12 +4,15 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Utils;
|
using osu.Framework.Utils;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
using osu.Game.Screens.Menu;
|
using osu.Game.Screens.Menu;
|
||||||
using osu.Game.Screens.Play;
|
using osu.Game.Screens.Play;
|
||||||
@ -24,6 +27,9 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private BeatmapManager manager { get; set; }
|
private BeatmapManager manager { get; set; }
|
||||||
|
|
||||||
|
[Cached(typeof(BeatmapDifficultyCache))]
|
||||||
|
private readonly TestBeatmapDifficultyCache testDifficultyCache = new TestBeatmapDifficultyCache();
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestLocal([Values("Beatmap", "Some long title and stuff")]
|
public void TestLocal([Values("Beatmap", "Some long title and stuff")]
|
||||||
string title,
|
string title,
|
||||||
@ -44,6 +50,27 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestDelayedStarRating()
|
||||||
|
{
|
||||||
|
AddStep("block calculation", () => testDifficultyCache.BlockCalculation = true);
|
||||||
|
|
||||||
|
showMetadataForBeatmap(() => CreateWorkingBeatmap(new Beatmap
|
||||||
|
{
|
||||||
|
BeatmapInfo =
|
||||||
|
{
|
||||||
|
Metadata = new BeatmapMetadata
|
||||||
|
{
|
||||||
|
Title = "Heavy beatmap",
|
||||||
|
},
|
||||||
|
Version = "10k objects",
|
||||||
|
StarDifficulty = 99.99f,
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
AddStep("allow calculation", () => testDifficultyCache.BlockCalculation = false);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestRandomFromDatabase()
|
public void TestRandomFromDatabase()
|
||||||
{
|
{
|
||||||
@ -68,8 +95,11 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
|
|
||||||
OsuLogo logo = new OsuLogo { Scale = new Vector2(0.15f) };
|
OsuLogo logo = new OsuLogo { Scale = new Vector2(0.15f) };
|
||||||
|
|
||||||
|
Remove(testDifficultyCache);
|
||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
|
testDifficultyCache,
|
||||||
display = new BeatmapMetadataDisplay(getBeatmap(), new Bindable<IReadOnlyList<Mod>>(randomMods), logo)
|
display = new BeatmapMetadataDisplay(getBeatmap(), new Bindable<IReadOnlyList<Mod>>(randomMods), logo)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
@ -85,5 +115,37 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
|
|
||||||
AddStep("finish loading", () => display.Loading = false);
|
AddStep("finish loading", () => display.Loading = false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class TestBeatmapDifficultyCache : BeatmapDifficultyCache
|
||||||
|
{
|
||||||
|
private TaskCompletionSource<bool> calculationBlocker;
|
||||||
|
|
||||||
|
private bool blockCalculation;
|
||||||
|
|
||||||
|
public bool BlockCalculation
|
||||||
|
{
|
||||||
|
get => blockCalculation;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value == blockCalculation)
|
||||||
|
return;
|
||||||
|
|
||||||
|
blockCalculation = value;
|
||||||
|
|
||||||
|
if (value)
|
||||||
|
calculationBlocker = new TaskCompletionSource<bool>();
|
||||||
|
else
|
||||||
|
calculationBlocker?.SetResult(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<StarDifficulty> GetDifficultyAsync(BeatmapInfo beatmapInfo, RulesetInfo rulesetInfo = null, IEnumerable<Mod> mods = null, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
if (blockCalculation)
|
||||||
|
await calculationBlocker.Task;
|
||||||
|
|
||||||
|
return await base.GetDifficultyAsync(beatmapInfo, rulesetInfo, mods, cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user