mirror of
https://github.com/ppy/osu.git
synced 2025-02-22 16:03:21 +08:00
Simplify derived classes of WorkingBeatmap
This commit is contained in:
parent
cc2b4c5c5b
commit
267238dc27
@ -1,4 +1,7 @@
|
|||||||
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;
|
||||||
@ -15,18 +18,9 @@ namespace osu.Desktop.VisualTests.Beatmaps
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Beatmap beatmap;
|
private Beatmap beatmap;
|
||||||
public override Beatmap Beatmap => beatmap;
|
|
||||||
public override Texture Background => null;
|
|
||||||
public override Track Track => null;
|
|
||||||
|
|
||||||
public override void Dispose()
|
protected override Beatmap GetBeatmap() => beatmap;
|
||||||
{
|
protected override Texture GetBackground() => null;
|
||||||
// This space intentionally left blank
|
protected override Track GetTrack() => null;
|
||||||
}
|
|
||||||
|
|
||||||
public override void TransferTo(WorkingBeatmap other)
|
|
||||||
{
|
|
||||||
// This space intentionally left blank
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,13 +37,63 @@ namespace osu.Game.Beatmaps
|
|||||||
WithStoryboard = withStoryboard;
|
WithStoryboard = withStoryboard;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract Beatmap Beatmap { get; }
|
protected abstract Beatmap GetBeatmap();
|
||||||
public abstract Texture Background { get; }
|
protected abstract Texture GetBackground();
|
||||||
public abstract Track Track { get; }
|
protected abstract Track GetTrack();
|
||||||
|
|
||||||
public abstract void TransferTo(WorkingBeatmap other);
|
private Beatmap beatmap;
|
||||||
public abstract void Dispose();
|
private object beatmapLock = new object();
|
||||||
|
public Beatmap Beatmap
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
lock (beatmapLock)
|
||||||
|
{
|
||||||
|
return beatmap ?? (beatmap = GetBeatmap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public virtual bool TrackLoaded => Track != null;
|
private object backgroundLock = new object();
|
||||||
|
private Texture background;
|
||||||
|
public Texture Background
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
lock (backgroundLock)
|
||||||
|
{
|
||||||
|
return background ?? (background = GetBackground());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Track track;
|
||||||
|
private object trackLock = new object();
|
||||||
|
public Track Track
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
lock (trackLock)
|
||||||
|
{
|
||||||
|
return track ?? (track = GetTrack());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
@ -21,16 +24,9 @@ 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;
|
||||||
{
|
|
||||||
lock (beatmapLock)
|
|
||||||
{
|
|
||||||
if (beatmap != null) return beatmap;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var reader = GetReader())
|
using (var reader = GetReader())
|
||||||
@ -48,24 +44,14 @@ namespace osu.Game.Database
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch { return null; }
|
catch { return null; }
|
||||||
|
|
||||||
return beatmap;
|
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)
|
||||||
lock (backgroundLock)
|
return null;
|
||||||
{
|
|
||||||
if (background != null) return background;
|
|
||||||
|
|
||||||
if (BeatmapInfo?.Metadata?.BackgroundFile == null) return null;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var reader = GetReader())
|
using (var reader = GetReader())
|
||||||
@ -76,52 +62,23 @@ namespace osu.Game.Database
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch { return null; }
|
catch { return null; }
|
||||||
|
|
||||||
return background;
|
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;
|
||||||
{
|
|
||||||
lock (trackLock)
|
|
||||||
{
|
|
||||||
if (track != null) return track;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//store a reference to the reader as we may continue accessing the stream in the background.
|
//store a reference to the reader as we may continue accessing the stream in the background.
|
||||||
trackReader = GetReader();
|
trackReader = GetReader();
|
||||||
var trackData = trackReader?.GetStream(BeatmapInfo.Metadata.AudioFile);
|
var trackData = trackReader?.GetStream(BeatmapInfo.Metadata.AudioFile);
|
||||||
if (trackData != null)
|
track = trackData == null ? null : new TrackBass(trackData);
|
||||||
track = new TrackBass(trackData);
|
|
||||||
}
|
}
|
||||||
catch { return null; }
|
catch { return null; }
|
||||||
|
|
||||||
return track;
|
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