Merge pull request #4853 from ligfx/always_connected

GCPadEmu: only connected if default device connected
This commit is contained in:
Leo Lam 2017-11-19 16:53:23 +01:00 committed by GitHub
commit 38f44b2839
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 102 additions and 61 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -174,8 +174,6 @@ InputConfig* GetConfig()
void GetStatus() void GetStatus()
{ {
s_hotkey.err = PAD_ERR_NONE;
// Get input // Get input
static_cast<HotkeyManager*>(s_config.GetController(0))->GetInput(&s_hotkey); static_cast<HotkeyManager*>(s_config.GetController(0))->GetInput(&s_hotkey);
} }

View File

@ -601,6 +601,8 @@ static void SetInputDisplayString(ControllerState padState, int controllerID)
{ {
std::string display_str = StringFromFormat("P%d:", controllerID + 1); std::string display_str = StringFromFormat("P%d:", controllerID + 1);
if (padState.is_connected)
{
if (padState.A) if (padState.A)
display_str += " A"; display_str += " A";
if (padState.B) if (padState.B)
@ -629,6 +631,11 @@ static void SetInputDisplayString(ControllerState padState, int controllerID)
display_str += Analog1DToString(padState.TriggerR, " R"); display_str += Analog1DToString(padState.TriggerR, " R");
display_str += Analog2DToString(padState.AnalogStickX, padState.AnalogStickY, " ANA"); display_str += Analog2DToString(padState.AnalogStickX, padState.AnalogStickY, " ANA");
display_str += Analog2DToString(padState.CStickX, padState.CStickY, " C"); display_str += Analog2DToString(padState.CStickX, padState.CStickY, " C");
}
else
{
display_str += " DISCONNECTED";
}
std::lock_guard<std::mutex> guard(s_input_display_lock); std::lock_guard<std::mutex> guard(s_input_display_lock);
s_InputDisplay[controllerID] = std::move(display_str); s_InputDisplay[controllerID] = std::move(display_str);
@ -782,6 +789,8 @@ void CheckPadStatus(GCPadStatus* PadStatus, int controllerID)
s_padState.CStickX = PadStatus->substickX; s_padState.CStickX = PadStatus->substickX;
s_padState.CStickY = PadStatus->substickY; s_padState.CStickY = PadStatus->substickY;
s_padState.is_connected = PadStatus->isConnected;
s_padState.disc = s_bDiscChange; s_padState.disc = s_bDiscChange;
s_bDiscChange = false; s_bDiscChange = false;
s_padState.reset = s_bReset; s_padState.reset = s_bReset;
@ -1031,24 +1040,25 @@ void LoadInput(const std::string& filename)
"is %d frames long.\n\n" "is %d frames long.\n\n"
"On frame %td, the current movie presses:\n" "On frame %td, the current movie presses:\n"
"Start=%d, A=%d, B=%d, X=%d, Y=%d, Z=%d, DUp=%d, DDown=%d, DLeft=%d, DRight=%d, " "Start=%d, A=%d, B=%d, X=%d, Y=%d, Z=%d, DUp=%d, DDown=%d, DLeft=%d, DRight=%d, "
"L=%d, R=%d, LT=%d, RT=%d, AnalogX=%d, AnalogY=%d, CX=%d, CY=%d" "L=%d, R=%d, LT=%d, RT=%d, AnalogX=%d, AnalogY=%d, CX=%d, CY=%d, Connected=%d"
"\n\n" "\n\n"
"On frame %td, the savestate's movie presses:\n" "On frame %td, the savestate's movie presses:\n"
"Start=%d, A=%d, B=%d, X=%d, Y=%d, Z=%d, DUp=%d, DDown=%d, DLeft=%d, DRight=%d, " "Start=%d, A=%d, B=%d, X=%d, Y=%d, Z=%d, DUp=%d, DDown=%d, DLeft=%d, DRight=%d, "
"L=%d, R=%d, LT=%d, RT=%d, AnalogX=%d, AnalogY=%d, CX=%d, CY=%d", "L=%d, R=%d, LT=%d, RT=%d, AnalogX=%d, AnalogY=%d, CX=%d, CY=%d, Connected=%d",
frame, (int)s_totalFrames, (int)tmpHeader.frameCount, frame, (int)curPadState.Start, frame, (int)s_totalFrames, (int)tmpHeader.frameCount, frame, (int)curPadState.Start,
(int)curPadState.A, (int)curPadState.B, (int)curPadState.X, (int)curPadState.Y, (int)curPadState.A, (int)curPadState.B, (int)curPadState.X, (int)curPadState.Y,
(int)curPadState.Z, (int)curPadState.DPadUp, (int)curPadState.DPadDown, (int)curPadState.Z, (int)curPadState.DPadUp, (int)curPadState.DPadDown,
(int)curPadState.DPadLeft, (int)curPadState.DPadRight, (int)curPadState.L, (int)curPadState.DPadLeft, (int)curPadState.DPadRight, (int)curPadState.L,
(int)curPadState.R, (int)curPadState.TriggerL, (int)curPadState.TriggerR, (int)curPadState.R, (int)curPadState.TriggerL, (int)curPadState.TriggerR,
(int)curPadState.AnalogStickX, (int)curPadState.AnalogStickY, (int)curPadState.AnalogStickX, (int)curPadState.AnalogStickY,
(int)curPadState.CStickX, (int)curPadState.CStickY, frame, (int)movPadState.Start, (int)curPadState.CStickX, (int)curPadState.CStickY, (int)curPadState.is_connected,
(int)movPadState.A, (int)movPadState.B, (int)movPadState.X, (int)movPadState.Y, frame, (int)movPadState.Start, (int)movPadState.A, (int)movPadState.B,
(int)movPadState.Z, (int)movPadState.DPadUp, (int)movPadState.DPadDown, (int)movPadState.X, (int)movPadState.Y, (int)movPadState.Z, (int)movPadState.DPadUp,
(int)movPadState.DPadLeft, (int)movPadState.DPadRight, (int)movPadState.L, (int)movPadState.DPadDown, (int)movPadState.DPadLeft, (int)movPadState.DPadRight,
(int)movPadState.R, (int)movPadState.TriggerL, (int)movPadState.TriggerR, (int)movPadState.L, (int)movPadState.R, (int)movPadState.TriggerL,
(int)movPadState.AnalogStickX, (int)movPadState.AnalogStickY, (int)movPadState.TriggerR, (int)movPadState.AnalogStickX,
(int)movPadState.CStickX, (int)movPadState.CStickY); (int)movPadState.AnalogStickY, (int)movPadState.CStickX, (int)movPadState.CStickY,
(int)curPadState.is_connected);
} }
} }
} }
@ -1110,15 +1120,11 @@ void PlayController(GCPadStatus* PadStatus, int controllerID)
return; return;
} }
// dtm files don't save the mic button or error bit. not sure if they're actually used, but better
// safe than sorry
signed char e = PadStatus->err;
memset(PadStatus, 0, sizeof(GCPadStatus));
PadStatus->err = e;
memcpy(&s_padState, &s_temp_input[s_currentByte], sizeof(ControllerState)); memcpy(&s_padState, &s_temp_input[s_currentByte], sizeof(ControllerState));
s_currentByte += sizeof(ControllerState); s_currentByte += sizeof(ControllerState);
PadStatus->isConnected = s_padState.is_connected;
PadStatus->triggerLeft = s_padState.TriggerL; PadStatus->triggerLeft = s_padState.TriggerL;
PadStatus->triggerRight = s_padState.TriggerR; PadStatus->triggerRight = s_padState.TriggerR;

View File

@ -42,7 +42,8 @@ struct ControllerState
bool L : 1, R : 1; // Binary triggers, 2 bits bool L : 1, R : 1; // Binary triggers, 2 bits
bool disc : 1; // Checks for disc being changed bool disc : 1; // Checks for disc being changed
bool reset : 1; // Console reset button bool reset : 1; // Console reset button
bool reserved : 2; // Reserved bits used for padding, 2 bits bool is_connected : 1; // Should controller be treated as connected
bool reserved : 1; // Reserved bits used for padding, 1 bit
u8 TriggerL, TriggerR; // Triggers, 16 bits u8 TriggerL, TriggerR; // Triggers, 16 bits
u8 AnalogStickX, AnalogStickY; // Main Stick, 16 bits u8 AnalogStickX, AnalogStickY; // Main Stick, 16 bits

View File

@ -326,7 +326,7 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
PadMapping map = 0; PadMapping map = 0;
GCPadStatus pad; GCPadStatus pad;
packet >> map >> pad.button >> pad.analogA >> pad.analogB >> pad.stickX >> pad.stickY >> packet >> map >> pad.button >> pad.analogA >> pad.analogB >> pad.stickX >> pad.stickY >>
pad.substickX >> pad.substickY >> pad.triggerLeft >> pad.triggerRight; pad.substickX >> pad.substickY >> pad.triggerLeft >> pad.triggerRight >> pad.isConnected;
// Trusting server for good map value (>=0 && <4) // Trusting server for good map value (>=0 && <4)
// add to pad buffer // add to pad buffer
@ -753,7 +753,7 @@ void NetPlayClient::SendPadState(const int in_game_pad, const GCPadStatus& pad)
packet << static_cast<MessageId>(NP_MSG_PAD_DATA); packet << static_cast<MessageId>(NP_MSG_PAD_DATA);
packet << static_cast<PadMapping>(in_game_pad); packet << static_cast<PadMapping>(in_game_pad);
packet << pad.button << pad.analogA << pad.analogB << pad.stickX << pad.stickY << pad.substickX packet << pad.button << pad.analogA << pad.analogB << pad.stickX << pad.stickY << pad.substickX
<< pad.substickY << pad.triggerLeft << pad.triggerRight; << pad.substickY << pad.triggerLeft << pad.triggerRight << pad.isConnected;
SendAsync(std::move(packet)); SendAsync(std::move(packet));
} }

View File

@ -520,7 +520,7 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
PadMapping map = 0; PadMapping map = 0;
GCPadStatus pad; GCPadStatus pad;
packet >> map >> pad.button >> pad.analogA >> pad.analogB >> pad.stickX >> pad.stickY >> packet >> map >> pad.button >> pad.analogA >> pad.analogB >> pad.stickX >> pad.stickY >>
pad.substickX >> pad.substickY >> pad.triggerLeft >> pad.triggerRight; pad.substickX >> pad.substickY >> pad.triggerLeft >> pad.triggerRight >> pad.isConnected;
// If the data is not from the correct player, // If the data is not from the correct player,
// then disconnect them. // then disconnect them.
@ -533,7 +533,8 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
sf::Packet spac; sf::Packet spac;
spac << (MessageId)NP_MSG_PAD_DATA; spac << (MessageId)NP_MSG_PAD_DATA;
spac << map << pad.button << pad.analogA << pad.analogB << pad.stickX << pad.stickY spac << map << pad.button << pad.analogA << pad.analogB << pad.stickX << pad.stickY
<< pad.substickX << pad.substickY << pad.triggerLeft << pad.triggerRight; << pad.substickX << pad.substickY << pad.triggerLeft << pad.triggerRight
<< pad.isConnected;
SendToClients(spac, player.pid); SendToClients(spac, player.pid);
} }

View File

@ -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;

View File

@ -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

View File

@ -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();
}
} }
} }

View File

@ -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;

View File

@ -6,14 +6,6 @@
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
enum PadError
{
PAD_ERR_NONE = 0,
PAD_ERR_NO_CONTROLLER = -1,
PAD_ERR_NOT_READY = -2,
PAD_ERR_TRANSFER = -3,
};
enum enum
{ {
PAD_USE_ORIGIN = 0x0080, PAD_USE_ORIGIN = 0x0080,
@ -48,7 +40,7 @@ struct GCPadStatus
u8 triggerRight; // 0 <= triggerRight <= 255 u8 triggerRight; // 0 <= triggerRight <= 255
u8 analogA; // 0 <= analogA <= 255 u8 analogA; // 0 <= analogA <= 255
u8 analogB; // 0 <= analogB <= 255 u8 analogB; // 0 <= analogB <= 255
s8 err; // one of PAD_ERR_* number bool isConnected{true};
static const u8 MAIN_STICK_CENTER_X = 0x80; static const u8 MAIN_STICK_CENTER_X = 0x80;
static const u8 MAIN_STICK_CENTER_Y = 0x80; static const u8 MAIN_STICK_CENTER_Y = 0x80;