mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-01-03 14:23:40 +01:00
cleanup
This commit is contained in:
parent
5081ac10e1
commit
427e5e7c06
5 changed files with 50 additions and 39 deletions
|
|
@ -79,7 +79,7 @@ internal class InterfaceManager : IInternalDisposableService
|
|||
private readonly ConcurrentQueue<Action> runBeforeImGuiRender = new();
|
||||
private readonly ConcurrentQueue<Action> runAfterImGuiRender = new();
|
||||
|
||||
private IWin32Backend? scene;
|
||||
private IWin32Backend? backend;
|
||||
|
||||
private Hook<SetCursorDelegate>? setCursorHook;
|
||||
private Hook<PresentDelegate>? presentHook;
|
||||
|
|
@ -179,26 +179,26 @@ internal class InterfaceManager : IInternalDisposableService
|
|||
/// <summary>
|
||||
/// Gets the DX11 scene.
|
||||
/// </summary>
|
||||
public IImGuiBackend? Scene => this.scene;
|
||||
public IImGuiBackend? Backend => this.backend;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether or not the game's cursor should be overridden with the ImGui cursor.
|
||||
/// </summary>
|
||||
public bool OverrideGameCursor
|
||||
{
|
||||
get => this.scene?.UpdateCursor ?? this.isOverrideGameCursor;
|
||||
get => this.backend?.UpdateCursor ?? this.isOverrideGameCursor;
|
||||
set
|
||||
{
|
||||
this.isOverrideGameCursor = value;
|
||||
if (this.scene != null)
|
||||
this.scene.UpdateCursor = value;
|
||||
if (this.backend != null)
|
||||
this.backend.UpdateCursor = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the Dalamud interface ready to use.
|
||||
/// </summary>
|
||||
public bool IsReady => this.scene != null;
|
||||
public bool IsReady => this.backend != null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether or not Draw events should be dispatched.
|
||||
|
|
@ -282,7 +282,7 @@ internal class InterfaceManager : IInternalDisposableService
|
|||
this.IconFontHandle = null;
|
||||
|
||||
Interlocked.Exchange(ref this.dalamudAtlas, null)?.Dispose();
|
||||
Interlocked.Exchange(ref this.scene, null)?.Dispose();
|
||||
Interlocked.Exchange(ref this.backend, null)?.Dispose();
|
||||
|
||||
return;
|
||||
|
||||
|
|
@ -416,14 +416,14 @@ internal class InterfaceManager : IInternalDisposableService
|
|||
/// <returns>The currently used video memory, or null if not available.</returns>
|
||||
public unsafe (long Used, long Available)? GetD3dMemoryInfo()
|
||||
{
|
||||
if (this.scene?.DeviceHandle is 0 or null)
|
||||
if (this.backend?.DeviceHandle is 0 or null)
|
||||
return null;
|
||||
|
||||
using var device = default(ComPtr<IDXGIDevice>);
|
||||
using var adapter = default(ComPtr<IDXGIAdapter>);
|
||||
using var adapter4 = default(ComPtr<IDXGIAdapter4>);
|
||||
|
||||
if (new ComPtr<IUnknown>((IUnknown*)this.scene.DeviceHandle).As(&device).FAILED)
|
||||
if (new ComPtr<IUnknown>((IUnknown*)this.backend.DeviceHandle).As(&device).FAILED)
|
||||
return null;
|
||||
|
||||
if (device.Get()->GetAdapter(adapter.GetAddressOf()).FAILED)
|
||||
|
|
@ -617,7 +617,7 @@ internal class InterfaceManager : IInternalDisposableService
|
|||
Log.Information("[IM] Scene & ImGui setup OK!");
|
||||
}
|
||||
|
||||
this.scene = newBackend;
|
||||
this.backend = newBackend;
|
||||
Service<InterfaceManagerWithScene>.Provide(new(this));
|
||||
|
||||
this.wndProcHookManager.PreWndProc += this.WndProcHookManagerOnPreWndProc;
|
||||
|
|
@ -625,7 +625,7 @@ internal class InterfaceManager : IInternalDisposableService
|
|||
|
||||
private void WndProcHookManagerOnPreWndProc(WndProcEventArgs args)
|
||||
{
|
||||
var r = this.scene?.ProcessWndProcW(args.Hwnd, args.Message, args.WParam, args.LParam);
|
||||
var r = this.backend?.ProcessWndProcW(args.Hwnd, args.Message, args.WParam, args.LParam);
|
||||
if (r is not null)
|
||||
args.SuppressWithValue(r.Value);
|
||||
}
|
||||
|
|
@ -638,14 +638,14 @@ internal class InterfaceManager : IInternalDisposableService
|
|||
{
|
||||
Debug.Assert(this.presentHook is not null, "How did PresentDetour get called when presentHook is null?");
|
||||
|
||||
if (this.scene is null)
|
||||
if (this.backend is null)
|
||||
{
|
||||
this.InitScene(swapChain);
|
||||
if (this.scene is null)
|
||||
if (this.backend is null)
|
||||
throw new InvalidOperationException("InitScene did not set this.scene?");
|
||||
}
|
||||
|
||||
if (!this.scene.IsAttachedToPresentationTarget((nint)swapChain))
|
||||
if (!this.backend.IsAttachedToPresentationTarget((nint)swapChain))
|
||||
return this.presentHook!.Original(swapChain, syncInterval, presentFlags);
|
||||
|
||||
// Do not do anything yet if no font atlas has been built yet.
|
||||
|
|
@ -664,7 +664,7 @@ internal class InterfaceManager : IInternalDisposableService
|
|||
this.IsMainThreadInPresent = true;
|
||||
this.CumulativePresentCalls++;
|
||||
this.PreImGuiRender();
|
||||
RenderImGui(this.scene!);
|
||||
RenderImGui(this.backend!);
|
||||
this.PostImGuiRender();
|
||||
this.IsMainThreadInPresent = false;
|
||||
|
||||
|
|
@ -833,23 +833,23 @@ internal class InterfaceManager : IInternalDisposableService
|
|||
this.ResizeBuffers?.InvokeSafely();
|
||||
|
||||
// We have to ensure we're working with the main swapchain, as other viewports might be resizing as well.
|
||||
if (this.scene?.IsAttachedToPresentationTarget((nint)swapChain) is not true)
|
||||
if (this.backend?.IsAttachedToPresentationTarget((nint)swapChain) is not true)
|
||||
return this.resizeBuffersHook!.Original(swapChain, bufferCount, width, height, newFormat, swapChainFlags);
|
||||
|
||||
this.scene?.OnPreResize();
|
||||
this.backend?.OnPreResize();
|
||||
|
||||
var ret = this.resizeBuffersHook!.Original(swapChain, bufferCount, width, height, newFormat, swapChainFlags);
|
||||
if (ret == DXGI.DXGI_ERROR_INVALID_CALL)
|
||||
Log.Error("invalid call to resizeBuffers");
|
||||
|
||||
this.scene?.OnPostResize((int)width, (int)height);
|
||||
this.backend?.OnPostResize((int)width, (int)height);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private HCURSOR SetCursorDetour(HCURSOR hCursor)
|
||||
{
|
||||
if (this.lastWantCapture && (!this.scene?.IsImGuiCursor(hCursor) ?? false) && this.OverrideGameCursor)
|
||||
if (this.lastWantCapture && (!this.backend?.IsImGuiCursor(hCursor) ?? false) && this.OverrideGameCursor)
|
||||
return default;
|
||||
|
||||
return this.setCursorHook?.IsDisposed is not false
|
||||
|
|
|
|||
|
|
@ -309,7 +309,7 @@ internal sealed partial class FontAtlasFactory
|
|||
throw;
|
||||
}
|
||||
|
||||
this.factory.SceneTask.ContinueWith(
|
||||
this.factory.BackendTask.ContinueWith(
|
||||
r =>
|
||||
{
|
||||
lock (this.syncRoot)
|
||||
|
|
@ -734,7 +734,7 @@ internal sealed partial class FontAtlasFactory
|
|||
foreach (var font in toolkit.Fonts)
|
||||
toolkit.BuildLookupTable(font);
|
||||
|
||||
if (this.factory.SceneTask is { IsCompleted: false } sceneTask)
|
||||
if (this.factory.BackendTask is { IsCompleted: false } backendTask)
|
||||
{
|
||||
Log.Verbose(
|
||||
"[{name}:{functionname}] 0x{ptr:X}: await SceneTask (at {sw}ms)",
|
||||
|
|
@ -742,7 +742,7 @@ internal sealed partial class FontAtlasFactory
|
|||
nameof(this.RebuildFontsPrivateReal),
|
||||
atlasPtr,
|
||||
sw.ElapsedMilliseconds);
|
||||
await sceneTask.ConfigureAwait(!isAsync);
|
||||
await backendTask.ConfigureAwait(!isAsync);
|
||||
}
|
||||
|
||||
#if VeryVerboseLog
|
||||
|
|
|
|||
|
|
@ -51,9 +51,9 @@ internal sealed partial class FontAtlasFactory
|
|||
this.Framework = framework;
|
||||
this.InterfaceManager = interfaceManager;
|
||||
this.dalamudAssetManager = dalamudAssetManager;
|
||||
this.SceneTask = Service<InterfaceManager.InterfaceManagerWithScene>
|
||||
this.BackendTask = Service<InterfaceManager.InterfaceManagerWithScene>
|
||||
.GetAsync()
|
||||
.ContinueWith(r => r.Result.Manager.Scene);
|
||||
.ContinueWith(r => r.Result.Manager.Backend);
|
||||
|
||||
var gffasInfo = Enum.GetValues<GameFontFamilyAndSize>()
|
||||
.Select(
|
||||
|
|
@ -140,7 +140,7 @@ internal sealed partial class FontAtlasFactory
|
|||
|
||||
/// <summary>
|
||||
/// Gets the service instance of <see cref="InterfaceManager"/>.<br />
|
||||
/// <see cref="Internal.InterfaceManager.Scene"/> may not yet be available.
|
||||
/// <see cref="Internal.InterfaceManager.Backend"/> may not yet be available.
|
||||
/// </summary>
|
||||
public InterfaceManager InterfaceManager { get; }
|
||||
|
||||
|
|
@ -152,7 +152,7 @@ internal sealed partial class FontAtlasFactory
|
|||
/// <summary>
|
||||
/// Gets the async task for <see cref="IImGuiBackend"/> inside <see cref="InterfaceManager"/>.
|
||||
/// </summary>
|
||||
public Task<IImGuiBackend> SceneTask { get; }
|
||||
public Task<IImGuiBackend> BackendTask { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default glyph ranges (glyph ranges of <see cref="GameFontFamilyAndSize.Axis12"/>).
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ internal sealed partial class TextureManager
|
|||
private unsafe TextureManager(InterfaceManager.InterfaceManagerWithScene withScene)
|
||||
{
|
||||
using var failsafe = new DisposeSafety.ScopedFinalizer();
|
||||
failsafe.Add(this.device = new((ID3D11Device*)withScene.Manager.Scene!.DeviceHandle));
|
||||
failsafe.Add(this.device = new((ID3D11Device*)withScene.Manager.Backend!.DeviceHandle));
|
||||
failsafe.Add(this.dynamicPriorityTextureLoader = new(Math.Max(1, Environment.ProcessorCount - 1)));
|
||||
failsafe.Add(this.sharedTextureManager = new(this));
|
||||
failsafe.Add(this.wicManager = new(this));
|
||||
|
|
|
|||
|
|
@ -118,12 +118,22 @@ public interface IUiBuilder
|
|||
/// <summary>
|
||||
/// Gets the game's active Direct3D device.
|
||||
/// </summary>
|
||||
// TODO: Remove it on API11/APIXI, and remove SharpDX/PInvoke/etc. dependency from Dalamud.
|
||||
[Obsolete($"Use {nameof(DeviceHandle)} and wrap it using DirectX wrapper library of your choice.")]
|
||||
SharpDX.Direct3D11.Device Device { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the game's main window handle.
|
||||
/// </summary>
|
||||
IntPtr WindowHandlePtr { get; }
|
||||
/// <summary>Gets the game's active Direct3D device.</summary>
|
||||
/// <value>Pointer to the instance of IUnknown that the game is using and should be containing an ID3D11Device,
|
||||
/// or 0 if it is not available yet.</value>
|
||||
/// <remarks>Use
|
||||
/// <a href="https://learn.microsoft.com/en-us/windows/win32/api/unknwn/nf-unknwn-iunknown-queryinterface(q)">
|
||||
/// QueryInterface</a> with IID of <c>IID_ID3D11Device</c> if you want to ensure that the interface type contained
|
||||
/// within is indeed an instance of ID3D11Device.</remarks>
|
||||
nint DeviceHandle { get; }
|
||||
|
||||
/// <summary>Gets the game's main window handle.</summary>
|
||||
/// <value>HWND of the main game window, or 0 if it is not available yet.</value>
|
||||
nint WindowHandlePtr { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether this plugin should hide its UI automatically when the game's UI is hidden.
|
||||
|
|
@ -415,16 +425,17 @@ public sealed class UiBuilder : IDisposable, IUiBuilder
|
|||
this.InterfaceManagerWithScene?.MonoFontHandle
|
||||
?? throw new InvalidOperationException("Scene is not yet ready.")));
|
||||
|
||||
/// <summary>
|
||||
/// Gets the game's active Direct3D device.
|
||||
/// </summary>
|
||||
/// <inheritdoc/>
|
||||
// TODO: Remove it on API11/APIXI, and remove SharpDX/PInvoke/etc. dependency from Dalamud.
|
||||
[Obsolete($"Use {nameof(DeviceHandle)} and wrap it using DirectX wrapper library of your choice.")]
|
||||
public SharpDX.Direct3D11.Device Device =>
|
||||
this.sdxDevice ??= new(this.InterfaceManagerWithScene!.Scene!.DeviceHandle);
|
||||
this.sdxDevice ??= new(this.InterfaceManagerWithScene!.Backend!.DeviceHandle);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the game's main window handle.
|
||||
/// </summary>
|
||||
public nint WindowHandlePtr => this.InterfaceManagerWithScene!.GameWindowHandle;
|
||||
/// <inheritdoc/>
|
||||
public nint DeviceHandle => this.InterfaceManagerWithScene?.Backend?.DeviceHandle ?? 0;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public nint WindowHandlePtr => this.InterfaceManagerWithScene is { } imws ? imws.GameWindowHandle : 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether this plugin should hide its UI automatically when the game's UI is hidden.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue