From 7dd6ff0fe24469877aab4c8e2908fb11c1446c23 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 25 May 2017 20:18:20 +0200 Subject: [PATCH] [Download] Optimize map download --- src/Components/Modules/Download.cpp | 18 ++++++++++++++++-- src/Components/Modules/Download.hpp | 2 ++ src/Components/Modules/Maps.cpp | 13 ++++++++++--- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/Components/Modules/Download.cpp b/src/Components/Modules/Download.cpp index 90cc7a18..00d43e76 100644 --- a/src/Components/Modules/Download.cpp +++ b/src/Components/Modules/Download.cpp @@ -6,6 +6,9 @@ namespace Components Download::ClientDownload Download::CLDownload; std::vector> Download::ScriptDownloads; + std::thread Download::ServerThread; + bool Download::Terminate; + #pragma region Client void Download::InitiateMapDownload(std::string map) @@ -703,6 +706,7 @@ namespace Components { if (Dedicated::IsEnabled()) { + Download::Terminate = false; ZeroMemory(&Download::Mgr, sizeof Download::Mgr); mg_mgr_init(&Download::Mgr, nullptr); @@ -726,9 +730,13 @@ namespace Components } }); - QuickPatch::OnFrame([] + Download::Terminate = false; + Download::ServerThread = std::thread([] { - mg_mgr_poll(&Download::Mgr, 0); + while (!Download::Terminate) + { + mg_mgr_poll(&Download::Mgr, 100); + } }); } else @@ -820,6 +828,12 @@ namespace Components Download::~Download() { + Download::Terminate = true; + if (Download::ServerThread.joinable()) + { + Download::ServerThread.join(); + } + if (Dedicated::IsEnabled()) { mg_mgr_free(&Download::Mgr); diff --git a/src/Components/Modules/Download.hpp b/src/Components/Modules/Download.hpp index e5891410..8d807ef9 100644 --- a/src/Components/Modules/Download.hpp +++ b/src/Components/Modules/Download.hpp @@ -210,6 +210,8 @@ namespace Components static mg_mgr Mgr; static ClientDownload CLDownload; static std::vector> ScriptDownloads; + static std::thread ServerThread; + static bool Terminate; static void EventHandler(mg_connection *nc, int ev, void *ev_data); static void ListHandler(mg_connection *nc, int ev, void *ev_data); diff --git a/src/Components/Modules/Maps.cpp b/src/Components/Modules/Maps.cpp index d5e172a2..624f77c3 100644 --- a/src/Components/Modules/Maps.cpp +++ b/src/Components/Modules/Maps.cpp @@ -453,9 +453,7 @@ namespace Components Command::Execute("awaitDatabase", false); // Wait for the database to load Command::Execute("wait 100", false); Command::Execute("openmenu popup_reconnectingtoparty", false); - Command::Execute("wait 8000", false); // Seems like 8000ms? - Command::Execute("closemenu popup_reconnectingtoparty", false); - Command::Execute("reconnect", false); + Command::Execute("delayReconnect", false); return true; } @@ -933,6 +931,15 @@ namespace Components Utils::Hook(0x5A9D51, Maps::LoadMapLoadscreenStub, HOOK_CALL).install()->quick(); Utils::Hook(0x5B34DD, Maps::LoadMapLoadscreenStub, HOOK_CALL).install()->quick(); + Command::Add("delayReconnect", [](Command::Params*) + { + Renderer::OnDelay([]() + { + Command::Execute("closemenu popup_reconnectingtoparty", false); + Command::Execute("reconnect", false); + }, 6s); + }); + // Download the map before a maprotation if necessary // Conflicts with Theater's SV map rotation check, but this one is safer! Utils::Hook(0x5AA91C, Maps::RotateCheckStub, HOOK_CALL).install()->quick();