Add statistic for count of alive WorkingBeatmaps

This commit is contained in:
Dean Herbert 2019-07-02 22:39:42 +09:00
parent f31d840c13
commit e7a7f2f660
1 changed files with 14 additions and 0 deletions

View File

@ -13,6 +13,7 @@
using System.Threading;
using System.Threading.Tasks;
using osu.Framework.Audio;
using osu.Framework.Statistics;
using osu.Game.IO.Serialization;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Objects;
@ -32,6 +33,8 @@ public abstract class WorkingBeatmap : IDisposable
protected AudioManager AudioManager { get; }
private static readonly GlobalStatistic<int> total_count = GlobalStatistics.Get<int>(nameof(Beatmaps), $"Total {nameof(WorkingBeatmap)}s");
protected WorkingBeatmap(BeatmapInfo beatmapInfo, AudioManager audioManager)
{
AudioManager = audioManager;
@ -44,6 +47,8 @@ protected WorkingBeatmap(BeatmapInfo beatmapInfo, AudioManager audioManager)
waveform = new RecyclableLazy<Waveform>(GetWaveform);
storyboard = new RecyclableLazy<Storyboard>(GetStoryboard);
skin = new RecyclableLazy<Skin>(GetSkin);
total_count.Value++;
}
protected virtual Track GetVirtualTrack()
@ -227,8 +232,15 @@ public void Dispose()
GC.SuppressFinalize(this);
}
private bool isDisposed;
protected virtual void Dispose(bool isDisposing)
{
if (isDisposed)
return;
isDisposed = true;
// recycling logic is not here for the time being, as components which use
// retrieved objects from WorkingBeatmap may not hold a reference to the WorkingBeatmap itself.
// this should be fine as each retrieved component do have their own finalizers.
@ -236,6 +248,8 @@ protected virtual void Dispose(bool isDisposing)
// cancelling the beatmap load is safe for now since the retrieval is a synchronous
// operation. if we add an async retrieval method this may need to be reconsidered.
beatmapCancellation.Cancel();
total_count.Value--;
}
~WorkingBeatmap()