1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 13:22:55 +08:00

Merge branch 'master' of https://github.com/ppy/osu into url-parsing-support

This commit is contained in:
FreezyLemon 2017-12-01 21:07:31 +01:00
commit 7699a3bb38
6 changed files with 71 additions and 21 deletions

@ -1 +1 @@
Subproject commit 87d68cda0015d51dc3da56d2322fa10d399fc4ed Subproject commit cc013fc4063dda0843f38c1c73568a413abcf229

View File

@ -31,7 +31,7 @@ namespace osu.Game.Beatmaps
Mods.ValueChanged += mods => applyRateAdjustments(); Mods.ValueChanged += mods => applyRateAdjustments();
beatmap = new AsyncLazy<Beatmap>(populateBeatmap); beatmap = new AsyncLazy<Beatmap>(populateBeatmap);
background = new AsyncLazy<Texture>(populateBackground); background = new AsyncLazy<Texture>(populateBackground, b => b == null || !b.IsDisposed);
track = new AsyncLazy<Track>(populateTrack); track = new AsyncLazy<Track>(populateTrack);
waveform = new AsyncLazy<Waveform>(populateWaveform); waveform = new AsyncLazy<Waveform>(populateWaveform);
} }
@ -99,10 +99,11 @@ namespace osu.Game.Beatmaps
if (WaveformLoaded) Waveform?.Dispose(); if (WaveformLoaded) Waveform?.Dispose();
} }
public void DisposeTrack() /// <summary>
{ /// Eagerly dispose of the audio track associated with this <see cref="WorkingBeatmap"/> (if any).
if (TrackLoaded) Track?.Dispose(); /// Accessing track again will load a fresh instance.
} /// </summary>
public void RecycleTrack() => track.Recycle();
private void applyRateAdjustments(Track t = null) private void applyRateAdjustments(Track t = null)
{ {
@ -114,11 +115,60 @@ namespace osu.Game.Beatmaps
mod.ApplyToClock(t); mod.ApplyToClock(t);
} }
public class AsyncLazy<T> : Lazy<Task<T>> public class AsyncLazy<T>
{ {
public AsyncLazy(Func<T> valueFactory) private Lazy<Task<T>> lazy;
: base(() => Task.Run(valueFactory)) private readonly Func<T> valueFactory;
private readonly Func<T, bool> stillValidFunction;
private readonly object initLock = new object();
public AsyncLazy(Func<T> valueFactory, Func<T, bool> stillValidFunction = null)
{ {
this.valueFactory = valueFactory;
this.stillValidFunction = stillValidFunction;
init();
}
public void Recycle()
{
if (!IsValueCreated) return;
(lazy.Value.Result as IDisposable)?.Dispose();
init();
}
public bool IsValueCreated
{
get
{
ensureValid();
return lazy.IsValueCreated;
}
}
public Task<T> Value
{
get
{
ensureValid();
return lazy.Value;
}
}
private void ensureValid()
{
lock (initLock)
{
if (!lazy.IsValueCreated || (stillValidFunction?.Invoke(lazy.Value.Result) ?? true)) return;
init();
}
}
private void init()
{
lazy = new Lazy<Task<T>>(() => Task.Run(valueFactory));
} }
} }
} }

View File

@ -154,7 +154,7 @@ namespace osu.Game
Debug.Assert(lastBeatmap != null); Debug.Assert(lastBeatmap != null);
Debug.Assert(lastBeatmap.Track != null); Debug.Assert(lastBeatmap.Track != null);
lastBeatmap.DisposeTrack(); lastBeatmap.RecycleTrack();
} }
Audio.Track.AddItem(b.Track); Audio.Track.AddItem(b.Track);

View File

@ -45,7 +45,7 @@ namespace osu.Game.Screens.Select
Task.Run(() => Task.Run(() =>
{ {
newGroups = value.Select(createGroup).ToList(); newGroups = value.Select(createGroup).Where(g => g != null).ToList();
criteria.Filter(newGroups); criteria.Filter(newGroups);
}).ContinueWith(t => }).ContinueWith(t =>
{ {
@ -124,16 +124,19 @@ namespace osu.Game.Screens.Select
// todo: this method should be smarter as to not recreate panels that haven't changed, etc. // todo: this method should be smarter as to not recreate panels that haven't changed, etc.
var group = groups.Find(b => b.BeatmapSet.ID == set.ID); var group = groups.Find(b => b.BeatmapSet.ID == set.ID);
if (group == null)
return;
int i = groups.IndexOf(group); int i = groups.IndexOf(group);
if (i >= 0)
groups.RemoveAt(i); groups.RemoveAt(i);
var newGroup = createGroup(set); var newGroup = createGroup(set);
if (newGroup != null) if (newGroup != null)
{
if (i >= 0)
groups.Insert(i, newGroup); groups.Insert(i, newGroup);
else
groups.Add(newGroup);
}
bool hadSelection = selectedGroup == group; bool hadSelection = selectedGroup == group;

View File

@ -263,10 +263,7 @@ namespace osu.Game.Screens.Select
beatmapNoDebounce = beatmap; beatmapNoDebounce = beatmap;
if (beatmap == null) if (beatmap == null)
{
if (!Beatmap.IsDefault)
performLoad(); performLoad();
}
else else
{ {
if (beatmap.BeatmapSetInfoID == beatmapNoDebounce?.BeatmapSetInfoID) if (beatmap.BeatmapSetInfoID == beatmapNoDebounce?.BeatmapSetInfoID)

View File

@ -282,7 +282,7 @@
<DependentUpon>20171025071459_AddMissingIndexRules.cs</DependentUpon> <DependentUpon>20171025071459_AddMissingIndexRules.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Migrations\20171119065731_AddBeatmapOnlineIDUniqueConstraint.cs" /> <Compile Include="Migrations\20171119065731_AddBeatmapOnlineIDUniqueConstraint.cs" />
<Compile Include="Migrations\20171119065731_AddBeatmapOnlineIDUniqueConstraint.designer.cs"> <Compile Include="Migrations\20171119065731_AddBeatmapOnlineIDUniqueConstraint.Designer.cs">
<DependentUpon>20171119065731_AddBeatmapOnlineIDUniqueConstraint.cs</DependentUpon> <DependentUpon>20171119065731_AddBeatmapOnlineIDUniqueConstraint.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Migrations\OsuDbContextModelSnapshot.cs" /> <Compile Include="Migrations\OsuDbContextModelSnapshot.cs" />