// Copyright (c) 2007-2017 ppy Pty Ltd . // 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 { /// /// A wrapper around extending it with additional data required for difficulty calculation. /// public class OsuDifficultyHitObject { /// /// The this refers to. /// public OsuHitObject BaseObject { get; } /// /// Normalized distance from the of the previous . /// public double Distance { get; private set; } /// /// Milliseconds elapsed since the StartTime of the previous . /// public double DeltaTime { get; private set; } /// /// Number of milliseconds until the has to be hit. /// public double TimeUntilHit { get; set; } private const int normalized_radius = 52; private readonly double timeRate; private readonly OsuHitObject[] t; /// /// Initializes the object calculating extra data required for difficulty calculation. /// public OsuDifficultyHitObject(OsuHitObject[] triangle, double timeRate) { this.timeRate = timeRate; 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; } Vector2 lastCursorPosition = t[1].StackedPosition; var lastSlider = t[1] as Slider; if (lastSlider != null) { computeSliderCursorPosition(lastSlider); lastCursorPosition = lastSlider.CursorPosition ?? lastCursorPosition; } Distance = (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); TimeUntilHit = 450; // BaseObject.PreEmpt; } private void computeSliderCursorPosition(Slider slider) { if (slider.CursorPosition != null) return; slider.CursorPosition = slider.StackedPosition; float approxFollowCircleRadius = (float)(slider.Radius * 3); var computeVertex = new Action(t => { var diff = slider.PositionAt(t) - slider.CursorPosition.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.CursorPosition += diff * dist; } }); var scoringTimes = slider.Ticks.Select(t => t.StartTime).Concat(slider.RepeatPoints.Select(r => r.StartTime)).OrderBy(t => t); foreach (var time in scoringTimes) computeVertex(time); computeVertex(slider.EndTime); } } }