From 4b508915f624d63bb6f262d93117fa3af85ab34e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 13 May 2019 17:10:25 +0900 Subject: [PATCH] Centralise caching of components at OsuGame level --- osu.Game/OsuGame.cs | 67 ++++++++++--------------------- osu.Game/Screens/Menu/MainMenu.cs | 10 ++--- 2 files changed, 26 insertions(+), 51 deletions(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 7b2a8184d1..978e78663f 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -58,16 +58,8 @@ namespace osu.Game private ChannelManager channelManager; - private MusicController musicController; - private NotificationOverlay notifications; - private LoginOverlay loginOverlay; - - private DialogOverlay dialogOverlay; - - private AccountCreationOverlay accountCreation; - private DirectOverlay direct; private SocialOverlay social; @@ -91,7 +83,6 @@ namespace osu.Game private OsuScreenStack screenStack; private VolumeOverlay volume; - private OnScreenDisplay onscreenDisplay; private OsuLogo osuLogo; private MainMenu menuScreen; @@ -124,10 +115,6 @@ namespace osu.Game RavenLogger = new RavenLogger(this); } - public void ToggleSettings() => settings.ToggleVisibility(); - - public void ToggleDirect() => direct.ToggleVisibility(); - private void updateBlockingOverlayFade() => screenContainer.FadeColour(visibleBlockingOverlays.Any() ? OsuColour.Gray(0.5f) : Color4.White, 500, Easing.OutQuint); @@ -381,6 +368,8 @@ namespace osu.Game Container logoContainer; + dependencies.CacheAs(idleTracker = new GameIdleTracker(6000)); + AddRange(new Drawable[] { new VolumeControlReceptor @@ -402,7 +391,7 @@ namespace osu.Game rightFloatingOverlayContent = new Container { RelativeSizeAxes = Axes.Both }, leftFloatingOverlayContent = new Container { RelativeSizeAxes = Axes.Both }, topMostOverlayContent = new Container { RelativeSizeAxes = Axes.Both }, - idleTracker = new GameIdleTracker(6000) + idleTracker }); screenStack.ScreenPushed += screenPushed; @@ -429,59 +418,44 @@ namespace osu.Game }, topMostOverlayContent.Add); loadComponentSingleFile(volume = new VolumeOverlay(), leftFloatingOverlayContent.Add); - loadComponentSingleFile(onscreenDisplay = new OnScreenDisplay(), Add); + loadComponentSingleFile(new OnScreenDisplay(), Add, true); loadComponentSingleFile(notifications = new NotificationOverlay { GetToolbarHeight = () => ToolbarOffset, Anchor = Anchor.TopRight, Origin = Anchor.TopRight, - }, rightFloatingOverlayContent.Add); + }, rightFloatingOverlayContent.Add, true); loadComponentSingleFile(screenshotManager, Add); //overlay elements - loadComponentSingleFile(direct = new DirectOverlay(), overlayContent.Add); - loadComponentSingleFile(social = new SocialOverlay(), overlayContent.Add); - loadComponentSingleFile(channelManager = new ChannelManager(), AddInternal); - loadComponentSingleFile(chatOverlay = new ChatOverlay(), overlayContent.Add); - loadComponentSingleFile(settings = new MainSettings { GetToolbarHeight = () => ToolbarOffset }, leftFloatingOverlayContent.Add); - loadComponentSingleFile(userProfile = new UserProfileOverlay(), overlayContent.Add); - loadComponentSingleFile(beatmapSetOverlay = new BeatmapSetOverlay(), overlayContent.Add); + loadComponentSingleFile(direct = new DirectOverlay(), overlayContent.Add, true); + loadComponentSingleFile(social = new SocialOverlay(), overlayContent.Add, true); + loadComponentSingleFile(channelManager = new ChannelManager(), AddInternal, true); + loadComponentSingleFile(chatOverlay = new ChatOverlay(), overlayContent.Add, true); + loadComponentSingleFile(settings = new MainSettings { GetToolbarHeight = () => ToolbarOffset }, leftFloatingOverlayContent.Add, true); + loadComponentSingleFile(userProfile = new UserProfileOverlay(), overlayContent.Add, true); + loadComponentSingleFile(beatmapSetOverlay = new BeatmapSetOverlay(), overlayContent.Add, true); - loadComponentSingleFile(loginOverlay = new LoginOverlay + loadComponentSingleFile(new LoginOverlay { GetToolbarHeight = () => ToolbarOffset, Anchor = Anchor.TopRight, Origin = Anchor.TopRight, - }, rightFloatingOverlayContent.Add); + }, rightFloatingOverlayContent.Add, true); - loadComponentSingleFile(musicController = new MusicController + loadComponentSingleFile(new MusicController { GetToolbarHeight = () => ToolbarOffset, Anchor = Anchor.TopRight, Origin = Anchor.TopRight, - }, rightFloatingOverlayContent.Add); + }, rightFloatingOverlayContent.Add, true); - loadComponentSingleFile(accountCreation = new AccountCreationOverlay(), topMostOverlayContent.Add); - loadComponentSingleFile(dialogOverlay = new DialogOverlay(), topMostOverlayContent.Add); + loadComponentSingleFile(new AccountCreationOverlay(), topMostOverlayContent.Add, true); + loadComponentSingleFile(new DialogOverlay(), topMostOverlayContent.Add, true); loadComponentSingleFile(externalLinkOpener = new ExternalLinkOpener(), topMostOverlayContent.Add); - dependencies.CacheAs(idleTracker); - dependencies.Cache(settings); - dependencies.Cache(onscreenDisplay); - dependencies.Cache(social); - dependencies.Cache(direct); - dependencies.Cache(chatOverlay); - dependencies.Cache(channelManager); - dependencies.Cache(userProfile); - dependencies.Cache(musicController); - dependencies.Cache(beatmapSetOverlay); - dependencies.Cache(notifications); - dependencies.Cache(loginOverlay); - dependencies.Cache(dialogOverlay); - dependencies.Cache(accountCreation); - chatOverlay.StateChanged += state => channelManager.HighPollRate.Value = state == Visibility.Visible; Add(externalLinkOpener = new ExternalLinkOpener()); @@ -610,9 +584,12 @@ namespace osu.Game private Task asyncLoadStream; - private void loadComponentSingleFile(T d, Action add) + private void loadComponentSingleFile(T d, Action add, bool cache = false) where T : Drawable { + if (cache) + dependencies.Cache(d); + // 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. diff --git a/osu.Game/Screens/Menu/MainMenu.cs b/osu.Game/Screens/Menu/MainMenu.cs index 21fc53be6e..788cad3bad 100644 --- a/osu.Game/Screens/Menu/MainMenu.cs +++ b/osu.Game/Screens/Menu/MainMenu.cs @@ -20,6 +20,7 @@ using osu.Game.Screens.Multi; using osu.Game.Screens.Select; using osu.Game.Screens.Tournament; using osu.Framework.Platform; +using osu.Game.Overlays; namespace osu.Game.Screens.Menu { @@ -45,7 +46,7 @@ namespace osu.Game.Screens.Menu protected override BackgroundScreen CreateBackground() => background; [BackgroundDependencyLoader(true)] - private void load(OsuGame game = null) + private void load(DirectOverlay direct, SettingsOverlay settings) { if (host.CanExit) AddInternal(new ExitConfirmOverlay { Action = this.Exit }); @@ -86,11 +87,8 @@ namespace osu.Game.Screens.Menu } }; - if (game != null) - { - buttons.OnSettings = game.ToggleSettings; - buttons.OnDirect = game.ToggleDirect; - } + buttons.OnSettings = () => settings?.ToggleVisibility(); + buttons.OnDirect = () => direct?.ToggleVisibility(); LoadComponentAsync(background = new BackgroundScreenDefault()); preloadSongSelect();