mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-04-07 15:36:26 +00:00
Perform refactoring of pads to remove the ugly pad initialization.
This commit is contained in:
parent
b01e7e3362
commit
d1cde4d0a7
8 changed files with 127 additions and 53 deletions
|
|
@ -63,9 +63,6 @@ void rpcs3_app::Init()
|
|||
// Create the main window
|
||||
RPCS3MainWin = new main_window(guiSettings, nullptr);
|
||||
|
||||
// Reset the pads -- see the method for why this is currently needed.
|
||||
ResetPads();
|
||||
|
||||
// Create callbacks from the emulator, which reference the handlers.
|
||||
InitializeCallbacks();
|
||||
|
||||
|
|
@ -113,7 +110,13 @@ void rpcs3_app::InitializeCallbacks()
|
|||
switch (keyboard_handler type = g_cfg.io.keyboard)
|
||||
{
|
||||
case keyboard_handler::null: return std::make_shared<NullKeyboardHandler>();
|
||||
case keyboard_handler::basic: return m_basicKeyboardHandler;
|
||||
case keyboard_handler::basic:
|
||||
{
|
||||
basic_keyboard_handler* ret = new basic_keyboard_handler();
|
||||
ret->moveToThread(thread());
|
||||
ret->SetTargetWindow(gameWindow);
|
||||
return std::shared_ptr<KeyboardHandlerBase>(ret);
|
||||
}
|
||||
default: fmt::throw_exception("Invalid keyboard handler: %s", type);
|
||||
}
|
||||
};
|
||||
|
|
@ -123,7 +126,13 @@ void rpcs3_app::InitializeCallbacks()
|
|||
switch (mouse_handler type = g_cfg.io.mouse)
|
||||
{
|
||||
case mouse_handler::null: return std::make_shared<NullMouseHandler>();
|
||||
case mouse_handler::basic: return m_basicMouseHandler;
|
||||
case mouse_handler::basic:
|
||||
{
|
||||
basic_mouse_handler* ret = new basic_mouse_handler();
|
||||
ret->moveToThread(thread());
|
||||
ret->SetTargetWindow(gameWindow);
|
||||
return std::shared_ptr<MouseHandlerBase>(ret);
|
||||
}
|
||||
default: fmt::throw_exception("Invalid mouse handler: %s", type);
|
||||
}
|
||||
};
|
||||
|
|
@ -133,7 +142,13 @@ void rpcs3_app::InitializeCallbacks()
|
|||
switch (pad_handler type = g_cfg.io.pad)
|
||||
{
|
||||
case pad_handler::null: return std::make_shared<NullPadHandler>();
|
||||
case pad_handler::keyboard: return m_keyboardPadHandler;
|
||||
case pad_handler::keyboard:
|
||||
{
|
||||
keyboard_pad_handler* ret = new keyboard_pad_handler();
|
||||
ret->moveToThread(thread());
|
||||
ret->SetTargetWindow(gameWindow);
|
||||
return std::shared_ptr<PadHandlerBase>(ret);
|
||||
}
|
||||
case pad_handler::ds4: return std::make_shared<ds4_pad_handler>();
|
||||
#ifdef _MSC_VER
|
||||
case pad_handler::xinput: return std::make_shared<xinput_pad_handler>();
|
||||
|
|
@ -166,11 +181,31 @@ void rpcs3_app::InitializeCallbacks()
|
|||
|
||||
switch (video_renderer type = g_cfg.video.renderer)
|
||||
{
|
||||
case video_renderer::null: return std::make_unique<gs_frame>("Null", w, h, RPCS3MainWin->GetAppIcon(), disableMouse);
|
||||
case video_renderer::opengl: return std::make_unique<gl_gs_frame>(w, h, RPCS3MainWin->GetAppIcon(), disableMouse);
|
||||
case video_renderer::vulkan: return std::make_unique<gs_frame>("Vulkan", w, h, RPCS3MainWin->GetAppIcon(), disableMouse);
|
||||
case video_renderer::null:
|
||||
{
|
||||
gs_frame* ret = new gs_frame("Null", size.first, size.second, RPCS3MainWin->GetAppIcon(), disableMouse);
|
||||
gameWindow = ret;
|
||||
return std::unique_ptr<gs_frame>(ret);
|
||||
}
|
||||
case video_renderer::opengl:
|
||||
{
|
||||
gl_gs_frame* ret = new gl_gs_frame(size.first, size.second, RPCS3MainWin->GetAppIcon(), disableMouse);
|
||||
gameWindow = ret;
|
||||
return std::unique_ptr<gl_gs_frame>(ret);
|
||||
}
|
||||
case video_renderer::vulkan:
|
||||
{
|
||||
gs_frame* ret = new gs_frame("Vulkan", size.first, size.second, RPCS3MainWin->GetAppIcon(), disableMouse);
|
||||
gameWindow = ret;
|
||||
return std::unique_ptr<gs_frame>(ret);
|
||||
}
|
||||
#ifdef _MSC_VER
|
||||
case video_renderer::dx12: return std::make_unique<gs_frame>("DirectX 12", w, h, RPCS3MainWin->GetAppIcon(), disableMouse);
|
||||
case video_renderer::dx12:
|
||||
{
|
||||
gs_frame* ret = new gs_frame("DirectX 12", size.first, size.second, RPCS3MainWin->GetAppIcon(), disableMouse);
|
||||
gameWindow = ret;
|
||||
return std::unique_ptr<gs_frame>(ret);
|
||||
}
|
||||
#endif
|
||||
default: fmt::throw_exception("Invalid video renderer: %s" HERE, type);
|
||||
}
|
||||
|
|
@ -237,7 +272,6 @@ void rpcs3_app::InitializeConnects()
|
|||
connect(this, &rpcs3_app::RequestCallAfter, this, &rpcs3_app::HandleCallAfter);
|
||||
|
||||
connect(this, &rpcs3_app::OnEmulatorRun, RPCS3MainWin, &main_window::OnEmuRun);
|
||||
connect(this, &rpcs3_app::OnEmulatorStop, this, &rpcs3_app::ResetPads);
|
||||
connect(this, &rpcs3_app::OnEmulatorStop, RPCS3MainWin, &main_window::OnEmuStop);
|
||||
connect(this, &rpcs3_app::OnEmulatorPause, RPCS3MainWin, &main_window::OnEmuPause);
|
||||
connect(this, &rpcs3_app::OnEmulatorResume, RPCS3MainWin, &main_window::OnEmuResume);
|
||||
|
|
@ -269,17 +303,3 @@ void rpcs3_app::HandleCallAfter(const std::function<void()>& func)
|
|||
{
|
||||
func();
|
||||
}
|
||||
|
||||
/**
|
||||
* We need to make this in the main thread to receive events from the main thread.
|
||||
* This leads to the tricky situation. Creating it while booting leads to deadlock with a blocking connection.
|
||||
* So, I need to make them before, but when?
|
||||
* I opted to reset them when the Emu stops and on first init. Potentially a race condition on restart? Never encountered issues.
|
||||
* The other tricky issue is that I don't want Init to be called twice on the same object. Reseting the pointer on emu stop should handle this as well!
|
||||
*/
|
||||
void rpcs3_app::ResetPads()
|
||||
{
|
||||
m_basicKeyboardHandler.reset(new basic_keyboard_handler(this, this));
|
||||
m_basicMouseHandler.reset(new basic_mouse_handler(this, this));
|
||||
m_keyboardPadHandler.reset(new keyboard_pad_handler(this, this));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue