mirror of
https://github.com/ppy/osu.git
synced 2024-11-13 18:07:25 +08:00
Split common functionality from rate adjust mods into helper class
This commit is contained in:
parent
eabfcfbf2a
commit
43238b0cee
@ -71,7 +71,6 @@ namespace osu.Game.Rulesets.Mods
|
||||
// Apply a fixed rate change when missing, allowing the player to catch up when the rate is too fast.
|
||||
private const double rate_change_on_miss = 0.95d;
|
||||
|
||||
private IAdjustableAudioComponent? track;
|
||||
private double targetRate = 1d;
|
||||
|
||||
/// <summary>
|
||||
@ -123,24 +122,26 @@ namespace osu.Game.Rulesets.Mods
|
||||
/// </summary>
|
||||
private readonly Dictionary<HitObject, double> ratesForRewinding = new Dictionary<HitObject, double>();
|
||||
|
||||
private readonly RateAdjustModHelper rateAdjustHelper;
|
||||
|
||||
public ModAdaptiveSpeed()
|
||||
{
|
||||
rateAdjustHelper = new RateAdjustModHelper(SpeedChange, AdjustPitch);
|
||||
|
||||
InitialRate.BindValueChanged(val =>
|
||||
{
|
||||
SpeedChange.Value = val.NewValue;
|
||||
targetRate = val.NewValue;
|
||||
});
|
||||
AdjustPitch.BindValueChanged(adjustPitchChanged);
|
||||
}
|
||||
|
||||
public void ApplyToTrack(IAdjustableAudioComponent track)
|
||||
{
|
||||
this.track = track;
|
||||
|
||||
InitialRate.TriggerChange();
|
||||
AdjustPitch.TriggerChange();
|
||||
recentRates.Clear();
|
||||
recentRates.AddRange(Enumerable.Repeat(InitialRate.Value, recent_rate_count));
|
||||
|
||||
rateAdjustHelper.ApplyToTrack(track);
|
||||
}
|
||||
|
||||
public void ApplyToSample(IAdjustableAudioComponent sample)
|
||||
@ -199,15 +200,6 @@ namespace osu.Game.Rulesets.Mods
|
||||
}
|
||||
}
|
||||
|
||||
private void adjustPitchChanged(ValueChangedEvent<bool> adjustPitchSetting)
|
||||
{
|
||||
track?.RemoveAdjustment(adjustmentForPitchSetting(adjustPitchSetting.OldValue), SpeedChange);
|
||||
track?.AddAdjustment(adjustmentForPitchSetting(adjustPitchSetting.NewValue), SpeedChange);
|
||||
}
|
||||
|
||||
private AdjustableProperty adjustmentForPitchSetting(bool adjustPitchSettingValue)
|
||||
=> adjustPitchSettingValue ? AdjustableProperty.Frequency : AdjustableProperty.Tempo;
|
||||
|
||||
private IEnumerable<HitObject> getAllApplicableHitObjects(IEnumerable<HitObject> hitObjects)
|
||||
{
|
||||
foreach (var hitObject in hitObjects)
|
||||
|
@ -39,7 +39,6 @@ namespace osu.Game.Rulesets.Mods
|
||||
|
||||
public override void ApplyToTrack(IAdjustableAudioComponent track)
|
||||
{
|
||||
// base.ApplyToTrack() intentionally not called (different tempo adjustment is applied)
|
||||
track.AddAdjustment(AdjustableProperty.Frequency, freqAdjust);
|
||||
track.AddAdjustment(AdjustableProperty.Tempo, tempoAdjust);
|
||||
}
|
||||
|
@ -27,29 +27,19 @@ namespace osu.Game.Rulesets.Mods
|
||||
Precision = 0.01,
|
||||
};
|
||||
|
||||
private IAdjustableAudioComponent? track;
|
||||
|
||||
[SettingSource("Adjust pitch", "Should pitch be adjusted with speed")]
|
||||
public virtual BindableBool AdjustPitch { get; } = new BindableBool(false);
|
||||
public virtual BindableBool AdjustPitch { get; } = new BindableBool();
|
||||
|
||||
private readonly RateAdjustModHelper rateAdjustHelper;
|
||||
|
||||
protected ModDoubleTime()
|
||||
{
|
||||
AdjustPitch.BindValueChanged(adjustPitchChanged);
|
||||
rateAdjustHelper = new RateAdjustModHelper(SpeedChange, AdjustPitch);
|
||||
}
|
||||
|
||||
private void adjustPitchChanged(ValueChangedEvent<bool> adjustPitchSetting)
|
||||
{
|
||||
track?.RemoveAdjustment(adjustmentForPitchSetting(adjustPitchSetting.OldValue), SpeedChange);
|
||||
track?.AddAdjustment(adjustmentForPitchSetting(adjustPitchSetting.NewValue), SpeedChange);
|
||||
}
|
||||
|
||||
private AdjustableProperty adjustmentForPitchSetting(bool adjustPitchSettingValue)
|
||||
=> adjustPitchSettingValue ? AdjustableProperty.Frequency : AdjustableProperty.Tempo;
|
||||
|
||||
public override void ApplyToTrack(IAdjustableAudioComponent track)
|
||||
{
|
||||
this.track = track;
|
||||
AdjustPitch.TriggerChange();
|
||||
rateAdjustHelper.ApplyToTrack(track);
|
||||
}
|
||||
|
||||
public override double ScoreMultiplier
|
||||
|
@ -27,29 +27,19 @@ namespace osu.Game.Rulesets.Mods
|
||||
Precision = 0.01,
|
||||
};
|
||||
|
||||
private IAdjustableAudioComponent? track;
|
||||
|
||||
[SettingSource("Adjust pitch", "Should pitch be adjusted with speed")]
|
||||
public virtual BindableBool AdjustPitch { get; } = new BindableBool(false);
|
||||
public virtual BindableBool AdjustPitch { get; } = new BindableBool();
|
||||
|
||||
private readonly RateAdjustModHelper rateAdjustHelper;
|
||||
|
||||
protected ModHalfTime()
|
||||
{
|
||||
AdjustPitch.BindValueChanged(adjustPitchChanged);
|
||||
rateAdjustHelper = new RateAdjustModHelper(SpeedChange, AdjustPitch);
|
||||
}
|
||||
|
||||
private void adjustPitchChanged(ValueChangedEvent<bool> adjustPitchSetting)
|
||||
{
|
||||
track?.RemoveAdjustment(adjustmentForPitchSetting(adjustPitchSetting.OldValue), SpeedChange);
|
||||
track?.AddAdjustment(adjustmentForPitchSetting(adjustPitchSetting.NewValue), SpeedChange);
|
||||
}
|
||||
|
||||
private AdjustableProperty adjustmentForPitchSetting(bool adjustPitchSettingValue)
|
||||
=> adjustPitchSettingValue ? AdjustableProperty.Frequency : AdjustableProperty.Tempo;
|
||||
|
||||
public override void ApplyToTrack(IAdjustableAudioComponent track)
|
||||
{
|
||||
this.track = track;
|
||||
AdjustPitch.TriggerChange();
|
||||
rateAdjustHelper.ApplyToTrack(track);
|
||||
}
|
||||
|
||||
public override double ScoreMultiplier
|
||||
|
@ -36,27 +36,6 @@ namespace osu.Game.Rulesets.Mods
|
||||
Precision = 0.01,
|
||||
};
|
||||
|
||||
public override double ScoreMultiplier
|
||||
{
|
||||
get
|
||||
{
|
||||
// Round to the nearest multiple of 0.1.
|
||||
double value = (int)(SpeedChange.Value * 10) / 10.0;
|
||||
|
||||
// Offset back to 0.
|
||||
value -= 1;
|
||||
|
||||
// Each 0.1 multiple changes score multiplier by 0.02.
|
||||
value /= 5;
|
||||
|
||||
return 1 + value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract partial class ModNightcore<TObject> : ModNightcore, IApplicableToDrawableRuleset<TObject>
|
||||
where TObject : HitObject
|
||||
{
|
||||
private readonly BindableNumber<double> tempoAdjust = new BindableDouble(1);
|
||||
private readonly BindableNumber<double> freqAdjust = new BindableDouble(1);
|
||||
|
||||
@ -71,11 +50,28 @@ namespace osu.Game.Rulesets.Mods
|
||||
|
||||
public override void ApplyToTrack(IAdjustableAudioComponent track)
|
||||
{
|
||||
// base.ApplyToTrack() intentionally not called (different tempo adjustment is applied)
|
||||
track.AddAdjustment(AdjustableProperty.Frequency, freqAdjust);
|
||||
track.AddAdjustment(AdjustableProperty.Tempo, tempoAdjust);
|
||||
}
|
||||
|
||||
public override double ScoreMultiplier
|
||||
{
|
||||
get
|
||||
{
|
||||
// Round to the nearest multiple of 0.1.
|
||||
double value = (int)(SpeedChange.Value * 10) / 10.0;
|
||||
|
||||
// Offset back to 0.
|
||||
value -= 1;
|
||||
|
||||
return 1 + value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract partial class ModNightcore<TObject> : ModNightcore, IApplicableToDrawableRuleset<TObject>
|
||||
where TObject : HitObject
|
||||
{
|
||||
public void ApplyToDrawableRuleset(DrawableRuleset<TObject> drawableRuleset)
|
||||
{
|
||||
drawableRuleset.Overlays.Add(new NightcoreBeatContainer());
|
||||
|
@ -44,21 +44,20 @@ namespace osu.Game.Rulesets.Mods
|
||||
Precision = 0.01,
|
||||
};
|
||||
|
||||
private IAdjustableAudioComponent? track;
|
||||
private readonly RateAdjustModHelper rateAdjustHelper;
|
||||
|
||||
protected ModTimeRamp()
|
||||
{
|
||||
rateAdjustHelper = new RateAdjustModHelper(SpeedChange, AdjustPitch);
|
||||
|
||||
// for preview purpose at song select. eventually we'll want to be able to update every frame.
|
||||
FinalRate.BindValueChanged(_ => applyRateAdjustment(double.PositiveInfinity), true);
|
||||
AdjustPitch.BindValueChanged(applyPitchAdjustment);
|
||||
}
|
||||
|
||||
public void ApplyToTrack(IAdjustableAudioComponent track)
|
||||
{
|
||||
this.track = track;
|
||||
|
||||
rateAdjustHelper.ApplyToTrack(track);
|
||||
FinalRate.TriggerChange();
|
||||
AdjustPitch.TriggerChange();
|
||||
}
|
||||
|
||||
public void ApplyToSample(IAdjustableAudioComponent sample)
|
||||
@ -95,16 +94,5 @@ namespace osu.Game.Rulesets.Mods
|
||||
/// Adjust the rate along the specified ramp.
|
||||
/// </summary>
|
||||
private void applyRateAdjustment(double time) => SpeedChange.Value = ApplyToRate(time);
|
||||
|
||||
private void applyPitchAdjustment(ValueChangedEvent<bool> adjustPitchSetting)
|
||||
{
|
||||
// remove existing old adjustment
|
||||
track?.RemoveAdjustment(adjustmentForPitchSetting(adjustPitchSetting.OldValue), SpeedChange);
|
||||
|
||||
track?.AddAdjustment(adjustmentForPitchSetting(adjustPitchSetting.NewValue), SpeedChange);
|
||||
}
|
||||
|
||||
private AdjustableProperty adjustmentForPitchSetting(bool adjustPitchSettingValue)
|
||||
=> adjustPitchSettingValue ? AdjustableProperty.Frequency : AdjustableProperty.Tempo;
|
||||
}
|
||||
}
|
||||
|
36
osu.Game/Rulesets/Mods/RateAdjustModHelper.cs
Normal file
36
osu.Game/Rulesets/Mods/RateAdjustModHelper.cs
Normal file
@ -0,0 +1,36 @@
|
||||
// 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.Bindables;
|
||||
|
||||
namespace osu.Game.Rulesets.Mods
|
||||
{
|
||||
public class RateAdjustModHelper : IApplicableToTrack
|
||||
{
|
||||
private readonly BindableBool? adjustPitch;
|
||||
private IAdjustableAudioComponent? track;
|
||||
|
||||
public RateAdjustModHelper(BindableNumber<double> speedChange, BindableBool? adjustPitch)
|
||||
{
|
||||
this.adjustPitch = adjustPitch;
|
||||
|
||||
// When switching between pitch adjust, we need to update adjustments to time-shift or frequency-scale.
|
||||
adjustPitch?.BindValueChanged(adjustPitchSetting =>
|
||||
{
|
||||
track?.RemoveAdjustment(adjustmentForPitchSetting(adjustPitchSetting.OldValue), speedChange);
|
||||
track?.AddAdjustment(adjustmentForPitchSetting(adjustPitchSetting.NewValue), speedChange);
|
||||
|
||||
AdjustableProperty adjustmentForPitchSetting(bool adjustPitchSettingValue)
|
||||
=> adjustPitchSettingValue ? AdjustableProperty.Frequency : AdjustableProperty.Tempo;
|
||||
});
|
||||
}
|
||||
|
||||
public void ApplyToTrack(IAdjustableAudioComponent track)
|
||||
{
|
||||
this.track = track;
|
||||
|
||||
adjustPitch?.TriggerChange();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user