From 7793b9beecc2c1b69e8effcefc37114e69286fcd Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Mon, 26 Jul 2021 16:48:49 +0200 Subject: [PATCH] Include a number of frames to wait after zone changes before redrawing, configurable in advanced settings. --- Penumbra/Configuration.cs | 1 + Penumbra/Interop/ActorRefresher.cs | 17 ++++++++++++++--- Penumbra/Plugin.cs | 2 +- Penumbra/UI/MenuTabs/TabSettings.cs | 26 ++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/Penumbra/Configuration.cs b/Penumbra/Configuration.cs index a907f00f..8424d974 100644 --- a/Penumbra/Configuration.cs +++ b/Penumbra/Configuration.cs @@ -22,6 +22,7 @@ namespace Penumbra public bool EnableHttpApi { get; set; } public bool EnableActorWatch { get; set; } = false; + public int WaitFrames { get; set; } = 30; public string ModDirectory { get; set; } = string.Empty; diff --git a/Penumbra/Interop/ActorRefresher.cs b/Penumbra/Interop/ActorRefresher.cs index c56780da..06732841 100644 --- a/Penumbra/Interop/ActorRefresher.cs +++ b/Penumbra/Interop/ActorRefresher.cs @@ -36,6 +36,9 @@ namespace Penumbra.Interop private readonly ModManager _mods; private readonly Queue< (int actorId, string name, RedrawType s) > _actorIds = new(); + internal int DefaultWaitFrames; + + private int _waitFrames = 0; private int _currentFrame = 0; private bool _changedSettings = false; private int _currentActorId = -1; @@ -46,10 +49,11 @@ namespace Penumbra.Interop public static IntPtr RenderPtr( Actor actor ) => actor.Address + RenderModeOffset; - public ActorRefresher( DalamudPluginInterface pi, ModManager mods ) + public ActorRefresher( DalamudPluginInterface pi, ModManager mods, int defaultWaitFrames ) { - _pi = pi; - _mods = mods; + _pi = pi; + _mods = mods; + DefaultWaitFrames = defaultWaitFrames; } private void ChangeSettings() @@ -251,6 +255,13 @@ namespace Penumbra.Interop { if( _pi.ClientState.Condition[ ConditionFlag.BetweenAreas51 ] || _pi.ClientState.Condition[ ConditionFlag.BetweenAreas ] ) { + _waitFrames = DefaultWaitFrames; + return; + } + + if( _waitFrames > 0 ) + { + --_waitFrames; return; } diff --git a/Penumbra/Plugin.cs b/Penumbra/Plugin.cs index 6e605c3e..58cf6491 100644 --- a/Penumbra/Plugin.cs +++ b/Penumbra/Plugin.cs @@ -57,7 +57,7 @@ namespace Penumbra modManager.DiscoverMods(); - ActorRefresher = new ActorRefresher( PluginInterface, modManager ); + ActorRefresher = new ActorRefresher( PluginInterface, modManager, Configuration.WaitFrames ); ResourceLoader = new ResourceLoader( this ); diff --git a/Penumbra/UI/MenuTabs/TabSettings.cs b/Penumbra/UI/MenuTabs/TabSettings.cs index 8aab2b1b..31efe8bd 100644 --- a/Penumbra/UI/MenuTabs/TabSettings.cs +++ b/Penumbra/UI/MenuTabs/TabSettings.cs @@ -21,6 +21,7 @@ namespace Penumbra.UI private const string LabelOpenFolder = "Open Mods Folder"; private const string LabelEnabled = "Enable Mods"; private const string LabelEnabledPlayerWatch = "Enable automatic Character Redraws"; + private const string LabelWaitFrames = "Wait Frames"; private const string LabelScaleModSelector = "Scale Mod Selector With Window Size"; private const string LabelShowAdvanced = "Show Advanced Settings"; private const string LabelLogLoadedFiles = "Log all loaded files"; @@ -174,6 +175,31 @@ namespace Penumbra.UI "If this setting is enabled, penumbra will keep tabs on characters that have a corresponding collection setup in the Collections tab.\n" + "Penumbra will try to automatically redraw those characters using their collection when they first appear in an instance, or when they change their current equip." ); } + + if( _config.EnableActorWatch && _config.ShowAdvanced ) + { + var waitFrames = _config.WaitFrames; + ImGui.SameLine(); + ImGui.SetNextItemWidth( 50 ); + if( ImGui.InputInt( LabelWaitFrames, ref waitFrames, 0, 0 ) + && waitFrames != _config.WaitFrames + && waitFrames > 0 + && waitFrames < 3000 ) + { + _base._plugin.ActorRefresher.DefaultWaitFrames = waitFrames; + _config.WaitFrames = waitFrames; + _configChanged = true; + } + + if( ImGui.IsItemHovered() ) + { + ImGui.SetTooltip( + "The number of frames penumbra waits after some events (like zone changes) until it starts trying to redraw actors again, in a range of [1, 3001].\n" + + "Keep this as low as possible while producing stable results." ); + } + + ; + } } private static void DrawReloadResourceButton()