2020-06-02 14:38:50 +00: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.
|
|
|
|
|
2020-06-18 13:11:03 +00:00
|
|
|
using System;
|
2020-06-02 14:38:50 +00:00
|
|
|
using System.Collections.Generic;
|
2020-06-22 11:32:04 +00:00
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
2022-09-11 19:43:15 +00:00
|
|
|
using osu.Framework.Bindables;
|
2020-06-02 14:38:50 +00:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2022-03-04 05:56:46 +00:00
|
|
|
using osu.Game.Rulesets.Objects;
|
2020-06-18 13:11:03 +00:00
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2020-06-19 11:03:18 +00:00
|
|
|
using osu.Game.Screens.Ranking.Statistics;
|
2020-06-02 14:38:50 +00:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Ranking
|
|
|
|
{
|
2020-06-19 11:03:18 +00:00
|
|
|
public partial class TestSceneHitEventTimingDistributionGraph : OsuTestScene
|
2020-06-02 14:38:50 +00:00
|
|
|
{
|
2022-09-07 07:43:48 +00:00
|
|
|
private HitEventTimingDistributionGraph graph = null!;
|
2022-09-11 19:43:15 +00:00
|
|
|
private readonly BindableFloat width = new BindableFloat(600);
|
|
|
|
private readonly BindableFloat height = new BindableFloat(130);
|
2022-03-04 05:34:33 +00:00
|
|
|
|
2022-03-04 05:56:46 +00:00
|
|
|
private static readonly HitObject placeholder_object = new HitCircle();
|
|
|
|
|
2022-09-11 19:43:15 +00:00
|
|
|
public TestSceneHitEventTimingDistributionGraph()
|
|
|
|
{
|
|
|
|
width.BindValueChanged(e => graph.Width = e.NewValue);
|
|
|
|
height.BindValueChanged(e => graph.Height = e.NewValue);
|
|
|
|
}
|
|
|
|
|
2020-06-22 11:32:04 +00:00
|
|
|
[Test]
|
|
|
|
public void TestManyDistributedEvents()
|
|
|
|
{
|
|
|
|
createTest(CreateDistributedHitEvents());
|
2022-03-04 05:34:33 +00:00
|
|
|
AddStep("add adjustment", () => graph.UpdateOffset(10));
|
2022-09-11 19:43:15 +00:00
|
|
|
AddSliderStep("width", 0.0f, 1000.0f, width.Value, width.Set);
|
|
|
|
AddSliderStep("height", 0.0f, 1000.0f, height.Value, height.Set);
|
2020-06-22 11:32:04 +00:00
|
|
|
}
|
|
|
|
|
2022-03-03 06:43:01 +00:00
|
|
|
[Test]
|
|
|
|
public void TestManyDistributedEventsOffset()
|
|
|
|
{
|
|
|
|
createTest(CreateDistributedHitEvents(-3.5));
|
|
|
|
}
|
|
|
|
|
2020-10-08 19:41:45 +00:00
|
|
|
[Test]
|
|
|
|
public void TestAroundCentre()
|
|
|
|
{
|
2022-03-04 05:56:46 +00:00
|
|
|
createTest(Enumerable.Range(-150, 300).Select(i => new HitEvent(i / 50f, HitResult.Perfect, placeholder_object, placeholder_object, null)).ToList());
|
2020-10-08 19:41:45 +00:00
|
|
|
}
|
|
|
|
|
2022-09-04 18:46:23 +00:00
|
|
|
[Test]
|
|
|
|
public void TestSparse()
|
|
|
|
{
|
|
|
|
createTest(new List<HitEvent>
|
|
|
|
{
|
|
|
|
new HitEvent(-7, HitResult.Perfect, placeholder_object, placeholder_object, null),
|
|
|
|
new HitEvent(-6, HitResult.Perfect, placeholder_object, placeholder_object, null),
|
|
|
|
new HitEvent(-5, HitResult.Perfect, placeholder_object, placeholder_object, null),
|
|
|
|
new HitEvent(5, HitResult.Perfect, placeholder_object, placeholder_object, null),
|
|
|
|
new HitEvent(6, HitResult.Perfect, placeholder_object, placeholder_object, null),
|
|
|
|
new HitEvent(7, HitResult.Perfect, placeholder_object, placeholder_object, null),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestVariousTypesOfHitResult()
|
|
|
|
{
|
|
|
|
createTest(CreateDistributedHitEvents(0, 50).Select(h =>
|
|
|
|
{
|
2022-09-06 17:29:15 +00:00
|
|
|
double offset = Math.Abs(h.TimeOffset);
|
2022-09-07 07:43:48 +00:00
|
|
|
HitResult result = offset > 36 ? HitResult.Miss
|
|
|
|
: offset > 32 ? HitResult.Meh
|
|
|
|
: offset > 24 ? HitResult.Ok
|
|
|
|
: offset > 16 ? HitResult.Good
|
|
|
|
: offset > 8 ? HitResult.Great
|
|
|
|
: HitResult.Perfect;
|
2022-09-04 18:46:23 +00:00
|
|
|
return new HitEvent(h.TimeOffset, result, placeholder_object, placeholder_object, null);
|
|
|
|
}).ToList());
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestMultipleWindowsOfHitResult()
|
|
|
|
{
|
|
|
|
var wide = CreateDistributedHitEvents(0, 50).Select(h =>
|
|
|
|
{
|
2022-09-06 17:29:15 +00:00
|
|
|
double offset = Math.Abs(h.TimeOffset);
|
2022-09-07 07:43:48 +00:00
|
|
|
HitResult result = offset > 36 ? HitResult.Miss
|
|
|
|
: offset > 32 ? HitResult.Meh
|
|
|
|
: offset > 24 ? HitResult.Ok
|
|
|
|
: offset > 16 ? HitResult.Good
|
|
|
|
: offset > 8 ? HitResult.Great
|
|
|
|
: HitResult.Perfect;
|
|
|
|
|
2022-09-04 18:46:23 +00:00
|
|
|
return new HitEvent(h.TimeOffset, result, placeholder_object, placeholder_object, null);
|
|
|
|
});
|
|
|
|
var narrow = CreateDistributedHitEvents(0, 50).Select(h =>
|
|
|
|
{
|
2022-09-06 17:29:15 +00:00
|
|
|
double offset = Math.Abs(h.TimeOffset);
|
2022-09-07 07:43:48 +00:00
|
|
|
HitResult result = offset > 25 ? HitResult.Miss
|
|
|
|
: offset > 20 ? HitResult.Meh
|
|
|
|
: offset > 15 ? HitResult.Ok
|
|
|
|
: offset > 10 ? HitResult.Good
|
|
|
|
: offset > 5 ? HitResult.Great
|
|
|
|
: HitResult.Perfect;
|
2022-09-04 18:46:23 +00:00
|
|
|
return new HitEvent(h.TimeOffset, result, placeholder_object, placeholder_object, null);
|
|
|
|
});
|
|
|
|
createTest(wide.Concat(narrow).ToList());
|
|
|
|
}
|
|
|
|
|
2020-06-22 11:32:04 +00:00
|
|
|
[Test]
|
|
|
|
public void TestZeroTimeOffset()
|
|
|
|
{
|
2022-03-04 05:56:46 +00:00
|
|
|
createTest(Enumerable.Range(0, 100).Select(_ => new HitEvent(0, HitResult.Perfect, placeholder_object, placeholder_object, null)).ToList());
|
2020-06-22 11:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestNoEvents()
|
|
|
|
{
|
|
|
|
createTest(new List<HitEvent>());
|
|
|
|
}
|
|
|
|
|
2020-08-31 05:15:47 +00:00
|
|
|
[Test]
|
|
|
|
public void TestMissesDontShow()
|
|
|
|
{
|
|
|
|
createTest(Enumerable.Range(0, 100).Select(i =>
|
|
|
|
{
|
|
|
|
if (i % 2 == 0)
|
2022-03-04 05:56:46 +00:00
|
|
|
return new HitEvent(0, HitResult.Perfect, placeholder_object, placeholder_object, null);
|
2020-08-31 05:15:47 +00:00
|
|
|
|
2022-03-04 05:56:46 +00:00
|
|
|
return new HitEvent(30, HitResult.Miss, placeholder_object, placeholder_object, null);
|
2020-08-31 05:15:47 +00:00
|
|
|
}).ToList());
|
|
|
|
}
|
|
|
|
|
2020-06-22 11:32:04 +00:00
|
|
|
private void createTest(List<HitEvent> events) => AddStep("create test", () =>
|
2020-06-02 14:38:50 +00:00
|
|
|
{
|
2020-06-12 13:48:43 +00:00
|
|
|
Children = new Drawable[]
|
2020-06-02 14:38:50 +00:00
|
|
|
{
|
2020-06-12 13:48:43 +00:00
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4Extensions.FromHex("#333")
|
|
|
|
},
|
2022-03-04 05:34:33 +00:00
|
|
|
graph = new HitEventTimingDistributionGraph(events)
|
2020-06-12 13:48:43 +00:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2022-09-11 19:43:15 +00:00
|
|
|
Size = new Vector2(width.Value, height.Value)
|
2020-06-12 13:48:43 +00:00
|
|
|
}
|
|
|
|
};
|
2020-06-22 11:32:04 +00:00
|
|
|
});
|
2020-06-02 14:38:50 +00:00
|
|
|
|
2022-03-01 06:40:37 +00:00
|
|
|
public static List<HitEvent> CreateDistributedHitEvents(double centre = 0, double range = 25)
|
2020-06-02 14:38:50 +00:00
|
|
|
{
|
2020-06-18 13:11:03 +00:00
|
|
|
var hitEvents = new List<HitEvent>();
|
2020-06-02 14:38:50 +00:00
|
|
|
|
2022-03-01 06:40:37 +00:00
|
|
|
for (int i = 0; i < range * 2; i++)
|
2020-06-02 14:38:50 +00:00
|
|
|
{
|
2022-03-04 05:56:46 +00:00
|
|
|
int count = (int)(Math.Pow(range - Math.Abs(i - range), 2)) / 10;
|
2020-06-02 14:38:50 +00:00
|
|
|
|
2020-06-18 13:11:03 +00:00
|
|
|
for (int j = 0; j < count; j++)
|
2022-03-04 05:56:46 +00:00
|
|
|
hitEvents.Add(new HitEvent(centre + i - range, HitResult.Perfect, placeholder_object, placeholder_object, null));
|
2020-06-02 14:38:50 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 13:11:03 +00:00
|
|
|
return hitEvents;
|
2020-06-02 14:38:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|