Skip to content

Commit

Permalink
Merge pull request #19800 from peppy/fix-editor-ear-rape
Browse files Browse the repository at this point in the history
Fix slider ticks playing back at infinite rate while making changes to a slider in the editor
  • Loading branch information
smoogipoo authored Aug 17, 2022
2 parents aaaaff1 + 6b9dec5 commit 0cf3c55
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
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 @@ -228,6 +239,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 @@ -237,6 +250,8 @@ public void UpdateAllHitObjects()
{
foreach (var h in HitObjects)
batchPendingUpdates.Add(h);

updateInProgress.Value = true;
}

/// <summary>
Expand Down Expand Up @@ -329,6 +344,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

0 comments on commit 0cf3c55

Please sign in to comment.