mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 12:17:26 +08:00
Replace invalidation logic with local realm notification subscription
This commit is contained in:
parent
9c3dad9fbf
commit
762de3cc97
@ -6,6 +6,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.IO.Stores;
|
||||
@ -21,6 +22,7 @@ namespace osu.Game.Skinning
|
||||
private Lazy<Dictionary<string, string>> fileToStoragePathMapping;
|
||||
|
||||
private readonly Live<T> liveSource;
|
||||
private readonly IDisposable? realmSubscription;
|
||||
|
||||
public RealmBackedResourceStore(Live<T> source, IResourceStore<byte[]> underlyingStore, RealmAccess? realm)
|
||||
: base(underlyingStore)
|
||||
@ -29,9 +31,17 @@ namespace osu.Game.Skinning
|
||||
|
||||
invalidateCache();
|
||||
Debug.Assert(fileToStoragePathMapping != null);
|
||||
|
||||
realmSubscription = realm?.RegisterForNotifications(r => r.All<T>().Where(s => s.ID == source.ID), skinChanged);
|
||||
}
|
||||
|
||||
public void Invalidate() => invalidateCache();
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
realmSubscription?.Dispose();
|
||||
}
|
||||
|
||||
private void skinChanged(IRealmCollection<T> sender, ChangeSet changes, Exception error) => invalidateCache();
|
||||
|
||||
protected override IEnumerable<string> GetFilenames(string name)
|
||||
{
|
||||
|
@ -54,8 +54,6 @@ namespace osu.Game.Skinning
|
||||
where TLookup : notnull
|
||||
where TValue : notnull;
|
||||
|
||||
public void InvalidateCaches() => realmBackedStorage?.Invalidate();
|
||||
|
||||
private readonly RealmBackedResourceStore<SkinInfo> realmBackedStorage;
|
||||
|
||||
/// <summary>
|
||||
@ -206,6 +204,8 @@ namespace osu.Game.Skinning
|
||||
|
||||
Textures?.Dispose();
|
||||
Samples?.Dispose();
|
||||
|
||||
realmBackedStorage?.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -16,7 +16,6 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.OpenGL.Textures;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osu.Framework.IO.Stores;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Framework.Threading;
|
||||
@ -27,7 +26,6 @@ using osu.Game.IO;
|
||||
using osu.Game.IO.Archives;
|
||||
using osu.Game.Models;
|
||||
using osu.Game.Overlays.Notifications;
|
||||
using Realms;
|
||||
|
||||
namespace osu.Game.Skinning
|
||||
{
|
||||
@ -61,8 +59,6 @@ namespace osu.Game.Skinning
|
||||
|
||||
private readonly IResourceStore<byte[]> userFiles;
|
||||
|
||||
private IDisposable currentSkinSubscription;
|
||||
|
||||
/// <summary>
|
||||
/// The default skin.
|
||||
/// </summary>
|
||||
@ -104,12 +100,6 @@ namespace osu.Game.Skinning
|
||||
CurrentSkinInfo.ValueChanged += skin =>
|
||||
{
|
||||
CurrentSkin.Value = skin.NewValue.PerformRead(GetSkin);
|
||||
|
||||
scheduler.Add(() =>
|
||||
{
|
||||
currentSkinSubscription?.Dispose();
|
||||
currentSkinSubscription = realm.RegisterForNotifications(r => r.All<SkinInfo>().Where(s => s.ID == skin.NewValue.ID), realmSkinChanged);
|
||||
});
|
||||
};
|
||||
|
||||
CurrentSkin.Value = DefaultSkin;
|
||||
@ -122,12 +112,6 @@ namespace osu.Game.Skinning
|
||||
};
|
||||
}
|
||||
|
||||
private void realmSkinChanged<T>(IRealmCollection<T> sender, ChangeSet changes, Exception error) where T : RealmObjectBase
|
||||
{
|
||||
Logger.Log("Detected a skin change");
|
||||
CurrentSkin.Value.InvalidateCaches();
|
||||
}
|
||||
|
||||
public void SelectRandomSkin()
|
||||
{
|
||||
realm.Run(r =>
|
||||
|
Loading…
Reference in New Issue
Block a user