osu/osu.Game/Screens/Loader.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

153 lines
5.5 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2018-04-13 09:19:50 +00:00
2022-06-17 07:37:17 +00:00
#nullable disable
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shaders;
2020-01-09 04:43:44 +00:00
using osu.Framework.Utils;
using osu.Game.Screens.Menu;
using osu.Framework.Screens;
2020-03-10 17:49:34 +00:00
using osu.Framework.Threading;
2019-08-09 11:05:28 +00:00
using osu.Game.Configuration;
2020-03-10 17:49:34 +00:00
using osu.Game.Graphics.UserInterface;
2019-08-09 11:05:28 +00:00
using IntroSequence = osu.Game.Configuration.IntroSequence;
2018-04-13 09:19:50 +00:00
namespace osu.Game.Screens
{
public partial class Loader : StartupScreen
{
public Loader()
{
ValidForResume = false;
}
2018-04-13 09:19:50 +00:00
2018-05-31 11:07:44 +00:00
private OsuScreen loadableScreen;
private ShaderPrecompiler precompiler;
2018-04-13 09:19:50 +00:00
2019-08-09 11:05:28 +00:00
private IntroSequence introSequence;
2020-03-10 17:49:34 +00:00
private LoadingSpinner spinner;
private ScheduledDelegate spinnerShow;
2019-08-09 11:05:28 +00:00
2023-12-28 08:21:29 +00:00
protected virtual OsuScreen CreateLoadableScreen() => getIntroSequence();
2019-07-09 09:06:49 +00:00
2019-08-09 11:05:28 +00:00
private IntroScreen getIntroSequence()
2019-09-28 19:34:09 +00:00
{
if (introSequence == IntroSequence.Random)
introSequence = (IntroSequence)RNG.Next(0, (int)IntroSequence.Random);
2019-08-09 11:05:28 +00:00
switch (introSequence)
{
case IntroSequence.Circles:
return new IntroCircles(createMainMenu);
2019-08-09 11:05:28 +00:00
case IntroSequence.Welcome:
return new IntroWelcome(createMainMenu);
2020-06-02 01:48:23 +00:00
2019-08-09 11:05:28 +00:00
default:
return new IntroTriangles(createMainMenu);
2019-08-09 11:05:28 +00:00
}
MainMenu createMainMenu() => new MainMenu();
2019-08-09 11:05:28 +00:00
}
2018-05-31 08:29:59 +00:00
2018-05-31 11:07:44 +00:00
protected virtual ShaderPrecompiler CreateShaderPrecompiler() => new ShaderPrecompiler();
public override void OnEntering(ScreenTransitionEvent e)
{
base.OnEntering(e);
2018-04-13 09:19:50 +00:00
2019-01-23 11:52:00 +00:00
LoadComponentAsync(precompiler = CreateShaderPrecompiler(), AddInternal);
2018-05-31 11:07:44 +00:00
LoadComponentAsync(loadableScreen = CreateLoadableScreen());
2020-03-10 17:49:34 +00:00
LoadComponentAsync(spinner = new LoadingSpinner(true, true)
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Margin = new MarginPadding(40),
}, _ =>
{
AddInternal(spinner);
spinnerShow = Scheduler.AddDelayed(spinner.Show, 200);
});
2018-05-31 11:07:44 +00:00
checkIfLoaded();
}
2018-04-13 09:19:50 +00:00
2018-05-31 11:07:44 +00:00
private void checkIfLoaded()
{
if (loadableScreen?.LoadState != LoadState.Ready || !precompiler.FinishedCompiling)
2018-05-31 11:07:44 +00:00
{
Schedule(checkIfLoaded);
return;
2018-05-31 11:07:44 +00:00
}
2018-04-13 09:19:50 +00:00
2020-03-10 17:49:34 +00:00
spinnerShow?.Cancel();
if (spinner.State.Value == Visibility.Visible)
{
spinner.Hide();
Scheduler.AddDelayed(() => this.Push(loadableScreen), LoadingSpinner.TRANSITION_DURATION);
}
else
this.Push(loadableScreen);
}
2018-04-13 09:19:50 +00:00
[BackgroundDependencyLoader]
2023-12-28 08:21:29 +00:00
private void load(OsuConfigManager config)
{
2019-08-09 11:05:28 +00:00
introSequence = config.Get<IntroSequence>(OsuSetting.IntroSequence);
}
2018-04-13 09:19:50 +00:00
/// <summary>
/// Compiles a set of shaders before continuing. Attempts to draw some frames between compilation by limiting to one compile per draw frame.
/// </summary>
public partial class ShaderPrecompiler : Drawable
{
2019-03-07 09:30:18 +00:00
private readonly List<IShader> loadTargets = new List<IShader>();
2018-04-13 09:19:50 +00:00
public bool FinishedCompiling { get; private set; }
2018-04-13 09:19:50 +00:00
[BackgroundDependencyLoader]
private void load(ShaderManager manager)
{
loadTargets.Add(manager.Load(VertexShaderDescriptor.TEXTURE_2, FragmentShaderDescriptor.TEXTURE));
2023-09-13 14:10:13 +00:00
loadTargets.Add(manager.Load(VertexShaderDescriptor.TEXTURE_2, FragmentShaderDescriptor.BLUR));
loadTargets.Add(manager.Load(VertexShaderDescriptor.TEXTURE_3, FragmentShaderDescriptor.TEXTURE));
2023-09-13 14:10:13 +00:00
loadTargets.Add(manager.Load(VertexShaderDescriptor.TEXTURE_2, @"TriangleBorder"));
loadTargets.Add(manager.Load(VertexShaderDescriptor.TEXTURE_2, @"FastCircle"));
loadTargets.Add(manager.Load(VertexShaderDescriptor.TEXTURE_2, @"CircularProgress"));
loadTargets.Add(manager.Load(VertexShaderDescriptor.TEXTURE_2, @"ArgonBarPath"));
loadTargets.Add(manager.Load(VertexShaderDescriptor.TEXTURE_2, @"ArgonBarPathBackground"));
loadTargets.Add(manager.Load(VertexShaderDescriptor.TEXTURE_2, @"SaturationSelectorBackground"));
loadTargets.Add(manager.Load(VertexShaderDescriptor.TEXTURE_2, @"HueSelectorBackground"));
loadTargets.Add(manager.Load(@"LogoAnimation", @"LogoAnimation"));
2024-09-27 07:11:24 +00:00
// Ruleset local shader usage (should probably move somewhere else).
loadTargets.Add(manager.Load(VertexShaderDescriptor.TEXTURE_2, @"SpinnerGlow"));
loadTargets.Add(manager.Load(@"CursorTrail", FragmentShaderDescriptor.TEXTURE));
}
2018-04-13 09:19:50 +00:00
2019-03-07 09:30:18 +00:00
protected virtual bool AllLoaded => loadTargets.All(s => s.IsLoaded);
2018-05-31 11:07:44 +00:00
protected override void Update()
{
base.Update();
2018-04-13 09:19:50 +00:00
// if our target is null we are done.
2018-05-31 11:07:44 +00:00
if (AllLoaded)
{
FinishedCompiling = true;
Expire();
}
}
}
}
}