1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 02:33:02 +08:00

Refactor sliders to have more central position/progress calculations.

This commit is contained in:
Dean Herbert 2017-03-06 11:11:29 +09:00
parent cb002ce7af
commit 56922b66be
No known key found for this signature in database
GPG Key ID: 46D71BF4958ABB49
3 changed files with 31 additions and 9 deletions

View File

@ -102,8 +102,8 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
double progress = MathHelper.Clamp((Time.Current - slider.StartTime) / slider.Duration, 0, 1);
int repeat = (int)(progress * slider.RepeatCount);
progress = (progress * slider.RepeatCount) % 1;
int repeat = slider.RepeatAt(progress);
progress = slider.CurveProgressAt(progress);
if (repeat > currentRepeat)
{
@ -112,9 +112,6 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
currentRepeat = repeat;
}
if (repeat % 2 == 1)
progress = 1 - progress;
bouncer2.Position = slider.Curve.PositionAt(body.SnakedEnd ?? 0);
//todo: we probably want to reconsider this before adding scoring, but it looks and feels nice.

View File

@ -14,7 +14,32 @@ namespace osu.Game.Modes.Osu.Objects
{
public override double EndTime => StartTime + RepeatCount * Curve.Length / Velocity;
public override Vector2 EndPosition => RepeatCount % 2 == 0 ? Position : Curve.PositionAt(1);
public override Vector2 EndPosition => PositionAt(1);
/// <summary>
/// Computes the position on the slider at a given progress that ranges from 0 (beginning of the slider)
/// to 1 (end of the slider). This includes repeat logic.
/// </summary>
/// <param name="progress">Ranges from 0 (beginning of the slider) to 1 (end of the slider).</param>
/// <returns></returns>
public Vector2 PositionAt(double progress) => Curve.PositionAt(CurveProgressAt(progress));
/// <summary>
/// Find the current progress along the curve, accounting for repeat logic.
/// </summary>
public double CurveProgressAt(double progress)
{
var p = progress * RepeatCount % 1;
if (RepeatAt(progress) % 2 == 1)
p = 1 - p;
return p;
}
/// <summary>
/// Determine which repeat of the slider we are on at a given progress.
/// Range is 0..RepeatCount where 0 is the first run.
/// </summary>
public int RepeatAt(double progress) => (int)(progress * RepeatCount);
private int stackHeight;
public override int StackHeight

View File

@ -186,10 +186,10 @@ namespace osu.Game.Modes.Osu.Objects
}
/// <summary>
/// Computes the position on the slider at a given progress that ranges from 0 (beginning of the slider)
/// to 1 (end of the slider).
/// Computes the position on the slider at a given progress that ranges from 0 (beginning of the curve)
/// to 1 (end of the curve).
/// </summary>
/// <param name="progress">Ranges from 0 (beginning of the slider) to 1 (end of the slider).</param>
/// <param name="progress">Ranges from 0 (beginning of the curve) to 1 (end of the curve).</param>
/// <returns></returns>
public Vector2 PositionAt(double progress)
{