input: move pad_state_notify_state_change to pad_thread

This commit is contained in:
Megamouse 2024-06-11 22:30:16 +02:00
parent b0d4858e42
commit b8452d29d6
26 changed files with 82 additions and 78 deletions

View file

@ -5,7 +5,7 @@
class NullPadHandler final : public PadHandlerBase
{
public:
NullPadHandler(bool emulation) : PadHandlerBase(pad_handler::null, emulation)
NullPadHandler() : PadHandlerBase(pad_handler::null)
{
b_has_pressure_intensity_button = false;
}

View file

@ -7,9 +7,7 @@
cfg_input g_cfg_input;
extern void pad_state_notify_state_change(usz index, u32 state);
PadHandlerBase::PadHandlerBase(pad_handler type, bool emulation) : m_type(type), m_emulation(emulation)
PadHandlerBase::PadHandlerBase(pad_handler type) : m_type(type)
{
}
@ -747,11 +745,6 @@ void PadHandlerBase::process()
pad->m_port_status |= CELL_PAD_STATUS_CONNECTED + CELL_PAD_STATUS_ASSIGN_CHANGES;
if (m_emulation && !pad->is_fake_pad)
{
pad_state_notify_state_change(i, CELL_PAD_STATUS_CONNECTED);
}
last_connection_status[i] = true;
connected_devices++;
}
@ -775,11 +768,6 @@ void PadHandlerBase::process()
pad->m_port_status |= CELL_PAD_STATUS_CONNECTED + CELL_PAD_STATUS_ASSIGN_CHANGES;
if (m_emulation && !pad->is_fake_pad)
{
pad_state_notify_state_change(i, CELL_PAD_STATUS_CONNECTED);
}
last_connection_status[i] = true;
connected_devices++;
}
@ -793,11 +781,6 @@ void PadHandlerBase::process()
pad->m_port_status &= ~CELL_PAD_STATUS_CONNECTED;
pad->m_port_status |= CELL_PAD_STATUS_ASSIGN_CHANGES;
if (m_emulation)
{
pad_state_notify_state_change(i, CELL_PAD_STATUS_DISCONNECTED);
}
last_connection_status[i] = false;
connected_devices--;
}

View file

@ -248,7 +248,6 @@ public:
pad_handler m_type;
bool m_is_init = false;
bool m_emulation = false;
std::string name_string() const;
usz max_devices() const;
@ -266,7 +265,7 @@ public:
void convert_stick_values(u16& x_out, u16& y_out, s32 x_in, s32 y_in, u32 deadzone, u32 anti_deadzone, u32 padsquircling) const;
virtual bool Init() { return true; }
PadHandlerBase(pad_handler type = pad_handler::null, bool emulation = false);
PadHandlerBase(pad_handler type = pad_handler::null);
virtual ~PadHandlerBase() = default;
// Sets window to config the controller(optional)
virtual void SetPadData(const std::string& /*padId*/, u8 /*player_id*/, u8 /*large_motor*/, u8 /*small_motor*/, s32 /*r*/, s32 /*g*/, s32 /*b*/, bool /*player_led*/, bool /*battery_led*/, u32 /*battery_led_brightness*/) {}

View file

@ -10,8 +10,8 @@ constexpr std::array<u8, 6> battery_capacity = {0, 1, 25, 50, 75, 100};
constexpr id_pair SONY_DS3_ID_0 = {0x054C, 0x0268};
ds3_pad_handler::ds3_pad_handler(bool emulation)
: hid_pad_handler(pad_handler::ds3, emulation, {SONY_DS3_ID_0})
ds3_pad_handler::ds3_pad_handler()
: hid_pad_handler(pad_handler::ds3, {SONY_DS3_ID_0})
{
button_list =
{

View file

@ -135,7 +135,7 @@ class ds3_pad_handler final : public hid_pad_handler<ds3_device>
#endif
public:
ds3_pad_handler(bool emulation);
ds3_pad_handler();
~ds3_pad_handler();
void SetPadData(const std::string& padId, u8 player_id, u8 large_motor, u8 small_motor, s32 r, s32 g, s32 b, bool player_led, bool battery_led, u32 battery_led_brightness) override;

View file

@ -59,8 +59,8 @@ namespace
}*/
}
ds4_pad_handler::ds4_pad_handler(bool emulation)
: hid_pad_handler<DS4Device>(pad_handler::ds4, emulation, {SONY_DS4_ID_0, SONY_DS4_ID_1, SONY_DS4_ID_2, ZEROPLUS_ID_0})
ds4_pad_handler::ds4_pad_handler()
: hid_pad_handler<DS4Device>(pad_handler::ds4, {SONY_DS4_ID_0, SONY_DS4_ID_1, SONY_DS4_ID_2, ZEROPLUS_ID_0})
{
// Unique names for the config files and our pad settings dialog
button_list =

View file

@ -164,7 +164,7 @@ class ds4_pad_handler final : public hid_pad_handler<DS4Device>
};
public:
ds4_pad_handler(bool emulation);
ds4_pad_handler();
~ds4_pad_handler();
void SetPadData(const std::string& padId, u8 player_id, u8 large_motor, u8 small_motor, s32 r, s32 g, s32 b, bool player_led, bool battery_led, u32 battery_led_brightness) override;

View file

@ -25,8 +25,8 @@ namespace
constexpr id_pair SONY_DUALSENSE_ID_1 = {0x054C, 0x0DF2}; // DualSense Edge
}
dualsense_pad_handler::dualsense_pad_handler(bool emulation)
: hid_pad_handler<DualSenseDevice>(pad_handler::dualsense, emulation, {SONY_DUALSENSE_ID_0, SONY_DUALSENSE_ID_1})
dualsense_pad_handler::dualsense_pad_handler()
: hid_pad_handler<DualSenseDevice>(pad_handler::dualsense, {SONY_DUALSENSE_ID_0, SONY_DUALSENSE_ID_1})
{
// Unique names for the config files and our pad settings dialog
button_list =

View file

@ -229,7 +229,7 @@ class dualsense_pad_handler final : public hid_pad_handler<DualSenseDevice>
};
public:
dualsense_pad_handler(bool emulation);
dualsense_pad_handler();
~dualsense_pad_handler();
void SetPadData(const std::string& padId, u8 player_id, u8 large_motor, u8 small_motor, s32 r, s32 g, s32 b, bool player_led, bool battery_led, u32 battery_led_brightness) override;

View file

@ -19,8 +19,8 @@
LOG_CHANNEL(evdev_log, "evdev");
evdev_joystick_handler::evdev_joystick_handler(bool emulation)
: PadHandlerBase(pad_handler::evdev, emulation)
evdev_joystick_handler::evdev_joystick_handler()
: PadHandlerBase(pad_handler::evdev)
{
init_configs();

View file

@ -400,7 +400,7 @@ class evdev_joystick_handler final : public PadHandlerBase
};
public:
evdev_joystick_handler(bool emulation);
evdev_joystick_handler();
~evdev_joystick_handler();
void init_config(cfg_pad* cfg) override;

View file

@ -201,26 +201,26 @@ std::shared_ptr<PadHandlerBase> gui_pad_thread::GetHandler(pad_handler type)
// Makes no sense to use this if we are in the GUI anyway
return nullptr;
case pad_handler::ds3:
return std::make_shared<ds3_pad_handler>(false);
return std::make_shared<ds3_pad_handler>();
case pad_handler::ds4:
return std::make_shared<ds4_pad_handler>(false);
return std::make_shared<ds4_pad_handler>();
case pad_handler::dualsense:
return std::make_shared<dualsense_pad_handler>(false);
return std::make_shared<dualsense_pad_handler>();
case pad_handler::skateboard:
return std::make_shared<skateboard_pad_handler>(false);
return std::make_shared<skateboard_pad_handler>();
#ifdef _WIN32
case pad_handler::xinput:
return std::make_shared<xinput_pad_handler>(false);
return std::make_shared<xinput_pad_handler>();
case pad_handler::mm:
return std::make_shared<mm_joystick_handler>(false);
return std::make_shared<mm_joystick_handler>();
#endif
#ifdef HAVE_SDL2
case pad_handler::sdl:
return std::make_shared<sdl_pad_handler>(false);
return std::make_shared<sdl_pad_handler>();
#endif
#ifdef HAVE_LIBEVDEV
case pad_handler::evdev:
return std::make_shared<evdev_joystick_handler>(false);
return std::make_shared<evdev_joystick_handler>();
#endif
}

View file

@ -21,8 +21,8 @@ static std::mutex s_hid_mutex; // hid_pad_handler is created by pad_thread and p
static u8 s_hid_instances{0};
template <class Device>
hid_pad_handler<Device>::hid_pad_handler(pad_handler type, bool emulation, std::vector<id_pair> ids)
: PadHandlerBase(type, emulation), m_ids(std::move(ids))
hid_pad_handler<Device>::hid_pad_handler(pad_handler type, std::vector<id_pair> ids)
: PadHandlerBase(type), m_ids(std::move(ids))
{
std::scoped_lock lock(s_hid_mutex);
ensure(s_hid_instances++ < 255);

View file

@ -51,7 +51,7 @@ template <class Device>
class hid_pad_handler : public PadHandlerBase
{
public:
hid_pad_handler(pad_handler type, bool emulation, std::vector<id_pair> ids);
hid_pad_handler(pad_handler type, std::vector<id_pair> ids);
~hid_pad_handler();
bool Init() override;

View file

@ -16,9 +16,9 @@ bool keyboard_pad_handler::Init()
return true;
}
keyboard_pad_handler::keyboard_pad_handler(bool emulation)
keyboard_pad_handler::keyboard_pad_handler()
: QObject()
, PadHandlerBase(pad_handler::keyboard, emulation)
, PadHandlerBase(pad_handler::keyboard)
{
init_configs();

View file

@ -69,7 +69,7 @@ class keyboard_pad_handler final : public QObject, public PadHandlerBase
public:
bool Init() override;
keyboard_pad_handler(bool emulation);
keyboard_pad_handler();
void SetTargetWindow(QWindow* target);
void processKeyEvent(QKeyEvent* event, bool pressed);

View file

@ -2,7 +2,7 @@
#include "mm_joystick_handler.h"
#include "Emu/Io/pad_config.h"
mm_joystick_handler::mm_joystick_handler(bool emulation) : PadHandlerBase(pad_handler::mm, emulation)
mm_joystick_handler::mm_joystick_handler() : PadHandlerBase(pad_handler::mm)
{
init_configs();

View file

@ -109,7 +109,7 @@ class mm_joystick_handler final : public PadHandlerBase
};
public:
mm_joystick_handler(bool emulation);
mm_joystick_handler();
bool Init() override;

View file

@ -29,6 +29,7 @@
LOG_CHANNEL(sys_log, "SYS");
extern void pad_state_notify_state_change(usz index, u32 state);
extern bool is_input_allowed();
extern std::string g_input_config_override;
@ -101,7 +102,7 @@ void pad_thread::Init()
m_info.now_connect = 0;
handlers.clear();
m_handlers.clear();
g_cfg_input_configs.load();
@ -138,8 +139,8 @@ void pad_thread::Init()
std::shared_ptr<keyboard_pad_handler> keyptr;
// Always have a Null Pad Handler
std::shared_ptr<NullPadHandler> nullpad = std::make_shared<NullPadHandler>(true);
handlers.emplace(pad_handler::null, nullpad);
std::shared_ptr<NullPadHandler> nullpad = std::make_shared<NullPadHandler>();
m_handlers.emplace(pad_handler::null, nullpad);
for (u32 i = 0; i < CELL_PAD_MAX_PORT_NUM; i++) // max 7 pads
{
@ -148,15 +149,15 @@ void pad_thread::Init()
const pad_handler handler_type = pad_settings[i].is_ldd_pad ? pad_handler::null : cfg->handler.get();
if (handlers.contains(handler_type))
if (m_handlers.contains(handler_type))
{
cur_pad_handler = handlers[handler_type];
cur_pad_handler = m_handlers[handler_type];
}
else
{
if (handler_type == pad_handler::keyboard)
{
keyptr = std::make_shared<keyboard_pad_handler>(true);
keyptr = std::make_shared<keyboard_pad_handler>();
keyptr->moveToThread(static_cast<QThread*>(m_curthread));
keyptr->SetTargetWindow(static_cast<QWindow*>(m_curwindow));
cur_pad_handler = keyptr;
@ -166,7 +167,7 @@ void pad_thread::Init()
cur_pad_handler = GetHandler(handler_type);
}
handlers.emplace(handler_type, cur_pad_handler);
m_handlers.emplace(handler_type, cur_pad_handler);
}
cur_pad_handler->Init();
@ -219,6 +220,22 @@ void pad_thread::SetIntercepted(bool intercepted)
}
}
void pad_thread::update_pad_states()
{
for (usz i = 0; i < m_pads.size(); i++)
{
const auto& pad = m_pads[i];
const bool connected = pad && !pad->is_fake_pad && !!(pad->m_port_status & CELL_PAD_STATUS_CONNECTED);
if (m_pads_connected[i] == connected)
continue;
pad_state_notify_state_change(i, connected ? CELL_PAD_STATUS_CONNECTED : CELL_PAD_STATUS_DISCONNECTED);
m_pads_connected[i] = connected;
}
}
void pad_thread::operator()()
{
Init();
@ -260,7 +277,7 @@ void pad_thread::operator()()
input_log.notice("Starting pad threads...");
for (const auto& handler : handlers)
for (const auto& handler : m_handlers)
{
if (handler.first == pad_handler::null)
{
@ -332,7 +349,7 @@ void pad_thread::operator()()
if (pad_mode == pad_handler_mode::single_threaded)
{
for (auto& handler : handlers)
for (auto& handler : m_handlers)
{
handler.second->process();
connected_devices += handler.second->connected_devices;
@ -340,12 +357,14 @@ void pad_thread::operator()()
}
else
{
for (auto& handler : handlers)
for (auto& handler : m_handlers)
{
connected_devices += handler.second->connected_devices;
}
}
update_pad_states();
m_info.now_connect = connected_devices + num_ldd_pad;
// The ignore_input section is only reached when a dialog was closed and the pads are still intercepted.
@ -580,30 +599,30 @@ std::shared_ptr<PadHandlerBase> pad_thread::GetHandler(pad_handler type)
switch (type)
{
case pad_handler::null:
return std::make_shared<NullPadHandler>(true);
return std::make_shared<NullPadHandler>();
case pad_handler::keyboard:
return std::make_shared<keyboard_pad_handler>(true);
return std::make_shared<keyboard_pad_handler>();
case pad_handler::ds3:
return std::make_shared<ds3_pad_handler>(true);
return std::make_shared<ds3_pad_handler>();
case pad_handler::ds4:
return std::make_shared<ds4_pad_handler>(true);
return std::make_shared<ds4_pad_handler>();
case pad_handler::dualsense:
return std::make_shared<dualsense_pad_handler>(true);
return std::make_shared<dualsense_pad_handler>();
case pad_handler::skateboard:
return std::make_shared<skateboard_pad_handler>(true);
return std::make_shared<skateboard_pad_handler>();
#ifdef _WIN32
case pad_handler::xinput:
return std::make_shared<xinput_pad_handler>(true);
return std::make_shared<xinput_pad_handler>();
case pad_handler::mm:
return std::make_shared<mm_joystick_handler>(true);
return std::make_shared<mm_joystick_handler>();
#endif
#ifdef HAVE_SDL2
case pad_handler::sdl:
return std::make_shared<sdl_pad_handler>(true);
return std::make_shared<sdl_pad_handler>();
#endif
#ifdef HAVE_LIBEVDEV
case pad_handler::evdev:
return std::make_shared<evdev_joystick_handler>(true);
return std::make_shared<evdev_joystick_handler>();
#endif
}

View file

@ -44,18 +44,21 @@ protected:
void InitLddPad(u32 handle, const u32* port_status);
// List of all handlers
std::map<pad_handler, std::shared_ptr<PadHandlerBase>> handlers;
std::map<pad_handler, std::shared_ptr<PadHandlerBase>> m_handlers;
// Used for pad_handler::keyboard
void* m_curthread = nullptr;
void* m_curwindow = nullptr;
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<bool, CELL_PAD_MAX_PORT_NUM> m_pads_connected{};
u32 num_ldd_pad = 0;
private:
void update_pad_states();
u32 m_mask_start_press_to_resume = 0;
u64 m_track_start_press_begin_timestamp = 0;
bool m_resume_emulation_flag = false;

View file

@ -15,7 +15,7 @@ u32 g_sdl_handler_count = 0;
constexpr u32 rumble_duration_ms = 500; // Some high number to keep rumble updates at a minimum.
constexpr u32 rumble_refresh_ms = rumble_duration_ms - 100; // We need to keep updating the rumble. Choose a refresh timeout that is unlikely to run into missed rumble updates.
sdl_pad_handler::sdl_pad_handler(bool emulation) : PadHandlerBase(pad_handler::sdl, emulation)
sdl_pad_handler::sdl_pad_handler() : PadHandlerBase(pad_handler::sdl)
{
button_list =
{

View file

@ -95,7 +95,7 @@ class sdl_pad_handler : public PadHandlerBase
};
public:
sdl_pad_handler(bool emulation);
sdl_pad_handler();
~sdl_pad_handler();
SDLDevice::sdl_info get_sdl_info(int i);

View file

@ -37,8 +37,8 @@ namespace
static constexpr std::array<u8, sizeof(skateboard_input_report)> disconnected_state = { 0x00, 0x00, 0x0F, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
}
skateboard_pad_handler::skateboard_pad_handler(bool emulation)
: hid_pad_handler<skateboard_device>(pad_handler::skateboard, emulation, {SKATEBOARD_ID_0})
skateboard_pad_handler::skateboard_pad_handler()
: hid_pad_handler<skateboard_device>(pad_handler::skateboard, {SKATEBOARD_ID_0})
{
// Unique names for the config files and our pad settings dialog
button_list =

View file

@ -171,7 +171,7 @@ class skateboard_pad_handler final : public hid_pad_handler<skateboard_device>
};
public:
skateboard_pad_handler(bool emulation);
skateboard_pad_handler();
~skateboard_pad_handler();
void SetPadData(const std::string& padId, u8 player_id, u8 large_motor, u8 small_motor, s32 r, s32 g, s32 b, bool player_led, bool battery_led, u32 battery_led_brightness) override;

View file

@ -14,7 +14,7 @@ namespace XINPUT_INFO
};
} // namespace XINPUT_INFO
xinput_pad_handler::xinput_pad_handler(bool emulation) : PadHandlerBase(pad_handler::xinput, emulation)
xinput_pad_handler::xinput_pad_handler() : PadHandlerBase(pad_handler::xinput)
{
// Unique names for the config files and our pad settings dialog
button_list =

View file

@ -102,7 +102,7 @@ class xinput_pad_handler final : public PadHandlerBase
};
public:
xinput_pad_handler(bool emulation);
xinput_pad_handler();
~xinput_pad_handler();
bool Init() override;