From 03631f9b8fe75cf1c3a70a3094aeddcebffa4cf9 Mon Sep 17 00:00:00 2001 From: wwylele Date: Thu, 12 May 2016 13:09:36 +0300 Subject: Refactor input subsystem --- src/common/key_map.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) (limited to 'src/common/key_map.h') diff --git a/src/common/key_map.h b/src/common/key_map.h index 68f7e2f99..0438a14e0 100644 --- a/src/common/key_map.h +++ b/src/common/key_map.h @@ -4,11 +4,42 @@ #pragma once +#include #include #include "core/hle/service/hid/hid.h" +class EmuWindow; + namespace KeyMap { +enum class IndirectTarget { + CIRCLE_PAD_UP, CIRCLE_PAD_DOWN, CIRCLE_PAD_LEFT, CIRCLE_PAD_RIGHT, +}; + +/** + * Represents a key mapping target. It can be a PadState that represents 3DS real 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(Service::HID::PadState pad) : direct(true) { + target.direct_target_hex = pad.hex; + } + + KeyTarget(IndirectTarget i) : direct(false) { + target.indirect_target = i; + } +}; + /** * Represents a key for a specific host device. */ @@ -27,19 +58,31 @@ struct HostDeviceKey { } }; +extern const std::array mapping_targets; + /** * Generates a new device id, which uniquely identifies a host device within KeyMap. */ int NewDeviceId(); /** - * Maps a device-specific key to a PadState. + * Maps a device-specific key to a target (a PadState or an IndirectTarget). + */ +void SetKeyMapping(HostDeviceKey key, KeyTarget target); + +/** + * Clears all key mappings belonging to one device. + */ +void ClearKeyMapping(int device_id); + +/** + * Maps a key press actions and call the corresponding function in EmuWindow */ -void SetKeyMapping(HostDeviceKey key, Service::HID::PadState padState); +void PressKey(EmuWindow& emu_window, HostDeviceKey key); /** - * Gets the PadState that's mapped to the provided device-specific key. + * Maps a key release actions and call the corresponding function in EmuWindow */ -Service::HID::PadState GetPadKey(HostDeviceKey key); +void ReleaseKey(EmuWindow& emu_window, HostDeviceKey key); } -- cgit v1.2.3 From 416faa20d1156ac4e8646710e9c1f9565c0ed14b Mon Sep 17 00:00:00 2001 From: wwylele Date: Fri, 13 May 2016 18:32:43 +0300 Subject: implement circle pad modifier --- src/citra/config.cpp | 2 ++ src/citra/default_ini.h | 5 +++++ src/citra_qt/config.cpp | 3 +++ src/common/key_map.cpp | 20 +++++++++++++++++--- src/common/key_map.h | 6 +++++- src/core/settings.h | 6 +++++- 6 files changed, 37 insertions(+), 5 deletions(-) (limited to 'src/common/key_map.h') diff --git a/src/citra/config.cpp b/src/citra/config.cpp index 4f6d0a464..fb8dd9ba3 100644 --- a/src/citra/config.cpp +++ b/src/citra/config.cpp @@ -53,6 +53,7 @@ static const std::array defaults = { // indirectly mapped keys SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, + SDL_SCANCODE_D, }; void Config::ReadValues() { @@ -61,6 +62,7 @@ void Config::ReadValues() { Settings::values.input_mappings[Settings::NativeInput::All[i]] = sdl2_config->GetInteger("Controls", Settings::NativeInput::Mapping[i], defaults[i]); } + Settings::values.pad_circle_modifier_scale = (float)sdl2_config->GetReal("Controls", "pad_circle_modifier_scale", 0.5); // Core Settings::values.frame_skip = sdl2_config->GetInteger("Core", "frame_skip", 0); diff --git a/src/citra/default_ini.h b/src/citra/default_ini.h index d0b258cab..a9017dcb3 100644 --- a/src/citra/default_ini.h +++ b/src/citra/default_ini.h @@ -31,6 +31,11 @@ pad_circle_up = pad_circle_down = pad_circle_left = pad_circle_right = +pad_circle_modifier = + +# The applied modifier scale to circle pad. +# Must be in range of 0.0-1.0. Defaults to 0.5 +pad_circle_modifier_scale = [Core] # The applied frameskip amount. Must be a power of two. diff --git a/src/citra_qt/config.cpp b/src/citra_qt/config.cpp index ebee8c821..539fafb6f 100644 --- a/src/citra_qt/config.cpp +++ b/src/citra_qt/config.cpp @@ -31,6 +31,7 @@ static const std::array defaults = // indirectly mapped keys Qt::Key_Up, Qt::Key_Down, Qt::Key_Left, Qt::Key_Right, + Qt::Key_D, }; void Config::ReadValues() { @@ -39,6 +40,7 @@ void Config::ReadValues() { Settings::values.input_mappings[Settings::NativeInput::All[i]] = qt_config->value(QString::fromStdString(Settings::NativeInput::Mapping[i]), defaults[i]).toInt(); } + Settings::values.pad_circle_modifier_scale = qt_config->value("pad_circle_modifier_scale", 0.5).toFloat(); qt_config->endGroup(); qt_config->beginGroup("Core"); @@ -128,6 +130,7 @@ void Config::SaveValues() { qt_config->setValue(QString::fromStdString(Settings::NativeInput::Mapping[i]), Settings::values.input_mappings[Settings::NativeInput::All[i]]); } + qt_config->setValue("pad_circle_modifier_scale", (double)Settings::values.pad_circle_modifier_scale); qt_config->endGroup(); qt_config->beginGroup("Core"); diff --git a/src/common/key_map.cpp b/src/common/key_map.cpp index c8f168aa1..61572cde6 100644 --- a/src/common/key_map.cpp +++ b/src/common/key_map.cpp @@ -23,12 +23,17 @@ const std::array mapping_targets = IndirectTarget::CIRCLE_PAD_DOWN, IndirectTarget::CIRCLE_PAD_LEFT, IndirectTarget::CIRCLE_PAD_RIGHT, + IndirectTarget::CIRCLE_PAD_MODIFIER, }}; static std::map key_map; static int next_device_id = 0; -static bool circle_pad_up = false, circle_pad_down = false, circle_pad_left = false, circle_pad_right = false; +static bool circle_pad_up = false; +static bool circle_pad_down = false; +static bool circle_pad_left = false; +static bool circle_pad_right = false; +static bool circle_pad_modifier = false; static void UpdateCirclePad(EmuWindow& emu_window) { constexpr float SQRT_HALF = 0.707106781; @@ -42,8 +47,9 @@ static void UpdateCirclePad(EmuWindow& emu_window) { ++y; if (circle_pad_down) --y; - // TODO: apply modifier here - emu_window.CirclePadUpdated(x * (y == 0 ? 1.0 : SQRT_HALF), y * (x == 0 ? 1.0 : SQRT_HALF)); + + float modifier = circle_pad_modifier ? Settings::values.pad_circle_modifier_scale : 1.0; + emu_window.CirclePadUpdated(x * modifier * (y == 0 ? 1.0 : SQRT_HALF), y * modifier * (x == 0 ? 1.0 : SQRT_HALF)); } int NewDeviceId() { @@ -89,6 +95,10 @@ void PressKey(EmuWindow& emu_window, HostDeviceKey key) { circle_pad_right = true; UpdateCirclePad(emu_window); break; + case IndirectTarget::CIRCLE_PAD_MODIFIER: + circle_pad_modifier = true; + UpdateCirclePad(emu_window); + break; } } } @@ -118,6 +128,10 @@ void ReleaseKey(EmuWindow& emu_window,HostDeviceKey key) { circle_pad_right = false; UpdateCirclePad(emu_window); break; + case IndirectTarget::CIRCLE_PAD_MODIFIER: + circle_pad_modifier = false; + UpdateCirclePad(emu_window); + break; } } } diff --git a/src/common/key_map.h b/src/common/key_map.h index 0438a14e0..ec371bdde 100644 --- a/src/common/key_map.h +++ b/src/common/key_map.h @@ -13,7 +13,11 @@ class EmuWindow; namespace KeyMap { enum class IndirectTarget { - CIRCLE_PAD_UP, CIRCLE_PAD_DOWN, CIRCLE_PAD_LEFT, CIRCLE_PAD_RIGHT, + CIRCLE_PAD_UP, + CIRCLE_PAD_DOWN, + CIRCLE_PAD_LEFT, + CIRCLE_PAD_RIGHT, + CIRCLE_PAD_MODIFIER, }; /** diff --git a/src/core/settings.h b/src/core/settings.h index df5915442..d6f8f2ff3 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -22,6 +22,7 @@ enum Values { // indirectly mapped keys CIRCLE_UP, CIRCLE_DOWN, CIRCLE_LEFT, CIRCLE_RIGHT, + CIRCLE_MODIFIER, NUM_INPUTS }; @@ -35,7 +36,8 @@ static const std::array Mapping = {{ "pad_cup", "pad_cdown", "pad_cleft", "pad_cright", // indirectly mapped keys - "pad_circle_up", "pad_circle_down", "pad_circle_left", "pad_circle_right" + "pad_circle_up", "pad_circle_down", "pad_circle_left", "pad_circle_right", + "pad_circle_modifier", }}; static const std::array All = {{ A, B, X, Y, @@ -44,6 +46,7 @@ static const std::array All = {{ DUP, DDOWN, DLEFT, DRIGHT, CUP, CDOWN, CLEFT, CRIGHT, CIRCLE_UP, CIRCLE_DOWN, CIRCLE_LEFT, CIRCLE_RIGHT, + CIRCLE_MODIFIER, }}; } @@ -51,6 +54,7 @@ static const std::array All = {{ struct Values { // Controls std::array input_mappings; + float pad_circle_modifier_scale; // Core int frame_skip; -- cgit v1.2.3 From 6d49e4621c7ea7565262998782ff52910940fcd9 Mon Sep 17 00:00:00 2001 From: wwylele Date: Sun, 15 May 2016 13:35:45 +0300 Subject: fixup! Refactor input system --- src/common/key_map.cpp | 30 +++++++++++++++--------------- src/common/key_map.h | 14 +++++++++----- 2 files changed, 24 insertions(+), 20 deletions(-) (limited to 'src/common/key_map.h') diff --git a/src/common/key_map.cpp b/src/common/key_map.cpp index 61572cde6..ad311d66b 100644 --- a/src/common/key_map.cpp +++ b/src/common/key_map.cpp @@ -19,11 +19,11 @@ const std::array mapping_targets = 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, - IndirectTarget::CIRCLE_PAD_UP, - IndirectTarget::CIRCLE_PAD_DOWN, - IndirectTarget::CIRCLE_PAD_LEFT, - IndirectTarget::CIRCLE_PAD_RIGHT, - IndirectTarget::CIRCLE_PAD_MODIFIER, + IndirectTarget::CirclePadUp, + IndirectTarget::CirclePadDown, + IndirectTarget::CirclePadLeft, + IndirectTarget::CirclePadRight, + IndirectTarget::CirclePadModifier, }}; static std::map key_map; @@ -79,23 +79,23 @@ void PressKey(EmuWindow& emu_window, HostDeviceKey key) { emu_window.ButtonPressed({{target->second.target.direct_target_hex}}); } else { switch (target->second.target.indirect_target) { - case IndirectTarget::CIRCLE_PAD_UP: + case IndirectTarget::CirclePadUp: circle_pad_up = true; UpdateCirclePad(emu_window); break; - case IndirectTarget::CIRCLE_PAD_DOWN: + case IndirectTarget::CirclePadDown: circle_pad_down = true; UpdateCirclePad(emu_window); break; - case IndirectTarget::CIRCLE_PAD_LEFT: + case IndirectTarget::CirclePadLeft: circle_pad_left = true; UpdateCirclePad(emu_window); break; - case IndirectTarget::CIRCLE_PAD_RIGHT: + case IndirectTarget::CirclePadRight: circle_pad_right = true; UpdateCirclePad(emu_window); break; - case IndirectTarget::CIRCLE_PAD_MODIFIER: + case IndirectTarget::CirclePadModifier: circle_pad_modifier = true; UpdateCirclePad(emu_window); break; @@ -112,23 +112,23 @@ void ReleaseKey(EmuWindow& emu_window,HostDeviceKey key) { emu_window.ButtonReleased({{target->second.target.direct_target_hex}}); } else { switch (target->second.target.indirect_target) { - case IndirectTarget::CIRCLE_PAD_UP: + case IndirectTarget::CirclePadUp: circle_pad_up = false; UpdateCirclePad(emu_window); break; - case IndirectTarget::CIRCLE_PAD_DOWN: + case IndirectTarget::CirclePadDown: circle_pad_down = false; UpdateCirclePad(emu_window); break; - case IndirectTarget::CIRCLE_PAD_LEFT: + case IndirectTarget::CirclePadLeft: circle_pad_left = false; UpdateCirclePad(emu_window); break; - case IndirectTarget::CIRCLE_PAD_RIGHT: + case IndirectTarget::CirclePadRight: circle_pad_right = false; UpdateCirclePad(emu_window); break; - case IndirectTarget::CIRCLE_PAD_MODIFIER: + case IndirectTarget::CirclePadModifier: circle_pad_modifier = false; UpdateCirclePad(emu_window); break; diff --git a/src/common/key_map.h b/src/common/key_map.h index ec371bdde..4b585c1b9 100644 --- a/src/common/key_map.h +++ b/src/common/key_map.h @@ -12,12 +12,16 @@ class EmuWindow; namespace KeyMap { +/** + * Represents a key mapping target that are not 3DS real buttons. + * They will be handled by KeyMap and translated to 3DS input. + */ enum class IndirectTarget { - CIRCLE_PAD_UP, - CIRCLE_PAD_DOWN, - CIRCLE_PAD_LEFT, - CIRCLE_PAD_RIGHT, - CIRCLE_PAD_MODIFIER, + CirclePadUp, + CirclePadDown, + CirclePadLeft, + CirclePadRight, + CirclePadModifier, }; /** -- cgit v1.2.3 From 6cccdcacd2c8dc442db5a8ece5e754b0ed655d8b Mon Sep 17 00:00:00 2001 From: wwylele Date: Sun, 15 May 2016 19:35:06 +0300 Subject: fixup! fixup! Refactor input system --- src/common/emu_window.h | 6 +++--- src/common/key_map.h | 8 ++++---- src/core/hle/service/hid/hid.cpp | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/common/key_map.h') diff --git a/src/common/emu_window.h b/src/common/emu_window.h index 0ae3ea2af..57e303b6d 100644 --- a/src/common/emu_window.h +++ b/src/common/emu_window.h @@ -75,14 +75,14 @@ public: /** * Signals a button press action to the HID module. * @param pad_state indicates which button to press - * @note only handle real buttons (A/B/X/Y/...), excluding analog input like circle pad. + * @note only handles real buttons (A/B/X/Y/...), excluding analog inputs like the circle pad. */ void ButtonPressed(Service::HID::PadState pad_state); /** * Signals a button release action to the HID module. * @param pad_state indicates which button to press - * @note only handle real buttons (A/B/X/Y/...), excluding analog input like circle pad. + * @note only handles real buttons (A/B/X/Y/...), excluding analog inputs like the circle pad. */ void ButtonReleased(Service::HID::PadState pad_state); @@ -123,7 +123,7 @@ public: } /** - * Gets the current cirle pad state. + * Gets the current circle pad state. * @note This should be called by the core emu thread to get a state set by the window thread. * @todo Fix this function to be thread-safe. * @return std::tuple of (x, y), where `x` and `y` are the circle pad coordinates diff --git a/src/common/key_map.h b/src/common/key_map.h index 4b585c1b9..b62f017c6 100644 --- a/src/common/key_map.h +++ b/src/common/key_map.h @@ -13,7 +13,7 @@ class EmuWindow; namespace KeyMap { /** - * Represents a key mapping target that are not 3DS real buttons. + * Represents key mapping targets that are not real 3DS buttons. * They will be handled by KeyMap and translated to 3DS input. */ enum class IndirectTarget { @@ -25,7 +25,7 @@ enum class IndirectTarget { }; /** - * Represents a key mapping target. It can be a PadState that represents 3DS real buttons, + * Represents a key mapping target. It can be a PadState that represents real 3DS buttons, * or an IndirectTarget. */ struct KeyTarget { @@ -84,12 +84,12 @@ void SetKeyMapping(HostDeviceKey key, KeyTarget target); void ClearKeyMapping(int device_id); /** - * Maps a key press actions and call the corresponding function in EmuWindow + * Maps a key press action and call the corresponding function in EmuWindow */ void PressKey(EmuWindow& emu_window, HostDeviceKey key); /** - * Maps a key release actions and call the corresponding function in EmuWindow + * Maps a key release action and call the corresponding function in EmuWindow */ void ReleaseKey(EmuWindow& emu_window, HostDeviceKey key); diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index a48184495..c975433f4 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -74,7 +74,7 @@ void Update() { PadState state = VideoCore::g_emu_window->GetPadState(); - // Get current circle pad positon and update circle pad direction + // Get current circle pad position and update circle pad direction s16 circle_pad_x, circle_pad_y; std::tie(circle_pad_x, circle_pad_y) = VideoCore::g_emu_window->GetCirclePadState(); state.hex |= GetCirclePadDirectionState(circle_pad_x, circle_pad_y).hex; -- cgit v1.2.3