mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
Extract collection counters.
This commit is contained in:
parent
7a2691b942
commit
fbbfe5e00d
10 changed files with 48 additions and 32 deletions
|
|
@ -2,7 +2,6 @@ using Penumbra.GameData.Enums;
|
|||
using Penumbra.GameData.Files;
|
||||
using Penumbra.GameData.Files.AtchStructs;
|
||||
using Penumbra.Meta;
|
||||
using Penumbra.Meta.Files;
|
||||
using Penumbra.Meta.Manipulations;
|
||||
|
||||
namespace Penumbra.Collections.Cache;
|
||||
|
|
@ -37,7 +36,7 @@ public sealed class AtchCache(MetaFileManager manager, ModCollection collection)
|
|||
|
||||
protected override void ApplyModInternal(AtchIdentifier identifier, AtchEntry entry)
|
||||
{
|
||||
++Collection.AtchChangeCounter;
|
||||
Collection.Counters.IncrementAtch();
|
||||
ApplyFile(identifier, entry);
|
||||
}
|
||||
|
||||
|
|
@ -68,7 +67,7 @@ public sealed class AtchCache(MetaFileManager manager, ModCollection collection)
|
|||
|
||||
protected override void RevertModInternal(AtchIdentifier identifier)
|
||||
{
|
||||
++Collection.AtchChangeCounter;
|
||||
Collection.Counters.IncrementAtch();
|
||||
if (!_atchFiles.TryGetValue(identifier.GenderRace, out var pair))
|
||||
return;
|
||||
|
||||
|
|
|
|||
|
|
@ -177,7 +177,7 @@ public sealed class CollectionCache : IDisposable
|
|||
var (paths, manipulations) = ModData.RemoveMod(mod);
|
||||
|
||||
if (addMetaChanges)
|
||||
_collection.IncrementCounter();
|
||||
_collection.Counters.IncrementChange();
|
||||
|
||||
foreach (var path in paths)
|
||||
{
|
||||
|
|
@ -250,7 +250,7 @@ public sealed class CollectionCache : IDisposable
|
|||
|
||||
if (addMetaChanges)
|
||||
{
|
||||
_collection.IncrementCounter();
|
||||
_collection.Counters.IncrementChange();
|
||||
_manager.MetaFileManager.ApplyDefaultFiles(_collection);
|
||||
}
|
||||
}
|
||||
|
|
@ -408,12 +408,12 @@ public sealed class CollectionCache : IDisposable
|
|||
// Identify and record all manipulated objects for this entire collection.
|
||||
private void SetChangedItems()
|
||||
{
|
||||
if (_changedItemsSaveCounter == _collection.ChangeCounter)
|
||||
if (_changedItemsSaveCounter == _collection.Counters.Change)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
_changedItemsSaveCounter = _collection.ChangeCounter;
|
||||
_changedItemsSaveCounter = _collection.Counters.Change;
|
||||
_changedItems.Clear();
|
||||
// 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.
|
||||
|
|
|
|||
|
|
@ -187,7 +187,7 @@ public class CollectionCacheManager : IDisposable, IService
|
|||
foreach (var mod in _modStorage)
|
||||
cache.AddModSync(mod, false);
|
||||
|
||||
collection.IncrementCounter();
|
||||
collection.Counters.IncrementChange();
|
||||
|
||||
MetaFileManager.ApplyDefaultFiles(collection);
|
||||
ResolvedFileChanged.Invoke(collection, ResolvedFileChanged.Type.FullRecomputeFinished, Utf8GamePath.Empty, FullPath.Empty,
|
||||
|
|
@ -297,7 +297,7 @@ public class CollectionCacheManager : IDisposable, IService
|
|||
private void IncrementCounters()
|
||||
{
|
||||
foreach (var collection in _storage.Where(c => c.HasCache))
|
||||
collection.IncrementCounter();
|
||||
collection.Counters.IncrementChange();
|
||||
MetaFileManager.CharacterUtility.LoadingFinished -= IncrementCounters;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public sealed class ImcCache(MetaFileManager manager, ModCollection collection)
|
|||
|
||||
protected override void ApplyModInternal(ImcIdentifier identifier, ImcEntry entry)
|
||||
{
|
||||
++Collection.ImcChangeCounter;
|
||||
Collection.Counters.IncrementImc();
|
||||
ApplyFile(identifier, entry);
|
||||
}
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ public sealed class ImcCache(MetaFileManager manager, ModCollection collection)
|
|||
|
||||
protected override void RevertModInternal(ImcIdentifier identifier)
|
||||
{
|
||||
++Collection.ImcChangeCounter;
|
||||
Collection.Counters.IncrementImc();
|
||||
var path = identifier.GamePath().Path;
|
||||
if (!_imcFiles.TryGetValue(path, out var pair))
|
||||
return;
|
||||
|
|
|
|||
28
Penumbra/Collections/CollectionCounters.cs
Normal file
28
Penumbra/Collections/CollectionCounters.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
namespace Penumbra.Collections;
|
||||
|
||||
public struct CollectionCounters(int changeCounter)
|
||||
{
|
||||
/// <summary> Count the number of changes of the effective file list. </summary>
|
||||
public int Change { get; private set; } = changeCounter;
|
||||
|
||||
/// <summary> Count the number of IMC-relevant changes of the effective file list. </summary>
|
||||
public int Imc { get; private set; }
|
||||
|
||||
/// <summary> Count the number of ATCH-relevant changes of the effective file list. </summary>
|
||||
public int Atch { get; private set; }
|
||||
|
||||
/// <summary> Increment the number of changes in the effective file list. </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int IncrementChange()
|
||||
=> ++Change;
|
||||
|
||||
/// <summary> Increment the number of IMC-relevant changes in the effective file list. </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int IncrementImc()
|
||||
=> ++Imc;
|
||||
|
||||
/// <summary> Increment the number of ATCH-relevant changes in the effective file list. </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int IncrementAtch()
|
||||
=> ++Imc;
|
||||
}
|
||||
|
|
@ -372,7 +372,7 @@ public class CollectionStorage : IReadOnlyList<ModCollection>, IDisposable, ISer
|
|||
{
|
||||
var (settings, _) = collection[mod.Index];
|
||||
if (settings is { Enabled: true })
|
||||
collection.IncrementCounter();
|
||||
collection.Counters.IncrementChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ public class TempCollectionManager : IDisposable, IService
|
|||
|
||||
_storage.Delete(collection);
|
||||
Penumbra.Log.Debug($"Deleted temporary collection {collection.Id}.");
|
||||
GlobalChangeCounter += Math.Max(collection.ChangeCounter + 1 - GlobalChangeCounter, 0);
|
||||
GlobalChangeCounter += Math.Max(collection.Counters.Change + 1 - GlobalChangeCounter, 0);
|
||||
for (var i = 0; i < Collections.Count; ++i)
|
||||
{
|
||||
if (Collections[i].Collection != collection)
|
||||
|
|
|
|||
|
|
@ -50,18 +50,7 @@ public partial class ModCollection
|
|||
/// <summary> The index of the collection is set and kept up-to-date by the CollectionManager. </summary>
|
||||
public int Index { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Count the number of changes of the effective file list.
|
||||
/// This is used for material and imc changes.
|
||||
/// </summary>
|
||||
public int ChangeCounter { get; private set; }
|
||||
|
||||
public uint ImcChangeCounter { get; set; }
|
||||
public uint AtchChangeCounter { get; set; }
|
||||
|
||||
/// <summary> Increment the number of changes in the effective file list. </summary>
|
||||
public int IncrementCounter()
|
||||
=> ++ChangeCounter;
|
||||
public CollectionCounters Counters;
|
||||
|
||||
/// <summary>
|
||||
/// If a ModSetting is null, it can be inherited from other collections.
|
||||
|
|
@ -213,7 +202,7 @@ public partial class ModCollection
|
|||
Id = id;
|
||||
LocalId = localId;
|
||||
Index = index;
|
||||
ChangeCounter = changeCounter;
|
||||
Counters = new CollectionCounters(changeCounter);
|
||||
Settings = appliedSettings;
|
||||
UnusedSettings = settings;
|
||||
DirectlyInheritsFrom = inheritsFrom;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ public static class PathDataHandler
|
|||
/// <summary> Create the encoding path for an IMC file. </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static FullPath CreateImc(CiByteString path, ModCollection collection)
|
||||
=> new($"|{collection.LocalId.Id}_{collection.ImcChangeCounter}_{DiscriminatorString}|{path}");
|
||||
=> new($"|{collection.LocalId.Id}_{collection.Counters.Imc}_{DiscriminatorString}|{path}");
|
||||
|
||||
/// <summary> Create the encoding path for a TMB file. </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
|
@ -47,17 +47,17 @@ public static class PathDataHandler
|
|||
/// <summary> Create the encoding path for an ATCH file. </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static FullPath CreateAtch(CiByteString path, ModCollection collection)
|
||||
=> new($"|{collection.LocalId.Id}_{collection.AtchChangeCounter}_{DiscriminatorString}|{path}");
|
||||
=> new($"|{collection.LocalId.Id}_{collection.Counters.Atch}_{DiscriminatorString}|{path}");
|
||||
|
||||
/// <summary> Create the encoding path for a MTRL file. </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static FullPath CreateMtrl(CiByteString path, ModCollection collection, Utf8GamePath originalPath)
|
||||
=> new($"|{collection.LocalId.Id}_{collection.ChangeCounter}_{originalPath.Path.Crc32:X8}_{DiscriminatorString}|{path}");
|
||||
=> new($"|{collection.LocalId.Id}_{collection.Counters.Change}_{originalPath.Path.Crc32:X8}_{DiscriminatorString}|{path}");
|
||||
|
||||
/// <summary> The base function shared by most file types. </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static FullPath CreateBase(CiByteString path, ModCollection collection)
|
||||
=> new($"|{collection.LocalId.Id}_{collection.ChangeCounter}_{DiscriminatorString}|{path}");
|
||||
=> new($"|{collection.LocalId.Id}_{collection.Counters.Change}_{DiscriminatorString}|{path}");
|
||||
|
||||
/// <summary> Read an additional data blurb and parse it into usable data for all file types but Materials. </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
|
|
|||
|
|
@ -204,7 +204,7 @@ public class DebugTab : Window, ITab, IUiService
|
|||
if (collection.HasCache)
|
||||
{
|
||||
using var color = PushColor(ImGuiCol.Text, ColorId.FolderExpanded.Value());
|
||||
using var node = TreeNode($"{collection.Name} (Change Counter {collection.ChangeCounter})###{collection.Name}");
|
||||
using var node = TreeNode($"{collection.Name} (Change Counter {collection.Counters.Change})###{collection.Name}");
|
||||
if (!node)
|
||||
continue;
|
||||
|
||||
|
|
@ -239,7 +239,7 @@ public class DebugTab : Window, ITab, IUiService
|
|||
else
|
||||
{
|
||||
using var color = PushColor(ImGuiCol.Text, ColorId.UndefinedMod.Value());
|
||||
TreeNode($"{collection.AnonymizedName} (Change Counter {collection.ChangeCounter})",
|
||||
TreeNode($"{collection.AnonymizedName} (Change Counter {collection.Counters.Change})",
|
||||
ImGuiTreeNodeFlags.Bullet | ImGuiTreeNodeFlags.Leaf).Dispose();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue