mirror of
https://github.com/osukey/osukey.git
synced 2025-08-07 00:23:59 +09:00
Merge pull request #9002 from Craftplacer/cacheas-game-components
Use CacheAs for caching game-wide components
This commit is contained in:
@ -91,7 +91,7 @@ namespace osu.Game
|
|||||||
|
|
||||||
protected BackButton BackButton;
|
protected BackButton BackButton;
|
||||||
|
|
||||||
protected SettingsPanel Settings;
|
protected SettingsOverlay Settings;
|
||||||
|
|
||||||
private VolumeOverlay volume;
|
private VolumeOverlay volume;
|
||||||
private OsuLogo osuLogo;
|
private OsuLogo osuLogo;
|
||||||
@ -767,13 +767,20 @@ namespace osu.Game
|
|||||||
|
|
||||||
private Task asyncLoadStream;
|
private Task asyncLoadStream;
|
||||||
|
|
||||||
private T loadComponentSingleFile<T>(T d, Action<T> add, bool cache = false)
|
/// <summary>
|
||||||
|
/// Queues loading the provided component in sequential fashion.
|
||||||
|
/// This operation is limited to a single thread to avoid saturating all cores.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="component">The component to load.</param>
|
||||||
|
/// <param name="loadCompleteAction">An action to invoke on load completion (generally to add the component to the hierarchy).</param>
|
||||||
|
/// <param name="cache">Whether to cache the component as type <typeparamref name="T"/> into the game dependencies before any scheduling.</param>
|
||||||
|
private T loadComponentSingleFile<T>(T component, Action<T> loadCompleteAction, bool cache = false)
|
||||||
where T : Drawable
|
where T : Drawable
|
||||||
{
|
{
|
||||||
if (cache)
|
if (cache)
|
||||||
dependencies.Cache(d);
|
dependencies.CacheAs(component);
|
||||||
|
|
||||||
if (d is OverlayContainer overlay)
|
if (component is OverlayContainer overlay)
|
||||||
overlays.Add(overlay);
|
overlays.Add(overlay);
|
||||||
|
|
||||||
// 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).
|
||||||
@ -791,12 +798,12 @@ namespace osu.Game
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Logger.Log($"Loading {d}...", level: LogLevel.Debug);
|
Logger.Log($"Loading {component}...", level: LogLevel.Debug);
|
||||||
|
|
||||||
// Since this is running in a separate thread, it is possible for OsuGame to be disposed after LoadComponentAsync has been called
|
// Since this is running in a separate thread, it is possible for OsuGame to be disposed after LoadComponentAsync has been called
|
||||||
// throwing an exception. To avoid this, the call is scheduled on the update thread, which does not run if IsDisposed = true
|
// throwing an exception. To avoid this, the call is scheduled on the update thread, which does not run if IsDisposed = true
|
||||||
Task task = null;
|
Task task = null;
|
||||||
var del = new ScheduledDelegate(() => task = LoadComponentAsync(d, add));
|
var del = new ScheduledDelegate(() => task = LoadComponentAsync(component, loadCompleteAction));
|
||||||
Scheduler.Add(del);
|
Scheduler.Add(del);
|
||||||
|
|
||||||
// The delegate won't complete if OsuGame has been disposed in the meantime
|
// The delegate won't complete if OsuGame has been disposed in the meantime
|
||||||
@ -811,7 +818,7 @@ namespace osu.Game
|
|||||||
|
|
||||||
await task;
|
await task;
|
||||||
|
|
||||||
Logger.Log($"Loaded {d}!", level: LogLevel.Debug);
|
Logger.Log($"Loaded {component}!", level: LogLevel.Debug);
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
{
|
{
|
||||||
@ -819,7 +826,7 @@ namespace osu.Game
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return d;
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnScroll(ScrollEvent e)
|
protected override bool OnScroll(ScrollEvent e)
|
||||||
|
Reference in New Issue
Block a user