mirror of
https://github.com/ppy/osu
synced 2024-12-13 18:37:04 +00:00
Add a single-file loading sequence for main components
This stops aync loading from getting overloaded with tasks, which was happening previously.
This commit is contained in:
parent
ae0029082a
commit
9b7d569a65
@ -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>(T d, Action<T> 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;
|
||||
|
Loading…
Reference in New Issue
Block a user