1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-28 06:12:54 +08:00

Re-implement store transferral in BeatmapManager

This commit is contained in:
smoogipoo 2020-08-05 22:09:47 +09:00
parent 0edd509397
commit 86ae61c6b7
2 changed files with 20 additions and 16 deletions

View File

@ -218,7 +218,7 @@ namespace osu.Game.Beatmaps
removeWorkingCache(info); removeWorkingCache(info);
} }
private readonly WeakList<WorkingBeatmap> workingCache = new WeakList<WorkingBeatmap>(); private readonly WeakList<BeatmapManagerWorkingBeatmap> workingCache = new WeakList<BeatmapManagerWorkingBeatmap>();
/// <summary> /// <summary>
/// Retrieve a <see cref="WorkingBeatmap"/> instance for the provided <see cref="BeatmapInfo"/> /// Retrieve a <see cref="WorkingBeatmap"/> instance for the provided <see cref="BeatmapInfo"/>
@ -246,16 +246,19 @@ namespace osu.Game.Beatmaps
lock (workingCache) lock (workingCache)
{ {
var working = workingCache.FirstOrDefault(w => w.BeatmapInfo?.ID == beatmapInfo.ID); var working = workingCache.FirstOrDefault(w => w.BeatmapInfo?.ID == beatmapInfo.ID);
if (working != null)
return working;
if (working == null) beatmapInfo.Metadata ??= beatmapInfo.BeatmapSet.Metadata;
{
beatmapInfo.Metadata ??= beatmapInfo.BeatmapSet.Metadata;
workingCache.Add(working = new BeatmapManagerWorkingBeatmap(Files.Store, ITrackStore trackStore = workingCache.FirstOrDefault(b => b.BeatmapInfo.AudioEquals(beatmapInfo))?.TrackStore;
new LargeTextureStore(host?.CreateTextureLoaderStore(Files.Store)), beatmapInfo, audioManager)); TextureStore textureStore = workingCache.FirstOrDefault(b => b.BeatmapInfo.BackgroundEquals(beatmapInfo))?.TextureStore;
}
textureStore ??= new LargeTextureStore(host?.CreateTextureLoaderStore(Files.Store));
trackStore ??= audioManager.GetTrackStore(Files.Store);
workingCache.Add(working = new BeatmapManagerWorkingBeatmap(Files.Store, textureStore, trackStore, beatmapInfo, audioManager));
// previous?.TransferTo(working);
return working; return working;
} }
} }

View File

@ -19,13 +19,18 @@ namespace osu.Game.Beatmaps
{ {
protected class BeatmapManagerWorkingBeatmap : WorkingBeatmap protected class BeatmapManagerWorkingBeatmap : WorkingBeatmap
{ {
public readonly TextureStore TextureStore;
public readonly ITrackStore TrackStore;
private readonly IResourceStore<byte[]> store; private readonly IResourceStore<byte[]> store;
public BeatmapManagerWorkingBeatmap(IResourceStore<byte[]> store, TextureStore textureStore, BeatmapInfo beatmapInfo, AudioManager audioManager) public BeatmapManagerWorkingBeatmap(IResourceStore<byte[]> store, TextureStore textureStore, ITrackStore trackStore, BeatmapInfo beatmapInfo, AudioManager audioManager)
: base(beatmapInfo, audioManager) : base(beatmapInfo, audioManager)
{ {
this.store = store; this.store = store;
this.textureStore = textureStore;
TextureStore = textureStore;
TrackStore = trackStore;
} }
protected override IBeatmap GetBeatmap() protected override IBeatmap GetBeatmap()
@ -44,10 +49,6 @@ namespace osu.Game.Beatmaps
private string getPathForFile(string filename) => BeatmapSetInfo.Files.SingleOrDefault(f => string.Equals(f.Filename, filename, StringComparison.OrdinalIgnoreCase))?.FileInfo.StoragePath; private string getPathForFile(string filename) => BeatmapSetInfo.Files.SingleOrDefault(f => string.Equals(f.Filename, filename, StringComparison.OrdinalIgnoreCase))?.FileInfo.StoragePath;
private TextureStore textureStore;
private ITrackStore trackStore;
protected override bool BackgroundStillValid(Texture b) => false; // bypass lazy logic. we want to return a new background each time for refcounting purposes. protected override bool BackgroundStillValid(Texture b) => false; // bypass lazy logic. we want to return a new background each time for refcounting purposes.
protected override Texture GetBackground() protected override Texture GetBackground()
@ -57,7 +58,7 @@ namespace osu.Game.Beatmaps
try try
{ {
return textureStore.Get(getPathForFile(Metadata.BackgroundFile)); return TextureStore.Get(getPathForFile(Metadata.BackgroundFile));
} }
catch (Exception e) catch (Exception e)
{ {
@ -70,7 +71,7 @@ namespace osu.Game.Beatmaps
{ {
try try
{ {
return (trackStore ??= AudioManager.GetTrackStore(store)).Get(getPathForFile(Metadata.AudioFile)); return TrackStore.Get(getPathForFile(Metadata.AudioFile));
} }
catch (Exception e) catch (Exception e)
{ {