2017-02-07 04:59:30 +00:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2016-10-28 05:14:45 +00:00
|
|
|
|
|
|
|
|
|
using osu.Framework.Audio.Track;
|
2017-03-06 05:52:37 +00:00
|
|
|
|
using osu.Framework.Configuration;
|
2016-11-05 11:00:14 +00:00
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2016-10-28 11:24:14 +00:00
|
|
|
|
using osu.Game.Database;
|
2017-04-18 07:05:58 +00:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2017-03-12 13:13:43 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2017-04-21 08:33:20 +00:00
|
|
|
|
using System.Linq;
|
2016-10-28 05:14:45 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps
|
|
|
|
|
{
|
2017-02-24 04:43:21 +00:00
|
|
|
|
public abstract class WorkingBeatmap : IDisposable
|
2016-10-28 05:14:45 +00:00
|
|
|
|
{
|
2016-11-05 09:16:15 +00:00
|
|
|
|
public readonly BeatmapInfo BeatmapInfo;
|
2016-10-28 11:24:14 +00:00
|
|
|
|
|
2016-11-05 09:16:15 +00:00
|
|
|
|
public readonly BeatmapSetInfo BeatmapSetInfo;
|
|
|
|
|
|
2017-05-01 13:29:57 +00:00
|
|
|
|
public readonly BeatmapMetadata Metadata;
|
|
|
|
|
|
2017-04-23 05:13:58 +00:00
|
|
|
|
public readonly Bindable<IEnumerable<Mod>> Mods = new Bindable<IEnumerable<Mod>>(new Mod[] { });
|
2017-03-06 05:52:37 +00:00
|
|
|
|
|
2017-07-20 00:22:39 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Denotes whether extras like storyboards have been loaded for this <see cref="WorkingBeatmap"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool FullyLoaded { get; protected set; }
|
2017-02-09 14:09:48 +00:00
|
|
|
|
|
2017-07-20 00:22:39 +00:00
|
|
|
|
protected WorkingBeatmap(BeatmapInfo beatmapInfo, bool fullyLoaded = false)
|
2017-02-24 04:43:21 +00:00
|
|
|
|
{
|
|
|
|
|
BeatmapInfo = beatmapInfo;
|
2017-05-08 08:42:53 +00:00
|
|
|
|
BeatmapSetInfo = beatmapInfo.BeatmapSet;
|
|
|
|
|
Metadata = beatmapInfo.Metadata ?? BeatmapSetInfo.Metadata;
|
2017-07-20 00:22:39 +00:00
|
|
|
|
FullyLoaded = fullyLoaded;
|
2017-04-23 05:41:15 +00:00
|
|
|
|
|
2017-04-21 08:33:20 +00:00
|
|
|
|
Mods.ValueChanged += mods => applyRateAdjustments();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void applyRateAdjustments()
|
|
|
|
|
{
|
|
|
|
|
var t = track;
|
|
|
|
|
if (t == null) return;
|
|
|
|
|
|
2017-04-21 10:26:32 +00:00
|
|
|
|
t.ResetSpeedAdjustments();
|
2017-04-21 08:33:20 +00:00
|
|
|
|
foreach (var mod in Mods.Value.OfType<IApplicableToClock>())
|
|
|
|
|
mod.ApplyToClock(t);
|
2017-02-24 04:43:21 +00:00
|
|
|
|
}
|
2017-03-22 10:15:32 +00:00
|
|
|
|
|
|
|
|
|
protected abstract Beatmap GetBeatmap();
|
|
|
|
|
protected abstract Texture GetBackground();
|
|
|
|
|
protected abstract Track GetTrack();
|
2017-04-06 08:21:18 +00:00
|
|
|
|
|
2017-03-22 10:15:32 +00:00
|
|
|
|
private Beatmap beatmap;
|
2017-03-23 04:41:50 +00:00
|
|
|
|
private readonly object beatmapLock = new object();
|
2017-03-22 10:15:32 +00:00
|
|
|
|
public Beatmap Beatmap
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
lock (beatmapLock)
|
|
|
|
|
{
|
|
|
|
|
return beatmap ?? (beatmap = GetBeatmap());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-04-06 08:21:18 +00:00
|
|
|
|
|
2017-03-23 04:41:50 +00:00
|
|
|
|
private readonly object backgroundLock = new object();
|
2017-03-22 10:15:32 +00:00
|
|
|
|
private Texture background;
|
|
|
|
|
public Texture Background
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
lock (backgroundLock)
|
|
|
|
|
{
|
|
|
|
|
return background ?? (background = GetBackground());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Track track;
|
2017-03-23 04:41:50 +00:00
|
|
|
|
private readonly object trackLock = new object();
|
2017-03-22 10:15:32 +00:00
|
|
|
|
public Track Track
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
lock (trackLock)
|
|
|
|
|
{
|
2017-04-21 08:33:20 +00:00
|
|
|
|
if (track != null) return track;
|
|
|
|
|
|
|
|
|
|
track = GetTrack();
|
|
|
|
|
applyRateAdjustments();
|
|
|
|
|
return track;
|
2017-03-22 10:15:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-28 11:24:14 +00:00
|
|
|
|
|
2017-03-22 10:15:32 +00:00
|
|
|
|
public bool TrackLoaded => track != null;
|
2016-11-05 12:01:46 +00:00
|
|
|
|
|
2017-03-22 10:15:32 +00:00
|
|
|
|
public void TransferTo(WorkingBeatmap other)
|
|
|
|
|
{
|
|
|
|
|
if (track != null && BeatmapInfo.AudioEquals(other.BeatmapInfo))
|
|
|
|
|
other.track = track;
|
2017-04-28 06:03:07 +00:00
|
|
|
|
|
|
|
|
|
if (background != null && BeatmapInfo.BackgroundEquals(other.BeatmapInfo))
|
|
|
|
|
other.background = background;
|
2017-03-22 10:15:32 +00:00
|
|
|
|
}
|
2017-04-06 08:21:18 +00:00
|
|
|
|
|
2017-03-22 10:15:32 +00:00
|
|
|
|
public virtual void Dispose()
|
|
|
|
|
{
|
|
|
|
|
track?.Dispose();
|
|
|
|
|
track = null;
|
|
|
|
|
background?.Dispose();
|
|
|
|
|
background = null;
|
|
|
|
|
}
|
2016-10-28 05:14:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|