1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 09:27:29 +08:00

Move accuracy heatmap to osu! ruleset, rename, remove magic number

This commit is contained in:
smoogipoo 2020-06-19 21:14:31 +09:00
parent 49997c54d0
commit 863666f7c4
3 changed files with 15 additions and 14 deletions

View File

@ -9,21 +9,21 @@ using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Framework.Threading;
using osu.Framework.Utils;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Statistics;
using osu.Game.Scoring;
using osu.Game.Tests.Beatmaps;
using osu.Game.Tests.Visual;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Tests.Visual.Ranking
namespace osu.Game.Rulesets.Osu.Tests
{
public class TestSceneAccuracyHeatmap : OsuManualInputManagerTestScene
{
private Box background;
private Drawable object1;
private Drawable object2;
private TestHeatmap heatmap;
private TestAccuracyHeatmap accuracyHeatmap;
private ScheduledDelegate automaticAdditionDelegate;
[SetUp]
@ -48,7 +48,7 @@ namespace osu.Game.Tests.Visual.Ranking
{
Position = new Vector2(100, 300),
},
heatmap = new TestHeatmap(new ScoreInfo { Beatmap = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo })
accuracyHeatmap = new TestAccuracyHeatmap(new ScoreInfo { Beatmap = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo })
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
@ -69,7 +69,7 @@ namespace osu.Game.Tests.Visual.Ranking
RNG.NextSingle(object1.DrawPosition.Y - object1.DrawSize.Y / 2, object1.DrawPosition.Y + object1.DrawSize.Y / 2));
// The background is used for ToLocalSpace() since we need to go _inside_ the DrawSizePreservingContainer (Content of TestScene).
heatmap.AddPoint(object2.Position, object1.Position, randomPos, RNG.NextSingle(10, 500));
accuracyHeatmap.AddPoint(object2.Position, object1.Position, randomPos, RNG.NextSingle(10, 500));
InputManager.MoveMouseTo(background.ToScreenSpace(randomPos));
}, 1, true);
});
@ -85,13 +85,13 @@ namespace osu.Game.Tests.Visual.Ranking
protected override bool OnMouseDown(MouseDownEvent e)
{
heatmap.AddPoint(object2.Position, object1.Position, background.ToLocalSpace(e.ScreenSpaceMouseDownPosition), 50);
accuracyHeatmap.AddPoint(object2.Position, object1.Position, background.ToLocalSpace(e.ScreenSpaceMouseDownPosition), 50);
return true;
}
private class TestHeatmap : Heatmap
private class TestAccuracyHeatmap : AccuracyHeatmap
{
public TestHeatmap(ScoreInfo score)
public TestAccuracyHeatmap(ScoreInfo score)
: base(score)
{
}

View File

@ -203,7 +203,7 @@ namespace osu.Game.Rulesets.Osu
RelativeSizeAxes = Axes.X,
Height = 130
}),
new StatisticItem("Accuracy Heatmap", new Heatmap(score)
new StatisticItem("Accuracy Heatmap", new AccuracyHeatmap(score)
{
RelativeSizeAxes = Axes.X,
Height = 130

View File

@ -9,6 +9,7 @@ using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Utils;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Scoring;
using osuTK;
@ -16,17 +17,17 @@ using osuTK.Graphics;
namespace osu.Game.Rulesets.Osu.Statistics
{
public class Heatmap : CompositeDrawable
public class AccuracyHeatmap : CompositeDrawable
{
/// <summary>
/// Size of the inner circle containing the "hit" points, relative to the size of this <see cref="Heatmap"/>.
/// Size of the inner circle containing the "hit" points, relative to the size of this <see cref="AccuracyHeatmap"/>.
/// All other points outside of the inner circle are "miss" points.
/// </summary>
private const float inner_portion = 0.8f;
/// <summary>
/// Number of rows/columns of points.
/// 4px per point @ 128x128 size (the contents of the <see cref="Heatmap"/> are always square). 1024 total points.
/// 4px per point @ 128x128 size (the contents of the <see cref="AccuracyHeatmap"/> are always square). 1024 total points.
/// </summary>
private const int points_per_dimension = 32;
@ -36,7 +37,7 @@ namespace osu.Game.Rulesets.Osu.Statistics
private readonly ScoreInfo score;
public Heatmap(ScoreInfo score)
public AccuracyHeatmap(ScoreInfo score)
{
this.score = score;
}
@ -170,7 +171,7 @@ namespace osu.Game.Rulesets.Osu.Statistics
// Convert the above into the local search space.
Vector2 localCentre = new Vector2(points_per_dimension) / 2;
float localRadius = localCentre.X * inner_portion * normalisedDistance; // The radius inside the inner portion which of the heatmap which the closest point lies.
double localAngle = finalAngle + 3 * Math.PI / 4; // The angle inside the heatmap on which the closest point lies.
double localAngle = finalAngle + Math.PI - MathUtils.DegreesToRadians(rotation); // The angle inside the heatmap on which the closest point lies.
Vector2 localPoint = localCentre + localRadius * new Vector2((float)Math.Cos(localAngle), (float)Math.Sin(localAngle));
// Find the most relevant hit point.