2023-12-28 02:43:14 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
|
|
|
using osu.Game.Scoring;
|
|
|
|
|
2023-12-28 21:10:03 +08:00
|
|
|
namespace osu.Game.Configuration
|
2023-12-28 02:43:14 +08:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Tracks the local user's average hit error during the ongoing play session.
|
|
|
|
/// </summary>
|
|
|
|
[Cached]
|
|
|
|
public partial class SessionAverageHitErrorTracker : Component
|
|
|
|
{
|
2023-12-29 19:20:14 +08:00
|
|
|
public IBindableList<DataPoint> AverageHitErrorHistory => averageHitErrorHistory;
|
|
|
|
private readonly BindableList<DataPoint> averageHitErrorHistory = new BindableList<DataPoint>();
|
2023-12-28 02:43:14 +08:00
|
|
|
|
|
|
|
private readonly Bindable<ScoreInfo?> latestScore = new Bindable<ScoreInfo?>();
|
|
|
|
|
2023-12-29 19:20:14 +08:00
|
|
|
[Resolved]
|
|
|
|
private OsuConfigManager configManager { get; set; } = null!;
|
|
|
|
|
2023-12-28 02:43:14 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(SessionStatics statics)
|
|
|
|
{
|
|
|
|
statics.BindWith(Static.LastLocalUserScore, latestScore);
|
|
|
|
latestScore.BindValueChanged(score => calculateAverageHitError(score.NewValue), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void calculateAverageHitError(ScoreInfo? newScore)
|
|
|
|
{
|
|
|
|
if (newScore == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (newScore.Mods.Any(m => !m.UserPlayable || m is IHasNoTimedInputs))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (newScore.HitEvents.Count < 10)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (newScore.HitEvents.CalculateAverageHitError() is not double averageError)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// keep a sane maximum number of entries.
|
|
|
|
if (averageHitErrorHistory.Count >= 50)
|
|
|
|
averageHitErrorHistory.RemoveAt(0);
|
2023-12-29 19:20:14 +08:00
|
|
|
|
|
|
|
double globalOffset = configManager.Get<double>(OsuSetting.AudioOffset);
|
|
|
|
averageHitErrorHistory.Add(new DataPoint(averageError, globalOffset));
|
2023-12-28 02:43:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void ClearHistory() => averageHitErrorHistory.Clear();
|
2023-12-29 19:20:14 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2023-12-28 02:43:14 +08:00
|
|
|
}
|
|
|
|
}
|