1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 16:07:24 +08:00

Fix global audio offset suggestion feature not taking previous offset value into account

See https://osu.ppy.sh/comments/2989193 etc.
This commit is contained in:
Bartłomiej Dach 2023-12-29 12:20:14 +01:00
parent 9548818a1b
commit cdcb3ef4aa
No known key found for this signature in database
2 changed files with 29 additions and 10 deletions

View File

@ -17,11 +17,14 @@ namespace osu.Game.Configuration
[Cached]
public partial class SessionAverageHitErrorTracker : Component
{
public IBindableList<double> AverageHitErrorHistory => averageHitErrorHistory;
private readonly BindableList<double> averageHitErrorHistory = new BindableList<double>();
public IBindableList<DataPoint> AverageHitErrorHistory => averageHitErrorHistory;
private readonly BindableList<DataPoint> averageHitErrorHistory = new BindableList<DataPoint>();
private readonly Bindable<ScoreInfo?> latestScore = new Bindable<ScoreInfo?>();
[Resolved]
private OsuConfigManager configManager { get; set; } = null!;
[BackgroundDependencyLoader]
private void load(SessionStatics statics)
{
@ -46,9 +49,25 @@ namespace osu.Game.Configuration
// keep a sane maximum number of entries.
if (averageHitErrorHistory.Count >= 50)
averageHitErrorHistory.RemoveAt(0);
averageHitErrorHistory.Add(averageError);
double globalOffset = configManager.Get<double>(OsuSetting.AudioOffset);
averageHitErrorHistory.Add(new DataPoint(averageError, globalOffset));
}
public void ClearHistory() => averageHitErrorHistory.Clear();
public readonly struct DataPoint
{
public double AverageHitError { get; }
public double GlobalAudioOffset { get; }
public double SuggestedGlobalAudioOffset => GlobalAudioOffset - AverageHitError;
public DataPoint(double averageHitError, double globalOffset)
{
AverageHitError = averageHitError;
GlobalAudioOffset = globalOffset;
}
}
}
}

View File

@ -42,7 +42,7 @@ namespace osu.Game.Overlays.Settings.Sections.Audio
private readonly BindableNumberWithCurrent<double> current = new BindableNumberWithCurrent<double>();
private readonly IBindableList<double> averageHitErrorHistory = new BindableList<double>();
private readonly IBindableList<SessionAverageHitErrorTracker.DataPoint> averageHitErrorHistory = new BindableList<SessionAverageHitErrorTracker.DataPoint>();
private readonly Bindable<double?> suggestedOffset = new Bindable<double?>();
@ -112,7 +112,7 @@ namespace osu.Game.Overlays.Settings.Sections.Audio
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
foreach (double average in e.NewItems!)
foreach (SessionAverageHitErrorTracker.DataPoint dataPoint in e.NewItems!)
{
notchContainer.ForEach(n => n.Alpha *= 0.95f);
notchContainer.Add(new Box
@ -122,16 +122,16 @@ namespace osu.Game.Overlays.Settings.Sections.Audio
RelativePositionAxes = Axes.X,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
X = getXPositionForAverage(average)
X = getXPositionForOffset(dataPoint.SuggestedGlobalAudioOffset)
});
}
break;
case NotifyCollectionChangedAction.Remove:
foreach (double average in e.OldItems!)
foreach (SessionAverageHitErrorTracker.DataPoint dataPoint in e.OldItems!)
{
var notch = notchContainer.FirstOrDefault(n => n.X == getXPositionForAverage(average));
var notch = notchContainer.FirstOrDefault(n => n.X == getXPositionForOffset(dataPoint.SuggestedGlobalAudioOffset));
Debug.Assert(notch != null);
notchContainer.Remove(notch, true);
}
@ -143,10 +143,10 @@ namespace osu.Game.Overlays.Settings.Sections.Audio
break;
}
suggestedOffset.Value = averageHitErrorHistory.Any() ? -averageHitErrorHistory.Average() : null;
suggestedOffset.Value = averageHitErrorHistory.Any() ? -averageHitErrorHistory.Average(dataPoint => dataPoint.SuggestedGlobalAudioOffset) : null;
}
private float getXPositionForAverage(double average) => (float)(Math.Clamp(-average, current.MinValue, current.MaxValue) / (2 * current.MaxValue));
private float getXPositionForOffset(double offset) => (float)(Math.Clamp(offset, current.MinValue, current.MaxValue) / (2 * current.MaxValue));
private void updateHintText()
{