1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-26 10:12:54 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Difficulty/Preprocessing/OsuDifficultyHitObject.cs

287 lines
14 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
2022-06-17 15:37:17 +08:00
#nullable disable
2018-04-13 17:19:50 +08:00
using System;
using System.Collections.Generic;
using osu.Game.Rulesets.Difficulty.Preprocessing;
using osu.Game.Rulesets.Objects;
2022-05-12 16:19:07 +08:00
using osu.Game.Rulesets.Osu.Mods;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Scoring;
2018-11-20 15:51:59 +08:00
using osuTK;
2018-04-13 17:19:50 +08:00
2018-05-15 16:36:29 +08:00
namespace osu.Game.Rulesets.Osu.Difficulty.Preprocessing
2018-04-13 17:19:50 +08:00
{
public class OsuDifficultyHitObject : DifficultyHitObject
2018-04-13 17:19:50 +08:00
{
/// <summary>
/// A distance by which all distances should be scaled in order to assume a uniform circle size.
/// </summary>
public const int NORMALISED_RADIUS = 50; // Change radius to 50 to make 100 the diameter. Easier for mental maths.
private const int min_delta_time = 25;
private const float maximum_slider_radius = NORMALISED_RADIUS * 2.4f;
private const float assumed_slider_radius = NORMALISED_RADIUS * 1.8f;
2018-05-15 20:44:45 +08:00
protected new OsuHitObject BaseObject => (OsuHitObject)base.BaseObject;
2018-04-13 17:19:50 +08:00
2021-09-15 18:24:48 +08:00
/// <summary>
2021-11-24 11:14:52 +08:00
/// Milliseconds elapsed since the start time of the previous <see cref="OsuDifficultyHitObject"/>, with a minimum of 25ms.
2021-09-15 18:24:48 +08:00
/// </summary>
2021-11-24 11:14:52 +08:00
public readonly double StrainTime;
2021-09-15 18:24:48 +08:00
2018-04-13 17:19:50 +08:00
/// <summary>
2021-12-07 22:14:35 +08:00
/// Normalised distance from the "lazy" end position of the previous <see cref="OsuDifficultyHitObject"/> to the start position of this <see cref="OsuDifficultyHitObject"/>.
/// <para>
/// The "lazy" end position is the position at which the cursor ends up if the previous hitobject is followed with as minimal movement as possible (i.e. on the edge of slider follow circles).
/// </para>
2018-04-13 17:19:50 +08:00
/// </summary>
2021-12-07 22:14:35 +08:00
public double LazyJumpDistance { get; private set; }
/// <summary>
2021-12-07 22:14:35 +08:00
/// Normalised shortest distance to consider for a jump between the previous <see cref="OsuDifficultyHitObject"/> and this <see cref="OsuDifficultyHitObject"/>.
/// </summary>
2021-11-24 12:11:44 +08:00
/// <remarks>
2021-12-07 22:14:35 +08:00
/// This is bounded from above by <see cref="LazyJumpDistance"/>, and is smaller than the former if a more natural path is able to be taken through the previous <see cref="OsuDifficultyHitObject"/>.
2021-11-24 12:11:44 +08:00
/// </remarks>
2021-12-07 22:14:35 +08:00
/// <example>
/// Suppose a linear slider - circle pattern.
/// <br />
/// Following the slider lazily (see: <see cref="LazyJumpDistance"/>) will result in underestimating the true end position of the slider as being closer towards the start position.
/// As a result, <see cref="LazyJumpDistance"/> overestimates the jump distance because the player is able to take a more natural path by following through the slider to its end,
/// such that the jump is felt as only starting from the slider's true end position.
/// <br />
/// Now consider a slider - circle pattern where the circle is stacked along the path inside the slider.
/// In this case, the lazy end position correctly estimates the true end position of the slider and provides the more natural movement path.
/// </example>
public double MinimumJumpDistance { get; private set; }
2018-04-13 17:19:50 +08:00
/// <summary>
2021-12-07 22:14:35 +08:00
/// The time taken to travel through <see cref="MinimumJumpDistance"/>, with a minimum value of 25ms.
2018-04-13 17:19:50 +08:00
/// </summary>
2021-12-07 22:14:35 +08:00
public double MinimumJumpTime { get; private set; }
2018-04-13 17:19:50 +08:00
2021-10-13 23:41:24 +08:00
/// <summary>
2021-11-24 12:01:53 +08:00
/// Normalised distance between the start and end position of this <see cref="OsuDifficultyHitObject"/>.
2021-10-13 23:41:24 +08:00
/// </summary>
2021-11-24 11:14:52 +08:00
public double TravelDistance { get; private set; }
2021-10-13 23:41:24 +08:00
/// <summary>
2022-05-25 12:01:12 +08:00
/// The time taken to travel through <see cref="TravelDistance"/>, with a minimum value of 25ms for <see cref="Slider"/> objects.
2021-10-13 23:41:24 +08:00
/// </summary>
public double TravelTime { get; private set; }
2021-09-25 11:02:33 +08:00
/// <summary>
2021-11-24 11:14:52 +08:00
/// Angle the player has to take to hit this <see cref="OsuDifficultyHitObject"/>.
/// Calculated as the angle between the circles (current-2, current-1, current).
2021-09-25 11:02:33 +08:00
/// </summary>
2021-11-24 11:14:52 +08:00
public double? Angle { get; private set; }
2021-09-25 11:02:33 +08:00
/// <summary>
/// Retrieves the full hit window for a Great <see cref="HitResult"/>.
/// </summary>
public double HitWindowGreat { get; private set; }
private readonly OsuHitObject lastLastObject;
private readonly OsuHitObject lastObject;
2018-04-13 17:19:50 +08:00
public OsuDifficultyHitObject(HitObject hitObject, HitObject lastObject, HitObject lastLastObject, double clockRate, List<DifficultyHitObject> objects, int index)
2022-06-09 17:49:11 +08:00
: base(hitObject, lastObject, clockRate, objects, index)
2018-04-13 17:19:50 +08:00
{
this.lastLastObject = (OsuHitObject)lastLastObject;
this.lastObject = (OsuHitObject)lastObject;
2021-11-02 22:47:20 +08:00
// Capped to 25ms to prevent difficulty calculation breaking from simultaneous objects.
StrainTime = Math.Max(DeltaTime, min_delta_time);
2021-10-13 23:41:24 +08:00
if (BaseObject is Slider sliderObject)
{
HitWindowGreat = 2 * sliderObject.HeadCircle.HitWindows.WindowFor(HitResult.Great) / clockRate;
}
else
{
HitWindowGreat = 2 * BaseObject.HitWindows.WindowFor(HitResult.Great) / clockRate;
}
2021-10-13 23:41:24 +08:00
setDistances(clockRate);
2018-04-13 17:19:50 +08:00
}
2022-05-12 16:19:07 +08:00
public double OpacityAt(double time, bool hidden)
{
2022-05-12 16:19:07 +08:00
if (time > BaseObject.StartTime)
{
// Consider a hitobject as being invisible when its start time is passed.
// In reality the hitobject will be visible beyond its start time up until its hittable window has passed,
// but this is an approximation and such a case is unlikely to be hit where this function is used.
return 0.0;
2022-05-12 16:19:07 +08:00
}
2021-11-30 10:54:41 +08:00
2022-05-12 16:19:07 +08:00
double fadeInStartTime = BaseObject.StartTime - BaseObject.TimePreempt;
double fadeInDuration = BaseObject.TimeFadeIn;
2021-11-21 20:53:40 +08:00
if (hidden)
2022-05-12 16:19:07 +08:00
{
// Taken from OsuModHidden.
double fadeOutStartTime = BaseObject.StartTime - BaseObject.TimePreempt + BaseObject.TimeFadeIn;
double fadeOutDuration = BaseObject.TimePreempt * OsuModHidden.FADE_OUT_DURATION_MULTIPLIER;
return Math.Min
(
Math.Clamp((time - fadeInStartTime) / fadeInDuration, 0.0, 1.0),
1.0 - Math.Clamp((time - fadeOutStartTime) / fadeOutDuration, 0.0, 1.0)
);
}
return Math.Clamp((time - fadeInStartTime) / fadeInDuration, 0.0, 1.0);
}
2021-10-13 23:41:24 +08:00
private void setDistances(double clockRate)
2018-04-13 17:19:50 +08:00
{
if (BaseObject is Slider currentSlider)
{
computeSliderCursorPosition(currentSlider);
2022-07-23 12:40:16 +08:00
// Bonus for repeat sliders until a better per nested object strain system can be achieved.
TravelDistance = currentSlider.LazyTravelDistance * (float)Math.Pow(1 + currentSlider.RepeatCount / 2.5, 1.0 / 2.5);
TravelTime = Math.Max(currentSlider.LazyTravelTime / clockRate, min_delta_time);
}
// We don't need to calculate either angle or distance when one of the last->curr objects is a spinner
if (BaseObject is Spinner || lastObject is Spinner)
return;
2018-04-13 17:19:50 +08:00
// We will scale distances by this factor, so we can assume a uniform CircleSize among beatmaps.
float scalingFactor = NORMALISED_RADIUS / (float)BaseObject.Radius;
2019-04-01 11:16:05 +08:00
2018-04-13 17:19:50 +08:00
if (BaseObject.Radius < 30)
{
2018-12-21 21:52:27 +08:00
float smallCircleBonus = Math.Min(30 - (float)BaseObject.Radius, 5) / 50;
2018-04-13 17:19:50 +08:00
scalingFactor *= 1 + smallCircleBonus;
}
Vector2 lastCursorPosition = getEndCursorPosition(lastObject);
2021-12-07 22:14:35 +08:00
LazyJumpDistance = (BaseObject.StackedPosition * scalingFactor - lastCursorPosition * scalingFactor).Length;
MinimumJumpTime = StrainTime;
MinimumJumpDistance = LazyJumpDistance;
if (lastObject is Slider lastSlider)
{
double lastTravelTime = Math.Max(lastSlider.LazyTravelTime / clockRate, min_delta_time);
2021-12-07 22:14:35 +08:00
MinimumJumpTime = Math.Max(StrainTime - lastTravelTime, min_delta_time);
//
// There are two types of slider-to-object patterns to consider in order to better approximate the real movement a player will take to jump between the hitobjects.
//
2021-12-08 14:52:59 +08:00
// 1. The anti-flow pattern, where players cut the slider short in order to move to the next hitobject.
//
2021-12-08 14:52:59 +08:00
// <======o==> ← slider
// | ← most natural jump path
// o ← a follow-up hitcircle
//
// In this case the most natural jump path is approximated by LazyJumpDistance.
//
2021-12-08 14:52:59 +08:00
// 2. The flow pattern, where players follow through the slider to its visual extent into the next hitobject.
2021-11-24 12:22:52 +08:00
//
2021-12-08 14:52:59 +08:00
// <======o==>---o
// ↑
// most natural jump path
//
// In this case the most natural jump path is better approximated by a new distance called "tailJumpDistance" - the distance between the slider's tail and the next hitobject.
2021-12-08 14:52:59 +08:00
//
// Thus, the player is assumed to jump the minimum of these two distances in all cases.
//
float tailJumpDistance = Vector2.Subtract(lastSlider.TailCircle.StackedPosition, BaseObject.StackedPosition).Length * scalingFactor;
2021-12-07 22:14:35 +08:00
MinimumJumpDistance = Math.Max(0, Math.Min(LazyJumpDistance - (maximum_slider_radius - assumed_slider_radius), tailJumpDistance - maximum_slider_radius));
}
2018-12-08 14:01:26 +08:00
if (lastLastObject != null && !(lastLastObject is Spinner))
2018-12-08 14:01:26 +08:00
{
Vector2 lastLastCursorPosition = getEndCursorPosition(lastLastObject);
2018-12-08 14:01:26 +08:00
Vector2 v1 = lastLastCursorPosition - lastObject.StackedPosition;
Vector2 v2 = BaseObject.StackedPosition - lastCursorPosition;
2018-12-08 14:01:26 +08:00
float dot = Vector2.Dot(v1, v2);
float det = v1.X * v2.Y - v1.Y * v2.X;
2018-12-09 19:31:04 +08:00
Angle = Math.Abs(Math.Atan2(det, dot));
2018-12-08 14:01:26 +08:00
}
2018-04-13 17:19:50 +08:00
}
private void computeSliderCursorPosition(Slider slider)
{
if (slider.LazyEndPosition != null)
return;
2019-02-28 12:31:40 +08:00
2021-11-07 03:42:54 +08:00
slider.LazyTravelTime = slider.NestedHitObjects[^1].StartTime - slider.StartTime;
2018-04-13 17:19:50 +08:00
double endTimeMin = slider.LazyTravelTime / slider.SpanDuration;
2021-11-07 03:42:54 +08:00
if (endTimeMin % 2 >= 1)
endTimeMin = 1 - endTimeMin % 1;
else
endTimeMin %= 1;
slider.LazyEndPosition = slider.StackedPosition + slider.Path.PositionAt(endTimeMin); // temporary lazy end position until a real result can be derived.
var currCursorPosition = slider.StackedPosition;
double scalingFactor = NORMALISED_RADIUS / slider.Radius; // lazySliderDistance is coded to be sensitive to scaling, this makes the maths easier with the thresholds being used.
for (int i = 1; i < slider.NestedHitObjects.Count; i++)
{
var currMovementObj = (OsuHitObject)slider.NestedHitObjects[i];
Vector2 currMovement = Vector2.Subtract(currMovementObj.StackedPosition, currCursorPosition);
double currMovementLength = scalingFactor * currMovement.Length;
2021-11-07 22:26:13 +08:00
// Amount of movement required so that the cursor position needs to be updated.
double requiredMovement = assumed_slider_radius;
2018-10-08 17:37:30 +08:00
if (i == slider.NestedHitObjects.Count - 1)
{
// The end of a slider has special aim rules due to the relaxed time constraint on position.
// There is both a lazy end position as well as the actual end slider position. We assume the player takes the simpler movement.
// For sliders that are circular, the lazy end position may actually be farther away than the sliders true end.
// This code is designed to prevent buffing situations where lazy end is actually a less efficient movement.
Vector2 lazyMovement = Vector2.Subtract((Vector2)slider.LazyEndPosition, currCursorPosition);
if (lazyMovement.Length < currMovement.Length)
currMovement = lazyMovement;
2018-04-13 17:19:50 +08:00
currMovementLength = scalingFactor * currMovement.Length;
}
else if (currMovementObj is SliderRepeat)
2021-11-07 22:26:13 +08:00
{
// For a slider repeat, assume a tighter movement threshold to better assess repeat sliders.
requiredMovement = NORMALISED_RADIUS;
2021-11-07 22:26:13 +08:00
}
2021-11-07 22:26:13 +08:00
if (currMovementLength > requiredMovement)
2018-04-13 17:19:50 +08:00
{
// this finds the positional delta from the required radius and the current position, and updates the currCursorPosition accordingly, as well as rewarding distance.
2021-11-07 22:26:13 +08:00
currCursorPosition = Vector2.Add(currCursorPosition, Vector2.Multiply(currMovement, (float)((currMovementLength - requiredMovement) / currMovementLength)));
currMovementLength *= (currMovementLength - requiredMovement) / currMovementLength;
slider.LazyTravelDistance += (float)currMovementLength;
2018-04-13 17:19:50 +08:00
}
if (i == slider.NestedHitObjects.Count - 1)
slider.LazyEndPosition = currCursorPosition;
}
2018-04-13 17:19:50 +08:00
}
private Vector2 getEndCursorPosition(OsuHitObject hitObject)
{
Vector2 pos = hitObject.StackedPosition;
2019-02-28 13:35:00 +08:00
if (hitObject is Slider slider)
{
computeSliderCursorPosition(slider);
pos = slider.LazyEndPosition ?? pos;
}
return pos;
}
2018-04-13 17:19:50 +08:00
}
}