Fix update-thread pauses

This commit is contained in:
smoogipoo
2021-08-31 21:36:31 +09:00
parent cfcf3d7507
commit fee94236de
4 changed files with 99 additions and 51 deletions

View File

@ -4,6 +4,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Game.Beatmaps;
@ -66,6 +68,9 @@ namespace osu.Game.Screens.Select.Leaderboards
[Resolved]
private ScoreManager scoreManager { get; set; }
[Resolved]
private BeatmapDifficultyCache difficultyCache { get; set; }
[Resolved]
private IBindable<RulesetInfo> ruleset { get; set; }
@ -120,8 +125,13 @@ namespace osu.Game.Screens.Select.Leaderboards
protected override bool IsOnlineScope => Scope != BeatmapLeaderboardScope.Local;
private CancellationTokenSource loadCancellationSource;
protected override APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback)
{
loadCancellationSource?.Cancel();
loadCancellationSource = new CancellationTokenSource();
if (Beatmap == null)
{
PlaceholderState = PlaceholderState.NoneSelected;
@ -146,11 +156,8 @@ namespace osu.Game.Screens.Select.Leaderboards
scores = scores.Where(s => s.Mods.Any(m => selectedMods.Contains(m.Acronym)));
}
Scores = scores.OrderByDescending(s => scoreManager.GetTotalScore(s))
.ThenBy(s => s.OnlineScoreID)
.ToArray();
PlaceholderState = Scores.Any() ? PlaceholderState.Successful : PlaceholderState.NoScores;
scoreManager.GetOrderedScoresAsync(scores.ToArray(), loadCancellationSource.Token)
.ContinueWith(ordered => scoresCallback?.Invoke(ordered.Result), TaskContinuationOptions.OnlyOnRanToCompletion);
return null;
}
@ -185,12 +192,15 @@ namespace osu.Game.Screens.Select.Leaderboards
req.Success += r =>
{
scoresCallback?.Invoke(
r.Scores.Select(s => s.CreateScoreInfo(rulesets))
.OrderByDescending(s => scoreManager.GetTotalScore(s))
.ThenBy(s => s.OnlineScoreID));
scoreManager.GetOrderedScoresAsync(r.Scores.Select(s => s.CreateScoreInfo(rulesets)).ToArray(), loadCancellationSource.Token)
.ContinueWith(ordered => Schedule(() =>
{
if (loadCancellationSource.IsCancellationRequested)
return;
TopScore = r.UserScore?.CreateScoreInfo(rulesets);
scoresCallback?.Invoke(ordered.Result);
TopScore = r.UserScore?.CreateScoreInfo(rulesets);
}), TaskContinuationOptions.OnlyOnRanToCompletion);
};
return req;