Change logic to better handle external adjustments

This commit is contained in:
Dean Herbert 2019-03-14 12:29:16 +09:00
parent 108dcd0a92
commit 85c518f146
1 changed files with 27 additions and 16 deletions

View File

@ -34,18 +34,11 @@ public abstract class ModTimeRamp<T> : ModTimeRamp, IUpdatableByPlayfield, IAppl
/// </summary>
private const double final_rate_progress = 0.75f;
/// <summary>
/// The adjustment applied on entering this mod's application method.
/// </summary>
private double baseAdjust;
public virtual void ApplyToClock(IAdjustableClock clock)
{
this.clock = clock;
// we capture the adjustment applied before entering our application method.
// this will cover external changes, which should re-fire this method.
baseAdjust = (clock as IHasPitchAdjust)?.PitchAdjust ?? clock.Rate;
lastAdjust = 1;
// for preview purposes. during gameplay, Update will overwrite this setting.
applyAdjustment(1);
@ -61,20 +54,38 @@ public virtual void ApplyToBeatmap(Beatmap<T> beatmap)
public virtual void Update(Playfield playfield)
{
var absRate = Math.Abs(FinalRateAdjustment);
applyAdjustment((clock.CurrentTime - beginRampTime) / finalRateTime);
}
private void applyAdjustment(double adjustAmount)
private double lastAdjust = 1;
private bool reported;
/// <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)
{
adjustAmount = MathHelper.Clamp(adjustAmount, 0, 1);
double adjust = 1 + (Math.Sign(FinalRateAdjustment) * MathHelper.Clamp(amount, 0, 1) * Math.Abs(FinalRateAdjustment));
var localAdjust = 1 + Math.Sign(FinalRateAdjustment) * adjustAmount * Math.Abs(FinalRateAdjustment);
switch (clock)
{
case IHasPitchAdjust pitch:
pitch.PitchAdjust /= lastAdjust;
pitch.PitchAdjust *= adjust;
break;
case IHasTempoAdjust tempo:
tempo.TempoAdjust /= lastAdjust;
tempo.TempoAdjust *= adjust;
break;
default:
clock.Rate /= lastAdjust;
clock.Rate *= adjust;
break;
}
if (clock is IHasPitchAdjust tempo)
tempo.PitchAdjust = baseAdjust * localAdjust;
else
clock.Rate = baseAdjust * localAdjust;
lastAdjust = adjust;
}
}
}