From 811a5626084e86a5fb47d002c2dc89f1f1b98012 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 10 Jan 2023 01:10:20 +0900 Subject: [PATCH] Don't use bindables to avoid potential cross-usage contamination --- osu.Game/Beatmaps/BeatmapManager.cs | 11 ++++++++++- osu.Game/Database/ModelManager.cs | 3 +-- osu.Game/Database/RealmArchiveModelImporter.cs | 7 +++---- osu.Game/OsuGame.cs | 9 ++++++--- osu.Game/Scoring/ScoreManager.cs | 12 ++++++++++-- osu.Game/Skinning/SkinManager.cs | 12 ++++++++++-- 6 files changed, 40 insertions(+), 14 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index 623a657cd0..eafd1e96e8 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -44,6 +44,16 @@ namespace osu.Game.Beatmaps public Action<(BeatmapSetInfo beatmapSet, bool isBatch)>? ProcessBeatmap { private get; set; } + public override bool PauseImports + { + get => base.PauseImports; + set + { + base.PauseImports = value; + beatmapImporter.PauseImports = value; + } + } + public BeatmapManager(Storage storage, RealmAccess realm, IAPIProvider? api, AudioManager audioManager, IResourceStore gameResources, GameHost? host = null, WorkingBeatmap? defaultBeatmap = null, BeatmapDifficultyCache? difficultyCache = null, bool performOnlineLookups = false) : base(storage, realm) @@ -62,7 +72,6 @@ namespace osu.Game.Beatmaps BeatmapTrackStore = audioManager.GetTrackStore(userResources); beatmapImporter = CreateBeatmapImporter(storage, realm); - beatmapImporter.PauseImports.BindTo(PauseImports); beatmapImporter.ProcessBeatmap = args => ProcessBeatmap?.Invoke(args); beatmapImporter.PostNotification = obj => PostNotification?.Invoke(obj); diff --git a/osu.Game/Database/ModelManager.cs b/osu.Game/Database/ModelManager.cs index 9a88bd5646..7d1dc5239a 100644 --- a/osu.Game/Database/ModelManager.cs +++ b/osu.Game/Database/ModelManager.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; -using osu.Framework.Bindables; using osu.Framework.Platform; using osu.Game.Beatmaps; using osu.Game.Extensions; @@ -22,7 +21,7 @@ namespace osu.Game.Database /// /// Temporarily pause imports to avoid performance overheads affecting gameplay scenarios. /// - public readonly BindableBool PauseImports = new BindableBool(); + public virtual bool PauseImports { get; set; } protected RealmAccess Realm { get; } diff --git a/osu.Game/Database/RealmArchiveModelImporter.cs b/osu.Game/Database/RealmArchiveModelImporter.cs index cd86a5a94c..1fe1569d36 100644 --- a/osu.Game/Database/RealmArchiveModelImporter.cs +++ b/osu.Game/Database/RealmArchiveModelImporter.cs @@ -8,7 +8,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using Humanizer; -using osu.Framework.Bindables; using osu.Framework.Extensions; using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Logging; @@ -60,7 +59,7 @@ namespace osu.Game.Database /// /// Temporarily pause imports to avoid performance overheads affecting gameplay scenarios. /// - public readonly BindableBool PauseImports = new BindableBool(); + public bool PauseImports { get; set; } public abstract IEnumerable HandledExtensions { get; } @@ -559,12 +558,12 @@ namespace osu.Game.Database private void pauseIfNecessary(CancellationToken cancellationToken) { - if (!PauseImports.Value) + if (!PauseImports) return; Logger.Log(@"Import is being paused."); - while (PauseImports.Value) + while (PauseImports) { cancellationToken.ThrowIfCancellationRequested(); Thread.Sleep(500); diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 27152743f8..dc4d56de11 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -307,9 +307,12 @@ namespace osu.Game // Transfer any runtime changes back to configuration file. SkinManager.CurrentSkinInfo.ValueChanged += skin => configSkin.Value = skin.NewValue.ID.ToString(); - BeatmapManager.PauseImports.BindTo(LocalUserPlaying); - SkinManager.PauseImports.BindTo(LocalUserPlaying); - ScoreManager.PauseImports.BindTo(LocalUserPlaying); + LocalUserPlaying.BindValueChanged(p => + { + BeatmapManager.PauseImports = p.NewValue; + SkinManager.PauseImports = p.NewValue; + ScoreManager.PauseImports = p.NewValue; + }, true); IsActive.BindValueChanged(active => updateActiveState(active.NewValue), true); diff --git a/osu.Game/Scoring/ScoreManager.cs b/osu.Game/Scoring/ScoreManager.cs index 0852ab43f4..3217c79768 100644 --- a/osu.Game/Scoring/ScoreManager.cs +++ b/osu.Game/Scoring/ScoreManager.cs @@ -28,6 +28,16 @@ namespace osu.Game.Scoring private readonly OsuConfigManager configManager; private readonly ScoreImporter scoreImporter; + public override bool PauseImports + { + get => base.PauseImports; + set + { + base.PauseImports = value; + scoreImporter.PauseImports = value; + } + } + public ScoreManager(RulesetStore rulesets, Func beatmaps, Storage storage, RealmAccess realm, IAPIProvider api, OsuConfigManager configManager = null) : base(storage, realm) @@ -38,8 +48,6 @@ namespace osu.Game.Scoring { PostNotification = obj => PostNotification?.Invoke(obj) }; - - scoreImporter.PauseImports.BindTo(PauseImports); } public Score GetScore(ScoreInfo score) => scoreImporter.GetScore(score); diff --git a/osu.Game/Skinning/SkinManager.cs b/osu.Game/Skinning/SkinManager.cs index a0e7037d6d..a4cf83b32e 100644 --- a/osu.Game/Skinning/SkinManager.cs +++ b/osu.Game/Skinning/SkinManager.cs @@ -64,6 +64,16 @@ namespace osu.Game.Skinning private Skin trianglesSkin { get; } + public override bool PauseImports + { + get => base.PauseImports; + set + { + base.PauseImports = value; + skinImporter.PauseImports = value; + } + } + public SkinManager(Storage storage, RealmAccess realm, GameHost host, IResourceStore resources, AudioManager audio, Scheduler scheduler) : base(storage, realm) { @@ -79,8 +89,6 @@ namespace osu.Game.Skinning PostNotification = obj => PostNotification?.Invoke(obj), }; - skinImporter.PauseImports.BindTo(PauseImports); - var defaultSkins = new[] { DefaultClassicSkin = new DefaultLegacySkin(this),