diff options
| -rw-r--r-- | src/citra/config.cpp | 20 | ||||
| -rw-r--r-- | src/citra_qt/config.cpp | 27 | ||||
| -rw-r--r-- | src/citra_qt/config.h | 2 | ||||
| -rw-r--r-- | src/input_common/CMakeLists.txt | 2 | ||||
| -rwxr-xr-x | src/input_common/analog_from_button.cpp | 58 | ||||
| -rwxr-xr-x | src/input_common/analog_from_button.h | 31 | ||||
| -rw-r--r-- | src/input_common/main.cpp | 18 | ||||
| -rw-r--r-- | src/input_common/main.h | 4 |
8 files changed, 162 insertions, 0 deletions
diff --git a/src/citra/config.cpp b/src/citra/config.cpp index 818824596..ef1229912 100644 --- a/src/citra/config.cpp +++ b/src/citra/config.cpp | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | #include "citra/default_ini.h" | 8 | #include "citra/default_ini.h" |
| 9 | #include "common/file_util.h" | 9 | #include "common/file_util.h" |
| 10 | #include "common/logging/log.h" | 10 | #include "common/logging/log.h" |
| 11 | #include "common/param_package.h" | ||
| 11 | #include "config.h" | 12 | #include "config.h" |
| 12 | #include "core/settings.h" | 13 | #include "core/settings.h" |
| 13 | #include "input_common/main.h" | 14 | #include "input_common/main.h" |
| @@ -44,6 +45,15 @@ static const std::array<int, Settings::NativeButton::NumButtons> default_buttons | |||
| 44 | SDL_SCANCODE_M, SDL_SCANCODE_N, SDL_SCANCODE_1, SDL_SCANCODE_2, SDL_SCANCODE_B, | 45 | SDL_SCANCODE_M, SDL_SCANCODE_N, SDL_SCANCODE_1, SDL_SCANCODE_2, SDL_SCANCODE_B, |
| 45 | }; | 46 | }; |
| 46 | 47 | ||
| 48 | static const std::array<std::array<int, 5>, Settings::NativeAnalog::NumAnalogs> default_analogs{{ | ||
| 49 | { | ||
| 50 | SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, SDL_SCANCODE_D, | ||
| 51 | }, | ||
| 52 | { | ||
| 53 | SDL_SCANCODE_I, SDL_SCANCODE_K, SDL_SCANCODE_J, SDL_SCANCODE_L, SDL_SCANCODE_D, | ||
| 54 | }, | ||
| 55 | }}; | ||
| 56 | |||
| 47 | void Config::ReadValues() { | 57 | void Config::ReadValues() { |
| 48 | // Controls | 58 | // Controls |
| 49 | for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { | 59 | for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { |
| @@ -54,6 +64,16 @@ void Config::ReadValues() { | |||
| 54 | Settings::values.buttons[i] = default_param; | 64 | Settings::values.buttons[i] = default_param; |
| 55 | } | 65 | } |
| 56 | 66 | ||
| 67 | for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) { | ||
| 68 | std::string default_param = InputCommon::GenerateAnalogParamFromKeys( | ||
| 69 | default_analogs[i][0], default_analogs[i][1], default_analogs[i][2], | ||
| 70 | default_analogs[i][3], default_analogs[i][4], 0.5f); | ||
| 71 | Settings::values.analogs[i] = | ||
| 72 | sdl2_config->Get("Controls", Settings::NativeAnalog::mapping[i], default_param); | ||
| 73 | if (Settings::values.analogs[i].empty()) | ||
| 74 | Settings::values.analogs[i] = default_param; | ||
| 75 | } | ||
| 76 | |||
| 57 | // Core | 77 | // Core |
| 58 | Settings::values.use_cpu_jit = sdl2_config->GetBoolean("Core", "use_cpu_jit", true); | 78 | Settings::values.use_cpu_jit = sdl2_config->GetBoolean("Core", "use_cpu_jit", true); |
| 59 | 79 | ||
diff --git a/src/citra_qt/config.cpp b/src/citra_qt/config.cpp index 5855c7105..6ccfa1577 100644 --- a/src/citra_qt/config.cpp +++ b/src/citra_qt/config.cpp | |||
| @@ -22,6 +22,15 @@ const std::array<int, Settings::NativeButton::NumButtons> Config::default_button | |||
| 22 | Qt::Key_Q, Qt::Key_W, Qt::Key_M, Qt::Key_N, Qt::Key_1, Qt::Key_2, Qt::Key_B, | 22 | Qt::Key_Q, Qt::Key_W, Qt::Key_M, Qt::Key_N, Qt::Key_1, Qt::Key_2, Qt::Key_B, |
| 23 | }; | 23 | }; |
| 24 | 24 | ||
| 25 | const std::array<std::array<int, 5>, Settings::NativeAnalog::NumAnalogs> Config::default_analogs{{ | ||
| 26 | { | ||
| 27 | Qt::Key_Up, Qt::Key_Down, Qt::Key_Left, Qt::Key_Right, Qt::Key_D, | ||
| 28 | }, | ||
| 29 | { | ||
| 30 | Qt::Key_I, Qt::Key_K, Qt::Key_J, Qt::Key_L, Qt::Key_D, | ||
| 31 | }, | ||
| 32 | }}; | ||
| 33 | |||
| 25 | void Config::ReadValues() { | 34 | void Config::ReadValues() { |
| 26 | qt_config->beginGroup("Controls"); | 35 | qt_config->beginGroup("Controls"); |
| 27 | for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { | 36 | for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { |
| @@ -34,6 +43,20 @@ void Config::ReadValues() { | |||
| 34 | if (Settings::values.buttons[i].empty()) | 43 | if (Settings::values.buttons[i].empty()) |
| 35 | Settings::values.buttons[i] = default_param; | 44 | Settings::values.buttons[i] = default_param; |
| 36 | } | 45 | } |
| 46 | |||
| 47 | for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) { | ||
| 48 | std::string default_param = InputCommon::GenerateAnalogParamFromKeys( | ||
| 49 | default_analogs[i][0], default_analogs[i][1], default_analogs[i][2], | ||
| 50 | default_analogs[i][3], default_analogs[i][4], 0.5f); | ||
| 51 | Settings::values.analogs[i] = | ||
| 52 | qt_config | ||
| 53 | ->value(Settings::NativeAnalog::mapping[i], QString::fromStdString(default_param)) | ||
| 54 | .toString() | ||
| 55 | .toStdString(); | ||
| 56 | if (Settings::values.analogs[i].empty()) | ||
| 57 | Settings::values.analogs[i] = default_param; | ||
| 58 | } | ||
| 59 | |||
| 37 | qt_config->endGroup(); | 60 | qt_config->endGroup(); |
| 38 | 61 | ||
| 39 | qt_config->beginGroup("Core"); | 62 | qt_config->beginGroup("Core"); |
| @@ -158,6 +181,10 @@ void Config::SaveValues() { | |||
| 158 | qt_config->setValue(QString::fromStdString(Settings::NativeButton::mapping[i]), | 181 | qt_config->setValue(QString::fromStdString(Settings::NativeButton::mapping[i]), |
| 159 | QString::fromStdString(Settings::values.buttons[i])); | 182 | QString::fromStdString(Settings::values.buttons[i])); |
| 160 | } | 183 | } |
| 184 | for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) { | ||
| 185 | qt_config->setValue(QString::fromStdString(Settings::NativeAnalog::mapping[i]), | ||
| 186 | QString::fromStdString(Settings::values.analogs[i])); | ||
| 187 | } | ||
| 161 | qt_config->endGroup(); | 188 | qt_config->endGroup(); |
| 162 | 189 | ||
| 163 | qt_config->beginGroup("Core"); | 190 | qt_config->beginGroup("Core"); |
diff --git a/src/citra_qt/config.h b/src/citra_qt/config.h index d7bf99442..cbf745ea2 100644 --- a/src/citra_qt/config.h +++ b/src/citra_qt/config.h | |||
| @@ -24,5 +24,7 @@ public: | |||
| 24 | 24 | ||
| 25 | void Reload(); | 25 | void Reload(); |
| 26 | void Save(); | 26 | void Save(); |
| 27 | |||
| 27 | static const std::array<int, Settings::NativeButton::NumButtons> default_buttons; | 28 | static const std::array<int, Settings::NativeButton::NumButtons> default_buttons; |
| 29 | static const std::array<std::array<int, 5>, Settings::NativeAnalog::NumAnalogs> default_analogs; | ||
| 28 | }; | 30 | }; |
diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt index ac1ad45a9..9f4422269 100644 --- a/src/input_common/CMakeLists.txt +++ b/src/input_common/CMakeLists.txt | |||
| @@ -1,9 +1,11 @@ | |||
| 1 | set(SRCS | 1 | set(SRCS |
| 2 | analog_from_button.cpp | ||
| 2 | keyboard.cpp | 3 | keyboard.cpp |
| 3 | main.cpp | 4 | main.cpp |
| 4 | ) | 5 | ) |
| 5 | 6 | ||
| 6 | set(HEADERS | 7 | set(HEADERS |
| 8 | analog_from_button.h | ||
| 7 | keyboard.h | 9 | keyboard.h |
| 8 | main.h | 10 | main.h |
| 9 | ) | 11 | ) |
diff --git a/src/input_common/analog_from_button.cpp b/src/input_common/analog_from_button.cpp new file mode 100755 index 000000000..e1a260762 --- /dev/null +++ b/src/input_common/analog_from_button.cpp | |||
| @@ -0,0 +1,58 @@ | |||
| 1 | // Copyright 2017 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "input_common/analog_from_button.h" | ||
| 6 | |||
| 7 | namespace InputCommon { | ||
| 8 | |||
| 9 | class Analog final : public Input::AnalogDevice { | ||
| 10 | public: | ||
| 11 | using Button = std::unique_ptr<Input::ButtonDevice>; | ||
| 12 | |||
| 13 | Analog(Button up_, Button down_, Button left_, Button right_, Button modifier_, | ||
| 14 | float modifier_scale_) | ||
| 15 | : up(std::move(up_)), down(std::move(down_)), left(std::move(left_)), | ||
| 16 | right(std::move(right_)), modifier(std::move(modifier_)), | ||
| 17 | modifier_scale(modifier_scale_) {} | ||
| 18 | |||
| 19 | std::tuple<float, float> GetStatus() const override { | ||
| 20 | constexpr float SQRT_HALF = 0.707106781f; | ||
| 21 | int x = 0, y = 0; | ||
| 22 | |||
| 23 | if (right->GetStatus()) | ||
| 24 | ++x; | ||
| 25 | if (left->GetStatus()) | ||
| 26 | --x; | ||
| 27 | if (up->GetStatus()) | ||
| 28 | ++y; | ||
| 29 | if (down->GetStatus()) | ||
| 30 | --y; | ||
| 31 | |||
| 32 | float coef = modifier->GetStatus() ? modifier_scale : 1.0f; | ||
| 33 | return std::make_tuple(x * coef * (y == 0 ? 1.0f : SQRT_HALF), | ||
| 34 | y * coef * (x == 0 ? 1.0f : SQRT_HALF)); | ||
| 35 | } | ||
| 36 | |||
| 37 | private: | ||
| 38 | Button up; | ||
| 39 | Button down; | ||
| 40 | Button left; | ||
| 41 | Button right; | ||
| 42 | Button modifier; | ||
| 43 | float modifier_scale; | ||
| 44 | }; | ||
| 45 | |||
| 46 | std::unique_ptr<Input::AnalogDevice> AnalogFromButton::Create(const Common::ParamPackage& params) { | ||
| 47 | const std::string null_engine = Common::ParamPackage{{"engine", "null"}}.Serialize(); | ||
| 48 | auto up = Input::CreateDevice<Input::ButtonDevice>(params.Get("up", null_engine)); | ||
| 49 | auto down = Input::CreateDevice<Input::ButtonDevice>(params.Get("down", null_engine)); | ||
| 50 | auto left = Input::CreateDevice<Input::ButtonDevice>(params.Get("left", null_engine)); | ||
| 51 | auto right = Input::CreateDevice<Input::ButtonDevice>(params.Get("right", null_engine)); | ||
| 52 | auto modifier = Input::CreateDevice<Input::ButtonDevice>(params.Get("modifier", null_engine)); | ||
| 53 | auto modifier_scale = params.Get("modifier_scale", 0.5f); | ||
| 54 | return std::make_unique<Analog>(std::move(up), std::move(down), std::move(left), | ||
| 55 | std::move(right), std::move(modifier), modifier_scale); | ||
| 56 | } | ||
| 57 | |||
| 58 | } // namespace InputCommon | ||
diff --git a/src/input_common/analog_from_button.h b/src/input_common/analog_from_button.h new file mode 100755 index 000000000..bbd583dd9 --- /dev/null +++ b/src/input_common/analog_from_button.h | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | // Copyright 2017 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <memory> | ||
| 8 | #include "core/frontend/input.h" | ||
| 9 | |||
| 10 | namespace InputCommon { | ||
| 11 | |||
| 12 | /** | ||
| 13 | * An analog device factory that takes direction button devices and combines them into a analog | ||
| 14 | * device. | ||
| 15 | */ | ||
| 16 | class AnalogFromButton final : public Input::Factory<Input::AnalogDevice> { | ||
| 17 | public: | ||
| 18 | /** | ||
| 19 | * Creates an analog device from direction button devices | ||
| 20 | * @param params contains parameters for creating the device: | ||
| 21 | * - "up": a serialized ParamPackage for creating a button device for up direction | ||
| 22 | * - "down": a serialized ParamPackage for creating a button device for down direction | ||
| 23 | * - "left": a serialized ParamPackage for creating a button device for left direction | ||
| 24 | * - "right": a serialized ParamPackage for creating a button device for right direction | ||
| 25 | * - "modifier": a serialized ParamPackage for creating a button device as the modifier | ||
| 26 | * - "modifier_scale": a float for the multiplier the modifier gives to the position | ||
| 27 | */ | ||
| 28 | std::unique_ptr<Input::AnalogDevice> Create(const Common::ParamPackage& params) override; | ||
| 29 | }; | ||
| 30 | |||
| 31 | } // namespace InputCommon | ||
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index ff25220b4..8455fdc17 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #include <memory> | 5 | #include <memory> |
| 6 | #include "common/param_package.h" | 6 | #include "common/param_package.h" |
| 7 | #include "input_common/analog_from_button.h" | ||
| 7 | #include "input_common/keyboard.h" | 8 | #include "input_common/keyboard.h" |
| 8 | #include "input_common/main.h" | 9 | #include "input_common/main.h" |
| 9 | 10 | ||
| @@ -14,11 +15,14 @@ static std::shared_ptr<Keyboard> keyboard; | |||
| 14 | void Init() { | 15 | void Init() { |
| 15 | keyboard = std::make_shared<InputCommon::Keyboard>(); | 16 | keyboard = std::make_shared<InputCommon::Keyboard>(); |
| 16 | Input::RegisterFactory<Input::ButtonDevice>("keyboard", keyboard); | 17 | Input::RegisterFactory<Input::ButtonDevice>("keyboard", keyboard); |
| 18 | Input::RegisterFactory<Input::AnalogDevice>("analog_from_button", | ||
| 19 | std::make_shared<InputCommon::AnalogFromButton>()); | ||
| 17 | } | 20 | } |
| 18 | 21 | ||
| 19 | void Shutdown() { | 22 | void Shutdown() { |
| 20 | Input::UnregisterFactory<Input::ButtonDevice>("keyboard"); | 23 | Input::UnregisterFactory<Input::ButtonDevice>("keyboard"); |
| 21 | keyboard.reset(); | 24 | keyboard.reset(); |
| 25 | Input::UnregisterFactory<Input::AnalogDevice>("analog_from_button"); | ||
| 22 | } | 26 | } |
| 23 | 27 | ||
| 24 | Keyboard* GetKeyboard() { | 28 | Keyboard* GetKeyboard() { |
| @@ -32,4 +36,18 @@ std::string GenerateKeyboardParam(int key_code) { | |||
| 32 | return param.Serialize(); | 36 | return param.Serialize(); |
| 33 | } | 37 | } |
| 34 | 38 | ||
| 39 | std::string GenerateAnalogParamFromKeys(int key_up, int key_down, int key_left, int key_right, | ||
| 40 | int key_modifier, float modifier_scale) { | ||
| 41 | Common::ParamPackage circle_pad_param{ | ||
| 42 | {"engine", "analog_from_button"}, | ||
| 43 | {"up", GenerateKeyboardParam(key_up)}, | ||
| 44 | {"down", GenerateKeyboardParam(key_down)}, | ||
| 45 | {"left", GenerateKeyboardParam(key_left)}, | ||
| 46 | {"right", GenerateKeyboardParam(key_right)}, | ||
| 47 | {"modifier", GenerateKeyboardParam(key_modifier)}, | ||
| 48 | {"modifier_scale", std::to_string(modifier_scale)}, | ||
| 49 | }; | ||
| 50 | return circle_pad_param.Serialize(); | ||
| 51 | } | ||
| 52 | |||
| 35 | } // namespace InputCommon | 53 | } // namespace InputCommon |
diff --git a/src/input_common/main.h b/src/input_common/main.h index a490dd829..140bbd014 100644 --- a/src/input_common/main.h +++ b/src/input_common/main.h | |||
| @@ -22,4 +22,8 @@ Keyboard* GetKeyboard(); | |||
| 22 | /// Generates a serialized param package for creating a keyboard button device | 22 | /// Generates a serialized param package for creating a keyboard button device |
| 23 | std::string GenerateKeyboardParam(int key_code); | 23 | std::string GenerateKeyboardParam(int key_code); |
| 24 | 24 | ||
| 25 | /// Generates a serialized param package for creating an analog device taking input from keyboard | ||
| 26 | std::string GenerateAnalogParamFromKeys(int key_up, int key_down, int key_left, int key_right, | ||
| 27 | int key_modifier, float modifier_scale); | ||
| 28 | |||
| 25 | } // namespace InputCommon | 29 | } // namespace InputCommon |