GCPadEmu: only connected if default device connected
This lets Dolphin know if a configured GameCube Controller should actually be treated as connected or not. Talked to @JMC47 a bit about this last night. My use-case is that all of my controllers are the same hardware (Xbox One controllers) so share the same configuration (modulo device number). Treating them all as always connected isn't a problem for most games, but in some (Smash Bros.) it forces me to go find a keyboard/mouse and unconfigure any controllers that I don't actually have connected. Hotplugging devices (works on macOS, at least) + this patch remove my need to ever touch the Controller Config dialog while in a game. This patch makes the following changes: - A new `BooleanSetting` in `GCPadEmu` called "Always Connected", which defaults to false. - `ControllerEmu` tracks whether the default device is connected on every call to `UpdateReferences()`. - `GCPadEmu.GetStatus()` now sets err bit to `PAD_ERR_NO_CONTROLLER` if the default device isn't connected. - `SIDevice_GCController` handles `PAD_ERR_NO_CONTROLLER` by imitating the behaviour of `SIDevice_Null` (as far as I can tell, this is the only use of the error bit from `GCPadStatus`). I wanted to add an OSD message akin to the ones when Wiimotes get connected/disconnected, but I haven't yet found where to put the logic.
This commit is contained in:
parent
379e28b58c
commit
c62d83a34b
|
@ -83,6 +83,10 @@ GCPad::GCPad(const unsigned int index) : m_index(index)
|
||||||
|
|
||||||
// options
|
// options
|
||||||
groups.emplace_back(m_options = new ControllerEmu::ControlGroup(_trans("Options")));
|
groups.emplace_back(m_options = new ControllerEmu::ControlGroup(_trans("Options")));
|
||||||
|
m_options->boolean_settings.emplace_back(
|
||||||
|
// i18n: Treat a controller as always being connected regardless of what
|
||||||
|
// devices the user actually has plugged in
|
||||||
|
m_always_connected = new ControllerEmu::BooleanSetting(_trans("Always Connected"), false));
|
||||||
m_options->boolean_settings.emplace_back(std::make_unique<ControllerEmu::BooleanSetting>(
|
m_options->boolean_settings.emplace_back(std::make_unique<ControllerEmu::BooleanSetting>(
|
||||||
_trans("Iterative Input"), false, ControllerEmu::SettingType::VIRTUAL));
|
_trans("Iterative Input"), false, ControllerEmu::SettingType::VIRTUAL));
|
||||||
}
|
}
|
||||||
|
@ -124,6 +128,12 @@ GCPadStatus GCPad::GetInput() const
|
||||||
ControlState x, y, triggers[2];
|
ControlState x, y, triggers[2];
|
||||||
GCPadStatus pad = {};
|
GCPadStatus pad = {};
|
||||||
|
|
||||||
|
if (!(m_always_connected->GetValue() || IsDefaultDeviceConnected()))
|
||||||
|
{
|
||||||
|
pad.isConnected = false;
|
||||||
|
return pad;
|
||||||
|
}
|
||||||
|
|
||||||
// buttons
|
// buttons
|
||||||
m_buttons->GetState(&pad.button, button_bitmasks);
|
m_buttons->GetState(&pad.button, button_bitmasks);
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
|
||||||
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
||||||
|
|
||||||
struct GCPadStatus;
|
struct GCPadStatus;
|
||||||
|
@ -14,7 +15,6 @@ namespace ControllerEmu
|
||||||
{
|
{
|
||||||
class AnalogStick;
|
class AnalogStick;
|
||||||
class Buttons;
|
class Buttons;
|
||||||
class ControlGroup;
|
|
||||||
class MixedTriggers;
|
class MixedTriggers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,6 +54,7 @@ private:
|
||||||
ControllerEmu::ControlGroup* m_rumble;
|
ControllerEmu::ControlGroup* m_rumble;
|
||||||
ControllerEmu::Buttons* m_mic;
|
ControllerEmu::Buttons* m_mic;
|
||||||
ControllerEmu::ControlGroup* m_options;
|
ControllerEmu::ControlGroup* m_options;
|
||||||
|
ControllerEmu::BooleanSetting* m_always_connected;
|
||||||
|
|
||||||
const unsigned int m_index;
|
const unsigned int m_index;
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,14 @@ int CSIDevice_GCController::RunBuffer(u8* buffer, int length)
|
||||||
// For debug logging only
|
// For debug logging only
|
||||||
ISIDevice::RunBuffer(buffer, length);
|
ISIDevice::RunBuffer(buffer, length);
|
||||||
|
|
||||||
|
GCPadStatus pad_status = GetPadStatus();
|
||||||
|
if (!pad_status.isConnected)
|
||||||
|
{
|
||||||
|
constexpr u32 reply = SI_ERROR_NO_RESPONSE;
|
||||||
|
std::memcpy(buffer, &reply, sizeof(reply));
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
// Read the command
|
// Read the command
|
||||||
EBufferCommands command = static_cast<EBufferCommands>(buffer[3]);
|
EBufferCommands command = static_cast<EBufferCommands>(buffer[3]);
|
||||||
|
|
||||||
|
@ -165,6 +173,13 @@ GCPadStatus CSIDevice_GCController::GetPadStatus()
|
||||||
bool CSIDevice_GCController::GetData(u32& hi, u32& low)
|
bool CSIDevice_GCController::GetData(u32& hi, u32& low)
|
||||||
{
|
{
|
||||||
GCPadStatus pad_status = GetPadStatus();
|
GCPadStatus pad_status = GetPadStatus();
|
||||||
|
|
||||||
|
if (!pad_status.isConnected)
|
||||||
|
{
|
||||||
|
hi = 0x80000000;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (HandleButtonCombos(pad_status) == COMBO_ORIGIN)
|
if (HandleButtonCombos(pad_status) == COMBO_ORIGIN)
|
||||||
pad_status.button |= PAD_GET_ORIGIN;
|
pad_status.button |= PAD_GET_ORIGIN;
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,8 @@ std::unique_lock<std::recursive_mutex> EmulatedController::GetStateLock()
|
||||||
void EmulatedController::UpdateReferences(const ControllerInterface& devi)
|
void EmulatedController::UpdateReferences(const ControllerInterface& devi)
|
||||||
{
|
{
|
||||||
const auto lock = GetStateLock();
|
const auto lock = GetStateLock();
|
||||||
|
m_default_device_is_connected = devi.HasConnectedDevice(m_default_device);
|
||||||
|
|
||||||
for (auto& ctrlGroup : groups)
|
for (auto& ctrlGroup : groups)
|
||||||
{
|
{
|
||||||
for (auto& control : ctrlGroup->controls)
|
for (auto& control : ctrlGroup->controls)
|
||||||
|
@ -48,6 +50,11 @@ void EmulatedController::UpdateReferences(const ControllerInterface& devi)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool EmulatedController::IsDefaultDeviceConnected() const
|
||||||
|
{
|
||||||
|
return m_default_device_is_connected;
|
||||||
|
}
|
||||||
|
|
||||||
const ciface::Core::DeviceQualifier& EmulatedController::GetDefaultDevice() const
|
const ciface::Core::DeviceQualifier& EmulatedController::GetDefaultDevice() const
|
||||||
{
|
{
|
||||||
return m_default_device;
|
return m_default_device;
|
||||||
|
|
|
@ -33,6 +33,7 @@ public:
|
||||||
virtual void LoadConfig(IniFile::Section* sec, const std::string& base = "");
|
virtual void LoadConfig(IniFile::Section* sec, const std::string& base = "");
|
||||||
virtual void SaveConfig(IniFile::Section* sec, const std::string& base = "");
|
virtual void SaveConfig(IniFile::Section* sec, const std::string& base = "");
|
||||||
|
|
||||||
|
bool IsDefaultDeviceConnected() const;
|
||||||
const ciface::Core::DeviceQualifier& GetDefaultDevice() const;
|
const ciface::Core::DeviceQualifier& GetDefaultDevice() const;
|
||||||
void SetDefaultDevice(const std::string& device);
|
void SetDefaultDevice(const std::string& device);
|
||||||
void SetDefaultDevice(ciface::Core::DeviceQualifier devq);
|
void SetDefaultDevice(ciface::Core::DeviceQualifier devq);
|
||||||
|
@ -49,5 +50,6 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ciface::Core::DeviceQualifier m_default_device;
|
ciface::Core::DeviceQualifier m_default_device;
|
||||||
|
bool m_default_device_is_connected{false};
|
||||||
};
|
};
|
||||||
} // namespace ControllerEmu
|
} // namespace ControllerEmu
|
||||||
|
|
|
@ -199,5 +199,11 @@ Device::Output* DeviceContainer::FindOutput(const std::string& name, const Devic
|
||||||
{
|
{
|
||||||
return def_dev->FindOutput(name);
|
return def_dev->FindOutput(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DeviceContainer::HasConnectedDevice(const DeviceQualifier& qualifier) const
|
||||||
|
{
|
||||||
|
const auto device = FindDevice(qualifier);
|
||||||
|
return device != nullptr && device->IsValid();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,6 +158,8 @@ public:
|
||||||
std::string GetDefaultDeviceString() const;
|
std::string GetDefaultDeviceString() const;
|
||||||
std::shared_ptr<Device> FindDevice(const DeviceQualifier& devq) const;
|
std::shared_ptr<Device> FindDevice(const DeviceQualifier& devq) const;
|
||||||
|
|
||||||
|
bool HasConnectedDevice(const DeviceQualifier& qualifier) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
mutable std::mutex m_devices_mutex;
|
mutable std::mutex m_devices_mutex;
|
||||||
std::vector<std::shared_ptr<Device>> m_devices;
|
std::vector<std::shared_ptr<Device>> m_devices;
|
||||||
|
|
Loading…
Reference in New Issue