2017-06-09 01:43:48 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
2017-06-02 17:20:14 +08:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2017-06-09 01:43:48 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2017-06-02 19:17:44 +08:00
|
|
|
|
using osu.Game.Rulesets.Timing;
|
|
|
|
|
|
2017-06-09 15:20:55 +08:00
|
|
|
|
namespace osu.Game.Rulesets.Mania.Timing
|
2017-06-01 14:13:52 +08:00
|
|
|
|
{
|
2017-06-12 14:20:34 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// A <see cref="DrawableTimingSection"/> that emulates a form of gravity where hit objects speed up over time.
|
|
|
|
|
/// </summary>
|
2017-06-09 15:11:31 +08:00
|
|
|
|
internal class GravityScrollingDrawableTimingSection : DrawableTimingSection
|
2017-06-01 14:13:52 +08:00
|
|
|
|
{
|
2017-06-12 14:20:34 +08:00
|
|
|
|
private readonly MultiplierControlPoint controlPoint;
|
2017-06-09 01:43:48 +08:00
|
|
|
|
|
2017-06-12 14:20:34 +08:00
|
|
|
|
public GravityScrollingDrawableTimingSection(MultiplierControlPoint controlPoint)
|
2017-06-09 01:43:48 +08:00
|
|
|
|
: base(Axes.Y)
|
2017-06-01 14:13:52 +08:00
|
|
|
|
{
|
2017-06-12 14:20:34 +08:00
|
|
|
|
this.controlPoint = controlPoint;
|
2017-06-01 14:13:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-09 01:43:48 +08:00
|
|
|
|
protected override void UpdateAfterChildren()
|
2017-06-01 14:13:52 +08:00
|
|
|
|
{
|
2017-06-09 01:43:48 +08:00
|
|
|
|
base.UpdateAfterChildren();
|
2017-06-01 14:13:52 +08:00
|
|
|
|
|
2017-06-02 14:30:59 +08:00
|
|
|
|
// The gravity-adjusted start position
|
2017-06-12 14:20:34 +08:00
|
|
|
|
float startPos = (float)computeGravityTime(controlPoint.StartTime);
|
2017-06-02 14:30:59 +08:00
|
|
|
|
// The gravity-adjusted end position
|
2017-06-12 14:20:34 +08:00
|
|
|
|
float endPos = (float)computeGravityTime(controlPoint.StartTime + RelativeChildSize.Y);
|
2017-06-02 10:35:51 +08:00
|
|
|
|
|
2017-06-09 01:43:48 +08:00
|
|
|
|
Y = startPos;
|
|
|
|
|
Height = endPos - startPos;
|
2017-06-02 14:30:59 +08:00
|
|
|
|
}
|
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
|
|
|
|
|
2017-06-09 15:11:31 +08:00
|
|
|
|
return VisibleTimeRange - acceleration * relativeTime * relativeTime * sign;
|
2017-06-01 14:13:52 +08:00
|
|
|
|
}
|
2017-06-02 14:30:59 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The acceleration due to "gravity" of the content of this container.
|
|
|
|
|
/// </summary>
|
2017-06-09 15:11:31 +08:00
|
|
|
|
private double acceleration => 1 / VisibleTimeRange;
|
2017-06-02 14:30:59 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2017-06-09 15:20:55 +08:00
|
|
|
|
/// Computes the current time relative to <paramref name="time"/>, accounting for <see cref="DrawableTimingSection.VisibleTimeRange"/>.
|
2017-06-02 14:30:59 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="time">The non-offset time.</param>
|
2017-06-09 15:20:55 +08:00
|
|
|
|
/// <returns>The current time relative to <paramref name="time"/> - <see cref="DrawableTimingSection.VisibleTimeRange"/>. </returns>
|
2017-06-09 15:11:31 +08:00
|
|
|
|
private double relativeTimeAt(double time) => Time.Current - time + VisibleTimeRange;
|
2017-06-01 14:13:52 +08:00
|
|
|
|
}
|
2017-06-09 01:43:48 +08:00
|
|
|
|
}
|