1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-06 10:22:54 +08:00

Centralise caching of components at OsuGame level

This commit is contained in:
Dean Herbert 2019-05-13 17:10:25 +09:00
parent 6e0fbaa96d
commit 4b508915f6
2 changed files with 26 additions and 51 deletions

View File

@ -58,16 +58,8 @@ namespace osu.Game
private ChannelManager channelManager; private ChannelManager channelManager;
private MusicController musicController;
private NotificationOverlay notifications; private NotificationOverlay notifications;
private LoginOverlay loginOverlay;
private DialogOverlay dialogOverlay;
private AccountCreationOverlay accountCreation;
private DirectOverlay direct; private DirectOverlay direct;
private SocialOverlay social; private SocialOverlay social;
@ -91,7 +83,6 @@ namespace osu.Game
private OsuScreenStack screenStack; private OsuScreenStack screenStack;
private VolumeOverlay volume; private VolumeOverlay volume;
private OnScreenDisplay onscreenDisplay;
private OsuLogo osuLogo; private OsuLogo osuLogo;
private MainMenu menuScreen; private MainMenu menuScreen;
@ -124,10 +115,6 @@ namespace osu.Game
RavenLogger = new RavenLogger(this); RavenLogger = new RavenLogger(this);
} }
public void ToggleSettings() => settings.ToggleVisibility();
public void ToggleDirect() => direct.ToggleVisibility();
private void updateBlockingOverlayFade() => private void updateBlockingOverlayFade() =>
screenContainer.FadeColour(visibleBlockingOverlays.Any() ? OsuColour.Gray(0.5f) : Color4.White, 500, Easing.OutQuint); screenContainer.FadeColour(visibleBlockingOverlays.Any() ? OsuColour.Gray(0.5f) : Color4.White, 500, Easing.OutQuint);
@ -381,6 +368,8 @@ namespace osu.Game
Container logoContainer; Container logoContainer;
dependencies.CacheAs(idleTracker = new GameIdleTracker(6000));
AddRange(new Drawable[] AddRange(new Drawable[]
{ {
new VolumeControlReceptor new VolumeControlReceptor
@ -402,7 +391,7 @@ namespace osu.Game
rightFloatingOverlayContent = new Container { RelativeSizeAxes = Axes.Both }, rightFloatingOverlayContent = new Container { RelativeSizeAxes = Axes.Both },
leftFloatingOverlayContent = new Container { RelativeSizeAxes = Axes.Both }, leftFloatingOverlayContent = new Container { RelativeSizeAxes = Axes.Both },
topMostOverlayContent = new Container { RelativeSizeAxes = Axes.Both }, topMostOverlayContent = new Container { RelativeSizeAxes = Axes.Both },
idleTracker = new GameIdleTracker(6000) idleTracker
}); });
screenStack.ScreenPushed += screenPushed; screenStack.ScreenPushed += screenPushed;
@ -429,59 +418,44 @@ namespace osu.Game
}, topMostOverlayContent.Add); }, topMostOverlayContent.Add);
loadComponentSingleFile(volume = new VolumeOverlay(), leftFloatingOverlayContent.Add); loadComponentSingleFile(volume = new VolumeOverlay(), leftFloatingOverlayContent.Add);
loadComponentSingleFile(onscreenDisplay = new OnScreenDisplay(), Add); loadComponentSingleFile(new OnScreenDisplay(), Add, true);
loadComponentSingleFile(notifications = new NotificationOverlay loadComponentSingleFile(notifications = new NotificationOverlay
{ {
GetToolbarHeight = () => ToolbarOffset, GetToolbarHeight = () => ToolbarOffset,
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
Origin = Anchor.TopRight, Origin = Anchor.TopRight,
}, rightFloatingOverlayContent.Add); }, rightFloatingOverlayContent.Add, true);
loadComponentSingleFile(screenshotManager, Add); loadComponentSingleFile(screenshotManager, Add);
//overlay elements //overlay elements
loadComponentSingleFile(direct = new DirectOverlay(), overlayContent.Add); loadComponentSingleFile(direct = new DirectOverlay(), overlayContent.Add, true);
loadComponentSingleFile(social = new SocialOverlay(), overlayContent.Add); loadComponentSingleFile(social = new SocialOverlay(), overlayContent.Add, true);
loadComponentSingleFile(channelManager = new ChannelManager(), AddInternal); loadComponentSingleFile(channelManager = new ChannelManager(), AddInternal, true);
loadComponentSingleFile(chatOverlay = new ChatOverlay(), overlayContent.Add); loadComponentSingleFile(chatOverlay = new ChatOverlay(), overlayContent.Add, true);
loadComponentSingleFile(settings = new MainSettings { GetToolbarHeight = () => ToolbarOffset }, leftFloatingOverlayContent.Add); loadComponentSingleFile(settings = new MainSettings { GetToolbarHeight = () => ToolbarOffset }, leftFloatingOverlayContent.Add, true);
loadComponentSingleFile(userProfile = new UserProfileOverlay(), overlayContent.Add); loadComponentSingleFile(userProfile = new UserProfileOverlay(), overlayContent.Add, true);
loadComponentSingleFile(beatmapSetOverlay = new BeatmapSetOverlay(), overlayContent.Add); loadComponentSingleFile(beatmapSetOverlay = new BeatmapSetOverlay(), overlayContent.Add, true);
loadComponentSingleFile(loginOverlay = new LoginOverlay loadComponentSingleFile(new LoginOverlay
{ {
GetToolbarHeight = () => ToolbarOffset, GetToolbarHeight = () => ToolbarOffset,
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
Origin = Anchor.TopRight, Origin = Anchor.TopRight,
}, rightFloatingOverlayContent.Add); }, rightFloatingOverlayContent.Add, true);
loadComponentSingleFile(musicController = new MusicController loadComponentSingleFile(new MusicController
{ {
GetToolbarHeight = () => ToolbarOffset, GetToolbarHeight = () => ToolbarOffset,
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
Origin = Anchor.TopRight, Origin = Anchor.TopRight,
}, rightFloatingOverlayContent.Add); }, rightFloatingOverlayContent.Add, true);
loadComponentSingleFile(accountCreation = new AccountCreationOverlay(), topMostOverlayContent.Add); loadComponentSingleFile(new AccountCreationOverlay(), topMostOverlayContent.Add, true);
loadComponentSingleFile(dialogOverlay = new DialogOverlay(), topMostOverlayContent.Add); loadComponentSingleFile(new DialogOverlay(), topMostOverlayContent.Add, true);
loadComponentSingleFile(externalLinkOpener = new ExternalLinkOpener(), topMostOverlayContent.Add); 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; chatOverlay.StateChanged += state => channelManager.HighPollRate.Value = state == Visibility.Visible;
Add(externalLinkOpener = new ExternalLinkOpener()); Add(externalLinkOpener = new ExternalLinkOpener());
@ -610,9 +584,12 @@ namespace osu.Game
private Task asyncLoadStream; private Task asyncLoadStream;
private void loadComponentSingleFile<T>(T d, Action<T> add) private void loadComponentSingleFile<T>(T d, Action<T> add, bool cache = false)
where T : Drawable 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). // 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, // 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. // we could avoid the need for scheduling altogether.

View File

@ -20,6 +20,7 @@ using osu.Game.Screens.Multi;
using osu.Game.Screens.Select; using osu.Game.Screens.Select;
using osu.Game.Screens.Tournament; using osu.Game.Screens.Tournament;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Game.Overlays;
namespace osu.Game.Screens.Menu namespace osu.Game.Screens.Menu
{ {
@ -45,7 +46,7 @@ namespace osu.Game.Screens.Menu
protected override BackgroundScreen CreateBackground() => background; protected override BackgroundScreen CreateBackground() => background;
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader(true)]
private void load(OsuGame game = null) private void load(DirectOverlay direct, SettingsOverlay settings)
{ {
if (host.CanExit) if (host.CanExit)
AddInternal(new ExitConfirmOverlay { Action = this.Exit }); AddInternal(new ExitConfirmOverlay { Action = this.Exit });
@ -86,11 +87,8 @@ namespace osu.Game.Screens.Menu
} }
}; };
if (game != null) buttons.OnSettings = () => settings?.ToggleVisibility();
{ buttons.OnDirect = () => direct?.ToggleVisibility();
buttons.OnSettings = game.ToggleSettings;
buttons.OnDirect = game.ToggleDirect;
}
LoadComponentAsync(background = new BackgroundScreenDefault()); LoadComponentAsync(background = new BackgroundScreenDefault());
preloadSongSelect(); preloadSongSelect();