2017-02-07 12:59:30 +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
|
2016-09-02 17:35:49 +08:00
|
|
|
|
|
2016-12-06 20:14:38 +08:00
|
|
|
|
using OpenTK;
|
2017-02-15 17:48:29 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2017-02-13 03:38:05 +08:00
|
|
|
|
using osu.Game.Beatmaps.Samples;
|
2017-02-16 01:55:49 +08:00
|
|
|
|
using osu.Game.Beatmaps.Timing;
|
2017-02-15 17:48:29 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2016-09-02 17:35:49 +08:00
|
|
|
|
|
2016-11-14 17:54:24 +08:00
|
|
|
|
namespace osu.Game.Modes.Osu.Objects
|
2016-09-02 17:35:49 +08:00
|
|
|
|
{
|
2016-11-19 18:07:57 +08:00
|
|
|
|
public class Slider : OsuHitObject
|
2016-09-02 17:35:49 +08:00
|
|
|
|
{
|
2016-11-28 17:45:50 +08:00
|
|
|
|
public override double EndTime => StartTime + RepeatCount * Curve.Length / Velocity;
|
2016-11-28 14:31:54 +08:00
|
|
|
|
|
2016-12-06 20:14:38 +08:00
|
|
|
|
public override Vector2 EndPosition => RepeatCount % 2 == 0 ? Position : Curve.PositionAt(1);
|
|
|
|
|
|
2017-02-09 15:29:21 +08:00
|
|
|
|
private int stackHeight;
|
|
|
|
|
public override int StackHeight
|
|
|
|
|
{
|
|
|
|
|
get { return stackHeight; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
stackHeight = value;
|
2017-02-14 17:40:37 +08:00
|
|
|
|
Curve.Offset = StackOffset;
|
2017-02-09 15:29:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-14 17:40:37 +08:00
|
|
|
|
public List<Vector2> ControlPoints
|
|
|
|
|
{
|
|
|
|
|
get { return Curve.ControlPoints; }
|
|
|
|
|
set { Curve.ControlPoints = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double Length
|
|
|
|
|
{
|
|
|
|
|
get { return Curve.Length; }
|
|
|
|
|
set { Curve.Length = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CurveTypes CurveType
|
|
|
|
|
{
|
|
|
|
|
get { return Curve.CurveType; }
|
|
|
|
|
set { Curve.CurveType = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-28 17:45:50 +08:00
|
|
|
|
public double Velocity;
|
2017-02-13 03:38:05 +08:00
|
|
|
|
public double TickDistance;
|
2016-11-28 17:45:50 +08:00
|
|
|
|
|
|
|
|
|
public override void SetDefaultsFromBeatmap(Beatmap beatmap)
|
|
|
|
|
{
|
2016-12-11 17:11:22 +08:00
|
|
|
|
base.SetDefaultsFromBeatmap(beatmap);
|
|
|
|
|
|
2017-02-13 03:38:05 +08:00
|
|
|
|
var baseDifficulty = beatmap.BeatmapInfo.BaseDifficulty;
|
|
|
|
|
|
2017-02-16 01:55:49 +08:00
|
|
|
|
ControlPoint overridePoint;
|
|
|
|
|
ControlPoint timingPoint = beatmap.TimingPointAt(StartTime, out overridePoint);
|
|
|
|
|
var velocityAdjustment = overridePoint?.VelocityAdjustment ?? 1;
|
|
|
|
|
var baseVelocity = 100 * baseDifficulty.SliderMultiplier;
|
2017-02-13 03:38:05 +08:00
|
|
|
|
|
2017-02-16 01:55:49 +08:00
|
|
|
|
Velocity = baseVelocity / (timingPoint.BeatLength * velocityAdjustment);
|
|
|
|
|
TickDistance = baseVelocity / (baseDifficulty.SliderTickRate * velocityAdjustment);
|
2016-11-28 17:45:50 +08:00
|
|
|
|
}
|
2016-09-02 17:35:49 +08:00
|
|
|
|
|
2017-02-14 10:15:40 +08:00
|
|
|
|
public int RepeatCount = 1;
|
2016-11-17 20:29:35 +08:00
|
|
|
|
|
2017-02-14 17:40:37 +08:00
|
|
|
|
internal readonly SliderCurve Curve = new SliderCurve();
|
2017-02-13 03:38:05 +08:00
|
|
|
|
|
|
|
|
|
public IEnumerable<SliderTick> Ticks
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var length = Curve.Length;
|
|
|
|
|
var tickDistance = Math.Min(TickDistance, length);
|
|
|
|
|
var repeatDuration = length / Velocity;
|
|
|
|
|
|
|
|
|
|
var minDistanceFromEnd = Velocity * 0.01;
|
|
|
|
|
|
|
|
|
|
for (var repeat = 0; repeat < RepeatCount; repeat++)
|
|
|
|
|
{
|
|
|
|
|
var repeatStartTime = StartTime + repeat * repeatDuration;
|
|
|
|
|
var reversed = repeat % 2 == 1;
|
|
|
|
|
|
|
|
|
|
for (var d = tickDistance; d <= length; d += tickDistance)
|
|
|
|
|
{
|
|
|
|
|
if (d > length - minDistanceFromEnd)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
var distanceProgress = d / length;
|
|
|
|
|
var timeProgress = reversed ? 1 - distanceProgress : distanceProgress;
|
|
|
|
|
|
|
|
|
|
yield return new SliderTick
|
|
|
|
|
{
|
|
|
|
|
RepeatIndex = repeat,
|
|
|
|
|
StartTime = repeatStartTime + timeProgress * repeatDuration,
|
|
|
|
|
Position = Curve.PositionAt(distanceProgress) - StackedPosition,
|
|
|
|
|
StackHeight = StackHeight,
|
|
|
|
|
Scale = Scale,
|
|
|
|
|
Colour = Colour,
|
|
|
|
|
Sample = new HitSampleInfo
|
|
|
|
|
{
|
|
|
|
|
Type = SampleType.None,
|
|
|
|
|
Set = SampleSet.Soft,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-02 17:35:49 +08:00
|
|
|
|
}
|
2016-11-17 20:29:35 +08:00
|
|
|
|
|
|
|
|
|
public enum CurveTypes
|
|
|
|
|
{
|
|
|
|
|
Catmull,
|
|
|
|
|
Bezier,
|
|
|
|
|
Linear,
|
|
|
|
|
PerfectCurve
|
2016-11-28 11:15:25 +08:00
|
|
|
|
}
|
2016-09-02 17:35:49 +08:00
|
|
|
|
}
|