heave fewer redraws as main method for data application, minor fixes

This commit is contained in:
rootdarkarchon
2023-11-17 02:05:49 +01:00
parent f89bbc45e6
commit 1522d8d7e7
8 changed files with 53 additions and 52 deletions

View File

@@ -24,30 +24,6 @@ public sealed class TransientResourceManager : DisposableMediatorSubscriberBase
_configurationService = configurationService; _configurationService = configurationService;
_dalamudUtil = dalamudUtil; _dalamudUtil = dalamudUtil;
PlayerPersistentDataKey = _dalamudUtil.GetPlayerNameAsync().GetAwaiter().GetResult() + "_" + _dalamudUtil.GetWorldIdAsync().GetAwaiter().GetResult();
SemiTransientResources.TryAdd(ObjectKind.Player, new HashSet<string>(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<PenumbraResourceLoadMessage>(this, Manager_PenumbraResourceLoadEvent); Mediator.Subscribe<PenumbraResourceLoadMessage>(this, Manager_PenumbraResourceLoadEvent);
Mediator.Subscribe<PenumbraModSettingChangedMessage>(this, (_) => Manager_PenumbraModSettingChanged()); Mediator.Subscribe<PenumbraModSettingChangedMessage>(this, (_) => Manager_PenumbraModSettingChanged());
Mediator.Subscribe<FrameworkUpdateMessage>(this, (_) => DalamudUtil_FrameworkUpdate()); Mediator.Subscribe<FrameworkUpdateMessage>(this, (_) => DalamudUtil_FrameworkUpdate());
@@ -68,8 +44,41 @@ public sealed class TransientResourceManager : DisposableMediatorSubscriberBase
}); });
} }
private string PlayerPersistentDataKey { get; } private string PlayerPersistentDataKey => _dalamudUtil.GetPlayerNameAsync().GetAwaiter().GetResult() + "_" + _dalamudUtil.GetHomeWorldIdAsync().GetAwaiter().GetResult();
private ConcurrentDictionary<ObjectKind, HashSet<string>> SemiTransientResources { get; } = new(); private ConcurrentDictionary<ObjectKind, HashSet<string>>? _semiTransientResources = null;
private ConcurrentDictionary<ObjectKind, HashSet<string>> SemiTransientResources
{
get
{
if (_semiTransientResources == null)
{
_semiTransientResources = new();
_semiTransientResources.TryAdd(ObjectKind.Player, new HashSet<string>(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<IntPtr, HashSet<string>> TransientResources { get; } = new(); private ConcurrentDictionary<IntPtr, HashSet<string>> TransientResources { get; } = new();
public void CleanUpSemiTransientResources(ObjectKind objectKind, List<FileReplacement>? fileReplacement = null) public void CleanUpSemiTransientResources(ObjectKind objectKind, List<FileReplacement>? fileReplacement = null)

View File

@@ -52,5 +52,4 @@ public class MareConfig : IMareConfiguration
public bool UseCompactor { get; set; } = false; public bool UseCompactor { get; set; } = false;
public int Version { get; set; } = 1; public int Version { get; set; } = 1;
public NotificationLocation WarningNotification { get; set; } = NotificationLocation.Both; public NotificationLocation WarningNotification { get; set; } = NotificationLocation.Both;
public bool UseLessRedraws { get; set; } = false;
} }

View File

@@ -77,7 +77,7 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
}); });
Mediator.Subscribe<ClassJobChangedMessage>(this, (msg) => Mediator.Subscribe<ClassJobChangedMessage>(this, (msg) =>
{ {
if (_mareConfigService.Current.UseLessRedraws && msg.gameObjectHandler == _charaHandler) if (msg.gameObjectHandler == _charaHandler)
{ {
_redrawOnNextApplication = true; _redrawOnNextApplication = true;
} }
@@ -262,7 +262,6 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
Logger.LogDebug("[{applicationId}] Applying Customization Data for {handler}", applicationId, handler); Logger.LogDebug("[{applicationId}] Applying Customization Data for {handler}", applicationId, handler);
await _dalamudUtil.WaitWhileCharacterIsDrawing(Logger, handler, applicationId, 30000, token).ConfigureAwait(false); await _dalamudUtil.WaitWhileCharacterIsDrawing(Logger, handler, applicationId, 30000, token).ConfigureAwait(false);
token.ThrowIfCancellationRequested(); token.ThrowIfCancellationRequested();
if (!_mareConfigService.Current.UseLessRedraws) changes.Value.Remove(PlayerChanges.ForcedRedraw);
foreach (var change in changes.Value.OrderBy(p => (int)p)) foreach (var change in changes.Value.OrderBy(p => (int)p))
{ {
Logger.LogDebug("[{applicationId}] Processing {change} for {handler}", applicationId, change, handler); Logger.LogDebug("[{applicationId}] Processing {change} for {handler}", applicationId, change, handler);
@@ -307,11 +306,6 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
} }
token.ThrowIfCancellationRequested(); 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 finally
{ {

View File

@@ -173,7 +173,7 @@ public class DalamudUtilService : IHostedService
public async Task<string> GetPlayerNameHashedAsync() public async Task<string> GetPlayerNameHashedAsync()
{ {
return await RunOnFrameworkThread(() => (GetPlayerName() + GetWorldId()).GetHash256()).ConfigureAwait(false); return await RunOnFrameworkThread(() => (GetPlayerName() + GetHomeWorldId()).GetHash256()).ConfigureAwait(false);
} }
public IntPtr GetPlayerPointer() public IntPtr GetPlayerPointer()
@@ -187,17 +187,28 @@ public class DalamudUtilService : IHostedService
return await RunOnFrameworkThread(GetPlayerPointer).ConfigureAwait(false); return await RunOnFrameworkThread(GetPlayerPointer).ConfigureAwait(false);
} }
public uint GetWorldId() public uint GetHomeWorldId()
{ {
EnsureIsOnFramework(); EnsureIsOnFramework();
return _clientState.LocalPlayer!.HomeWorld.Id; return _clientState.LocalPlayer!.HomeWorld.Id;
} }
public uint GetWorldId()
{
EnsureIsOnFramework();
return _clientState.LocalPlayer!.CurrentWorld.Id;
}
public async Task<uint> GetWorldIdAsync() public async Task<uint> GetWorldIdAsync()
{ {
return await RunOnFrameworkThread(GetWorldId).ConfigureAwait(false); return await RunOnFrameworkThread(GetWorldId).ConfigureAwait(false);
} }
public async Task<uint> GetHomeWorldIdAsync()
{
return await RunOnFrameworkThread(GetHomeWorldId).ConfigureAwait(false);
}
public unsafe bool IsGameObjectPresent(IntPtr key) public unsafe bool IsGameObjectPresent(IntPtr key)
{ {
return _objectTable.Any(f => f.Address == key); return _objectTable.Any(f => f.Address == key);

View File

@@ -62,7 +62,7 @@ public class ServerConfigurationManager
} }
var charaName = _dalamudUtil.GetPlayerNameAsync().GetAwaiter().GetResult(); 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()) if (!currentServer.Authentications.Any() && currentServer.SecretKeys.Any())
{ {
currentServer.Authentications.Add(new Authentication() currentServer.Authentications.Add(new Authentication()
@@ -136,7 +136,7 @@ public class ServerConfigurationManager
server.Authentications.Add(new Authentication() server.Authentications.Add(new Authentication()
{ {
CharacterName = _dalamudUtil.GetPlayerNameAsync().GetAwaiter().GetResult(), CharacterName = _dalamudUtil.GetPlayerNameAsync().GetAwaiter().GetResult(),
WorldId = _dalamudUtil.GetWorldIdAsync().GetAwaiter().GetResult(), WorldId = _dalamudUtil.GetHomeWorldIdAsync().GetAwaiter().GetResult(),
SecretKeyIdx = addLastSecretKey ? server.SecretKeys.Last().Key : -1, SecretKeyIdx = addLastSecretKey ? server.SecretKeys.Last().Key : -1,
}); });
Save(); Save();

View File

@@ -549,18 +549,6 @@ public class SettingsUi : WindowMediatorSubscriberBase
} }
_lastTab = "General"; _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); UiSharedService.FontText("Notes", _uiShared.UidFont);
if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.StickyNote, "Export all your user notes to clipboard")) if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.StickyNote, "Export all your user notes to clipboard"))
{ {

View File

@@ -125,7 +125,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
public Dictionary<ushort, string> WorldData => _dalamudUtil.WorldData.Value; public Dictionary<ushort, string> WorldData => _dalamudUtil.WorldData.Value;
public uint WorldId => _dalamudUtil.GetWorldId(); public uint WorldId => _dalamudUtil.GetHomeWorldId();
public const string TooltipSeparator = "--SEP--"; public const string TooltipSeparator = "--SEP--";

View File

@@ -198,7 +198,7 @@ public sealed class FileUploadManager : DisposableMediatorSubscriberBase
Logger.LogDebug("Verifying {count} files", unverifiedUploadHashes.Count); Logger.LogDebug("Verifying {count} files", unverifiedUploadHashes.Count);
var filesToUpload = await FilesSend([.. unverifiedUploadHashes], visiblePlayers.Select(p => p.UID).ToList(), uploadToken).ConfigureAwait(false); 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 try
{ {