1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 05:52:55 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Difficulty/Preprocessing/OsuDifficultyHitObject.cs

200 lines
9.7 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
using System;
using System.Linq;
using osu.Game.Rulesets.Difficulty.Preprocessing;
using osu.Game.Rulesets.Objects;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets.Osu.Objects;
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
{
2021-09-25 11:02:33 +08:00
private const int normalized_radius = 50; // Change radius to 50 to make 100 the diameter. Easier for mental maths.
private const int min_delta_time = 25;
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-09-25 11:02:33 +08:00
/// Normalized distance from the end position of the previous <see cref="OsuDifficultyHitObject"/> to the start position of this <see cref="OsuDifficultyHitObject"/>.
2021-09-15 18:24:48 +08:00
/// </summary>
2021-09-25 11:02:33 +08:00
public double JumpDistance { get; private set; }
2021-09-15 18:24:48 +08:00
2018-04-13 17:19:50 +08:00
/// <summary>
2021-10-13 23:41:24 +08:00
/// Minimum distance from the end position of the previous <see cref="OsuDifficultyHitObject"/> to the start position of this <see cref="OsuDifficultyHitObject"/>.
2018-04-13 17:19:50 +08:00
/// </summary>
2021-10-13 23:41:24 +08:00
public double MovementDistance { get; private set; }
/// <summary>
2018-10-09 11:03:47 +08:00
/// Normalized distance between the start and end position of the previous <see cref="OsuDifficultyHitObject"/>.
/// </summary>
public double TravelDistance { get; private set; }
2018-04-13 17:19:50 +08:00
/// <summary>
/// Angle the player has to take to hit this <see cref="OsuDifficultyHitObject"/>.
/// Calculated as the angle between the circles (current-2, current-1, current).
2018-04-13 17:19:50 +08:00
/// </summary>
public double? Angle { get; private set; }
2018-04-13 17:19:50 +08:00
2021-10-13 23:41:24 +08:00
/// <summary>
/// Milliseconds elapsed since the end time of the Previous <see cref="OsuDifficultyHitObject"/>, with a minimum of 25ms.
/// </summary>
public double MovementTime { get; private set; }
/// <summary>
/// Milliseconds elapsed since from the start time of the Previous <see cref="OsuDifficultyHitObject"/> to the end time of the same Previous <see cref="OsuDifficultyHitObject"/>, with a minimum of 25ms.
/// </summary>
public double TravelTime { get; private set; }
2021-09-25 11:02:33 +08:00
/// <summary>
/// Milliseconds elapsed since the start time of the previous <see cref="OsuDifficultyHitObject"/>, with a minimum of 25ms.
2021-09-25 11:02:33 +08:00
/// </summary>
public readonly double StrainTime;
private readonly OsuHitObject lastLastObject;
private readonly OsuHitObject lastObject;
2018-04-13 17:19:50 +08:00
2019-02-19 16:43:12 +08:00
public OsuDifficultyHitObject(HitObject hitObject, HitObject lastLastObject, HitObject lastObject, double clockRate)
: base(hitObject, lastObject, clockRate)
2018-04-13 17:19:50 +08:00
{
this.lastLastObject = (OsuHitObject)lastLastObject;
this.lastObject = (OsuHitObject)lastObject;
2021-09-15 22:27:36 +08:00
// Capped to 25ms to prevent difficulty calculation breaking from simulatenous objects.
StrainTime = Math.Max(DeltaTime, min_delta_time);
2021-10-13 23:41:24 +08:00
setDistances(clockRate);
2018-04-13 17:19:50 +08:00
}
2021-10-13 23:41:24 +08:00
private void setDistances(double clockRate)
2018-04-13 17:19:50 +08:00
{
// 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 = normalized_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;
}
if (lastObject is Slider lastSlider)
{
computeSliderCursorPosition(lastSlider);
2021-10-22 00:08:35 +08:00
TravelDistance = 0;
TravelTime = Math.Max(lastSlider.LazyTravelTime / clockRate, min_delta_time);
2021-10-22 05:30:00 +08:00
MovementTime = Math.Max(StrainTime - lastSlider.LazyTravelTime / clockRate, min_delta_time);
2021-10-14 00:04:39 +08:00
MovementDistance = Vector2.Subtract(lastSlider.TailCircle.StackedPosition, BaseObject.StackedPosition).Length * scalingFactor;
2021-10-22 00:08:35 +08:00
int repeatCount = 0;
2021-10-22 00:08:35 +08:00
for (int i = 1; i < lastSlider.NestedHitObjects.Count; i++)
{
Vector2 currSlider = Vector2.Subtract(((OsuHitObject)lastSlider.NestedHitObjects[i]).StackedPosition, ((OsuHitObject)lastSlider.NestedHitObjects[i - 1]).StackedPosition);
if ((OsuHitObject)lastSlider.NestedHitObjects[i] is SliderRepeat && (OsuHitObject)lastSlider.NestedHitObjects[i - 1] is SliderRepeat)
{
repeatCount++;
TravelDistance += Math.Max(0, currSlider.Length * scalingFactor - 240); // remove 240 distance to avoid buffing overlapping followcircles.
}
else if ((OsuHitObject)lastSlider.NestedHitObjects[i] is SliderRepeat)
{
repeatCount++;
TravelDistance += Math.Max(0, currSlider.Length * scalingFactor - 120); // remove 120 distance to avoid buffing overlapping followcircles.
}
2021-10-23 01:17:19 +08:00
else if ((OsuHitObject)lastSlider.NestedHitObjects[i] is SliderEndCircle)
{
Vector2 possSlider = Vector2.Subtract((Vector2)lastSlider.LazyEndPosition, ((OsuHitObject)lastSlider.NestedHitObjects[i - 1]).StackedPosition);
TravelDistance += Math.Min(possSlider.Length, currSlider.Length) * scalingFactor; // Take the least distance from slider end vs lazy end.
}
2021-10-22 00:08:35 +08:00
else
TravelDistance += Math.Max(0, currSlider.Length * scalingFactor - 100); // remove 100 distance to avoid buffing overlapping ticks, mostly needed to prevent buffing slow sliders with high tick rate.
}
2021-10-22 00:08:35 +08:00
if (repeatCount == 0)
{
TravelDistance = Math.Max(TravelDistance, scalingFactor * // idea here is to prevent ticks from dropping difficulty of slider by removing distance in calculation.
Math.Min(Vector2.Subtract(((OsuHitObject)lastSlider.NestedHitObjects[lastSlider.NestedHitObjects.Count - 1]).StackedPosition, ((OsuHitObject)lastSlider.NestedHitObjects[0]).StackedPosition).Length,
Vector2.Subtract((Vector2)lastSlider.LazyEndPosition, ((OsuHitObject)lastSlider.NestedHitObjects[0]).StackedPosition).Length));
2021-10-22 00:08:35 +08:00
}
else
TravelDistance *= Math.Pow(1 + repeatCount / 2.0, 1.0 / 2.0); // Bonus for repeat sliders until a better per nested object strain system can be achieved.
}
Vector2 lastCursorPosition = getEndCursorPosition(lastObject);
2018-04-13 17:19:50 +08:00
JumpDistance = (BaseObject.StackedPosition * scalingFactor - lastCursorPosition * scalingFactor).Length;
2021-10-23 01:17:19 +08:00
MovementDistance = Math.Max(0, Math.Min(JumpDistance - 50, MovementDistance - 120)); // radius for jumpdistance is within 50 of maximum possible sliderLeniency, 120 for movement distance.
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
2018-10-11 12:53:29 +08:00
slider.LazyEndPosition = slider.StackedPosition;
2018-04-13 17:19:50 +08:00
2021-10-23 01:17:19 +08:00
float approxFollowCircleRadius = (float)(slider.Radius * 1.4); // using 1.4 to better follow the real movement of a cursor.
2018-04-13 17:19:50 +08:00
var computeVertex = new Action<double>(t =>
{
double progress = (t - slider.StartTime) / slider.SpanDuration;
if (progress % 2 >= 1)
2018-10-08 17:37:30 +08:00
progress = 1 - progress % 1;
else
2019-11-12 17:56:38 +08:00
progress %= 1;
2018-10-08 17:37:30 +08:00
2018-04-13 17:19:50 +08:00
// ReSharper disable once PossibleInvalidOperationException (bugged in current r# version)
var diff = slider.StackedPosition + slider.Path.PositionAt(progress) - slider.LazyEndPosition.Value;
2018-04-13 17:19:50 +08:00
float dist = diff.Length;
2021-10-13 23:41:24 +08:00
slider.LazyTravelTime = t - slider.StartTime;
2021-10-23 01:17:19 +08:00
if (dist > approxFollowCircleRadius)
2018-04-13 17:19:50 +08:00
{
// The cursor would be outside the follow circle, we need to move it
diff.Normalize(); // Obtain direction of diff
2021-10-23 01:17:19 +08:00
dist -= approxFollowCircleRadius;
2018-04-13 17:19:50 +08:00
slider.LazyEndPosition += diff * dist;
slider.LazyTravelDistance += dist;
}
});
// Skip the head circle
var scoringTimes = slider.NestedHitObjects.Skip(1).Select(t => t.StartTime);
2018-04-13 17:19:50 +08:00
foreach (var time in scoringTimes)
computeVertex(time);
}
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
}
}