Temp fix for FPS drops with too many messages rendered

- Also replaces TextWrap with an ImRaii using version
This commit is contained in:
Infi
2024-05-13 15:24:51 +02:00
parent b7c6c1da5a
commit 26e993be67
5 changed files with 73 additions and 21 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<Version>1.24.2</Version> <Version>1.24.3</Version>
<TargetFramework>net8.0-windows</TargetFramework> <TargetFramework>net8.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
+4 -13
View File
@@ -222,7 +222,7 @@ public sealed class PayloadHandler {
} }
internal void Hover(Payload payload) { internal void Hover(Payload payload) {
var hoverSize = 250f * ImGuiHelpers.GlobalScale; var hoverSize = 350f * ImGuiHelpers.GlobalScale;
switch (payload) switch (payload)
{ {
@@ -260,21 +260,12 @@ public sealed class PayloadHandler {
{ {
ImGui.SetNextWindowSize(new Vector2(width, -1f)); ImGui.SetNextWindowSize(new Vector2(width, -1f));
ImGui.BeginTooltip(); using var tooltip = ImRaii.Tooltip();
ImGui.PushTextWrapPos(); using var color = ImRaii.PushColor(ImGuiCol.Text, LogWindow.DefaultText);
ImGui.PushStyleColor(ImGuiCol.Text, LogWindow.DefaultText); using var wrap = ImGuiUtil.TextWrapPos();
try
{
inside(); inside();
} }
finally
{
ImGui.PopStyleColor();
ImGui.PopTextWrapPos();
ImGui.EndTooltip();
}
}
public unsafe void MoveTooltip(AddonEvent type, AddonArgs args) public unsafe void MoveTooltip(AddonEvent type, AddonArgs args)
{ {
+26 -6
View File
@@ -896,6 +896,12 @@ public sealed class ChatLogWindow : Window
private void DrawMessages(Tab tab, PayloadHandler handler, bool isTable, bool moreCompact = false, float oldCellPaddingY = 0) private void DrawMessages(Tab tab, PayloadHandler handler, bool isTable, bool moreCompact = false, float oldCellPaddingY = 0)
{ {
// TODO Remove when the temp fix is replaced with a perm one
Plugin.DebuggerWindow.InvisibleMessages = 0;
Plugin.DebuggerWindow.InvisibleAfter = 0;
Plugin.DebuggerWindow.HeightNull = 0;
Plugin.DebuggerWindow.HeightCalculationsInside = 0;
try try
{ {
tab.MessagesMutex.Wait(); tab.MessagesMutex.Wait();
@@ -963,13 +969,19 @@ public sealed class ChatLogWindow : Window
if (i > 0) if (i > 0)
{ {
var prevMessage = tab.Messages[i - 1]; var prevMessage = tab.Messages[i - 1];
if (prevMessage.IsVisible.TryGetValue(tab.Identifier, out var prevVisible) && prevVisible)
// TODO: TryGetValue isn't always true for some strange reason
// This should be looked into, because default will be null for the prevHeight in that case
prevMessage.Height.TryGetValue(tab.Identifier, out var prevHeight);
if (prevHeight == null || (prevMessage.IsVisible.TryGetValue(tab.Identifier, out var prevVisible) && prevVisible))
{ {
Plugin.DebuggerWindow.HeightCalculationsInside++;
var newHeight = ImGui.GetCursorPosY() - lastPosY; var newHeight = ImGui.GetCursorPosY() - lastPosY;
// Remove the padding from the bottom of the previous row and the top of the current row.
if (isTable && !moreCompact) if (isTable && !moreCompact)
// Remove the padding from the bottom of the
// previous row and the top of the current row.
newHeight -= oldCellPaddingY * 2; newHeight -= oldCellPaddingY * 2;
if (newHeight != 0) if (newHeight != 0)
prevMessage.Height[tab.Identifier] = newHeight; prevMessage.Height[tab.Identifier] = newHeight;
} }
@@ -979,9 +991,12 @@ public sealed class ChatLogWindow : Window
// message has rendered once // message has rendered once
// message isn't visible, so render dummy // message isn't visible, so render dummy
message.Height.TryGetValue(tab.Identifier, out var height); message.Height.TryGetValue(tab.Identifier, out var height);
if (height == null)
Plugin.DebuggerWindow.HeightNull++;
message.IsVisible.TryGetValue(tab.Identifier, out var visible); message.IsVisible.TryGetValue(tab.Identifier, out var visible);
if (height != null && !visible) if (height != null && !visible)
{ {
Plugin.DebuggerWindow.InvisibleMessages++;
var beforeDummy = ImGui.GetCursorPos(); var beforeDummy = ImGui.GetCursorPos();
// skip to the message column for vis test // skip to the message column for vis test
@@ -999,8 +1014,10 @@ public sealed class ChatLogWindow : Window
ImGui.SetCursorPos(beforeDummy); ImGui.SetCursorPos(beforeDummy);
} }
else else
{
continue; continue;
} }
}
if (tab.DisplayTimestamp) if (tab.DisplayTimestamp)
{ {
@@ -1034,14 +1051,17 @@ public sealed class ChatLogWindow : Window
ImGui.SameLine(); ImGui.SameLine();
} }
// We need to draw something otherwise the item visibility check below won't work.
if (message.Content.Count == 0) if (message.Content.Count == 0)
// We need to draw something otherwise the item visibility
// check below won't work.
DrawChunks(new[] { new TextChunk(ChunkSource.Content, null, " ") }, true, handler, lineWidth); DrawChunks(new[] { new TextChunk(ChunkSource.Content, null, " ") }, true, handler, lineWidth);
else else
DrawChunks(message.Content, true, handler, lineWidth); DrawChunks(message.Content, true, handler, lineWidth);
message.IsVisible[tab.Identifier] = ImGui.IsItemVisible(); var vis = ImGui.IsItemVisible();
if (!vis)
Plugin.DebuggerWindow.InvisibleAfter++;
message.IsVisible[tab.Identifier] = vis;
} }
} }
finally finally
+11
View File
@@ -11,6 +11,11 @@ public class DebuggerWindow : Window
private readonly Plugin Plugin; private readonly Plugin Plugin;
private readonly ChatLogWindow ChatLogWindow; private readonly ChatLogWindow ChatLogWindow;
public int InvisibleMessages;
public int InvisibleAfter;
public int HeightNull;
public int HeightCalculationsInside;
public DebuggerWindow(Plugin plugin) : base($"Debugger###chat2-debugger") public DebuggerWindow(Plugin plugin) : base($"Debugger###chat2-debugger")
{ {
Plugin = plugin; Plugin = plugin;
@@ -50,5 +55,11 @@ public class DebuggerWindow : Window
ImGui.TextUnformatted($"Hovered Item: {ChatLogWindow.PayloadHandler._hoveredItem}"); ImGui.TextUnformatted($"Hovered Item: {ChatLogWindow.PayloadHandler._hoveredItem}");
ImGui.TextUnformatted($"Hover Counter: {ChatLogWindow.PayloadHandler._hoverCounter}"); ImGui.TextUnformatted($"Hover Counter: {ChatLogWindow.PayloadHandler._hoverCounter}");
ImGui.TextUnformatted($"Last Hover Counter: {ChatLogWindow.PayloadHandler._lastHoverCounter}"); ImGui.TextUnformatted($"Last Hover Counter: {ChatLogWindow.PayloadHandler._lastHoverCounter}");
ImGui.NewLine();
ImGui.NewLine();
ImGui.TextUnformatted($"Invisible Messages: {InvisibleMessages}");
ImGui.TextUnformatted($"Invisible After: {InvisibleAfter}");
ImGui.TextUnformatted($"Height was null: {HeightNull}");
ImGui.TextUnformatted($"Actual Height Calculations {HeightCalculationsInside}");
} }
} }
+30
View File
@@ -417,4 +417,34 @@ internal static class ImGuiUtil
return result != 0 || key == VirtualKey.NO_KEY; return result != 0 || key == VirtualKey.NO_KEY;
} }
private struct EndUnconditionally(Action endAction, bool success) : ImRaii.IEndObject
{
private Action EndAction { get; } = endAction;
public bool Success { get; } = success;
public bool Disposed { get; private set; } = false;
public void Dispose()
{
if (!Disposed)
{
EndAction();
Disposed = true;
}
}
}
public static ImRaii.IEndObject TextWrapPos()
{
ImGui.PushTextWrapPos();
return new EndUnconditionally(ImGui.PopTextWrapPos, true);
}
public static ImRaii.IEndObject TextWrapPos(float wrapLocalPosX)
{
ImGui.PushTextWrapPos(wrapLocalPosX);
return new EndUnconditionally(ImGui.PopTextWrapPos, true);
}
} }