From a9c349fa6db682c9c2cdfa961f2821e84bac57d4 Mon Sep 17 00:00:00 2001 From: Terochi Date: Wed, 15 Mar 2023 09:00:34 +0100 Subject: [PATCH] Cache any skin changes in `SkinReloadableDrawable` to `ScheduledDelegate` --- osu.Game/Skinning/SkinReloadableDrawable.cs | 19 +++++++++++++++++-- osu.Game/Skinning/SkinnableSound.cs | 6 +++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/osu.Game/Skinning/SkinReloadableDrawable.cs b/osu.Game/Skinning/SkinReloadableDrawable.cs index cef1db4bc0..757ca8de83 100644 --- a/osu.Game/Skinning/SkinReloadableDrawable.cs +++ b/osu.Game/Skinning/SkinReloadableDrawable.cs @@ -5,6 +5,7 @@ using System; using osu.Framework.Allocation; using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics.Pooling; +using osu.Framework.Threading; namespace osu.Game.Skinning { @@ -14,6 +15,8 @@ namespace osu.Game.Skinning /// public abstract partial class SkinReloadableDrawable : PoolableDrawable { + private ScheduledDelegate? pendingSkinChange; + /// /// Invoked when has changed. /// @@ -31,10 +34,22 @@ namespace osu.Game.Skinning CurrentSkin.SourceChanged += onChange; } - private void onChange() => + private void onChange() + { // schedule required to avoid calls after disposed. // note that this has the side-effect of components only performing a skin change when they are alive. - Scheduler.AddOnce(skinChanged); + pendingSkinChange?.Cancel(); + pendingSkinChange = Scheduler.Add(skinChanged); + } + + public void FlushPendingSkinChanges() + { + if (pendingSkinChange == null) + return; + + pendingSkinChange.RunTask(); + pendingSkinChange = null; + } protected override void LoadAsyncComplete() { diff --git a/osu.Game/Skinning/SkinnableSound.cs b/osu.Game/Skinning/SkinnableSound.cs index 43e16f4930..052b1e5b9f 100644 --- a/osu.Game/Skinning/SkinnableSound.cs +++ b/osu.Game/Skinning/SkinnableSound.cs @@ -115,12 +115,12 @@ namespace osu.Game.Skinning /// public virtual void Play() { - if (Scheduler.HasPendingTasks) - // update samples queued due to skin change before playing them - UpdateSubTree(); + FlushPendingSkinChanges(); samplesContainer.ForEach(c => { + c.FlushPendingSkinChanges(); + if (PlayWhenZeroVolume || c.AggregateVolume.Value > 0) { c.Stop();