diff --git a/src/citra/emu_window/emu_window_sdl2.cpp b/src/citra/emu_window/emu_window_sdl2.cpp index ca46614b8..bde4fef32 100644 --- a/src/citra/emu_window/emu_window_sdl2.cpp +++ b/src/citra/emu_window/emu_window_sdl2.cpp @@ -8,19 +8,18 @@ #define SDL_MAIN_HANDLED #include #include + #include "common/logging/log.h" #include "common/scm_rev.h" #include "common/string_util.h" #include "core/hle/service/hid/hid.h" #include "core/settings.h" - #include "input_core/devices/keyboard.h" #include "input_core/input_core.h" +#include "video_core/video_core.h" #include "citra/emu_window/emu_window_sdl2.h" -#include "video_core/video_core.h" - void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) { TouchMoved((unsigned)std::max(x, 0), (unsigned)std::max(y, 0)); motion_emu->Tilt(x, y); diff --git a/src/citra_qt/configure_input.cpp b/src/citra_qt/configure_input.cpp index 973b44f54..e3dc6d1d7 100644 --- a/src/citra_qt/configure_input.cpp +++ b/src/citra_qt/configure_input.cpp @@ -100,11 +100,11 @@ void ConfigureInput::loadConfiguration() { updateButtonLabels(); } -void ConfigureInput::setKey(Settings::InputDeviceMapping keyPressed) { - if (keyPressed.key == -1 || keyPressed.key == Qt::Key_Escape) { +void ConfigureInput::setKey(Settings::InputDeviceMapping key_pressed) { + if (key_pressed.key == -1 || key_pressed.key == Qt::Key_Escape) { } else { - key_map[changing_button] = keyPressed; - removeDuplicates(keyPressed); + key_map[changing_button] = key_pressed; + removeDuplicates(key_pressed); } updateButtonLabels(); releaseKeyboard(); @@ -136,10 +136,10 @@ QString ConfigureInput::getKeyName(Settings::InputDeviceMapping mapping) { return QKeySequence(mapping.key).toString(); } -void ConfigureInput::removeDuplicates(const Settings::InputDeviceMapping newValue) { +void ConfigureInput::removeDuplicates(const Settings::InputDeviceMapping new_value) { for (auto& entry : key_map) { if (changing_button != entry.first) { - if (newValue == entry.second && newValue.key == entry.second.key) { + if (new_value == entry.second && new_value.key == entry.second.key) { entry.second = Settings::InputDeviceMapping(); } } diff --git a/src/citra_qt/configure_input.h b/src/citra_qt/configure_input.h index b9830057e..067f2420c 100644 --- a/src/citra_qt/configure_input.h +++ b/src/citra_qt/configure_input.h @@ -40,7 +40,7 @@ private: /// Check all inputs for duplicate keys. Clears out any other button with the same value as this /// button's new value. - void removeDuplicates(const Settings::InputDeviceMapping newValue); + void removeDuplicates(const Settings::InputDeviceMapping new_value); /// Handle keykoard key press event for input tab when a button is 'waiting'. void keyPressEvent(QKeyEvent* event) override; @@ -49,7 +49,7 @@ private: static QString getKeyName(Settings::InputDeviceMapping mapping); /// Set button text to name of key pressed. - void setKey(Settings::InputDeviceMapping keyPressed); + void setKey(Settings::InputDeviceMapping key_pressed); /// Event handler for all button released() event. void handleClick(QPushButton* sender); diff --git a/src/citra_qt/keybinding_names.cpp b/src/citra_qt/keybinding_names.cpp index 886e6ca74..d4b19030d 100644 --- a/src/citra_qt/keybinding_names.cpp +++ b/src/citra_qt/keybinding_names.cpp @@ -1,4 +1,4 @@ -// Copyright 2016 Citra Emulator Project +// Copyright 2017 Citra Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. diff --git a/src/citra_qt/keybinding_names.h b/src/citra_qt/keybinding_names.h index b750c0344..e7b57981b 100644 --- a/src/citra_qt/keybinding_names.h +++ b/src/citra_qt/keybinding_names.h @@ -1,4 +1,4 @@ -// Copyright 2016 Citra Emulator Project +// Copyright 2017 Citra Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 6362e282a..4e7897f36 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -30,7 +30,7 @@ set(SRCS file_sys/path_parser.cpp file_sys/savedata_archive.cpp frontend/emu_window.cpp - frontend/motion_emu.cpp + frontend/motion_emu.cpp gdbstub/gdbstub.cpp hle/config_mem.cpp hle/applets/applet.cpp @@ -203,7 +203,7 @@ set(HEADERS file_sys/path_parser.h file_sys/savedata_archive.h frontend/emu_window.h - frontend/motion_emu.h + frontend/motion_emu.h gdbstub/gdbstub.h hle/config_mem.h hle/function_wrappers.h diff --git a/src/core/frontend/emu_window.cpp b/src/core/frontend/emu_window.cpp index 5e475fa47..2ee5cc8e9 100644 --- a/src/core/frontend/emu_window.cpp +++ b/src/core/frontend/emu_window.cpp @@ -7,11 +7,10 @@ #include "common/assert.h" #include "common/profiler_reporting.h" #include "core/frontend/emu_window.h" +#include "input_core/input_core.h" #include "video_core/video_core.h" #include "emu_window.h" -#include "input_core/input_core.h" -#include "video_core/video_core.h" /** * Check if the given x/y coordinates are within the touchpad specified by the framebuffer layout diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 388a1e713..b952605c1 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -10,15 +10,14 @@ #include "core/hle/service/hid/hid_user.h" #include "core/hle/service/service.h" -#include "input_core/input_core.h" - #include "core/core_timing.h" #include "core/hle/kernel/event.h" #include "core/hle/kernel/shared_memory.h" -#include "core/hle/service/hid/hid.h" #include "core/hle/service/hid/hid_spvr.h" #include "core/hle/service/hid/hid_user.h" #include "core/hle/service/service.h" + +#include "input_core/input_core.h" #include "video_core/video_core.h" namespace Service { diff --git a/src/input_core/devices/device.cpp b/src/input_core/devices/device.cpp index c7b4cd9a9..06245b22b 100644 --- a/src/input_core/devices/device.cpp +++ b/src/input_core/devices/device.cpp @@ -1,4 +1,4 @@ -// Copyright 2016 Citra Emulator Project +// Copyright 2017 Citra Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. diff --git a/src/input_core/devices/device.h b/src/input_core/devices/device.h index 7821c20ce..5928cc1f4 100644 --- a/src/input_core/devices/device.h +++ b/src/input_core/devices/device.h @@ -1,4 +1,4 @@ -// Copyright 2016 Citra Emulator Project +// Copyright 2017 Citra Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. diff --git a/src/input_core/devices/gamecontrollerdb.h b/src/input_core/devices/gamecontrollerdb.h index 8dc3be138..dcbc7e923 100644 --- a/src/input_core/devices/gamecontrollerdb.h +++ b/src/input_core/devices/gamecontrollerdb.h @@ -1,4 +1,4 @@ -// Copyright 2016 Citra Emulator Project +// Copyright 2017 Citra Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. diff --git a/src/input_core/devices/keyboard.cpp b/src/input_core/devices/keyboard.cpp index 79914fb30..aedbeb8c5 100644 --- a/src/input_core/devices/keyboard.cpp +++ b/src/input_core/devices/keyboard.cpp @@ -1,4 +1,4 @@ -// Copyright 2016 Citra Emulator Project +// Copyright 2017 Citra Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. @@ -7,9 +7,9 @@ #include "input_core/devices/keyboard.h" -Keyboard::Keyboard() {} +Keyboard::Keyboard() = default; -Keyboard::~Keyboard() {} +Keyboard::~Keyboard() = default; bool Keyboard::InitDevice(int number, Settings::InputDeviceMapping device_mapping) { input_device_mapping = device_mapping; @@ -17,14 +17,13 @@ bool Keyboard::InitDevice(int number, Settings::InputDeviceMapping device_mappin } std::map Keyboard::ProcessInput() { - std::map keysPressedCopy; + std::map keys_pressed_copy; { std::lock_guard lock(m); - keysPressedCopy = keys_pressed; + keys_pressed_copy = keys_pressed; } std::map button_status; - bool circlePadModPressed = keysPressedCopy[circle_pad_modifier]; - for (const auto& key : keysPressedCopy) { + for (const auto& key : keys_pressed_copy) { input_device_mapping.key = key.first.key; button_status.emplace(input_device_mapping, key.second ? 1.0 : 0.0); } diff --git a/src/input_core/devices/keyboard.h b/src/input_core/devices/keyboard.h index 01a2ae1d7..6cdb62c84 100644 --- a/src/input_core/devices/keyboard.h +++ b/src/input_core/devices/keyboard.h @@ -1,4 +1,4 @@ -// Copyright 2016 Citra Emulator Project +// Copyright 2017 Citra Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. diff --git a/src/input_core/devices/sdl_gamepad.cpp b/src/input_core/devices/sdl_gamepad.cpp index d307a2d9e..11b3989db 100644 --- a/src/input_core/devices/sdl_gamepad.cpp +++ b/src/input_core/devices/sdl_gamepad.cpp @@ -1,4 +1,4 @@ -// Copyright 2016 Citra Emulator Project +// Copyright 2017 Citra Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. @@ -16,7 +16,7 @@ bool SDLGamepad::SDLInitialized = false; -SDLGamepad::SDLGamepad() {} +SDLGamepad::SDLGamepad() = default; SDLGamepad::SDLGamepad(int number_, _SDL_GameController* gamepad_) : number(number_), gamepad(gamepad_) {} SDLGamepad::~SDLGamepad() { @@ -51,14 +51,15 @@ std::map SDLGamepad::ProcessInput() { SDL_GameControllerButton button = static_cast(i); Uint8 pressed = SDL_GameControllerGetButton(gamepad, button); input_device_mapping.key = static_cast( - gamepadinput_to_sdlname_mapping2[SDL_GameControllerGetStringForButton(button)]); + gamepadinput_to_sdlname_mapping[SDL_GameControllerGetStringForButton(button)]); button_status.emplace(input_device_mapping, pressed); } for (int i = 0; i < SDL_GameControllerAxis::SDL_CONTROLLER_AXIS_MAX; i++) { SDL_GameControllerAxis axis = static_cast(i); - float strength = fmaxf(-1, (float)SDL_GameControllerGetAxis(gamepad, axis) / 32767.0); + float strength = + fmaxf(-1, static_cast(SDL_GameControllerGetAxis(gamepad, axis) / 32767.0)); input_device_mapping.key = static_cast( - gamepadinput_to_sdlname_mapping2[SDL_GameControllerGetStringForAxis(axis)]); + gamepadinput_to_sdlname_mapping[SDL_GameControllerGetStringForAxis(axis)]); if (strength < 0) { button_status.emplace(input_device_mapping, 0); input_device_mapping.key += 1; // minus axis value is always one greater @@ -94,6 +95,7 @@ std::vector> SDLGamepad::GetAllDevices() { } void SDLGamepad::LoadGameControllerDB() { + // gamecontrollerdb file is split into 4 sections due to exceeding max length of string. std::vector lines1, lines2, lines3, lines4; Common::SplitString(SDLGameControllerDB::db_file1, '\n', lines1); Common::SplitString(SDLGameControllerDB::db_file2, '\n', lines2); @@ -102,7 +104,7 @@ void SDLGamepad::LoadGameControllerDB() { lines1.insert(lines1.end(), lines2.begin(), lines2.end()); lines1.insert(lines1.end(), lines3.begin(), lines3.end()); lines1.insert(lines1.end(), lines4.begin(), lines4.end()); - for (std::string s : lines1) { + for (const auto s : lines1) { SDL_GameControllerAddMapping(s.c_str()); } } @@ -112,7 +114,7 @@ Settings::InputDeviceMapping SDLGamepad::GetInput() { return Settings::InputDeviceMapping(""); auto results = ProcessInput(); - for (auto& input : results) { + for (const auto& input : results) { if (input.second > 0.5) return input.first; } diff --git a/src/input_core/devices/sdl_gamepad.h b/src/input_core/devices/sdl_gamepad.h index 17f21a1e5..b40ffd0ef 100644 --- a/src/input_core/devices/sdl_gamepad.h +++ b/src/input_core/devices/sdl_gamepad.h @@ -1,4 +1,4 @@ -// Copyright 2016 Citra Emulator Project +// Copyright 2017 Citra Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. @@ -52,33 +52,7 @@ public: private: /// Maps the friendly name shown on GUI with the string name for getting the SDL button /// instance. - std::map gamepadinput_to_sdlname_mapping = { - {GamepadInputs::ButtonA, "a"}, - {GamepadInputs::ButtonB, "b"}, - {GamepadInputs::ButtonX, "x"}, - {GamepadInputs::ButtonY, "y"}, - {GamepadInputs::LeftShoulder, "leftshoulder"}, - {GamepadInputs::RightShoulder, "rightshoulder"}, - {GamepadInputs::Start, "start"}, - {GamepadInputs::Back, "back"}, - {GamepadInputs::DPadUp, "dpup"}, - {GamepadInputs::DpadDown, "dpdown"}, - {GamepadInputs::DpadLeft, "dpleft"}, - {GamepadInputs::DpadRight, "dpright"}, - {GamepadInputs::L3, "leftstick"}, - {GamepadInputs::R3, "rightstick"}, - {GamepadInputs::LeftTrigger, "lefttrigger"}, - {GamepadInputs::RightTrigger, "righttrigger"}, - {GamepadInputs::LeftYPlus, "lefty"}, - {GamepadInputs::LeftYMinus, "lefty"}, - {GamepadInputs::LeftXPlus, "leftx"}, - {GamepadInputs::LeftXMinus, "leftx"}, - {GamepadInputs::RightYPlus, "righty"}, - {GamepadInputs::RightYMinus, "righty"}, - {GamepadInputs::RightXPlus, "rightx"}, - {GamepadInputs::RightXMinus, "rightx"}, - }; - std::map gamepadinput_to_sdlname_mapping2 = { + std::map gamepadinput_to_sdlname_mapping = { {"a", GamepadInputs::ButtonA}, {"b", GamepadInputs::ButtonB}, {"x", GamepadInputs::ButtonX}, diff --git a/src/input_core/input_core.cpp b/src/input_core/input_core.cpp index 90ba2f72f..0bc343aa3 100644 --- a/src/input_core/input_core.cpp +++ b/src/input_core/input_core.cpp @@ -1,4 +1,4 @@ -// Copyright 2016 Citra Emulator Project +// Copyright 2017 Citra Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. @@ -28,7 +28,7 @@ std::mutex InputCore::touch_mutex; u16 InputCore::touch_x; ///< Touchpad X-position in native 3DS pixel coordinates (0-320) u16 InputCore::touch_y; ///< Touchpad Y-position in native 3DS pixel coordinates (0-240) bool InputCore::touch_pressed; ///< True if touchpad area is currently pressed, otherwise false -const float input_detect_threshold = +const float InputCore::input_detect_threshold = 0.45; ///< Applies to analog controls being used for digital 3ds inputs. void InputCore::Init() { @@ -60,7 +60,7 @@ void InputCore::UpdateEmulatorInputs( std::lock_guard lock(pad_state_mutex); // Apply deadzone for circle pad - float leftx = 0, lefty = 0; + float left_x = 0, left_y = 0; float circle_pad_modifier = 1.0; auto circle_pad_modifier_mapping = Settings::values.pad_circle_modifier; for (auto& input_device : inputs) { @@ -69,13 +69,13 @@ void InputCore::UpdateEmulatorInputs( auto emulator_inputs = key_mappings[button_states.first]; for (auto& emulator_input : emulator_inputs) { if (emulator_input == Service::HID::PAD_CIRCLE_UP && abs(strength) > 0) { - lefty = -strength; + left_y = -strength; } else if (emulator_input == Service::HID::PAD_CIRCLE_DOWN && abs(strength) > 0) { - lefty = strength; + left_y = strength; } else if (emulator_input == Service::HID::PAD_CIRCLE_LEFT && abs(strength) > 0) { - leftx = -strength; + left_x = -strength; } else if (emulator_input == Service::HID::PAD_CIRCLE_RIGHT && abs(strength) > 0) { - leftx = strength; + left_x = strength; } } if (button_states.first == circle_pad_modifier_mapping) @@ -85,7 +85,7 @@ void InputCore::UpdateEmulatorInputs( } } float deadzone = Settings::values.pad_circle_deadzone; - std::tuple left_stick = ApplyDeadzone(leftx, lefty, deadzone); + std::tuple left_stick = ApplyDeadzone(left_x, left_y, deadzone); // Set emulator circlepad values std::get<0>(circle_pad) = @@ -149,24 +149,26 @@ void InputCore::SetTouchState(std::tuple value) { std::tie(touch_x, touch_y, touch_pressed) = value; } -bool InputCore::CheckIfMappingExists(const std::vector& uniqueMapping, - Settings::InputDeviceMapping mappingToCheck) { - return std::any_of(uniqueMapping.begin(), uniqueMapping.end(), - [mappingToCheck](const auto& mapping) { return mapping == mappingToCheck; }); +bool InputCore::CheckIfMappingExists( + const std::vector& unique_mapping, + Settings::InputDeviceMapping mapping_to_check) { + return std::any_of( + unique_mapping.begin(), unique_mapping.end(), + [mapping_to_check](const auto& mapping) { return mapping == mapping_to_check; }); } std::vector InputCore::GatherUniqueMappings() { - std::vector uniqueMappings; + std::vector unique_mappings; for (const auto& mapping : Settings::values.input_mappings) { - if (!CheckIfMappingExists(uniqueMappings, mapping)) { - uniqueMappings.push_back(mapping); + if (!CheckIfMappingExists(unique_mappings, mapping)) { + unique_mappings.push_back(mapping); } } - if (!CheckIfMappingExists(uniqueMappings, Settings::values.pad_circle_modifier)) { - uniqueMappings.push_back(Settings::values.pad_circle_modifier); + if (!CheckIfMappingExists(unique_mappings, Settings::values.pad_circle_modifier)) { + unique_mappings.push_back(Settings::values.pad_circle_modifier); } - return uniqueMappings; + return unique_mappings; } void InputCore::BuildKeyMapping() { @@ -237,7 +239,7 @@ std::vector> InputCore::GetAllDevices() { } Settings::InputDeviceMapping InputCore::DetectInput(int max_time, - std::function update_GUI) { + std::function update_gui) { auto devices = GetAllDevices(); for (auto& device : devices) { device->Clear(); @@ -245,7 +247,7 @@ Settings::InputDeviceMapping InputCore::DetectInput(int max_time, Settings::InputDeviceMapping input_device; auto start = std::chrono::high_resolution_clock::now(); while (input_device.key == -1) { - update_GUI(); + update_gui(); auto duration = std::chrono::duration_cast( std::chrono::high_resolution_clock::now() - start) .count(); diff --git a/src/input_core/input_core.h b/src/input_core/input_core.h index 77170e50a..63dfbeec1 100644 --- a/src/input_core/input_core.h +++ b/src/input_core/input_core.h @@ -1,4 +1,4 @@ -// Copyright 2016 Citra Emulator Project +// Copyright 2017 Citra Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. @@ -92,6 +92,7 @@ private: static u16 touch_x; ///< Touchpad X-position in native 3DS pixel coordinates (0-320) static u16 touch_y; ///< Touchpad Y-position in native 3DS pixel coordinates (0-240) static bool touch_pressed; ///< True if touchpad area is currently pressed, otherwise false + static const float input_detect_threshold; /** * Loops through all unique input devices, and all bound inputs to update the emulator's input diff --git a/src/input_core/key_map.cpp b/src/input_core/key_map.cpp index 2ff9197f1..bd5ee9bc0 100644 --- a/src/input_core/key_map.cpp +++ b/src/input_core/key_map.cpp @@ -1,4 +1,4 @@ -// Copyright 2016 Citra Emulator Project +// Copyright 2017 Citra Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. diff --git a/src/input_core/key_map.h b/src/input_core/key_map.h index 2447a8847..57acced33 100644 --- a/src/input_core/key_map.h +++ b/src/input_core/key_map.h @@ -1,4 +1,4 @@ -// Copyright 2016 Citra Emulator Project +// Copyright 2017 Citra Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included.