Add debounce to WorkingBeatmap creation at song select.

Improves perceived performance when quickly moving through carousel.
This commit is contained in:
Dean Herbert 2017-04-28 20:44:16 +09:00
parent 003cf53441
commit 45729a8881
1 changed files with 16 additions and 3 deletions

View File

@ -15,6 +15,7 @@
using osu.Framework.Graphics.Primitives;
using osu.Framework.Input;
using osu.Framework.Screens;
using osu.Framework.Threading;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Database;
@ -297,6 +298,11 @@ protected override void OnBeatmapChanged(WorkingBeatmap beatmap)
carousel.SelectBeatmap(beatmap?.BeatmapInfo);
}
ScheduledDelegate selectionChangedDebounce;
// We need to keep track of the last selected beatmap ignoring debounce to play the correct selection sounds.
private BeatmapInfo selectionChangeNoBounce;
/// <summary>
/// selection has been changed as the result of interaction with the carousel.
/// </summary>
@ -306,16 +312,23 @@ private void selectionChanged(BeatmapInfo beatmap)
if (!beatmap.Equals(Beatmap?.BeatmapInfo))
{
if (beatmap.BeatmapSetInfoID == Beatmap?.BeatmapInfo.BeatmapSetInfoID)
if (beatmap.BeatmapSetInfoID == selectionChangeNoBounce?.BeatmapSetInfoID)
sampleChangeDifficulty.Play();
else
{
sampleChangeBeatmap.Play();
beatmapSetChange = true;
}
Beatmap = database.GetWorkingBeatmap(beatmap, Beatmap);
}
ensurePlayingSelected(beatmapSetChange);
selectionChangeNoBounce = beatmap;
selectionChangedDebounce?.Cancel();
selectionChangedDebounce = Scheduler.AddDelayed(delegate
{
Beatmap = database.GetWorkingBeatmap(beatmap, Beatmap);
ensurePlayingSelected(beatmapSetChange);
}, 100);
}
private void ensurePlayingSelected(bool preview = false)