2019-03-08 19:13:11 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 16:43:03 +08:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
|
using System.Linq;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2019-01-03 16:43:10 +08:00
|
|
|
|
using osu.Framework.Caching;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Audio;
|
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
2018-08-02 19:36:38 +08:00
|
|
|
|
using osu.Game.Rulesets.Judgements;
|
|
|
|
|
using osu.Game.Rulesets.Osu.Judgements;
|
2019-09-06 14:24:00 +08:00
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Objects
|
|
|
|
|
{
|
|
|
|
|
public class Slider : OsuHitObject, IHasCurve
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Scoring distance with a speed-adjusted beat length of 1 second.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const float base_scoring_distance = 100;
|
|
|
|
|
|
2018-11-01 02:52:24 +08:00
|
|
|
|
public double EndTime => StartTime + this.SpanCount() * Path.Distance / Velocity;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public double Duration => EndTime - StartTime;
|
|
|
|
|
|
2019-08-09 18:12:29 +08:00
|
|
|
|
private readonly Cached<Vector2> endPositionCache = new Cached<Vector2>();
|
2019-01-03 16:43:10 +08:00
|
|
|
|
|
|
|
|
|
public override Vector2 EndPosition => endPositionCache.IsValid ? endPositionCache.Value : endPositionCache.Value = Position + this.CurvePositionAt(1);
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public Vector2 StackedPositionAt(double t) => StackedPosition + this.CurvePositionAt(t);
|
|
|
|
|
|
2018-11-14 13:29:22 +08:00
|
|
|
|
public readonly Bindable<SliderPath> PathBindable = new Bindable<SliderPath>();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-11-01 14:38:19 +08:00
|
|
|
|
public SliderPath Path
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-11-14 13:29:22 +08:00
|
|
|
|
get => PathBindable.Value;
|
2019-01-03 16:43:10 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
PathBindable.Value = value;
|
|
|
|
|
endPositionCache.Invalidate();
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-12 13:07:48 +08:00
|
|
|
|
public double Distance => Path.Distance;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-10-25 17:16:25 +08:00
|
|
|
|
public override Vector2 Position
|
|
|
|
|
{
|
|
|
|
|
get => base.Position;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
base.Position = value;
|
|
|
|
|
|
2019-10-01 18:39:06 +08:00
|
|
|
|
endPositionCache.Invalidate();
|
|
|
|
|
|
2018-10-25 17:16:25 +08:00
|
|
|
|
if (HeadCircle != null)
|
|
|
|
|
HeadCircle.Position = value;
|
|
|
|
|
|
|
|
|
|
if (TailCircle != null)
|
|
|
|
|
TailCircle.Position = EndPosition;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-13 21:20:34 +08:00
|
|
|
|
public double? LegacyLastTickOffset { get; set; }
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The position of the cursor at the point of completion of this <see cref="Slider"/> if it was hit
|
|
|
|
|
/// with as few movements as possible. This is set and used by difficulty calculation.
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal Vector2? LazyEndPosition;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The distance travelled by the cursor upon completion of this <see cref="Slider"/> if it was hit
|
|
|
|
|
/// with as few movements as possible. This is set and used by difficulty calculation.
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal float LazyTravelDistance;
|
|
|
|
|
|
2019-06-30 20:58:30 +08:00
|
|
|
|
public List<List<HitSampleInfo>> NodeSamples { get; set; } = new List<List<HitSampleInfo>>();
|
2018-10-16 16:10:24 +08:00
|
|
|
|
|
2019-01-03 16:43:10 +08:00
|
|
|
|
private int repeatCount;
|
|
|
|
|
|
|
|
|
|
public int RepeatCount
|
|
|
|
|
{
|
|
|
|
|
get => repeatCount;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
repeatCount = value;
|
|
|
|
|
endPositionCache.Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The length of one span of this <see cref="Slider"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public double SpanDuration => Duration / this.SpanCount();
|
|
|
|
|
|
2018-10-15 11:32:59 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Velocity of this <see cref="Slider"/>.
|
|
|
|
|
/// </summary>
|
2018-10-15 11:31:52 +08:00
|
|
|
|
public double Velocity { get; private set; }
|
2018-10-15 11:32:59 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Spacing between <see cref="SliderTick"/>s of this <see cref="Slider"/>.
|
|
|
|
|
/// </summary>
|
2018-10-15 11:31:52 +08:00
|
|
|
|
public double TickDistance { get; private set; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-10-15 11:25:42 +08:00
|
|
|
|
/// <summary>
|
2018-10-15 11:32:59 +08:00
|
|
|
|
/// An extra multiplier that affects the number of <see cref="SliderTick"/>s generated by this <see cref="Slider"/>.
|
2018-10-15 11:25:42 +08:00
|
|
|
|
/// An increase in this value increases <see cref="TickDistance"/>, which reduces the number of ticks generated.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public double TickDistanceMultiplier = 1;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
public HitCircle HeadCircle;
|
2018-08-01 20:46:22 +08:00
|
|
|
|
public SliderTailCircle TailCircle;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
|
|
|
|
|
{
|
|
|
|
|
base.ApplyDefaultsToSelf(controlPointInfo, difficulty);
|
|
|
|
|
|
|
|
|
|
TimingControlPoint timingPoint = controlPointInfo.TimingPointAt(StartTime);
|
|
|
|
|
DifficultyControlPoint difficultyPoint = controlPointInfo.DifficultyPointAt(StartTime);
|
|
|
|
|
|
|
|
|
|
double scoringDistance = base_scoring_distance * difficulty.SliderMultiplier * difficultyPoint.SpeedMultiplier;
|
|
|
|
|
|
|
|
|
|
Velocity = scoringDistance / timingPoint.BeatLength;
|
2018-10-15 11:25:42 +08:00
|
|
|
|
TickDistance = scoringDistance / difficulty.SliderTickRate * TickDistanceMultiplier;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void CreateNestedHitObjects()
|
|
|
|
|
{
|
|
|
|
|
base.CreateNestedHitObjects();
|
|
|
|
|
|
2019-03-08 12:48:45 +08:00
|
|
|
|
foreach (var e in
|
|
|
|
|
SliderEventGenerator.Generate(StartTime, SpanDuration, Velocity, TickDistance, Path.Distance, this.SpanCount(), LegacyLastTickOffset))
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-06-30 20:58:30 +08:00
|
|
|
|
var firstSample = Samples.Find(s => s.Name == HitSampleInfo.HIT_NORMAL)
|
2019-03-08 12:48:45 +08:00
|
|
|
|
?? Samples.FirstOrDefault(); // TODO: remove this when guaranteed sort is present for samples (https://github.com/ppy/osu/issues/1933)
|
2019-06-30 20:58:30 +08:00
|
|
|
|
var sampleList = new List<HitSampleInfo>();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-03-08 12:48:45 +08:00
|
|
|
|
if (firstSample != null)
|
2019-06-30 20:58:30 +08:00
|
|
|
|
sampleList.Add(new HitSampleInfo
|
2019-03-08 12:48:45 +08:00
|
|
|
|
{
|
|
|
|
|
Bank = firstSample.Bank,
|
|
|
|
|
Volume = firstSample.Volume,
|
|
|
|
|
Name = @"slidertick",
|
|
|
|
|
});
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-03-08 12:48:45 +08:00
|
|
|
|
switch (e.Type)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-03-08 12:48:45 +08:00
|
|
|
|
case SliderEventType.Tick:
|
|
|
|
|
AddNested(new SliderTick
|
|
|
|
|
{
|
|
|
|
|
SpanIndex = e.SpanIndex,
|
|
|
|
|
SpanStartTime = e.SpanStartTime,
|
2019-03-11 13:36:29 +08:00
|
|
|
|
StartTime = e.Time,
|
2019-03-08 12:48:45 +08:00
|
|
|
|
Position = Position + Path.PositionAt(e.PathProgress),
|
|
|
|
|
StackHeight = StackHeight,
|
|
|
|
|
Scale = Scale,
|
|
|
|
|
Samples = sampleList
|
|
|
|
|
});
|
2018-04-13 17:19:50 +08:00
|
|
|
|
break;
|
2019-04-01 11:44:46 +08:00
|
|
|
|
|
2019-03-08 12:48:45 +08:00
|
|
|
|
case SliderEventType.Head:
|
|
|
|
|
AddNested(HeadCircle = new SliderCircle
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-03-11 13:36:29 +08:00
|
|
|
|
StartTime = e.Time,
|
2019-03-08 12:48:45 +08:00
|
|
|
|
Position = Position,
|
|
|
|
|
Samples = getNodeSamples(0),
|
|
|
|
|
SampleControlPoint = SampleControlPoint,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
});
|
2019-03-08 12:48:45 +08:00
|
|
|
|
break;
|
2019-04-01 11:44:46 +08:00
|
|
|
|
|
2019-03-08 19:13:11 +08:00
|
|
|
|
case SliderEventType.LegacyLastTick:
|
2019-03-08 19:12:48 +08:00
|
|
|
|
// we need to use the LegacyLastTick here for compatibility reasons (difficulty).
|
|
|
|
|
// it is *okay* to use this because the TailCircle is not used for any meaningful purpose in gameplay.
|
|
|
|
|
// if this is to change, we should revisit this.
|
2019-03-08 12:48:45 +08:00
|
|
|
|
AddNested(TailCircle = new SliderTailCircle(this)
|
|
|
|
|
{
|
2019-03-11 13:36:29 +08:00
|
|
|
|
StartTime = e.Time,
|
2019-03-08 12:48:45 +08:00
|
|
|
|
Position = EndPosition,
|
|
|
|
|
});
|
|
|
|
|
break;
|
2019-04-01 11:44:46 +08:00
|
|
|
|
|
2019-03-08 12:48:45 +08:00
|
|
|
|
case SliderEventType.Repeat:
|
|
|
|
|
AddNested(new RepeatPoint
|
|
|
|
|
{
|
|
|
|
|
RepeatIndex = e.SpanIndex,
|
|
|
|
|
SpanDuration = SpanDuration,
|
|
|
|
|
StartTime = StartTime + (e.SpanIndex + 1) * SpanDuration,
|
2019-03-08 14:14:57 +08:00
|
|
|
|
Position = Position + Path.PositionAt(e.PathProgress),
|
2019-03-08 12:48:45 +08:00
|
|
|
|
StackHeight = StackHeight,
|
|
|
|
|
Scale = Scale,
|
2019-03-11 13:53:21 +08:00
|
|
|
|
Samples = getNodeSamples(e.SpanIndex + 1)
|
2019-03-08 12:48:45 +08:00
|
|
|
|
});
|
|
|
|
|
break;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-30 20:58:30 +08:00
|
|
|
|
private List<HitSampleInfo> getNodeSamples(int nodeIndex) =>
|
2019-03-08 12:48:45 +08:00
|
|
|
|
nodeIndex < NodeSamples.Count ? NodeSamples[nodeIndex] : Samples;
|
2018-10-16 17:27:09 +08:00
|
|
|
|
|
2018-08-06 10:50:18 +08:00
|
|
|
|
public override Judgement CreateJudgement() => new OsuJudgement();
|
2019-09-02 15:10:30 +08:00
|
|
|
|
|
|
|
|
|
protected override HitWindows CreateHitWindows() => null;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|