mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 07:32:55 +08:00
Merge branch 'master' of https://github.com/ppy/osu into url-parsing-support
This commit is contained in:
commit
7699a3bb38
@ -1 +1 @@
|
||||
Subproject commit 87d68cda0015d51dc3da56d2322fa10d399fc4ed
|
||||
Subproject commit cc013fc4063dda0843f38c1c73568a413abcf229
|
@ -31,7 +31,7 @@ namespace osu.Game.Beatmaps
|
||||
Mods.ValueChanged += mods => applyRateAdjustments();
|
||||
|
||||
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);
|
||||
waveform = new AsyncLazy<Waveform>(populateWaveform);
|
||||
}
|
||||
@ -99,10 +99,11 @@ namespace osu.Game.Beatmaps
|
||||
if (WaveformLoaded) Waveform?.Dispose();
|
||||
}
|
||||
|
||||
public void DisposeTrack()
|
||||
{
|
||||
if (TrackLoaded) Track?.Dispose();
|
||||
}
|
||||
/// <summary>
|
||||
/// Eagerly dispose of the audio track associated with this <see cref="WorkingBeatmap"/> (if any).
|
||||
/// Accessing track again will load a fresh instance.
|
||||
/// </summary>
|
||||
public void RecycleTrack() => track.Recycle();
|
||||
|
||||
private void applyRateAdjustments(Track t = null)
|
||||
{
|
||||
@ -114,11 +115,60 @@ namespace osu.Game.Beatmaps
|
||||
mod.ApplyToClock(t);
|
||||
}
|
||||
|
||||
public class AsyncLazy<T> : Lazy<Task<T>>
|
||||
public class AsyncLazy<T>
|
||||
{
|
||||
public AsyncLazy(Func<T> valueFactory)
|
||||
: base(() => Task.Run(valueFactory))
|
||||
private Lazy<Task<T>> lazy;
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ namespace osu.Game
|
||||
Debug.Assert(lastBeatmap != null);
|
||||
Debug.Assert(lastBeatmap.Track != null);
|
||||
|
||||
lastBeatmap.DisposeTrack();
|
||||
lastBeatmap.RecycleTrack();
|
||||
}
|
||||
|
||||
Audio.Track.AddItem(b.Track);
|
||||
|
@ -45,7 +45,7 @@ namespace osu.Game.Screens.Select
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
newGroups = value.Select(createGroup).ToList();
|
||||
newGroups = value.Select(createGroup).Where(g => g != null).ToList();
|
||||
criteria.Filter(newGroups);
|
||||
}).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.
|
||||
var group = groups.Find(b => b.BeatmapSet.ID == set.ID);
|
||||
|
||||
if (group == null)
|
||||
return;
|
||||
|
||||
int i = groups.IndexOf(group);
|
||||
groups.RemoveAt(i);
|
||||
if (i >= 0)
|
||||
groups.RemoveAt(i);
|
||||
|
||||
var newGroup = createGroup(set);
|
||||
|
||||
if (newGroup != null)
|
||||
groups.Insert(i, newGroup);
|
||||
{
|
||||
if (i >= 0)
|
||||
groups.Insert(i, newGroup);
|
||||
else
|
||||
groups.Add(newGroup);
|
||||
}
|
||||
|
||||
bool hadSelection = selectedGroup == group;
|
||||
|
||||
|
@ -263,10 +263,7 @@ namespace osu.Game.Screens.Select
|
||||
beatmapNoDebounce = beatmap;
|
||||
|
||||
if (beatmap == null)
|
||||
{
|
||||
if (!Beatmap.IsDefault)
|
||||
performLoad();
|
||||
}
|
||||
performLoad();
|
||||
else
|
||||
{
|
||||
if (beatmap.BeatmapSetInfoID == beatmapNoDebounce?.BeatmapSetInfoID)
|
||||
|
@ -282,7 +282,7 @@
|
||||
<DependentUpon>20171025071459_AddMissingIndexRules.cs</DependentUpon>
|
||||
</Compile>
|
||||
<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>
|
||||
</Compile>
|
||||
<Compile Include="Migrations\OsuDbContextModelSnapshot.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user