mirror of
https://github.com/ppy/osu.git
synced 2024-11-19 15:32:55 +08:00
66 lines
2.5 KiB
C#
66 lines
2.5 KiB
C#
using System;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.MathUtils;
|
|
using osu.Framework.Physics;
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
namespace osu.Game.Rulesets.Mania.Timing.Drawables
|
|
{
|
|
public class DrawableGravityTimingChange : DrawableTimingChange
|
|
{
|
|
public DrawableGravityTimingChange(TimingChange timingChange)
|
|
: base(timingChange)
|
|
{
|
|
}
|
|
|
|
protected override void Update()
|
|
{
|
|
base.Update();
|
|
|
|
// 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);
|
|
|
|
Content.Y = startY;
|
|
Content.Height = endY - startY;
|
|
}
|
|
|
|
/// <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);
|
|
|
|
// The sign of the relative time, this is used to apply backwards acceleration leading into startTime
|
|
double sign = relativeTime < 0 ? -1 : 1;
|
|
|
|
return timeSpan - acceleration * relativeTime * relativeTime * sign;
|
|
}
|
|
|
|
/// <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>
|
|
private double acceleration => timeSpan / travelTime / travelTime;
|
|
|
|
/// <summary>
|
|
/// The travel time, after beat length adjustments.
|
|
/// </summary>
|
|
private double travelTime => timeSpan / TimingChange.SpeedMultiplier;
|
|
|
|
/// <summary>
|
|
/// Computes the current time relative to <paramref name="time"/>, accounting for <see cref="travelTime"/>.
|
|
/// </summary>
|
|
/// <param name="time">The non-offset time.</param>
|
|
/// <returns>The current time relative to <paramref name="time"/> - <see cref="travelTime"/>. </returns>
|
|
private double relativeTimeAt(double time) => Time.Current - time + travelTime;
|
|
}
|
|
} |