1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-14 05:47:20 +08:00

Add components to track average hit errors across session

This commit is contained in:
Bartłomiej Dach 2023-12-27 19:43:14 +01:00
parent 1b7af989ec
commit f51b5f5487
No known key found for this signature in database
3 changed files with 80 additions and 0 deletions

View File

@ -55,6 +55,7 @@ using osu.Game.Online.Spectator;
using osu.Game.Overlays;
using osu.Game.Overlays.Settings;
using osu.Game.Overlays.Settings.Sections;
using osu.Game.Overlays.Settings.Sections.Audio;
using osu.Game.Overlays.Settings.Sections.Input;
using osu.Game.Resources;
using osu.Game.Rulesets;
@ -349,6 +350,7 @@ namespace osu.Game
dependencies.CacheAs(powerStatus);
dependencies.Cache(SessionStatics = new SessionStatics());
dependencies.Cache(new SessionAverageHitErrorTracker());
dependencies.Cache(Colours = new OsuColour());
RegisterImportHandler(BeatmapManager);

View File

@ -0,0 +1,23 @@
// 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 osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
namespace osu.Game.Overlays.Settings.Sections.Audio
{
public partial class AudioOffsetAdjustControl : SettingsItem<double>
{
[BackgroundDependencyLoader]
private void load()
{
}
protected override Drawable CreateControl() => new AudioOffsetPreview();
private partial class AudioOffsetPreview : CompositeDrawable
{
}
}
}

View File

@ -0,0 +1,55 @@
// 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.Configuration;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
namespace osu.Game.Overlays.Settings.Sections.Audio
{
/// <summary>
/// Tracks the local user's average hit error during the ongoing play session.
/// </summary>
[Cached]
public partial class SessionAverageHitErrorTracker : Component
{
public IBindableList<double> AverageHitErrorHistory => averageHitErrorHistory;
private readonly BindableList<double> averageHitErrorHistory = new BindableList<double>();
private readonly Bindable<ScoreInfo?> latestScore = new Bindable<ScoreInfo?>();
[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);
averageHitErrorHistory.Add(averageError);
}
public void ClearHistory() => averageHitErrorHistory.Clear();
}
}