mirror of
https://github.com/osukey/osukey.git
synced 2025-08-06 08:03:52 +09:00
Add gravity timing change.
This commit is contained in:
@ -8,11 +8,11 @@ namespace osu.Game.Rulesets.Mania.Timing.Drawables
|
|||||||
{
|
{
|
||||||
public class DrawableGravityTimingChange : DrawableTimingChange
|
public class DrawableGravityTimingChange : DrawableTimingChange
|
||||||
{
|
{
|
||||||
private const double acceleration = 9.8f;
|
// Amount of time to travel this container such that
|
||||||
private const double terminal_velocity = 50f;
|
// at time = 0, gravityTime = timeSpan and
|
||||||
|
// at time = travel_time, gravityTime = 0
|
||||||
private const double duration = 2000;
|
// Where gravityTime is used as the position of the content
|
||||||
|
private const double travel_time = 1000;
|
||||||
|
|
||||||
public DrawableGravityTimingChange(TimingChange timingChange)
|
public DrawableGravityTimingChange(TimingChange timingChange)
|
||||||
: base(timingChange)
|
: base(timingChange)
|
||||||
@ -23,17 +23,52 @@ namespace osu.Game.Rulesets.Mania.Timing.Drawables
|
|||||||
{
|
{
|
||||||
base.Update();
|
base.Update();
|
||||||
|
|
||||||
var parent = (TimingChangeContainer)Parent;
|
// 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);
|
||||||
|
|
||||||
double elapsed = Math.Max(0, Time.Current - TimingChange.Time);
|
Content.Y = startY;
|
||||||
|
Content.Height = endY - startY;
|
||||||
// @ Current == TimingChange.Time - duration -> Y = TimingChange.Time
|
|
||||||
// @ Current == TimingChange.Time -> Y = 0
|
|
||||||
// @ Current == TimingChange.Time + x -> Y = -f(x)
|
|
||||||
|
|
||||||
double acceleration = elapsed / 2 / 1000 / 1000;
|
|
||||||
|
|
||||||
Content.Y = (float)(TimingChange.Time - 1 / 2f * acceleration * elapsed * elapsed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <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 / 2 * 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 => 2 * timeSpan / travel_time / travel_time;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Computes the current time relative to <paramref name="time"/>, accounting for <see cref="travel_time"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="time">The non-offset time.</param>
|
||||||
|
/// <returns>The current time relative to <paramref name="time"/> - <see cref="travel_time"/>. </returns>
|
||||||
|
private double relativeTimeAt(double time) => Time.Current - time + travel_time;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The velocity of the content of this container at a time.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="time">The non-offset time.</param>
|
||||||
|
/// <returns>The velocity at <paramref name="time"/>.</returns>
|
||||||
|
private double velocityAt(double time) => acceleration * relativeTimeAt(time);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,7 +10,7 @@ namespace osu.Game.Rulesets.Mania.Timing.Drawables
|
|||||||
{
|
{
|
||||||
public abstract class DrawableTimingChange : Container<DrawableHitObject>
|
public abstract class DrawableTimingChange : Container<DrawableHitObject>
|
||||||
{
|
{
|
||||||
protected readonly TimingChange TimingChange;
|
public readonly TimingChange TimingChange;
|
||||||
|
|
||||||
protected override Container<DrawableHitObject> Content => content;
|
protected override Container<DrawableHitObject> Content => content;
|
||||||
private readonly Container<DrawableHitObject> content;
|
private readonly Container<DrawableHitObject> content;
|
||||||
|
Reference in New Issue
Block a user