From 85c518f146f4b8ff1c8bbd7971d0023545825701 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 14 Mar 2019 12:29:16 +0900 Subject: [PATCH] Change logic to better handle external adjustments --- osu.Game/Rulesets/Mods/ModTimeRamp.cs | 43 +++++++++++++++++---------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/osu.Game/Rulesets/Mods/ModTimeRamp.cs b/osu.Game/Rulesets/Mods/ModTimeRamp.cs index 082f0091c6..8cd4b28ce3 100644 --- a/osu.Game/Rulesets/Mods/ModTimeRamp.cs +++ b/osu.Game/Rulesets/Mods/ModTimeRamp.cs @@ -34,18 +34,11 @@ public abstract class ModTimeRamp : ModTimeRamp, IUpdatableByPlayfield, IAppl /// private const double final_rate_progress = 0.75f; - /// - /// The adjustment applied on entering this mod's application method. - /// - 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 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; + + /// + /// Adjust the rate along the specified ramp + /// + /// The amount of adjustment to apply (from 0..1). + 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; } } }