mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 06:42:54 +08:00
Remove track store reference counting, use single instance stores
This commit is contained in:
parent
6aafb3d271
commit
338c01fa43
@ -63,8 +63,9 @@ namespace osu.Game.Beatmaps
|
||||
private readonly RulesetStore rulesets;
|
||||
private readonly BeatmapStore beatmaps;
|
||||
private readonly AudioManager audioManager;
|
||||
private readonly GameHost host;
|
||||
private readonly BeatmapOnlineLookupQueue onlineLookupQueue;
|
||||
private readonly TextureStore textureStore;
|
||||
private readonly ITrackStore trackStore;
|
||||
|
||||
public BeatmapManager(Storage storage, IDatabaseContextFactory contextFactory, RulesetStore rulesets, IAPIProvider api, AudioManager audioManager, GameHost host = null,
|
||||
WorkingBeatmap defaultBeatmap = null)
|
||||
@ -72,7 +73,6 @@ namespace osu.Game.Beatmaps
|
||||
{
|
||||
this.rulesets = rulesets;
|
||||
this.audioManager = audioManager;
|
||||
this.host = host;
|
||||
|
||||
DefaultBeatmap = defaultBeatmap;
|
||||
|
||||
@ -83,6 +83,9 @@ namespace osu.Game.Beatmaps
|
||||
beatmaps.ItemUpdated += removeWorkingCache;
|
||||
|
||||
onlineLookupQueue = new BeatmapOnlineLookupQueue(api, storage);
|
||||
|
||||
textureStore = new LargeTextureStore(host?.CreateTextureLoaderStore(Files.Store));
|
||||
trackStore = audioManager.GetTrackStore(Files.Store);
|
||||
}
|
||||
|
||||
protected override ArchiveDownloadRequest<BeatmapSetInfo> CreateDownloadRequest(BeatmapSetInfo set, bool minimiseDownloadSize) =>
|
||||
@ -219,7 +222,6 @@ namespace osu.Game.Beatmaps
|
||||
}
|
||||
|
||||
private readonly WeakList<BeatmapManagerWorkingBeatmap> workingCache = new WeakList<BeatmapManagerWorkingBeatmap>();
|
||||
private readonly Dictionary<ITrackStore, int> referencedTrackStores = new Dictionary<ITrackStore, int>();
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve a <see cref="WorkingBeatmap"/> instance for the provided <see cref="BeatmapInfo"/>
|
||||
@ -252,31 +254,12 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
beatmapInfo.Metadata ??= beatmapInfo.BeatmapSet.Metadata;
|
||||
|
||||
ITrackStore trackStore = workingCache.FirstOrDefault(b => b.BeatmapInfo.AudioEquals(beatmapInfo))?.TrackStore;
|
||||
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, dereferenceTrackStore));
|
||||
referencedTrackStores[trackStore] = referencedTrackStores.GetOrDefault(trackStore) + 1;
|
||||
workingCache.Add(working = new BeatmapManagerWorkingBeatmap(Files.Store, textureStore, trackStore, beatmapInfo, audioManager));
|
||||
|
||||
return working;
|
||||
}
|
||||
}
|
||||
|
||||
private void dereferenceTrackStore(ITrackStore trackStore)
|
||||
{
|
||||
lock (workingCache)
|
||||
{
|
||||
if (--referencedTrackStores[trackStore] == 0)
|
||||
{
|
||||
referencedTrackStores.Remove(trackStore);
|
||||
trackStore.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Perform a lookup query on available <see cref="BeatmapSetInfo"/>s.
|
||||
/// </summary>
|
||||
|
@ -19,21 +19,16 @@ namespace osu.Game.Beatmaps
|
||||
{
|
||||
protected class BeatmapManagerWorkingBeatmap : WorkingBeatmap
|
||||
{
|
||||
public readonly TextureStore TextureStore;
|
||||
public readonly ITrackStore TrackStore;
|
||||
|
||||
private readonly IResourceStore<byte[]> store;
|
||||
private readonly Action<ITrackStore> dereferenceAction;
|
||||
private readonly TextureStore textureStore;
|
||||
private readonly ITrackStore trackStore;
|
||||
|
||||
public BeatmapManagerWorkingBeatmap(IResourceStore<byte[]> store, TextureStore textureStore, ITrackStore trackStore, BeatmapInfo beatmapInfo, AudioManager audioManager,
|
||||
Action<ITrackStore> dereferenceAction)
|
||||
public BeatmapManagerWorkingBeatmap(IResourceStore<byte[]> store, TextureStore textureStore, ITrackStore trackStore, BeatmapInfo beatmapInfo, AudioManager audioManager)
|
||||
: base(beatmapInfo, audioManager)
|
||||
{
|
||||
this.store = store;
|
||||
this.dereferenceAction = dereferenceAction;
|
||||
|
||||
TextureStore = textureStore;
|
||||
TrackStore = trackStore;
|
||||
this.textureStore = textureStore;
|
||||
this.trackStore = trackStore;
|
||||
}
|
||||
|
||||
protected override IBeatmap GetBeatmap()
|
||||
@ -61,7 +56,7 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
try
|
||||
{
|
||||
return TextureStore.Get(getPathForFile(Metadata.BackgroundFile));
|
||||
return textureStore.Get(getPathForFile(Metadata.BackgroundFile));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -74,7 +69,7 @@ namespace osu.Game.Beatmaps
|
||||
{
|
||||
try
|
||||
{
|
||||
return TrackStore.Get(getPathForFile(Metadata.AudioFile));
|
||||
return trackStore.Get(getPathForFile(Metadata.AudioFile));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -140,11 +135,6 @@ namespace osu.Game.Beatmaps
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
~BeatmapManagerWorkingBeatmap()
|
||||
{
|
||||
dereferenceAction?.Invoke(TrackStore);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user