Replace checks with realistic ones

This commit is contained in:
Naxess
2021-04-10 13:03:16 +02:00
parent b30e41b805
commit bc4f3351f3
6 changed files with 169 additions and 153 deletions

View File

@ -1,86 +0,0 @@
// 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.Collections.Generic;
using System.Linq;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Screens.Edit.Verify;
using osu.Game.Screens.Edit.Verify.Components;
namespace osu.Game.Rulesets.Osu.Edit.Checks
{
public class CheckConsecutiveCircles : BeatmapCheck
{
private const double consecutive_threshold = 3;
private const double delta_time_min_expected = 300;
private const double delta_time_min_threshold = 100;
public override CheckMetadata Metadata() => new CheckMetadata
(
category: CheckMetadata.CheckCategory.Spread,
description: "Too many or fast consecutive circles."
);
private IssueTemplate templateManyInARow = new IssueTemplate
(
type: IssueTemplate.IssueType.Problem,
unformattedMessage: "There are {0} circles in a row here, expected at most {1}."
);
private IssueTemplate templateTooFast = new IssueTemplate
(
type: IssueTemplate.IssueType.Warning,
unformattedMessage: "These circles are too fast ({0:0} ms), expected at least {1:0} ms."
);
private IssueTemplate templateAlmostTooFast = new IssueTemplate
(
type: IssueTemplate.IssueType.Negligible,
unformattedMessage: "These circles are almost too fast ({0:0} ms), expected at least {1:0} ms."
);
public override IEnumerable<IssueTemplate> Templates() => new[]
{
templateManyInARow,
templateTooFast,
templateAlmostTooFast
};
public override IEnumerable<Issue> Run(IBeatmap beatmap)
{
List<HitCircle> prevCircles = new List<HitCircle>();
foreach (HitObject hitobject in beatmap.HitObjects)
{
if (!(hitobject is HitCircle circle) || hitobject == beatmap.HitObjects.Last())
{
if (prevCircles.Count > consecutive_threshold)
{
yield return new Issue(
prevCircles,
templateManyInARow,
prevCircles.Count, consecutive_threshold
);
}
prevCircles.Clear();
continue;
}
double? prevDeltaTime = circle.StartTime - prevCircles.LastOrDefault()?.StartTime;
prevCircles.Add(circle);
if (prevDeltaTime == null || prevDeltaTime >= delta_time_min_expected)
continue;
yield return new Issue(
prevCircles.TakeLast(2),
prevDeltaTime < delta_time_min_threshold ? templateTooFast : templateAlmostTooFast,
prevDeltaTime, delta_time_min_expected
);
}
}
}
}

View File

@ -0,0 +1,110 @@
// 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.Collections.Generic;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit.Checks.Components;
using osu.Game.Rulesets.Osu.Objects;
using osuTK;
namespace osu.Game.Rulesets.Osu.Edit.Checks
{
public class CheckOffscreenObjects : BeatmapCheck
{
// These are close approximates to the edges of the screen
// in gameplay on a 4:3 aspect ratio for osu!stable.
private const int min_x = -67;
private const int min_y = -60;
private const int max_x = 579;
private const int max_y = 428;
// The amount of milliseconds to step through a slider path at a time
// (higher = more performant, but higher false-negative chance).
private const int path_step_size = 5;
public override CheckMetadata Metadata() => new CheckMetadata
(
category: CheckMetadata.CheckCategory.Compose,
description: "Offscreen hitobjects."
);
public override IEnumerable<IssueTemplate> Templates() => new[]
{
templateOffscreen,
templateOffscreenSliderPath
};
private readonly IssueTemplate templateOffscreen = new IssueTemplate
(
type: IssueTemplate.IssueType.Problem,
unformattedMessage: "This object goes offscreen on a 4:3 aspect ratio."
);
private readonly IssueTemplate templateOffscreenSliderPath = new IssueTemplate
(
type: IssueTemplate.IssueType.Problem,
unformattedMessage: "This slider goes offscreen here on a 4:3 aspect ratio."
);
public override IEnumerable<Issue> Run(IBeatmap beatmap)
{
foreach (var hitobject in beatmap.HitObjects)
{
switch (hitobject)
{
case Slider slider:
{
foreach (var issue in sliderIssues(slider))
yield return issue;
break;
}
case HitCircle circle:
{
if (isOffscreen(circle.StackedPosition, circle.Radius))
yield return new Issue(circle, templateOffscreen);
break;
}
}
}
}
/// <summary>
/// Steps through points on the slider to ensure the entire path is on-screen.
/// Returns at most one issue.
/// </summary>
/// <param name="slider">The slider whose path to check.</param>
/// <returns></returns>
private IEnumerable<Issue> sliderIssues(Slider slider)
{
for (int i = 0; i < slider.Distance; i += path_step_size)
{
double progress = i / slider.Distance;
Vector2 position = slider.StackedPositionAt(progress);
if (!isOffscreen(position, slider.Radius))
continue;
// `SpanDuration` ensures we don't include reverses.
double time = slider.StartTime + progress * slider.SpanDuration;
yield return new Issue(slider, templateOffscreenSliderPath) { Time = time };
yield break;
}
// Above loop may skip the last position in the slider due to step size.
if (!isOffscreen(slider.StackedEndPosition, slider.Radius))
yield break;
yield return new Issue(slider, templateOffscreenSliderPath) { Time = slider.EndTime };
}
private bool isOffscreen(Vector2 position, double radius)
{
return position.X - radius < min_x || position.X + radius > max_x ||
position.Y - radius < min_y || position.Y + radius > max_y;
}
}
}