Make IsMainThreadInPresent and CumulativePresentCalls clearer

This commit is contained in:
Soreepeong 2024-06-05 00:11:33 +09:00
parent 6d8102dc79
commit 3f138c2600
2 changed files with 11 additions and 9 deletions

View file

@ -217,7 +217,7 @@ internal class InterfaceManager : IInternalDisposableService
/// <summary>Gets a value indicating whether the main thread is executing <see cref="PresentDetour"/>.</summary>
/// <remarks>This still will be <c>true</c> even when queried off the main thread.</remarks>
public bool IsInPresent { get; private set; }
public bool IsMainThreadInPresent { get; private set; }
/// <summary>
/// Gets a value indicating the native handle of the game main window.
@ -249,9 +249,11 @@ internal class InterfaceManager : IInternalDisposableService
/// </summary>
public Task FontBuildTask => WhenFontsReady().dalamudAtlas!.BuildTask;
/// <summary>
/// Gets the number of calls to <see cref="PresentDetour"/> so far.
/// </summary>
/// <summary>Gets the number of calls to <see cref="PresentDetour"/> so far.</summary>
/// <remarks>
/// The value increases even when Dalamud is hidden via &quot;/xlui hide&quot;.
/// <see cref="DalamudInterface.FrameCount"/> does not.
/// </remarks>
public long CumulativePresentCalls { get; private set; }
/// <summary>
@ -657,7 +659,7 @@ internal class InterfaceManager : IInternalDisposableService
}
this.CumulativePresentCalls++;
this.IsInPresent = true;
this.IsMainThreadInPresent = true;
while (this.runBeforeImGuiRender.TryDequeue(out var action))
action.InvokeSafely();
@ -668,14 +670,14 @@ internal class InterfaceManager : IInternalDisposableService
RenderImGui(this.scene!);
this.PostImGuiRender();
this.IsInPresent = false;
this.IsMainThreadInPresent = false;
return pRes;
}
RenderImGui(this.scene!);
this.PostImGuiRender();
this.IsInPresent = false;
this.IsMainThreadInPresent = false;
return this.presentHook!.Original(swapChain, syncInterval, presentFlags);
}

View file

@ -380,7 +380,7 @@ internal sealed partial class TextureManager
// Not sure why this and the below can't be unconditional RunOnFrameworkThread
private async Task RunDuringPresent(Action action)
{
if (this.interfaceManager.IsInPresent && ThreadSafety.IsMainThread)
if (this.interfaceManager.IsMainThreadInPresent && ThreadSafety.IsMainThread)
action();
else
await this.interfaceManager.RunBeforeImGuiRender(action);
@ -392,7 +392,7 @@ internal sealed partial class TextureManager
/// <returns>The return value from the function.</returns>
private async Task<T> RunDuringPresent<T>(Func<T> func)
{
if (this.interfaceManager.IsInPresent && ThreadSafety.IsMainThread)
if (this.interfaceManager.IsMainThreadInPresent && ThreadSafety.IsMainThread)
return func();
return await this.interfaceManager.RunBeforeImGuiRender(func);
}