From 2a1cefb58b2b7970a3403f097748d00ed1d013e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 5 Mar 2026 14:36:06 +0100 Subject: [PATCH] (Fake-)load adhoc server list asynchronously when opening server list window. --- Common/System/System.h | 1 + Core/HLE/sceNetAdhoc.cpp | 9 +++++++++ Core/HLE/sceNetAdhoc.h | 1 + UI/AdhocServerScreen.cpp | 9 ++++++++- UI/AdhocServerScreen.h | 2 ++ UI/NativeApp.cpp | 3 --- 6 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Common/System/System.h b/Common/System/System.h index b18bf88665..081227589f 100644 --- a/Common/System/System.h +++ b/Common/System/System.h @@ -304,6 +304,7 @@ enum class UIMessage { RESTART_GRAPHICS, RECENT_FILES_CHANGED, SAVE_FRAME_DUMP, + ADHOC_SERVER_LIST_CHANGED, }; std::string System_GetProperty(SystemProperty prop); diff --git a/Core/HLE/sceNetAdhoc.cpp b/Core/HLE/sceNetAdhoc.cpp index 1b6f337195..e7bfa0daeb 100644 --- a/Core/HLE/sceNetAdhoc.cpp +++ b/Core/HLE/sceNetAdhoc.cpp @@ -29,6 +29,7 @@ #include "Common/Serialize/SerializeFuncs.h" #include "Common/Serialize/SerializeMap.h" #include "Common/System/OSD.h" +#include "Common/System/System.h" #include "Common/Thread/ThreadUtil.h" #include "Common/TimeUtil.h" @@ -124,6 +125,13 @@ std::mutex g_proAdhocServerListMutex; std::vector g_proAdhocServerList; void AdhocLoadServerList() { + { + std::lock_guard guard(g_proAdhocServerListMutex); + if (!g_proAdhocServerList.empty()) { + return; + } + } + // Do this async. std::thread thread([]() { // Pretend for now, actually load later. @@ -132,6 +140,7 @@ void AdhocLoadServerList() { // 2. Online list from some url, and cache it in PSP/SYSTEM/CACHE for next time. std::lock_guard guard(g_proAdhocServerListMutex); g_proAdhocServerList = defaultProAdhocServerList; + System_PostUIMessage(UIMessage::ADHOC_SERVER_LIST_CHANGED); }); thread.detach(); } diff --git a/Core/HLE/sceNetAdhoc.h b/Core/HLE/sceNetAdhoc.h index 34fe0ef6fc..6db2bb715e 100644 --- a/Core/HLE/sceNetAdhoc.h +++ b/Core/HLE/sceNetAdhoc.h @@ -112,6 +112,7 @@ struct AdhocServerListEntry { AdhocDataMode mode = AdhocDataMode::P2P; }; +void AdhocLoadServerList(); std::vector AdhocGetServerList(); class PointerWrap; diff --git a/UI/AdhocServerScreen.cpp b/UI/AdhocServerScreen.cpp index 6cbc793ec8..483fb3b912 100644 --- a/UI/AdhocServerScreen.cpp +++ b/UI/AdhocServerScreen.cpp @@ -11,6 +11,7 @@ AdhocServerScreen::AdhocServerScreen(std::string *value, std::string_view title) thiz->ResolverThread(); }, this); editValue_ = *value; + AdhocLoadServerList(); } AdhocServerScreen::~AdhocServerScreen() { @@ -22,6 +23,12 @@ AdhocServerScreen::~AdhocServerScreen() { resolver_.join(); } +void AdhocServerScreen::sendMessage(UIMessage message, const char *value) { + if (message == UIMessage::ADHOC_SERVER_LIST_CHANGED) { + RecreateViews(); + } +} + void AdhocServerScreen::CreatePopupContents(UI::ViewGroup *parent) { using namespace UI; auto sy = GetI18NCategory(I18NCat::SYSTEM); @@ -48,7 +55,7 @@ void AdhocServerScreen::CreatePopupContents(UI::ViewGroup *parent) { LinearLayout *innerView = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); innerView->SetSpacing(5.0f); if (listIP.size() > 0) { - for (const auto& label : listIP) { + for (const auto &label : listIP) { // Filter out IP prefixed with "127." and "169.254." also "0." since they can be redundant or unusable if (label.find("127.") != 0 && label.find("169.254.") != 0 && label.find("0.") != 0) { auto button = innerView->Add(new Button(label, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT))); diff --git a/UI/AdhocServerScreen.h b/UI/AdhocServerScreen.h index ac5abb12e9..9ac29dfba9 100644 --- a/UI/AdhocServerScreen.h +++ b/UI/AdhocServerScreen.h @@ -23,6 +23,8 @@ protected: void OnCompleted(DialogResult result) override; bool CanComplete(DialogResult result) override; + void sendMessage(UIMessage message, const char *value) override; + private: void ResolverThread(); diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index a53be59cc3..e780260e9b 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -348,9 +348,6 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch // Make sure UI state is MENU. ResetUIState(); - // We kind of have to do this during startup, since these are visible in settings. - AdhocLoadServerList(); - bool skipLogo = false; setlocale( LC_ALL, "C" ); std::string user_data_path = savegame_dir;