mirror of
https://github.com/ppy/osu.git
synced 2025-03-15 22:37:21 +08:00
Merge pull request #19032 from peppy/fix-background-loading-too-much
Fix background loading excessively on startup
This commit is contained in:
commit
113fdf5491
@ -38,15 +38,21 @@ namespace osu.Game.Graphics.Backgrounds
|
||||
private void load(OsuConfigManager config, SessionStatics sessionStatics)
|
||||
{
|
||||
seasonalBackgroundMode = config.GetBindable<SeasonalBackgroundMode>(OsuSetting.SeasonalBackgroundMode);
|
||||
seasonalBackgroundMode.BindValueChanged(_ => SeasonalBackgroundChanged?.Invoke());
|
||||
seasonalBackgroundMode.BindValueChanged(_ => triggerSeasonalBackgroundChanged());
|
||||
|
||||
seasonalBackgrounds = sessionStatics.GetBindable<APISeasonalBackgrounds>(Static.SeasonalBackgrounds);
|
||||
seasonalBackgrounds.BindValueChanged(_ => SeasonalBackgroundChanged?.Invoke());
|
||||
seasonalBackgrounds.BindValueChanged(_ => triggerSeasonalBackgroundChanged());
|
||||
|
||||
apiState.BindTo(api.State);
|
||||
apiState.BindValueChanged(fetchSeasonalBackgrounds, true);
|
||||
}
|
||||
|
||||
private void triggerSeasonalBackgroundChanged()
|
||||
{
|
||||
if (shouldShowSeasonal)
|
||||
SeasonalBackgroundChanged?.Invoke();
|
||||
}
|
||||
|
||||
private void fetchSeasonalBackgrounds(ValueChangedEvent<APIState> stateChanged)
|
||||
{
|
||||
if (seasonalBackgrounds.Value != null || stateChanged.NewValue != APIState.Online)
|
||||
@ -64,15 +70,10 @@ namespace osu.Game.Graphics.Backgrounds
|
||||
|
||||
public SeasonalBackground LoadNextBackground()
|
||||
{
|
||||
if (seasonalBackgroundMode.Value == SeasonalBackgroundMode.Never
|
||||
|| (seasonalBackgroundMode.Value == SeasonalBackgroundMode.Sometimes && !isInSeason))
|
||||
{
|
||||
if (!shouldShowSeasonal)
|
||||
return null;
|
||||
}
|
||||
|
||||
var backgrounds = seasonalBackgrounds.Value?.Backgrounds;
|
||||
if (backgrounds == null || !backgrounds.Any())
|
||||
return null;
|
||||
var backgrounds = seasonalBackgrounds.Value.Backgrounds;
|
||||
|
||||
current = (current + 1) % backgrounds.Count;
|
||||
string url = backgrounds[current].Url;
|
||||
@ -80,6 +81,20 @@ namespace osu.Game.Graphics.Backgrounds
|
||||
return new SeasonalBackground(url);
|
||||
}
|
||||
|
||||
private bool shouldShowSeasonal
|
||||
{
|
||||
get
|
||||
{
|
||||
if (seasonalBackgroundMode.Value == SeasonalBackgroundMode.Never)
|
||||
return false;
|
||||
|
||||
if (seasonalBackgroundMode.Value == SeasonalBackgroundMode.Sometimes && !isInSeason)
|
||||
return false;
|
||||
|
||||
return seasonalBackgrounds.Value?.Backgrounds?.Any() == true;
|
||||
}
|
||||
}
|
||||
|
||||
private bool isInSeason => seasonalBackgrounds.Value != null && DateTimeOffset.Now < seasonalBackgrounds.Value.EndDate;
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ using System.Threading;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Beatmaps;
|
||||
@ -26,7 +27,7 @@ namespace osu.Game.Screens.Backgrounds
|
||||
private const int background_count = 7;
|
||||
private IBindable<APIUser> user;
|
||||
private Bindable<Skin> skin;
|
||||
private Bindable<BackgroundSource> mode;
|
||||
private Bindable<BackgroundSource> source;
|
||||
private Bindable<IntroSequence> introSequence;
|
||||
private readonly SeasonalBackgroundLoader seasonalBackgroundLoader = new SeasonalBackgroundLoader();
|
||||
|
||||
@ -45,24 +46,29 @@ namespace osu.Game.Screens.Backgrounds
|
||||
{
|
||||
user = api.LocalUser.GetBoundCopy();
|
||||
skin = skinManager.CurrentSkin.GetBoundCopy();
|
||||
mode = config.GetBindable<BackgroundSource>(OsuSetting.MenuBackgroundSource);
|
||||
source = config.GetBindable<BackgroundSource>(OsuSetting.MenuBackgroundSource);
|
||||
introSequence = config.GetBindable<IntroSequence>(OsuSetting.IntroSequence);
|
||||
|
||||
AddInternal(seasonalBackgroundLoader);
|
||||
|
||||
user.ValueChanged += _ => Scheduler.AddOnce(loadNextIfRequired);
|
||||
skin.ValueChanged += _ => Scheduler.AddOnce(loadNextIfRequired);
|
||||
mode.ValueChanged += _ => Scheduler.AddOnce(loadNextIfRequired);
|
||||
beatmap.ValueChanged += _ => Scheduler.AddOnce(loadNextIfRequired);
|
||||
introSequence.ValueChanged += _ => Scheduler.AddOnce(loadNextIfRequired);
|
||||
seasonalBackgroundLoader.SeasonalBackgroundChanged += () => Scheduler.AddOnce(loadNextIfRequired);
|
||||
|
||||
// Load first background asynchronously as part of BDL load.
|
||||
currentDisplay = RNG.Next(0, background_count);
|
||||
|
||||
Next();
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
user.ValueChanged += _ => Scheduler.AddOnce(next);
|
||||
skin.ValueChanged += _ => Scheduler.AddOnce(next);
|
||||
source.ValueChanged += _ => Scheduler.AddOnce(next);
|
||||
beatmap.ValueChanged += _ => Scheduler.AddOnce(next);
|
||||
introSequence.ValueChanged += _ => Scheduler.AddOnce(next);
|
||||
seasonalBackgroundLoader.SeasonalBackgroundChanged += () => Scheduler.AddOnce(next);
|
||||
|
||||
// helper function required for AddOnce usage.
|
||||
void loadNextIfRequired() => Next();
|
||||
void next() => Next();
|
||||
}
|
||||
|
||||
private ScheduledDelegate nextTask;
|
||||
@ -80,6 +86,8 @@ namespace osu.Game.Screens.Backgrounds
|
||||
if (nextBackground == background)
|
||||
return false;
|
||||
|
||||
Logger.Log("🌅 Background change queued");
|
||||
|
||||
cancellationTokenSource?.Cancel();
|
||||
cancellationTokenSource = new CancellationTokenSource();
|
||||
|
||||
@ -108,12 +116,12 @@ namespace osu.Game.Screens.Backgrounds
|
||||
|
||||
if (newBackground == null && user.Value?.IsSupporter == true)
|
||||
{
|
||||
switch (mode.Value)
|
||||
switch (source.Value)
|
||||
{
|
||||
case BackgroundSource.Beatmap:
|
||||
case BackgroundSource.BeatmapWithStoryboard:
|
||||
{
|
||||
if (mode.Value == BackgroundSource.BeatmapWithStoryboard && AllowStoryboardBackground)
|
||||
if (source.Value == BackgroundSource.BeatmapWithStoryboard && AllowStoryboardBackground)
|
||||
newBackground = new BeatmapBackgroundWithStoryboard(beatmap.Value, getBackgroundTextureName());
|
||||
newBackground ??= new BeatmapBackground(beatmap.Value, getBackgroundTextureName());
|
||||
|
||||
|
@ -88,6 +88,11 @@ namespace osu.Game.Screens.Menu
|
||||
/// </summary>
|
||||
protected bool UsingThemedIntro { get; private set; }
|
||||
|
||||
protected override BackgroundScreen CreateBackground() => new BackgroundScreenDefault(false)
|
||||
{
|
||||
Colour = Color4.Black
|
||||
};
|
||||
|
||||
protected IntroScreen([CanBeNull] Func<MainMenu> createNextScreen = null)
|
||||
{
|
||||
this.createNextScreen = createNextScreen;
|
||||
@ -201,6 +206,8 @@ namespace osu.Game.Screens.Menu
|
||||
{
|
||||
this.FadeIn(300);
|
||||
|
||||
ApplyToBackground(b => b.FadeColour(Color4.Black, 100));
|
||||
|
||||
double fadeOutTime = exit_delay;
|
||||
|
||||
var track = musicController.CurrentTrack;
|
||||
@ -243,13 +250,22 @@ namespace osu.Game.Screens.Menu
|
||||
base.OnResuming(e);
|
||||
}
|
||||
|
||||
private bool backgroundFaded;
|
||||
|
||||
protected void FadeInBackground(float duration = 0)
|
||||
{
|
||||
ApplyToBackground(b => b.FadeColour(Color4.White, duration));
|
||||
backgroundFaded = true;
|
||||
}
|
||||
|
||||
public override void OnSuspending(ScreenTransitionEvent e)
|
||||
{
|
||||
base.OnSuspending(e);
|
||||
initialBeatmap = null;
|
||||
}
|
||||
|
||||
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBlack();
|
||||
if (!backgroundFaded)
|
||||
FadeInBackground(200);
|
||||
}
|
||||
|
||||
protected virtual void StartTrack()
|
||||
{
|
||||
|
@ -8,19 +8,18 @@ using JetBrains.Annotations;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Sample;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Framework.Timing;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Screens.Backgrounds;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
|
||||
@ -32,16 +31,9 @@ namespace osu.Game.Screens.Menu
|
||||
|
||||
protected override string BeatmapFile => "triangles.osz";
|
||||
|
||||
protected override BackgroundScreen CreateBackground() => background = new BackgroundScreenDefault(false)
|
||||
{
|
||||
Alpha = 0,
|
||||
};
|
||||
|
||||
[Resolved]
|
||||
private AudioManager audio { get; set; }
|
||||
|
||||
private BackgroundScreenDefault background;
|
||||
|
||||
private Sample welcome;
|
||||
|
||||
private DecoupleableInterpolatingFramedClock decoupledClock;
|
||||
@ -75,7 +67,7 @@ namespace osu.Game.Screens.Menu
|
||||
if (UsingThemedIntro)
|
||||
decoupledClock.ChangeSource(Track);
|
||||
|
||||
LoadComponentAsync(intro = new TrianglesIntroSequence(logo, background)
|
||||
LoadComponentAsync(intro = new TrianglesIntroSequence(logo, () => FadeInBackground())
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Clock = decoupledClock,
|
||||
@ -95,19 +87,10 @@ namespace osu.Game.Screens.Menu
|
||||
{
|
||||
base.OnSuspending(e);
|
||||
|
||||
// ensure the background is shown, even if the TriangleIntroSequence failed to do so.
|
||||
background.ApplyToBackground(b => b.Show());
|
||||
|
||||
// important as there is a clock attached to a track which will likely be disposed before returning to this screen.
|
||||
intro.Expire();
|
||||
}
|
||||
|
||||
public override void OnResuming(ScreenTransitionEvent e)
|
||||
{
|
||||
base.OnResuming(e);
|
||||
background.FadeOut(100);
|
||||
}
|
||||
|
||||
protected override void StartTrack()
|
||||
{
|
||||
decoupledClock.Start();
|
||||
@ -116,7 +99,7 @@ namespace osu.Game.Screens.Menu
|
||||
private class TrianglesIntroSequence : CompositeDrawable
|
||||
{
|
||||
private readonly OsuLogo logo;
|
||||
private readonly BackgroundScreenDefault background;
|
||||
private readonly Action showBackgroundAction;
|
||||
private OsuSpriteText welcomeText;
|
||||
|
||||
private RulesetFlow rulesets;
|
||||
@ -128,10 +111,10 @@ namespace osu.Game.Screens.Menu
|
||||
|
||||
public Action LoadMenu;
|
||||
|
||||
public TrianglesIntroSequence(OsuLogo logo, BackgroundScreenDefault background)
|
||||
public TrianglesIntroSequence(OsuLogo logo, Action showBackgroundAction)
|
||||
{
|
||||
this.logo = logo;
|
||||
this.background = background;
|
||||
this.showBackgroundAction = showBackgroundAction;
|
||||
}
|
||||
|
||||
[Resolved]
|
||||
@ -205,7 +188,6 @@ namespace osu.Game.Screens.Menu
|
||||
|
||||
rulesets.Hide();
|
||||
lazerLogo.Hide();
|
||||
background.ApplyToBackground(b => b.Hide());
|
||||
|
||||
using (BeginAbsoluteSequence(0))
|
||||
{
|
||||
@ -267,7 +249,7 @@ namespace osu.Game.Screens.Menu
|
||||
|
||||
logo.FadeIn();
|
||||
|
||||
background.ApplyToBackground(b => b.Show());
|
||||
showBackgroundAction();
|
||||
|
||||
game.Add(new GameWideFlash());
|
||||
|
||||
|
@ -5,11 +5,9 @@
|
||||
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using osuTK;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Sample;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
@ -17,8 +15,8 @@ using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osu.Game.Audio;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Screens.Backgrounds;
|
||||
using osu.Game.Skinning;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Screens.Menu
|
||||
@ -35,13 +33,6 @@ namespace osu.Game.Screens.Menu
|
||||
private ISample pianoReverb;
|
||||
protected override string SeeyaSampleName => "Intro/Welcome/seeya";
|
||||
|
||||
protected override BackgroundScreen CreateBackground() => background = new BackgroundScreenDefault(false)
|
||||
{
|
||||
Alpha = 0,
|
||||
};
|
||||
|
||||
private BackgroundScreenDefault background;
|
||||
|
||||
public IntroWelcome([CanBeNull] Func<MainMenu> createNextScreen = null)
|
||||
: base(createNextScreen)
|
||||
{
|
||||
@ -100,7 +91,7 @@ namespace osu.Game.Screens.Menu
|
||||
logo.ScaleTo(1);
|
||||
logo.FadeIn(fade_in_time);
|
||||
|
||||
background.FadeIn(fade_in_time);
|
||||
FadeInBackground(fade_in_time);
|
||||
|
||||
LoadMenu();
|
||||
}, delay_step_two);
|
||||
@ -108,12 +99,6 @@ namespace osu.Game.Screens.Menu
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnResuming(ScreenTransitionEvent e)
|
||||
{
|
||||
base.OnResuming(e);
|
||||
background.FadeOut(100);
|
||||
}
|
||||
|
||||
private class WelcomeIntroSequence : Container
|
||||
{
|
||||
private Drawable welcomeText;
|
||||
|
@ -65,9 +65,7 @@ namespace osu.Game.Screens.Menu
|
||||
[Resolved(canBeNull: true)]
|
||||
private IDialogOverlay dialogOverlay { get; set; }
|
||||
|
||||
private BackgroundScreenDefault background;
|
||||
|
||||
protected override BackgroundScreen CreateBackground() => background;
|
||||
protected override BackgroundScreen CreateBackground() => new BackgroundScreenDefault();
|
||||
|
||||
protected override bool PlayExitSound => false;
|
||||
|
||||
@ -148,7 +146,6 @@ namespace osu.Game.Screens.Menu
|
||||
Buttons.OnSettings = () => settings?.ToggleVisibility();
|
||||
Buttons.OnBeatmapListing = () => beatmapListing?.ToggleVisibility();
|
||||
|
||||
LoadComponentAsync(background = new BackgroundScreenDefault());
|
||||
preloadSongSelect();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user