Merge pull request #4458 from peppy/mod-ramp-hotfix

Fix "wind" mods adjusting rate twice
This commit is contained in:
Dan Balasescu 2019-03-14 15:23:22 +09:00 committed by GitHub
commit 719056c485
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 93 additions and 33 deletions

View File

@ -17,7 +17,7 @@ namespace osu.Game.Rulesets.Mods
public override void ApplyToClock(IAdjustableClock clock)
{
if (clock is IHasPitchAdjust pitchAdjust)
pitchAdjust.PitchAdjust = 0.75;
pitchAdjust.PitchAdjust *= RateAdjust;
else
base.ApplyToClock(clock);
}

View File

@ -2,12 +2,12 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Timing;
using System.Linq;
using osu.Game.Graphics;
namespace osu.Game.Rulesets.Mods
{
public abstract class ModDoubleTime : Mod, IApplicableToClock
public abstract class ModDoubleTime : ModTimeAdjust, IApplicableToClock
{
public override string Name => "Double Time";
public override string Acronym => "DT";
@ -15,11 +15,9 @@ namespace osu.Game.Rulesets.Mods
public override ModType Type => ModType.DifficultyIncrease;
public override string Description => "Zoooooooooom...";
public override bool Ranked => true;
public override Type[] IncompatibleMods => new[] { typeof(ModHalfTime), typeof(ModTimeRamp) };
public virtual void ApplyToClock(IAdjustableClock clock)
{
clock.Rate = 1.5;
}
public override Type[] IncompatibleMods => base.IncompatibleMods.Append(typeof(ModHalfTime)).ToArray();
protected override double RateAdjust => 1.5;
}
}

View File

@ -2,12 +2,12 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Timing;
using System.Linq;
using osu.Game.Graphics;
namespace osu.Game.Rulesets.Mods
{
public abstract class ModHalfTime : Mod, IApplicableToClock
public abstract class ModHalfTime : ModTimeAdjust, IApplicableToClock
{
public override string Name => "Half Time";
public override string Acronym => "HT";
@ -15,11 +15,9 @@ namespace osu.Game.Rulesets.Mods
public override ModType Type => ModType.DifficultyReduction;
public override string Description => "Less zoom...";
public override bool Ranked => true;
public override Type[] IncompatibleMods => new[] { typeof(ModDoubleTime), typeof(ModTimeRamp) };
public virtual void ApplyToClock(IAdjustableClock clock)
{
clock.Rate = 0.75;
}
public override Type[] IncompatibleMods => base.IncompatibleMods.Append(typeof(ModDoubleTime)).ToArray();
protected override double RateAdjust => 0.75;
}
}

View File

@ -17,7 +17,7 @@ namespace osu.Game.Rulesets.Mods
public override void ApplyToClock(IAdjustableClock clock)
{
if (clock is IHasPitchAdjust pitchAdjust)
pitchAdjust.PitchAdjust = 1.5;
pitchAdjust.PitchAdjust *= RateAdjust;
else
base.ApplyToClock(clock);
}

View File

@ -0,0 +1,24 @@
// 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;
using osu.Framework.Audio;
using osu.Framework.Timing;
namespace osu.Game.Rulesets.Mods
{
public abstract class ModTimeAdjust : Mod
{
public override Type[] IncompatibleMods => new[] { typeof(ModTimeRamp) };
protected abstract double RateAdjust { get; }
public virtual void ApplyToClock(IAdjustableClock clock)
{
if (clock is IHasTempoAdjust tempo)
tempo.TempoAdjust *= RateAdjust;
else
clock.Rate *= RateAdjust;
}
}
}

View File

@ -15,7 +15,7 @@ namespace osu.Game.Rulesets.Mods
{
public abstract class ModTimeRamp : Mod
{
public override Type[] IncompatibleMods => new[] { typeof(ModDoubleTime), typeof(ModHalfTime) };
public override Type[] IncompatibleMods => new[] { typeof(ModTimeAdjust) };
protected abstract double FinalRateAdjustment { get; }
}
@ -29,8 +29,6 @@ namespace osu.Game.Rulesets.Mods
private IAdjustableClock clock;
private IHasPitchAdjust pitchAdjust;
/// <summary>
/// The point in the beatmap at which the final ramping rate should be reached.
/// </summary>
@ -39,10 +37,11 @@ namespace osu.Game.Rulesets.Mods
public virtual void ApplyToClock(IAdjustableClock clock)
{
this.clock = clock;
pitchAdjust = (IHasPitchAdjust)clock;
// for preview purposes
pitchAdjust.PitchAdjust = 1.0 + FinalRateAdjustment;
lastAdjust = 1;
// for preview purposes. during gameplay, Update will overwrite this setting.
applyAdjustment(1);
}
public virtual void ApplyToBeatmap(Beatmap<T> beatmap)
@ -55,10 +54,36 @@ namespace osu.Game.Rulesets.Mods
public virtual void Update(Playfield playfield)
{
var absRate = Math.Abs(FinalRateAdjustment);
var adjustment = MathHelper.Clamp(absRate * ((clock.CurrentTime - beginRampTime) / finalRateTime), 0, absRate);
applyAdjustment((clock.CurrentTime - beginRampTime) / finalRateTime);
}
pitchAdjust.PitchAdjust = 1 + Math.Sign(FinalRateAdjustment) * adjustment;
private double lastAdjust = 1;
/// <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)
{
double adjust = 1 + (Math.Sign(FinalRateAdjustment) * MathHelper.Clamp(amount, 0, 1) * 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;
}
lastAdjust = adjust;
}
}
}

View File

@ -1,6 +1,8 @@
// 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;
using System.Linq;
using osu.Game.Graphics;
using osu.Game.Rulesets.Objects;
@ -14,6 +16,9 @@ namespace osu.Game.Rulesets.Mods
public override string Description => "Sloooow doooown...";
public override FontAwesome Icon => FontAwesome.fa_chevron_circle_down;
public override double ScoreMultiplier => 1.0;
protected override double FinalRateAdjustment => -0.25;
public override Type[] IncompatibleMods => base.IncompatibleMods.Append(typeof(ModWindUp<T>)).ToArray();
}
}

View File

@ -1,6 +1,8 @@
// 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;
using System.Linq;
using osu.Game.Graphics;
using osu.Game.Rulesets.Objects;
@ -14,6 +16,9 @@ namespace osu.Game.Rulesets.Mods
public override string Description => "Can you keep up?";
public override FontAwesome Icon => FontAwesome.fa_chevron_circle_up;
public override double ScoreMultiplier => 1.0;
protected override double FinalRateAdjustment => 0.5;
public override Type[] IncompatibleMods => base.IncompatibleMods.Append(typeof(ModWindDown<T>)).ToArray();
}
}
}

View File

@ -6,6 +6,7 @@ using System.Linq;
using System.Threading.Tasks;
using osu.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -141,11 +142,15 @@ namespace osu.Game.Screens.Play
{
if (sourceClock == null) return;
sourceClock.Rate = 1;
sourceClock.ResetSpeedAdjustments();
if (sourceClock is IHasTempoAdjust tempo)
tempo.TempoAdjust = UserPlaybackRate.Value;
else
sourceClock.Rate = UserPlaybackRate.Value;
foreach (var mod in beatmap.Mods.Value.OfType<IApplicableToClock>())
mod.ApplyToClock(sourceClock);
sourceClock.Rate *= UserPlaybackRate.Value;
}
}
}

View File

@ -13,7 +13,7 @@ namespace osu.Game.Tests.Visual
base.Update();
// note that this will override any mod rate application
Beatmap.Value.Track.Rate = Clock.Rate;
Beatmap.Value.Track.TempoAdjust = Clock.Rate;
}
}
}

View File

@ -16,7 +16,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2019.128.0" />
<PackageReference Include="ppy.osu.Framework" Version="2019.308.0" />
<PackageReference Include="ppy.osu.Framework" Version="2019.313.0" />
<PackageReference Include="SharpCompress" Version="0.22.0" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="SharpRaven" Version="2.4.0" />

View File

@ -105,8 +105,8 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2019.128.0" />
<PackageReference Include="ppy.osu.Framework" Version="2019.308.0" />
<PackageReference Include="ppy.osu.Framework.iOS" Version="2019.308.0" />
<PackageReference Include="ppy.osu.Framework" Version="2019.313.0" />
<PackageReference Include="ppy.osu.Framework.iOS" Version="2019.313.0" />
<PackageReference Include="SharpCompress" Version="0.22.0" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="SharpRaven" Version="2.4.0" />