1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 12:57:36 +08:00

Addressed changes

This commit is contained in:
Terochi 2023-03-21 23:15:49 +01:00
parent 8e6a4559e3
commit 1478a26cc0
2 changed files with 5 additions and 45 deletions

View File

@ -107,15 +107,12 @@ namespace osu.Game.Tests.Visual.Gameplay
AddUntilStep("ensure sample loaded", () => skinnableSound.ChildrenOfType<DrawableSample>().Single().Name, () => Is.EqualTo(sample_lookup)); AddUntilStep("ensure sample loaded", () => skinnableSound.ChildrenOfType<DrawableSample>().Single().Name, () => Is.EqualTo(sample_lookup));
AddStep("Change source", () => AddStep("change source", () =>
{ {
skinSource.OverridingSample = new SampleVirtual("new skin"); skinSource.OverridingSample = new SampleVirtual("new skin");
skinSource.TriggerSourceChanged(); skinSource.TriggerSourceChanged();
}); });
// Samples are nulled on source change immediately
AddUntilStep("wait for sample null", () => skinnableSound.ChildrenOfType<DrawableSample>().Count(), () => Is.Zero);
AddStep("start sample", () => skinnableSound.Play()); AddStep("start sample", () => skinnableSound.Play());
AddUntilStep("sample updated", () => skinnableSound.ChildrenOfType<DrawableSample>().Single().Name, () => Is.EqualTo("new skin")); AddUntilStep("sample updated", () => skinnableSound.ChildrenOfType<DrawableSample>().Single().Name, () => Is.EqualTo("new skin"));
} }

View File

@ -4,12 +4,10 @@
#nullable disable #nullable disable
using System; using System;
using System.Linq;
using JetBrains.Annotations; using JetBrains.Annotations;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Audio.Sample; using osu.Framework.Audio.Sample;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Audio; using osu.Framework.Graphics.Audio;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -70,48 +68,21 @@ namespace osu.Game.Skinning
updateSample(); updateSample();
} }
protected override void LoadComplete()
{
base.LoadComplete();
CurrentSkin.SourceChanged += skinChangedImmediate;
}
private void skinChangedImmediate()
{
// Clean up the previous sample immediately on a source change.
// This avoids a potential call to Play() of an already disposed sample (samples are disposed along with the skin, but SkinChanged is scheduled).
clearPreviousSamples();
}
protected override void SkinChanged(ISkinSource skin) protected override void SkinChanged(ISkinSource skin)
{ {
base.SkinChanged(skin); base.SkinChanged(skin);
updateSample(); updateSample();
} }
/// <summary>
/// Whether this sample was playing before a skin source change.
/// </summary>
private bool wasPlaying;
private void clearPreviousSamples()
{
// only run if the samples aren't already cleared.
// this ensures the "wasPlaying" state is stored correctly even if multiple clear calls are executed.
if (!sampleContainer.Any()) return;
wasPlaying = Playing;
sampleContainer.Clear();
Sample = null;
}
private void updateSample() private void updateSample()
{ {
if (sampleInfo == null) if (sampleInfo == null)
return; return;
bool wasPlaying = Playing;
sampleContainer.Clear();
var sample = CurrentSkin.GetSample(sampleInfo); var sample = CurrentSkin.GetSample(sampleInfo);
if (sample == null) if (sample == null)
@ -174,14 +145,6 @@ namespace osu.Game.Skinning
} }
} }
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (CurrentSkin.IsNotNull())
CurrentSkin.SourceChanged -= skinChangedImmediate;
}
#region Re-expose AudioContainer #region Re-expose AudioContainer
public BindableNumber<double> Volume => sampleContainer.Volume; public BindableNumber<double> Volume => sampleContainer.Volume;