Skip to content

Commit

Permalink
controllers_dialog: Add option to disable motion
Browse files Browse the repository at this point in the history
  • Loading branch information
nishinji committed Oct 18, 2023
1 parent ae3ea6a commit fb16fee
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions vita3k/config/include/config/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions vita3k/ctrl/include/ctrl/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions vita3k/ctrl/src/ctrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
}
Expand Down
11 changes: 10 additions & 1 deletion vita3k/gui/src/controllers_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions vita3k/modules/SceDriverUser/SceMotion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex> guard(emuenv.motion.mutex);
sensorState->accelerometer = get_acceleration(emuenv.motion);
sensorState->gyro = get_gyroscope(emuenv.motion);
Expand Down Expand Up @@ -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<std::mutex> guard(emuenv.motion.mutex);
motionState->timestamp = emuenv.motion.last_accel_timestamp;

Expand Down

0 comments on commit fb16fee

Please sign in to comment.