1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 19:22:54 +08:00

Centralise TrackManager.AddItem logic to avoid duplicate adds

This commit is contained in:
Dean Herbert 2017-07-20 17:46:23 +09:00
parent 67b95926c4
commit 3bdd4d7d02
5 changed files with 17 additions and 28 deletions

View File

@ -134,11 +134,18 @@ namespace osu.Game
}); });
Beatmap.ValueChanged += b => Beatmap.ValueChanged += b =>
{
// compare to last baetmap as sometimes the two may share a track representation (optimisation, see WorkingBeatmap.TransferTo)
if (lastBeatmap?.Track != b.Track)
{ {
// this disposal is done to stop the audio track. // this disposal is done to stop the audio track.
// it may not be exactly what we want for cases beatmaps are reused, as it will // it may not be exactly what we want for cases beatmaps are reused, as it will
// trigger a fresh load of contained resources. // trigger a fresh load of contained resources.
lastBeatmap?.Dispose(); lastBeatmap?.Dispose();
Audio.Track.AddItem(b.Track);
}
lastBeatmap = b; lastBeatmap = b;
}; };

View File

@ -3,9 +3,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio.Track;
using osu.Framework.Configuration; using osu.Framework.Configuration;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -15,7 +13,6 @@ using osu.Game.Database;
using osu.Game.Graphics; using osu.Game.Graphics;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Framework.Extensions;
using osu.Framework.Input; using osu.Framework.Input;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
@ -30,7 +27,6 @@ namespace osu.Game.Overlays.Music
private FilterControl filter; private FilterControl filter;
private PlaylistList list; private PlaylistList list;
private TrackManager trackManager;
private BeatmapDatabase beatmaps; private BeatmapDatabase beatmaps;
private readonly Bindable<WorkingBeatmap> beatmapBacking = new Bindable<WorkingBeatmap>(); private readonly Bindable<WorkingBeatmap> beatmapBacking = new Bindable<WorkingBeatmap>();
@ -43,7 +39,6 @@ namespace osu.Game.Overlays.Music
{ {
this.inputManager = inputManager; this.inputManager = inputManager;
this.beatmaps = beatmaps; this.beatmaps = beatmaps;
trackManager = game.Audio.Track;
Children = new Drawable[] Children = new Drawable[]
{ {
@ -154,13 +149,7 @@ namespace osu.Game.Overlays.Music
private void playSpecified(BeatmapInfo info) private void playSpecified(BeatmapInfo info)
{ {
beatmapBacking.Value = beatmaps.GetWorkingBeatmap(info, beatmapBacking); beatmapBacking.Value = beatmaps.GetWorkingBeatmap(info, beatmapBacking);
beatmapBacking.Value.Track.Start();
Task.Run(() =>
{
var track = beatmapBacking.Value.Track;
trackManager.AddItem(track);
track.Start();
}).ContinueWith(task => Schedule(task.ThrowIfFaulted), TaskContinuationOptions.OnlyOnFaulted);
} }
} }

View File

@ -72,8 +72,6 @@ namespace osu.Game.Screens.Menu
menuVoice = config.GetBindable<bool>(OsuSetting.MenuVoice); menuVoice = config.GetBindable<bool>(OsuSetting.MenuVoice);
menuMusic = config.GetBindable<bool>(OsuSetting.MenuMusic); menuMusic = config.GetBindable<bool>(OsuSetting.MenuMusic);
var trackManager = audio.Track;
BeatmapSetInfo setInfo = null; BeatmapSetInfo setInfo = null;
if (!menuMusic) if (!menuMusic)
@ -106,7 +104,6 @@ namespace osu.Game.Screens.Menu
Beatmap.Value = beatmaps.GetWorkingBeatmap(setInfo.Beatmaps[0]); Beatmap.Value = beatmaps.GetWorkingBeatmap(setInfo.Beatmaps[0]);
track = Beatmap.Value.Track; track = Beatmap.Value.Track;
trackManager.AddItem(track);
welcome = audio.Sample.Get(@"welcome"); welcome = audio.Sample.Get(@"welcome");
seeya = audio.Sample.Get(@"seeya"); seeya = audio.Sample.Get(@"seeya");

View File

@ -119,10 +119,7 @@ namespace osu.Game.Screens.Play
Track track = Beatmap.Value.Track; Track track = Beatmap.Value.Track;
if (track != null) if (track != null)
{
audio.Track.AddItem(track);
adjustableSourceClock = track; adjustableSourceClock = track;
}
adjustableSourceClock = (IAdjustableClock)track ?? new StopwatchClock(); adjustableSourceClock = (IAdjustableClock)track ?? new StopwatchClock();

View File

@ -32,7 +32,6 @@ namespace osu.Game.Screens.Select
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(); protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap();
private readonly BeatmapCarousel carousel; private readonly BeatmapCarousel carousel;
private TrackManager trackManager;
private DialogOverlay dialogOverlay; private DialogOverlay dialogOverlay;
private static readonly Vector2 wedged_container_size = new Vector2(0.5f, 245); private static readonly Vector2 wedged_container_size = new Vector2(0.5f, 245);
@ -174,7 +173,6 @@ namespace osu.Game.Screens.Select
database.BeatmapSetAdded += onBeatmapSetAdded; database.BeatmapSetAdded += onBeatmapSetAdded;
database.BeatmapSetRemoved += onBeatmapSetRemoved; database.BeatmapSetRemoved += onBeatmapSetRemoved;
trackManager = audio.Track;
dialogOverlay = dialog; dialogOverlay = dialog;
sampleChangeDifficulty = audio.Sample.Get(@"SongSelect/select-difficulty"); sampleChangeDifficulty = audio.Sample.Get(@"SongSelect/select-difficulty");
@ -358,11 +356,12 @@ namespace osu.Game.Screens.Select
{ {
Track track = Beatmap.Value.Track; Track track = Beatmap.Value.Track;
trackManager.AddItem(track); if (!track.IsRunning)
{
if (preview) track.Seek(Beatmap.Value.Metadata.PreviewTime); if (preview) track.Seek(Beatmap.Value.Metadata.PreviewTime);
track.Start(); track.Start();
} }
}
private void removeBeatmapSet(BeatmapSetInfo beatmapSet) private void removeBeatmapSet(BeatmapSetInfo beatmapSet)
{ {