osu/osu.Game.Rulesets.Osu/Difficulty/Preprocessing/OsuDifficultyHitObject.cs

142 lines
5.4 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 09:19:50 +00:00
using System;
using System.Linq;
using osu.Game.Rulesets.Difficulty.Preprocessing;
using osu.Game.Rulesets.Objects;
2018-04-13 09:19:50 +00:00
using osu.Game.Rulesets.Osu.Objects;
2018-11-20 07:51:59 +00:00
using osuTK;
2018-04-13 09:19:50 +00:00
2018-05-15 08:36:29 +00:00
namespace osu.Game.Rulesets.Osu.Difficulty.Preprocessing
2018-04-13 09:19:50 +00:00
{
public class OsuDifficultyHitObject : DifficultyHitObject
2018-04-13 09:19:50 +00:00
{
2018-05-15 12:44:45 +00:00
private const int normalized_radius = 52;
protected new OsuHitObject BaseObject => (OsuHitObject)base.BaseObject;
2018-04-13 09:19:50 +00:00
/// <summary>
2018-10-09 03:03:47 +00:00
/// Normalized distance from the end position of the previous <see cref="OsuDifficultyHitObject"/> to the start position of this <see cref="OsuDifficultyHitObject"/>.
2018-04-13 09:19:50 +00:00
/// </summary>
public double JumpDistance { get; private set; }
/// <summary>
2018-10-09 03:03:47 +00: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 09:19:50 +00: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 09:19:50 +00:00
/// </summary>
public double? Angle { get; private set; }
2018-04-13 09:19:50 +00:00
/// <summary>
/// Milliseconds elapsed since the start time of the previous <see cref="OsuDifficultyHitObject"/>, with a minimum of 50ms.
/// </summary>
public readonly double StrainTime;
2018-12-08 06:01:26 +00:00
private readonly OsuHitObject lastLastObject;
private readonly OsuHitObject lastObject;
2018-04-13 09:19:50 +00:00
2019-02-19 08:43:12 +00:00
public OsuDifficultyHitObject(HitObject hitObject, HitObject lastLastObject, HitObject lastObject, double clockRate)
: base(hitObject, lastObject, clockRate)
2018-04-13 09:19:50 +00:00
{
this.lastLastObject = (OsuHitObject)lastLastObject;
this.lastObject = (OsuHitObject)lastObject;
2018-04-13 09:19:50 +00:00
setDistances();
// Every strain interval is hard capped at the equivalent of 375 BPM streaming speed as a safety measure
StrainTime = Math.Max(50, DeltaTime);
2018-04-13 09:19:50 +00:00
}
private void setDistances()
{
// 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 03:16:05 +00:00
2018-04-13 09:19:50 +00:00
if (BaseObject.Radius < 30)
{
2018-12-21 13:52:27 +00:00
float smallCircleBonus = Math.Min(30 - (float)BaseObject.Radius, 5) / 50;
2018-04-13 09:19:50 +00:00
scalingFactor *= 1 + smallCircleBonus;
}
if (lastObject is Slider lastSlider)
{
computeSliderCursorPosition(lastSlider);
TravelDistance = lastSlider.LazyTravelDistance * scalingFactor;
}
Vector2 lastCursorPosition = getEndCursorPosition(lastObject);
2018-04-13 09:19:50 +00:00
// Don't need to jump to reach spinners
if (!(BaseObject is Spinner))
2018-10-10 09:08:46 +00:00
JumpDistance = (BaseObject.StackedPosition * scalingFactor - lastCursorPosition * scalingFactor).Length;
2018-12-08 06:01:26 +00:00
if (lastLastObject != null)
2018-12-08 06:01:26 +00:00
{
Vector2 lastLastCursorPosition = getEndCursorPosition(lastLastObject);
2018-12-08 06:01:26 +00:00
Vector2 v1 = lastLastCursorPosition - lastObject.StackedPosition;
Vector2 v2 = BaseObject.StackedPosition - lastCursorPosition;
2018-12-08 06:01:26 +00:00
float dot = Vector2.Dot(v1, v2);
float det = v1.X * v2.Y - v1.Y * v2.X;
2018-12-09 11:31:04 +00:00
Angle = Math.Abs(Math.Atan2(det, dot));
2018-12-08 06:01:26 +00:00
}
2018-04-13 09:19:50 +00:00
}
private void computeSliderCursorPosition(Slider slider)
{
if (slider.LazyEndPosition != null)
return;
2019-02-28 04:31:40 +00:00
2018-10-11 04:53:29 +00:00
slider.LazyEndPosition = slider.StackedPosition;
2018-04-13 09:19:50 +00:00
float approxFollowCircleRadius = (float)(slider.Radius * 3);
var computeVertex = new Action<double>(t =>
{
double progress = (t - slider.StartTime) / slider.SpanDuration;
if (progress % 2 >= 1)
2018-10-08 09:37:30 +00:00
progress = 1 - progress % 1;
else
2019-11-12 09:56:38 +00:00
progress %= 1;
2018-10-08 09:37:30 +00:00
2018-04-13 09:19:50 +00:00
// ReSharper disable once PossibleInvalidOperationException (bugged in current r# version)
var diff = slider.StackedPosition + slider.Path.PositionAt(progress) - slider.LazyEndPosition.Value;
2018-04-13 09:19:50 +00:00
float dist = diff.Length;
if (dist > approxFollowCircleRadius)
{
// The cursor would be outside the follow circle, we need to move it
diff.Normalize(); // Obtain direction of diff
dist -= approxFollowCircleRadius;
slider.LazyEndPosition += diff * dist;
slider.LazyTravelDistance += dist;
}
});
// Skip the head circle
var scoringTimes = slider.NestedHitObjects.Skip(1).Select(t => t.StartTime);
2018-04-13 09:19:50 +00:00
foreach (var time in scoringTimes)
computeVertex(time);
}
private Vector2 getEndCursorPosition(OsuHitObject hitObject)
{
Vector2 pos = hitObject.StackedPosition;
2019-02-28 05:35:00 +00:00
if (hitObject is Slider slider)
{
computeSliderCursorPosition(slider);
pos = slider.LazyEndPosition ?? pos;
}
return pos;
}
2018-04-13 09:19:50 +00:00
}
}