From 6ad7260471271859c7bae01f637580ef4955334d Mon Sep 17 00:00:00 2001 From: Anon Date: Sat, 6 Aug 2016 17:09:25 -0500 Subject: [PATCH] Fix travis build. Fix more code style issues --- src/citra/emu_window/emu_window_sdl2.cpp | 2 +- src/citra_qt/bootmanager.cpp | 4 +- src/input_core/devices/IDevice.h | 1 - src/input_core/devices/Keyboard.cpp | 8 +- src/input_core/devices/Keyboard.h | 4 +- src/input_core/devices/SDLGamepad.cpp | 20 ++--- src/input_core/devices/SDLGamepad.h | 3 +- src/input_core/input_core.cpp | 34 ++++---- src/input_core/input_core.h | 22 ++--- src/input_core/key_map.cpp | 104 +++++++++++------------ src/input_core/key_map.h | 84 +++++++++--------- 11 files changed, 143 insertions(+), 143 deletions(-) diff --git a/src/citra/emu_window/emu_window_sdl2.cpp b/src/citra/emu_window/emu_window_sdl2.cpp index 7d5372277..75161ff03 100644 --- a/src/citra/emu_window/emu_window_sdl2.cpp +++ b/src/citra/emu_window/emu_window_sdl2.cpp @@ -42,7 +42,7 @@ void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) { } void EmuWindow_SDL2::OnKeyEvent(SDL_Keysym key, u8 state) { - auto& keyboard = InputCore::GetKeyboard(); + auto keyboard = InputCore::GetKeyboard(); KeyboardKey param = KeyboardKey(key.sym, key.scancode, SDL_GetKeyName(key.scancode)); if (state == SDL_PRESSED) { diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp index 15d595564..d24cdbcb7 100644 --- a/src/citra_qt/bootmanager.cpp +++ b/src/citra_qt/bootmanager.cpp @@ -237,14 +237,14 @@ void GRenderWindow::closeEvent(QCloseEvent* event) { void GRenderWindow::keyPressEvent(QKeyEvent* event) { - auto& keyboard = InputCore::GetKeyboard(); + auto keyboard = InputCore::GetKeyboard(); KeyboardKey param = KeyboardKey(event->key(), event->nativeScanCode(), QKeySequence(event->key()).toString().toStdString()); keyboard->KeyPressed(param); } void GRenderWindow::keyReleaseEvent(QKeyEvent* event) { - auto& keyboard = InputCore::GetKeyboard(); + auto keyboard = InputCore::GetKeyboard(); KeyboardKey param = KeyboardKey(event->key(), event->nativeScanCode(), QKeySequence(event->key()).toString().toStdString()); keyboard->KeyReleased(param); } diff --git a/src/input_core/devices/IDevice.h b/src/input_core/devices/IDevice.h index e262d8879..2262996ae 100644 --- a/src/input_core/devices/IDevice.h +++ b/src/input_core/devices/IDevice.h @@ -18,5 +18,4 @@ public: virtual bool CloseDevice() = 0; protected: std::map> keyMapping; ///< Maps the string in the settings file to the HID Padstate object - }; diff --git a/src/input_core/devices/Keyboard.cpp b/src/input_core/devices/Keyboard.cpp index a4fd8475f..9638203cf 100644 --- a/src/input_core/devices/Keyboard.cpp +++ b/src/input_core/devices/Keyboard.cpp @@ -23,17 +23,17 @@ void Keyboard::ProcessInput() { std::lock_guard lock(m); keysPressedCopy = keysPressed; } - for (const auto &ent1 : keyMapping) { - int scancode = std::stoul(ent1.first, nullptr, 16); + for (const auto& entry : keyMapping) { + int scancode = std::stoul(entry.first, nullptr, 16); KeyboardKey proxy = KeyboardKey(0, scancode, ""); if (keysPressedCopy[proxy] == true && keysPressedLast[scancode] == false) { - for (const auto& key : ent1.second) { + for (const auto& key : entry.second) { KeyMap::PressKey(key, 1.0); } keysPressedLast[scancode] = true; } else if (keysPressedCopy[proxy] == false && keysPressedLast[scancode] == true) { - for (const auto& key : ent1.second) { + for (const auto& key : entry.second) { KeyMap::ReleaseKey(key); } keysPressedLast[scancode] = false; diff --git a/src/input_core/devices/Keyboard.h b/src/input_core/devices/Keyboard.h index d8271abc7..82a1f9c57 100644 --- a/src/input_core/devices/Keyboard.h +++ b/src/input_core/devices/Keyboard.h @@ -32,7 +32,9 @@ struct KeyboardKey { uint32_t scancode; std::string character; - KeyboardKey(uint32_t key_, uint32_t scancode_, std::string character_) : key(key_), scancode(scancode_), character(std::move(character_)) { + KeyboardKey(uint32_t key_, uint32_t scancode_, std::string character_) + : key(key_), scancode(scancode_), character(std::move(character_)) + { } bool operator==(const KeyboardKey& other) const { return scancode == other.scancode; diff --git a/src/input_core/devices/SDLGamepad.cpp b/src/input_core/devices/SDLGamepad.cpp index 0ac5652fe..b722bea13 100644 --- a/src/input_core/devices/SDLGamepad.cpp +++ b/src/input_core/devices/SDLGamepad.cpp @@ -47,29 +47,29 @@ void SDLGamepad::ProcessInput() { if (gamepad == nullptr) return; SDL_GameControllerUpdate(); - for (const auto &ent1 : keyMapping) { - SDL_GameControllerButton button = SDL_GameControllerGetButtonFromString(friendlyNameMapping[ent1.first].c_str()); + for (const auto& entry : keyMapping) { + SDL_GameControllerButton button = SDL_GameControllerGetButtonFromString(friendlyNameMapping[entry.first].c_str()); if (button != SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_INVALID) { Uint8 pressed = SDL_GameControllerGetButton(gamepad, button); - if (pressed == 1 && keysPressed[ent1.first] == false) { - for (const auto& padstate : ent1.second) { + if (pressed == 1 && keysPressed[entry.first] == false) { + for (const auto& padstate : entry.second) { KeyMap::PressKey(padstate, 1.0); - keysPressed[ent1.first] = true; + keysPressed[entry.first] = true; } } - else if (pressed == 0 && keysPressed[ent1.first] == true) { - for (const auto& padstate : ent1.second) { + else if (pressed == 0 && keysPressed[entry.first] == true) { + for (const auto& padstate : entry.second) { KeyMap::ReleaseKey(padstate); - keysPressed[ent1.first] = false; + keysPressed[entry.first] = false; } } } else { // Try axis if button isn't valid - SDL_GameControllerAxis axis = SDL_GameControllerGetAxisFromString(friendlyNameMapping[ent1.first].c_str()); + SDL_GameControllerAxis axis = SDL_GameControllerGetAxisFromString(friendlyNameMapping[entry.first].c_str()); if (axis != SDL_GameControllerAxis::SDL_CONTROLLER_AXIS_INVALID) { Sint16 value = SDL_GameControllerGetAxis(gamepad, axis); - for (const auto& padstate : ent1.second) { + for (const auto& padstate : entry.second) { // dont process if in deadzone. Replace later with settings for deadzone. if (abs(value) < 0.2 * 32767.0) KeyMap::ReleaseKey(padstate); diff --git a/src/input_core/devices/SDLGamepad.h b/src/input_core/devices/SDLGamepad.h index d33b6fba8..6e41ab1ba 100644 --- a/src/input_core/devices/SDLGamepad.h +++ b/src/input_core/devices/SDLGamepad.h @@ -17,7 +17,8 @@ public: void ProcessInput() override; bool CloseDevice() override; private: - std::map friendlyNameMapping = { /// Maps the friendly name shown on GUI with the string name for getting the SDL button instance. + /// Maps the friendly name shown on GUI with the string name for getting the SDL button instance. + std::map friendlyNameMapping = { { "Button A","a" }, { "Button B","b" }, { "Button X","x" }, diff --git a/src/input_core/input_core.cpp b/src/input_core/input_core.cpp index 788326cd7..1f489e3b5 100644 --- a/src/input_core/input_core.cpp +++ b/src/input_core/input_core.cpp @@ -14,10 +14,10 @@ namespace InputCore { constexpr u64 frame_ticks = 268123480ull / 60; static int tick_event; -Service::HID::PadState pad_state; -std::tuple circle_pad = { 0,0 }; -std::shared_ptr main_keyboard; -std::vector> devices; ///< Devices that are handling input for the game +static Service::HID::PadState pad_state; +static std::tuple circle_pad = { 0,0 }; +static std::shared_ptr main_keyboard; +static std::vector> devices; ///< Devices that are handling input for the game static void InputTickCallback(u64, int cycles_late) { for (auto& device : devices) @@ -43,7 +43,7 @@ Service::HID::PadState GetPadState() { return pad_state; } -void SetPadState(Service::HID::PadState& state) { +void SetPadState(const Service::HID::PadState& state) { pad_state.hex = state.hex; } @@ -51,7 +51,7 @@ std::tuple GetCirclePad() { return circle_pad; } -void SetCirclePad(std::tuple& pad) { +void SetCirclePad(std::tuple pad) { circle_pad = pad; } @@ -59,11 +59,11 @@ std::shared_ptr GetKeyboard() { return main_keyboard; } -///Get Unique input mappings from settings -std::vector GatherUniqueMappings() { +/// Get Unique input mappings from settings +static std::vector GatherUniqueMappings() { std::vector uniqueMappings; - for (auto& mapping : Settings::values.input_mappings) { + for (const auto& mapping : Settings::values.input_mappings) { if (!CheckIfMappingExists(uniqueMappings, mapping)) { uniqueMappings.push_back(mapping); } @@ -71,9 +71,9 @@ std::vector GatherUniqueMappings() { return uniqueMappings; } -std::map> BuildKeyMapping(Settings::InputDeviceMapping mapping) { +static std::map> BuildKeyMapping(Settings::InputDeviceMapping mapping) { std::map> keyMapping; - for (int i = 0; i < Settings::values.input_mappings.size(); i++) { + for (size_t i = 0; i < Settings::values.input_mappings.size(); i++) { KeyMap::KeyTarget val = KeyMap::mapping_targets[i]; std::string key = Settings::values.input_mappings[i].key; if (Settings::values.input_mappings[i] == mapping) { @@ -83,10 +83,10 @@ std::map> BuildKeyMapping(Settings:: return keyMapping; } -///Generate a device for each unique mapping -void GenerateUniqueDevices(std::vector uniqueMappings) { +/// Generate a device for each unique mapping +static void GenerateUniqueDevices(const std::vector& uniqueMappings) { std::shared_ptr input; - for (auto& mapping : uniqueMappings) { + for (const auto& mapping : uniqueMappings) { switch (mapping.framework) { case Settings::DeviceFramework::Qt: { @@ -109,19 +109,17 @@ void GenerateUniqueDevices(std::vector uniqueMappi } devices.push_back(input); - //Build map of inputs to listen for, for this device + // Build map of inputs to listen for, for this device auto keyMapping = BuildKeyMapping(mapping); input->InitDevice(mapping.number, keyMapping); } } void ParseSettings() { - std::vector> devices; - auto uniqueMappings = GatherUniqueMappings(); GenerateUniqueDevices(uniqueMappings); - //init keyboard, if it hasn't already + // init keyboard, if it hasn't already if (main_keyboard == nullptr) main_keyboard = std::make_shared(); } diff --git a/src/input_core/input_core.h b/src/input_core/input_core.h index ddd856867..4400c04fa 100644 --- a/src/input_core/input_core.h +++ b/src/input_core/input_core.h @@ -14,16 +14,16 @@ class Keyboard; namespace InputCore { - void Init(); - void Shutdown(); - Service::HID::PadState GetPadState(); - void SetPadState(Service::HID::PadState& state); - std::tuple GetCirclePad(); - void SetCirclePad(std::tuple& circle ); - std::shared_ptr GetKeyboard(); - /// Read settings to initialize devices - void ParseSettings(); +void Init(); +void Shutdown(); +Service::HID::PadState GetPadState(); +void SetPadState(const Service::HID::PadState& state); +std::tuple GetCirclePad(); +void SetCirclePad(std::tuple circle); +std::shared_ptr GetKeyboard(); +/// Read settings to initialize devices +void ParseSettings(); - /// Helper method to check if device was already initialized - bool CheckIfMappingExists(const std::vector& uniqueMapping, Settings::InputDeviceMapping mappingToCheck); +/// Helper method to check if device was already initialized +bool CheckIfMappingExists(const std::vector& uniqueMapping, Settings::InputDeviceMapping mappingToCheck); } diff --git a/src/input_core/key_map.cpp b/src/input_core/key_map.cpp index 4f271df28..69741ddfe 100644 --- a/src/input_core/key_map.cpp +++ b/src/input_core/key_map.cpp @@ -12,62 +12,62 @@ #include "input_core/key_map.h" namespace KeyMap { - constexpr int MAX_CIRCLEPAD_POS = 0x9C; /// Max value for a circle pad position - const std::array mapping_targets = { { - Service::HID::PAD_A, Service::HID::PAD_B, Service::HID::PAD_X, Service::HID::PAD_Y, - Service::HID::PAD_L, Service::HID::PAD_R, Service::HID::PAD_ZL, Service::HID::PAD_ZR, - Service::HID::PAD_START, Service::HID::PAD_SELECT, Service::HID::PAD_TOUCH, - Service::HID::PAD_UP, Service::HID::PAD_DOWN, Service::HID::PAD_LEFT, Service::HID::PAD_RIGHT, - Service::HID::PAD_C_UP, Service::HID::PAD_C_DOWN, Service::HID::PAD_C_LEFT, Service::HID::PAD_C_RIGHT, +constexpr int MAX_CIRCLEPAD_POS = 0x9C; /// Max value for a circle pad position +const std::array mapping_targets = { { + Service::HID::PAD_A, Service::HID::PAD_B, Service::HID::PAD_X, Service::HID::PAD_Y, + Service::HID::PAD_L, Service::HID::PAD_R, Service::HID::PAD_ZL, Service::HID::PAD_ZR, + Service::HID::PAD_START, Service::HID::PAD_SELECT, Service::HID::PAD_TOUCH, + Service::HID::PAD_UP, Service::HID::PAD_DOWN, Service::HID::PAD_LEFT, Service::HID::PAD_RIGHT, + Service::HID::PAD_C_UP, Service::HID::PAD_C_DOWN, Service::HID::PAD_C_LEFT, Service::HID::PAD_C_RIGHT, - Service::HID::PAD_CIRCLE_UP, - Service::HID::PAD_CIRCLE_DOWN, - Service::HID::PAD_CIRCLE_LEFT, - Service::HID::PAD_CIRCLE_RIGHT, - } }; - ///Array of inputs that are analog only, and require a strength when set - const std::array analog_inputs = { - Service::HID::PAD_CIRCLE_UP, - Service::HID::PAD_CIRCLE_DOWN, - Service::HID::PAD_CIRCLE_LEFT, - Service::HID::PAD_CIRCLE_RIGHT - }; + Service::HID::PAD_CIRCLE_UP, + Service::HID::PAD_CIRCLE_DOWN, + Service::HID::PAD_CIRCLE_LEFT, + Service::HID::PAD_CIRCLE_RIGHT, +} }; +///Array of inputs that are analog only, and require a strength when set +const std::array analog_inputs = { + Service::HID::PAD_CIRCLE_UP, + Service::HID::PAD_CIRCLE_DOWN, + Service::HID::PAD_CIRCLE_LEFT, + Service::HID::PAD_CIRCLE_RIGHT +}; - void PressKey(KeyTarget target, const float strength) { - auto pad_state = InputCore::GetPadState(); - // If is digital keytarget - if (std::find(std::begin(analog_inputs), std::end(analog_inputs), target) == std::end(analog_inputs)) { - pad_state.hex |= target.target.direct_target_hex; - InputCore::SetPadState(pad_state); - } - else { // it is analog input - auto circle_pad = InputCore::GetCirclePad(); - if (target == Service::HID::PAD_CIRCLE_UP || target == Service::HID::PAD_CIRCLE_DOWN) { - std::get<1>(circle_pad) = MAX_CIRCLEPAD_POS * strength * -1; - } - else if (target == Service::HID::PAD_CIRCLE_LEFT || target == Service::HID::PAD_CIRCLE_RIGHT) { - std::get<0>(circle_pad) = MAX_CIRCLEPAD_POS * strength; - } - InputCore::SetCirclePad(circle_pad); - } +void PressKey(KeyTarget target, const float strength) { + auto pad_state = InputCore::GetPadState(); + // If is digital keytarget + if (std::find(std::begin(analog_inputs), std::end(analog_inputs), target) == std::end(analog_inputs)) { + pad_state.hex |= target.target.direct_target_hex; + InputCore::SetPadState(pad_state); } - - void ReleaseKey(KeyTarget target) { - auto pad_state = InputCore::GetPadState(); - // If is digital keytarget - if (std::find(std::begin(analog_inputs), std::end(analog_inputs), target) == std::end(analog_inputs)) { - pad_state.hex &= ~target.target.direct_target_hex; - InputCore::SetPadState(pad_state); + else { // it is analog input + auto circle_pad = InputCore::GetCirclePad(); + if (target == Service::HID::PAD_CIRCLE_UP || target == Service::HID::PAD_CIRCLE_DOWN) { + std::get<1>(circle_pad) = MAX_CIRCLEPAD_POS * strength * -1; } - else { // it is analog input - auto circle_pad = InputCore::GetCirclePad(); - if (target == Service::HID::PAD_CIRCLE_UP || target == Service::HID::PAD_CIRCLE_DOWN) { - std::get<1>(circle_pad) = 0; - } - else if (target == Service::HID::PAD_CIRCLE_LEFT || target == Service::HID::PAD_CIRCLE_RIGHT) { - std::get<0>(circle_pad) = 0; - } - InputCore::SetCirclePad(circle_pad); + else if (target == Service::HID::PAD_CIRCLE_LEFT || target == Service::HID::PAD_CIRCLE_RIGHT) { + std::get<0>(circle_pad) = MAX_CIRCLEPAD_POS * strength; } + InputCore::SetCirclePad(circle_pad); } } + +void ReleaseKey(KeyTarget target) { + auto pad_state = InputCore::GetPadState(); + // If is digital keytarget + if (std::find(std::begin(analog_inputs), std::end(analog_inputs), target) == std::end(analog_inputs)) { + pad_state.hex &= ~target.target.direct_target_hex; + InputCore::SetPadState(pad_state); + } + else { // it is analog input + auto circle_pad = InputCore::GetCirclePad(); + if (target == Service::HID::PAD_CIRCLE_UP || target == Service::HID::PAD_CIRCLE_DOWN) { + std::get<1>(circle_pad) = 0; + } + else if (target == Service::HID::PAD_CIRCLE_LEFT || target == Service::HID::PAD_CIRCLE_RIGHT) { + std::get<0>(circle_pad) = 0; + } + InputCore::SetCirclePad(circle_pad); + } +} +} diff --git a/src/input_core/key_map.h b/src/input_core/key_map.h index 18ff2f485..0c2cef907 100644 --- a/src/input_core/key_map.h +++ b/src/input_core/key_map.h @@ -12,53 +12,53 @@ class EmuWindow; namespace KeyMap { - /** - * Represents key mapping targets that are not real 3DS buttons. - * They will be handled by KeyMap and translated to 3DS input. - */ - enum class IndirectTarget { - CirclePadUp, - CirclePadDown, - CirclePadLeft, - CirclePadRight, - CirclePadModifier - }; +/** + * Represents key mapping targets that are not real 3DS buttons. + * They will be handled by KeyMap and translated to 3DS input. + */ +enum class IndirectTarget { + CirclePadUp, + CirclePadDown, + CirclePadLeft, + CirclePadRight, + CirclePadModifier +}; - /** - * Represents a key mapping target. It can be a PadState that represents real 3DS buttons, - * or an IndirectTarget. - */ - struct KeyTarget { - bool direct; - union { - u32 direct_target_hex; - IndirectTarget indirect_target; - } target; +/** + * Represents a key mapping target. It can be a PadState that represents real 3DS buttons, + * or an IndirectTarget. + */ +struct KeyTarget { + bool direct; + union { + u32 direct_target_hex; + IndirectTarget indirect_target; + } target; - KeyTarget() : direct(true) { - target.direct_target_hex = 0; - } + KeyTarget() : direct(true) { + target.direct_target_hex = 0; + } - KeyTarget(Service::HID::PadState pad) : direct(true) { - target.direct_target_hex = pad.hex; - } + KeyTarget(Service::HID::PadState pad) : direct(true) { + target.direct_target_hex = pad.hex; + } - KeyTarget(IndirectTarget i) : direct(false) { - target.indirect_target = i; - } - const bool operator==(const Service::HID::PadState &other) const { - return this->target.direct_target_hex == other.hex; - } - const bool operator==(const KeyTarget &other) const { - return this->target.direct_target_hex == other.target.direct_target_hex; - } - }; + KeyTarget(IndirectTarget i) : direct(false) { + target.indirect_target = i; + } + const bool operator==(const Service::HID::PadState &other) const { + return this->target.direct_target_hex == other.hex; + } + const bool operator==(const KeyTarget &other) const { + return this->target.direct_target_hex == other.target.direct_target_hex; + } +}; - extern const std::array mapping_targets; +extern const std::array mapping_targets; - ///Handles the pressing of a key and modifies InputCore state - void PressKey(KeyTarget target, float strength); +///Handles the pressing of a key and modifies InputCore state +void PressKey(KeyTarget target, float strength); - ///Handles the releasing of a key and modifies InputCore state - void ReleaseKey(KeyTarget target); +///Handles the releasing of a key and modifies InputCore state +void ReleaseKey(KeyTarget target); }