1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 21:43:04 +08:00

Merge branch 'apply-to-track' into adjustable-double-time

This commit is contained in:
Dean Herbert 2019-12-09 17:45:19 +09:00
commit ba538cf09b
14 changed files with 54 additions and 85 deletions

View File

@ -57,8 +57,8 @@ namespace osu.Game.Tests.Visual.Gameplay
beforeLoadAction?.Invoke();
Beatmap.Value = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
foreach (var mod in Mods.Value.OfType<IApplicableToClock>())
mod.ApplyToClock(Beatmap.Value.Track);
foreach (var mod in Mods.Value.OfType<IApplicableToTrack>())
mod.ApplyToTrack(Beatmap.Value.Track);
InputManager.Child = container = new TestPlayerLoaderContainer(
loader = new TestPlayerLoader(() =>

View File

@ -261,8 +261,8 @@ namespace osu.Game.Overlays
if (allowRateAdjustments)
{
foreach (var mod in mods.Value.OfType<IApplicableToClock>())
mod.ApplyToClock(track);
foreach (var mod in mods.Value.OfType<IApplicableToTrack>())
mod.ApplyToTrack(track);
}
}

View File

@ -4,8 +4,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Audio.Track;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Difficulty.Preprocessing;
using osu.Game.Rulesets.Difficulty.Skills;
@ -41,10 +41,10 @@ namespace osu.Game.Rulesets.Difficulty
IBeatmap playableBeatmap = beatmap.GetPlayableBeatmap(ruleset.RulesetInfo, mods);
var clock = new StopwatchClock();
mods.OfType<IApplicableToClock>().ForEach(m => m.ApplyToClock(clock));
var track = new TrackVirtual(10000);
mods.OfType<IApplicableToTrack>().ForEach(m => m.ApplyToTrack(track));
return calculate(playableBeatmap, mods, clock.Rate);
return calculate(playableBeatmap, mods, track.Rate);
}
/// <summary>

View File

@ -3,8 +3,8 @@
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Audio.Track;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Mods;
using osu.Game.Scoring;
@ -35,9 +35,9 @@ namespace osu.Game.Rulesets.Difficulty
protected virtual void ApplyMods(Mod[] mods)
{
var clock = new StopwatchClock();
mods.OfType<IApplicableToClock>().ForEach(m => m.ApplyToClock(clock));
TimeRate = clock.Rate;
var track = new TrackVirtual(10000);
mods.OfType<IApplicableToTrack>().ForEach(m => m.ApplyToTrack(track));
TimeRate = track.Rate;
}
public abstract double Calculate(Dictionary<string, double> categoryDifficulty = null);

View File

@ -1,15 +1,15 @@
// 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.Timing;
using osu.Framework.Audio.Track;
namespace osu.Game.Rulesets.Mods
{
/// <summary>
/// An interface for mods that make adjustments to the track.
/// </summary>
public interface IApplicableToClock : IApplicableMod
public interface IApplicableToTrack : IApplicableMod
{
void ApplyToClock(IAdjustableClock clock);
void ApplyToTrack(Track track);
}
}

View File

@ -1,9 +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 osu.Framework.Audio;
using osu.Framework.Audio.Track;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Timing;
namespace osu.Game.Rulesets.Mods
{
@ -14,12 +13,9 @@ namespace osu.Game.Rulesets.Mods
public override IconUsage Icon => FontAwesome.Solid.Question;
public override string Description => "Whoaaaaa...";
public override void ApplyToClock(IAdjustableClock clock)
public override void ApplyToTrack(Track track)
{
if (clock is IHasPitchAdjust pitchAdjust)
pitchAdjust.PitchAdjust *= RateAdjust;
else
base.ApplyToClock(clock);
track.Frequency.Value *= RateAdjust;
}
}
}

View File

@ -10,7 +10,7 @@ using osu.Game.Graphics;
namespace osu.Game.Rulesets.Mods
{
public abstract class ModDoubleTime : ModTimeAdjust, IApplicableToClock
public abstract class ModDoubleTime : ModTimeAdjust
{
public override string Name => "Double Time";
public override string Acronym => "DT";

View File

@ -10,7 +10,7 @@ using osu.Game.Graphics;
namespace osu.Game.Rulesets.Mods
{
public abstract class ModHalfTime : ModTimeAdjust, IApplicableToClock
public abstract class ModHalfTime : ModTimeAdjust
{
public override string Name => "Half Time";
public override string Acronym => "HT";

View File

@ -1,9 +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 osu.Framework.Audio;
using osu.Framework.Audio.Track;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Timing;
using osu.Game.Graphics;
namespace osu.Game.Rulesets.Mods
@ -15,12 +14,9 @@ namespace osu.Game.Rulesets.Mods
public override IconUsage Icon => OsuIcon.ModNightcore;
public override string Description => "Uguuuuuuuu...";
public override void ApplyToClock(IAdjustableClock clock)
public override void ApplyToTrack(Track track)
{
if (clock is IHasPitchAdjust pitchAdjust)
pitchAdjust.PitchAdjust *= RateAdjust;
else
base.ApplyToClock(clock);
track.Frequency.Value *= RateAdjust;
}
}
}

View File

@ -2,23 +2,19 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Audio;
using osu.Framework.Timing;
using osu.Framework.Audio.Track;
namespace osu.Game.Rulesets.Mods
{
public abstract class ModTimeAdjust : Mod
public abstract class ModTimeAdjust : Mod, IApplicableToTrack
{
public override Type[] IncompatibleMods => new[] { typeof(ModTimeRamp) };
protected abstract double RateAdjust { get; }
public virtual void ApplyToClock(IAdjustableClock clock)
public virtual void ApplyToTrack(Track track)
{
if (clock is IHasTempoAdjust tempo)
tempo.TempoAdjust *= RateAdjust;
else
clock.Rate *= RateAdjust;
track.TempoAdjust *= RateAdjust;
}
}
}

View File

@ -3,15 +3,14 @@
using System;
using System.Linq;
using osu.Framework.Audio;
using osu.Framework.Timing;
using osu.Framework.Audio.Track;
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, IApplicableToClock, IApplicableToBeatmap
public abstract class ModTimeRamp : Mod, IUpdatableByPlayfield, IApplicableToTrack, IApplicableToBeatmap
{
/// <summary>
/// The point in the beatmap at which the final ramping rate should be reached.
@ -24,11 +23,11 @@ namespace osu.Game.Rulesets.Mods
private double finalRateTime;
private double beginRampTime;
private IAdjustableClock clock;
private Track track;
public virtual void ApplyToClock(IAdjustableClock clock)
public virtual void ApplyToTrack(Track track)
{
this.clock = clock;
this.track = track;
lastAdjust = 1;
@ -46,7 +45,7 @@ namespace osu.Game.Rulesets.Mods
public virtual void Update(Playfield playfield)
{
applyAdjustment((clock.CurrentTime - beginRampTime) / finalRateTime);
applyAdjustment((track.CurrentTime - beginRampTime) / finalRateTime);
}
private double lastAdjust = 1;
@ -59,23 +58,8 @@ namespace osu.Game.Rulesets.Mods
{
double adjust = 1 + (Math.Sign(FinalRateAdjustment) * Math.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;
}
track.Tempo.Value /= lastAdjust;
track.Tempo.Value *= lastAdjust;
lastAdjust = adjust;
}

View File

@ -28,9 +28,9 @@ namespace osu.Game.Screens.Play
private readonly IReadOnlyList<Mod> mods;
/// <summary>
/// The original source (usually a <see cref="WorkingBeatmap"/>'s track).
/// The <see cref="WorkingBeatmap"/>'s track.
/// </summary>
private IAdjustableClock sourceClock;
private Track track;
public readonly BindableBool IsPaused = new BindableBool();
@ -72,8 +72,8 @@ namespace osu.Game.Screens.Play
RelativeSizeAxes = Axes.Both;
sourceClock = (IAdjustableClock)beatmap.Track ?? new StopwatchClock();
(sourceClock as IAdjustableAudioComponent)?.AddAdjustment(AdjustableProperty.Frequency, pauseFreqAdjust);
track = beatmap.Track;
track.AddAdjustment(AdjustableProperty.Frequency, pauseFreqAdjust);
adjustableClock = new DecoupleableInterpolatingFramedClock { IsCoupled = false };
@ -127,11 +127,11 @@ namespace osu.Game.Screens.Play
{
Task.Run(() =>
{
sourceClock.Reset();
track.Reset();
Schedule(() =>
{
adjustableClock.ChangeSource(sourceClock);
adjustableClock.ChangeSource(track);
updateRate();
if (!IsPaused.Value)
@ -197,13 +197,13 @@ namespace osu.Game.Screens.Play
/// </summary>
public void StopUsingBeatmapClock()
{
if (sourceClock != beatmap.Track)
if (track != beatmap.Track)
return;
removeSourceClockAdjustments();
sourceClock = new TrackVirtual(beatmap.Track.Length);
adjustableClock.ChangeSource(sourceClock);
track = new TrackVirtual(beatmap.Track.Length);
adjustableClock.ChangeSource(track);
}
protected override void Update()
@ -218,18 +218,15 @@ namespace osu.Game.Screens.Play
private void updateRate()
{
if (sourceClock == null) return;
if (track == null) return;
speedAdjustmentsApplied = true;
sourceClock.ResetSpeedAdjustments();
track.ResetSpeedAdjustments();
if (sourceClock is IHasTempoAdjust tempo)
tempo.TempoAdjust = UserPlaybackRate.Value;
else
sourceClock.Rate = UserPlaybackRate.Value;
track.Tempo.Value = UserPlaybackRate.Value;
foreach (var mod in mods.OfType<IApplicableToClock>())
mod.ApplyToClock(sourceClock);
foreach (var mod in mods.OfType<IApplicableToTrack>())
mod.ApplyToTrack(track);
}
protected override void Dispose(bool isDisposing)
@ -237,18 +234,18 @@ namespace osu.Game.Screens.Play
base.Dispose(isDisposing);
removeSourceClockAdjustments();
sourceClock = null;
track = null;
}
private void removeSourceClockAdjustments()
{
if (speedAdjustmentsApplied)
{
sourceClock.ResetSpeedAdjustments();
track.ResetSpeedAdjustments();
speedAdjustmentsApplied = false;
}
(sourceClock as IAdjustableAudioComponent)?.RemoveAdjustment(AdjustableProperty.Frequency, pauseFreqAdjust);
(track as IAdjustableAudioComponent)?.RemoveAdjustment(AdjustableProperty.Frequency, pauseFreqAdjust);
}
}
}

View File

@ -27,6 +27,6 @@
<PackageReference Include="Sentry" Version="1.2.0" />
<PackageReference Include="SharpCompress" Version="0.24.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.6.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
</ItemGroup>
</Project>

View File

@ -86,7 +86,7 @@
<PackageReference Include="SharpCompress" Version="0.24.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="SharpRaven" Version="2.4.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.6.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
<PackageReference Include="ppy.osu.Framework.NativeLibs" Version="2019.1104.0" ExcludeAssets="all" />
</ItemGroup>
</Project>