mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-04-05 22:47:03 +00:00
Input: Enable In-Game Pad Config Reset
This commit is contained in:
parent
5a40c1802b
commit
bc3ab7a9d9
9 changed files with 142 additions and 32 deletions
|
|
@ -1,4 +1,4 @@
|
|||
#include "pad_thread.h"
|
||||
#include "pad_thread.h"
|
||||
#include "ds4_pad_handler.h"
|
||||
#ifdef _WIN32
|
||||
#include "xinput_pad_handler.h"
|
||||
|
|
@ -12,27 +12,71 @@
|
|||
namespace pad
|
||||
{
|
||||
atomic_t<pad_thread*> g_current = nullptr;
|
||||
std::recursive_mutex g_pad_mutex;
|
||||
}
|
||||
|
||||
struct pad_setting
|
||||
{
|
||||
u32 port_status;
|
||||
u32 device_capability;
|
||||
u32 device_type;
|
||||
};
|
||||
|
||||
pad_thread::pad_thread(void *_curthread, void *_curwindow) : curthread(_curthread), curwindow(_curwindow)
|
||||
{
|
||||
Init();
|
||||
|
||||
thread = std::make_shared<std::thread>(&pad_thread::ThreadFunc, this);
|
||||
pad::g_current = this;
|
||||
}
|
||||
|
||||
pad_thread::~pad_thread()
|
||||
{
|
||||
pad::g_current = nullptr;
|
||||
active = false;
|
||||
thread->join();
|
||||
|
||||
handlers.clear();
|
||||
}
|
||||
|
||||
void pad_thread::Init()
|
||||
{
|
||||
std::lock_guard lock(pad::g_pad_mutex);
|
||||
|
||||
// Cache old settings if possible
|
||||
std::vector<pad_setting> pad_settings;
|
||||
for (u32 i = 0; i < CELL_PAD_MAX_PORT_NUM; i++) // max 7 pads
|
||||
{
|
||||
if (i >= m_pads.size())
|
||||
{
|
||||
pad_settings.push_back({ CELL_PAD_STATUS_DISCONNECTED, CELL_PAD_CAPABILITY_PS3_CONFORMITY | CELL_PAD_CAPABILITY_PRESS_MODE | CELL_PAD_CAPABILITY_ACTUATOR, CELL_PAD_DEV_TYPE_STANDARD });
|
||||
}
|
||||
else
|
||||
{
|
||||
pad_settings.push_back({ m_pads[i]->m_port_status, m_pads[i]->m_device_capability, m_pads[i]->m_device_type });
|
||||
}
|
||||
}
|
||||
|
||||
std::memset(&m_info, 0, sizeof(m_info));
|
||||
m_info.now_connect = 0;
|
||||
|
||||
m_pads.clear();
|
||||
handlers.clear();
|
||||
|
||||
g_cfg_input.load();
|
||||
|
||||
std::shared_ptr<keyboard_pad_handler> keyptr;
|
||||
|
||||
//Always have a Null Pad Handler
|
||||
// Always have a Null Pad Handler
|
||||
std::shared_ptr<NullPadHandler> nullpad = std::make_shared<NullPadHandler>();
|
||||
handlers.emplace(pad_handler::null, nullpad);
|
||||
|
||||
for (u32 i = 0; i < 7 /* Max 7 pads */; i++)
|
||||
for (u32 i = 0; i < CELL_PAD_MAX_PORT_NUM; i++) // max 7 pads
|
||||
{
|
||||
std::shared_ptr<PadHandlerBase> cur_pad_handler;
|
||||
|
||||
const auto &handler_type = g_cfg_input.player[i]->handler;
|
||||
|
||||
|
||||
if (handlers.count(handler_type) != 0)
|
||||
{
|
||||
cur_pad_handler = handlers[handler_type];
|
||||
|
|
@ -70,30 +114,15 @@ pad_thread::pad_thread(void *_curthread, void *_curwindow) : curthread(_curthrea
|
|||
}
|
||||
cur_pad_handler->Init();
|
||||
|
||||
m_pads.push_back(std::make_shared<Pad>(
|
||||
CELL_PAD_STATUS_DISCONNECTED,
|
||||
CELL_PAD_CAPABILITY_PS3_CONFORMITY | CELL_PAD_CAPABILITY_PRESS_MODE | CELL_PAD_CAPABILITY_ACTUATOR,
|
||||
CELL_PAD_DEV_TYPE_STANDARD));
|
||||
m_pads.push_back(std::make_shared<Pad>(CELL_PAD_STATUS_DISCONNECTED, pad_settings[i].device_capability, pad_settings[i].device_type));
|
||||
|
||||
if (cur_pad_handler->bindPadToDevice(m_pads.back(), g_cfg_input.player[i]->device.to_string()) == false)
|
||||
{
|
||||
//Failed to bind the device to cur_pad_handler so binds to NullPadHandler
|
||||
// Failed to bind the device to cur_pad_handler so binds to NullPadHandler
|
||||
LOG_ERROR(GENERAL, "Failed to bind device %s to handler %s", g_cfg_input.player[i]->device.to_string(), handler_type.to_string());
|
||||
nullpad->bindPadToDevice(m_pads.back(), g_cfg_input.player[i]->device.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
thread = std::make_shared<std::thread>(&pad_thread::ThreadFunc, this);
|
||||
pad::g_current = this;
|
||||
}
|
||||
|
||||
pad_thread::~pad_thread()
|
||||
{
|
||||
pad::g_current = nullptr;
|
||||
active = false;
|
||||
thread->join();
|
||||
|
||||
handlers.clear();
|
||||
}
|
||||
|
||||
void pad_thread::SetRumble(const u32 pad, u8 largeMotor, bool smallMotor)
|
||||
|
|
@ -108,11 +137,20 @@ void pad_thread::SetRumble(const u32 pad, u8 largeMotor, bool smallMotor)
|
|||
}
|
||||
}
|
||||
|
||||
void pad_thread::Reset()
|
||||
{
|
||||
reset = active.load();
|
||||
}
|
||||
|
||||
void pad_thread::ThreadFunc()
|
||||
{
|
||||
active = true;
|
||||
while (active)
|
||||
{
|
||||
if (reset && reset.exchange(false))
|
||||
{
|
||||
Init();
|
||||
}
|
||||
u32 connected = 0;
|
||||
for (auto& cur_pad_handler : handlers)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue