Properly log device creation/destruction + untangle profile saving from slot connectivity
This commit is contained in:
parent
3e60c31d26
commit
efd9108279
|
@ -467,25 +467,24 @@ bool Settings::LoadConfig()
|
|||
// ==== Input Port Begin ====
|
||||
|
||||
for (int port_num = 0; port_num < 4; port_num++) {
|
||||
m_input_port[port_num].Type = to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID);
|
||||
m_input_port[port_num].TopSlotType = to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID);
|
||||
m_input_port[port_num].BottomSlotType = to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID);
|
||||
for (int slot = 0; slot < XBOX_CTRL_NUM_SLOTS; ++slot) {
|
||||
m_input_port[port_num].Type = to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID);
|
||||
m_input_port[port_num].SlotType[slot] = to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID);
|
||||
|
||||
std::string current_section = std::string(section_input_port) + std::to_string(port_num);
|
||||
int ret = m_si.GetLongValue(current_section.c_str(), sect_input_port.type, -2);
|
||||
if (ret == -2) {
|
||||
continue;
|
||||
std::string current_section = std::string(section_input_port) + std::to_string(port_num);
|
||||
int ret = m_si.GetLongValue(current_section.c_str(), sect_input_port.type, -2);
|
||||
if (ret == -2) {
|
||||
continue;
|
||||
}
|
||||
m_input_port[port_num].Type = ret;
|
||||
m_input_port[port_num].DeviceName = m_si.GetValue(current_section.c_str(), sect_input_port.device);
|
||||
m_input_port[port_num].ProfileName = TrimQuoteFromString(m_si.GetValue(current_section.c_str(), sect_input_port.config));
|
||||
ret = m_si.GetLongValue(current_section.c_str(), slot == 0 ? sect_input_port.top_slot : sect_input_port.bottom_slot, -2);
|
||||
if (ret == -2) {
|
||||
continue;
|
||||
}
|
||||
m_input_port[port_num].SlotType[slot] = ret;
|
||||
}
|
||||
m_input_port[port_num].Type = ret;
|
||||
m_input_port[port_num].DeviceName = m_si.GetValue(current_section.c_str(), sect_input_port.device);
|
||||
m_input_port[port_num].ProfileName = TrimQuoteFromString(m_si.GetValue(current_section.c_str(), sect_input_port.config));
|
||||
ret = m_si.GetLongValue(current_section.c_str(), sect_input_port.top_slot, -2);
|
||||
if (ret == -2) {
|
||||
continue;
|
||||
}
|
||||
m_input_port[port_num].TopSlotType = ret;
|
||||
m_input_port[port_num].BottomSlotType = m_si.GetLongValue(current_section.c_str(), sect_input_port.bottom_slot, -2);
|
||||
assert(m_input_port[port_num].BottomSlotType != -2);
|
||||
}
|
||||
|
||||
// ==== Input Port End ==============
|
||||
|
@ -656,8 +655,8 @@ bool Settings::Save(std::string file_path)
|
|||
m_si.SetLongValue(current_section.c_str(), sect_input_port.type, m_input_port[port_num].Type, nullptr, false, true);
|
||||
m_si.SetValue(current_section.c_str(), sect_input_port.device, m_input_port[port_num].DeviceName.c_str(), nullptr, true);
|
||||
m_si.SetValue(current_section.c_str(), sect_input_port.config, quoted_prf_str.c_str(), nullptr, true);
|
||||
m_si.SetLongValue(current_section.c_str(), sect_input_port.top_slot, m_input_port[port_num].TopSlotType, nullptr, false, true);
|
||||
m_si.SetLongValue(current_section.c_str(), sect_input_port.bottom_slot, m_input_port[port_num].BottomSlotType, nullptr, false, true);
|
||||
m_si.SetLongValue(current_section.c_str(), sect_input_port.top_slot, m_input_port[port_num].SlotType[SLOT_TOP], nullptr, false, true);
|
||||
m_si.SetLongValue(current_section.c_str(), sect_input_port.bottom_slot, m_input_port[port_num].SlotType[SLOT_BOTTOM], nullptr, false, true);
|
||||
}
|
||||
|
||||
// ==== Input Port End ==============
|
||||
|
@ -783,8 +782,8 @@ void Settings::SyncToEmulator()
|
|||
// register xbox device input settings
|
||||
for (int i = 0; i < 4; i++) {
|
||||
g_EmuShared->SetInputDevTypeSettings(&m_input_port[i].Type, i);
|
||||
g_EmuShared->SetInputSlotTypeSettings(&m_input_port[i].TopSlotType, i, SLOT_TOP);
|
||||
g_EmuShared->SetInputSlotTypeSettings(&m_input_port[i].BottomSlotType, i, SLOT_BOTTOM);
|
||||
g_EmuShared->SetInputSlotTypeSettings(&m_input_port[i].SlotType[SLOT_TOP], i, SLOT_TOP);
|
||||
g_EmuShared->SetInputSlotTypeSettings(&m_input_port[i].SlotType[SLOT_BOTTOM], i, SLOT_BOTTOM);
|
||||
if (m_input_port[i].Type != to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID)) {
|
||||
g_EmuShared->SetInputDevNameSettings(m_input_port[i].DeviceName.c_str(), i);
|
||||
auto it = std::find_if(m_input_profiles[m_input_port[i].Type].begin(),
|
||||
|
|
|
@ -147,10 +147,9 @@ public:
|
|||
|
||||
struct s_input_port {
|
||||
int Type;
|
||||
int SlotType[2];
|
||||
std::string DeviceName;
|
||||
std::string ProfileName;
|
||||
int TopSlotType;
|
||||
int BottomSlotType;
|
||||
};
|
||||
std::array<s_input_port, 4> m_input_port;
|
||||
|
||||
|
|
|
@ -297,16 +297,12 @@ void InputDeviceManager::ConnectDevice(DeviceState *dev, DeviceState *upstream,
|
|||
{
|
||||
ConstructHleInputDevice(dev, upstream, type, port);
|
||||
BindHostDevice(type, port);
|
||||
EmuLog(LOG_LEVEL::INFO, "Attached device %s to port %d", GetInputDeviceName(type).c_str(),
|
||||
PortUserFormat(port).c_str());
|
||||
}
|
||||
|
||||
void InputDeviceManager::DisconnectDevice(DeviceState *dev, std::string_view port, bool ack)
|
||||
{
|
||||
if (ack) {
|
||||
int type = to_underlying(dev->type);
|
||||
DestructHleInputDevice(dev);
|
||||
EmuLog(LOG_LEVEL::INFO, "Detached device %s from port %d", GetInputDeviceName(type).c_str(), PortUserFormat(port).c_str());
|
||||
}
|
||||
else {
|
||||
dev->bPendingRemoval = true;
|
||||
|
|
|
@ -260,9 +260,6 @@ bool InputWindow::SaveProfile(const std::string& name)
|
|||
g_Settings->m_input_port[m_port_num].DeviceName = profile.DeviceName;
|
||||
g_Settings->m_input_port[m_port_num].ProfileName = profile.ProfileName;
|
||||
g_Settings->m_input_profiles[m_dev_type].push_back(std::move(profile));
|
||||
if (auto duke_wnd = dynamic_cast<DukeInputWindow *>(this)) {
|
||||
duke_wnd->SaveSlotConfig();
|
||||
}
|
||||
|
||||
m_bHasChanges = false;
|
||||
return true;
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
#define RUMBLE_CLEAR 7
|
||||
#define BUTTON_CLEAR 8
|
||||
#define BUTTON_SWAP 9
|
||||
#define SLOTS_CHANGED 10
|
||||
|
||||
#define XINPUT_DEFAULT 0
|
||||
#define DINPUT_DEFAULT 1
|
||||
|
@ -75,6 +74,7 @@ protected:
|
|||
void OverwriteProfile(const std::string& name);
|
||||
void LoadDefaultProfile();
|
||||
virtual int EnableDefaultButton() = 0;
|
||||
virtual void SaveSlotConfig() = 0;
|
||||
|
||||
// xbox device under configuration
|
||||
EmuDevice* m_DeviceConfig;
|
||||
|
@ -107,7 +107,7 @@ public:
|
|||
void BindDefault();
|
||||
void ClearBindings() override;
|
||||
void UpdateProfile(const std::string &name, int command) override;
|
||||
void SaveSlotConfig();
|
||||
void SaveSlotConfig() override;
|
||||
|
||||
|
||||
private:
|
||||
|
@ -131,6 +131,7 @@ class SbcInputWindow : public InputWindow
|
|||
public:
|
||||
void Initialize(HWND hwnd, int port_num, int dev_type) override;
|
||||
void ClearBindings() override;
|
||||
void SaveSlotConfig() override;
|
||||
|
||||
|
||||
private:
|
||||
|
|
|
@ -277,6 +277,8 @@ void ConstructHleInputDevice(DeviceState *dev, DeviceState *upstream, int type,
|
|||
UpdateXppState(dev, static_cast<XBOX_INPUT_DEVICE>(type), port);
|
||||
|
||||
g_bIsDevicesEmulating = false;
|
||||
|
||||
EmuLogEx(CXBXR_MODULE::INPSYS, LOG_LEVEL::INFO, "Attached device %s to port %s", GetInputDeviceName(type).c_str(), PortUserFormat(port).c_str());
|
||||
}
|
||||
|
||||
void DestructHleInputDevice(DeviceState *dev)
|
||||
|
@ -343,6 +345,8 @@ void DestructHleInputDevice(DeviceState *dev)
|
|||
dev->upstream = nullptr;
|
||||
|
||||
g_bIsDevicesEmulating = false;
|
||||
|
||||
EmuLogEx(CXBXR_MODULE::INPSYS, LOG_LEVEL::INFO, "Detached device %s from port %s", GetInputDeviceName(to_underlying(type)).c_str(), PortUserFormat(port).c_str());
|
||||
}
|
||||
|
||||
void SetupXboxDeviceTypes()
|
||||
|
|
|
@ -51,8 +51,8 @@ void SyncInputSettings(int port_num, int dev_type, bool is_opt)
|
|||
if (!is_opt) {
|
||||
// Sync updated input to kernel process to use run-time settings.
|
||||
g_EmuShared->SetInputDevTypeSettings(&g_Settings->m_input_port[port_num].Type, port_num);
|
||||
g_EmuShared->SetInputSlotTypeSettings(&g_Settings->m_input_port[port_num].TopSlotType, port_num, SLOT_TOP);
|
||||
g_EmuShared->SetInputSlotTypeSettings(&g_Settings->m_input_port[port_num].BottomSlotType, port_num, SLOT_BOTTOM);
|
||||
g_EmuShared->SetInputSlotTypeSettings(&g_Settings->m_input_port[port_num].SlotType[SLOT_TOP], port_num, SLOT_TOP);
|
||||
g_EmuShared->SetInputSlotTypeSettings(&g_Settings->m_input_port[port_num].SlotType[SLOT_BOTTOM], port_num, SLOT_BOTTOM);
|
||||
|
||||
if (dev_type != to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID)) {
|
||||
std::string dev_name = g_Settings->m_input_port[port_num].DeviceName;
|
||||
|
@ -165,8 +165,8 @@ INT_PTR CALLBACK DlgInputConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPAR
|
|||
DeviceType != to_underlying(XBOX_INPUT_DEVICE::MS_CONTROLLER_S)) {
|
||||
// Forcefully set the child devices to none. This will happen if the user sets MUs in the controller dialog but
|
||||
// then they set the parent device to a device that cannot support them in the input dialog
|
||||
g_Settings->m_input_port[port].TopSlotType = to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID);
|
||||
g_Settings->m_input_port[port].BottomSlotType = to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID);
|
||||
g_Settings->m_input_port[port].SlotType[SLOT_TOP] = to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID);
|
||||
g_Settings->m_input_port[port].SlotType[SLOT_BOTTOM] = to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID);
|
||||
}
|
||||
SyncInputSettings(port, DeviceType, false);
|
||||
}
|
||||
|
|
|
@ -88,31 +88,24 @@ void DukeInputWindow::Initialize(HWND hwnd, int port_num, int dev_type)
|
|||
|
||||
if (m_dev_type == to_underlying(XBOX_INPUT_DEVICE::ARCADE_STICK)) {
|
||||
// The arcade joystick does not have slot ports so we always disable the corresponding options
|
||||
LRESULT index_top = SendMessage(m_hwnd_slot_list[SLOT_TOP], CB_ADDSTRING, 0,
|
||||
reinterpret_cast<LPARAM>(GetInputDeviceName(to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID)).c_str()));
|
||||
LRESULT index_bottom = SendMessage(m_hwnd_slot_list[SLOT_BOTTOM], CB_ADDSTRING, 0,
|
||||
reinterpret_cast<LPARAM>(GetInputDeviceName(to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID)).c_str()));
|
||||
SendMessage(m_hwnd_slot_list[SLOT_TOP], CB_SETITEMDATA, index_top, to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID));
|
||||
SendMessage(m_hwnd_slot_list[SLOT_BOTTOM], CB_SETITEMDATA, index_bottom, to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID));
|
||||
SendMessage(m_hwnd_slot_list[SLOT_TOP], CB_SETCURSEL, index_top, 0);
|
||||
SendMessage(m_hwnd_slot_list[SLOT_BOTTOM], CB_SETCURSEL, index_bottom, 0);
|
||||
EnableWindow(m_hwnd_slot_list[SLOT_TOP], FALSE);
|
||||
EnableWindow(m_hwnd_slot_list[SLOT_BOTTOM], FALSE);
|
||||
for (unsigned slot = 0; slot < XBOX_CTRL_NUM_SLOTS; ++slot) {
|
||||
LRESULT index = SendMessage(m_hwnd_slot_list[slot], CB_ADDSTRING, 0,
|
||||
reinterpret_cast<LPARAM>(GetInputDeviceName(to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID)).c_str()));
|
||||
SendMessage(m_hwnd_slot_list[slot], CB_SETITEMDATA, index, to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID));
|
||||
SendMessage(m_hwnd_slot_list[slot], CB_SETCURSEL, index, 0);
|
||||
EnableWindow(m_hwnd_slot_list[slot], FALSE);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Set up the device types we support in the slot ports
|
||||
for (auto slot_type : slot_support_list) {
|
||||
LRESULT index_top = SendMessage(m_hwnd_slot_list[SLOT_TOP], CB_ADDSTRING, 0,
|
||||
reinterpret_cast<LPARAM>(GetInputDeviceName(to_underlying(slot_type)).c_str()));
|
||||
LRESULT index_bottom = SendMessage(m_hwnd_slot_list[SLOT_BOTTOM], CB_ADDSTRING, 0,
|
||||
reinterpret_cast<LPARAM>(GetInputDeviceName(to_underlying(slot_type)).c_str()));
|
||||
SendMessage(m_hwnd_slot_list[SLOT_TOP], CB_SETITEMDATA, index_top, to_underlying(slot_type));
|
||||
SendMessage(m_hwnd_slot_list[SLOT_BOTTOM], CB_SETITEMDATA, index_bottom, to_underlying(slot_type));
|
||||
if (g_Settings->m_input_port[m_port_num].TopSlotType == to_underlying(slot_type)) {
|
||||
SendMessage(m_hwnd_slot_list[SLOT_TOP], CB_SETCURSEL, index_top, 0);
|
||||
}
|
||||
if (g_Settings->m_input_port[m_port_num].BottomSlotType == to_underlying(slot_type)) {
|
||||
SendMessage(m_hwnd_slot_list[SLOT_BOTTOM], CB_SETCURSEL, index_bottom, 0);
|
||||
for (unsigned slot = 0; slot < XBOX_CTRL_NUM_SLOTS; ++slot) {
|
||||
LRESULT index = SendMessage(m_hwnd_slot_list[slot], CB_ADDSTRING, 0,
|
||||
reinterpret_cast<LPARAM>(GetInputDeviceName(to_underlying(slot_type)).c_str()));
|
||||
SendMessage(m_hwnd_slot_list[slot], CB_SETITEMDATA, index, to_underlying(slot_type));
|
||||
if (g_Settings->m_input_port[m_port_num].SlotType[slot] == to_underlying(slot_type)) {
|
||||
SendMessage(m_hwnd_slot_list[slot], CB_SETCURSEL, index, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -218,10 +211,6 @@ void DukeInputWindow::UpdateProfile(const std::string &name, int command)
|
|||
m_rumble = std::string();
|
||||
break;
|
||||
|
||||
case SLOTS_CHANGED:
|
||||
m_bHasChanges = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
InputWindow::UpdateProfile(name, command);
|
||||
}
|
||||
|
@ -258,10 +247,10 @@ void DukeInputWindow::DetectOutput(int ms)
|
|||
|
||||
void DukeInputWindow::SaveSlotConfig()
|
||||
{
|
||||
int DeviceType = SendMessage(m_hwnd_slot_list[SLOT_TOP], CB_GETITEMDATA, SendMessage(m_hwnd_slot_list[SLOT_TOP], CB_GETCURSEL, 0, 0), 0);
|
||||
g_Settings->m_input_port[m_port_num].TopSlotType = DeviceType;
|
||||
DeviceType = SendMessage(m_hwnd_slot_list[SLOT_BOTTOM], CB_GETITEMDATA, SendMessage(m_hwnd_slot_list[SLOT_BOTTOM], CB_GETCURSEL, 0, 0), 0);
|
||||
g_Settings->m_input_port[m_port_num].BottomSlotType = DeviceType;
|
||||
for (unsigned slot = 0; slot < XBOX_CTRL_NUM_SLOTS; ++slot) {
|
||||
g_Settings->m_input_port[m_port_num].SlotType[slot] = SendMessage(m_hwnd_slot_list[slot], CB_GETITEMDATA,
|
||||
SendMessage(m_hwnd_slot_list[slot], CB_GETCURSEL, 0, 0), 0);
|
||||
}
|
||||
}
|
||||
|
||||
static INT_PTR CALLBACK DlgRumbleConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||
|
@ -291,6 +280,7 @@ INT_PTR CALLBACK DlgXidControllerConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wPar
|
|||
case WM_CLOSE:
|
||||
{
|
||||
if (g_InputWindow->IsProfileSaved()) {
|
||||
g_InputWindow->SaveSlotConfig();
|
||||
delete g_InputWindow;
|
||||
g_InputWindow = nullptr;
|
||||
EndDialog(hWndDlg, wParam);
|
||||
|
@ -309,14 +299,6 @@ INT_PTR CALLBACK DlgXidControllerConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wPar
|
|||
}
|
||||
break;
|
||||
|
||||
case IDC_DEVICE_LIST_TOP_SLOT:
|
||||
case IDC_DEVICE_LIST_BOTTOM_SLOT: {
|
||||
if (HIWORD(wParam) == CBN_SELCHANGE) {
|
||||
g_InputWindow->UpdateProfile(std::string(), SLOTS_CHANGED);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case IDC_PROFILE_NAME: {
|
||||
if (HIWORD(wParam) == CBN_SELCHANGE) {
|
||||
char name[50];
|
||||
|
|
|
@ -87,6 +87,13 @@ int SbcInputWindow::EnableDefaultButton()
|
|||
return -1;
|
||||
}
|
||||
|
||||
void SbcInputWindow::SaveSlotConfig()
|
||||
{
|
||||
for (unsigned slot = 0; slot < XBOX_CTRL_NUM_SLOTS; ++slot) {
|
||||
g_Settings->m_input_port[m_port_num].SlotType[slot] = to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID);
|
||||
}
|
||||
}
|
||||
|
||||
INT_PTR CALLBACK DlgSBControllerConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (uMsg)
|
||||
|
@ -110,6 +117,7 @@ INT_PTR CALLBACK DlgSBControllerConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wPara
|
|||
case WM_CLOSE:
|
||||
{
|
||||
if (g_InputWindow->IsProfileSaved()) {
|
||||
g_InputWindow->SaveSlotConfig();
|
||||
delete g_InputWindow;
|
||||
g_InputWindow = nullptr;
|
||||
EndDialog(hWndDlg, wParam);
|
||||
|
|
Loading…
Reference in New Issue