1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 05:53:10 +08:00

Fix remaining cases to work without things

This commit is contained in:
Dean Herbert 2019-05-28 23:54:42 +09:00
parent 23b5d30360
commit a20eda7b5f
10 changed files with 58 additions and 57 deletions

View File

@ -5,6 +5,7 @@ using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio.Track; using osu.Framework.Audio.Track;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.IO.Stores;
using osu.Game.Audio; using osu.Game.Audio;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
@ -111,11 +112,11 @@ namespace osu.Game.Tests.Visual.Components
private class TestPreviewTrackManager : PreviewTrackManager private class TestPreviewTrackManager : PreviewTrackManager
{ {
protected override TrackManagerPreviewTrack CreatePreviewTrack(BeatmapSetInfo beatmapSetInfo, TrackStore trackStore) => new TestPreviewTrack(beatmapSetInfo, trackStore); protected override TrackManagerPreviewTrack CreatePreviewTrack(BeatmapSetInfo beatmapSetInfo, IResourceStore<Track> trackStore) => new TestPreviewTrack(beatmapSetInfo, trackStore);
protected class TestPreviewTrack : TrackManagerPreviewTrack protected class TestPreviewTrack : TrackManagerPreviewTrack
{ {
public TestPreviewTrack(BeatmapSetInfo beatmapSetInfo, TrackStore trackManager) public TestPreviewTrack(BeatmapSetInfo beatmapSetInfo, IResourceStore<Track> trackManager)
: base(beatmapSetInfo, trackManager) : base(beatmapSetInfo, trackManager)
{ {
} }

View File

@ -20,17 +20,16 @@ namespace osu.Game.Audio
private readonly BindableDouble muteBindable = new BindableDouble(); private readonly BindableDouble muteBindable = new BindableDouble();
private AudioManager audio; private AudioManager audio;
private TrackStore trackStore; private IAdjustableResourceStore<Track> trackStore;
private TrackManagerPreviewTrack current; private TrackManagerPreviewTrack current;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(AudioManager audio, FrameworkConfigManager config) private void load(AudioManager audio, FrameworkConfigManager config)
{ {
trackStore = new TrackStore(new OnlineStore()); trackStore = audio.GetTrackStore(new OnlineStore());
this.audio = audio; this.audio = audio;
audio.AddItem(trackStore);
config.BindWith(FrameworkSetting.VolumeMusic, trackStore.Volume); config.BindWith(FrameworkSetting.VolumeMusic, trackStore.Volume);
} }
@ -81,16 +80,16 @@ namespace osu.Game.Audio
/// <summary> /// <summary>
/// Creates the <see cref="TrackManagerPreviewTrack"/>. /// Creates the <see cref="TrackManagerPreviewTrack"/>.
/// </summary> /// </summary>
protected virtual TrackManagerPreviewTrack CreatePreviewTrack(BeatmapSetInfo beatmapSetInfo, TrackStore trackStore) => new TrackManagerPreviewTrack(beatmapSetInfo, trackStore); protected virtual TrackManagerPreviewTrack CreatePreviewTrack(BeatmapSetInfo beatmapSetInfo, IResourceStore<Track> trackStore) => new TrackManagerPreviewTrack(beatmapSetInfo, trackStore);
protected class TrackManagerPreviewTrack : PreviewTrack protected class TrackManagerPreviewTrack : PreviewTrack
{ {
public IPreviewTrackOwner Owner { get; private set; } public IPreviewTrackOwner Owner { get; private set; }
private readonly BeatmapSetInfo beatmapSetInfo; private readonly BeatmapSetInfo beatmapSetInfo;
private readonly TrackStore trackManager; private readonly IResourceStore<Track> trackManager;
public TrackManagerPreviewTrack(BeatmapSetInfo beatmapSetInfo, TrackStore trackManager) public TrackManagerPreviewTrack(BeatmapSetInfo beatmapSetInfo, IResourceStore<Track> trackManager)
{ {
this.beatmapSetInfo = beatmapSetInfo; this.beatmapSetInfo = beatmapSetInfo;
this.trackManager = trackManager; this.trackManager = trackManager;

View File

@ -20,14 +20,13 @@ namespace osu.Game.Beatmaps
protected class BeatmapManagerWorkingBeatmap : WorkingBeatmap protected class BeatmapManagerWorkingBeatmap : WorkingBeatmap
{ {
private readonly IResourceStore<byte[]> store; private readonly IResourceStore<byte[]> store;
private readonly AudioManager audioManager;
public BeatmapManagerWorkingBeatmap(IResourceStore<byte[]> store, TextureStore textureStore, BeatmapInfo beatmapInfo, AudioManager audioManager) public BeatmapManagerWorkingBeatmap(IResourceStore<byte[]> store, TextureStore textureStore, BeatmapInfo beatmapInfo, AudioManager audioManager)
: base(beatmapInfo) : base(beatmapInfo)
{ {
this.store = store; this.store = store;
this.textureStore = textureStore; this.textureStore = textureStore;
this.audioManager = audioManager; AudioManager = audioManager;
} }
protected override IBeatmap GetBeatmap() protected override IBeatmap GetBeatmap()
@ -47,6 +46,8 @@ namespace osu.Game.Beatmaps
private TextureStore textureStore; private TextureStore textureStore;
private IAdjustableResourceStore<Track> trackStore;
protected override bool BackgroundStillValid(Texture b) => false; // bypass lazy logic. we want to return a new background each time for refcounting purposes. protected override bool BackgroundStillValid(Texture b) => false; // bypass lazy logic. we want to return a new background each time for refcounting purposes.
protected override Texture GetBackground() protected override Texture GetBackground()
@ -68,8 +69,7 @@ namespace osu.Game.Beatmaps
{ {
try try
{ {
var trackData = store.GetStream(getPathForFile(Metadata.AudioFile)); return (trackStore ?? (trackStore = AudioManager.GetTrackStore(store))).Get(getPathForFile(Metadata.AudioFile));
return trackData == null ? null : new TrackBass(trackData);
} }
catch catch
{ {
@ -77,6 +77,14 @@ namespace osu.Game.Beatmaps
} }
} }
public override void RecycleTrack()
{
base.RecycleTrack();
trackStore?.Dispose();
trackStore = null;
}
public override void TransferTo(WorkingBeatmap other) public override void TransferTo(WorkingBeatmap other)
{ {
base.TransferTo(other); base.TransferTo(other);
@ -135,7 +143,7 @@ namespace osu.Game.Beatmaps
try try
{ {
skin = new LegacyBeatmapSkin(BeatmapInfo, store, audioManager); skin = new LegacyBeatmapSkin(BeatmapInfo, store, AudioManager);
} }
catch (Exception e) catch (Exception e)
{ {

View File

@ -1,11 +1,9 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Diagnostics; using System.Diagnostics;
using JetBrains.Annotations; using JetBrains.Annotations;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Audio.Track;
using osu.Framework.Bindables; using osu.Framework.Bindables;
namespace osu.Game.Beatmaps namespace osu.Game.Beatmaps
@ -16,32 +14,26 @@ namespace osu.Game.Beatmaps
/// </summary> /// </summary>
public abstract class BindableBeatmap : NonNullableBindable<WorkingBeatmap> public abstract class BindableBeatmap : NonNullableBindable<WorkingBeatmap>
{ {
private AudioManager audioManager; protected AudioManager AudioManager;
private WorkingBeatmap lastBeatmap; private WorkingBeatmap lastBeatmap;
protected BindableBeatmap(WorkingBeatmap defaultValue) protected BindableBeatmap(WorkingBeatmap defaultValue, AudioManager audioManager)
: base(defaultValue) : base(defaultValue)
{ {
} // we don't want to attempt to update tracks if we are a bound copy.
if (audioManager != null)
/// <summary>
/// Registers an <see cref="AudioManager"/> for <see cref="Track"/>s to be added to.
/// </summary>
/// <param name="audioManager">The <see cref="AudioManager"/> to register.</param>
protected void RegisterAudioManager([NotNull] AudioManager audioManager)
{ {
if (this.audioManager != null) throw new InvalidOperationException($"Cannot register multiple {nameof(AudioManager)}s."); AudioManager = audioManager;
ValueChanged += b => updateAudioTrack(b.NewValue);
this.audioManager = audioManager;
ValueChanged += b => registerAudioTrack(b.NewValue);
// If the track has changed prior to this being called, let's register it // If the track has changed prior to this being called, let's register it
if (Value != Default) if (Value != Default)
registerAudioTrack(Value); updateAudioTrack(Value);
}
} }
private void registerAudioTrack(WorkingBeatmap beatmap) private void updateAudioTrack(WorkingBeatmap beatmap)
{ {
var trackLoaded = lastBeatmap?.TrackLoaded ?? false; var trackLoaded = lastBeatmap?.TrackLoaded ?? false;
@ -55,8 +47,6 @@ namespace osu.Game.Beatmaps
lastBeatmap.RecycleTrack(); lastBeatmap.RecycleTrack();
} }
audioManager.Tracks.AddItem(beatmap.Track);
} }
lastBeatmap = beatmap; lastBeatmap = beatmap;

View File

@ -11,6 +11,7 @@ using osu.Framework.IO.File;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using osu.Framework.Audio;
using osu.Game.IO.Serialization; using osu.Game.IO.Serialization;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
@ -150,6 +151,9 @@ namespace osu.Game.Beatmaps
public bool SkinLoaded => skin.IsResultAvailable; public bool SkinLoaded => skin.IsResultAvailable;
public Skin Skin => skin.Value; public Skin Skin => skin.Value;
public AudioManager AudioManager { get; set; }
protected virtual Skin GetSkin() => new DefaultSkin(); protected virtual Skin GetSkin() => new DefaultSkin();
private readonly RecyclableLazy<Skin> skin; private readonly RecyclableLazy<Skin> skin;
@ -175,7 +179,7 @@ namespace osu.Game.Beatmaps
/// Eagerly dispose of the audio track associated with this <see cref="WorkingBeatmap"/> (if any). /// Eagerly dispose of the audio track associated with this <see cref="WorkingBeatmap"/> (if any).
/// Accessing track again will load a fresh instance. /// Accessing track again will load a fresh instance.
/// </summary> /// </summary>
public void RecycleTrack() => track.Recycle(); public virtual void RecycleTrack() => track.Recycle();
public class RecyclableLazy<T> public class RecyclableLazy<T>
{ {

View File

@ -281,20 +281,19 @@ namespace osu.Game
private class OsuBindableBeatmap : BindableBeatmap private class OsuBindableBeatmap : BindableBeatmap
{ {
public OsuBindableBeatmap(WorkingBeatmap defaultValue, AudioManager audioManager) public OsuBindableBeatmap(WorkingBeatmap defaultValue)
: this(defaultValue) : base(defaultValue, null)
{ {
RegisterAudioManager(audioManager);
} }
public OsuBindableBeatmap(WorkingBeatmap defaultValue) public OsuBindableBeatmap(WorkingBeatmap defaultValue, AudioManager audioManager)
: base(defaultValue) : base(defaultValue, audioManager)
{ {
} }
public override BindableBeatmap GetBoundCopy() public override BindableBeatmap GetBoundCopy()
{ {
var copy = new OsuBindableBeatmap(Default); var copy = new OsuBindableBeatmap(Default, AudioManager);
copy.BindTo(this); copy.BindTo(this);
return copy; return copy;
} }

View File

@ -350,7 +350,7 @@ namespace osu.Game.Overlays
direction = last > next ? TransformDirection.Prev : TransformDirection.Next; direction = last > next ? TransformDirection.Prev : TransformDirection.Next;
} }
current.Track.Completed -= currentTrackCompleted; //current.Track.Completed -= currentTrackCompleted;
} }
current = beatmap.NewValue; current = beatmap.NewValue;

View File

@ -580,9 +580,6 @@ namespace osu.Game.Screens.Select
if (!track.IsRunning || restart) if (!track.IsRunning || restart)
{ {
// Ensure the track is added to the TrackManager, since it is removed after the player finishes the map.
// Using AddItemToList rather than AddItem so that it doesn't attempt to register adjustment dependencies more than once.
Game.Audio.Tracks.AddItem(track);
track.RestartPoint = Beatmap.Value.Metadata.PreviewTime; track.RestartPoint = Beatmap.Value.Metadata.PreviewTime;
track.Restart(); track.Restart();
} }

View File

@ -21,7 +21,7 @@ namespace osu.Game.Skinning
{ {
protected TextureStore Textures; protected TextureStore Textures;
protected SampleStore Samples; protected IResourceStore<SampleChannel> Samples;
public LegacySkin(SkinInfo skin, IResourceStore<byte[]> storage, AudioManager audioManager) public LegacySkin(SkinInfo skin, IResourceStore<byte[]> storage, AudioManager audioManager)
: this(skin, new LegacySkinResourceStore<SkinFileInfo>(skin, storage), audioManager, "skin.ini") : this(skin, new LegacySkinResourceStore<SkinFileInfo>(skin, storage), audioManager, "skin.ini")
@ -42,6 +42,13 @@ namespace osu.Game.Skinning
Textures = new TextureStore(new TextureLoaderStore(storage)); Textures = new TextureStore(new TextureLoaderStore(storage));
} }
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
Textures?.Dispose();
Samples?.Dispose();
}
public override Drawable GetDrawableComponent(string componentName) public override Drawable GetDrawableComponent(string componentName)
{ {
switch (componentName) switch (componentName)

View File

@ -19,7 +19,7 @@ namespace osu.Game.Tests.Visual
{ {
[Cached(typeof(Bindable<WorkingBeatmap>))] [Cached(typeof(Bindable<WorkingBeatmap>))]
[Cached(typeof(IBindable<WorkingBeatmap>))] [Cached(typeof(IBindable<WorkingBeatmap>))]
private readonly OsuTestBeatmap beatmap = new OsuTestBeatmap(new DummyWorkingBeatmap()); private readonly OsuTestBeatmap beatmap = new OsuTestBeatmap(new DummyWorkingBeatmap(), null);
protected BindableBeatmap Beatmap => beatmap; protected BindableBeatmap Beatmap => beatmap;
@ -52,8 +52,6 @@ namespace osu.Game.Tests.Visual
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(AudioManager audioManager, RulesetStore rulesets) private void load(AudioManager audioManager, RulesetStore rulesets)
{ {
beatmap.SetAudioManager(audioManager);
Ruleset.Value = rulesets.AvailableRulesets.First(); Ruleset.Value = rulesets.AvailableRulesets.First();
} }
@ -95,16 +93,14 @@ namespace osu.Game.Tests.Visual
private class OsuTestBeatmap : BindableBeatmap private class OsuTestBeatmap : BindableBeatmap
{ {
public OsuTestBeatmap(WorkingBeatmap defaultValue) public OsuTestBeatmap(WorkingBeatmap defaultValue, AudioManager audioManager)
: base(defaultValue) : base(defaultValue, audioManager)
{ {
} }
public void SetAudioManager(AudioManager audioManager) => RegisterAudioManager(audioManager);
public override BindableBeatmap GetBoundCopy() public override BindableBeatmap GetBoundCopy()
{ {
var copy = new OsuTestBeatmap(Default); var copy = new OsuTestBeatmap(Default, AudioManager);
copy.BindTo(this); copy.BindTo(this);
return copy; return copy;
} }