mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-22 10:42:36 +01:00
Input: fix pad initialization
This commit is contained in:
parent
fd1968dd22
commit
c4b38869ab
@ -28,6 +28,7 @@ namespace pad
|
|||||||
atomic_t<pad_thread*> g_current = nullptr;
|
atomic_t<pad_thread*> g_current = nullptr;
|
||||||
shared_mutex g_pad_mutex;
|
shared_mutex g_pad_mutex;
|
||||||
std::string g_title_id;
|
std::string g_title_id;
|
||||||
|
atomic_t<bool> g_started{false};
|
||||||
atomic_t<bool> g_reset{false};
|
atomic_t<bool> g_reset{false};
|
||||||
atomic_t<bool> g_enabled{true};
|
atomic_t<bool> g_enabled{true};
|
||||||
}
|
}
|
||||||
@ -40,11 +41,11 @@ struct pad_setting
|
|||||||
s32 ldd_handle = -1;
|
s32 ldd_handle = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
pad_thread::pad_thread(void *_curthread, void *_curwindow, std::string_view title_id) : curthread(_curthread), curwindow(_curwindow)
|
pad_thread::pad_thread(void* curthread, void* curwindow, std::string_view title_id) : m_curthread(curthread), m_curwindow(curwindow)
|
||||||
{
|
{
|
||||||
pad::g_title_id = title_id;
|
pad::g_title_id = title_id;
|
||||||
pad::g_current = this;
|
pad::g_current = this;
|
||||||
pad::g_reset = true;
|
pad::g_started = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pad_thread::~pad_thread()
|
pad_thread::~pad_thread()
|
||||||
@ -138,8 +139,8 @@ void pad_thread::Init()
|
|||||||
{
|
{
|
||||||
case pad_handler::keyboard:
|
case pad_handler::keyboard:
|
||||||
keyptr = std::make_shared<keyboard_pad_handler>();
|
keyptr = std::make_shared<keyboard_pad_handler>();
|
||||||
keyptr->moveToThread(static_cast<QThread*>(curthread));
|
keyptr->moveToThread(static_cast<QThread*>(m_curthread));
|
||||||
keyptr->SetTargetWindow(static_cast<QWindow*>(curwindow));
|
keyptr->SetTargetWindow(static_cast<QWindow*>(m_curwindow));
|
||||||
cur_pad_handler = keyptr;
|
cur_pad_handler = keyptr;
|
||||||
break;
|
break;
|
||||||
case pad_handler::ds3:
|
case pad_handler::ds3:
|
||||||
@ -216,13 +217,19 @@ void pad_thread::SetIntercepted(bool intercepted)
|
|||||||
void pad_thread::operator()()
|
void pad_thread::operator()()
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
|
|
||||||
pad::g_reset = false;
|
pad::g_reset = false;
|
||||||
|
pad::g_started = true;
|
||||||
|
|
||||||
|
bool mode_changed = true;
|
||||||
|
|
||||||
atomic_t<pad_handler_mode> pad_mode{g_cfg.io.pad_mode.get()};
|
atomic_t<pad_handler_mode> pad_mode{g_cfg.io.pad_mode.get()};
|
||||||
std::vector<std::unique_ptr<named_thread<std::function<void()>>>> threads;
|
std::vector<std::unique_ptr<named_thread<std::function<void()>>>> threads;
|
||||||
|
|
||||||
const auto stop_threads = [&threads]()
|
const auto stop_threads = [&threads]()
|
||||||
{
|
{
|
||||||
|
input_log.notice("Stopping pad threads...");
|
||||||
|
|
||||||
for (auto& thread : threads)
|
for (auto& thread : threads)
|
||||||
{
|
{
|
||||||
if (thread)
|
if (thread)
|
||||||
@ -233,6 +240,8 @@ void pad_thread::operator()()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
threads.clear();
|
threads.clear();
|
||||||
|
|
||||||
|
input_log.notice("Pad threads stopped");
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto start_threads = [this, &threads, &pad_mode]()
|
const auto start_threads = [this, &threads, &pad_mode]()
|
||||||
@ -242,13 +251,15 @@ void pad_thread::operator()()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input_log.notice("Starting pad threads...");
|
||||||
|
|
||||||
for (const auto& handler : handlers)
|
for (const auto& handler : handlers)
|
||||||
{
|
{
|
||||||
if (handler.first == pad_handler::null)
|
if (handler.first == pad_handler::null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
threads.push_back(std::make_unique<named_thread<std::function<void()>>>(fmt::format("%s Thread", handler.second->m_type), [&handler = handler.second, &pad_mode]()
|
threads.push_back(std::make_unique<named_thread<std::function<void()>>>(fmt::format("%s Thread", handler.second->m_type), [&handler = handler.second, &pad_mode]()
|
||||||
{
|
{
|
||||||
while (thread_ctrl::state() != thread_state::aborting)
|
while (thread_ctrl::state() != thread_state::aborting)
|
||||||
@ -265,6 +276,8 @@ void pad_thread::operator()()
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input_log.notice("Pad threads started");
|
||||||
};
|
};
|
||||||
|
|
||||||
while (thread_ctrl::state() != thread_state::aborting)
|
while (thread_ctrl::state() != thread_state::aborting)
|
||||||
@ -277,11 +290,13 @@ void pad_thread::operator()()
|
|||||||
|
|
||||||
// Update variables
|
// Update variables
|
||||||
const bool needs_reset = pad::g_reset && pad::g_reset.exchange(false);
|
const bool needs_reset = pad::g_reset && pad::g_reset.exchange(false);
|
||||||
const bool mode_changed = pad_mode != pad_mode.exchange(g_cfg.io.pad_mode.get());
|
mode_changed |= pad_mode != pad_mode.exchange(g_cfg.io.pad_mode.get());
|
||||||
|
|
||||||
// Reset pad handlers if necessary
|
// Reset pad handlers if necessary
|
||||||
if (needs_reset || mode_changed)
|
if (needs_reset || mode_changed)
|
||||||
{
|
{
|
||||||
|
mode_changed = false;
|
||||||
|
|
||||||
stop_threads();
|
stop_threads();
|
||||||
|
|
||||||
if (needs_reset)
|
if (needs_reset)
|
||||||
|
@ -17,7 +17,7 @@ class PadHandlerBase;
|
|||||||
class pad_thread
|
class pad_thread
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
pad_thread(void* _curthread, void* _curwindow, std::string_view title_id); // void * instead of QThread * and QWindow * because of include in emucore
|
pad_thread(void* curthread, void* curwindow, std::string_view title_id); // void * instead of QThread * and QWindow * because of include in emucore
|
||||||
pad_thread(const pad_thread&) = delete;
|
pad_thread(const pad_thread&) = delete;
|
||||||
pad_thread& operator=(const pad_thread&) = delete;
|
pad_thread& operator=(const pad_thread&) = delete;
|
||||||
~pad_thread();
|
~pad_thread();
|
||||||
@ -45,8 +45,8 @@ protected:
|
|||||||
std::map<pad_handler, std::shared_ptr<PadHandlerBase>> handlers;
|
std::map<pad_handler, std::shared_ptr<PadHandlerBase>> handlers;
|
||||||
|
|
||||||
// Used for pad_handler::keyboard
|
// Used for pad_handler::keyboard
|
||||||
void *curthread;
|
void* m_curthread = nullptr;
|
||||||
void *curwindow;
|
void* m_curwindow = nullptr;
|
||||||
|
|
||||||
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;
|
||||||
@ -61,6 +61,7 @@ namespace pad
|
|||||||
extern std::string g_title_id;
|
extern std::string g_title_id;
|
||||||
extern atomic_t<bool> g_enabled;
|
extern atomic_t<bool> g_enabled;
|
||||||
extern atomic_t<bool> g_reset;
|
extern atomic_t<bool> g_reset;
|
||||||
|
extern atomic_t<bool> g_started;
|
||||||
|
|
||||||
static inline class pad_thread* get_current_handler(bool relaxed = false)
|
static inline class pad_thread* get_current_handler(bool relaxed = false)
|
||||||
{
|
{
|
||||||
|
@ -106,7 +106,7 @@ EmuCallbacks main_application::CreateCallbacks()
|
|||||||
callbacks.init_pad_handler = [this](std::string_view title_id)
|
callbacks.init_pad_handler = [this](std::string_view title_id)
|
||||||
{
|
{
|
||||||
ensure(g_fxo->init<named_thread<pad_thread>>(get_thread(), m_game_window, title_id));
|
ensure(g_fxo->init<named_thread<pad_thread>>(get_thread(), m_game_window, title_id));
|
||||||
while (pad::g_reset) std::this_thread::yield();
|
while (!pad::g_started) std::this_thread::yield();
|
||||||
};
|
};
|
||||||
|
|
||||||
callbacks.get_audio = []() -> std::shared_ptr<AudioBackend>
|
callbacks.get_audio = []() -> std::shared_ptr<AudioBackend>
|
||||||
|
Loading…
Reference in New Issue
Block a user