From 639b8112b61f5a4d2e873d404360961a6d08afdc Mon Sep 17 00:00:00 2001 From: Megamouse Date: Wed, 6 Jul 2022 14:35:50 +0200 Subject: [PATCH] Input: make move handler dynamic --- rpcs3/Emu/Cell/Modules/cellGem.cpp | 37 +++++++++++++---------------- rpcs3/Emu/system_config.h | 2 +- rpcs3/Input/basic_mouse_handler.cpp | 9 ++++++- rpcs3/main_application.cpp | 2 ++ 4 files changed, 27 insertions(+), 23 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/cellGem.cpp b/rpcs3/Emu/Cell/Modules/cellGem.cpp index 2fb5f4000b..a61a883cdc 100644 --- a/rpcs3/Emu/Cell/Modules/cellGem.cpp +++ b/rpcs3/Emu/Cell/Modules/cellGem.cpp @@ -571,6 +571,9 @@ static bool mouse_input_to_pad(const u32 mouse_no, be_t& digital_buttons, b std::scoped_lock lock(handler.mutex); + // Make sure that the mouse handler is initialized + handler.Init(std::min(g_fxo->get().attribute.max_connect, CELL_GEM_MAX_NUM)); + if (mouse_no >= handler.GetMice().size()) { return false; @@ -621,6 +624,9 @@ static void mouse_pos_to_gem_image_state(const u32 mouse_no, const gem_config::g std::scoped_lock lock(handler.mutex); + // Make sure that the mouse handler is initialized + handler.Init(std::min(g_fxo->get().attribute.max_connect, CELL_GEM_MAX_NUM)); + if (mouse_no >= handler.GetMice().size()) { return; @@ -669,6 +675,9 @@ static void mouse_pos_to_gem_state(const u32 mouse_no, const gem_config::gem_con std::scoped_lock lock(handler.mutex); + // Make sure that the mouse handler is initialized + handler.Init(std::min(g_fxo->get().attribute.max_connect, CELL_GEM_MAX_NUM)); + if (mouse_no >= handler.GetMice().size()) { return; @@ -741,11 +750,8 @@ error_code cellGemCalibrate(u32 gem_num) return CELL_EBUSY; } - if (g_cfg.io.move == move_handler::fake || g_cfg.io.move == move_handler::mouse) - { - gem.controllers[gem_num].is_calibrating = true; - gem.controllers[gem_num].calibration_start_us = get_guest_system_time(); - } + gem.controllers[gem_num].is_calibrating = true; + gem.controllers[gem_num].calibration_start_us = get_guest_system_time(); return CELL_OK; } @@ -1507,14 +1513,6 @@ error_code cellGemInit(ppu_thread& ppu, vm::cptr attribute) gem.status_flags = 0; gem.attribute = *attribute; - if (g_cfg.io.move == move_handler::mouse) - { - // init mouse handler - auto& handler = g_fxo->get(); - - handler.Init(std::min(attribute->max_connect, CELL_GEM_MAX_NUM)); - } - for (int gem_num = 0; gem_num < CELL_GEM_MAX_NUM; gem_num++) { gem.reset_controller(gem_num); @@ -1544,16 +1542,13 @@ error_code cellGemInvalidateCalibration(s32 gem_num) return CELL_GEM_ERROR_INVALID_PARAMETER; } - if (g_cfg.io.move == move_handler::fake || g_cfg.io.move == move_handler::mouse) - { - gem.controllers[gem_num].calibrated_magnetometer = false; + gem.controllers[gem_num].calibrated_magnetometer = false; - // TODO: does this really stop an ongoing calibration ? - gem.controllers[gem_num].is_calibrating = false; - gem.controllers[gem_num].calibration_start_us = 0; + // TODO: does this really stop an ongoing calibration ? + gem.controllers[gem_num].is_calibrating = false; + gem.controllers[gem_num].calibration_start_us = 0; - // TODO: gem.status_flags (probably not changed) - } + // TODO: gem.status_flags (probably not changed) return CELL_OK; } diff --git a/rpcs3/Emu/system_config.h b/rpcs3/Emu/system_config.h index bc54b606ab..194f2b82dc 100644 --- a/rpcs3/Emu/system_config.h +++ b/rpcs3/Emu/system_config.h @@ -273,7 +273,7 @@ struct cfg_root : cfg::node cfg::_enum camera_type{ this, "Camera type", fake_camera_type::unknown }; cfg::_enum camera_flip_option{ this, "Camera flip", camera_flip::none, true }; cfg::string camera_id{ this, "Camera ID", "Default", true }; - cfg::_enum move{ this, "Move", move_handler::null }; + cfg::_enum move{ this, "Move", move_handler::null, true }; cfg::_enum buzz{ this, "Buzz emulated controller", buzz_handler::null }; cfg::_enum turntable{this, "Turntable emulated controller", turntable_handler::null}; cfg::_enum ghltar{this, "GHLtar emulated controller", ghltar_handler::null}; diff --git a/rpcs3/Input/basic_mouse_handler.cpp b/rpcs3/Input/basic_mouse_handler.cpp index 6bc4e3c248..ac1c061aa9 100644 --- a/rpcs3/Input/basic_mouse_handler.cpp +++ b/rpcs3/Input/basic_mouse_handler.cpp @@ -12,8 +12,15 @@ LOG_CHANNEL(input_log, "Input"); void basic_mouse_handler::Init(const u32 max_connect) { + if (m_info.max_connect > 0) + { + // Already initialized + return; + } + + m_mice.clear(); m_mice.emplace_back(Mouse()); - memset(&m_info, 0, sizeof(MouseInfo)); + m_info = {}; m_info.max_connect = max_connect; m_info.now_connect = std::min(::size32(m_mice), max_connect); m_info.info = input::g_mice_intercepted ? CELL_MOUSE_INFO_INTERCEPTED : 0; // Ownership of mouse data: 0=Application, 1=System diff --git a/rpcs3/main_application.cpp b/rpcs3/main_application.cpp index b5b0034873..490517cf3e 100644 --- a/rpcs3/main_application.cpp +++ b/rpcs3/main_application.cpp @@ -81,7 +81,9 @@ EmuCallbacks main_application::CreateCallbacks() ret->SetTargetWindow(m_game_window); } else + { g_fxo->init(Emu.DeserialManager()); + } break; }