2019-01-26 20:15:19 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
using System;
|
2019-03-06 13:14:41 +08:00
|
|
|
using System.Linq;
|
2019-01-26 20:15:19 +08:00
|
|
|
using osu.Framework.Audio;
|
|
|
|
using osu.Framework.Timing;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Rulesets.UI;
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mods
|
|
|
|
{
|
2019-08-01 11:35:17 +08:00
|
|
|
public abstract class ModTimeRamp : Mod, IUpdatableByPlayfield, IApplicableToClock, IApplicableToBeatmap
|
2019-01-26 20:15:19 +08:00
|
|
|
{
|
2019-08-01 11:35:17 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The point in the beatmap at which the final ramping rate should be reached.
|
|
|
|
/// </summary>
|
|
|
|
private const double final_rate_progress = 0.75f;
|
|
|
|
|
2019-03-12 17:15:18 +08:00
|
|
|
public override Type[] IncompatibleMods => new[] { typeof(ModTimeAdjust) };
|
2019-03-06 13:14:41 +08:00
|
|
|
|
|
|
|
protected abstract double FinalRateAdjustment { get; }
|
2019-01-26 20:15:19 +08:00
|
|
|
|
2019-03-06 13:14:41 +08:00
|
|
|
private double finalRateTime;
|
|
|
|
private double beginRampTime;
|
2019-01-26 20:15:19 +08:00
|
|
|
private IAdjustableClock clock;
|
2019-03-06 13:14:41 +08:00
|
|
|
|
|
|
|
public virtual void ApplyToClock(IAdjustableClock clock)
|
2019-01-26 20:15:19 +08:00
|
|
|
{
|
2019-03-06 13:14:41 +08:00
|
|
|
this.clock = clock;
|
|
|
|
|
2019-03-14 11:29:16 +08:00
|
|
|
lastAdjust = 1;
|
2019-03-12 17:15:18 +08:00
|
|
|
|
|
|
|
// for preview purposes. during gameplay, Update will overwrite this setting.
|
|
|
|
applyAdjustment(1);
|
2019-01-26 20:15:19 +08:00
|
|
|
}
|
|
|
|
|
2019-08-01 11:35:17 +08:00
|
|
|
public virtual void ApplyToBeatmap(IBeatmap beatmap)
|
2019-01-26 20:15:19 +08:00
|
|
|
{
|
2019-03-06 13:14:41 +08:00
|
|
|
HitObject lastObject = beatmap.HitObjects.LastOrDefault();
|
|
|
|
|
|
|
|
beginRampTime = beatmap.HitObjects.FirstOrDefault()?.StartTime ?? 0;
|
2019-11-25 18:01:24 +08:00
|
|
|
finalRateTime = final_rate_progress * (lastObject?.GetEndTime() ?? 0);
|
2019-01-26 20:15:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void Update(Playfield playfield)
|
|
|
|
{
|
2019-03-13 20:37:33 +08:00
|
|
|
applyAdjustment((clock.CurrentTime - beginRampTime) / finalRateTime);
|
2019-03-12 17:15:18 +08:00
|
|
|
}
|
|
|
|
|
2019-03-14 11:29:16 +08:00
|
|
|
private double lastAdjust = 1;
|
2019-03-13 20:37:33 +08:00
|
|
|
|
2019-03-14 11:29:16 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Adjust the rate along the specified ramp
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="amount">The amount of adjustment to apply (from 0..1).</param>
|
|
|
|
private void applyAdjustment(double amount)
|
|
|
|
{
|
2019-11-20 20:19:49 +08:00
|
|
|
double adjust = 1 + (Math.Sign(FinalRateAdjustment) * Math.Clamp(amount, 0, 1) * Math.Abs(FinalRateAdjustment));
|
2019-03-14 11:29:16 +08:00
|
|
|
|
|
|
|
switch (clock)
|
|
|
|
{
|
|
|
|
case IHasPitchAdjust pitch:
|
|
|
|
pitch.PitchAdjust /= lastAdjust;
|
|
|
|
pitch.PitchAdjust *= adjust;
|
|
|
|
break;
|
2019-04-01 11:44:46 +08:00
|
|
|
|
2019-03-14 11:29:16 +08:00
|
|
|
case IHasTempoAdjust tempo:
|
|
|
|
tempo.TempoAdjust /= lastAdjust;
|
|
|
|
tempo.TempoAdjust *= adjust;
|
|
|
|
break;
|
2019-04-01 11:44:46 +08:00
|
|
|
|
2019-03-14 11:29:16 +08:00
|
|
|
default:
|
|
|
|
clock.Rate /= lastAdjust;
|
|
|
|
clock.Rate *= adjust;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
lastAdjust = adjust;
|
2019-01-26 20:15:19 +08:00
|
|
|
}
|
|
|
|
}
|
2019-03-06 13:14:41 +08:00
|
|
|
}
|