1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 07:38:21 +08:00
osu-lazer/osu.Game.Rulesets.Mania/Timing/Drawables/DrawableGravityTimingChange.cs

58 lines
2.3 KiB
C#
Raw Normal View History

2017-06-02 17:20:14 +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
namespace osu.Game.Rulesets.Mania.Timing.Drawables
{
public class DrawableGravityTimingChange : DrawableManiaTimingChange
{
public DrawableGravityTimingChange(TimingChange timingChange)
: base(timingChange)
{
}
protected override void Update()
{
base.Update();
2017-06-02 14:30:59 +08:00
// The gravity-adjusted start position
float startY = (float)computeGravityTime(TimingChange.Time);
// The gravity-adjusted end position
float endY = (float)computeGravityTime(TimingChange.Time + Content.RelativeCoordinateSpace.Y);
2017-06-02 10:35:51 +08:00
2017-06-02 14:30:59 +08:00
Content.Y = startY;
Content.Height = endY - startY;
}
2017-06-02 10:35:51 +08:00
2017-06-02 14:30:59 +08:00
/// <summary>
/// Applies gravity to a time value based on the current time.
/// </summary>
/// <param name="time">The time value gravity should be applied to.</param>
/// <returns>The time after gravity is applied to <paramref name="time"/>.</returns>
private double computeGravityTime(double time)
{
double relativeTime = relativeTimeAt(time);
2017-06-02 10:35:51 +08:00
2017-06-02 14:30:59 +08:00
// The sign of the relative time, this is used to apply backwards acceleration leading into startTime
double sign = relativeTime < 0 ? -1 : 1;
2017-06-02 10:35:51 +08:00
return timeSpan - acceleration * relativeTime * relativeTime * sign;
}
2017-06-02 14:30:59 +08:00
/// <summary>
/// The time spanned by this container.
/// </summary>
private double timeSpan => RelativeCoordinateSpace.Y;
/// <summary>
/// The acceleration due to "gravity" of the content of this container.
/// </summary>
2017-06-02 18:34:55 +08:00
private double acceleration => 1 / timeSpan;
2017-06-02 14:30:59 +08:00
/// <summary>
2017-06-02 18:53:30 +08:00
/// Computes the current time relative to <paramref name="time"/>, accounting for <see cref="timeSpan"/>.
2017-06-02 14:30:59 +08:00
/// </summary>
/// <param name="time">The non-offset time.</param>
2017-06-02 18:53:30 +08:00
/// <returns>The current time relative to <paramref name="time"/> - <see cref="timeSpan"/>. </returns>
2017-06-02 18:34:55 +08:00
private double relativeTimeAt(double time) => Time.Current - time + timeSpan;
}
}