Move Collection Change Counter to Collection instead of Cache so it does not reset if cache is destroyed.

This commit is contained in:
Ottermandias 2022-07-08 10:50:57 +02:00
parent f984283231
commit 70bae7737e
4 changed files with 13 additions and 13 deletions

View file

@ -18,8 +18,9 @@ public partial class ModCollection
public bool HasCache public bool HasCache
=> _cache != null; => _cache != null;
public int RecomputeCounter // Count the number of changes of the effective file list.
=> _cache?.ChangeCounter ?? 0; // This is used for material and imc changes.
public int ChangeCounter { get; private set; }
// Only create, do not update. // Only create, do not update.
private void CreateCache() private void CreateCache()

View file

@ -32,9 +32,6 @@ public partial class ModCollection
public SingleArray< ModConflicts > Conflicts( IMod mod ) public SingleArray< ModConflicts > Conflicts( IMod mod )
=> _conflicts.TryGetValue( mod, out var c ) ? c : new SingleArray< ModConflicts >(); => _conflicts.TryGetValue( mod, out var c ) ? c : new SingleArray< ModConflicts >();
// Count the number of changes of the effective file list.
// This is used for material and imc changes.
public int ChangeCounter { get; private set; }
private int _changedItemsSaveCounter = -1; private int _changedItemsSaveCounter = -1;
// Obtain currently changed items. Computes them if they haven't been computed before. // Obtain currently changed items. Computes them if they haven't been computed before.
@ -55,8 +52,10 @@ public partial class ModCollection
_collection.ModSettingChanged += OnModSettingChange; _collection.ModSettingChanged += OnModSettingChange;
_collection.InheritanceChanged += OnInheritanceChange; _collection.InheritanceChanged += OnInheritanceChange;
if( !Penumbra.CharacterUtility.Ready ) if( !Penumbra.CharacterUtility.Ready )
{
Penumbra.CharacterUtility.LoadingFinished += IncrementCounter; Penumbra.CharacterUtility.LoadingFinished += IncrementCounter;
} }
}
public void Dispose() public void Dispose()
{ {
@ -176,7 +175,7 @@ public partial class ModCollection
AddMetaFiles(); AddMetaFiles();
++ChangeCounter; ++_collection.ChangeCounter;
if( _collection == Penumbra.CollectionManager.Default && Penumbra.CharacterUtility.Ready ) if( _collection == Penumbra.CollectionManager.Default && Penumbra.CharacterUtility.Ready )
{ {
@ -239,7 +238,7 @@ public partial class ModCollection
if( addMetaChanges ) if( addMetaChanges )
{ {
++ChangeCounter; ++_collection.ChangeCounter;
if( _collection == Penumbra.CollectionManager.Default && Penumbra.CharacterUtility.Ready ) if( _collection == Penumbra.CollectionManager.Default && Penumbra.CharacterUtility.Ready )
{ {
Penumbra.ResidentResources.Reload(); Penumbra.ResidentResources.Reload();
@ -292,7 +291,7 @@ public partial class ModCollection
if( addMetaChanges ) if( addMetaChanges )
{ {
++ChangeCounter; ++_collection.ChangeCounter;
if( mod.TotalManipulations > 0 ) if( mod.TotalManipulations > 0 )
{ {
AddMetaFiles(); AddMetaFiles();
@ -449,7 +448,7 @@ public partial class ModCollection
// Increment the counter to ensure new files are loaded after applying meta changes. // Increment the counter to ensure new files are loaded after applying meta changes.
private void IncrementCounter() private void IncrementCounter()
{ {
++ChangeCounter; ++_collection.ChangeCounter;
Penumbra.CharacterUtility.LoadingFinished -= IncrementCounter; Penumbra.CharacterUtility.LoadingFinished -= IncrementCounter;
} }
@ -457,14 +456,14 @@ public partial class ModCollection
// Identify and record all manipulated objects for this entire collection. // Identify and record all manipulated objects for this entire collection.
private void SetChangedItems() private void SetChangedItems()
{ {
if( _changedItemsSaveCounter == ChangeCounter ) if( _changedItemsSaveCounter == _collection.ChangeCounter )
{ {
return; return;
} }
try try
{ {
_changedItemsSaveCounter = ChangeCounter; _changedItemsSaveCounter = _collection.ChangeCounter;
_changedItems.Clear(); _changedItems.Clear();
// Skip IMCs because they would result in far too many false-positive items, // Skip IMCs because they would result in far too many false-positive items,
// since they are per set instead of per item-slot/item/variant. // since they are per set instead of per item-slot/item/variant.

View file

@ -113,7 +113,7 @@ public unsafe partial class PathResolver
{ {
if( nonDefault && type == ResourceType.Mtrl ) if( nonDefault && type == ResourceType.Mtrl )
{ {
var fullPath = new FullPath( $"|{collection.Name}_{collection.RecomputeCounter}|{path}" ); var fullPath = new FullPath( $"|{collection.Name}_{collection.ChangeCounter}|{path}" );
data = ( fullPath, collection ); data = ( fullPath, collection );
} }
else else

View file

@ -145,7 +145,7 @@ public partial class MetaManager
} }
private FullPath CreateImcPath( Utf8GamePath path ) private FullPath CreateImcPath( Utf8GamePath path )
=> new($"|{_collection.Name}_{_collection.RecomputeCounter}|{path}"); => new($"|{_collection.Name}_{_collection.ChangeCounter}|{path}");
private static unsafe bool ImcLoadHandler( Utf8String split, Utf8String path, ResourceManager* resourceManager, private static unsafe bool ImcLoadHandler( Utf8String split, Utf8String path, ResourceManager* resourceManager,