1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 18:23:04 +08:00

Pass track from Player to components

This commit is contained in:
smoogipoo 2020-08-06 18:31:08 +09:00
parent 7c3ae4ed42
commit 2e3ecf71c7
6 changed files with 36 additions and 30 deletions

View File

@ -19,7 +19,12 @@ namespace osu.Game.Tests.Gameplay
{
GameplayClockContainer gcc = null;
AddStep("create container", () => Add(gcc = new GameplayClockContainer(CreateWorkingBeatmap(new OsuRuleset().RulesetInfo), Array.Empty<Mod>(), 0)));
AddStep("create container", () =>
{
var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
Add(gcc = new GameplayClockContainer(working.GetRealTrack(), working, Array.Empty<Mod>(), 0));
});
AddStep("start track", () => gcc.Start());
AddUntilStep("elapsed greater than zero", () => gcc.GameplayClock.ElapsedFrameTime > 0);
}

View File

@ -59,7 +59,9 @@ namespace osu.Game.Tests.Gameplay
AddStep("create container", () =>
{
Add(gameplayContainer = new GameplayClockContainer(CreateWorkingBeatmap(new OsuRuleset().RulesetInfo), Array.Empty<Mod>(), 0));
var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
Add(gameplayContainer = new GameplayClockContainer(working.GetRealTrack(), working, Array.Empty<Mod>(), 0));
gameplayContainer.Add(sample = new DrawableStoryboardSample(new StoryboardSampleInfo(string.Empty, 0, 1))
{
@ -103,7 +105,7 @@ namespace osu.Game.Tests.Gameplay
Beatmap.Value = new TestCustomSkinWorkingBeatmap(new OsuRuleset().RulesetInfo, Audio);
SelectedMods.Value = new[] { testedMod };
Add(gameplayContainer = new GameplayClockContainer(Beatmap.Value, SelectedMods.Value, 0));
Add(gameplayContainer = new GameplayClockContainer(MusicController.CurrentTrack, Beatmap.Value, SelectedMods.Value, 0));
gameplayContainer.Add(sample = new TestDrawableStoryboardSample(new StoryboardSampleInfo("test-sample", 1, 1))
{

View File

@ -32,7 +32,9 @@ namespace osu.Game.Tests.Visual.Gameplay
requestCount = 0;
increment = skip_time;
Child = gameplayClockContainer = new GameplayClockContainer(CreateWorkingBeatmap(CreateBeatmap(new OsuRuleset().RulesetInfo)), Array.Empty<Mod>(), 0)
var working = CreateWorkingBeatmap(CreateBeatmap(new OsuRuleset().RulesetInfo));
Child = gameplayClockContainer = new GameplayClockContainer(working.GetRealTrack(), working, Array.Empty<Mod>(), 0)
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]

View File

@ -8,11 +8,10 @@ using System;
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Audio.Sample;
using osu.Framework.Audio.Track;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Audio;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Overlays;
using osu.Game.Rulesets.Objects.Drawables;
using osuTK;
using osuTK.Graphics;
@ -28,24 +27,23 @@ namespace osu.Game.Screens.Play
public Action OnComplete;
private readonly DrawableRuleset drawableRuleset;
private readonly ITrack track;
private readonly BindableDouble trackFreq = new BindableDouble(1);
private DrawableTrack track;
private const float duration = 2500;
private SampleChannel failSample;
public FailAnimation(DrawableRuleset drawableRuleset)
public FailAnimation(DrawableRuleset drawableRuleset, ITrack track)
{
this.drawableRuleset = drawableRuleset;
this.track = track;
}
[BackgroundDependencyLoader]
private void load(AudioManager audio, IBindable<WorkingBeatmap> beatmap, MusicController musicController)
private void load(AudioManager audio, IBindable<WorkingBeatmap> beatmap)
{
track = musicController.CurrentTrack;
failSample = audio.Samples.Get(@"Gameplay/failsound");
}
@ -69,7 +67,7 @@ namespace osu.Game.Screens.Play
Expire();
});
track.AddAdjustment(AdjustableProperty.Frequency, trackFreq);
(track as IAdjustableAudioComponent)?.AddAdjustment(AdjustableProperty.Frequency, trackFreq);
applyToPlayfield(drawableRuleset.Playfield);
drawableRuleset.Playfield.HitObjectContainer.FlashColour(Color4.Red, 500);
@ -108,7 +106,7 @@ namespace osu.Game.Screens.Play
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
track?.RemoveAdjustment(AdjustableProperty.Frequency, trackFreq);
(track as IAdjustableAudioComponent)?.RemoveAdjustment(AdjustableProperty.Frequency, trackFreq);
}
}
}

View File

@ -11,12 +11,10 @@ using osu.Framework.Audio;
using osu.Framework.Audio.Track;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Audio;
using osu.Framework.Graphics.Containers;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Overlays;
using osu.Game.Rulesets.Mods;
namespace osu.Game.Screens.Play
@ -29,7 +27,7 @@ namespace osu.Game.Screens.Play
private readonly WorkingBeatmap beatmap;
private readonly IReadOnlyList<Mod> mods;
private DrawableTrack track;
private ITrack track;
public readonly BindableBool IsPaused = new BindableBool();
@ -62,11 +60,13 @@ namespace osu.Game.Screens.Play
private readonly FramedOffsetClock platformOffsetClock;
public GameplayClockContainer(WorkingBeatmap beatmap, IReadOnlyList<Mod> mods, double gameplayStartTime)
public GameplayClockContainer(ITrack track, WorkingBeatmap beatmap, IReadOnlyList<Mod> mods, double gameplayStartTime)
{
this.beatmap = beatmap;
this.mods = mods;
this.gameplayStartTime = gameplayStartTime;
this.track = track;
firstHitObjectTime = beatmap.Beatmap.HitObjects.First().StartTime;
RelativeSizeAxes = Axes.Both;
@ -96,10 +96,8 @@ namespace osu.Game.Screens.Play
private readonly BindableDouble pauseFreqAdjust = new BindableDouble(1);
[BackgroundDependencyLoader]
private void load(OsuConfigManager config, MusicController musicController)
private void load(OsuConfigManager config)
{
track = musicController.CurrentTrack;
userAudioOffset = config.GetBindable<double>(OsuSetting.AudioOffset);
userAudioOffset.BindValueChanged(offset => userOffsetClock.Offset = offset.NewValue, true);
@ -132,7 +130,7 @@ namespace osu.Game.Screens.Play
Schedule(() =>
{
adjustableClock.ChangeSource(track);
adjustableClock.ChangeSource((IAdjustableClock)track);
updateRate();
if (!IsPaused.Value)
@ -203,8 +201,8 @@ namespace osu.Game.Screens.Play
removeSourceClockAdjustments();
track = new DrawableTrack(new TrackVirtual(track.Length));
adjustableClock.ChangeSource(track);
track = new TrackVirtual(track.Length);
adjustableClock.ChangeSource((IAdjustableClock)track);
}
protected override void Update()
@ -224,8 +222,8 @@ namespace osu.Game.Screens.Play
speedAdjustmentsApplied = true;
track.ResetSpeedAdjustments();
track.AddAdjustment(AdjustableProperty.Frequency, pauseFreqAdjust);
track.AddAdjustment(AdjustableProperty.Tempo, UserPlaybackRate);
(track as IAdjustableAudioComponent)?.AddAdjustment(AdjustableProperty.Frequency, pauseFreqAdjust);
(track as IAdjustableAudioComponent)?.AddAdjustment(AdjustableProperty.Tempo, UserPlaybackRate);
foreach (var mod in mods.OfType<IApplicableToTrack>())
mod.ApplyToTrack(track);

View File

@ -8,6 +8,7 @@ using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Audio.Track;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -150,7 +151,7 @@ namespace osu.Game.Screens.Play
}
[BackgroundDependencyLoader]
private void load(AudioManager audio, OsuConfigManager config)
private void load(AudioManager audio, OsuConfigManager config, MusicController musicController)
{
Mods.Value = base.Mods.Value.Select(m => m.CreateCopy()).ToArray();
@ -178,7 +179,7 @@ namespace osu.Game.Screens.Play
if (!ScoreProcessor.Mode.Disabled)
config.BindWith(OsuSetting.ScoreDisplayMode, ScoreProcessor.Mode);
InternalChild = GameplayClockContainer = new GameplayClockContainer(Beatmap.Value, Mods.Value, DrawableRuleset.GameplayStartTime);
InternalChild = GameplayClockContainer = new GameplayClockContainer(musicController.CurrentTrack, Beatmap.Value, Mods.Value, DrawableRuleset.GameplayStartTime);
AddInternal(gameplayBeatmap = new GameplayBeatmap(playableBeatmap));
AddInternal(screenSuspension = new ScreenSuspensionHandler(GameplayClockContainer));
@ -187,7 +188,7 @@ namespace osu.Game.Screens.Play
addUnderlayComponents(GameplayClockContainer);
addGameplayComponents(GameplayClockContainer, Beatmap.Value, playableBeatmap);
addOverlayComponents(GameplayClockContainer, Beatmap.Value);
addOverlayComponents(GameplayClockContainer, Beatmap.Value, musicController.CurrentTrack);
if (!DrawableRuleset.AllowGameplayOverlays)
{
@ -264,7 +265,7 @@ namespace osu.Game.Screens.Play
});
}
private void addOverlayComponents(Container target, WorkingBeatmap working)
private void addOverlayComponents(Container target, WorkingBeatmap working, ITrack track)
{
target.AddRange(new[]
{
@ -331,7 +332,7 @@ namespace osu.Game.Screens.Play
performImmediateExit();
},
},
failAnimation = new FailAnimation(DrawableRuleset) { OnComplete = onFailComplete, },
failAnimation = new FailAnimation(DrawableRuleset, track) { OnComplete = onFailComplete, },
});
}