1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-23 21:12:54 +08:00

Merge branch 'master' into shader-precompile

This commit is contained in:
Dan Balasescu 2017-12-07 04:15:24 +09:00 committed by GitHub
commit 9c4ca46786
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -41,7 +41,7 @@ namespace osu.Game.Beatmaps
protected abstract Track GetTrack(); protected abstract Track GetTrack();
protected virtual Waveform GetWaveform() => new Waveform(); protected virtual Waveform GetWaveform() => new Waveform();
public bool BeatmapLoaded => beatmap.IsValueCreated; public bool BeatmapLoaded => beatmap.IsResultAvailable;
public Beatmap Beatmap => beatmap.Value.Result; public Beatmap Beatmap => beatmap.Value.Result;
public async Task<Beatmap> GetBeatmapAsync() => await beatmap.Value; public async Task<Beatmap> GetBeatmapAsync() => await beatmap.Value;
@ -57,14 +57,14 @@ namespace osu.Game.Beatmaps
return b; return b;
} }
public bool BackgroundLoaded => background.IsValueCreated; public bool BackgroundLoaded => background.IsResultAvailable;
public Texture Background => background.Value.Result; public Texture Background => background.Value.Result;
public async Task<Texture> GetBackgroundAsync() => await background.Value; public async Task<Texture> GetBackgroundAsync() => await background.Value;
private AsyncLazy<Texture> background; private AsyncLazy<Texture> background;
private Texture populateBackground() => GetBackground(); private Texture populateBackground() => GetBackground();
public bool TrackLoaded => track.IsValueCreated; public bool TrackLoaded => track.IsResultAvailable;
public Track Track => track.Value.Result; public Track Track => track.Value.Result;
public async Task<Track> GetTrackAsync() => await track.Value; public async Task<Track> GetTrackAsync() => await track.Value;
private AsyncLazy<Track> track; private AsyncLazy<Track> track;
@ -77,7 +77,7 @@ namespace osu.Game.Beatmaps
return t; return t;
} }
public bool WaveformLoaded => waveform.IsValueCreated; public bool WaveformLoaded => waveform.IsResultAvailable;
public Waveform Waveform => waveform.Value.Result; public Waveform Waveform => waveform.Value.Result;
public async Task<Waveform> GetWaveformAsync() => await waveform.Value; public async Task<Waveform> GetWaveformAsync() => await waveform.Value;
private readonly AsyncLazy<Waveform> waveform; private readonly AsyncLazy<Waveform> waveform;
@ -86,10 +86,10 @@ namespace osu.Game.Beatmaps
public void TransferTo(WorkingBeatmap other) public void TransferTo(WorkingBeatmap other)
{ {
if (track.IsValueCreated && Track != null && BeatmapInfo.AudioEquals(other.BeatmapInfo)) if (track.IsResultAvailable && Track != null && BeatmapInfo.AudioEquals(other.BeatmapInfo))
other.track = track; other.track = track;
if (background.IsValueCreated && Background != null && BeatmapInfo.BackgroundEquals(other.BeatmapInfo)) if (background.IsResultAvailable && Background != null && BeatmapInfo.BackgroundEquals(other.BeatmapInfo))
other.background = background; other.background = background;
} }
@ -107,7 +107,7 @@ namespace osu.Game.Beatmaps
private void applyRateAdjustments(Track t = null) private void applyRateAdjustments(Track t = null)
{ {
if (t == null && track.IsValueCreated) t = Track; if (t == null && track.IsResultAvailable) t = Track;
if (t == null) return; if (t == null) return;
t.ResetSpeedAdjustments(); t.ResetSpeedAdjustments();
@ -128,23 +128,23 @@ namespace osu.Game.Beatmaps
this.valueFactory = valueFactory; this.valueFactory = valueFactory;
this.stillValidFunction = stillValidFunction; this.stillValidFunction = stillValidFunction;
init(); recreate();
} }
public void Recycle() public void Recycle()
{ {
if (!IsValueCreated) return; if (!IsResultAvailable) return;
(lazy.Value.Result as IDisposable)?.Dispose(); (lazy.Value.Result as IDisposable)?.Dispose();
init(); recreate();
} }
public bool IsValueCreated public bool IsResultAvailable
{ {
get get
{ {
ensureValid(); recreateIfInvalid();
return lazy.IsValueCreated; return lazy.Value.IsCompleted;
} }
} }
@ -152,24 +152,28 @@ namespace osu.Game.Beatmaps
{ {
get get
{ {
ensureValid(); recreateIfInvalid();
return lazy.Value; return lazy.Value;
} }
} }
private void ensureValid() private void recreateIfInvalid()
{ {
lock (initLock) lock (initLock)
{ {
if (!lazy.IsValueCreated || (stillValidFunction?.Invoke(lazy.Value.Result) ?? true)) return; if (!lazy.IsValueCreated || !lazy.Value.IsCompleted)
init(); // we have not yet been initialised or haven't run the task.
return;
if (stillValidFunction?.Invoke(lazy.Value.Result) ?? true)
// we are still in a valid state.
return;
recreate();
} }
} }
private void init() private void recreate() => lazy = new Lazy<Task<T>>(() => Task.Run(valueFactory));
{
lazy = new Lazy<Task<T>>(() => Task.Run(valueFactory));
}
} }
} }
} }