From 1522d8d7e72b2d31f71e2270bff5fdb7412214df Mon Sep 17 00:00:00 2001 From: rootdarkarchon Date: Fri, 17 Nov 2023 02:05:49 +0100 Subject: [PATCH] heave fewer redraws as main method for data application, minor fixes --- .../FileCache/TransientResourceManager.cs | 61 +++++++++++-------- .../Configurations/MareConfig.cs | 1 - .../PlayerData/Handlers/PairHandler.cs | 8 +-- MareSynchronos/Services/DalamudUtilService.cs | 15 ++++- .../ServerConfigurationManager.cs | 4 +- MareSynchronos/UI/SettingsUi.cs | 12 ---- MareSynchronos/UI/UISharedService.cs | 2 +- .../WebAPI/Files/FileUploadManager.cs | 2 +- 8 files changed, 53 insertions(+), 52 deletions(-) diff --git a/MareSynchronos/FileCache/TransientResourceManager.cs b/MareSynchronos/FileCache/TransientResourceManager.cs index 8848abd..00329f6 100644 --- a/MareSynchronos/FileCache/TransientResourceManager.cs +++ b/MareSynchronos/FileCache/TransientResourceManager.cs @@ -24,30 +24,6 @@ public sealed class TransientResourceManager : DisposableMediatorSubscriberBase _configurationService = configurationService; _dalamudUtil = dalamudUtil; - PlayerPersistentDataKey = _dalamudUtil.GetPlayerNameAsync().GetAwaiter().GetResult() + "_" + _dalamudUtil.GetWorldIdAsync().GetAwaiter().GetResult(); - - SemiTransientResources.TryAdd(ObjectKind.Player, new HashSet(StringComparer.Ordinal)); - if (_configurationService.Current.PlayerPersistentTransientCache.TryGetValue(PlayerPersistentDataKey, out var gamePaths)) - { - int restored = 0; - foreach (var gamePath in gamePaths) - { - if (string.IsNullOrEmpty(gamePath)) continue; - - try - { - Logger.LogDebug("Loaded persistent transient resource {path}", gamePath); - SemiTransientResources[ObjectKind.Player].Add(gamePath); - restored++; - } - catch (Exception ex) - { - Logger.LogWarning(ex, "Error during loading persistent transient resource {path}", gamePath); - } - } - Logger.LogDebug("Restored {restored}/{total} semi persistent resources", restored, gamePaths.Count); - } - Mediator.Subscribe(this, Manager_PenumbraResourceLoadEvent); Mediator.Subscribe(this, (_) => Manager_PenumbraModSettingChanged()); Mediator.Subscribe(this, (_) => DalamudUtil_FrameworkUpdate()); @@ -68,8 +44,41 @@ public sealed class TransientResourceManager : DisposableMediatorSubscriberBase }); } - private string PlayerPersistentDataKey { get; } - private ConcurrentDictionary> SemiTransientResources { get; } = new(); + private string PlayerPersistentDataKey => _dalamudUtil.GetPlayerNameAsync().GetAwaiter().GetResult() + "_" + _dalamudUtil.GetHomeWorldIdAsync().GetAwaiter().GetResult(); + private ConcurrentDictionary>? _semiTransientResources = null; + private ConcurrentDictionary> SemiTransientResources + { + get + { + if (_semiTransientResources == null) + { + _semiTransientResources = new(); + _semiTransientResources.TryAdd(ObjectKind.Player, new HashSet(StringComparer.Ordinal)); + if (_configurationService.Current.PlayerPersistentTransientCache.TryGetValue(PlayerPersistentDataKey, out var gamePaths)) + { + int restored = 0; + foreach (var gamePath in gamePaths) + { + if (string.IsNullOrEmpty(gamePath)) continue; + + try + { + Logger.LogDebug("Loaded persistent transient resource {path}", gamePath); + SemiTransientResources[ObjectKind.Player].Add(gamePath); + restored++; + } + catch (Exception ex) + { + Logger.LogWarning(ex, "Error during loading persistent transient resource {path}", gamePath); + } + } + Logger.LogDebug("Restored {restored}/{total} semi persistent resources", restored, gamePaths.Count); + } + } + + return _semiTransientResources; + } + } private ConcurrentDictionary> TransientResources { get; } = new(); public void CleanUpSemiTransientResources(ObjectKind objectKind, List? fileReplacement = null) diff --git a/MareSynchronos/MareConfiguration/Configurations/MareConfig.cs b/MareSynchronos/MareConfiguration/Configurations/MareConfig.cs index 1099395..8392327 100644 --- a/MareSynchronos/MareConfiguration/Configurations/MareConfig.cs +++ b/MareSynchronos/MareConfiguration/Configurations/MareConfig.cs @@ -52,5 +52,4 @@ public class MareConfig : IMareConfiguration public bool UseCompactor { get; set; } = false; public int Version { get; set; } = 1; public NotificationLocation WarningNotification { get; set; } = NotificationLocation.Both; - public bool UseLessRedraws { get; set; } = false; } \ No newline at end of file diff --git a/MareSynchronos/PlayerData/Handlers/PairHandler.cs b/MareSynchronos/PlayerData/Handlers/PairHandler.cs index c55d640..21593d4 100644 --- a/MareSynchronos/PlayerData/Handlers/PairHandler.cs +++ b/MareSynchronos/PlayerData/Handlers/PairHandler.cs @@ -77,7 +77,7 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase }); Mediator.Subscribe(this, (msg) => { - if (_mareConfigService.Current.UseLessRedraws && msg.gameObjectHandler == _charaHandler) + if (msg.gameObjectHandler == _charaHandler) { _redrawOnNextApplication = true; } @@ -262,7 +262,6 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase Logger.LogDebug("[{applicationId}] Applying Customization Data for {handler}", applicationId, handler); await _dalamudUtil.WaitWhileCharacterIsDrawing(Logger, handler, applicationId, 30000, token).ConfigureAwait(false); token.ThrowIfCancellationRequested(); - if (!_mareConfigService.Current.UseLessRedraws) changes.Value.Remove(PlayerChanges.ForcedRedraw); foreach (var change in changes.Value.OrderBy(p => (int)p)) { Logger.LogDebug("[{applicationId}] Processing {change} for {handler}", applicationId, change, handler); @@ -307,11 +306,6 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase } token.ThrowIfCancellationRequested(); } - - if (!_mareConfigService.Current.UseLessRedraws && (changes.Value.Contains(PlayerChanges.ModFiles) || changes.Value.Contains(PlayerChanges.ModManip) || changes.Value.Contains(PlayerChanges.Glamourer))) - { - await _ipcManager.PenumbraRedrawAsync(Logger, handler, applicationId, token).ConfigureAwait(false); - } } finally { diff --git a/MareSynchronos/Services/DalamudUtilService.cs b/MareSynchronos/Services/DalamudUtilService.cs index 724cfad..0306e1c 100644 --- a/MareSynchronos/Services/DalamudUtilService.cs +++ b/MareSynchronos/Services/DalamudUtilService.cs @@ -173,7 +173,7 @@ public class DalamudUtilService : IHostedService public async Task GetPlayerNameHashedAsync() { - return await RunOnFrameworkThread(() => (GetPlayerName() + GetWorldId()).GetHash256()).ConfigureAwait(false); + return await RunOnFrameworkThread(() => (GetPlayerName() + GetHomeWorldId()).GetHash256()).ConfigureAwait(false); } public IntPtr GetPlayerPointer() @@ -187,17 +187,28 @@ public class DalamudUtilService : IHostedService return await RunOnFrameworkThread(GetPlayerPointer).ConfigureAwait(false); } - public uint GetWorldId() + public uint GetHomeWorldId() { EnsureIsOnFramework(); return _clientState.LocalPlayer!.HomeWorld.Id; } + public uint GetWorldId() + { + EnsureIsOnFramework(); + return _clientState.LocalPlayer!.CurrentWorld.Id; + } + public async Task GetWorldIdAsync() { return await RunOnFrameworkThread(GetWorldId).ConfigureAwait(false); } + public async Task GetHomeWorldIdAsync() + { + return await RunOnFrameworkThread(GetHomeWorldId).ConfigureAwait(false); + } + public unsafe bool IsGameObjectPresent(IntPtr key) { return _objectTable.Any(f => f.Address == key); diff --git a/MareSynchronos/Services/ServerConfiguration/ServerConfigurationManager.cs b/MareSynchronos/Services/ServerConfiguration/ServerConfigurationManager.cs index f89c6a8..b7c717d 100644 --- a/MareSynchronos/Services/ServerConfiguration/ServerConfigurationManager.cs +++ b/MareSynchronos/Services/ServerConfiguration/ServerConfigurationManager.cs @@ -62,7 +62,7 @@ public class ServerConfigurationManager } var charaName = _dalamudUtil.GetPlayerNameAsync().GetAwaiter().GetResult(); - var worldId = _dalamudUtil.GetWorldIdAsync().GetAwaiter().GetResult(); + var worldId = _dalamudUtil.GetHomeWorldIdAsync().GetAwaiter().GetResult(); if (!currentServer.Authentications.Any() && currentServer.SecretKeys.Any()) { currentServer.Authentications.Add(new Authentication() @@ -136,7 +136,7 @@ public class ServerConfigurationManager server.Authentications.Add(new Authentication() { CharacterName = _dalamudUtil.GetPlayerNameAsync().GetAwaiter().GetResult(), - WorldId = _dalamudUtil.GetWorldIdAsync().GetAwaiter().GetResult(), + WorldId = _dalamudUtil.GetHomeWorldIdAsync().GetAwaiter().GetResult(), SecretKeyIdx = addLastSecretKey ? server.SecretKeys.Last().Key : -1, }); Save(); diff --git a/MareSynchronos/UI/SettingsUi.cs b/MareSynchronos/UI/SettingsUi.cs index 1d7cc0b..b238ced 100644 --- a/MareSynchronos/UI/SettingsUi.cs +++ b/MareSynchronos/UI/SettingsUi.cs @@ -549,18 +549,6 @@ public class SettingsUi : WindowMediatorSubscriberBase } _lastTab = "General"; - UiSharedService.FontText("General Settings", _uiShared.UidFont); - bool lessRedraws = _configService.Current.UseLessRedraws; - if (ImGui.Checkbox("[Experimental] Use fewer redraws", ref lessRedraws)) - { - _configService.Current.UseLessRedraws = lessRedraws; - _configService.Save(); - } - UiSharedService.DrawHelpText("This will attempt to use fewer redraws. Changes that solely affect the players body appearance (i.e. clothes) should not cause a redraw anymore." + Environment.NewLine + - "Some changes, especially to hair, face, tail or any vfx, animation or skeleton changes, or class changes will still force a redraw." + Environment.NewLine + Environment.NewLine + - "WARNING: this is an experimental, little tested feature and can potentially lead to issues with animation state or crashes. Use at your own risk."); - ImGui.Separator(); - UiSharedService.FontText("Notes", _uiShared.UidFont); if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.StickyNote, "Export all your user notes to clipboard")) { diff --git a/MareSynchronos/UI/UISharedService.cs b/MareSynchronos/UI/UISharedService.cs index 5fea4db..ac32007 100644 --- a/MareSynchronos/UI/UISharedService.cs +++ b/MareSynchronos/UI/UISharedService.cs @@ -125,7 +125,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase public Dictionary WorldData => _dalamudUtil.WorldData.Value; - public uint WorldId => _dalamudUtil.GetWorldId(); + public uint WorldId => _dalamudUtil.GetHomeWorldId(); public const string TooltipSeparator = "--SEP--"; diff --git a/MareSynchronos/WebAPI/Files/FileUploadManager.cs b/MareSynchronos/WebAPI/Files/FileUploadManager.cs index 15e1935..171c11f 100644 --- a/MareSynchronos/WebAPI/Files/FileUploadManager.cs +++ b/MareSynchronos/WebAPI/Files/FileUploadManager.cs @@ -198,7 +198,7 @@ public sealed class FileUploadManager : DisposableMediatorSubscriberBase Logger.LogDebug("Verifying {count} files", unverifiedUploadHashes.Count); var filesToUpload = await FilesSend([.. unverifiedUploadHashes], visiblePlayers.Select(p => p.UID).ToList(), uploadToken).ConfigureAwait(false); - foreach (var file in filesToUpload.Where(f => !f.IsForbidden)) + foreach (var file in filesToUpload.Where(f => !f.IsForbidden).DistinctBy(f => f.Hash)) { try {