From 896c9cccec94a193126f586ec1ff3a2e5f418257 Mon Sep 17 00:00:00 2001 From: Shanoah Alkire <arcum42@gmail.com> Date: Sat, 6 Oct 2018 22:54:47 -0700 Subject: [PATCH] onepad_legacy: reformat code. --- plugins/onepad_legacy/GamePad.cpp | 6 +- plugins/onepad_legacy/KeyStatus.cpp | 29 ++- .../Linux/GamepadConfiguration.cpp | 63 +++--- .../Linux/JoystickConfiguration.cpp | 88 ++++++--- plugins/onepad_legacy/Linux/dialog.cpp | 183 ++++++++++++------ plugins/onepad_legacy/Linux/dialog.h | 4 +- plugins/onepad_legacy/Linux/ini.cpp | 106 +++++----- plugins/onepad_legacy/Linux/linux.cpp | 55 +++--- plugins/onepad_legacy/Linux/opPanel.cpp | 24 ++- plugins/onepad_legacy/SDL/joystick.cpp | 123 +++++++----- plugins/onepad_legacy/controller.cpp | 2 +- plugins/onepad_legacy/controller.h | 11 +- plugins/onepad_legacy/keyboard.cpp | 97 ++++++---- plugins/onepad_legacy/onepad.cpp | 97 +++++----- plugins/onepad_legacy/state_management.cpp | 97 +++++++--- 15 files changed, 612 insertions(+), 373 deletions(-) diff --git a/plugins/onepad_legacy/GamePad.cpp b/plugins/onepad_legacy/GamePad.cpp index 3f27aadc1f..a17fee6be5 100644 --- a/plugins/onepad_legacy/GamePad.cpp +++ b/plugins/onepad_legacy/GamePad.cpp @@ -37,10 +37,10 @@ void GamePad::UpdateReleaseState() void GamePad::DoRumble(int type, int pad) { u32 id = conf->get_joyid(pad); - if (GamePadIdWithinBounds(id)) { + if (GamePadIdWithinBounds(id)) + { GamePad *gamePad = s_vgamePad[id]; - if (gamePad) - gamePad->Rumble(type, pad); + if (gamePad) gamePad->Rumble(type, pad); } } diff --git a/plugins/onepad_legacy/KeyStatus.cpp b/plugins/onepad_legacy/KeyStatus.cpp index ce9021c90e..e584fe0c85 100644 --- a/plugins/onepad_legacy/KeyStatus.cpp +++ b/plugins/onepad_legacy/KeyStatus.cpp @@ -23,13 +23,15 @@ void KeyStatus::Init() { - for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) { + for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) + { m_button[pad] = 0xFFFF; m_internal_button_kbd[pad] = 0xFFFF; m_internal_button_joy[pad] = 0xFFFF; m_state_acces[pad] = false; - for (int index = 0; index < MAX_KEYS; index++) { + for (int index = 0; index < MAX_KEYS; index++) + { m_button_pressure[pad][index] = 0xFF; m_internal_button_pressure[pad][index] = 0xFF; } @@ -51,13 +53,16 @@ void KeyStatus::Init() void KeyStatus::press(u32 pad, u32 index, s32 value) { - if (!IsAnalogKey(index)) { + if (!IsAnalogKey(index)) + { m_internal_button_pressure[pad][index] = value; if (m_state_acces[pad]) clear_bit(m_internal_button_kbd[pad], index); else clear_bit(m_internal_button_joy[pad], index); - } else { + } + else + { // clamp value if (value > MAX_ANALOG_VALUE) value = MAX_ANALOG_VALUE; @@ -79,12 +84,15 @@ void KeyStatus::press(u32 pad, u32 index, s32 value) void KeyStatus::release(u32 pad, u32 index) { - if (!IsAnalogKey(index)) { + if (!IsAnalogKey(index)) + { if (m_state_acces[pad]) set_bit(m_internal_button_kbd[pad], index); else set_bit(m_internal_button_joy[pad], index); - } else { + } + else + { analog_set(pad, index, m_analog_released_val); } } @@ -102,7 +110,8 @@ void KeyStatus::analog_set(u32 pad, u32 index, u8 value) else m_internal_analog_ref = &m_internal_analog_joy[pad]; - switch (index) { + switch (index) + { case PAD_R_LEFT: case PAD_R_RIGHT: m_internal_analog_ref->rx = value; @@ -130,7 +139,8 @@ void KeyStatus::analog_set(u32 pad, u32 index, u8 value) bool KeyStatus::analog_is_reversed(u32 pad, u32 index) { - switch (index) { + switch (index) + { case PAD_L_RIGHT: case PAD_L_LEFT: return (conf->pad_options[pad].reverse_lx); @@ -154,7 +164,8 @@ bool KeyStatus::analog_is_reversed(u32 pad, u32 index) u8 KeyStatus::get(u32 pad, u32 index) { - switch (index) { + switch (index) + { case PAD_R_LEFT: case PAD_R_RIGHT: return m_analog[pad].rx; diff --git a/plugins/onepad_legacy/Linux/GamepadConfiguration.cpp b/plugins/onepad_legacy/Linux/GamepadConfiguration.cpp index 556613a879..9323198312 100644 --- a/plugins/onepad_legacy/Linux/GamepadConfiguration.cpp +++ b/plugins/onepad_legacy/Linux/GamepadConfiguration.cpp @@ -19,14 +19,14 @@ #include "GamepadConfiguration.h" -// Construtor of GamepadConfiguration +// Constructor of GamepadConfiguration GamepadConfiguration::GamepadConfiguration(int pad, wxWindow *parent) : wxDialog( parent, // Parent wxID_ANY, // ID _T("Gamepad configuration"), // Title wxDefaultPosition, // Position - wxSize(400, 230), // Width + Lenght + wxSize(400, 230), // Width + Length // Style wxSYSTEM_MENU | wxCAPTION | @@ -40,27 +40,27 @@ GamepadConfiguration::GamepadConfiguration(int pad, wxWindow *parent) wxID_ANY, // ID wxDefaultPosition, // Prosition wxSize(300, 200) // Size - ); + ); m_cb_rumble = new wxCheckBox( m_pan_gamepad_config, // Parent wxID_ANY, // ID _T("&Enable rumble"), // Label wxPoint(20, 20) // Position - ); + ); m_cb_hack_sixaxis_usb = new wxCheckBox( m_pan_gamepad_config, // Parent wxID_ANY, // ID _T("&Hack: Sixaxis/DS3 plugged in USB"), // Label wxPoint(20, 40) // Position - ); + ); m_cb_hack_sixaxis_pressure = new wxCheckBox( m_pan_gamepad_config, // Parent wxID_ANY, // ID _T("&Hack: Sixaxis/DS3 pressure"), // Label wxPoint(20, 60) // Position - ); + ); wxString txt_rumble = wxT("Rumble intensity"); m_lbl_rumble_intensity = new wxStaticText( @@ -69,7 +69,7 @@ GamepadConfiguration::GamepadConfiguration(int pad, wxWindow *parent) txt_rumble, // Text which must be displayed wxPoint(20, 90), // Position wxDefaultSize // Size - ); + ); m_sl_rumble_intensity = new wxSlider( m_pan_gamepad_config, // Parent @@ -79,7 +79,7 @@ GamepadConfiguration::GamepadConfiguration(int pad, wxWindow *parent) 0x7FFF, // max value 0x7FFF wxPoint(150, 83), // Position wxSize(200, 30) // Size - ); + ); wxString txt_joystick = wxT("Joystick sensibility"); m_lbl_rumble_intensity = new wxStaticText( @@ -88,7 +88,7 @@ GamepadConfiguration::GamepadConfiguration(int pad, wxWindow *parent) txt_joystick, // Text which must be displayed wxPoint(20, 120), // Position wxDefaultSize // Size - ); + ); m_sl_joystick_sensibility = new wxSlider( m_pan_gamepad_config, // Parent @@ -98,7 +98,7 @@ GamepadConfiguration::GamepadConfiguration(int pad, wxWindow *parent) 100, // max value wxPoint(150, 113), // Position wxSize(200, 30) // Size - ); + ); m_bt_ok = new wxButton( m_pan_gamepad_config, // Parent @@ -106,7 +106,7 @@ GamepadConfiguration::GamepadConfiguration(int pad, wxWindow *parent) _T("&OK"), // Label wxPoint(250, 160), // Position wxSize(60, 25) // Size - ); + ); m_bt_cancel = new wxButton( m_pan_gamepad_config, // Parent @@ -114,7 +114,7 @@ GamepadConfiguration::GamepadConfiguration(int pad, wxWindow *parent) _T("&Cancel"), // Label wxPoint(320, 160), // Position wxSize(60, 25) // Size - ); + ); Bind(wxEVT_BUTTON, &GamepadConfiguration::OnButtonClicked, this); Bind(wxEVT_SCROLL_THUMBRELEASE, &GamepadConfiguration::OnSliderReleased, this); @@ -137,7 +137,8 @@ void GamepadConfiguration::InitGamepadConfiguration() * if the pad id is 1, you need at least 2 gamepad connected, * Prevent to use a none initialized value on s_vgamePad (core dump) */ - if (s_vgamePad.size() >= m_pad_id + 1) { + if (s_vgamePad.size() >= m_pad_id + 1) + { /* * Determine if the device can use rumble * Use TestForce with a very low strength (can't be felt) @@ -150,7 +151,9 @@ void GamepadConfiguration::InitGamepadConfiguration() // m_cb_rumble->Disable(); // disable the rumble checkbox // m_sl_rumble_intensity->Disable(); // disable the rumble intensity slider // } - } else { + } + else + { wxMessageBox(L"No gamepad detected."); m_sl_joystick_sensibility->Disable(); // disable the joystick sensibility slider m_cb_rumble->Disable(); // disable the rumble checkbox @@ -170,9 +173,12 @@ void GamepadConfiguration::OnButtonClicked(wxCommandEvent &event) // Affichage d'un message à chaque clic sur le bouton wxButton *bt_tmp = (wxButton *)event.GetEventObject(); // get the button object int bt_id = bt_tmp->GetId(); // get the real ID - if (bt_id == m_bt_ok->GetId()) { // If the button ID is equals to the Ok button ID + if (bt_id == m_bt_ok->GetId()) // If the button ID is equals to the Ok button ID + { Close(); // Close the window - } else if (bt_id == m_bt_cancel->GetId()) { // If the button ID is equals to the cancel button ID + } + else if (bt_id == m_bt_cancel->GetId()) // If the button ID is equals to the cancel button ID + { reset(); // reinitialize the value of each parameters Close(); // Close the window } @@ -187,7 +193,8 @@ void GamepadConfiguration::OnSliderReleased(wxCommandEvent &event) { wxSlider *sl_tmp = (wxSlider *)event.GetEventObject(); // get the slider object int sl_id = sl_tmp->GetId(); // slider id - if (sl_id == m_sl_rumble_intensity->GetId()) { // if this is the rumble intensity slider + if (sl_id == m_sl_rumble_intensity->GetId()) // if this is the rumble intensity slider + { u32 intensity = m_sl_rumble_intensity->GetValue(); // get the new value conf->set_ff_intensity(intensity); // and set the force feedback intensity value with it // get the rumble intensity @@ -204,7 +211,9 @@ void GamepadConfiguration::OnSliderReleased(wxCommandEvent &event) * 1 : maximum value of the intensity for the sdl rumble test */ s_vgamePad[m_pad_id]->TestForce(strength / 0x7FFF); - } else if (sl_id == m_sl_joystick_sensibility->GetId()) { + } + else if (sl_id == m_sl_joystick_sensibility->GetId()) + { u32 sensibility = m_sl_joystick_sensibility->GetValue(); // get the new value conf->set_sensibility(sensibility); // and set the joystick sensibility } @@ -217,17 +226,25 @@ void GamepadConfiguration::OnCheckboxChange(wxCommandEvent &event) { wxCheckBox *cb_tmp = (wxCheckBox *)event.GetEventObject(); // get the slider object int cb_id = cb_tmp->GetId(); - if (cb_id == m_cb_rumble->GetId()) { + if (cb_id == m_cb_rumble->GetId()) + { conf->pad_options[m_pad_id].forcefeedback = (m_cb_rumble->GetValue()) ? (u32)1 : (u32)0; - if (m_cb_rumble->GetValue()) { + if (m_cb_rumble->GetValue()) + { s_vgamePad[m_pad_id]->TestForce(); m_sl_rumble_intensity->Enable(); - } else { + } + else + { m_sl_rumble_intensity->Disable(); } - } else if (cb_id == m_cb_hack_sixaxis_usb->GetId()) { + } + else if (cb_id == m_cb_hack_sixaxis_usb->GetId()) + { conf->pad_options[m_pad_id].sixaxis_usb = (m_cb_hack_sixaxis_usb->GetValue()) ? (u32)1 : (u32)0; - } else if (cb_id == m_cb_hack_sixaxis_pressure->GetId()) { + } + else if (cb_id == m_cb_hack_sixaxis_pressure->GetId()) + { conf->pad_options[m_pad_id].sixaxis_pressure = (m_cb_hack_sixaxis_pressure->GetValue()) ? (u32)1 : (u32)0; } } diff --git a/plugins/onepad_legacy/Linux/JoystickConfiguration.cpp b/plugins/onepad_legacy/Linux/JoystickConfiguration.cpp index 3a39047893..5935b530a3 100644 --- a/plugins/onepad_legacy/Linux/JoystickConfiguration.cpp +++ b/plugins/onepad_legacy/Linux/JoystickConfiguration.cpp @@ -26,7 +26,7 @@ JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow *paren wxID_ANY, // ID _T("Gamepad configuration"), // Title wxDefaultPosition, // Position - wxSize(400, 200), // Width + Lenght + wxSize(400, 200), // Width + Length // Style wxSYSTEM_MENU | wxCAPTION | @@ -47,54 +47,57 @@ JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow *paren wxID_ANY, // ID wxDefaultPosition, // Prosition wxSize(300, 200) // Size - ); + ); - if (m_isForLeftJoystick) { + if (m_isForLeftJoystick) + { m_cb_reverse_Lx = new wxCheckBox( m_pan_joystick_config, // Parent wxID_ANY, // ID _T("Reverse Lx"), // Label wxPoint(20, 20) // Position - ); + ); m_cb_reverse_Ly = new wxCheckBox( m_pan_joystick_config, // Parent wxID_ANY, // ID _T("Reverse Ly"), // Label wxPoint(20, 40) // Position - ); + ); m_cb_mouse_Ljoy = new wxCheckBox( m_pan_joystick_config, // Parent wxID_ANY, // ID _T("Use mouse for left analog joystick"), // Label wxPoint(20, 60) // Position - ); + ); m_cb_reverse_Rx = nullptr; m_cb_reverse_Ry = nullptr; m_cb_mouse_Rjoy = nullptr; - } else { + } + else + { m_cb_reverse_Rx = new wxCheckBox( m_pan_joystick_config, // Parent wxID_ANY, // ID _T("Reverse Rx"), // Label wxPoint(20, 20) // Position - ); + ); m_cb_reverse_Ry = new wxCheckBox( m_pan_joystick_config, // Parent wxID_ANY, // ID _T("Reverse Ry"), // Label wxPoint(20, 40) // Position - ); + ); m_cb_mouse_Rjoy = new wxCheckBox( m_pan_joystick_config, // Parent wxID_ANY, // ID _T("Use mouse for right analog joystick"), // Label wxPoint(20, 60) // Position - ); + ); m_cb_reverse_Lx = nullptr; m_cb_reverse_Ly = nullptr; @@ -107,7 +110,7 @@ JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow *paren _T("&OK"), // Label wxPoint(250, 130), // Position wxSize(60, 25) // Size - ); + ); m_bt_cancel = new wxButton( m_pan_joystick_config, // Parent @@ -115,7 +118,7 @@ JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow *paren _T("&Cancel"), // Label wxPoint(320, 130), // Position wxSize(60, 25) // Size - ); + ); Bind(wxEVT_BUTTON, &JoystickConfiguration::OnButtonClicked, this); Bind(wxEVT_CHECKBOX, &JoystickConfiguration::OnCheckboxChange, this); @@ -134,13 +137,17 @@ void JoystickConfiguration::InitJoystickConfiguration() * if the pad id is 1, you need at least 2 gamepad connected, * Prevent to use a none initialized value on s_vgamePad (core dump) */ - if (s_vgamePad.size() < m_pad_id + 1) { + if (s_vgamePad.size() < m_pad_id + 1) + { wxMessageBox(L"No gamepad detected."); // disable all checkbox - if (m_isForLeftJoystick) { + if (m_isForLeftJoystick) + { m_cb_reverse_Lx->Disable(); m_cb_reverse_Ly->Disable(); - } else { + } + else + { m_cb_reverse_Rx->Disable(); m_cb_reverse_Ry->Disable(); } @@ -159,9 +166,12 @@ void JoystickConfiguration::OnButtonClicked(wxCommandEvent &event) // Affichage d'un message à chaque clic sur le bouton wxButton *bt_tmp = (wxButton *)event.GetEventObject(); // get the button object int bt_id = bt_tmp->GetId(); // get the real ID - if (bt_id == m_bt_ok->GetId()) { // If the button ID is equals to the Ok button ID + if (bt_id == m_bt_ok->GetId()) // If the button ID is equals to the Ok button ID + { Close(); // Close the window - } else if (bt_id == m_bt_cancel->GetId()) { // If the button ID is equals to the cancel button ID + } + else if (bt_id == m_bt_cancel->GetId()) // If the button ID is equals to the cancel button ID + { reset(); // reinitialize the value of each parameters Close(); // Close the window } @@ -175,25 +185,38 @@ void JoystickConfiguration::OnCheckboxChange(wxCommandEvent &event) wxCheckBox *cb_tmp = (wxCheckBox *)event.GetEventObject(); // get the slider object int cb_id = cb_tmp->GetId(); bool val; - if (m_isForLeftJoystick) { - if (cb_id == m_cb_reverse_Ly->GetId()) { + if (m_isForLeftJoystick) + { + if (cb_id == m_cb_reverse_Ly->GetId()) + { val = m_cb_reverse_Ly->GetValue(); conf->pad_options[m_pad_id].reverse_ly = val; - } else if (cb_id == m_cb_reverse_Lx->GetId()) { + } + else if (cb_id == m_cb_reverse_Lx->GetId()) + { val = m_cb_reverse_Lx->GetValue(); conf->pad_options[m_pad_id].reverse_lx = val; - } else if (cb_id == m_cb_mouse_Ljoy->GetId()) { + } + else if (cb_id == m_cb_mouse_Ljoy->GetId()) + { val = m_cb_mouse_Ljoy->GetValue(); conf->pad_options[m_pad_id].mouse_l = val; } - } else { - if (cb_id == m_cb_reverse_Ry->GetId()) { + } + else + { + if (cb_id == m_cb_reverse_Ry->GetId()) + { val = m_cb_reverse_Ry->GetValue(); conf->pad_options[m_pad_id].reverse_ry = val; - } else if (cb_id == m_cb_reverse_Rx->GetId()) { + } + else if (cb_id == m_cb_reverse_Rx->GetId()) + { val = m_cb_reverse_Rx->GetValue(); conf->pad_options[m_pad_id].reverse_rx = val; - } else if (cb_id == m_cb_mouse_Rjoy->GetId()) { + } + else if (cb_id == m_cb_mouse_Rjoy->GetId()) + { val = m_cb_mouse_Rjoy->GetValue(); conf->pad_options[m_pad_id].mouse_r = val; } @@ -207,11 +230,14 @@ void JoystickConfiguration::OnCheckboxChange(wxCommandEvent &event) // Reset checkbox and slider values void JoystickConfiguration::reset() { - if (m_isForLeftJoystick) { + if (m_isForLeftJoystick) + { m_cb_reverse_Lx->SetValue(m_init_reverse_Lx); m_cb_reverse_Ly->SetValue(m_init_reverse_Ly); m_cb_mouse_Ljoy->SetValue(m_init_mouse_Ljoy); - } else { + } + else + { m_cb_reverse_Rx->SetValue(m_init_reverse_Rx); m_cb_reverse_Ry->SetValue(m_init_reverse_Ry); m_cb_mouse_Rjoy->SetValue(m_init_mouse_Rjoy); @@ -222,7 +248,9 @@ void JoystickConfiguration::reset() void JoystickConfiguration::repopulate() { bool val; - if (m_isForLeftJoystick) { + + if (m_isForLeftJoystick) + { val = conf->pad_options[m_pad_id].reverse_lx; m_init_reverse_Lx = val; m_cb_reverse_Lx->SetValue(val); @@ -234,7 +262,9 @@ void JoystickConfiguration::repopulate() val = conf->pad_options[m_pad_id].mouse_l; m_init_mouse_Ljoy = val; m_cb_mouse_Ljoy->SetValue(val); - } else { + } + else + { val = conf->pad_options[m_pad_id].reverse_rx; m_init_reverse_Rx = val; m_cb_reverse_Rx->SetValue(val); diff --git a/plugins/onepad_legacy/Linux/dialog.cpp b/plugins/onepad_legacy/Linux/dialog.cpp index ecb3482cd8..75437c9e88 100644 --- a/plugins/onepad_legacy/Linux/dialog.cpp +++ b/plugins/onepad_legacy/Linux/dialog.cpp @@ -25,7 +25,7 @@ Dialog::Dialog() wxID_ANY, // ID _T("OnePad configuration"), // Title wxDefaultPosition, // Position - wxSize(DEFAULT_WIDTH, DEFAULT_HEIGHT), // Width + Lenght + wxSize(DEFAULT_WIDTH, DEFAULT_HEIGHT), // Width + Length // Style wxSYSTEM_MENU | wxCAPTION | @@ -40,7 +40,7 @@ Dialog::Dialog() * padding[ButtonID][2] : x position * padding[ButtonID][3] : y position */ - int padding[BUTTONS_LENGHT][4]; + int padding[BUTTONS_LENGTH][4]; // L1 padding[PAD_L1][0] = 218; // Width @@ -236,7 +236,8 @@ Dialog::Dialog() // create a new Notebook m_tab_gamepad = new wxNotebook(this, wxID_ANY); - for (int i = 0; i < GAMEPAD_NUMBER; ++i) { + for (int i = 0; i < GAMEPAD_NUMBER; ++i) + { // Tabs panels m_pan_tabs[i] = new opPanel( m_tab_gamepad, @@ -252,9 +253,10 @@ Dialog::Dialog() m_tab_gamepad->AddPage( m_pan_tabs[i], // Parent wxString(sstm.str().c_str(), wxConvUTF8) // Title - ); + ); - for (int j = 0; j < BUTTONS_LENGHT; ++j) { + for (int j = 0; j < BUTTONS_LENGTH; ++j) + { // Gamepad buttons m_bt_gamepad[i][j] = new wxButton( m_pan_tabs[i], // Parent @@ -262,7 +264,7 @@ Dialog::Dialog() _T("Undefined"), // Label wxPoint(padding[j][2], padding[j][3]), // Position wxSize(padding[j][0], padding[j][1]) // Size - ); + ); } // Redefine others gui buttons label m_bt_gamepad[i][JoyL_config]->SetLabel(_T("&Left Joystick Config")); @@ -283,8 +285,10 @@ Dialog::Dialog() Bind(wxEVT_TIMER, &Dialog::JoystickEvent, this); m_time_update_gui.Start(UPDATE_TIME, wxTIMER_CONTINUOUS); - for (int i = 0; i < GAMEPAD_NUMBER; ++i) { - for (int j = 0; j < NB_IMG; ++j) { + for (int i = 0; i < GAMEPAD_NUMBER; ++i) + { + for (int j = 0; j < NB_IMG; ++j) + { m_pressed[i][j] = false; } } @@ -304,32 +308,44 @@ void Dialog::InitDialog() void Dialog::OnButtonClicked(wxCommandEvent &event) { // Affichage d'un message à chaque clic sur le bouton + // Per Google Translate: Display a message each time the button is clicked. wxButton *bt_tmp = (wxButton *)event.GetEventObject(); // get the button object int bt_id = bt_tmp->GetId() - wxID_HIGHEST - 1; // get the real ID int gamepad_id = m_tab_gamepad->GetSelection(); // get the tab ID (equivalent to the gamepad id) - if (bt_id >= 0 && bt_id <= PAD_R_LEFT) { // if the button ID is a gamepad button + if (bt_id >= 0 && bt_id <= PAD_R_LEFT) // if the button ID is a gamepad button + { bt_tmp->Disable(); // switch the button state to "Disable" config_key(gamepad_id, bt_id); - bt_tmp->Enable(); // switch the button state to "Enable" - } else if (bt_id == Gamepad_config) { // If the button ID is equals to the Gamepad_config button ID + bt_tmp->Enable(); // switch the button state to "Enable" + } + else if (bt_id == Gamepad_config) // If the button ID is equals to the Gamepad_config button ID + { GamepadConfiguration gamepad_config(gamepad_id, this); gamepad_config.InitGamepadConfiguration(); gamepad_config.ShowModal(); - } else if (bt_id == JoyL_config) { // If the button ID is equals to the JoyL_config button ID + } + else if (bt_id == JoyL_config) // If the button ID is equals to the JoyL_config button ID + { JoystickConfiguration joystick_config(gamepad_id, true, this); joystick_config.InitJoystickConfiguration(); joystick_config.ShowModal(); - } else if (bt_id == JoyR_config) { // If the button ID is equals to the JoyR_config button ID + } + else if (bt_id == JoyR_config) // If the button ID is equals to the JoyR_config button ID + { JoystickConfiguration joystick_config(gamepad_id, false, this); joystick_config.InitJoystickConfiguration(); joystick_config.ShowModal(); - } else if (bt_id == Set_all) { // If the button ID is equals to the Set_all button ID - for (int i = 0; i < MAX_KEYS; ++i) { + } + else if (bt_id == Set_all) // If the button ID is equals to the Set_all button ID + { + for (int i = 0; i < MAX_KEYS; ++i) + { bt_tmp = m_bt_gamepad[gamepad_id][i]; - switch (i) { + switch (i) + { case PAD_L_UP: // Left joystick (Up) ↑ m_pan_tabs[gamepad_id]->ShowImg(img_l_arrow_up); break; @@ -361,7 +377,8 @@ void Dialog::OnButtonClicked(wxCommandEvent &event) m_pan_tabs[gamepad_id]->Refresh(); m_pan_tabs[gamepad_id]->Update(); config_key(gamepad_id, i); - switch (i) { + switch (i) + { case PAD_L_UP: // Left joystick (Up) ↑ m_pan_tabs[gamepad_id]->HideImg(img_l_arrow_up); break; @@ -394,13 +411,19 @@ void Dialog::OnButtonClicked(wxCommandEvent &event) m_pan_tabs[gamepad_id]->Update(); usleep(500000); // give enough time to the user to release the button } - } else if (bt_id == Ok) { // If the button ID is equals to the Ok button ID - SaveConfig(); // Save the configuration - Close(); // Close the window - } else if (bt_id == Apply) { // If the button ID is equals to the Apply button ID - SaveConfig(); // Save the configuration - } else if (bt_id == Cancel) { // If the button ID is equals to the cancel button ID - Close(); // Close the window + } + else if (bt_id == Ok) // If the button ID is equals to the Ok button ID + { + SaveConfig(); // Save the configuration + Close(); // Close the window + } + else if (bt_id == Apply) // If the button ID is equals to the Apply button ID + { + SaveConfig(); // Save the configuration + } + else if (bt_id == Cancel) // If the button ID is equals to the cancel button ID + { + Close(); // Close the window } } @@ -413,32 +436,44 @@ void Dialog::JoystickEvent(wxTimerEvent &event) std::map<u32, int>::iterator it2; SDL_JoystickEventState(SDL_ENABLE); SDL_Event events; - while (SDL_PollEvent(&events)) { - switch (events.type) { + while (SDL_PollEvent(&events)) + { + switch (events.type) + { case SDL_KEYDOWN: case SDL_KEYUP: break; case SDL_JOYAXISMOTION: - if (events.jaxis.which < GAMEPAD_NUMBER) { + if (events.jaxis.which < GAMEPAD_NUMBER) + { key = axis_to_key(false, (events.jaxis.value < 0), events.jaxis.axis); it = m_map_images[events.jaxis.which].find(key); - if (it != m_map_images[events.jaxis.which].end()) { + if (it != m_map_images[events.jaxis.which].end()) + { map = m_map_images[events.jaxis.which][key]; - if (events.jaxis.value == 0) { + if (events.jaxis.value == 0) + { if (map >= PAD_L_UP && map <= PAD_L_LEFT) m_pan_tabs[events.jaxis.which]->HideImg(img_left_cursor); else if (map >= PAD_R_UP && map <= PAD_R_LEFT) m_pan_tabs[events.jaxis.which]->HideImg(img_right_cursor); else if (map < PAD_L_UP) m_pan_tabs[events.jaxis.which]->HideImg(map); - } else { - if (map >= PAD_L_UP && map <= PAD_L_LEFT) { + } + else + { + if (map >= PAD_L_UP && map <= PAD_L_LEFT) + { m_pan_tabs[events.jaxis.which]->MoveJoystick(events.jaxis.axis, events.jaxis.value); m_pan_tabs[events.jaxis.which]->ShowImg(img_left_cursor); - } else if (map >= PAD_R_UP && map <= PAD_R_LEFT) { + } + else if (map >= PAD_R_UP && map <= PAD_R_LEFT) + { m_pan_tabs[events.jaxis.which]->MoveJoystick(events.jaxis.axis, events.jaxis.value); m_pan_tabs[events.jaxis.which]->ShowImg(img_right_cursor); - } else if (map < PAD_L_UP) { // if this is not a joystick + } + else if (map < PAD_L_UP) // if this is not a joystick + { m_pan_tabs[events.jaxis.which]->ShowImg(map); } } @@ -447,9 +482,11 @@ void Dialog::JoystickEvent(wxTimerEvent &event) // Hack Dualshock 4 (L2, R2) key = axis_to_key(false, (events.jaxis.value > 0), events.jaxis.axis); it2 = m_map_images[events.jaxis.which].find(key); - if (it2 != m_map_images[events.jaxis.which].end()) { + if (it2 != m_map_images[events.jaxis.which].end()) + { map = m_map_images[events.jaxis.which][key]; - if (map < PAD_L_UP) { // if this is not a joystick + if (map < PAD_L_UP) // if this is not a joystick + { m_pan_tabs[events.jaxis.which]->HideImg(map); } break; @@ -457,53 +494,63 @@ void Dialog::JoystickEvent(wxTimerEvent &event) } break; case SDL_JOYBUTTONDOWN: - if (events.jbutton.which < GAMEPAD_NUMBER) { + if (events.jbutton.which < GAMEPAD_NUMBER) + { key = button_to_key(events.jbutton.button); it = m_map_images[events.jbutton.which].find(key); - if (it != m_map_images[events.jbutton.which].end()) { + if (it != m_map_images[events.jbutton.which].end()) + { map = m_map_images[events.jbutton.which][key]; m_pan_tabs[events.jbutton.which]->ShowImg(map); } } break; case SDL_JOYBUTTONUP: - if (events.jbutton.which < GAMEPAD_NUMBER) { + if (events.jbutton.which < GAMEPAD_NUMBER) + { key = button_to_key(events.jbutton.button); it = m_map_images[events.jbutton.which].find(key); - if (it != m_map_images[events.jbutton.which].end()) { + if (it != m_map_images[events.jbutton.which].end()) + { map = m_map_images[events.jbutton.which][key]; m_pan_tabs[events.jbutton.which]->HideImg(map); } } break; case SDL_JOYHATMOTION: - if (events.jhat.which < GAMEPAD_NUMBER) { - switch (events.jhat.value) { + if (events.jhat.which < GAMEPAD_NUMBER) + { + switch (events.jhat.value) + { case SDL_HAT_UP: key = hat_to_key(events.jhat.value, events.jhat.hat); it = m_map_images[events.jhat.which].find(key); - if (it != m_map_images[events.jhat.which].end()) { + if (it != m_map_images[events.jhat.which].end()) + { m_pan_tabs[events.jhat.which]->ShowImg(img_dp_up); } break; case SDL_HAT_DOWN: key = hat_to_key(events.jhat.value, events.jhat.hat); it = m_map_images[events.jhat.which].find(key); - if (it != m_map_images[events.jhat.which].end()) { + if (it != m_map_images[events.jhat.which].end()) + { m_pan_tabs[events.jhat.which]->ShowImg(img_dp_bottom); } break; case SDL_HAT_RIGHT: key = hat_to_key(events.jhat.value, events.jhat.hat); it = m_map_images[events.jhat.which].find(key); - if (it != m_map_images[events.jhat.which].end()) { + if (it != m_map_images[events.jhat.which].end()) + { m_pan_tabs[events.jhat.which]->ShowImg(img_dp_right); } break; case SDL_HAT_LEFT: key = hat_to_key(events.jhat.value, events.jhat.hat); it = m_map_images[events.jhat.which].find(key); - if (it != m_map_images[events.jhat.which].end()) { + if (it != m_map_images[events.jhat.which].end()) + { m_pan_tabs[events.jhat.which]->ShowImg(img_dp_left); } break; @@ -533,34 +580,45 @@ void Dialog::config_key(int pad, int key) // I don't have any guarantee that not-yet-pressed state is egual to released state GamePad::UpdateReleaseState(); - while (!captured) { + while (!captured) + { std::vector<GamePad *>::iterator itjoy; - if (PollX11KeyboardMouseEvent(key_pressed)) { + if (PollX11KeyboardMouseEvent(key_pressed)) + { // special case for keyboard/mouse to handle multiple keys // Note: key_pressed == 0 when ESC is hit to abort the capture - if (key_pressed > 0) { + if (key_pressed > 0) + { clear_key(pad, key); - set_keyboad_key(pad, key_pressed, key); + set_keyboard_key(pad, key_pressed, key); m_simulatedKeys[pad][key] = key_pressed; m_map_images[pad][key_pressed] = key; } captured = true; - } else { + } + else + { GamePad::UpdateGamePadState(); itjoy = s_vgamePad.begin(); - while ((itjoy != s_vgamePad.end()) && (!captured)) { - if ((*itjoy)->PollButtons(key_pressed)) { + while ((itjoy != s_vgamePad.end()) && (!captured)) + { + if ((*itjoy)->PollButtons(key_pressed)) + { clear_key(pad, key); set_key(pad, key, key_pressed); m_map_images[pad][key_pressed] = key; captured = true; - } else if ((*itjoy)->PollAxes(key_pressed)) { + } + else if ((*itjoy)->PollAxes(key_pressed)) + { clear_key(pad, key); set_key(pad, key, key_pressed); m_map_images[pad][key_pressed] = key; captured = true; - } else if ((*itjoy)->PollHats(key_pressed)) { + } + else if ((*itjoy)->PollHats(key_pressed)) + { clear_key(pad, key); set_key(pad, key, key_pressed); m_map_images[pad][key_pressed] = key; @@ -590,7 +648,8 @@ void Dialog::clear_key(int pad, int key) int val = get_key(pad, key); std::map<u32, int>::iterator it2; it2 = m_map_images[pad].find(val); - if (it2 != m_map_images[pad].end()) { + if (it2 != m_map_images[pad].end()) + { m_map_images[pad].erase(it2); } @@ -604,9 +663,12 @@ void Dialog::clear_key(int pad, int key) // Set button values void Dialog::repopulate() { - for (int gamepad_id = 0; gamepad_id < GAMEPAD_NUMBER; ++gamepad_id) { - for (int key = 0; key < MAX_KEYS; key++) { - if (get_key(gamepad_id, key) != 0) { + for (int gamepad_id = 0; gamepad_id < GAMEPAD_NUMBER; ++gamepad_id) + { + for (int key = 0; key < MAX_KEYS; key++) + { + if (get_key(gamepad_id, key) != 0) + { m_bt_gamepad[gamepad_id][key]->SetLabel( KeyName(gamepad_id, key).c_str()); @@ -615,9 +677,10 @@ void Dialog::repopulate() } // keyboard/mouse key - std::map<u32, u32>::iterator it; + std::map<u32, u32>::iterator it; for (it = conf->keysym_map[gamepad_id].begin(); - it != conf->keysym_map[gamepad_id].end(); ++it) { + it != conf->keysym_map[gamepad_id].end(); ++it) + { int keysym = it->first; int key = it->second; diff --git a/plugins/onepad_legacy/Linux/dialog.h b/plugins/onepad_legacy/Linux/dialog.h index ee10a80b86..3e4a3593f6 100644 --- a/plugins/onepad_legacy/Linux/dialog.h +++ b/plugins/onepad_legacy/Linux/dialog.h @@ -58,7 +58,7 @@ enum gui_buttons { Cancel // Exit without apply modificatons }; -#define BUTTONS_LENGHT 32 // numbers of buttons on the gamepad +#define BUTTONS_LENGTH 32 // numbers of buttons on the gamepad #define UPDATE_TIME 5 #define DEFAULT_WIDTH 1000 #define DEFAULT_HEIGHT 740 @@ -70,7 +70,7 @@ class Dialog : public wxDialog // Notebooks wxNotebook *m_tab_gamepad; // Joysticks Tabs // Buttons - wxButton *m_bt_gamepad[GAMEPAD_NUMBER][BUTTONS_LENGHT]; // Joystick button use to modify the button mapping + wxButton *m_bt_gamepad[GAMEPAD_NUMBER][BUTTONS_LENGTH]; // Joystick button use to modify the button mapping // Contain all simulated key u32 m_simulatedKeys[GAMEPAD_NUMBER][MAX_KEYS]; // Timer diff --git a/plugins/onepad_legacy/Linux/ini.cpp b/plugins/onepad_legacy/Linux/ini.cpp index 23d0546169..c7fcd96419 100644 --- a/plugins/onepad_legacy/Linux/ini.cpp +++ b/plugins/onepad_legacy/Linux/ini.cpp @@ -33,10 +33,13 @@ std::string KeyName(int pad, int key, int keysym) std::string tmp; tmp.resize(28); - if (keysym) { - if (keysym < 10) { + if (keysym) + { + if (keysym < 10) + { // mouse - switch (keysym) { + switch (keysym) + { case 1: sprintf(&tmp[0], "Mouse Left"); break; @@ -49,31 +52,40 @@ std::string KeyName(int pad, int key, int keysym) default: // Use only number for extra button sprintf(&tmp[0], "Mouse %d", keysym); } - } else { + } + else + { // keyboard char *pstr = XKeysymToString(keysym); if (pstr != NULL) tmp = pstr; } - } else { + } + else + { // joystick KeyType k = type_of_joykey(pad, key); - switch (k) { - case PAD_JOYBUTTONS: { + switch (k) + { + case PAD_JOYBUTTONS: + { int button = key_to_button(pad, key); sprintf(&tmp[0], "JBut %d", button); break; } - case PAD_AXIS: { + case PAD_AXIS: + { if (key_to_axis_type(pad, key)) sprintf(&tmp[0], "JAxis %d Full", key_to_axis(pad, key)); else sprintf(&tmp[0], "JAxis %d Half%s", key_to_axis(pad, key), key_to_axis_sign(pad, key) ? "-" : "+"); break; } - case PAD_HAT: { + case PAD_HAT: + { int axis = key_to_axis(pad, key); - switch (key_to_hat_dir(pad, key)) { + switch (key_to_hat_dir(pad, key)) + { case HAT_UP: sprintf(&tmp[0], "JPOVU-%d", axis); break; @@ -102,20 +114,20 @@ std::string KeyName(int pad, int key, int keysym) void DefaultKeyboardValues() { - set_keyboad_key(0, XK_a, PAD_L2); - set_keyboad_key(0, XK_semicolon, PAD_R2); - set_keyboad_key(0, XK_w, PAD_L1); - set_keyboad_key(0, XK_p, PAD_R1); - set_keyboad_key(0, XK_i, PAD_TRIANGLE); - set_keyboad_key(0, XK_l, PAD_CIRCLE); - set_keyboad_key(0, XK_k, PAD_CROSS); - set_keyboad_key(0, XK_j, PAD_SQUARE); - set_keyboad_key(0, XK_v, PAD_SELECT); - set_keyboad_key(0, XK_n, PAD_START); - set_keyboad_key(0, XK_e, PAD_UP); - set_keyboad_key(0, XK_f, PAD_RIGHT); - set_keyboad_key(0, XK_d, PAD_DOWN); - set_keyboad_key(0, XK_s, PAD_LEFT); + set_keyboard_key(0, XK_a, PAD_L2); + set_keyboard_key(0, XK_semicolon, PAD_R2); + set_keyboard_key(0, XK_w, PAD_L1); + set_keyboard_key(0, XK_p, PAD_R1); + set_keyboard_key(0, XK_i, PAD_TRIANGLE); + set_keyboard_key(0, XK_l, PAD_CIRCLE); + set_keyboard_key(0, XK_k, PAD_CROSS); + set_keyboard_key(0, XK_j, PAD_SQUARE); + set_keyboard_key(0, XK_v, PAD_SELECT); + set_keyboard_key(0, XK_n, PAD_START); + set_keyboard_key(0, XK_e, PAD_UP); + set_keyboard_key(0, XK_f, PAD_RIGHT); + set_keyboard_key(0, XK_d, PAD_DOWN); + set_keyboard_key(0, XK_s, PAD_LEFT); } void SaveConfig() @@ -124,7 +136,8 @@ void SaveConfig() const std::string iniFile(s_strIniPath + "OnePAD.ini"); f = fopen(iniFile.c_str(), "w"); - if (f == NULL) { + if (f == NULL) + { printf("OnePAD: failed to save ini %s\n", iniFile.c_str()); return; } @@ -135,8 +148,10 @@ void SaveConfig() fprintf(f, "joy_pad_map = %d\n", conf->joyid_map); fprintf(f, "ff_intensity = %d\n", conf->get_ff_intensity()); - for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) { - for (int key = 0; key < MAX_KEYS; key++) { + for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) + { + for (int key = 0; key < MAX_KEYS; key++) + { fprintf(f, "[%d][%d] = 0x%x\n", pad, key, get_key(pad, key)); } } @@ -155,40 +170,42 @@ void LoadConfig() char str[256]; bool have_user_setting = false; - if (!conf) - conf = new PADconf; + if (!conf) conf = new PADconf; conf->init(); const std::string iniFile(s_strIniPath + "OnePAD.ini"); f = fopen(iniFile.c_str(), "r"); - if (f == NULL) { + if (f == NULL) + { printf("OnePAD: failed to load ini %s\n", iniFile.c_str()); SaveConfig(); //save and return return; } u32 value; - if (fscanf(f, "log = %u\n", &value) == 0) - goto error; + + if (fscanf(f, "log = %u\n", &value) == 0) goto error; conf->log = value; - if (fscanf(f, "options = %u\n", &value) == 0) - goto error; + + if (fscanf(f, "options = %u\n", &value) == 0) goto error; conf->packed_options = value; - if (fscanf(f, "mouse_sensibility = %u\n", &value) == 0) - goto error; + + if (fscanf(f, "mouse_sensibility = %u\n", &value) == 0) goto error; conf->set_sensibility(value); - if (fscanf(f, "joy_pad_map = %u\n", &value) == 0) - goto error; + + if (fscanf(f, "joy_pad_map = %u\n", &value) == 0) goto error; // Value is now hardcoded in controller.h avoid to reload a bad // value from an old ini file. //conf->joyid_map = value; - if (fscanf(f, "ff_intensity = %u\n", &value) == 0) - goto error; + + if (fscanf(f, "ff_intensity = %u\n", &value) == 0) goto error; conf->set_ff_intensity(value); - for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) { - for (int key = 0; key < MAX_KEYS; key++) { + for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) + { + for (int key = 0; key < MAX_KEYS; key++) + { sprintf(str, "[%d][%d] = 0x%%x\n", pad, key); u32 temp = 0; @@ -203,8 +220,9 @@ void LoadConfig() u32 pad; u32 keysym; u32 index; - while (fscanf(f, "PAD %u:KEYSYM 0x%x = %u\n", &pad, &keysym, &index) != EOF) { - set_keyboad_key(pad & 1, keysym, index); + while (fscanf(f, "PAD %u:KEYSYM 0x%x = %u\n", &pad, &keysym, &index) != EOF) + { + set_keyboard_key(pad & 1, keysym, index); if (pad == 0) have_user_setting = true; } diff --git a/plugins/onepad_legacy/Linux/linux.cpp b/plugins/onepad_legacy/Linux/linux.cpp index 0e7bbf4416..311de1195e 100644 --- a/plugins/onepad_legacy/Linux/linux.cpp +++ b/plugins/onepad_legacy/Linux/linux.cpp @@ -53,14 +53,12 @@ void SysMessage(const char *fmt, ...) gtk_widget_destroy(dialog); } -EXPORT_C_(void) -PADabout() +EXPORT_C_(void) PADabout() { SysMessage("OnePad is a rewrite of Zerofrog's ZeroPad, done by arcum42."); } -EXPORT_C_(s32) -PADtest() +EXPORT_C_(s32) PADtest() { return 0; } @@ -81,7 +79,8 @@ void _PADclose() std::vector<GamePad *>::iterator it = s_vgamePad.begin(); // Delete everything in the vector vjoysticks. - while (it != s_vgamePad.end()) { + while (it != s_vgamePad.end()) + { delete *it; ++it; } @@ -96,11 +95,14 @@ void PollForJoystickInput(int cpad) return; GamePad::UpdateGamePadState(); - for (int i = 0; i < MAX_KEYS; i++) { + for (int i = 0; i < MAX_KEYS; i++) + { GamePad *gamePad = s_vgamePad[joyid]; - switch (type_of_joykey(cpad, i)) { - case PAD_JOYBUTTONS: { + switch (type_of_joykey(cpad, i)) + { + case PAD_JOYBUTTONS: + { int value = gamePad->GetButton(key_to_button(cpad, i)); if (value) @@ -110,7 +112,8 @@ void PollForJoystickInput(int cpad) break; } - case PAD_HAT: { + case PAD_HAT: + { int value = gamePad->GetHat(key_to_axis(cpad, i)); // key_to_hat_dir and SDL_JoystickGetHat are a 4 bits bitmap, one for each directions. Only 1 bit can be high for @@ -123,26 +126,31 @@ void PollForJoystickInput(int cpad) break; } - case PAD_AXIS: { + case PAD_AXIS: + { int value = gamePad->GetAxisFromKey(cpad, i); bool sign = key_to_axis_sign(cpad, i); bool full_axis = key_to_axis_type(cpad, i); - if (IsAnalogKey(i)) { + if (IsAnalogKey(i)) + { if (abs(value) > gamePad->GetDeadzone()) key_status->press(cpad, i, value); else key_status->release(cpad, i); - - } else { - if (full_axis) { + } + else + { + if (full_axis) + { value += 0x8000; if (value > gamePad->GetDeadzone()) key_status->press(cpad, i, std::min(value / 256, 0xFF)); else key_status->release(cpad, i); - - } else { + } + else + { if (sign && (-value > gamePad->GetDeadzone())) key_status->press(cpad, i, std::min(-value / 128, 0xFF)); else if (!sign && (value > gamePad->GetDeadzone())) @@ -158,15 +166,15 @@ void PollForJoystickInput(int cpad) } } -EXPORT_C_(void) -PADupdate(int pad) +EXPORT_C_(void) PADupdate(int pad) { // Gamepad inputs don't count as an activity. Therefore screensaver will // be fired after a couple of minute. // Emulate an user activity static int count = 0; count++; - if ((count & 0xFFF) == 0) { + if ((count & 0xFFF) == 0) + { // 1 call every 4096 Vsync is enough XResetScreenSaver(GSdsp); } @@ -176,13 +184,15 @@ PADupdate(int pad) // Poll keyboard/mouse event. There is currently no way to separate pad0 from pad1 event. // So we will populate both pad in the same time - for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++) { + for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++) + { key_status->keyboard_state_acces(cpad); } PollForX11KeyboardInput(); // Get joystick state + Commit - for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++) { + for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++) + { key_status->joystick_state_acces(cpad); PollForJoystickInput(cpad); @@ -193,8 +203,7 @@ PADupdate(int pad) Pad::rumble_all(); } -EXPORT_C_(void) -PADconfigure() +EXPORT_C_(void) PADconfigure() { LoadConfig(); diff --git a/plugins/onepad_legacy/Linux/opPanel.cpp b/plugins/onepad_legacy/Linux/opPanel.cpp index 159e3c543d..ce6502363f 100644 --- a/plugins/onepad_legacy/Linux/opPanel.cpp +++ b/plugins/onepad_legacy/Linux/opPanel.cpp @@ -85,7 +85,8 @@ opPanel::opPanel(wxWindow *parent, m_picture[img_r_arrow_bottom] = EmbeddedImage<res_arrow_bottom>().Get(); m_picture[img_r_arrow_left] = EmbeddedImage<res_arrow_left>().Get(); - for (int i = 0; i < NB_IMG; ++i) { + for (int i = 0; i < NB_IMG; ++i) + { m_show_image[i] = false; HideImg(i); } @@ -100,7 +101,8 @@ opPanel::opPanel(wxWindow *parent, void opPanel::HideImg(int id) { - if (id < NB_IMG) { + if (id < NB_IMG) + { m_show_image[id] = false; Refresh(); } @@ -108,7 +110,8 @@ void opPanel::HideImg(int id) void opPanel::ShowImg(int id) { - if (id < NB_IMG) { + if (id < NB_IMG) + { m_show_image[id] = true; Refresh(); } @@ -116,13 +119,20 @@ void opPanel::ShowImg(int id) void opPanel::MoveJoystick(int axe, int value) { - if (axe == 0) { + if (axe == 0) + { m_left_cursor_x = value * 30 / 40000; - } else if (axe == 1) { + } + else if (axe == 1) + { m_left_cursor_y = value * 30 / 40000; - } else if (axe == 2) { + } + else if (axe == 2) + { m_right_cursor_x = value * 30 / 40000; - } else { + } + else + { m_right_cursor_y = value * 30 / 40000; } } diff --git a/plugins/onepad_legacy/SDL/joystick.cpp b/plugins/onepad_legacy/SDL/joystick.cpp index 96fce469bd..36229d9c9d 100644 --- a/plugins/onepad_legacy/SDL/joystick.cpp +++ b/plugins/onepad_legacy/SDL/joystick.cpp @@ -35,7 +35,8 @@ void JoystickInfo::UpdateReleaseState() SDL_JoystickUpdate(); // Save everything in the vector s_vjoysticks. - while (itjoy != s_vgamePad.end()) { + while (itjoy != s_vgamePad.end()) + { (*itjoy)->SaveState(); ++itjoy; } @@ -45,20 +46,20 @@ void JoystickInfo::UpdateReleaseState() void JoystickInfo::EnumerateJoysticks(std::vector<GamePad *> &vjoysticks) { - if (!s_bSDLInit) { + if (!s_bSDLInit) + { #if SDL_MAJOR_VERSION >= 2 // Tell SDL to catch event even if the windows isn't focussed SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); - if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_EVENTS) < 0) - return; + if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_EVENTS) < 0) return; + // WTF! Give me back the control of my system struct sigaction action = {}; action.sa_handler = SIG_DFL; sigaction(SIGINT, &action, NULL); sigaction(SIGTERM, &action, NULL); #else - if (SDL_Init(SDL_INIT_JOYSTICK) < 0) - return; + if (SDL_Init(SDL_INIT_JOYSTICK) < 0) return; #endif SDL_JoystickEventState(SDL_QUERY); s_bSDLInit = true; @@ -67,14 +68,16 @@ void JoystickInfo::EnumerateJoysticks(std::vector<GamePad *> &vjoysticks) std::vector<GamePad *>::iterator it = vjoysticks.begin(); // Delete everything in the vector vjoysticks. - while (it != vjoysticks.end()) { + while (it != vjoysticks.end()) + { delete *it; ++it; } vjoysticks.resize(SDL_NumJoysticks()); - for (int i = 0; i < (int)vjoysticks.size(); ++i) { + for (int i = 0; i < (int)vjoysticks.size(); ++i) + { vjoysticks[i] = new JoystickInfo(); vjoysticks[i]->Init(i); } @@ -83,7 +86,8 @@ void JoystickInfo::EnumerateJoysticks(std::vector<GamePad *> &vjoysticks) void JoystickInfo::GenerateDefaultEffect() { #if SDL_MAJOR_VERSION >= 2 - for (int i = 0; i < NB_EFFECT; i++) { + for (int i = 0; i < NB_EFFECT; i++) + { SDL_HapticEffect effect; memset(&effect, 0, sizeof(SDL_HapticEffect)); // 0 is safe default SDL_HapticDirection direction; @@ -104,16 +108,14 @@ void JoystickInfo::GenerateDefaultEffect() void JoystickInfo::Rumble(int type, int pad) { - if (type > 1) - return; - if (!(conf->pad_options[pad].forcefeedback)) - return; + if (type > 1) return; + if (!(conf->pad_options[pad].forcefeedback)) return; #if SDL_MAJOR_VERSION >= 2 - if (haptic == NULL) - return; + if (haptic == NULL) return; - if (first) { // If done multiple times, device memory will be filled + if (first) // If done multiple times, device memory will be filled + { first = 0; GenerateDefaultEffect(); /** Sine and triangle are quite probably the best, don't change that lightly and if you do @@ -125,21 +127,24 @@ void JoystickInfo::Rumble(int type, int pad) **/ effects[0].type = SDL_HAPTIC_SINE; effects_id[0] = SDL_HapticNewEffect(haptic, &effects[0]); - if (effects_id[0] < 0) { + if (effects_id[0] < 0) + { fprintf(stderr, "ERROR: Effect is not uploaded! %s, id is %d\n", SDL_GetError(), effects_id[0]); } /** Effect for big motor **/ effects[1].type = SDL_HAPTIC_TRIANGLE; effects_id[1] = SDL_HapticNewEffect(haptic, &effects[1]); - if (effects_id[1] < 0) { + if (effects_id[1] < 0) + { fprintf(stderr, "ERROR: Effect is not uploaded! %s, id is %d\n", SDL_GetError(), effects_id[1]); } } int id; id = effects_id[type]; - if (SDL_HapticRunEffect(haptic, id, 1) != 0) { + if (SDL_HapticRunEffect(haptic, id, 1) != 0) + { fprintf(stderr, "ERROR: Effect is not working! %s, id is %d\n", SDL_GetError(), id); } #endif @@ -147,10 +152,12 @@ void JoystickInfo::Rumble(int type, int pad) void JoystickInfo::Destroy() { - if (joy != NULL) { + if (joy != NULL) + { #if SDL_MAJOR_VERSION >= 2 // Haptic must be closed before the joystick - if (haptic != NULL) { + if (haptic != NULL) + { SDL_HapticClose(haptic); haptic = NULL; } @@ -158,12 +165,10 @@ void JoystickInfo::Destroy() #if SDL_MAJOR_VERSION >= 2 #if SDL_MINOR_VERSION >= 4 // Version before 2.0.4 are bugged, JoystickClose crashes randomly - if (joy) - SDL_JoystickClose(joy); + if (joy) SDL_JoystickClose(joy); #endif #else - if (SDL_JoystickOpened(_id)) - SDL_JoystickClose(joy); + if (SDL_JoystickOpened(_id)) SDL_JoystickClose(joy); #endif joy = NULL; } @@ -175,7 +180,8 @@ bool JoystickInfo::Init(int id) _id = id; joy = SDL_JoystickOpen(id); - if (joy == NULL) { + if (joy == NULL) + { PAD_LOG("failed to open joystick %d\n", id); return false; } @@ -201,17 +207,24 @@ bool JoystickInfo::Init(int id) auto found_hack = devname.find("PLAYSTATION(R)3"); // FIXME: people need to restart the plugin to take the option into account. bool hack_enabled = (conf->pad_options[0].sixaxis_pressure) || (conf->pad_options[1].sixaxis_pressure); - if (found_hack != std::string::npos && numaxes > 4 && hack_enabled) { + + if (found_hack != std::string::npos && numaxes > 4 && hack_enabled) + { numbuttons = 4; // (select, start, l3, r3) - // Enable this hack in bluetooth too. It avoid to restart the onepad gui + + // Enable this hack in bluetooth too. It avoids restarting the onepad gui numbuttons += 4; // the 4 hat buttons } #if SDL_MAJOR_VERSION >= 2 - if (haptic == NULL) { - if (!SDL_JoystickIsHaptic(joy)) { + if (haptic == NULL) + { + if (!SDL_JoystickIsHaptic(joy)) + { PAD_LOG("Haptic devices not supported!\n"); - } else { + } + else + { haptic = SDL_HapticOpenFromJoystick(joy); first = true; } @@ -236,11 +249,12 @@ bool JoystickInfo::TestForce(float strength = 0.60) { #if SDL_MAJOR_VERSION >= 2 // This code just use standard rumble to check that SDL handles the pad correctly! --3kinox - if (haptic == NULL) - return false; // Otherwise, core dump! + if (haptic == NULL) return false; // Otherwise, core dump! SDL_HapticRumbleInit(haptic); + // Make the haptic pad rumble 60% strength for half a second, shoudld be enough for user to see if it works or not - if (SDL_HapticRumblePlay(haptic, strength, 400) != 0) { + if (SDL_HapticRumblePlay(haptic, strength, 400) != 0) + { fprintf(stderr, "ERROR: Rumble is not working! %s\n", SDL_GetError()); return false; } @@ -253,19 +267,21 @@ bool JoystickInfo::TestForce(float strength = 0.60) bool JoystickInfo::PollButtons(u32 &pkey) { // MAKE sure to look for changes in the state!! - for (int i = 0; i < GetNumButtons(); ++i) { + for (int i = 0; i < GetNumButtons(); ++i) + { int but = SDL_JoystickGetButton(GetJoy(), i); - if (but != GetButtonState(i)) { + if (but != GetButtonState(i)) + { // Pressure sensitive button are detected as both button (digital) and axes (analog). So better // drop the button to emulate the pressure sensiblity of the ds2 :) // Trick: detect the release of the button. It avoid all races condition between axes and buttons :) // If the button support pressure it will be detected as an axis when it is pressed. - if (but) { + if (but) + { SetButtonState(i, but); return false; } - pkey = button_to_key(i); return true; } @@ -278,25 +294,26 @@ bool JoystickInfo::PollAxes(u32 &pkey) { auto found_hack = devname.find("PLAYSTATION(R)3"); - for (int i = 0; i < GetNumAxes(); ++i) { + for (int i = 0; i < GetNumAxes(); ++i) + { // Sixaxis, dualshock3 hack - if (found_hack != std::string::npos) { + if (found_hack != std::string::npos) + { // The analog mode of the hat button is quite erratic. Values can be in half- axis // or full axis... So better keep them as button for the moment -- gregory - if (i >= 8 && i <= 11 && (conf->pad_options[pad].sixaxis_usb)) - continue; + if (i >= 8 && i <= 11 && (conf->pad_options[pad].sixaxis_usb)) continue; + // Disable accelerometer - if ((i >= 4 && i <= 6)) - continue; + if ((i >= 4 && i <= 6)) continue; } s32 value = SDL_JoystickGetAxis(GetJoy(), i); s32 old_value = GetAxisState(i); - if (abs(value - old_value) < 0x1000) - continue; + if (abs(value - old_value) < 0x1000) continue; - if (value != old_value) { + if (value != old_value) + { PAD_LOG("Change in joystick %d: %d.\n", i, value); // There are several kinds of axes // Half+: 0 (release) -> 32768 @@ -313,7 +330,8 @@ bool JoystickInfo::PollAxes(u32 &pkey) continue; } - if ((!is_full_axis && abs(value) > half_axis_ceil) || (is_full_axis && value > full_axis_ceil)) { + if ((!is_full_axis && abs(value) > half_axis_ceil) || (is_full_axis && value > full_axis_ceil)) + { bool sign = (value < 0); pkey = axis_to_key(is_full_axis, sign, i); @@ -327,11 +345,14 @@ bool JoystickInfo::PollAxes(u32 &pkey) bool JoystickInfo::PollHats(u32 &pkey) { - for (int i = 0; i < GetNumHats(); ++i) { + for (int i = 0; i < GetNumHats(); ++i) + { int value = SDL_JoystickGetHat(GetJoy(), i); - if ((value != GetHatState(i)) && (value != SDL_HAT_CENTERED)) { - switch (value) { + if ((value != GetHatState(i)) && (value != SDL_HAT_CENTERED)) + { + switch (value) + { case SDL_HAT_UP: case SDL_HAT_RIGHT: case SDL_HAT_DOWN: diff --git a/plugins/onepad_legacy/controller.cpp b/plugins/onepad_legacy/controller.cpp index c1703830c6..11ddc68656 100644 --- a/plugins/onepad_legacy/controller.cpp +++ b/plugins/onepad_legacy/controller.cpp @@ -22,7 +22,7 @@ #include "onepad.h" #include "controller.h" -__forceinline void set_keyboad_key(int pad, int keysym, int index) +__forceinline void set_keyboard_key(int pad, int keysym, int index) { conf->keysym_map[pad][keysym] = index; } diff --git a/plugins/onepad_legacy/controller.h b/plugins/onepad_legacy/controller.h index b470fdd532..cafb1e125d 100644 --- a/plugins/onepad_legacy/controller.h +++ b/plugins/onepad_legacy/controller.h @@ -30,7 +30,7 @@ enum KeyType { PAD_NULL = -1 }; -extern void set_keyboad_key(int pad, int keysym, int index); +extern void set_keyboard_key(int pad, int keysym, int index); extern int get_keyboard_key(int pad, int keysym); extern void set_key(int pad, int index, int value); extern int get_key(int pad, int index); @@ -86,7 +86,8 @@ public: log = packed_options = joyid_map = 0; ff_intensity = 0x7FFF; // set it at max value by default sensibility = 500; - for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) { + for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) + { keysym_map[pad].clear(); set_joyid((u32)pad, (u32)pad); // define id mapping for each gamepad } @@ -119,7 +120,8 @@ public: **/ void set_ff_intensity(u32 new_intensity) { - if (new_intensity <= 0x7FFF) { + if (new_intensity <= 0x7FFF) + { ff_intensity = new_intensity; } } @@ -131,7 +133,8 @@ public: **/ void set_sensibility(u32 new_sensibility) { - if (sensibility > 0) { + if (sensibility > 0) + { sensibility = new_sensibility; } } diff --git a/plugins/onepad_legacy/keyboard.cpp b/plugins/onepad_legacy/keyboard.cpp index 3b5f02f56d..52d2fda994 100644 --- a/plugins/onepad_legacy/keyboard.cpp +++ b/plugins/onepad_legacy/keyboard.cpp @@ -41,7 +41,8 @@ char *KeysymToChar(int keysym) void SetAutoRepeat(bool autorep) { #if defined(__unix__) - if (toggleAutoRepeat) { + if (toggleAutoRepeat) + { if (autorep) XAutoRepeatOn(GSdsp); else @@ -61,29 +62,36 @@ void AnalyzeKeyEvent(keyEvent &evt) int pad = 0; int index = -1; - for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++) { + for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++) + { int tmp_index = get_keyboard_key(cpad, key); - if (tmp_index != -1) { + if (tmp_index != -1) + { pad = cpad; index = tmp_index; } } - switch (evt.evt) { + switch (evt.evt) + { case KeyPress: // Shift F12 is not yet use by pcsx2. So keep it to grab/ungrab input // I found it very handy vs the automatic fullscreen detection // 1/ Does not need to detect full-screen // 2/ Can use a debugger in full-screen // 3/ Can grab input in window without the need of a pixelated full-screen - if (key == XK_Shift_R || key == XK_Shift_L) - s_Shift = true; - if (key == XK_F12 && s_Shift) { - if (!s_grab_input) { + if (key == XK_Shift_R || key == XK_Shift_L) s_Shift = true; + + if (key == XK_F12 && s_Shift) + { + if (!s_grab_input) + { s_grab_input = true; XGrabPointer(GSdsp, GSwin, True, ButtonPressMask, GrabModeAsync, GrabModeAsync, GSwin, None, CurrentTime); XGrabKeyboard(GSdsp, GSwin, True, GrabModeAsync, GrabModeAsync, CurrentTime); - } else { + } + else + { s_grab_input = false; XUngrabPointer(GSdsp, CurrentTime); XUngrabKeyboard(GSdsp, CurrentTime); @@ -91,8 +99,10 @@ void AnalyzeKeyEvent(keyEvent &evt) } // Analog controls. - if (IsAnalogKey(index)) { - switch (index) { + if (IsAnalogKey(index)) + { + switch (index) + { case PAD_R_LEFT: case PAD_R_UP: case PAD_L_LEFT: @@ -106,7 +116,8 @@ void AnalyzeKeyEvent(keyEvent &evt) key_status->press(pad, index, MAX_ANALOG_VALUE); break; } - } else if (index != -1) + } + else if (index != -1) key_status->press(pad, index); //PAD_LOG("Key pressed:%d\n", index); @@ -116,11 +127,9 @@ void AnalyzeKeyEvent(keyEvent &evt) break; case KeyRelease: - if (key == XK_Shift_R || key == XK_Shift_L) - s_Shift = false; + if (key == XK_Shift_R || key == XK_Shift_L) s_Shift = false; - if (index != -1) - key_status->release(pad, index); + if (index != -1) key_status->release(pad, index); event.evt = KEYRELEASE; event.key = key; @@ -136,13 +145,11 @@ void AnalyzeKeyEvent(keyEvent &evt) break; case ButtonPress: - if (index != -1) - key_status->press(pad, index); + if (index != -1) key_status->press(pad, index); break; case ButtonRelease: - if (index != -1) - key_status->release(pad, index); + if (index != -1) key_status->release(pad, index); break; case MotionNotify: @@ -150,14 +157,18 @@ void AnalyzeKeyEvent(keyEvent &evt) // 1/ small move == no move. Cons : can not do small movement // 2/ use a watchdog timer thread // 3/ ??? idea welcome ;) - if (conf->pad_options[pad].mouse_l | conf->pad_options[pad].mouse_r) { + if (conf->pad_options[pad].mouse_l | conf->pad_options[pad].mouse_r) + { unsigned int pad_x; unsigned int pad_y; // Note when both PADOPTION_MOUSE_R and PADOPTION_MOUSE_L are set, take only the right one - if (conf->pad_options[pad].mouse_r) { + if (conf->pad_options[pad].mouse_r) + { pad_x = PAD_R_RIGHT; pad_y = PAD_R_UP; - } else { + } + else + { pad_x = PAD_L_RIGHT; pad_y = PAD_L_UP; } @@ -207,7 +218,8 @@ void PollForX11KeyboardInput() XEvent E = {0}; // Keyboard input send by PCSX2 - while (!ev_fifo.empty()) { + while (!ev_fifo.empty()) + { AnalyzeKeyEvent(ev_fifo.front()); pthread_spin_lock(&mutex_KeyEvent); ev_fifo.pop(); @@ -215,13 +227,15 @@ void PollForX11KeyboardInput() } // keyboard input - while (XPending(GSdsp) > 0) { + while (XPending(GSdsp) > 0) + { XNextEvent(GSdsp, &E); // Change the format of the structure to be compatible with GSOpen2 // mode (event come from pcsx2 not X) evt.evt = E.type; - switch (E.type) { + switch (E.type) + { case MotionNotify: evt.key = (E.xbutton.x & 0xFFFF) | (E.xbutton.y << 16); break; @@ -241,11 +255,15 @@ bool PollX11KeyboardMouseEvent(u32 &pkey) { GdkEvent *ev = gdk_event_get(); - if (ev != NULL) { - if (ev->type == GDK_KEY_PRESS) { + if (ev != NULL) + { + if (ev->type == GDK_KEY_PRESS) + { pkey = ev->key.keyval != GDK_KEY_Escape ? ev->key.keyval : 0; return true; - } else if (ev->type == GDK_BUTTON_PRESS) { + } + else if (ev->type == GDK_BUTTON_PRESS) + { pkey = ev->button.button; return true; } @@ -260,14 +278,18 @@ LRESULT WINAPI PADwndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) static bool lbutton = false, rbutton = false; key_status->keyboard_state_acces(cpad); - switch (msg) { + switch (msg) + { case WM_KEYDOWN: if (lParam & 0x40000000) return TRUE; - for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad) { - for (int i = 0; i < MAX_KEYS; i++) { - if (wParam == get_key(pad, i)) { + for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad) + { + for (int i = 0; i < MAX_KEYS; i++) + { + if (wParam == get_key(pad, i)) + { key_status->press(pad, i); break; } @@ -279,9 +301,12 @@ LRESULT WINAPI PADwndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) break; case WM_KEYUP: - for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad) { - for (int i = 0; i < MAX_KEYS; i++) { - if (wParam == get_key(pad, i)) { + for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad) + { + for (int i = 0; i < MAX_KEYS; i++) + { + if (wParam == get_key(pad, i)) + { key_status->release(pad, i); break; } diff --git a/plugins/onepad_legacy/onepad.cpp b/plugins/onepad_legacy/onepad.cpp index 944abef7fc..9882eab5f7 100644 --- a/plugins/onepad_legacy/onepad.cpp +++ b/plugins/onepad_legacy/onepad.cpp @@ -85,21 +85,18 @@ static void InitLibraryName() #endif } -EXPORT_C_(u32) -PS2EgetLibType() +EXPORT_C_(u32) PS2EgetLibType() { return PS2E_LT_PAD; } -EXPORT_C_(const char *) -PS2EgetLibName() +EXPORT_C_(const char *) PS2EgetLibName() { InitLibraryName(); return libraryName; } -EXPORT_C_(u32) -PS2EgetLibVersion2(u32 type) +EXPORT_C_(u32) PS2EgetLibVersion2(u32 type) { return (version << 16) | (revision << 8) | build; } @@ -148,7 +145,8 @@ void initLogging() void CloseLogging() { #ifdef PAD_LOG - if (padLog) { + if (padLog) + { fclose(padLog); padLog = NULL; } @@ -162,8 +160,7 @@ void clearPAD(int pad) set_key(pad, key, 0); } -EXPORT_C_(s32) -PADinit(u32 flags) +EXPORT_C_(s32) PADinit(u32 flags) { initLogging(); @@ -176,13 +173,12 @@ PADinit(u32 flags) query.reset(); for (int port = 0; port < 2; port++) - slots[port] = 0; + slots[port] = 0; return 0; } -EXPORT_C_(void) -PADshutdown() +EXPORT_C_(void) PADshutdown() { CloseLogging(); @@ -193,8 +189,7 @@ PADshutdown() key_status = nullptr; } -EXPORT_C_(s32) -PADopen(void *pDsp) +EXPORT_C_(s32) PADopen(void *pDsp) { memset(&event, 0, sizeof(event)); key_status->Init(); @@ -210,15 +205,13 @@ PADopen(void *pDsp) return _PADopen(pDsp); } -EXPORT_C_(void) -PADsetSettingsDir(const char *dir) +EXPORT_C_(void) PADsetSettingsDir(const char *dir) { // Get the path to the ini directory. s_strIniPath = (dir == NULL) ? "inis/" : dir; } -EXPORT_C_(void) -PADsetLogDir(const char *dir) +EXPORT_C_(void) PADsetLogDir(const char *dir) { // Get the path to the log directory. s_strLogPath = (dir == NULL) ? "logs/" : dir; @@ -228,8 +221,7 @@ PADsetLogDir(const char *dir) initLogging(); } -EXPORT_C_(void) -PADclose() +EXPORT_C_(void) PADclose() { while (!ev_fifo.empty()) ev_fifo.pop(); @@ -238,18 +230,17 @@ PADclose() _PADclose(); } -EXPORT_C_(u32) -PADquery() +EXPORT_C_(u32) PADquery() { return 3; // both } -EXPORT_C_(s32) -PADsetSlot(u8 port, u8 slot) +EXPORT_C_(s32) PADsetSlot(u8 port, u8 slot) { port--; slot--; - if (port > 1 || slot > 3) { + if (port > 1 || slot > 3) + { return 0; } // Even if no pad there, record the slot, as it is the active slot regardless. @@ -258,16 +249,17 @@ PADsetSlot(u8 port, u8 slot) return 1; } -EXPORT_C_(s32) -PADfreeze(int mode, freezeData *data) +EXPORT_C_(s32) PADfreeze(int mode, freezeData *data) { if (!data) return -1; - if (mode == FREEZE_SIZE) { + if (mode == FREEZE_SIZE) + { data->size = sizeof(PadPluginFreezeData); - - } else if (mode == FREEZE_LOAD) { + } + else if (mode == FREEZE_LOAD) + { PadPluginFreezeData *pdata = (PadPluginFreezeData *)(data->data); Pad::stop_vibrate_all(); @@ -277,17 +269,21 @@ PADfreeze(int mode, freezeData *data) return 0; query = pdata->query; - if (pdata->query.slot < 4) { + if (pdata->query.slot < 4) + { query = pdata->query; } // Tales of the Abyss - pad fix // - restore data for both ports - for (int port = 0; port < 2; port++) { - for (int slot = 0; slot < 4; slot++) { + for (int port = 0; port < 2; port++) + { + for (int slot = 0; slot < 4; slot++) + { u8 mode = pdata->padData[port][slot].mode; - if (mode != MODE_DIGITAL && mode != MODE_ANALOG && mode != MODE_DS2_NATIVE) { + if (mode != MODE_DIGITAL && mode != MODE_ANALOG && mode != MODE_DS2_NATIVE) + { break; } @@ -295,10 +291,11 @@ PADfreeze(int mode, freezeData *data) } if (pdata->slot[port] < 4) - slots[port] = pdata->slot[port]; + slots[port] = pdata->slot[port]; } - - } else if (mode == FREEZE_SAVE) { + } + else if (mode == FREEZE_SAVE) + { if (data->size != sizeof(PadPluginFreezeData)) return 0; @@ -312,36 +309,36 @@ PADfreeze(int mode, freezeData *data) pdata->version = PAD_SAVE_STATE_VERSION; pdata->query = query; - for (int port = 0; port < 2; port++) { - for (int slot = 0; slot < 4; slot++) { + for (int port = 0; port < 2; port++) + { + for (int slot = 0; slot < 4; slot++) + { pdata->padData[port][slot] = pads[port][slot]; } pdata->slot[port] = slots[port]; } - - } else { + } + else + { return -1; } return 0; } -EXPORT_C_(u8) -PADstartPoll(int pad) +EXPORT_C_(u8) PADstartPoll(int pad) { return pad_start_poll(pad); } -EXPORT_C_(u8) -PADpoll(u8 value) +EXPORT_C_(u8) PADpoll(u8 value) { return pad_poll(value); } // PADkeyEvent is called every vsync (return NULL if no event) -EXPORT_C_(keyEvent *) -PADkeyEvent() +EXPORT_C_(keyEvent *) PADkeyEvent() { s_event = event; event.evt = 0; @@ -350,12 +347,12 @@ PADkeyEvent() } #if defined(__unix__) -EXPORT_C_(void) -PADWriteEvent(keyEvent &evt) +EXPORT_C_(void) PADWriteEvent(keyEvent &evt) { // This function call be called before PADopen. Therefore we cann't // guarantee that the spin lock was initialized - if (mutex_WasInit) { + if (mutex_WasInit) + { pthread_spin_lock(&mutex_KeyEvent); ev_fifo.push(evt); pthread_spin_unlock(&mutex_KeyEvent); diff --git a/plugins/onepad_legacy/state_management.cpp b/plugins/onepad_legacy/state_management.cpp index c275b0d662..7c4615ac8c 100644 --- a/plugins/onepad_legacy/state_management.cpp +++ b/plugins/onepad_legacy/state_management.cpp @@ -58,7 +58,8 @@ void QueryInfo::reset() u8 QueryInfo::start_poll(int _port) { - if (port > 1) { + if (port > 1) + { reset(); return 0; } @@ -119,9 +120,11 @@ void Pad::reset() void Pad::rumble(int port) { - for (int motor = 0; motor < 2; motor++) { + for (int motor = 0; motor < 2; motor++) + { // TODO: Probably be better to send all of these at once. - if (nextVibrate[motor] | currentVibrate[motor]) { + if (nextVibrate[motor] | currentVibrate[motor]) + { currentVibrate[motor] = nextVibrate[motor]; GamePad::DoRumble(motor, port); @@ -179,29 +182,35 @@ u8 pad_start_poll(u8 pad) u8 pad_poll(u8 value) { - if (query.lastByte + 1 >= query.numBytes) { + if (query.lastByte + 1 >= query.numBytes) + { return 0; } - if (query.lastByte && query.queryDone) { + if (query.lastByte && query.queryDone) + { return query.response[++query.lastByte]; } Pad *pad = &pads[query.port][query.slot]; - if (query.lastByte == 0) { + if (query.lastByte == 0) + { query.lastByte++; query.currentCommand = value; - switch (value) { + switch (value) + { case CMD_CONFIG_MODE: - if (pad->config) { + if (pad->config) + { // In config mode. Might not actually be leaving it. query.set_result(ConfigExit); return 0xF3; } - // fallthrough on purpose (but I don't know why) + // fallthrough on purpose (but I don't know why) - case CMD_READ_DATA_AND_VIBRATE: { + case CMD_READ_DATA_AND_VIBRATE: + { query.response[2] = 0x5A; #if 0 int i; @@ -246,7 +255,8 @@ u8 pad_poll(u8 value) query.response[3] = (buttons >> 8) & 0xFF; query.response[4] = (buttons >> 0) & 0xFF; - if (pad->mode != MODE_DIGITAL) { // ANALOG || DS2 native + if (pad->mode != MODE_DIGITAL) + { // ANALOG || DS2 native query.numBytes = 9; query.response[5] = key_status->get(query.port, PAD_R_RIGHT); @@ -254,7 +264,8 @@ u8 pad_poll(u8 value) query.response[7] = key_status->get(query.port, PAD_L_RIGHT); query.response[8] = key_status->get(query.port, PAD_L_UP); - if (pad->mode != MODE_ANALOG) { // DS2 native + if (pad->mode != MODE_ANALOG) + { // DS2 native query.numBytes = 21; query.response[9] = !test_bit(buttons, 13) ? key_status->get(query.port, PAD_RIGHT) : 0; @@ -319,10 +330,13 @@ u8 pad_poll(u8 value) case CMD_QUERY_DS2_ANALOG_MODE: // Right? Wrong? No clue. - if (pad->mode == MODE_DIGITAL) { + if (pad->mode == MODE_DIGITAL) + { queryMaskMode[1] = queryMaskMode[2] = queryMaskMode[3] = 0; queryMaskMode[6] = 0x00; - } else { + } + else + { queryMaskMode[1] = pad->umask[0]; queryMaskMode[2] = pad->umask[1]; queryMaskMode[3] = 0x03; @@ -339,9 +353,12 @@ u8 pad_poll(u8 value) break; case CMD_QUERY_MODEL_AND_MODE: - if (IsDualshock2()) { + if (IsDualshock2()) + { query.set_final_result(queryModelDS2); - } else { + } + else + { query.set_final_result(queryModelDS1); } // Not digital mode. @@ -368,9 +385,12 @@ u8 pad_poll(u8 value) break; case CMD_SET_DS2_NATIVE_MODE: - if (IsDualshock2()) { + if (IsDualshock2()) + { query.set_result(setNativeMode); - } else { + } + else + { query.set_final_result(setNativeMode); } break; @@ -382,11 +402,13 @@ u8 pad_poll(u8 value) } return 0xF3; - - } else { + } + else + { query.lastByte++; - switch (query.currentCommand) { + switch (query.currentCommand) + { case CMD_READ_DATA_AND_VIBRATE: if (query.lastByte == pad->vibrateI[0]) pad->set_vibrate(1, 255 * (value & 1)); @@ -396,16 +418,20 @@ u8 pad_poll(u8 value) break; case CMD_CONFIG_MODE: - if (query.lastByte == 3) { + if (query.lastByte == 3) + { query.queryDone = 1; pad->config = value; } break; case CMD_SET_MODE_AND_LOCK: - if (query.lastByte == 3 && value < 2) { + if (query.lastByte == 3 && value < 2) + { pad->set_mode(value ? MODE_ANALOG : MODE_DIGITAL); - } else if (query.lastByte == 4) { + } + else if (query.lastByte == 4) + { if (value == 3) pad->modeLock = 3; else @@ -416,7 +442,8 @@ u8 pad_poll(u8 value) break; case CMD_QUERY_ACT: - if (query.lastByte == 3) { + if (query.lastByte == 3) + { if (value < 2) query.set_result(queryAct[value]); // bunch of 0's @@ -426,7 +453,8 @@ u8 pad_poll(u8 value) break; case CMD_QUERY_MODE: - if (query.lastByte == 3 && value < 2) { + if (query.lastByte == 3 && value < 2) + { query.response[6] = 4 + value * 3; query.queryDone = 1; } @@ -435,10 +463,14 @@ u8 pad_poll(u8 value) break; case CMD_VIBRATION_TOGGLE: - if (query.lastByte >= 3) { - if (value == 0) { + if (query.lastByte >= 3) + { + if (value == 0) + { pad->vibrateI[0] = (u8)query.lastByte; - } else if (value == 1) { + } + else if (value == 1) + { pad->vibrateI[1] = (u8)query.lastByte; } pad->vibrate[query.lastByte - 2] = value; @@ -446,9 +478,12 @@ u8 pad_poll(u8 value) break; case CMD_SET_DS2_NATIVE_MODE: - if (query.lastByte == 3 || query.lastByte == 4) { + if (query.lastByte == 3 || query.lastByte == 4) + { pad->umask[query.lastByte - 3] = value; - } else if (query.lastByte == 5) { + } + else if (query.lastByte == 5) + { if (!(value & 1)) pad->set_mode(MODE_DIGITAL); else if (!(value & 2))