mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 22:22:54 +08:00
Update mods and user adjust to use adjustments
This commit is contained in:
parent
6b667daf09
commit
7fd52c21f5
@ -1,6 +1,7 @@
|
||||
// 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 osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Track;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
|
||||
@ -15,7 +16,7 @@ namespace osu.Game.Rulesets.Mods
|
||||
|
||||
public override void ApplyToTrack(Track track)
|
||||
{
|
||||
track.Frequency.Value *= RateAdjust;
|
||||
track.AddAdjustment(AdjustableProperty.Frequency, SpeedChange);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ using osu.Game.Graphics;
|
||||
|
||||
namespace osu.Game.Rulesets.Mods
|
||||
{
|
||||
public abstract class ModDoubleTime : ModTimeAdjust
|
||||
public abstract class ModDoubleTime : ModRateAdjust
|
||||
{
|
||||
public override string Name => "Double Time";
|
||||
public override string Acronym => "DT";
|
||||
@ -22,7 +22,7 @@ namespace osu.Game.Rulesets.Mods
|
||||
public override Type[] IncompatibleMods => base.IncompatibleMods.Append(typeof(ModHalfTime)).ToArray();
|
||||
|
||||
[SettingSource("Speed increase", "The actual increase to apply")]
|
||||
public BindableNumber<double> SpeedChange { get; } = new BindableDouble
|
||||
public override BindableNumber<double> SpeedChange { get; } = new BindableDouble
|
||||
{
|
||||
MinValue = 1.01,
|
||||
MaxValue = 2,
|
||||
@ -30,7 +30,5 @@ namespace osu.Game.Rulesets.Mods
|
||||
Value = 1.5,
|
||||
Precision = 0.01,
|
||||
};
|
||||
|
||||
protected override double RateAdjust => SpeedChange.Value;
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ using osu.Game.Graphics;
|
||||
|
||||
namespace osu.Game.Rulesets.Mods
|
||||
{
|
||||
public abstract class ModHalfTime : ModTimeAdjust
|
||||
public abstract class ModHalfTime : ModRateAdjust
|
||||
{
|
||||
public override string Name => "Half Time";
|
||||
public override string Acronym => "HT";
|
||||
@ -22,7 +22,7 @@ namespace osu.Game.Rulesets.Mods
|
||||
public override Type[] IncompatibleMods => base.IncompatibleMods.Append(typeof(ModDoubleTime)).ToArray();
|
||||
|
||||
[SettingSource("Speed decrease", "The actual decrease to apply")]
|
||||
public BindableNumber<double> SpeedChange { get; } = new BindableDouble
|
||||
public override BindableNumber<double> SpeedChange { get; } = new BindableDouble
|
||||
{
|
||||
MinValue = 0.5,
|
||||
MaxValue = 0.99,
|
||||
@ -30,7 +30,5 @@ namespace osu.Game.Rulesets.Mods
|
||||
Value = 0.75,
|
||||
Precision = 0.01,
|
||||
};
|
||||
|
||||
protected override double RateAdjust => SpeedChange.Value;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
// 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 osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Track;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Game.Graphics;
|
||||
@ -16,7 +17,7 @@ namespace osu.Game.Rulesets.Mods
|
||||
|
||||
public override void ApplyToTrack(Track track)
|
||||
{
|
||||
track.Frequency.Value *= RateAdjust;
|
||||
track.AddAdjustment(AdjustableProperty.Frequency, SpeedChange);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,19 +2,21 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Track;
|
||||
using osu.Framework.Bindables;
|
||||
|
||||
namespace osu.Game.Rulesets.Mods
|
||||
{
|
||||
public abstract class ModTimeAdjust : Mod, IApplicableToTrack
|
||||
public abstract class ModRateAdjust : Mod, IApplicableToTrack
|
||||
{
|
||||
public override Type[] IncompatibleMods => new[] { typeof(ModTimeRamp) };
|
||||
|
||||
protected abstract double RateAdjust { get; }
|
||||
public abstract BindableNumber<double> SpeedChange { get; }
|
||||
|
||||
public virtual void ApplyToTrack(Track track)
|
||||
{
|
||||
track.TempoAdjust *= RateAdjust;
|
||||
track.AddAdjustment(AdjustableProperty.Tempo, SpeedChange);
|
||||
}
|
||||
}
|
||||
}
|
@ -3,36 +3,42 @@
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Track;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
|
||||
namespace osu.Game.Rulesets.Mods
|
||||
{
|
||||
public abstract class ModTimeRamp : Mod, IUpdatableByPlayfield, IApplicableToTrack, IApplicableToBeatmap
|
||||
public abstract class ModTimeRamp : Mod, IUpdatableByPlayfield, IApplicableToBeatmap, IApplicableToTrack
|
||||
{
|
||||
/// <summary>
|
||||
/// The point in the beatmap at which the final ramping rate should be reached.
|
||||
/// </summary>
|
||||
private const double final_rate_progress = 0.75f;
|
||||
|
||||
public override Type[] IncompatibleMods => new[] { typeof(ModTimeAdjust) };
|
||||
public override Type[] IncompatibleMods => new[] { typeof(ModRateAdjust) };
|
||||
|
||||
protected abstract double FinalRateAdjustment { get; }
|
||||
|
||||
private double finalRateTime;
|
||||
private double beginRampTime;
|
||||
|
||||
public BindableNumber<double> SpeedChange { get; } = new BindableDouble
|
||||
{
|
||||
Default = 1,
|
||||
Value = 1,
|
||||
Precision = 0.01,
|
||||
};
|
||||
|
||||
private Track track;
|
||||
|
||||
public virtual void ApplyToTrack(Track track)
|
||||
public void ApplyToTrack(Track track)
|
||||
{
|
||||
this.track = track;
|
||||
|
||||
lastAdjust = 1;
|
||||
|
||||
// for preview purposes. during gameplay, Update will overwrite this setting.
|
||||
applyAdjustment(1);
|
||||
track.AddAdjustment(AdjustableProperty.Frequency, SpeedChange);
|
||||
}
|
||||
|
||||
public virtual void ApplyToBeatmap(IBeatmap beatmap)
|
||||
@ -48,20 +54,11 @@ namespace osu.Game.Rulesets.Mods
|
||||
applyAdjustment((track.CurrentTime - beginRampTime) / finalRateTime);
|
||||
}
|
||||
|
||||
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) * Math.Clamp(amount, 0, 1) * Math.Abs(FinalRateAdjustment));
|
||||
|
||||
track.Tempo.Value /= lastAdjust;
|
||||
track.Tempo.Value *= lastAdjust;
|
||||
|
||||
lastAdjust = adjust;
|
||||
}
|
||||
private void applyAdjustment(double amount) =>
|
||||
SpeedChange.Value = 1 + (Math.Sign(FinalRateAdjustment) * Math.Clamp(amount, 0, 1) * Math.Abs(FinalRateAdjustment));
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
private readonly double firstHitObjectTime;
|
||||
|
||||
public readonly Bindable<double> UserPlaybackRate = new BindableDouble(1)
|
||||
public readonly BindableNumber<double> UserPlaybackRate = new BindableDouble(1)
|
||||
{
|
||||
Default = 1,
|
||||
MinValue = 0.5,
|
||||
@ -73,7 +73,6 @@ namespace osu.Game.Screens.Play
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
|
||||
track = beatmap.Track;
|
||||
track.AddAdjustment(AdjustableProperty.Frequency, pauseFreqAdjust);
|
||||
|
||||
adjustableClock = new DecoupleableInterpolatingFramedClock { IsCoupled = false };
|
||||
|
||||
@ -120,7 +119,6 @@ namespace osu.Game.Screens.Play
|
||||
Seek(startTime);
|
||||
|
||||
adjustableClock.ProcessFrame();
|
||||
UserPlaybackRate.ValueChanged += _ => updateRate();
|
||||
}
|
||||
|
||||
public void Restart()
|
||||
@ -223,7 +221,8 @@ namespace osu.Game.Screens.Play
|
||||
speedAdjustmentsApplied = true;
|
||||
track.ResetSpeedAdjustments();
|
||||
|
||||
track.Tempo.Value = UserPlaybackRate.Value;
|
||||
track.AddAdjustment(AdjustableProperty.Frequency, pauseFreqAdjust);
|
||||
track.AddAdjustment(AdjustableProperty.Tempo, UserPlaybackRate);
|
||||
|
||||
foreach (var mod in mods.OfType<IApplicableToTrack>())
|
||||
mod.ApplyToTrack(track);
|
||||
@ -244,8 +243,6 @@ namespace osu.Game.Screens.Play
|
||||
track.ResetSpeedAdjustments();
|
||||
speedAdjustmentsApplied = false;
|
||||
}
|
||||
|
||||
track.RemoveAdjustment(AdjustableProperty.Frequency, pauseFreqAdjust);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user