mirror of
https://github.com/ppy/osu.git
synced 2025-02-22 00:43:25 +08:00
Simplify derived classes of WorkingBeatmap
This commit is contained in:
parent
cc2b4c5c5b
commit
267238dc27
@ -1,32 +1,26 @@
|
|||||||
using System;
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System;
|
||||||
using osu.Framework.Audio.Track;
|
using osu.Framework.Audio.Track;
|
||||||
using osu.Framework.Graphics.Textures;
|
using osu.Framework.Graphics.Textures;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Beatmaps.IO;
|
using osu.Game.Beatmaps.IO;
|
||||||
|
|
||||||
namespace osu.Desktop.VisualTests.Beatmaps
|
namespace osu.Desktop.VisualTests.Beatmaps
|
||||||
{
|
{
|
||||||
public class TestWorkingBeatmap : WorkingBeatmap
|
public class TestWorkingBeatmap : WorkingBeatmap
|
||||||
{
|
{
|
||||||
public TestWorkingBeatmap(Beatmap beatmap)
|
public TestWorkingBeatmap(Beatmap beatmap)
|
||||||
: base(beatmap.BeatmapInfo, beatmap.BeatmapInfo.BeatmapSet)
|
: base(beatmap.BeatmapInfo, beatmap.BeatmapInfo.BeatmapSet)
|
||||||
{
|
{
|
||||||
this.beatmap = beatmap;
|
this.beatmap = beatmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Beatmap beatmap;
|
private Beatmap beatmap;
|
||||||
public override Beatmap Beatmap => beatmap;
|
|
||||||
public override Texture Background => null;
|
protected override Beatmap GetBeatmap() => beatmap;
|
||||||
public override Track Track => null;
|
protected override Texture GetBackground() => null;
|
||||||
|
protected override Track GetTrack() => null;
|
||||||
public override void Dispose()
|
}
|
||||||
{
|
}
|
||||||
// This space intentionally left blank
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void TransferTo(WorkingBeatmap other)
|
|
||||||
{
|
|
||||||
// This space intentionally left blank
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -36,14 +36,64 @@ namespace osu.Game.Beatmaps
|
|||||||
BeatmapSetInfo = beatmapSetInfo;
|
BeatmapSetInfo = beatmapSetInfo;
|
||||||
WithStoryboard = withStoryboard;
|
WithStoryboard = withStoryboard;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract Beatmap GetBeatmap();
|
||||||
|
protected abstract Texture GetBackground();
|
||||||
|
protected abstract Track GetTrack();
|
||||||
|
|
||||||
public abstract Beatmap Beatmap { get; }
|
private Beatmap beatmap;
|
||||||
public abstract Texture Background { get; }
|
private object beatmapLock = new object();
|
||||||
public abstract Track Track { get; }
|
public Beatmap Beatmap
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
lock (beatmapLock)
|
||||||
|
{
|
||||||
|
return beatmap ?? (beatmap = GetBeatmap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private object backgroundLock = new object();
|
||||||
|
private Texture background;
|
||||||
|
public Texture Background
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
lock (backgroundLock)
|
||||||
|
{
|
||||||
|
return background ?? (background = GetBackground());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public abstract void TransferTo(WorkingBeatmap other);
|
private Track track;
|
||||||
public abstract void Dispose();
|
private object trackLock = new object();
|
||||||
|
public Track Track
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
lock (trackLock)
|
||||||
|
{
|
||||||
|
return track ?? (track = GetTrack());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public virtual bool TrackLoaded => Track != null;
|
public bool TrackLoaded => track != null;
|
||||||
|
|
||||||
|
public void TransferTo(WorkingBeatmap other)
|
||||||
|
{
|
||||||
|
if (track != null && BeatmapInfo.AudioEquals(other.BeatmapInfo))
|
||||||
|
other.track = track;
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void Dispose()
|
||||||
|
{
|
||||||
|
track?.Dispose();
|
||||||
|
track = null;
|
||||||
|
background?.Dispose();
|
||||||
|
background = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
using System.IO;
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System.IO;
|
||||||
using osu.Framework.Audio.Track;
|
using osu.Framework.Audio.Track;
|
||||||
using osu.Framework.Graphics.Textures;
|
using osu.Framework.Graphics.Textures;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
@ -20,107 +23,61 @@ namespace osu.Game.Database
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ArchiveReader GetReader() => database?.GetReader(BeatmapSetInfo);
|
private ArchiveReader GetReader() => database?.GetReader(BeatmapSetInfo);
|
||||||
|
|
||||||
private Beatmap beatmap;
|
protected override Beatmap GetBeatmap()
|
||||||
private object beatmapLock = new object();
|
|
||||||
public override Beatmap Beatmap
|
|
||||||
{
|
{
|
||||||
get
|
Beatmap beatmap;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
lock (beatmapLock)
|
using (var reader = GetReader())
|
||||||
{
|
{
|
||||||
if (beatmap != null) return beatmap;
|
BeatmapDecoder decoder;
|
||||||
|
using (var stream = new StreamReader(reader.GetStream(BeatmapInfo.Path)))
|
||||||
try
|
|
||||||
{
|
{
|
||||||
using (var reader = GetReader())
|
decoder = BeatmapDecoder.GetDecoder(stream);
|
||||||
{
|
beatmap = decoder?.Decode(stream);
|
||||||
BeatmapDecoder decoder;
|
|
||||||
using (var stream = new StreamReader(reader.GetStream(BeatmapInfo.Path)))
|
|
||||||
{
|
|
||||||
decoder = BeatmapDecoder.GetDecoder(stream);
|
|
||||||
beatmap = decoder?.Decode(stream);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (WithStoryboard && beatmap != null && BeatmapSetInfo.StoryboardFile != null)
|
|
||||||
using (var stream = new StreamReader(reader.GetStream(BeatmapSetInfo.StoryboardFile)))
|
|
||||||
decoder?.Decode(stream, beatmap);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch { return null; }
|
|
||||||
|
if (WithStoryboard && beatmap != null && BeatmapSetInfo.StoryboardFile != null)
|
||||||
return beatmap;
|
using (var stream = new StreamReader(reader.GetStream(BeatmapSetInfo.StoryboardFile)))
|
||||||
|
decoder?.Decode(stream, beatmap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch { return null; }
|
||||||
|
return beatmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private object backgroundLock = new object();
|
protected override Texture GetBackground()
|
||||||
private Texture background;
|
|
||||||
public override Texture Background
|
|
||||||
{
|
{
|
||||||
get
|
Texture background;
|
||||||
|
if (BeatmapInfo?.Metadata?.BackgroundFile == null)
|
||||||
|
return null;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
lock (backgroundLock)
|
using (var reader = GetReader())
|
||||||
{
|
{
|
||||||
if (background != null) return background;
|
background = new TextureStore(
|
||||||
|
new RawTextureLoaderStore(reader),
|
||||||
if (BeatmapInfo?.Metadata?.BackgroundFile == null) return null;
|
false).Get(BeatmapInfo.Metadata.BackgroundFile);
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (var reader = GetReader())
|
|
||||||
{
|
|
||||||
background = new TextureStore(
|
|
||||||
new RawTextureLoaderStore(reader),
|
|
||||||
false).Get(BeatmapInfo.Metadata.BackgroundFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch { return null; }
|
|
||||||
|
|
||||||
return background;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch { return null; }
|
||||||
|
return background;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArchiveReader trackReader;
|
private ArchiveReader trackReader;
|
||||||
private Track track;
|
protected override Track GetTrack()
|
||||||
private object trackLock = new object();
|
|
||||||
public override Track Track
|
|
||||||
{
|
{
|
||||||
get
|
Track track;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
lock (trackLock)
|
//store a reference to the reader as we may continue accessing the stream in the background.
|
||||||
{
|
trackReader = GetReader();
|
||||||
if (track != null) return track;
|
var trackData = trackReader?.GetStream(BeatmapInfo.Metadata.AudioFile);
|
||||||
|
track = trackData == null ? null : new TrackBass(trackData);
|
||||||
try
|
|
||||||
{
|
|
||||||
//store a reference to the reader as we may continue accessing the stream in the background.
|
|
||||||
trackReader = GetReader();
|
|
||||||
var trackData = trackReader?.GetStream(BeatmapInfo.Metadata.AudioFile);
|
|
||||||
if (trackData != null)
|
|
||||||
track = new TrackBass(trackData);
|
|
||||||
}
|
|
||||||
catch { return null; }
|
|
||||||
|
|
||||||
return track;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
catch { return null; }
|
||||||
|
return track;
|
||||||
public override bool TrackLoaded => track != null;
|
|
||||||
|
|
||||||
public override void TransferTo(WorkingBeatmap other)
|
|
||||||
{
|
|
||||||
var _other = (DatabaseWorkingBeatmap)other;
|
|
||||||
if (track != null && BeatmapInfo.AudioEquals(_other.BeatmapInfo))
|
|
||||||
_other.track = track;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Dispose()
|
|
||||||
{
|
|
||||||
background?.Dispose();
|
|
||||||
background = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user