mirror of
https://github.com/ppy/osu.git
synced 2024-11-08 12:17:43 +08:00
d6968ca09c
Always parse storyboards for now. Let's not optimise this until it is necessary. It was leading to weird threading problems due to the load call in Player's async load method.
111 lines
3.2 KiB
C#
111 lines
3.2 KiB
C#
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
using osu.Framework.Audio.Track;
|
|
using osu.Framework.Configuration;
|
|
using osu.Framework.Graphics.Textures;
|
|
using osu.Game.Database;
|
|
using osu.Game.Rulesets.Mods;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace osu.Game.Beatmaps
|
|
{
|
|
public abstract class WorkingBeatmap : IDisposable
|
|
{
|
|
public readonly BeatmapInfo BeatmapInfo;
|
|
|
|
public readonly BeatmapSetInfo BeatmapSetInfo;
|
|
|
|
public readonly BeatmapMetadata Metadata;
|
|
|
|
public readonly Bindable<IEnumerable<Mod>> Mods = new Bindable<IEnumerable<Mod>>(new Mod[] { });
|
|
|
|
protected WorkingBeatmap(BeatmapInfo beatmapInfo)
|
|
{
|
|
BeatmapInfo = beatmapInfo;
|
|
BeatmapSetInfo = beatmapInfo.BeatmapSet;
|
|
Metadata = beatmapInfo.Metadata ?? BeatmapSetInfo.Metadata;
|
|
|
|
Mods.ValueChanged += mods => applyRateAdjustments();
|
|
}
|
|
|
|
private void applyRateAdjustments()
|
|
{
|
|
var t = track;
|
|
if (t == null) return;
|
|
|
|
t.ResetSpeedAdjustments();
|
|
foreach (var mod in Mods.Value.OfType<IApplicableToClock>())
|
|
mod.ApplyToClock(t);
|
|
}
|
|
|
|
protected abstract Beatmap GetBeatmap();
|
|
protected abstract Texture GetBackground();
|
|
protected abstract Track GetTrack();
|
|
|
|
private Beatmap beatmap;
|
|
private readonly object beatmapLock = new object();
|
|
public Beatmap Beatmap
|
|
{
|
|
get
|
|
{
|
|
lock (beatmapLock)
|
|
{
|
|
return beatmap ?? (beatmap = GetBeatmap());
|
|
}
|
|
}
|
|
}
|
|
|
|
private readonly object backgroundLock = new object();
|
|
private Texture background;
|
|
public Texture Background
|
|
{
|
|
get
|
|
{
|
|
lock (backgroundLock)
|
|
{
|
|
return background ?? (background = GetBackground());
|
|
}
|
|
}
|
|
}
|
|
|
|
private Track track;
|
|
private readonly object trackLock = new object();
|
|
public Track Track
|
|
{
|
|
get
|
|
{
|
|
lock (trackLock)
|
|
{
|
|
if (track != null) return track;
|
|
|
|
track = GetTrack();
|
|
applyRateAdjustments();
|
|
return track;
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool TrackLoaded => track != null;
|
|
|
|
public void TransferTo(WorkingBeatmap other)
|
|
{
|
|
if (track != null && BeatmapInfo.AudioEquals(other.BeatmapInfo))
|
|
other.track = track;
|
|
|
|
if (background != null && BeatmapInfo.BackgroundEquals(other.BeatmapInfo))
|
|
other.background = background;
|
|
}
|
|
|
|
public virtual void Dispose()
|
|
{
|
|
track?.Dispose();
|
|
track = null;
|
|
background?.Dispose();
|
|
background = null;
|
|
}
|
|
}
|
|
}
|