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

View File

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