From ae0029082ab9fbb36454ba086a0fe4ed403fc275 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 23 Oct 2017 01:19:28 +0900 Subject: [PATCH 1/9] Allow version manager to load completely async --- osu.Desktop/OsuGameDesktop.cs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/osu.Desktop/OsuGameDesktop.cs b/osu.Desktop/OsuGameDesktop.cs index 1e4bf3119d..5a9d2adfd4 100644 --- a/osu.Desktop/OsuGameDesktop.cs +++ b/osu.Desktop/OsuGameDesktop.cs @@ -12,7 +12,6 @@ using osu.Desktop.Overlays; using osu.Framework.Graphics.Containers; using osu.Framework.Platform; using osu.Game; -using osu.Game.Screens.Menu; using OpenTK.Input; namespace osu.Desktop @@ -82,16 +81,11 @@ namespace osu.Desktop { base.LoadComplete(); - LoadComponentAsync(versionManager = new VersionManager { Depth = int.MinValue }); - - ScreenChanged += s => + LoadComponentAsync(versionManager = new VersionManager { Depth = int.MinValue }, v => { - if (s is Intro && s.ChildScreen == null) - { - Add(versionManager); - versionManager.State = Visibility.Visible; - } - }; + Add(v); + v.State = Visibility.Visible; + }); } public override void SetHost(GameHost host) From 9b7d569a6593d564a5a23edb9362ed9eab56c9cb Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 23 Oct 2017 01:20:12 +0900 Subject: [PATCH 2/9] Add a single-file loading sequence for main components This stops aync loading from getting overloaded with tasks, which was happening previously. --- osu.Game/OsuGame.cs | 61 +++++++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index d1baca68db..41153c4d34 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -16,6 +16,7 @@ using osu.Game.Screens; using osu.Game.Screens.Menu; using OpenTK; using System.Linq; +using System.Threading; using System.Threading.Tasks; using osu.Framework.Input.Bindings; using osu.Framework.Platform; @@ -172,25 +173,35 @@ namespace osu.Game new OnScreenDisplay(), }); - LoadComponentAsync(screenStack = new Loader(), d => + loadComponentSingleFile(screenStack = new Loader(), d => { screenStack.ModePushed += screenAdded; screenStack.Exited += screenRemoved; mainContent.Add(screenStack); }); + loadComponentSingleFile(Toolbar = new Toolbar + { + Depth = -5, + OnHome = delegate + { + hideAllOverlays(); + intro?.ChildScreen?.MakeCurrent(); + }, + }, overlayContent.Add); + //overlay elements - LoadComponentAsync(direct = new DirectOverlay { Depth = -1 }, mainContent.Add); - LoadComponentAsync(social = new SocialOverlay { Depth = -1 }, mainContent.Add); - LoadComponentAsync(chat = new ChatOverlay { Depth = -1 }, mainContent.Add); - LoadComponentAsync(settings = new MainSettings + loadComponentSingleFile(direct = new DirectOverlay { Depth = -1 }, mainContent.Add); + loadComponentSingleFile(social = new SocialOverlay { Depth = -1 }, mainContent.Add); + loadComponentSingleFile(chat = new ChatOverlay { Depth = -1 }, mainContent.Add); + loadComponentSingleFile(settings = new MainSettings { GetToolbarHeight = () => ToolbarOffset, Depth = -1 }, overlayContent.Add); - LoadComponentAsync(userProfile = new UserProfileOverlay { Depth = -2 }, mainContent.Add); - LoadComponentAsync(beatmapSetOverlay = new BeatmapSetOverlay { Depth = -3 }, mainContent.Add); - LoadComponentAsync(musicController = new MusicController + loadComponentSingleFile(userProfile = new UserProfileOverlay { Depth = -2 }, mainContent.Add); + loadComponentSingleFile(beatmapSetOverlay = new BeatmapSetOverlay { Depth = -3 }, mainContent.Add); + loadComponentSingleFile(musicController = new MusicController { Depth = -4, Position = new Vector2(0, Toolbar.HEIGHT), @@ -198,16 +209,16 @@ namespace osu.Game Origin = Anchor.TopRight, }, overlayContent.Add); - LoadComponentAsync(notificationOverlay = new NotificationOverlay + loadComponentSingleFile(notificationOverlay = new NotificationOverlay { Depth = -4, Anchor = Anchor.TopRight, Origin = Anchor.TopRight, }, overlayContent.Add); - LoadComponentAsync(dialogOverlay = new DialogOverlay + loadComponentSingleFile(dialogOverlay = new DialogOverlay { - Depth = -5, + Depth = -6, }, overlayContent.Add); Logger.NewEntry += entry => @@ -246,16 +257,6 @@ namespace osu.Game }; } - LoadComponentAsync(Toolbar = new Toolbar - { - Depth = -4, - OnHome = delegate - { - hideAllOverlays(); - intro?.ChildScreen?.MakeCurrent(); - }, - }, overlayContent.Add); - settings.StateChanged += delegate { switch (settings.State) @@ -272,6 +273,24 @@ namespace osu.Game Cursor.State = Visibility.Hidden; } + private Task asyncLoadStream; + + private void loadComponentSingleFile(T d, Action add) + where T : Drawable + { + Schedule(() => + { + if (asyncLoadStream != null) + asyncLoadStream = asyncLoadStream.ContinueWith(t => + { + Thread.Sleep(100); + LoadComponentAsync(d, add).Wait(); + }); + else + asyncLoadStream = LoadComponentAsync(d, add); + }); + } + public bool OnPressed(GlobalAction action) { if (intro == null) return false; From 65b23f38f161b328befa1562046221e0e2378f3f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 23 Oct 2017 12:48:33 +0900 Subject: [PATCH 3/9] fixup! Allow version manager to load completely async --- osu.Desktop/OsuGameDesktop.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/osu.Desktop/OsuGameDesktop.cs b/osu.Desktop/OsuGameDesktop.cs index 5a9d2adfd4..5f05fae213 100644 --- a/osu.Desktop/OsuGameDesktop.cs +++ b/osu.Desktop/OsuGameDesktop.cs @@ -18,8 +18,6 @@ namespace osu.Desktop { internal class OsuGameDesktop : OsuGame { - private VersionManager versionManager; - public OsuGameDesktop(string[] args = null) : base(args) { @@ -81,7 +79,7 @@ namespace osu.Desktop { base.LoadComplete(); - LoadComponentAsync(versionManager = new VersionManager { Depth = int.MinValue }, v => + LoadComponentAsync(new VersionManager { Depth = int.MinValue }, v => { Add(v); v.State = Visibility.Visible; From 777cdcbdc15ebe2526ec479d258c12f92d6ac391 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 23 Oct 2017 13:08:58 +0900 Subject: [PATCH 4/9] Load even more components async --- osu.Game/OsuGame.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 41153c4d34..cb502963f7 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -158,19 +158,15 @@ namespace osu.Game BeatmapManager.PostNotification = n => notificationOverlay?.Post(n); BeatmapManager.GetStableStorage = GetStorageForStableInstall; - AddRange(new Drawable[] { + AddRange(new Drawable[] + { new VolumeControlReceptor { RelativeSizeAxes = Axes.Both, ActionRequested = action => volume.Adjust(action) }, - mainContent = new Container - { - RelativeSizeAxes = Axes.Both, - }, - volume = new VolumeControl(), - overlayContent = new Container { RelativeSizeAxes = Axes.Both }, - new OnScreenDisplay(), + mainContent = new Container { RelativeSizeAxes = Axes.Both }, + overlayContent = new Container { RelativeSizeAxes = Axes.Both, Depth = float.MinValue }, }); loadComponentSingleFile(screenStack = new Loader(), d => @@ -190,6 +186,9 @@ namespace osu.Game }, }, overlayContent.Add); + loadComponentSingleFile(volume = new VolumeControl(), AddInternal); + loadComponentSingleFile(new OnScreenDisplay(), AddInternal); + //overlay elements loadComponentSingleFile(direct = new DirectOverlay { Depth = -1 }, mainContent.Add); loadComponentSingleFile(social = new SocialOverlay { Depth = -1 }, mainContent.Add); From 0e04260b3c0083e831de9b429eaa4e9d4c964dff Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 23 Oct 2017 13:43:47 +0900 Subject: [PATCH 5/9] Move ToolbarUserArea initialisation to BDL --- osu.Game/Overlays/Toolbar/ToolbarUserArea.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/osu.Game/Overlays/Toolbar/ToolbarUserArea.cs b/osu.Game/Overlays/Toolbar/ToolbarUserArea.cs index c1fd234628..95a25fcb86 100644 --- a/osu.Game/Overlays/Toolbar/ToolbarUserArea.cs +++ b/osu.Game/Overlays/Toolbar/ToolbarUserArea.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Primitives; @@ -11,11 +12,12 @@ namespace osu.Game.Overlays.Toolbar internal class ToolbarUserArea : Container { public LoginOverlay LoginOverlay; - private readonly ToolbarUserButton button; + private ToolbarUserButton button; public override RectangleF BoundingBox => button.BoundingBox; - public ToolbarUserArea() + [BackgroundDependencyLoader] + private void load() { RelativeSizeAxes = Axes.Y; AutoSizeAxes = Axes.X; @@ -36,4 +38,4 @@ namespace osu.Game.Overlays.Toolbar }; } } -} \ No newline at end of file +} From cc01878f2ba54e3c90e3a33172f03362160813c0 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 24 Oct 2017 10:12:32 +0900 Subject: [PATCH 6/9] Update framework --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index 26f3091dca..ecc5e3189e 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 26f3091dcaf47e3b355b7f7ad83b292621d7d6b5 +Subproject commit ecc5e3189e8229d36095882b9a7a0efc95402be9 From e98bfec6444a0841558987d50938936562c6504c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 24 Oct 2017 11:40:38 +0900 Subject: [PATCH 7/9] Remove Thread.Sleep and tidy up new method --- osu.Game/OsuGame.cs | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index cb502963f7..b8c197abc9 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -277,17 +277,7 @@ namespace osu.Game private void loadComponentSingleFile(T d, Action add) where T : Drawable { - Schedule(() => - { - if (asyncLoadStream != null) - asyncLoadStream = asyncLoadStream.ContinueWith(t => - { - Thread.Sleep(100); - LoadComponentAsync(d, add).Wait(); - }); - else - asyncLoadStream = LoadComponentAsync(d, add); - }); + Schedule(() => { asyncLoadStream = asyncLoadStream?.ContinueWith(t => LoadComponentAsync(d, add).Wait()) ?? LoadComponentAsync(d, add); }); } public bool OnPressed(GlobalAction action) From 9ec870a8219f4832b6552f5dd4acdc74994892ec Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 24 Oct 2017 11:50:18 +0900 Subject: [PATCH 8/9] Add comment pertaining to why Schedule() is required --- osu.Game/OsuGame.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index b8c197abc9..a278366e3e 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -277,6 +277,9 @@ namespace osu.Game private void loadComponentSingleFile(T d, Action add) where T : Drawable { + // schedule is here to ensure that all component loads are done after LoadComplete is run (and thus all dependencies are cached). + // with some better organisation of LoadComplete to do construction and dependency caching in one step, followed by calls to loadComponentSingleFile, + // we could avoid the need for scheduling altogether. Schedule(() => { asyncLoadStream = asyncLoadStream?.ContinueWith(t => LoadComponentAsync(d, add).Wait()) ?? LoadComponentAsync(d, add); }); } From 635f26badca57f47887837512744c0185ca8bb68 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 24 Oct 2017 11:59:57 +0900 Subject: [PATCH 9/9] Remove unnecessary using --- osu.Game/OsuGame.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index a278366e3e..1e7b0dc0bc 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -16,7 +16,6 @@ using osu.Game.Screens; using osu.Game.Screens.Menu; using OpenTK; using System.Linq; -using System.Threading; using System.Threading.Tasks; using osu.Framework.Input.Bindings; using osu.Framework.Platform;