From f0fcb821a836606d20fa70b65220db27f81af919 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Fri, 15 Nov 2024 13:40:39 +0100 Subject: [PATCH] Engine: only call ImguiSystem message handler when imgui surface is active Save even more performance by not calling the ImguiSystem message handler at all when the imgui surface isn't active; we don't need to track input movement at all when this isn't active. Also dropped the blockage of all window messages except 'WM_SETCURSOR', added a detailed comment as to why this is blocked. --- src/engine/sys_mainwind.cpp | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/src/engine/sys_mainwind.cpp b/src/engine/sys_mainwind.cpp index 6aef8753..37b7d0f7 100644 --- a/src/engine/sys_mainwind.cpp +++ b/src/engine/sys_mainwind.cpp @@ -33,8 +33,6 @@ LRESULT CGame::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) if (!ImguiSystem()->IsInitialized()) return CGame__WindowProc(hWnd, uMsg, wParam, lParam); - ImguiSystem()->MessageHandler(hWnd, uMsg, wParam, lParam); - if (uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN) { if (wParam == g_ImGuiConfig.m_ConsoleConfig.m_nBind0 || @@ -55,26 +53,16 @@ LRESULT CGame::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) if (g_Console.IsActivated() || g_Browser.IsActivated()) {////////////////////////////////////////////////////////////////////////////// g_bBlockInput = true; + ImguiSystem()->MessageHandler(hWnd, uMsg, wParam, lParam); switch (uMsg) { - case WM_LBUTTONDOWN: - case WM_LBUTTONUP: - case WM_LBUTTONDBLCLK: - case WM_RBUTTONDOWN: - case WM_RBUTTONUP: - case WM_RBUTTONDBLCLK: - case WM_MBUTTONDOWN: - case WM_MBUTTONUP: - case WM_MBUTTONDBLCLK: - case WM_KEYDOWN: - case WM_KEYUP: - case WM_MOUSEACTIVATE: - case WM_MOUSEHOVER: - case WM_MOUSEHWHEEL: - case WM_MOUSELEAVE: - case WM_MOUSEMOVE: - case WM_MOUSEWHEEL: + // This is required as the game calls CInputStackSystem::SetCursorPosition(), + // which hides the cursor. It keeps calling it as the game window is the top + // most window, even when the ImGui window is enabled. We could in the future + // create a new input context for the imgui system, then push it to the stack + // after the game's context and call CInputStackSystem::EnableInputContext() + // on the new imgui context. case WM_SETCURSOR: uMsg = WM_NULL; break;