diff --git a/osu.Game.Rulesets.Osu/Difficulty/Preprocessing/OsuDifficultyHitObject.cs b/osu.Game.Rulesets.Osu/Difficulty/Preprocessing/OsuDifficultyHitObject.cs index b1de132aa7..92b50412d9 100644 --- a/osu.Game.Rulesets.Osu/Difficulty/Preprocessing/OsuDifficultyHitObject.cs +++ b/osu.Game.Rulesets.Osu/Difficulty/Preprocessing/OsuDifficultyHitObject.cs @@ -14,7 +14,8 @@ namespace osu.Game.Rulesets.Osu.Difficulty.Preprocessing { 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; - private const int minimum_slider_radius = normalized_radius * 2.4; + private const float maximum_slider_radius = normalized_radius * 2.4f; + private const float assumed_slider_radius = normalized_radius * 1.6f; protected new OsuHitObject BaseObject => (OsuHitObject)base.BaseObject; @@ -90,63 +91,9 @@ namespace osu.Game.Rulesets.Osu.Difficulty.Preprocessing if (lastObject is Slider lastSlider) { computeSliderCursorPosition(lastSlider); - TravelDistance = 0; + TravelDistance = lastSlider.LazyTravelDistance; TravelTime = Math.Max(lastSlider.LazyTravelTime / clockRate, min_delta_time); MovementTime = Math.Max(StrainTime - TravelTime, min_delta_time); - MovementDistance = Vector2.Subtract(lastSlider.TailCircle.StackedPosition, BaseObject.StackedPosition).Length * scalingFactor; - - int repeatCount = 0; - - Vector2 currSliderPosition = ((OsuHitObject)lastSlider.NestedHitObjects[0]).StackedPosition; - - for (int i = 1; i < lastSlider.NestedHitObjects.Count; i++) - { - var currSliderObj = (OsuHitObject)lastSlider.NestedHitObjects[i]; - - Vector2 currSlider = Vector2.Subtract(currSliderObj.StackedPosition, currSliderPosition); - double currSliderLength = currSlider.Length * scalingFactor; - - if (currSliderObj is SliderEndCircle && !(currSliderObj is SliderRepeat)) - { - Vector2 lazySlider = Vector2.Subtract((Vector2)lastSlider.LazyEndPosition, currSliderPosition); - if (lazySlider.Length < currSlider.Length) - currSlider = lazySlider; // Take the least distance from slider end vs lazy end. - - currSliderLength = currSlider.Length * scalingFactor; - } - - if (currSliderObj is SliderTick) - { - if (currSliderLength > minimum_slider_radius) // minimum_slider_radius is used here as 120 = 2.4 * radius, which means that the cursor assumes the position of least movement required to reach the active tick window. - { - currSliderPosition = Vector2.Add(currSliderPosition, Vector2.Multiply(currSlider, (float)((currSliderLength - minimum_slider_radius) / currSliderLength))); - currSliderLength *= (currSliderLength - minimum_slider_radius) / currSliderLength; - } - else - currSliderLength = 0; - } - else if (currSliderObj is SliderRepeat) - { - if (currSliderLength > normalized_radius) // normalized_radius is used here as 50 = radius. This is a way to reward motion of back and forths sliders where we assume the player moves to atleast the rim of the hitcircle. - { - currSliderPosition = Vector2.Add(currSliderPosition, Vector2.Multiply(currSlider, (float)((currSliderLength - normalized_radius) / currSliderLength))); - currSliderLength *= (currSliderLength - normalized_radius) / currSliderLength; - } - else - currSliderLength = 0; - } - else - { - currSliderPosition = Vector2.Add(currSliderPosition, currSlider); - } - - if (currSliderObj is SliderRepeat) - repeatCount++; - - TravelDistance += currSliderLength; - } - - TravelDistance *= Math.Pow(1 + repeatCount / 2.5, 1.0 / 2.5); // Bonus for repeat sliders until a better per nested object strain system can be achieved. // Jump distance from the slider tail to the next object, as opposed to the lazy position of JumpDistance. float tailJumpDistance = Vector2.Subtract(lastSlider.TailCircle.StackedPosition, BaseObject.StackedPosition).Length * scalingFactor; @@ -155,8 +102,8 @@ namespace osu.Game.Rulesets.Osu.Difficulty.Preprocessing // such that they're not jumping from the lazy position but rather from very close to (or the end of) the slider. // In such cases, a leniency is applied by also considering the jump distance from the tail of the slider, and taking the minimum jump distance. // Additional distance is removed based on position of jump relative to slider follow circle radius. - // JumpDistance is normalized_radius because lazyCursorPos uses a tighter 1.4 followCircle. tailJumpDistance is minimum_slider_radius since the full distance of radial leniency is still possible. - MovementDistance = Math.Max(0, Math.Min(JumpDistance - normalized_radius, tailJumpDistance - 120)); + // JumpDistance is the distance beyond the s. tailJumpDistance is maximum_slider_radius since the full distance of radial leniency is still possible. + MovementDistance = Math.Max(0, Math.Min(JumpDistance - (maximum_slider_radius - assumed_slider_radius), tailJumpDistance - maximum_slider_radius)); } else { @@ -183,37 +130,64 @@ namespace osu.Game.Rulesets.Osu.Difficulty.Preprocessing if (slider.LazyEndPosition != null) return; - slider.LazyEndPosition = slider.StackedPosition; + slider.LazyTravelTime = slider.NestedHitObjects[slider.NestedHitObjects.Count - 1].StartTime - slider.StartTime; - float approxFollowCircleRadius = (float)(slider.Radius * 1.4); // using 1.4 to better follow the real movement of a cursor. - var computeVertex = new Action(t => - { - double progress = (t - slider.StartTime) / slider.SpanDuration; - if (progress % 2 >= 1) - progress = 1 - progress % 1; + double endTimeMin = slider.LazyTravelTime / slider.SpanDuration; + if (endTimeMin % 2 >= 1) + endTimeMin = 1 - endTimeMin % 1; else - progress %= 1; + endTimeMin %= 1; - // ReSharper disable once PossibleInvalidOperationException (bugged in current r# version) - var diff = slider.StackedPosition + slider.Path.PositionAt(progress) - slider.LazyEndPosition.Value; - float dist = diff.Length; + 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 = normalized_radius / slider.Radius; // lazySliderDistance is coded to be sensitive to scaling, this makes the maths easier with the thresholds being used. - slider.LazyTravelTime = t - slider.StartTime; + for (int i = 1; i < slider.NestedHitObjects.Count; i++) + { + var currMovementObj = (OsuHitObject)slider.NestedHitObjects[i]; - if (dist > approxFollowCircleRadius) + Vector2 currMovement = Vector2.Subtract(currMovementObj.StackedPosition, currCursorPosition); + double currMovementLength = scalingFactor * currMovement.Length; + + if (i == slider.NestedHitObjects.Count - 1) { - // 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; - } - }); + // 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); - // Skip the head circle - var scoringTimes = slider.NestedHitObjects.Skip(1).Select(t => t.StartTime); - foreach (double time in scoringTimes) - computeVertex(time); + if (lazyMovement.Length < currMovement.Length) + currMovement = lazyMovement; + + currMovementLength = scalingFactor * currMovement.Length; + + if (currMovementLength > assumed_slider_radius) + { + // Calculate the vector movement, regardless of final location to get the true lazy end position. + currCursorPosition = Vector2.Add(currCursorPosition, Vector2.Multiply(currMovement, (float)((currMovementLength - assumed_slider_radius) / currMovementLength))); + currMovementLength *= (currMovementLength - assumed_slider_radius) / currMovementLength; + slider.LazyTravelDistance += (float)currMovementLength; + } + slider.LazyEndPosition = currCursorPosition; + } + else if (currMovementObj is SliderRepeat && currMovementLength > normalized_radius) + { + // For a slider repeat, assume a tighter movement threshold to better assess repeat sliders. + currCursorPosition = Vector2.Add(currCursorPosition, Vector2.Multiply(currMovement, (float)((currMovementLength - normalized_radius) / currMovementLength))); + currMovementLength *= (currMovementLength - normalized_radius) / currMovementLength; + slider.LazyTravelDistance += (float)currMovementLength; + } + else if (currMovementLength > assumed_slider_radius) + { + // For a slider ticks, use the assumed slider radius for a more accurate movement assessment. + currCursorPosition = Vector2.Add(currCursorPosition, Vector2.Multiply(currMovement, (float)((currMovementLength - assumed_slider_radius) / currMovementLength))); + currMovementLength *= (currMovementLength - assumed_slider_radius) / currMovementLength; + slider.LazyTravelDistance += (float)currMovementLength; + } + } + + slider.LazyTravelDistance *= (float)Math.Pow(1 + slider.RepeatCount / 2.5, 1.0 / 2.5); // Bonus for repeat sliders until a better per nested object strain system can be achieved. } private Vector2 getEndCursorPosition(OsuHitObject hitObject)