Use ReadWriteDictionary as base for meta changes.

This commit is contained in:
Ottermandias 2024-08-28 18:32:22 +02:00
parent 6d408ba695
commit 4117d45d15
4 changed files with 20 additions and 28 deletions

@ -1 +1 @@
Subproject commit 9217ac56697bc8285ced483b1fd4734fd36ba64d
Subproject commit bfbde4f8aa6acc8eb3ed8bc419d5ae2afc77b5f1

View file

@ -1,3 +1,4 @@
using OtterGui.Classes;
using OtterGui.Services;
using Penumbra.GameData.Structs;
using Penumbra.Meta.Manipulations;
@ -5,7 +6,7 @@ using Penumbra.Mods.Editor;
namespace Penumbra.Collections.Cache;
public class GlobalEqpCache : Dictionary<GlobalEqpManipulation, IMod>, IService
public class GlobalEqpCache : ReadWriteDictionary<GlobalEqpManipulation, IMod>, IService
{
private readonly HashSet<PrimaryId> _doNotHideEarrings = [];
private readonly HashSet<PrimaryId> _doNotHideNecklace = [];

View file

@ -3,7 +3,6 @@ using Penumbra.GameData.Structs;
using Penumbra.Meta;
using Penumbra.Meta.Manipulations;
using Penumbra.Mods.Editor;
using Penumbra.String.Classes;
namespace Penumbra.Collections.Cache;
@ -16,6 +15,7 @@ public class MetaCache(MetaFileManager manager, ModCollection collection)
public readonly RspCache Rsp = new(manager, collection);
public readonly ImcCache Imc = new(manager, collection);
public readonly GlobalEqpCache GlobalEqp = new();
public bool IsDisposed { get; private set; }
public int Count
=> Eqp.Count + Eqdp.Count + Est.Count + Gmp.Count + Rsp.Count + Imc.Count + GlobalEqp.Count;
@ -42,6 +42,10 @@ public class MetaCache(MetaFileManager manager, ModCollection collection)
public void Dispose()
{
if (IsDisposed)
return;
IsDisposed = true;
Eqp.Dispose();
Eqdp.Dispose();
Est.Dispose();

View file

@ -1,3 +1,4 @@
using OtterGui.Classes;
using Penumbra.Meta;
using Penumbra.Meta.Manipulations;
using Penumbra.Mods.Editor;
@ -5,35 +6,25 @@ using Penumbra.Mods.Editor;
namespace Penumbra.Collections.Cache;
public abstract class MetaCacheBase<TIdentifier, TEntry>(MetaFileManager manager, ModCollection collection)
: Dictionary<TIdentifier, (IMod Source, TEntry Entry)>
: ReadWriteDictionary<TIdentifier, (IMod Source, TEntry Entry)>
where TIdentifier : unmanaged, IMetaIdentifier
where TEntry : unmanaged
{
protected readonly MetaFileManager Manager = manager;
protected readonly ModCollection Collection = collection;
public void Dispose()
{
Dispose(true);
}
public bool ApplyMod(IMod source, TIdentifier identifier, TEntry entry)
{
lock (this)
{
if (TryGetValue(identifier, out var pair) && pair.Source == source && EqualityComparer<TEntry>.Default.Equals(pair.Entry, entry))
return false;
this[identifier] = (source, entry);
}
ApplyModInternal(identifier, entry);
return true;
}
public bool RevertMod(TIdentifier identifier, [NotNullWhen(true)] out IMod? mod)
{
lock (this)
{
if (!Remove(identifier, out var pair))
{
@ -42,7 +33,6 @@ public abstract class MetaCacheBase<TIdentifier, TEntry>(MetaFileManager manager
}
mod = pair.Source;
}
RevertModInternal(identifier);
return true;
@ -54,7 +44,4 @@ public abstract class MetaCacheBase<TIdentifier, TEntry>(MetaFileManager manager
protected virtual void RevertModInternal(TIdentifier identifier)
{ }
protected virtual void Dispose(bool _)
{ }
}