From 1db49d250f89c4172e8e558c2f060bdc50bba0d2 Mon Sep 17 00:00:00 2001 From: Salman Alshamrani Date: Thu, 14 Aug 2025 13:42:48 +0300 Subject: [PATCH] Move beatmap offset write logic to a separate method Note that calling `writeOffsetToBeatmap` from `currentChanged` is still intentionally not scheduled, see https://github.com/ppy/osu/pull/34612#discussion_r2269052138. This commit is done so that if that call is scheduled, then the logic above it that update the play graph and visibility state of the button still don't get scheduled, otherwise the test will fail (as noticed in https://github.com/ppy/osu/pull/34612#discussion_r2269208998). --- .../PlayerSettings/BeatmapOffsetControl.cs | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/osu.Game/Screens/Play/PlayerSettings/BeatmapOffsetControl.cs b/osu.Game/Screens/Play/PlayerSettings/BeatmapOffsetControl.cs index d6b7b51ddc..61ecc470f7 100644 --- a/osu.Game/Screens/Play/PlayerSettings/BeatmapOffsetControl.cs +++ b/osu.Game/Screens/Play/PlayerSettings/BeatmapOffsetControl.cs @@ -146,42 +146,42 @@ namespace osu.Game.Screens.Play.PlayerSettings private void currentChanged(ValueChangedEvent offset) { - updateOffset(); + // Negative is applied here because the play graph is considering a hit offset, not track (as we currently use for clocks). + lastPlayGraph?.UpdateOffset(-adjustmentSinceLastPlay); - void updateOffset() + // Calibration button may be hidden due to automatic offset adjustment, but it should be visible when the user manually adjusts their offset away from the applied suggestion. + calibrateFromLastPlayButton?.Show(); + + writeOffsetToBeatmap(); + } + + private void writeOffsetToBeatmap() + { + // ensure the previous write has completed. ignoring performance concerns, if we don't do this, the async writes could be out of sequence. + if (realmWriteTask?.IsCompleted == false) { - // Negative is applied here because the play graph is considering a hit offset, not track (as we currently use for clocks). - lastPlayGraph?.UpdateOffset(-adjustmentSinceLastPlay); - - // Calibration button may be hidden due to automatic offset adjustment, but it should be visible when the user manually adjusts their offset away from the applied suggestion. - calibrateFromLastPlayButton?.Show(); - - // ensure the previous write has completed. ignoring performance concerns, if we don't do this, the async writes could be out of sequence. - if (realmWriteTask?.IsCompleted == false) - { - Scheduler.AddOnce(updateOffset); - return; - } - - realmWriteTask = realm.WriteAsync(r => - { - var setInfo = r.Find(beatmap.Value.BeatmapSetInfo.ID); - - if (setInfo == null) // only the case for tests. - return; - - // Apply to all difficulties in a beatmap set if they have the same audio - // (they generally always share timing). - foreach (var b in setInfo.Beatmaps) - { - BeatmapUserSettings userSettings = b.UserSettings; - double val = Current.Value; - - if (userSettings.Offset != val && b.AudioEquals(beatmap.Value.BeatmapInfo)) - userSettings.Offset = val; - } - }); + Scheduler.AddOnce(writeOffsetToBeatmap); + return; } + + realmWriteTask = realm.WriteAsync(r => + { + var setInfo = r.Find(beatmap.Value.BeatmapSetInfo.ID); + + if (setInfo == null) // only the case for tests. + return; + + // Apply to all difficulties in a beatmap set if they have the same audio + // (they generally always share timing). + foreach (var b in setInfo.Beatmaps) + { + BeatmapUserSettings userSettings = b.UserSettings; + double val = Current.Value; + + if (userSettings.Offset != val && b.AudioEquals(beatmap.Value.BeatmapInfo)) + userSettings.Offset = val; + } + }); } private void scoreChanged(ValueChangedEvent score)