Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix slider ticks playing back at infinite rate while making changes to a slider in the editor #19800

Merged
merged 3 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion osu.Game/Screens/Edit/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using osu.Framework.Platform;
using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Framework.Threading;
using osu.Framework.Timing;
using osu.Game.Audio;
using osu.Game.Beatmaps;
Expand Down Expand Up @@ -233,6 +234,8 @@ private void load(OsuConfigManager config)
AddInternal(editorBeatmap = new EditorBeatmap(playableBeatmap, loadableBeatmap.GetSkin(), loadableBeatmap.BeatmapInfo));
dependencies.CacheAs(editorBeatmap);

editorBeatmap.UpdateInProgress.BindValueChanged(updateInProgress);

canSave = editorBeatmap.BeatmapInfo.Ruleset.CreateInstance() is ILegacyRuleset;

if (canSave)
Expand Down Expand Up @@ -714,6 +717,27 @@ private void confirmExit()
this.Exit();
}

#region Mute from update application

private ScheduledDelegate temporaryMuteRestorationDelegate;
private bool temporaryMuteFromUpdateInProgress;

private void updateInProgress(ValueChangedEvent<bool> obj)
{
temporaryMuteFromUpdateInProgress = true;
updateSampleDisabledState();

// Debounce is arbitrarily high enough to avoid flip-flopping the value each other frame.
temporaryMuteRestorationDelegate?.Cancel();
temporaryMuteRestorationDelegate = Scheduler.AddDelayed(() =>
{
temporaryMuteFromUpdateInProgress = false;
updateSampleDisabledState();
}, 50);
}

#endregion

#region Clipboard support

private EditorMenuItem cutMenuItem;
Expand Down Expand Up @@ -829,7 +853,9 @@ private void onModeChanged(ValueChangedEvent<EditorScreenMode> e)

private void updateSampleDisabledState()
{
samplePlaybackDisabled.Value = clock.SeekingOrStopped.Value || !(currentScreen is ComposeScreen);
samplePlaybackDisabled.Value = clock.SeekingOrStopped.Value
|| currentScreen is not ComposeScreen
|| temporaryMuteFromUpdateInProgress;
}

private void seek(UIEvent e, int direction)
Expand Down
17 changes: 17 additions & 0 deletions osu.Game/Screens/Edit/EditorBeatmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ namespace osu.Game.Screens.Edit
{
public class EditorBeatmap : TransactionalCommitComponent, IBeatmap, IBeatSnapProvider
{
/// <summary>
/// Will become <c>true</c> when a new update is queued, and <c>false</c> when all updates have been applied.
/// </summary>
/// <remarks>
/// This is intended to be used to avoid performing operations (like playback of samples)
/// while mutating hitobjects.
/// </remarks>
public IBindable<bool> UpdateInProgress => updateInProgress;

private readonly BindableBool updateInProgress = new BindableBool();

/// <summary>
/// Invoked when a <see cref="HitObject"/> is added to this <see cref="EditorBeatmap"/>.
/// </summary>
Expand Down Expand Up @@ -225,6 +236,8 @@ public void Update([NotNull] HitObject hitObject)
{
// updates are debounced regardless of whether a batch is active.
batchPendingUpdates.Add(hitObject);

updateInProgress.Value = true;
}

/// <summary>
Expand All @@ -234,6 +247,8 @@ public void UpdateAllHitObjects()
{
foreach (var h in HitObjects)
batchPendingUpdates.Add(h);

updateInProgress.Value = true;
}

/// <summary>
Expand Down Expand Up @@ -326,6 +341,8 @@ protected override void UpdateState()
foreach (var h in deletes) HitObjectRemoved?.Invoke(h);
foreach (var h in inserts) HitObjectAdded?.Invoke(h);
foreach (var h in updates) HitObjectUpdated?.Invoke(h);

updateInProgress.Value = false;
}

/// <summary>
Expand Down