mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 17:43:05 +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;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using osu.Framework.Extensions;
|
using osu.Framework.Extensions;
|
||||||
using osu.Framework.IO.Stores;
|
using osu.Framework.IO.Stores;
|
||||||
@ -21,6 +22,7 @@ namespace osu.Game.Skinning
|
|||||||
private Lazy<Dictionary<string, string>> fileToStoragePathMapping;
|
private Lazy<Dictionary<string, string>> fileToStoragePathMapping;
|
||||||
|
|
||||||
private readonly Live<T> liveSource;
|
private readonly Live<T> liveSource;
|
||||||
|
private readonly IDisposable? realmSubscription;
|
||||||
|
|
||||||
public RealmBackedResourceStore(Live<T> source, IResourceStore<byte[]> underlyingStore, RealmAccess? realm)
|
public RealmBackedResourceStore(Live<T> source, IResourceStore<byte[]> underlyingStore, RealmAccess? realm)
|
||||||
: base(underlyingStore)
|
: base(underlyingStore)
|
||||||
@ -29,9 +31,17 @@ namespace osu.Game.Skinning
|
|||||||
|
|
||||||
invalidateCache();
|
invalidateCache();
|
||||||
Debug.Assert(fileToStoragePathMapping != null);
|
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)
|
protected override IEnumerable<string> GetFilenames(string name)
|
||||||
{
|
{
|
||||||
|
@ -54,8 +54,6 @@ namespace osu.Game.Skinning
|
|||||||
where TLookup : notnull
|
where TLookup : notnull
|
||||||
where TValue : notnull;
|
where TValue : notnull;
|
||||||
|
|
||||||
public void InvalidateCaches() => realmBackedStorage?.Invalidate();
|
|
||||||
|
|
||||||
private readonly RealmBackedResourceStore<SkinInfo> realmBackedStorage;
|
private readonly RealmBackedResourceStore<SkinInfo> realmBackedStorage;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -206,6 +204,8 @@ namespace osu.Game.Skinning
|
|||||||
|
|
||||||
Textures?.Dispose();
|
Textures?.Dispose();
|
||||||
Samples?.Dispose();
|
Samples?.Dispose();
|
||||||
|
|
||||||
|
realmBackedStorage?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -16,7 +16,6 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Framework.Graphics.OpenGL.Textures;
|
using osu.Framework.Graphics.OpenGL.Textures;
|
||||||
using osu.Framework.Graphics.Textures;
|
using osu.Framework.Graphics.Textures;
|
||||||
using osu.Framework.IO.Stores;
|
using osu.Framework.IO.Stores;
|
||||||
using osu.Framework.Logging;
|
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
using osu.Framework.Threading;
|
using osu.Framework.Threading;
|
||||||
@ -27,7 +26,6 @@ using osu.Game.IO;
|
|||||||
using osu.Game.IO.Archives;
|
using osu.Game.IO.Archives;
|
||||||
using osu.Game.Models;
|
using osu.Game.Models;
|
||||||
using osu.Game.Overlays.Notifications;
|
using osu.Game.Overlays.Notifications;
|
||||||
using Realms;
|
|
||||||
|
|
||||||
namespace osu.Game.Skinning
|
namespace osu.Game.Skinning
|
||||||
{
|
{
|
||||||
@ -61,8 +59,6 @@ namespace osu.Game.Skinning
|
|||||||
|
|
||||||
private readonly IResourceStore<byte[]> userFiles;
|
private readonly IResourceStore<byte[]> userFiles;
|
||||||
|
|
||||||
private IDisposable currentSkinSubscription;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The default skin.
|
/// The default skin.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -104,12 +100,6 @@ namespace osu.Game.Skinning
|
|||||||
CurrentSkinInfo.ValueChanged += skin =>
|
CurrentSkinInfo.ValueChanged += skin =>
|
||||||
{
|
{
|
||||||
CurrentSkin.Value = skin.NewValue.PerformRead(GetSkin);
|
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;
|
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()
|
public void SelectRandomSkin()
|
||||||
{
|
{
|
||||||
realm.Run(r =>
|
realm.Run(r =>
|
||||||
|
Loading…
Reference in New Issue
Block a user