From e754e9d56a0bef37dae1bc6957c3e5b42c654b36 Mon Sep 17 00:00:00 2001 From: Edo Date: Mon, 13 Jun 2022 19:59:32 +0200 Subject: [PATCH] Remove accidental usage of the async pipeline (#305) Removing the parameter default value will prevent this from happening in the future --- src/Components/Modules/Dedicated.cpp | 14 +++------ src/Components/Modules/Download.cpp | 45 ++++++++++++++-------------- src/Components/Modules/Friends.cpp | 2 +- src/Components/Modules/Scheduler.hpp | 8 ++--- 4 files changed, 32 insertions(+), 37 deletions(-) diff --git a/src/Components/Modules/Dedicated.cpp b/src/Components/Modules/Dedicated.cpp index 00ec8568..684582e1 100644 --- a/src/Components/Modules/Dedicated.cpp +++ b/src/Components/Modules/Dedicated.cpp @@ -101,23 +101,17 @@ namespace Components void Dedicated::TimeWrapStub(Game::errorParm_t code, const char* message) { - static bool partyEnable; - static std::string mapname; - - partyEnable = Dvar::Var("party_enable").get(); - mapname = Dvar::Var("mapname").get(); - - Scheduler::Once([]() + Scheduler::Once([] { - Dvar::Var("party_enable").set(partyEnable); + const auto partyEnable = Dvar::Var("party_enable").get(); + auto mapname = Dvar::Var("mapname").get(); if (!partyEnable) // Time wrapping should not occur in party servers, but yeah... { if (mapname.empty()) mapname = "mp_rust"; Command::Execute(Utils::String::VA("map %s", mapname.data()), false); - mapname.clear(); } - }); + }, Scheduler::Pipeline::SERVER); Game::Com_Error(code, message); } diff --git a/src/Components/Modules/Download.cpp b/src/Components/Modules/Download.cpp index a6e93940..6b6a8489 100644 --- a/src/Components/Modules/Download.cpp +++ b/src/Components/Modules/Download.cpp @@ -21,12 +21,12 @@ namespace Components { if (Download::CLDownload.running) return; - Scheduler::Once([]() + Scheduler::Once([] { Dvar::Var("ui_dl_timeLeft").set(Utils::String::FormatTimeSpan(0)); Dvar::Var("ui_dl_progress").set("(0/0) %"); Dvar::Var("ui_dl_transRate").set("0.0 MB/s"); - }); + }, Scheduler::Pipeline::MAIN); Command::Execute("openmenu mod_download_popmenu", false); @@ -155,22 +155,23 @@ namespace Components } } - std::string host = "http://" + download->target.getString(); - std::string fastHost = Dvar::Var("sv_wwwBaseUrl").get(); + auto host = "http://" + download->target.getString(); + auto fastHost = Dvar::Var("sv_wwwBaseUrl").get(); if (Utils::String::StartsWith(fastHost, "https://")) { download->thread.detach(); download->clear(); - Scheduler::Once([]() + Scheduler::Once([] { Command::Execute("closemenu mod_download_popmenu"); Party::ConnectError("HTTPS not supported for downloading!"); - }); + }, Scheduler::Pipeline::CLIENT); - return 0; + return false; } - else if (!Utils::String::StartsWith(fastHost, "http://")) + + if (!Utils::String::StartsWith(fastHost, "http://")) { fastHost = "http://" + fastHost; } @@ -277,11 +278,11 @@ namespace Components download->thread.detach(); download->clear(); - Scheduler::Once([]() + Scheduler::Once([] { Command::Execute("closemenu mod_download_popmenu"); Party::ConnectError("Failed to download the modlist!"); - }); + }, Scheduler::Pipeline::CLIENT); return; } @@ -295,11 +296,11 @@ namespace Components download->thread.detach(); download->clear(); - Scheduler::Once([]() + Scheduler::Once([] { Command::Execute("closemenu mod_download_popmenu"); Party::ConnectError("Failed to parse the modlist!"); - }); + }, Scheduler::Pipeline::CLIENT); return; } @@ -321,14 +322,14 @@ namespace Components download->thread.detach(); download->clear(); - Scheduler::Once([]() + Scheduler::Once([] { Dvar::Var("partyend_reason").set(mod); mod.clear(); Command::Execute("closemenu mod_download_popmenu"); Command::Execute("openmenu menu_xboxlive_partyended"); - }); + }, Scheduler::Pipeline::CLIENT); return; } @@ -341,15 +342,15 @@ namespace Components if (download->isMap) { - Scheduler::Once([]() + Scheduler::Once([] { Command::Execute("reconnect", false); - }); + }, Scheduler::Pipeline::CLIENT); } else { // Run this on the main thread - Scheduler::Once([]() + Scheduler::Once([] { auto fsGame = Dvar::Var("fs_game"); fsGame.set(mod); @@ -364,7 +365,7 @@ namespace Components } Command::Execute("reconnect", false); - }); + }, Scheduler::Pipeline::MAIN); } } @@ -419,11 +420,11 @@ namespace Components dlProgress = static_cast(progress); framePushed = true; - Scheduler::Once([]() + Scheduler::Once([] { framePushed = false; Dvar::Var("ui_dl_progress").set(Utils::String::VA("(%d/%d) %d%%", dlIndex, dlSize, dlProgress)); - }); + }, Scheduler::Pipeline::CLIENT); } int delta = Game::Sys_Milliseconds() - fDownload->download->lastTimeStamp; @@ -449,11 +450,11 @@ namespace Components dlDelta = delta; dlTsBytes = fDownload->download->timeStampBytes; - Scheduler::Once([]() + Scheduler::Once([] { Dvar::Var("ui_dl_timeLeft").set(Utils::String::FormatTimeSpan(dlTimeLeft)); Dvar::Var("ui_dl_transRate").set(Utils::String::FormatBandwidth(dlTsBytes, dlDelta)); - }); + }, Scheduler::Pipeline::MAIN); } fDownload->download->timeStampBytes = 0; diff --git a/src/Components/Modules/Friends.cpp b/src/Components/Modules/Friends.cpp index ea227ebb..44de5b4a 100644 --- a/src/Components/Modules/Friends.cpp +++ b/src/Components/Modules/Friends.cpp @@ -739,7 +739,7 @@ namespace Components Friends::UpdateState(); Friends::UpdateFriends(); - }); + }, Scheduler::Pipeline::MAIN); } Friends::~Friends() diff --git a/src/Components/Modules/Scheduler.hpp b/src/Components/Modules/Scheduler.hpp index 8a85fd26..5d430a9b 100644 --- a/src/Components/Modules/Scheduler.hpp +++ b/src/Components/Modules/Scheduler.hpp @@ -20,13 +20,13 @@ namespace Components void preDestroy() override; - static void Schedule(const std::function& callback, Pipeline type = Pipeline::ASYNC, + static void Schedule(const std::function& callback, Pipeline type, std::chrono::milliseconds delay = 0ms); - static void Loop(const std::function& callback, Pipeline type = Pipeline::ASYNC, + static void Loop(const std::function& callback, Pipeline type, std::chrono::milliseconds delay = 0ms); - static void Once(const std::function& callback, Pipeline type = Pipeline::ASYNC, + static void Once(const std::function& callback, Pipeline type, std::chrono::milliseconds delay = 0ms); - static void OnGameInitialized(const std::function& callback, Pipeline type = Pipeline::ASYNC, + static void OnGameInitialized(const std::function& callback, Pipeline type, std::chrono::milliseconds delay = 0ms); static void OnGameShutdown(const std::function& callback);