2018-04-13 17:19:50 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using OpenTK;
|
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.OsuDifficulty.Preprocessing
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A wrapper around <see cref="OsuHitObject"/> extending it with additional data required for difficulty calculation.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class OsuDifficultyHitObject
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The <see cref="OsuHitObject"/> this <see cref="OsuDifficultyHitObject"/> refers to.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public OsuHitObject BaseObject { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Normalized distance from the <see cref="OsuHitObject.StackedPosition"/> of the previous <see cref="OsuDifficultyHitObject"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public double Distance { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Milliseconds elapsed since the StartTime of the previous <see cref="OsuDifficultyHitObject"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public double DeltaTime { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private const int normalized_radius = 52;
|
|
|
|
|
|
2018-05-15 20:22:57 +08:00
|
|
|
|
private readonly OsuHitObject lastObject;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private readonly double timeRate;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes the object calculating extra data required for difficulty calculation.
|
|
|
|
|
/// </summary>
|
2018-05-15 20:22:57 +08:00
|
|
|
|
public OsuDifficultyHitObject(OsuHitObject currentObject, OsuHitObject lastObject, double timeRate)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-05-15 20:22:57 +08:00
|
|
|
|
this.lastObject = lastObject;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
this.timeRate = timeRate;
|
|
|
|
|
|
2018-05-15 20:22:57 +08:00
|
|
|
|
BaseObject = currentObject;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
setDistances();
|
|
|
|
|
setTimingValues();
|
|
|
|
|
// Calculate angle here
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setDistances()
|
|
|
|
|
{
|
|
|
|
|
// We will scale distances by this factor, so we can assume a uniform CircleSize among beatmaps.
|
|
|
|
|
double scalingFactor = normalized_radius / BaseObject.Radius;
|
|
|
|
|
if (BaseObject.Radius < 30)
|
|
|
|
|
{
|
|
|
|
|
double smallCircleBonus = Math.Min(30 - BaseObject.Radius, 5) / 50;
|
|
|
|
|
scalingFactor *= 1 + smallCircleBonus;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-15 20:22:57 +08:00
|
|
|
|
Vector2 lastCursorPosition = lastObject.StackedPosition;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
float lastTravelDistance = 0;
|
|
|
|
|
|
2018-05-15 20:22:57 +08:00
|
|
|
|
var lastSlider = lastObject as Slider;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
if (lastSlider != null)
|
|
|
|
|
{
|
|
|
|
|
computeSliderCursorPosition(lastSlider);
|
|
|
|
|
lastCursorPosition = lastSlider.LazyEndPosition ?? lastCursorPosition;
|
|
|
|
|
lastTravelDistance = lastSlider.LazyTravelDistance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Distance = (lastTravelDistance + (BaseObject.StackedPosition - lastCursorPosition).Length) * scalingFactor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setTimingValues()
|
|
|
|
|
{
|
|
|
|
|
// Every timing inverval is hard capped at the equivalent of 375 BPM streaming speed as a safety measure.
|
|
|
|
|
DeltaTime = Math.Max(40, (t[0].StartTime - t[1].StartTime) / timeRate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void computeSliderCursorPosition(Slider slider)
|
|
|
|
|
{
|
|
|
|
|
if (slider.LazyEndPosition != null)
|
|
|
|
|
return;
|
|
|
|
|
slider.LazyEndPosition = slider.StackedPosition;
|
|
|
|
|
|
|
|
|
|
float approxFollowCircleRadius = (float)(slider.Radius * 3);
|
|
|
|
|
var computeVertex = new Action<double>(t =>
|
|
|
|
|
{
|
|
|
|
|
// ReSharper disable once PossibleInvalidOperationException (bugged in current r# version)
|
|
|
|
|
var diff = slider.StackedPositionAt(t) - slider.LazyEndPosition.Value;
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var scoringTimes = slider.NestedHitObjects.Select(t => t.StartTime);
|
|
|
|
|
foreach (var time in scoringTimes)
|
|
|
|
|
computeVertex(time);
|
|
|
|
|
computeVertex(slider.EndTime);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|