mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 08:49:59 +09:00
Refactor sliders to have more central position/progress calculations.
This commit is contained in:
@ -102,8 +102,8 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
|
|||||||
|
|
||||||
double progress = MathHelper.Clamp((Time.Current - slider.StartTime) / slider.Duration, 0, 1);
|
double progress = MathHelper.Clamp((Time.Current - slider.StartTime) / slider.Duration, 0, 1);
|
||||||
|
|
||||||
int repeat = (int)(progress * slider.RepeatCount);
|
int repeat = slider.RepeatAt(progress);
|
||||||
progress = (progress * slider.RepeatCount) % 1;
|
progress = slider.CurveProgressAt(progress);
|
||||||
|
|
||||||
if (repeat > currentRepeat)
|
if (repeat > currentRepeat)
|
||||||
{
|
{
|
||||||
@ -112,9 +112,6 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
|
|||||||
currentRepeat = repeat;
|
currentRepeat = repeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (repeat % 2 == 1)
|
|
||||||
progress = 1 - progress;
|
|
||||||
|
|
||||||
bouncer2.Position = slider.Curve.PositionAt(body.SnakedEnd ?? 0);
|
bouncer2.Position = slider.Curve.PositionAt(body.SnakedEnd ?? 0);
|
||||||
|
|
||||||
//todo: we probably want to reconsider this before adding scoring, but it looks and feels nice.
|
//todo: we probably want to reconsider this before adding scoring, but it looks and feels nice.
|
||||||
|
@ -14,7 +14,32 @@ namespace osu.Game.Modes.Osu.Objects
|
|||||||
{
|
{
|
||||||
public override double EndTime => StartTime + RepeatCount * Curve.Length / Velocity;
|
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;
|
private int stackHeight;
|
||||||
public override int StackHeight
|
public override int StackHeight
|
||||||
|
@ -186,10 +186,10 @@ namespace osu.Game.Modes.Osu.Objects
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Computes the position on the slider at a given progress that ranges from 0 (beginning 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 slider).
|
/// to 1 (end of the curve).
|
||||||
/// </summary>
|
/// </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>
|
/// <returns></returns>
|
||||||
public Vector2 PositionAt(double progress)
|
public Vector2 PositionAt(double progress)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user