1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 12:17:26 +08:00

Merge pull request #27064 from smoogipoo/heatmap-misses

Display misses in the hit accuracy heatmap
This commit is contained in:
Bartłomiej Dach 2024-03-19 16:20:25 +01:00 committed by GitHub
commit 0180b25546
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 139 additions and 96 deletions

View File

@ -91,11 +91,11 @@ namespace osu.Game.Rulesets.Osu.Tests
var skinnable = firstObject.ApproachCircle; var skinnable = firstObject.ApproachCircle;
if (skin == null && skinnable?.Drawable is DefaultApproachCircle) if (skin == null && skinnable.Drawable is DefaultApproachCircle)
// check for default skin provider // check for default skin provider
return true; return true;
var text = skinnable?.Drawable as SpriteText; var text = skinnable.Drawable as SpriteText;
return text?.Text == skin; return text?.Text == skin;
}); });

View File

@ -95,12 +95,7 @@ namespace osu.Game.Rulesets.Osu.Mods
/// </summary> /// </summary>
private static void blockInputToObjectsUnderSliderHead(DrawableSliderHead slider) private static void blockInputToObjectsUnderSliderHead(DrawableSliderHead slider)
{ {
var oldHitAction = slider.HitArea.Hit; slider.HitArea.CanBeHit = () => !slider.DrawableSlider.AllJudged;
slider.HitArea.Hit = () =>
{
oldHitAction?.Invoke();
return !slider.DrawableSlider.AllJudged;
};
} }
private void applyEarlyFading(DrawableHitCircle circle) private void applyEarlyFading(DrawableHitCircle circle)

View File

@ -1,16 +1,12 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Input;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
@ -28,35 +24,30 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
{ {
public partial class DrawableHitCircle : DrawableOsuHitObject, IHasApproachCircle public partial class DrawableHitCircle : DrawableOsuHitObject, IHasApproachCircle
{ {
public OsuAction? HitAction => HitArea?.HitAction; public OsuAction? HitAction => HitArea.HitAction;
protected virtual OsuSkinComponents CirclePieceComponent => OsuSkinComponents.HitCircle; protected virtual OsuSkinComponents CirclePieceComponent => OsuSkinComponents.HitCircle;
public SkinnableDrawable ApproachCircle { get; private set; } public SkinnableDrawable ApproachCircle { get; private set; } = null!;
public HitReceptor HitArea { get; private set; } public HitReceptor HitArea { get; private set; } = null!;
public SkinnableDrawable CirclePiece { get; private set; } public SkinnableDrawable CirclePiece { get; private set; } = null!;
protected override IEnumerable<Drawable> DimmablePieces => new[] protected override IEnumerable<Drawable> DimmablePieces => new[] { CirclePiece };
{
CirclePiece,
};
Drawable IHasApproachCircle.ApproachCircle => ApproachCircle; Drawable IHasApproachCircle.ApproachCircle => ApproachCircle;
private Container scaleContainer; private Container scaleContainer = null!;
private InputManager inputManager; private ShakeContainer shakeContainer = null!;
public DrawableHitCircle() public DrawableHitCircle()
: this(null) : this(null)
{ {
} }
public DrawableHitCircle([CanBeNull] HitCircle h = null) public DrawableHitCircle(HitCircle? h = null)
: base(h) : base(h)
{ {
} }
private ShakeContainer shakeContainer;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
@ -73,14 +64,8 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
{ {
HitArea = new HitReceptor HitArea = new HitReceptor
{ {
Hit = () => CanBeHit = () => !AllJudged,
{ Hit = () => UpdateResult(true)
if (AllJudged)
return false;
UpdateResult(true);
return true;
},
}, },
shakeContainer = new ShakeContainer shakeContainer = new ShakeContainer
{ {
@ -114,13 +99,6 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
ScaleBindable.BindValueChanged(scale => scaleContainer.Scale = new Vector2(scale.NewValue)); ScaleBindable.BindValueChanged(scale => scaleContainer.Scale = new Vector2(scale.NewValue));
} }
protected override void LoadComplete()
{
base.LoadComplete();
inputManager = GetContainingInputManager();
}
public override double LifetimeStart public override double LifetimeStart
{ {
get => base.LifetimeStart; get => base.LifetimeStart;
@ -155,7 +133,15 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
if (!userTriggered) if (!userTriggered)
{ {
if (!HitObject.HitWindows.CanBeHit(timeOffset)) if (!HitObject.HitWindows.CanBeHit(timeOffset))
ApplyMinResult(); {
ApplyResult((r, position) =>
{
var circleResult = (OsuHitCircleJudgementResult)r;
circleResult.Type = r.Judgement.MinResult;
circleResult.CursorPositionAtHit = position;
}, computeHitPosition());
}
return; return;
} }
@ -169,22 +155,21 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
if (result == HitResult.None || clickAction != ClickAction.Hit) if (result == HitResult.None || clickAction != ClickAction.Hit)
return; return;
Vector2? hitPosition = null;
// Todo: This should also consider misses, but they're a little more interesting to handle, since we don't necessarily know the position at the time of a miss.
if (result.IsHit())
{
var localMousePosition = ToLocalSpace(inputManager.CurrentState.Mouse.Position);
hitPosition = HitObject.StackedPosition + (localMousePosition - DrawSize / 2);
}
ApplyResult<(HitResult result, Vector2? position)>((r, state) => ApplyResult<(HitResult result, Vector2? position)>((r, state) =>
{ {
var circleResult = (OsuHitCircleJudgementResult)r; var circleResult = (OsuHitCircleJudgementResult)r;
circleResult.Type = state.result; circleResult.Type = state.result;
circleResult.CursorPositionAtHit = state.position; circleResult.CursorPositionAtHit = state.position;
}, (result, hitPosition)); }, (result, computeHitPosition()));
}
private Vector2? computeHitPosition()
{
if (HitArea.ClosestPressPosition is Vector2 screenSpaceHitPosition)
return HitObject.StackedPosition + (ToLocalSpace(screenSpaceHitPosition) - DrawSize / 2);
return null;
} }
/// <summary> /// <summary>
@ -227,7 +212,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
break; break;
case ArmedState.Idle: case ArmedState.Idle:
HitArea.HitAction = null; HitArea.Reset();
break; break;
case ArmedState.Miss: case ArmedState.Miss:
@ -247,9 +232,25 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
// IsHovered is used // IsHovered is used
public override bool HandlePositionalInput => true; public override bool HandlePositionalInput => true;
public Func<bool> Hit; /// <summary>
/// Whether the hitobject can still be hit at the current point in time.
/// </summary>
public required Func<bool> CanBeHit { get; set; }
public OsuAction? HitAction; /// <summary>
/// An action that's invoked to perform the hit.
/// </summary>
public required Action Hit { get; set; }
/// <summary>
/// The <see cref="OsuAction"/> with which the hit was attempted.
/// </summary>
public OsuAction? HitAction { get; private set; }
/// <summary>
/// The closest position to the hit receptor at the point where the hit was attempted.
/// </summary>
public Vector2? ClosestPressPosition { get; private set; }
public HitReceptor() public HitReceptor()
{ {
@ -264,12 +265,27 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
public bool OnPressed(KeyBindingPressEvent<OsuAction> e) public bool OnPressed(KeyBindingPressEvent<OsuAction> e)
{ {
if (!CanBeHit())
return false;
switch (e.Action) switch (e.Action)
{ {
case OsuAction.LeftButton: case OsuAction.LeftButton:
case OsuAction.RightButton: case OsuAction.RightButton:
if (IsHovered && (Hit?.Invoke() ?? false)) if (ClosestPressPosition is Vector2 curClosest)
{ {
float oldDist = Vector2.DistanceSquared(curClosest, ScreenSpaceDrawQuad.Centre);
float newDist = Vector2.DistanceSquared(e.ScreenSpaceMousePosition, ScreenSpaceDrawQuad.Centre);
if (newDist < oldDist)
ClosestPressPosition = e.ScreenSpaceMousePosition;
}
else
ClosestPressPosition = e.ScreenSpaceMousePosition;
if (IsHovered)
{
Hit();
HitAction ??= e.Action; HitAction ??= e.Action;
return true; return true;
} }
@ -283,13 +299,22 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
public void OnReleased(KeyBindingReleaseEvent<OsuAction> e) public void OnReleased(KeyBindingReleaseEvent<OsuAction> e)
{ {
} }
/// <summary>
/// Resets to a fresh state.
/// </summary>
public void Reset()
{
HitAction = null;
ClosestPressPosition = null;
}
} }
private partial class ProxyableSkinnableDrawable : SkinnableDrawable private partial class ProxyableSkinnableDrawable : SkinnableDrawable
{ {
public override bool RemoveWhenNotAlive => false; public override bool RemoveWhenNotAlive => false;
public ProxyableSkinnableDrawable(ISkinComponentLookup lookup, Func<ISkinComponentLookup, Drawable> defaultImplementation = null, ConfineMode confineMode = ConfineMode.NoScaling) public ProxyableSkinnableDrawable(ISkinComponentLookup lookup, Func<ISkinComponentLookup, Drawable>? defaultImplementation = null, ConfineMode confineMode = ConfineMode.NoScaling)
: base(lookup, defaultImplementation, confineMode) : base(lookup, defaultImplementation, confineMode)
{ {
} }

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.Graphics.Sprites;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Graphics; using osu.Game.Graphics;
@ -191,16 +192,22 @@ namespace osu.Game.Rulesets.Osu.Statistics
for (int c = 0; c < points_per_dimension; c++) for (int c = 0; c < points_per_dimension; c++)
{ {
HitPointType pointType = Vector2.Distance(new Vector2(c + 0.5f, r + 0.5f), centre) <= innerRadius bool isHit = Vector2.Distance(new Vector2(c + 0.5f, r + 0.5f), centre) <= innerRadius;
? HitPointType.Hit
: HitPointType.Miss;
var point = new HitPoint(pointType, this) if (isHit)
{ {
BaseColour = pointType == HitPointType.Hit ? new Color4(102, 255, 204, 255) : new Color4(255, 102, 102, 255) points[r][c] = new HitPoint(this)
{
BaseColour = new Color4(102, 255, 204, 255)
}; };
}
points[r][c] = point; else
{
points[r][c] = new MissPoint
{
BaseColour = new Color4(255, 102, 102, 255)
};
}
} }
} }
@ -250,40 +257,31 @@ namespace osu.Game.Rulesets.Osu.Statistics
var rotatedCoordinate = -1 * new Vector2((float)Math.Cos(rotatedAngle), (float)Math.Sin(rotatedAngle)); var rotatedCoordinate = -1 * new Vector2((float)Math.Cos(rotatedAngle), (float)Math.Sin(rotatedAngle));
Vector2 localCentre = new Vector2(points_per_dimension - 1) / 2; Vector2 localCentre = new Vector2(points_per_dimension - 1) / 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;
Vector2 localPoint = localCentre + localRadius * rotatedCoordinate; Vector2 localPoint = localCentre + localRadius * rotatedCoordinate;
// Find the most relevant hit point. // Find the most relevant hit point.
int r = Math.Clamp((int)Math.Round(localPoint.Y), 0, points_per_dimension - 1); int r = (int)Math.Round(localPoint.Y);
int c = Math.Clamp((int)Math.Round(localPoint.X), 0, points_per_dimension - 1); int c = (int)Math.Round(localPoint.X);
PeakValue = Math.Max(PeakValue, ((HitPoint)pointGrid.Content[r][c]).Increment()); if (r < 0 || r >= points_per_dimension || c < 0 || c >= points_per_dimension)
return;
PeakValue = Math.Max(PeakValue, ((GridPoint)pointGrid.Content[r][c]).Increment());
bufferedGrid.ForceRedraw(); bufferedGrid.ForceRedraw();
} }
private partial class HitPoint : Circle private abstract partial class GridPoint : CompositeDrawable
{ {
/// <summary> /// <summary>
/// The base colour which will be lightened/darkened depending on the value of this <see cref="HitPoint"/>. /// The base colour which will be lightened/darkened depending on the value of this <see cref="HitPoint"/>.
/// </summary> /// </summary>
public Color4 BaseColour; public Color4 BaseColour;
private readonly HitPointType pointType; public override bool IsPresent => Count > 0;
private readonly AccuracyHeatmap heatmap;
public override bool IsPresent => count > 0; protected int Count { get; private set; }
public HitPoint(HitPointType pointType, AccuracyHeatmap heatmap)
{
this.pointType = pointType;
this.heatmap = heatmap;
RelativeSizeAxes = Axes.Both;
Alpha = 1;
}
private int count;
/// <summary> /// <summary>
/// Increment the value of this point by one. /// Increment the value of this point by one.
@ -291,7 +289,41 @@ namespace osu.Game.Rulesets.Osu.Statistics
/// <returns>The value after incrementing.</returns> /// <returns>The value after incrementing.</returns>
public int Increment() public int Increment()
{ {
return ++count; return ++Count;
}
}
private partial class MissPoint : GridPoint
{
public MissPoint()
{
RelativeSizeAxes = Axes.Both;
InternalChild = new SpriteIcon
{
RelativeSizeAxes = Axes.Both,
Icon = FontAwesome.Solid.Times
};
}
protected override void Update()
{
Alpha = 0.8f;
Colour = BaseColour;
}
}
private partial class HitPoint : GridPoint
{
private readonly AccuracyHeatmap heatmap;
public HitPoint(AccuracyHeatmap heatmap)
{
this.heatmap = heatmap;
RelativeSizeAxes = Axes.Both;
InternalChild = new Circle { RelativeSizeAxes = Axes.Both };
} }
protected override void Update() protected override void Update()
@ -307,10 +339,10 @@ namespace osu.Game.Rulesets.Osu.Statistics
float amount = 0; float amount = 0;
// give some amount of alpha regardless of relative count // give some amount of alpha regardless of relative count
amount += non_relative_portion * Math.Min(1, count / 10f); amount += non_relative_portion * Math.Min(1, Count / 10f);
// add relative portion // add relative portion
amount += (1 - non_relative_portion) * (count / heatmap.PeakValue); amount += (1 - non_relative_portion) * (Count / heatmap.PeakValue);
// apply easing // apply easing
amount = (float)Interpolation.ApplyEasing(Easing.OutQuint, Math.Min(1, amount)); amount = (float)Interpolation.ApplyEasing(Easing.OutQuint, Math.Min(1, amount));
@ -318,15 +350,8 @@ namespace osu.Game.Rulesets.Osu.Statistics
Debug.Assert(amount <= 1); Debug.Assert(amount <= 1);
Alpha = Math.Min(amount / lighten_cutoff, 1); Alpha = Math.Min(amount / lighten_cutoff, 1);
if (pointType == HitPointType.Hit)
Colour = BaseColour.Lighten(Math.Max(0, amount - lighten_cutoff)); Colour = BaseColour.Lighten(Math.Max(0, amount - lighten_cutoff));
} }
} }
private enum HitPointType
{
Hit,
Miss
}
} }
} }

View File

@ -4,7 +4,6 @@
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Description>click the circles. to the beat.</Description> <Description>click the circles. to the beat.</Description>
<LangVersion>10</LangVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Label="Nuget"> <PropertyGroup Label="Nuget">

View File

@ -3,7 +3,6 @@
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>10</LangVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Label="Nuget"> <PropertyGroup Label="Nuget">
<Title>osu!</Title> <Title>osu!</Title>