mirror of
https://github.com/ppy/osu
synced 2024-12-17 04:15:37 +00:00
Avoid reloading background unnecessariyl when not yet loaded
This commit is contained in:
parent
b83073c2e9
commit
789904ccd1
@ -7,6 +7,7 @@ using System.Threading;
|
|||||||
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.Logging;
|
||||||
using osu.Framework.Threading;
|
using osu.Framework.Threading;
|
||||||
using osu.Framework.Utils;
|
using osu.Framework.Utils;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
@ -26,7 +27,7 @@ namespace osu.Game.Screens.Backgrounds
|
|||||||
private const int background_count = 7;
|
private const int background_count = 7;
|
||||||
private IBindable<APIUser> user;
|
private IBindable<APIUser> user;
|
||||||
private Bindable<Skin> skin;
|
private Bindable<Skin> skin;
|
||||||
private Bindable<BackgroundSource> mode;
|
private Bindable<BackgroundSource> source;
|
||||||
private Bindable<IntroSequence> introSequence;
|
private Bindable<IntroSequence> introSequence;
|
||||||
private readonly SeasonalBackgroundLoader seasonalBackgroundLoader = new SeasonalBackgroundLoader();
|
private readonly SeasonalBackgroundLoader seasonalBackgroundLoader = new SeasonalBackgroundLoader();
|
||||||
|
|
||||||
@ -45,14 +46,14 @@ namespace osu.Game.Screens.Backgrounds
|
|||||||
{
|
{
|
||||||
user = api.LocalUser.GetBoundCopy();
|
user = api.LocalUser.GetBoundCopy();
|
||||||
skin = skinManager.CurrentSkin.GetBoundCopy();
|
skin = skinManager.CurrentSkin.GetBoundCopy();
|
||||||
mode = config.GetBindable<BackgroundSource>(OsuSetting.MenuBackgroundSource);
|
source = config.GetBindable<BackgroundSource>(OsuSetting.MenuBackgroundSource);
|
||||||
introSequence = config.GetBindable<IntroSequence>(OsuSetting.IntroSequence);
|
introSequence = config.GetBindable<IntroSequence>(OsuSetting.IntroSequence);
|
||||||
|
|
||||||
AddInternal(seasonalBackgroundLoader);
|
AddInternal(seasonalBackgroundLoader);
|
||||||
|
|
||||||
user.ValueChanged += _ => Scheduler.AddOnce(loadNextIfRequired);
|
user.ValueChanged += _ => Scheduler.AddOnce(loadNextIfRequired);
|
||||||
skin.ValueChanged += _ => Scheduler.AddOnce(loadNextIfRequired);
|
skin.ValueChanged += _ => Scheduler.AddOnce(loadNextIfRequired);
|
||||||
mode.ValueChanged += _ => Scheduler.AddOnce(loadNextIfRequired);
|
source.ValueChanged += _ => Scheduler.AddOnce(loadNextIfRequired);
|
||||||
beatmap.ValueChanged += _ => Scheduler.AddOnce(loadNextIfRequired);
|
beatmap.ValueChanged += _ => Scheduler.AddOnce(loadNextIfRequired);
|
||||||
introSequence.ValueChanged += _ => Scheduler.AddOnce(loadNextIfRequired);
|
introSequence.ValueChanged += _ => Scheduler.AddOnce(loadNextIfRequired);
|
||||||
seasonalBackgroundLoader.SeasonalBackgroundChanged += () => Scheduler.AddOnce(loadNextIfRequired);
|
seasonalBackgroundLoader.SeasonalBackgroundChanged += () => Scheduler.AddOnce(loadNextIfRequired);
|
||||||
@ -62,7 +63,13 @@ namespace osu.Game.Screens.Backgrounds
|
|||||||
Next();
|
Next();
|
||||||
|
|
||||||
// helper function required for AddOnce usage.
|
// helper function required for AddOnce usage.
|
||||||
void loadNextIfRequired() => Next();
|
void loadNextIfRequired()
|
||||||
|
{
|
||||||
|
if (!IsLoaded)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Next();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScheduledDelegate nextTask;
|
private ScheduledDelegate nextTask;
|
||||||
@ -80,6 +87,8 @@ namespace osu.Game.Screens.Backgrounds
|
|||||||
if (nextBackground == background)
|
if (nextBackground == background)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
Logger.Log("🌅 Background change queued");
|
||||||
|
|
||||||
cancellationTokenSource?.Cancel();
|
cancellationTokenSource?.Cancel();
|
||||||
cancellationTokenSource = new CancellationTokenSource();
|
cancellationTokenSource = new CancellationTokenSource();
|
||||||
|
|
||||||
@ -108,12 +117,12 @@ namespace osu.Game.Screens.Backgrounds
|
|||||||
|
|
||||||
if (newBackground == null && user.Value?.IsSupporter == true)
|
if (newBackground == null && user.Value?.IsSupporter == true)
|
||||||
{
|
{
|
||||||
switch (mode.Value)
|
switch (source.Value)
|
||||||
{
|
{
|
||||||
case BackgroundSource.Beatmap:
|
case BackgroundSource.Beatmap:
|
||||||
case BackgroundSource.BeatmapWithStoryboard:
|
case BackgroundSource.BeatmapWithStoryboard:
|
||||||
{
|
{
|
||||||
if (mode.Value == BackgroundSource.BeatmapWithStoryboard && AllowStoryboardBackground)
|
if (source.Value == BackgroundSource.BeatmapWithStoryboard && AllowStoryboardBackground)
|
||||||
newBackground = new BeatmapBackgroundWithStoryboard(beatmap.Value, getBackgroundTextureName());
|
newBackground = new BeatmapBackgroundWithStoryboard(beatmap.Value, getBackgroundTextureName());
|
||||||
newBackground ??= new BeatmapBackground(beatmap.Value, getBackgroundTextureName());
|
newBackground ??= new BeatmapBackground(beatmap.Value, getBackgroundTextureName());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user