Merge pull request #14608 from JosJuice/gcadapter-auto-start

GCAdapter: Automatically start and stop thread
This commit is contained in:
Dentomologist
2026-04-24 19:51:51 -07:00
committed by GitHub
6 changed files with 30 additions and 62 deletions
@@ -300,9 +300,6 @@ object NativeLibrary {
@JvmStatic @JvmStatic
external fun ResetDolphinSettings() external fun ResetDolphinSettings()
@JvmStatic
external fun UpdateGCAdapterScanThread()
/** /**
* Initializes the native parts of the app. * Initializes the native parts of the app.
* *
@@ -56,7 +56,6 @@ class Settings : Closeable {
NativeConfig.save(NativeConfig.LAYER_BASE) NativeConfig.save(NativeConfig.LAYER_BASE)
NativeLibrary.ReloadLoggerConfig() NativeLibrary.ReloadLoggerConfig()
NativeLibrary.UpdateGCAdapterScanThread()
} else { } else {
NativeConfig.save(NativeConfig.LAYER_LOCAL_GAME) NativeConfig.save(NativeConfig.LAYER_LOCAL_GAME)
} }
-16
View File
@@ -56,8 +56,6 @@
#include "DiscIO/ScrubbedBlob.h" #include "DiscIO/ScrubbedBlob.h"
#include "DiscIO/Volume.h" #include "DiscIO/Volume.h"
#include "InputCommon/GCAdapter.h"
#include "UICommon/GameFile.h" #include "UICommon/GameFile.h"
#include "UICommon/UICommon.h" #include "UICommon/UICommon.h"
@@ -533,20 +531,6 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ResetDolphin
UICommon::SetUserDirectory(File::GetUserPath(D_USER_IDX)); UICommon::SetUserDirectory(File::GetUserPath(D_USER_IDX));
} }
JNIEXPORT void JNICALL
Java_org_dolphinemu_dolphinemu_NativeLibrary_UpdateGCAdapterScanThread(JNIEnv*, jclass)
{
HostThreadLock guard;
if (GCAdapter::UseAdapter())
{
GCAdapter::StartScanThread();
}
else
{
GCAdapter::StopScanThread();
}
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Initialize(JNIEnv*, jclass) JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Initialize(JNIEnv*, jclass)
{ {
HostThreadLock guard; HostThreadLock guard;
@@ -26,8 +26,6 @@
#include "DolphinQt/QtUtils/SignalBlocking.h" #include "DolphinQt/QtUtils/SignalBlocking.h"
#include "DolphinQt/Settings.h" #include "DolphinQt/Settings.h"
#include "InputCommon/GCAdapter.h"
using SIDeviceName = std::pair<SerialInterface::SIDevices, const char*>; using SIDeviceName = std::pair<SerialInterface::SIDevices, const char*>;
static constexpr std::array s_gc_types = { static constexpr std::array s_gc_types = {
SIDeviceName{SerialInterface::SIDEVICE_NONE, _trans("None")}, SIDeviceName{SerialInterface::SIDEVICE_NONE, _trans("None")},
@@ -205,10 +203,6 @@ void GamecubeControllersWidget::SaveSettings()
} }
} }
} }
if (GCAdapter::UseAdapter())
GCAdapter::StartScanThread();
else
GCAdapter::StopScanThread();
SConfig::GetInstance().SaveSettings(); SConfig::GetInstance().SaveSettings();
} }
+30 -33
View File
@@ -462,7 +462,7 @@ static void ScanThreadFunc()
while (s_adapter_detect_thread_running.IsSet()) while (s_adapter_detect_thread_running.IsSet())
{ {
if (!s_detected && UseAdapter() && if (!s_detected && s_is_adapter_wanted &&
env->CallStaticBooleanMethod(s_adapter_class, is_usb_device_available_func)) env->CallStaticBooleanMethod(s_adapter_class, is_usb_device_available_func))
{ {
std::lock_guard lk(s_init_mutex); std::lock_guard lk(s_init_mutex);
@@ -483,6 +483,27 @@ void SetAdapterCallback(std::function<void(void)> func)
#endif #endif
} }
static void StartScanThread()
{
if (s_adapter_detect_thread_running.IsSet())
return;
#if GCADAPTER_USE_LIBUSB_IMPLEMENTATION
if (!s_libusb_context->IsValid())
return;
#endif
s_adapter_detect_thread_running.Set(true);
s_adapter_detect_thread = std::thread(ScanThreadFunc);
}
static void StopScanThread()
{
if (s_adapter_detect_thread_running.TestAndClear())
{
s_hotplug_event.Set();
s_adapter_detect_thread.join();
}
}
static void RefreshConfig() static void RefreshConfig()
{ {
s_is_adapter_wanted = false; s_is_adapter_wanted = false;
@@ -493,6 +514,11 @@ static void RefreshConfig()
SerialInterface::SIDevices::SIDEVICE_WIIU_ADAPTER; SerialInterface::SIDevices::SIDEVICE_WIIU_ADAPTER;
s_config_rumble_enabled[i] = Config::Get(Config::GetInfoForAdapterRumble(i)); s_config_rumble_enabled[i] = Config::Get(Config::GetInfoForAdapterRumble(i));
} }
if (s_is_adapter_wanted)
StartScanThread();
else
StopScanThread();
} }
void Init() void Init()
@@ -531,30 +557,6 @@ void Init()
if (!s_config_callback_id) if (!s_config_callback_id)
s_config_callback_id = Config::AddConfigChangedCallback(RefreshConfig); s_config_callback_id = Config::AddConfigChangedCallback(RefreshConfig);
RefreshConfig(); RefreshConfig();
if (UseAdapter())
StartScanThread();
}
void StartScanThread()
{
if (s_adapter_detect_thread_running.IsSet())
return;
#if GCADAPTER_USE_LIBUSB_IMPLEMENTATION
if (!s_libusb_context->IsValid())
return;
#endif
s_adapter_detect_thread_running.Set(true);
s_adapter_detect_thread = std::thread(ScanThreadFunc);
}
void StopScanThread()
{
if (s_adapter_detect_thread_running.TestAndClear())
{
s_hotplug_event.Set();
s_adapter_detect_thread.join();
}
} }
static void Setup() static void Setup()
@@ -828,7 +830,7 @@ static void Reset()
GCPadStatus Input(int chan) GCPadStatus Input(int chan)
{ {
if (!UseAdapter()) if (!s_is_adapter_wanted)
return {}; return {};
#if GCADAPTER_USE_LIBUSB_IMPLEMENTATION #if GCADAPTER_USE_LIBUSB_IMPLEMENTATION
@@ -966,11 +968,6 @@ void ResetDeviceType(int chan)
s_port_states[chan].controller_type = ControllerType::None; s_port_states[chan].controller_type = ControllerType::None;
} }
bool UseAdapter()
{
return s_is_adapter_wanted;
}
void ResetRumble() void ResetRumble()
{ {
#if GCADAPTER_USE_LIBUSB_IMPLEMENTATION #if GCADAPTER_USE_LIBUSB_IMPLEMENTATION
@@ -994,7 +991,7 @@ void ResetRumble()
// being called while the libusb state is being reset // being called while the libusb state is being reset
static void ResetRumbleLockNeeded() static void ResetRumbleLockNeeded()
{ {
if (!UseAdapter() || (s_handle == nullptr || s_status != AdapterStatus::Detected)) if (!s_is_adapter_wanted || s_handle == nullptr || s_status != AdapterStatus::Detected)
{ {
return; return;
} }
@@ -1021,7 +1018,7 @@ static void ResetRumbleLockNeeded()
void Output(int chan, u8 rumble_command) void Output(int chan, u8 rumble_command)
{ {
if (!UseAdapter() || !s_config_rumble_enabled[chan]) if (!s_is_adapter_wanted || !s_config_rumble_enabled[chan])
return; return;
#if GCADAPTER_USE_LIBUSB_IMPLEMENTATION #if GCADAPTER_USE_LIBUSB_IMPLEMENTATION
-3
View File
@@ -15,8 +15,6 @@ void Init();
void ResetRumble(); void ResetRumble();
void Shutdown(); void Shutdown();
void SetAdapterCallback(std::function<void(void)> func); void SetAdapterCallback(std::function<void(void)> func);
void StartScanThread();
void StopScanThread();
// Buttons have PAD_GET_ORIGIN set on new connection // Buttons have PAD_GET_ORIGIN set on new connection
// Netplay and CSIDevice_GCAdapter make use of this. // Netplay and CSIDevice_GCAdapter make use of this.
@@ -26,7 +24,6 @@ void Output(int chan, u8 rumble_command);
bool IsDetected(const char** error_message); bool IsDetected(const char** error_message);
bool DeviceConnected(int chan); bool DeviceConnected(int chan);
void ResetDeviceType(int chan); void ResetDeviceType(int chan);
bool UseAdapter();
// Callable from any thread. Returns 0 when the adapter is not detected. // Callable from any thread. Returns 0 when the adapter is not detected.
double GetCurrentPollRate(); double GetCurrentPollRate();