input: revert stupid ideas

In order to make input more "atomic" I added man in the middle interfaces to decrease the delay between input and cellPad.
But I failed to notice that this introduced a data race between both ends of the pipeline.
I hope the new mutex location doesn't cause any noticeable input lag.
This commit is contained in:
Megamouse 2021-08-26 04:55:24 +02:00
parent 38097783b8
commit 970fe0df12
2 changed files with 8 additions and 28 deletions

View file

@ -179,22 +179,19 @@ void pad_thread::Init()
nullpad->bindPadToDevice(m_pads[i], g_cfg_input.player[i]->device.to_string(), i); nullpad->bindPadToDevice(m_pads[i], g_cfg_input.player[i]->device.to_string(), i);
} }
m_pads_interface[i] = std::make_shared<Pad>(CELL_PAD_STATUS_DISCONNECTED, pad_settings[i].device_capability, pad_settings[i].device_type);
*m_pads_interface[i] = *m_pads[i];
input_log.notice("Pad %d: %s", i, g_cfg_input.player[i]->device.to_string()); input_log.notice("Pad %d: %s", i, g_cfg_input.player[i]->device.to_string());
} }
} }
void pad_thread::SetRumble(const u32 pad, u8 largeMotor, bool smallMotor) void pad_thread::SetRumble(const u32 pad, u8 largeMotor, bool smallMotor)
{ {
if (pad > m_pads_interface.size()) if (pad > m_pads.size())
return; return;
if (m_pads_interface[pad]->m_vibrateMotors.size() >= 2) if (m_pads[pad]->m_vibrateMotors.size() >= 2)
{ {
m_pads_interface[pad]->m_vibrateMotors[0].m_value = largeMotor; m_pads[pad]->m_vibrateMotors[0].m_value = largeMotor;
m_pads_interface[pad]->m_vibrateMotors[1].m_value = smallMotor ? 255 : 0; m_pads[pad]->m_vibrateMotors[1].m_value = smallMotor ? 255 : 0;
} }
} }
@ -229,26 +226,15 @@ void pad_thread::ThreadFunc()
u32 connected_devices = 0; u32 connected_devices = 0;
// Copy public pad data - which might have been changed - to internal pads
{ {
std::lock_guard lock(pad::g_pad_mutex); std::lock_guard lock(pad::g_pad_mutex);
for (usz i = 0; i < m_pads.size(); i++)
{
*m_pads[i] = *m_pads_interface[i];
}
}
for (auto& cur_pad_handler : handlers) for (auto& cur_pad_handler : handlers)
{ {
cur_pad_handler.second->ThreadProc(); cur_pad_handler.second->ThreadProc();
connected_devices += cur_pad_handler.second->connected_devices; connected_devices += cur_pad_handler.second->connected_devices;
} }
// Copy new internal pad data back to public pads
{
std::lock_guard lock(pad::g_pad_mutex);
m_info.now_connect = connected_devices + num_ldd_pad; m_info.now_connect = connected_devices + num_ldd_pad;
// The input_ignored section is only reached when a dialog was closed and the pads are still intercepted. // The input_ignored section is only reached when a dialog was closed and the pads are still intercepted.
@ -287,8 +273,6 @@ void pad_thread::ThreadFunc()
} }
} }
} }
*m_pads_interface[i] = *pad;
} }
if (input_ignored && !any_button_pressed) if (input_ignored && !any_button_pressed)
@ -325,8 +309,6 @@ void pad_thread::InitLddPad(u32 handle)
50 50
); );
*m_pads_interface[handle] = *m_pads[handle];
num_ldd_pad++; num_ldd_pad++;
} }
@ -350,7 +332,6 @@ void pad_thread::UnregisterLddPad(u32 handle)
ensure(handle < m_pads.size()); ensure(handle < m_pads.size());
m_pads[handle]->ldd = false; m_pads[handle]->ldd = false;
m_pads_interface[handle]->ldd = false;
num_ldd_pad--; num_ldd_pad--;
} }

View file

@ -24,7 +24,7 @@ public:
~pad_thread(); ~pad_thread();
PadInfo& GetInfo() { return m_info; } PadInfo& GetInfo() { return m_info; }
auto& GetPads() { return m_pads_interface; } auto& GetPads() { return m_pads; }
void SetRumble(const u32 pad, u8 largeMotor, bool smallMotor); void SetRumble(const u32 pad, u8 largeMotor, bool smallMotor);
void Init(); void Init();
void SetIntercepted(bool intercepted); void SetIntercepted(bool intercepted);
@ -48,7 +48,6 @@ protected:
PadInfo m_info{ 0, 0, false }; PadInfo m_info{ 0, 0, false };
std::array<std::shared_ptr<Pad>, CELL_PAD_MAX_PORT_NUM> m_pads; std::array<std::shared_ptr<Pad>, CELL_PAD_MAX_PORT_NUM> m_pads;
std::array<std::shared_ptr<Pad>, CELL_PAD_MAX_PORT_NUM> m_pads_interface;
std::shared_ptr<std::thread> thread; std::shared_ptr<std::thread> thread;