[Download] Optimize map download

This commit is contained in:
momo5502 2017-05-25 20:18:20 +02:00
parent fc6c24ca30
commit 7dd6ff0fe2
3 changed files with 28 additions and 5 deletions

View File

@ -6,6 +6,9 @@ namespace Components
Download::ClientDownload Download::CLDownload; Download::ClientDownload Download::CLDownload;
std::vector<std::shared_ptr<Download::ScriptDownload>> Download::ScriptDownloads; std::vector<std::shared_ptr<Download::ScriptDownload>> Download::ScriptDownloads;
std::thread Download::ServerThread;
bool Download::Terminate;
#pragma region Client #pragma region Client
void Download::InitiateMapDownload(std::string map) void Download::InitiateMapDownload(std::string map)
@ -703,6 +706,7 @@ namespace Components
{ {
if (Dedicated::IsEnabled()) if (Dedicated::IsEnabled())
{ {
Download::Terminate = false;
ZeroMemory(&Download::Mgr, sizeof Download::Mgr); ZeroMemory(&Download::Mgr, sizeof Download::Mgr);
mg_mgr_init(&Download::Mgr, nullptr); 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 else
@ -820,6 +828,12 @@ namespace Components
Download::~Download() Download::~Download()
{ {
Download::Terminate = true;
if (Download::ServerThread.joinable())
{
Download::ServerThread.join();
}
if (Dedicated::IsEnabled()) if (Dedicated::IsEnabled())
{ {
mg_mgr_free(&Download::Mgr); mg_mgr_free(&Download::Mgr);

View File

@ -210,6 +210,8 @@ namespace Components
static mg_mgr Mgr; static mg_mgr Mgr;
static ClientDownload CLDownload; static ClientDownload CLDownload;
static std::vector<std::shared_ptr<ScriptDownload>> ScriptDownloads; static std::vector<std::shared_ptr<ScriptDownload>> ScriptDownloads;
static std::thread ServerThread;
static bool Terminate;
static void EventHandler(mg_connection *nc, int ev, void *ev_data); static void EventHandler(mg_connection *nc, int ev, void *ev_data);
static void ListHandler(mg_connection *nc, int ev, void *ev_data); static void ListHandler(mg_connection *nc, int ev, void *ev_data);

View File

@ -453,9 +453,7 @@ namespace Components
Command::Execute("awaitDatabase", false); // Wait for the database to load Command::Execute("awaitDatabase", false); // Wait for the database to load
Command::Execute("wait 100", false); Command::Execute("wait 100", false);
Command::Execute("openmenu popup_reconnectingtoparty", false); Command::Execute("openmenu popup_reconnectingtoparty", false);
Command::Execute("wait 8000", false); // Seems like 8000ms? Command::Execute("delayReconnect", false);
Command::Execute("closemenu popup_reconnectingtoparty", false);
Command::Execute("reconnect", false);
return true; return true;
} }
@ -933,6 +931,15 @@ namespace Components
Utils::Hook(0x5A9D51, Maps::LoadMapLoadscreenStub, HOOK_CALL).install()->quick(); Utils::Hook(0x5A9D51, Maps::LoadMapLoadscreenStub, HOOK_CALL).install()->quick();
Utils::Hook(0x5B34DD, 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 // Download the map before a maprotation if necessary
// Conflicts with Theater's SV map rotation check, but this one is safer! // Conflicts with Theater's SV map rotation check, but this one is safer!
Utils::Hook(0x5AA91C, Maps::RotateCheckStub, HOOK_CALL).install()->quick(); Utils::Hook(0x5AA91C, Maps::RotateCheckStub, HOOK_CALL).install()->quick();