1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 04:02:57 +08:00

Only load panels asynchronously outside of BDL

This commit is contained in:
Bartłomiej Dach 2022-05-06 17:33:32 +02:00
parent 9f96dd47d1
commit 9514a5cef7
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497

View File

@ -275,20 +275,39 @@ namespace osu.Game.Overlays.Mods
return;
localAvailableMods = newMods;
loadPanels();
if (!IsLoaded)
// if we're coming from BDL, perform the first load synchronously to make sure everything is in place as early as possible.
onPanelsLoaded(createPanels());
else
asyncLoadPanels();
}
private CancellationTokenSource? cancellationTokenSource;
private void loadPanels()
private void asyncLoadPanels()
{
cancellationTokenSource?.Cancel();
var panels = localAvailableMods.Select(mod => CreateModPanel(mod).With(panel => panel.Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0)));
var panels = createPanels();
Task? loadTask;
latestLoadTask = loadTask = LoadComponentsAsync(panels, loaded =>
latestLoadTask = loadTask = LoadComponentsAsync(panels, onPanelsLoaded, (cancellationTokenSource = new CancellationTokenSource()).Token);
loadTask.ContinueWith(_ =>
{
if (loadTask == latestLoadTask)
latestLoadTask = null;
});
}
private IEnumerable<ModPanel> createPanels()
{
var panels = localAvailableMods.Select(mod => CreateModPanel(mod).With(panel => panel.Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0)));
return panels;
}
private void onPanelsLoaded(IEnumerable<ModPanel> loaded)
{
panelFlow.ChildrenEnumerable = loaded;
@ -298,12 +317,6 @@ namespace osu.Game.Overlays.Mods
{
panel.Active.BindValueChanged(_ => panelStateChanged(panel));
}
}, (cancellationTokenSource = new CancellationTokenSource()).Token);
loadTask.ContinueWith(_ =>
{
if (loadTask == latestLoadTask)
latestLoadTask = null;
});
}
private void updateState()