1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 00:33:21 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Objects/Slider.cs

174 lines
6.0 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
2017-04-18 15:05:58 +08:00
using osu.Game.Rulesets.Objects.Types;
using System;
using System.Collections.Generic;
2017-04-18 15:05:58 +08:00
using osu.Game.Rulesets.Objects;
using System.Linq;
using osu.Game.Audio;
2017-07-26 12:22:46 +08:00
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
2017-04-18 15:05:58 +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;
public readonly SliderCurve Curve = new SliderCurve();
public double EndTime => StartTime + RepeatCount * Curve.Distance / Velocity;
public double Duration => EndTime - StartTime;
public override Vector2 EndPosition => PositionAt(1);
public List<Vector2> ControlPoints
{
get { return Curve.ControlPoints; }
set { Curve.ControlPoints = value; }
}
public CurveType CurveType
{
get { return Curve.CurveType; }
set { Curve.CurveType = value; }
}
public double Distance
{
get { return Curve.Distance; }
set { Curve.Distance = value; }
}
/// <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;
2017-12-25 14:35:28 +08:00
public List<List<SampleInfo>> RepeatSamples { get; set; } = new List<List<SampleInfo>>();
public int RepeatCount { get; set; } = 1;
private int stackHeight;
public override int StackHeight
{
get { return stackHeight; }
set
{
stackHeight = value;
Curve.Offset = StackOffset;
}
}
public double Velocity;
2017-02-13 03:38:05 +08:00
public double TickDistance;
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
{
base.ApplyDefaultsToSelf(controlPointInfo, difficulty);
TimingControlPoint timingPoint = controlPointInfo.TimingPointAt(StartTime);
DifficultyControlPoint difficultyPoint = controlPointInfo.DifficultyPointAt(StartTime);
2017-02-13 03:38:05 +08:00
double scoringDistance = base_scoring_distance * difficulty.SliderMultiplier * difficultyPoint.SpeedMultiplier;
Velocity = scoringDistance / timingPoint.BeatLength;
TickDistance = scoringDistance / difficulty.SliderTickRate;
}
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);
protected override void CreateNestedHitObjects()
2017-02-13 03:38:05 +08:00
{
base.CreateNestedHitObjects();
createTicks();
createRepeatPoints();
}
private void createTicks()
{
if (TickDistance == 0) return;
2017-02-13 03:38:05 +08:00
var length = Curve.Distance;
var tickDistance = Math.Min(TickDistance, length);
var repeatDuration = length / Velocity;
2017-02-13 03:38:05 +08:00
var minDistanceFromEnd = Velocity * 0.01;
2017-02-13 03:38:05 +08:00
for (var repeat = 0; repeat < RepeatCount; repeat++)
{
var repeatStartTime = StartTime + repeat * repeatDuration;
var reversed = repeat % 2 == 1;
2017-02-13 03:38:05 +08:00
for (var d = tickDistance; d <= length; d += tickDistance)
{
if (d > length - minDistanceFromEnd)
break;
var distanceProgress = d / length;
var timeProgress = reversed ? 1 - distanceProgress : distanceProgress;
2017-02-13 03:38:05 +08:00
AddNested(new SliderTick
{
RepeatIndex = repeat,
StartTime = repeatStartTime + timeProgress * repeatDuration,
Position = Curve.PositionAt(distanceProgress),
StackHeight = StackHeight,
Scale = Scale,
ComboColour = ComboColour,
2017-12-25 14:35:28 +08:00
Samples = new List<SampleInfo>(Samples.Select(s => new SampleInfo
2017-02-13 03:38:05 +08:00
{
Bank = s.Bank,
Name = @"slidertick",
Volume = s.Volume
}))
});
2017-02-13 03:38:05 +08:00
}
}
}
private void createRepeatPoints()
2017-09-27 00:13:34 +08:00
{
2017-12-27 19:37:28 +08:00
var repeatDuration = Distance / Velocity;
2017-12-24 12:12:10 +08:00
for (var repeat = 1; repeat < RepeatCount; repeat++)
{
2017-12-27 19:37:28 +08:00
var repeatStartTime = StartTime + repeat * repeatDuration;
2017-12-24 12:12:10 +08:00
2017-12-27 19:37:28 +08:00
AddNested(new RepeatPoint
2017-09-27 00:13:34 +08:00
{
2017-12-27 19:37:28 +08:00
RepeatIndex = repeat,
StartTime = repeatStartTime,
Position = Curve.PositionAt(repeat % 2),
2017-12-27 19:37:28 +08:00
StackHeight = StackHeight,
Scale = Scale,
ComboColour = ComboColour,
Samples = new List<SampleInfo>(RepeatSamples[repeat])
});
2017-09-27 00:13:34 +08:00
}
}
}
}