diff --git a/Source/Engine/Platform/Base/DragDropHelper.h b/Source/Engine/Platform/Base/DragDropHelper.h new file mode 100644 index 000000000..a607cdaec --- /dev/null +++ b/Source/Engine/Platform/Base/DragDropHelper.h @@ -0,0 +1,31 @@ +// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. + +#pragma once + +#include "Engine/Threading/ThreadPoolTask.h" +#include "Engine/Threading/ThreadPool.h" +#include "Engine/Scripting/Scripting.h" +#include "Engine/Scripting/ManagedCLR/MDomain.h" +#include "Engine/Engine/Engine.h" +#include "Engine/Platform/Platform.h" + +/// +/// Async DoDragDrop helper (used for rendering frames during main thread stall). +/// +class DoDragDropJob : public ThreadPoolTask +{ +public: + int64 ExitFlag = 0; + + // [ThreadPoolTask] + bool Run() override + { + Scripting::GetScriptsDomain()->Dispatch(); + while (Platform::AtomicRead(&ExitFlag) == 0) + { + Engine::OnDraw(); + Platform::Sleep(20); + } + return false; + } +}; diff --git a/Source/Engine/Platform/Mac/MacWindow.cpp b/Source/Engine/Platform/Mac/MacWindow.cpp index 4c392fc4e..373d19bae 100644 --- a/Source/Engine/Platform/Mac/MacWindow.cpp +++ b/Source/Engine/Platform/Mac/MacWindow.cpp @@ -8,9 +8,7 @@ #include "Engine/Platform/IGuiData.h" #if USE_EDITOR #include "Engine/Platform/CriticalSection.h" -#include "Engine/Threading/ThreadPoolTask.h" -#include "Engine/Threading/ThreadPool.h" -#include "Engine/Engine/Engine.h" +#include "Engine/Platform/Base/DragDropHelper.h" #endif #include "Engine/Core/Log.h" #include "Engine/Input/Input.h" @@ -25,23 +23,7 @@ // Data for drawing window while doing drag&drop on Mac (engine is paused during platform tick) CriticalSection MacDragLocker; NSDraggingSession* MacDragSession = nullptr; -class DoDragDropJob* MacDragJob = nullptr; - -class DoDragDropJob : public ThreadPoolTask -{ -public: - int64 ExitFlag = 0; - - bool Run() override - { - while (Platform::AtomicRead(&ExitFlag) == 0) - { - Engine::OnDraw(); - Platform::Sleep(20); - } - return false; - } -}; +DoDragDropJob* MacDragJob = nullptr; #endif inline bool IsWindowInvalid(Window* win) diff --git a/Source/Engine/Platform/Windows/WindowsWindow.cpp b/Source/Engine/Platform/Windows/WindowsWindow.cpp index e29d0fc19..181077125 100644 --- a/Source/Engine/Platform/Windows/WindowsWindow.cpp +++ b/Source/Engine/Platform/Windows/WindowsWindow.cpp @@ -12,14 +12,10 @@ #include "Engine/Graphics/GPUDevice.h" #if USE_EDITOR #include "Engine/Core/Collections/Array.h" -#include "Engine/Engine/Engine.h" #include "Engine/Platform/IGuiData.h" +#include "Engine/Platform/Base/DragDropHelper.h" #include "Engine/Input/Input.h" #include "Engine/Input/Mouse.h" -#include "Engine/Threading/ThreadPoolTask.h" -#include "Engine/Threading/ThreadPool.h" -#include "Engine/Scripting/Scripting.h" -#include "Engine/Scripting/ManagedCLR/MDomain.h" #endif #include "../Win32/IncludeWindowsHeaders.h" #include @@ -1829,36 +1825,13 @@ private: WindowsGuiData GuiDragDropData; -/// -/// Async DoDragDrop helper (used for rendering frames during main thread stall). -/// -class DoDragDropJob : public ThreadPoolTask -{ -public: - int64 ExitFlag = 0; - - // [ThreadPoolTask] - bool Run() override - { - Scripting::GetScriptsDomain()->Dispatch(); - while (Platform::AtomicRead(&ExitFlag) == 0) - { - Engine::OnDraw(); - Platform::Sleep(20); - } - return false; - } -}; - DragDropEffect WindowsWindow::DoDragDrop(const StringView& data) { // Create background worker that will keep updating GUI (perform rendering) const auto task = New(); Task::StartNew(task); while (task->GetState() == TaskState::Queued) - { Platform::Sleep(1); - } // Create descriptors FORMATETC fmtetc = { CF_TEXT, nullptr, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };