2017-02-07 04:59:30 +00: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 09:35:49 +00:00
|
|
|
|
|
2016-12-06 12:14:38 +00:00
|
|
|
|
using OpenTK;
|
2017-04-18 07:05:58 +00:00
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2017-02-15 09:48:29 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2017-04-18 07:05:58 +00:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2017-04-06 02:41:16 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Game.Audio;
|
2017-07-26 04:22:46 +00:00
|
|
|
|
using osu.Game.Beatmaps;
|
2017-05-23 04:55:18 +00:00
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
2016-09-02 09:35:49 +00:00
|
|
|
|
|
2017-04-18 07:05:58 +00:00
|
|
|
|
namespace osu.Game.Rulesets.Osu.Objects
|
2016-09-02 09:35:49 +00:00
|
|
|
|
{
|
2017-03-15 03:52:25 +00:00
|
|
|
|
public class Slider : OsuHitObject, IHasCurve
|
2016-09-02 09:35:49 +00:00
|
|
|
|
{
|
2017-04-03 05:10:20 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Scoring distance with a speed-adjusted beat length of 1 second.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const float base_scoring_distance = 100;
|
|
|
|
|
|
2017-04-22 11:43:20 +00:00
|
|
|
|
public readonly SliderCurve Curve = new SliderCurve();
|
2017-03-15 03:52:25 +00:00
|
|
|
|
|
|
|
|
|
public double EndTime => StartTime + RepeatCount * Curve.Distance / Velocity;
|
2017-03-13 10:15:25 +00:00
|
|
|
|
public double Duration => EndTime - StartTime;
|
2016-11-28 06:31:54 +00:00
|
|
|
|
|
2017-03-06 02:11:29 +00:00
|
|
|
|
public override Vector2 EndPosition => PositionAt(1);
|
|
|
|
|
|
2017-04-21 11:29:27 +00:00
|
|
|
|
public List<Vector2> ControlPoints
|
|
|
|
|
{
|
|
|
|
|
get { return Curve.ControlPoints; }
|
|
|
|
|
set { Curve.ControlPoints = value; }
|
|
|
|
|
}
|
2017-03-06 02:11:29 +00:00
|
|
|
|
|
2017-04-21 11:29:27 +00:00
|
|
|
|
public CurveType CurveType
|
|
|
|
|
{
|
|
|
|
|
get { return Curve.CurveType; }
|
|
|
|
|
set { Curve.CurveType = value; }
|
|
|
|
|
}
|
2017-04-21 07:18:34 +00:00
|
|
|
|
|
2017-04-21 11:29:27 +00:00
|
|
|
|
public double Distance
|
|
|
|
|
{
|
|
|
|
|
get { return Curve.Distance; }
|
|
|
|
|
set { Curve.Distance = value; }
|
|
|
|
|
}
|
2017-03-15 03:52:25 +00:00
|
|
|
|
|
2017-04-26 05:12:21 +00:00
|
|
|
|
public List<SampleInfoList> RepeatSamples { get; set; } = new List<SampleInfoList>();
|
2017-04-21 11:29:27 +00:00
|
|
|
|
public int RepeatCount { get; set; } = 1;
|
2016-12-06 12:14:38 +00:00
|
|
|
|
|
2017-02-09 07:29:21 +00:00
|
|
|
|
private int stackHeight;
|
|
|
|
|
public override int StackHeight
|
|
|
|
|
{
|
|
|
|
|
get { return stackHeight; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
stackHeight = value;
|
2017-02-14 09:40:37 +00:00
|
|
|
|
Curve.Offset = StackOffset;
|
2017-02-09 07:29:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-28 09:45:50 +00:00
|
|
|
|
public double Velocity;
|
2017-02-12 19:38:05 +00:00
|
|
|
|
public double TickDistance;
|
2016-11-28 09:45:50 +00:00
|
|
|
|
|
2017-05-23 04:55:18 +00:00
|
|
|
|
public override void ApplyDefaults(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
|
2016-11-28 09:45:50 +00:00
|
|
|
|
{
|
2017-05-23 04:55:18 +00:00
|
|
|
|
base.ApplyDefaults(controlPointInfo, difficulty);
|
2017-02-12 19:38:05 +00:00
|
|
|
|
|
2017-05-23 04:55:18 +00:00
|
|
|
|
TimingControlPoint timingPoint = controlPointInfo.TimingPointAt(StartTime);
|
|
|
|
|
DifficultyControlPoint difficultyPoint = controlPointInfo.DifficultyPointAt(StartTime);
|
2017-02-12 19:38:05 +00:00
|
|
|
|
|
2017-08-21 02:45:57 +00:00
|
|
|
|
double scoringDistance = base_scoring_distance * difficulty.SliderMultiplier * difficultyPoint.SpeedMultiplier;
|
2017-05-23 04:55:18 +00:00
|
|
|
|
|
|
|
|
|
Velocity = scoringDistance / timingPoint.BeatLength;
|
2017-04-03 05:10:20 +00:00
|
|
|
|
TickDistance = scoringDistance / difficulty.SliderTickRate;
|
2016-11-28 09:45:50 +00:00
|
|
|
|
}
|
2016-09-02 09:35:49 +00:00
|
|
|
|
|
2017-04-21 11:29:27 +00:00
|
|
|
|
public Vector2 PositionAt(double progress) => Curve.PositionAt(ProgressAt(progress));
|
|
|
|
|
|
|
|
|
|
public double ProgressAt(double progress)
|
|
|
|
|
{
|
|
|
|
|
double p = progress * RepeatCount % 1;
|
|
|
|
|
if (RepeatAt(progress) % 2 == 1)
|
|
|
|
|
p = 1 - p;
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int RepeatAt(double progress) => (int)(progress * RepeatCount);
|
|
|
|
|
|
2017-02-12 19:38:05 +00:00
|
|
|
|
public IEnumerable<SliderTick> Ticks
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-02-16 04:20:30 +00:00
|
|
|
|
if (TickDistance == 0) yield break;
|
|
|
|
|
|
2017-03-15 03:52:25 +00:00
|
|
|
|
var length = Curve.Distance;
|
2017-02-12 19:38:05 +00:00
|
|
|
|
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,
|
2017-02-16 08:02:36 +00:00
|
|
|
|
Position = Curve.PositionAt(distanceProgress),
|
2017-02-12 19:38:05 +00:00
|
|
|
|
StackHeight = StackHeight,
|
|
|
|
|
Scale = Scale,
|
2017-03-13 10:15:25 +00:00
|
|
|
|
ComboColour = ComboColour,
|
2017-04-26 05:12:21 +00:00
|
|
|
|
Samples = new SampleInfoList(Samples.Select(s => new SampleInfo
|
2017-04-06 02:41:16 +00:00
|
|
|
|
{
|
|
|
|
|
Bank = s.Bank,
|
|
|
|
|
Name = @"slidertick",
|
|
|
|
|
Volume = s.Volume
|
2017-04-26 05:12:21 +00:00
|
|
|
|
}))
|
2017-02-12 19:38:05 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-27 15:28:44 +00:00
|
|
|
|
public IEnumerable<RepeatPoint> RepeatPoints
|
2017-09-26 16:13:34 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var length = Curve.Distance;
|
2017-09-27 15:28:44 +00:00
|
|
|
|
var repeatPointDistance = Math.Min(Distance, length);
|
2017-09-26 16:13:34 +00:00
|
|
|
|
var repeatDuration = length / Velocity;
|
|
|
|
|
|
2017-10-12 14:28:55 +00:00
|
|
|
|
for (var repeat = 1; repeat < RepeatCount; repeat++)
|
2017-09-26 16:13:34 +00:00
|
|
|
|
{
|
2017-10-12 14:28:55 +00:00
|
|
|
|
for (var d = repeatPointDistance; d <= length; d += repeatPointDistance)
|
|
|
|
|
{
|
|
|
|
|
var repeatStartTime = StartTime + repeat * repeatDuration;
|
|
|
|
|
var distanceProgress = d / length;
|
2017-09-26 16:13:34 +00:00
|
|
|
|
|
2017-10-12 14:28:55 +00:00
|
|
|
|
yield return new RepeatPoint
|
|
|
|
|
{
|
|
|
|
|
RepeatIndex = repeat,
|
|
|
|
|
StartTime = repeatStartTime,
|
|
|
|
|
Position = Curve.PositionAt(distanceProgress),
|
|
|
|
|
StackHeight = StackHeight,
|
|
|
|
|
Scale = Scale,
|
|
|
|
|
ComboColour = ComboColour,
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-09-26 16:13:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-02 09:35:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|