From 0285928b33a160b01079bdf96a603f695579fba9 Mon Sep 17 00:00:00 2001 From: nishinji Date: Sun, 24 Sep 2023 17:57:24 +0900 Subject: [PATCH] controllers_dialog: Add option to disable motion --- vita3k/config/include/config/state.h | 1 + vita3k/ctrl/include/ctrl/state.h | 1 + vita3k/ctrl/src/ctrl.cpp | 1 + vita3k/gui/src/controllers_dialog.cpp | 11 ++++++++++- vita3k/interface.cpp | 4 ++-- vita3k/modules/SceDriverUser/SceMotion.cpp | 4 ++-- 6 files changed, 17 insertions(+), 5 deletions(-) diff --git a/vita3k/config/include/config/state.h b/vita3k/config/include/config/state.h index d2ec206869..6dd3c20ca9 100644 --- a/vita3k/config/include/config/state.h +++ b/vita3k/config/include/config/state.h @@ -99,6 +99,7 @@ struct Config : YamlLoader { bool fullscreen = false; bool console = false; bool load_app_list = false; + bool disable_motion = false; /** * @brief Available HLE modules for advanced profiling using Tracy diff --git a/vita3k/ctrl/include/ctrl/state.h b/vita3k/ctrl/include/ctrl/state.h index 57162c948c..6f82e04d5e 100644 --- a/vita3k/ctrl/include/ctrl/state.h +++ b/vita3k/ctrl/include/ctrl/state.h @@ -60,6 +60,7 @@ struct CtrlState { ControllerList controllers; int controllers_num = 0; bool has_motion_support = false; + bool controllers_has_motion_support[SCE_CTRL_MAX_WIRELESS_NUM] = { false, false, false, false }; const char *controllers_name[SCE_CTRL_MAX_WIRELESS_NUM]; bool free_ports[SCE_CTRL_MAX_WIRELESS_NUM] = { true, true, true, true }; SceCtrlPadInputMode input_mode = SCE_CTRL_MODE_DIGITAL; diff --git a/vita3k/ctrl/src/ctrl.cpp b/vita3k/ctrl/src/ctrl.cpp index 3757e1e749..4ccfb8d4fd 100644 --- a/vita3k/ctrl/src/ctrl.cpp +++ b/vita3k/ctrl/src/ctrl.cpp @@ -96,6 +96,7 @@ void refresh_controllers(CtrlState &state, EmuEnvState &emuenv) { state.controllers.emplace(guid, new_controller); state.controllers_name[joystick_index] = SDL_GameControllerNameForIndex(joystick_index); + state.controllers_has_motion_support[joystick_index] = found_gyro && found_accel; state.controllers_num++; } } diff --git a/vita3k/gui/src/controllers_dialog.cpp b/vita3k/gui/src/controllers_dialog.cpp index 10fdb4affe..82b55de0fa 100644 --- a/vita3k/gui/src/controllers_dialog.cpp +++ b/vita3k/gui/src/controllers_dialog.cpp @@ -190,14 +190,17 @@ void draw_controllers_dialog(GuiState &gui, EmuEnvState &emuenv) { ImGui::Spacing(); ImGui::Separator(); ImGui::Spacing(); - if (ImGui::BeginTable("main", 2, ImGuiTableFlags_NoSavedSettings | ImGuiTableFlags_BordersInnerV)) { + if (ImGui::BeginTable("main", 3, ImGuiTableFlags_NoSavedSettings | ImGuiTableFlags_BordersInnerV)) { ImGui::TableSetupColumn("num"); ImGui::TableSetupColumn("name"); + ImGui::TableSetupColumn("motion"); ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::TextColored(GUI_COLOR_TEXT_TITLE, "%s", lang["num"].c_str()); ImGui::TableSetColumnIndex(1); ImGui::TextColored(GUI_COLOR_TEXT_TITLE, "%s", lang["name"].c_str()); + ImGui::TableSetColumnIndex(2); + ImGui::TextColored(GUI_COLOR_TEXT_TITLE, "%s", "Motion_Support"); ImGui::Spacing(); for (auto i = 0; i < ctrl.controllers_num; i++) { ImGui::TableNextRow(); @@ -343,6 +346,11 @@ void draw_controllers_dialog(GuiState &gui, EmuEnvState &emuenv) { } ImGui::End(); } + ImGui::TableSetColumnIndex(2); + if (ctrl.controllers_has_motion_support[i]) { + ImGui::Text("%s", "Yes"); + } else + ImGui::Text("%s", "No"); } ImGui::EndTable(); } @@ -351,6 +359,7 @@ void draw_controllers_dialog(GuiState &gui, EmuEnvState &emuenv) { if (emuenv.ctrl.has_motion_support) { ImGui::Spacing(); + ImGui::Checkbox("Disable Motion", &emuenv.cfg.disable_motion); ImGui::PushTextWrapPos(ImGui::GetWindowWidth() - (ImGui::GetStyle().WindowPadding.x * 2.f)); ImGui::TextColored(GUI_COLOR_TEXT_TITLE, "%s", lang["motion_support"].c_str()); ImGui::PopTextWrapPos(); diff --git a/vita3k/interface.cpp b/vita3k/interface.cpp index e0671e3ae1..c3491d381d 100644 --- a/vita3k/interface.cpp +++ b/vita3k/interface.cpp @@ -444,8 +444,8 @@ static ExitCode load_app_impl(SceUID &main_module_id, EmuEnvState &emuenv, const LOG_INFO("{} Controllers Connected", emuenv.ctrl.controllers_num); for (auto i = 0; i < emuenv.ctrl.controllers_num; i++) LOG_INFO("Controller {}: {}", i, emuenv.ctrl.controllers_name[i]); - if (emuenv.ctrl.has_motion_support) - LOG_INFO("Controller has motion support"); + if (emuenv.ctrl.has_motion_support) + LOG_INFO("Controller has motion support"); } LOG_INFO("modules mode: {}", config_modules_mode[emuenv.cfg.current_config.modules_mode][ModulesModeType::MODE]); if ((emuenv.cfg.current_config.modules_mode != ModulesMode::AUTOMATIC) && !emuenv.cfg.current_config.lle_modules.empty()) { diff --git a/vita3k/modules/SceDriverUser/SceMotion.cpp b/vita3k/modules/SceDriverUser/SceMotion.cpp index 8edc1727d5..aad2f51dc3 100644 --- a/vita3k/modules/SceDriverUser/SceMotion.cpp +++ b/vita3k/modules/SceDriverUser/SceMotion.cpp @@ -82,7 +82,7 @@ EXPORT(int, sceMotionGetSensorState, SceMotionSensorState *sensorState, int numR if (!sensorState) return RET_ERROR(SCE_MOTION_ERROR_NULL_PARAMETER); - if (emuenv.ctrl.has_motion_support) { + if (emuenv.ctrl.has_motion_support && !emuenv.cfg.disable_motion) { std::lock_guard guard(emuenv.motion.mutex); sensorState->accelerometer = get_acceleration(emuenv.motion); sensorState->gyro = get_gyroscope(emuenv.motion); @@ -115,7 +115,7 @@ EXPORT(int, sceMotionGetState, SceMotionState *motionState) { if (!motionState) return RET_ERROR(SCE_MOTION_ERROR_NULL_PARAMETER); - if (emuenv.ctrl.has_motion_support) { + if (emuenv.ctrl.has_motion_support && !emuenv.cfg.disable_motion) { std::lock_guard guard(emuenv.motion.mutex); motionState->timestamp = emuenv.motion.last_accel_timestamp;