Skip to content

Commit

Permalink
Merge pull request #30622 from bdach/not-enough-timed-events
Browse files Browse the repository at this point in the history
Do not show timing distribution graph in offset control if there's not enough timed hits
  • Loading branch information
smoogipoo authored Nov 15, 2024
2 parents b94d3d7 + bd1d3ca commit 58aba54
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
37 changes: 37 additions & 0 deletions osu.Game.Tests/Visual/Gameplay/TestSceneBeatmapOffsetControl.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Overlays.Settings;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
using osu.Game.Screens.Play.PlayerSettings;
using osu.Game.Tests.Resources;
Expand Down Expand Up @@ -52,6 +56,39 @@ public void TestTooShortToDisplay()
AddAssert("No calibration button", () => !offsetControl.ChildrenOfType<SettingsButton>().Any());
}

[Test]
public void TestNotEnoughTimedHitEvents()
{
AddStep("Set short reference score", () =>
{
List<HitEvent> hitEvents =
[
// 10 events total. one of them (head circle) being timed / having hitwindows, rest having no hitwindows
new HitEvent(30, 1, HitResult.LargeTickHit, new SliderHeadCircle { ClassicSliderBehaviour = true }, null, null),
new HitEvent(0, 1, HitResult.LargeTickHit, new SliderTick(), null, null),
new HitEvent(0, 1, HitResult.LargeTickHit, new SliderTick(), null, null),
new HitEvent(0, 1, HitResult.LargeTickHit, new SliderTick(), null, null),
new HitEvent(0, 1, HitResult.LargeTickHit, new SliderTick(), null, null),
new HitEvent(0, 1, HitResult.LargeTickHit, new SliderTick(), null, null),
new HitEvent(0, 1, HitResult.LargeTickHit, new SliderTick(), null, null),
new HitEvent(0, 1, HitResult.LargeTickHit, new SliderTick(), null, null),
new HitEvent(0, 1, HitResult.LargeTickHit, new SliderTick(), null, null),
new HitEvent(0, 1, HitResult.LargeTickHit, new SliderTick(), null, null),
];

foreach (var ev in hitEvents)
ev.HitObject.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());

offsetControl.ReferenceScore.Value = new ScoreInfo
{
HitEvents = hitEvents,
BeatmapInfo = Beatmap.Value.BeatmapInfo,
};
});

AddAssert("No calibration button", () => !offsetControl.ChildrenOfType<SettingsButton>().Any());
}

[Test]
public void TestScoreFromDifferentBeatmap()
{
Expand Down
6 changes: 3 additions & 3 deletions osu.Game/Rulesets/Scoring/HitEventExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static class HitEventExtensions

foreach (var e in hitEvents)
{
if (!affectsUnstableRate(e))
if (!AffectsUnstableRate(e))
continue;

count++;
Expand All @@ -57,14 +57,14 @@ public static class HitEventExtensions
/// </returns>
public static double? CalculateAverageHitError(this IEnumerable<HitEvent> hitEvents)
{
double[] timeOffsets = hitEvents.Where(affectsUnstableRate).Select(ev => ev.TimeOffset).ToArray();
double[] timeOffsets = hitEvents.Where(AffectsUnstableRate).Select(ev => ev.TimeOffset).ToArray();

if (timeOffsets.Length == 0)
return null;

return timeOffsets.Average();
}

private static bool affectsUnstableRate(HitEvent e) => !(e.HitObject.HitWindows is HitWindows.EmptyHitWindows) && e.Result.IsHit();
public static bool AffectsUnstableRate(HitEvent e) => !(e.HitObject.HitWindows is HitWindows.EmptyHitWindows) && e.Result.IsHit();
}
}
5 changes: 4 additions & 1 deletion osu.Game/Screens/Play/PlayerSettings/BeatmapOffsetControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,10 @@ private void scoreChanged(ValueChangedEvent<ScoreInfo?> score)
},
};

if (hitEvents.Count < 10)
// affecting unstable rate here is used as a substitute of determining if a hit event represents a *timed* hit event,
// i.e. an user input that the user had to *time to the track*,
// i.e. one that it *makes sense to use* when doing anything with timing and offsets.
if (hitEvents.Count(HitEventExtensions.AffectsUnstableRate) < 10)
{
referenceScoreContainer.AddRange(new Drawable[]
{
Expand Down

0 comments on commit 58aba54

Please sign in to comment.