1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 06:42:54 +08:00

Add explicit LoadTrack method

This commit is contained in:
Dean Herbert 2020-08-17 15:38:16 +09:00
parent 0c4aefb15e
commit d9debef156
10 changed files with 37 additions and 12 deletions

View File

@ -22,7 +22,9 @@ namespace osu.Game.Tests.Gameplay
AddStep("create container", () =>
{
var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
Add(gcc = new GameplayClockContainer(working.GetTrack(), working, Array.Empty<Mod>(), 0));
working.LoadTrack();
Add(gcc = new GameplayClockContainer(working, Array.Empty<Mod>(), 0));
});
AddStep("start track", () => gcc.Start());

View File

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

View File

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

View File

@ -58,6 +58,6 @@ namespace osu.Game.Beatmaps
/// <summary>
/// Retrieves the <see cref="Track"/> which this <see cref="WorkingBeatmap"/> provides.
/// </summary>
Track GetTrack();
Track LoadTrack();
}
}

View File

@ -250,8 +250,29 @@ namespace osu.Game.Beatmaps
protected abstract Texture GetBackground();
private readonly RecyclableLazy<Texture> background;
private Track loadedTrack;
/// <summary>
/// Load a new audio track instance for this beatmap.
/// </summary>
/// <returns>A fresh track instance, which will also be available via <see cref="Track"/>.</returns>
[NotNull]
public Track GetTrack() => GetBeatmapTrack() ?? GetVirtualTrack(1000);
public Track LoadTrack() => loadedTrack = GetBeatmapTrack() ?? GetVirtualTrack(1000);
/// <summary>
/// Get the loaded audio track instance. <see cref="LoadTrack"/> must have first been called.
/// This generally happens via MusicController when changing the global beatmap.
/// </summary>
public Track Track
{
get
{
if (loadedTrack == null)
throw new InvalidOperationException($"Cannot access {nameof(Track)} without first calling {nameof(LoadTrack)}.");
return loadedTrack;
}
}
protected abstract Track GetBeatmapTrack();

View File

@ -319,7 +319,7 @@ namespace osu.Game.Overlays
{
var lastTrack = CurrentTrack;
var newTrack = new DrawableTrack(current.GetTrack());
var newTrack = new DrawableTrack(current.LoadTrack());
newTrack.Completed += () => onTrackCompleted(current);
CurrentTrack = newTrack;

View File

@ -26,7 +26,7 @@ namespace osu.Game.Screens.Edit
private readonly DecoupleableInterpolatingFramedClock underlyingClock;
public EditorClock(WorkingBeatmap beatmap, BindableBeatDivisor beatDivisor)
: this(beatmap.Beatmap.ControlPointInfo, beatmap.GetTrack().Length, beatDivisor)
: this(beatmap.Beatmap.ControlPointInfo, beatmap.Track.Length, beatDivisor)
{
}

View File

@ -115,7 +115,7 @@ namespace osu.Game.Screens.Menu
if (setInfo != null)
{
initialBeatmap = beatmaps.GetWorkingBeatmap(setInfo.Beatmaps[0]);
UsingThemedIntro = !initialBeatmap.GetTrack().IsDummyDevice;
UsingThemedIntro = !initialBeatmap.LoadTrack().IsDummyDevice;
}
return UsingThemedIntro;

View File

@ -62,12 +62,12 @@ namespace osu.Game.Screens.Play
private readonly FramedOffsetClock platformOffsetClock;
public GameplayClockContainer([NotNull] ITrack track, WorkingBeatmap beatmap, IReadOnlyList<Mod> mods, double gameplayStartTime)
public GameplayClockContainer(WorkingBeatmap beatmap, IReadOnlyList<Mod> mods, double gameplayStartTime)
{
this.beatmap = beatmap;
this.mods = mods;
this.gameplayStartTime = gameplayStartTime;
this.track = track;
track = beatmap.Track;
firstHitObjectTime = beatmap.Beatmap.HitObjects.First().StartTime;

View File

@ -179,7 +179,7 @@ namespace osu.Game.Screens.Play
if (!ScoreProcessor.Mode.Disabled)
config.BindWith(OsuSetting.ScoreDisplayMode, ScoreProcessor.Mode);
InternalChild = GameplayClockContainer = new GameplayClockContainer(musicController.CurrentTrack, Beatmap.Value, Mods.Value, DrawableRuleset.GameplayStartTime);
InternalChild = GameplayClockContainer = new GameplayClockContainer(Beatmap.Value, Mods.Value, DrawableRuleset.GameplayStartTime);
AddInternal(gameplayBeatmap = new GameplayBeatmap(playableBeatmap));
AddInternal(screenSuspension = new ScreenSuspensionHandler(GameplayClockContainer));