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.Input.Events;
using osu.Framework.Threading; using osu.Framework.Threading;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Statistics; using osu.Game.Rulesets.Osu.Statistics;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Tests.Beatmaps; using osu.Game.Tests.Beatmaps;
using osu.Game.Tests.Visual;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
namespace osu.Game.Tests.Visual.Ranking namespace osu.Game.Rulesets.Osu.Tests
{ {
public class TestSceneAccuracyHeatmap : OsuManualInputManagerTestScene public class TestSceneAccuracyHeatmap : OsuManualInputManagerTestScene
{ {
private Box background; private Box background;
private Drawable object1; private Drawable object1;
private Drawable object2; private Drawable object2;
private TestHeatmap heatmap; private TestAccuracyHeatmap accuracyHeatmap;
private ScheduledDelegate automaticAdditionDelegate; private ScheduledDelegate automaticAdditionDelegate;
[SetUp] [SetUp]
@ -48,7 +48,7 @@ namespace osu.Game.Tests.Visual.Ranking
{ {
Position = new Vector2(100, 300), 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, Anchor = Anchor.Centre,
Origin = 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)); 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). // 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)); InputManager.MoveMouseTo(background.ToScreenSpace(randomPos));
}, 1, true); }, 1, true);
}); });
@ -85,13 +85,13 @@ namespace osu.Game.Tests.Visual.Ranking
protected override bool OnMouseDown(MouseDownEvent e) 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; return true;
} }
private class TestHeatmap : Heatmap private class TestAccuracyHeatmap : AccuracyHeatmap
{ {
public TestHeatmap(ScoreInfo score) public TestAccuracyHeatmap(ScoreInfo score)
: base(score) : base(score)
{ {
} }

View File

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

View File

@ -9,6 +9,7 @@ using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Utils;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Scoring; using osu.Game.Scoring;
using osuTK; using osuTK;
@ -16,17 +17,17 @@ using osuTK.Graphics;
namespace osu.Game.Rulesets.Osu.Statistics namespace osu.Game.Rulesets.Osu.Statistics
{ {
public class Heatmap : CompositeDrawable public class AccuracyHeatmap : CompositeDrawable
{ {
/// <summary> /// <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. /// All other points outside of the inner circle are "miss" points.
/// </summary> /// </summary>
private const float inner_portion = 0.8f; private const float inner_portion = 0.8f;
/// <summary> /// <summary>
/// Number of rows/columns of points. /// 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> /// </summary>
private const int points_per_dimension = 32; private const int points_per_dimension = 32;
@ -36,7 +37,7 @@ namespace osu.Game.Rulesets.Osu.Statistics
private readonly ScoreInfo score; private readonly ScoreInfo score;
public Heatmap(ScoreInfo score) public AccuracyHeatmap(ScoreInfo score)
{ {
this.score = score; this.score = score;
} }
@ -170,7 +171,7 @@ namespace osu.Game.Rulesets.Osu.Statistics
// Convert the above into the local search space. // Convert the above into the local search space.
Vector2 localCentre = new Vector2(points_per_dimension) / 2; 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. 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)); Vector2 localPoint = localCentre + localRadius * new Vector2((float)Math.Cos(localAngle), (float)Math.Sin(localAngle));
// Find the most relevant hit point. // Find the most relevant hit point.