Reduce lock usage during window events

This commit is contained in:
2025-04-19 21:12:38 +03:00
parent 3b8c7f0d8d
commit 43968c1a5e
4 changed files with 5 additions and 25 deletions

View File

@@ -402,10 +402,11 @@ DEFINE_INTERNAL_CALL(void) EditorInternal_RunVisualScriptBreakpointLoopTick(floa
break;
}
}
WindowsManager::WindowsLocker.Unlock();
for (const auto& e : inputEvents)
{
auto window = e.Target ? e.Target : defaultWindow;
if (!window)
if (!window || window->IsClosed())
continue;
switch (e.Type)
{
@@ -443,7 +444,6 @@ DEFINE_INTERNAL_CALL(void) EditorInternal_RunVisualScriptBreakpointLoopTick(floa
break;
}
}
WindowsManager::WindowsLocker.Unlock();
}
WindowsManager::WindowsLocker.Lock();
Array<Window*, InlinedAllocation<32>> windows;

View File

@@ -913,11 +913,10 @@ void InputService::Update()
WindowsManager::WindowsLocker.Unlock();
// Send input events for the focused window
WindowsManager::WindowsLocker.Lock();
for (const auto& e : InputEvents)
{
auto window = e.Target ? e.Target : defaultWindow;
if (!window || !WindowsManager::Windows.Contains(window))
if (!window || window->IsClosed())
continue;
switch (e.Type)
{
@@ -965,7 +964,6 @@ void InputService::Update()
break;
}
}
WindowsManager::WindowsLocker.Unlock();
// Skip if game has no focus to handle the input
if (!Engine::HasGameViewportFocus())

View File

@@ -32,26 +32,9 @@ namespace WinImpl
// The events for releasing the mouse during window dragging are missing, handle the mouse release event here
bool SDLCALL SDLPlatform::EventMessageHook(void* userdata, MSG* msg)
{
#define GET_WINDOW_WITH_HWND(window, hwnd) \
do { \
(window) = nullptr; \
WindowsManager::WindowsLocker.Lock(); \
for (int32 i = 0; i < WindowsManager::Windows.Count(); i++) \
{ \
if (WindowsManager::Windows[i]->GetNativePtr() == (hwnd)) \
{ \
(window) = WindowsManager::Windows[i]; \
break; \
} \
} \
WindowsManager::WindowsLocker.Unlock(); \
ASSERT((window) != nullptr); \
} while (false)
if (msg->message == WM_NCLBUTTONDOWN)
{
Window* window;
GET_WINDOW_WITH_HWND(window, msg->hwnd);
Window* window = WindowsManager::GetByNativePtr(msg->hwnd);
Float2 mousePosition(static_cast<float>(static_cast<LONG>(WINDOWS_GET_X_LPARAM(msg->lParam))), static_cast<float>(static_cast<LONG>(WINDOWS_GET_Y_LPARAM(msg->lParam))));
WinImpl::DraggedWindow = window;
@@ -81,7 +64,6 @@ bool SDLCALL SDLPlatform::EventMessageHook(void* userdata, MSG* msg)
}
}
return true;
#undef GET_WINDOW_WITH_HWND
}
bool SDLPlatform::InitInternal()

View File

@@ -589,7 +589,7 @@ void SDLWindow::Restore()
bool SDLWindow::IsClosed() const
{
return _handle == nullptr;
return WindowBase::IsClosed() || _handle == nullptr;
}
bool SDLWindow::IsForegroundWindow() const