2017-06-06 05:45:22 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System;
|
2017-11-17 19:28:41 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using OpenTK;
|
2017-06-06 05:45:22 +08:00
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.OsuDifficulty.Preprocessing
|
|
|
|
|
{
|
2017-06-07 00:59:46 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// A wrapper around <see cref="OsuHitObject"/> extending it with additional data required for difficulty calculation.
|
|
|
|
|
/// </summary>
|
2017-06-06 05:45:22 +08:00
|
|
|
|
public class OsuDifficultyHitObject
|
|
|
|
|
{
|
2017-06-06 21:39:37 +08:00
|
|
|
|
/// <summary>
|
2017-06-07 00:59:46 +08:00
|
|
|
|
/// The <see cref="OsuHitObject"/> this <see cref="OsuDifficultyHitObject"/> refers to.
|
2017-06-06 21:39:37 +08:00
|
|
|
|
/// </summary>
|
2017-06-06 05:45:22 +08:00
|
|
|
|
public OsuHitObject BaseObject { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2017-06-07 00:59:46 +08:00
|
|
|
|
/// Normalized distance from the <see cref="OsuHitObject.StackedPosition"/> of the previous <see cref="OsuDifficultyHitObject"/>.
|
2017-06-06 05:45:22 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public double Distance { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2017-06-07 00:59:46 +08:00
|
|
|
|
/// Milliseconds elapsed since the StartTime of the previous <see cref="OsuDifficultyHitObject"/>.
|
2017-06-06 05:45:22 +08:00
|
|
|
|
/// </summary>
|
2017-06-06 21:39:37 +08:00
|
|
|
|
public double DeltaTime { get; private set; }
|
2017-06-06 05:45:22 +08:00
|
|
|
|
|
2017-06-06 21:39:37 +08:00
|
|
|
|
/// <summary>
|
2017-06-07 01:09:26 +08:00
|
|
|
|
/// Number of milliseconds until the <see cref="OsuDifficultyHitObject"/> has to be hit.
|
2017-06-06 21:39:37 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public double TimeUntilHit { get; set; }
|
2017-06-06 05:45:22 +08:00
|
|
|
|
|
|
|
|
|
private const int normalized_radius = 52;
|
|
|
|
|
|
2017-11-17 16:28:22 +08:00
|
|
|
|
private readonly double timeRate;
|
|
|
|
|
|
2017-06-06 07:08:34 +08:00
|
|
|
|
private readonly OsuHitObject[] t;
|
2017-06-06 05:45:22 +08:00
|
|
|
|
|
2017-06-06 21:39:37 +08:00
|
|
|
|
/// <summary>
|
2017-06-07 00:59:46 +08:00
|
|
|
|
/// Initializes the object calculating extra data required for difficulty calculation.
|
2017-06-06 21:39:37 +08:00
|
|
|
|
/// </summary>
|
2017-11-17 16:28:22 +08:00
|
|
|
|
public OsuDifficultyHitObject(OsuHitObject[] triangle, double timeRate)
|
2017-06-06 05:45:22 +08:00
|
|
|
|
{
|
2017-11-17 16:28:22 +08:00
|
|
|
|
this.timeRate = timeRate;
|
|
|
|
|
|
2017-06-06 05:45:22 +08:00
|
|
|
|
t = triangle;
|
|
|
|
|
BaseObject = t[0];
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-17 19:28:41 +08:00
|
|
|
|
Vector2 lastCursorPosition = t[1].StackedPosition;
|
2017-11-17 20:28:59 +08:00
|
|
|
|
float lastTravelDistance = 0;
|
2017-11-17 19:28:41 +08:00
|
|
|
|
|
|
|
|
|
var lastSlider = t[1] as Slider;
|
|
|
|
|
if (lastSlider != null)
|
|
|
|
|
{
|
2017-11-17 19:57:45 +08:00
|
|
|
|
computeSliderCursorPosition(lastSlider);
|
2017-11-17 20:28:59 +08:00
|
|
|
|
lastCursorPosition = lastSlider.LazyEndPosition ?? lastCursorPosition;
|
|
|
|
|
lastTravelDistance = lastSlider.LazyTravelDistance;
|
2017-11-17 19:28:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-17 20:28:59 +08:00
|
|
|
|
Distance = (lastTravelDistance + (BaseObject.StackedPosition - lastCursorPosition).Length) * scalingFactor;
|
2017-06-06 05:45:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setTimingValues()
|
|
|
|
|
{
|
|
|
|
|
// Every timing inverval is hard capped at the equivalent of 375 BPM streaming speed as a safety measure.
|
2017-11-17 19:27:44 +08:00
|
|
|
|
DeltaTime = Math.Max(40, (t[0].StartTime - t[1].StartTime) / timeRate);
|
2017-06-06 21:39:37 +08:00
|
|
|
|
TimeUntilHit = 450; // BaseObject.PreEmpt;
|
2017-06-06 05:45:22 +08:00
|
|
|
|
}
|
2017-11-17 19:57:45 +08:00
|
|
|
|
|
|
|
|
|
private void computeSliderCursorPosition(Slider slider)
|
|
|
|
|
{
|
2017-11-17 20:28:59 +08:00
|
|
|
|
if (slider.LazyEndPosition != null)
|
2017-11-17 19:57:45 +08:00
|
|
|
|
return;
|
2017-11-17 20:28:59 +08:00
|
|
|
|
slider.LazyEndPosition = slider.StackedPosition;
|
2017-11-17 19:57:45 +08:00
|
|
|
|
|
|
|
|
|
float approxFollowCircleRadius = (float)(slider.Radius * 3);
|
|
|
|
|
var computeVertex = new Action<double>(t =>
|
|
|
|
|
{
|
2017-12-21 22:14:42 +08:00
|
|
|
|
// ReSharper disable once PossibleInvalidOperationException (bugged in current r# version)
|
2017-11-17 20:28:59 +08:00
|
|
|
|
var diff = slider.PositionAt(t) - slider.LazyEndPosition.Value;
|
2017-11-17 19:57:45 +08: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;
|
2017-11-17 20:28:59 +08:00
|
|
|
|
slider.LazyEndPosition += diff * dist;
|
|
|
|
|
slider.LazyTravelDistance += dist;
|
2017-11-17 19:57:45 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-22 20:42:54 +08:00
|
|
|
|
var scoringTimes = slider.NestedHitObjects.Select(t => t.StartTime);
|
2017-11-17 19:57:45 +08:00
|
|
|
|
foreach (var time in scoringTimes)
|
|
|
|
|
computeVertex(time);
|
|
|
|
|
computeVertex(slider.EndTime);
|
|
|
|
|
}
|
2017-06-06 05:45:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|