From e398b56c6fff3bd695f66676fa9fb274f812949d Mon Sep 17 00:00:00 2001 From: Stanley Dimant Date: Mon, 13 Jan 2025 01:22:23 +0100 Subject: [PATCH] add mdl, tex, mtrl handling to transient resource manager, add delay on new file arrival --- .../FileCache/TransientResourceManager.cs | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/MareSynchronos/FileCache/TransientResourceManager.cs b/MareSynchronos/FileCache/TransientResourceManager.cs index f514df1..c2e14f4 100644 --- a/MareSynchronos/FileCache/TransientResourceManager.cs +++ b/MareSynchronos/FileCache/TransientResourceManager.cs @@ -16,7 +16,7 @@ public sealed class TransientResourceManager : DisposableMediatorSubscriberBase private readonly HashSet _cachedHandledPaths = new(StringComparer.Ordinal); private readonly TransientConfigService _configurationService; private readonly DalamudUtilService _dalamudUtil; - private readonly string[] _fileTypesToHandle = ["tmb", "pap", "avfx", "atex", "sklb", "eid", "phyb", "scd", "skp", "shpk"]; + private readonly string[] _fileTypesToHandle = ["tmb", "pap", "avfx", "atex", "sklb", "eid", "phyb", "scd", "skp", "shpk", "mdl", "mtrl", "tex"]; private readonly HashSet _playerRelatedPointers = []; private ConcurrentDictionary _cachedFrameAddresses = []; private ConcurrentDictionary>? _semiTransientResources = null; @@ -160,7 +160,13 @@ public sealed class TransientResourceManager : DisposableMediatorSubscriberBase { if (TransientResources.TryGetValue(objectKind, out var set)) { - set.RemoveWhere(p => list.Contains(p, StringComparer.OrdinalIgnoreCase)); + foreach (var file in set.Where(p => list.Contains(p, StringComparer.OrdinalIgnoreCase))) + { + Logger.LogTrace("Removing From Transient: {file}", file); + } + + int removed = set.RemoveWhere(p => list.Contains(p, StringComparer.OrdinalIgnoreCase)); + Logger.LogInformation("Removed {removed} previously existing paths", removed); } } @@ -275,9 +281,20 @@ public sealed class TransientResourceManager : DisposableMediatorSubscriberBase } else { + var thing = _playerRelatedPointers.FirstOrDefault(f => f.Address == gameObject); value.Add(replacedGamePath); - Logger.LogDebug("Adding {replacedGamePath} for {gameObject} ({filePath})", replacedGamePath, gameObject.ToString("X"), filePath); - Mediator.Publish(new TransientResourceChangedMessage(gameObject)); + Logger.LogDebug("Adding {replacedGamePath} for {gameObject} ({filePath})", replacedGamePath, thing?.ToString() ?? gameObject.ToString("X"), filePath); + _ = Task.Run(async () => + { + _sendTransientCts?.Cancel(); + _sendTransientCts?.Dispose(); + _sendTransientCts = new(); + var token = _sendTransientCts.Token; + await Task.Delay(TimeSpan.FromSeconds(2), token).ConfigureAwait(false); + Mediator.Publish(new TransientResourceChangedMessage(gameObject)); + }); } } + + private CancellationTokenSource _sendTransientCts = new(); } \ No newline at end of file