diff options
| author | 2017-03-17 14:59:39 -0400 | |
|---|---|---|
| committer | 2017-03-17 14:59:39 -0400 | |
| commit | 423ab5e2bcf5a522e5f412447c05f648df57a14c (patch) | |
| tree | 1e60eaeffa59229254a47f885d2fe2cbbdc1a5c0 /src/citra | |
| parent | Merge pull request #2618 from wwylele/log-less-filename (diff) | |
| parent | qt/config_input: don't connect for null button (diff) | |
| download | yuzu-423ab5e2bcf5a522e5f412447c05f648df57a14c.tar.gz yuzu-423ab5e2bcf5a522e5f412447c05f648df57a14c.tar.xz yuzu-423ab5e2bcf5a522e5f412447c05f648df57a14c.zip | |
Merge pull request #2497 from wwylele/input-2
Refactor input emulation & add SDL gamepad support
Diffstat (limited to 'src/citra')
| -rw-r--r-- | src/citra/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/citra/config.cpp | 45 | ||||
| -rw-r--r-- | src/citra/default_ini.h | 69 | ||||
| -rw-r--r-- | src/citra/emu_window/emu_window_sdl2.cpp | 21 | ||||
| -rw-r--r-- | src/citra/emu_window/emu_window_sdl2.h | 6 |
5 files changed, 79 insertions, 64 deletions
diff --git a/src/citra/CMakeLists.txt b/src/citra/CMakeLists.txt index ecb5d2dfe..47231ba71 100644 --- a/src/citra/CMakeLists.txt +++ b/src/citra/CMakeLists.txt | |||
| @@ -18,7 +18,7 @@ create_directory_groups(${SRCS} ${HEADERS}) | |||
| 18 | include_directories(${SDL2_INCLUDE_DIR}) | 18 | include_directories(${SDL2_INCLUDE_DIR}) |
| 19 | 19 | ||
| 20 | add_executable(citra ${SRCS} ${HEADERS}) | 20 | add_executable(citra ${SRCS} ${HEADERS}) |
| 21 | target_link_libraries(citra core video_core audio_core common) | 21 | target_link_libraries(citra core video_core audio_core common input_common) |
| 22 | target_link_libraries(citra ${SDL2_LIBRARY} ${OPENGL_gl_LIBRARY} inih glad) | 22 | target_link_libraries(citra ${SDL2_LIBRARY} ${OPENGL_gl_LIBRARY} inih glad) |
| 23 | if (MSVC) | 23 | if (MSVC) |
| 24 | target_link_libraries(citra getopt) | 24 | target_link_libraries(citra getopt) |
diff --git a/src/citra/config.cpp b/src/citra/config.cpp index fac1c9a0e..ef1229912 100644 --- a/src/citra/config.cpp +++ b/src/citra/config.cpp | |||
| @@ -8,8 +8,10 @@ | |||
| 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" |
| 14 | #include "input_common/main.h" | ||
| 13 | 15 | ||
| 14 | Config::Config() { | 16 | Config::Config() { |
| 15 | // TODO: Don't hardcode the path; let the frontend decide where to put the config files. | 17 | // TODO: Don't hardcode the path; let the frontend decide where to put the config files. |
| @@ -37,25 +39,40 @@ bool Config::LoadINI(const std::string& default_contents, bool retry) { | |||
| 37 | return true; | 39 | return true; |
| 38 | } | 40 | } |
| 39 | 41 | ||
| 40 | static const std::array<int, Settings::NativeInput::NUM_INPUTS> defaults = { | 42 | static const std::array<int, Settings::NativeButton::NumButtons> default_buttons = { |
| 41 | // directly mapped keys | 43 | SDL_SCANCODE_A, SDL_SCANCODE_S, SDL_SCANCODE_Z, SDL_SCANCODE_X, SDL_SCANCODE_T, |
| 42 | SDL_SCANCODE_A, SDL_SCANCODE_S, SDL_SCANCODE_Z, SDL_SCANCODE_X, SDL_SCANCODE_Q, SDL_SCANCODE_W, | 44 | SDL_SCANCODE_G, SDL_SCANCODE_F, SDL_SCANCODE_H, SDL_SCANCODE_Q, SDL_SCANCODE_W, |
| 43 | SDL_SCANCODE_1, SDL_SCANCODE_2, SDL_SCANCODE_M, SDL_SCANCODE_N, SDL_SCANCODE_B, SDL_SCANCODE_T, | 45 | SDL_SCANCODE_M, SDL_SCANCODE_N, SDL_SCANCODE_1, SDL_SCANCODE_2, SDL_SCANCODE_B, |
| 44 | SDL_SCANCODE_G, SDL_SCANCODE_F, SDL_SCANCODE_H, SDL_SCANCODE_I, SDL_SCANCODE_K, SDL_SCANCODE_J, | ||
| 45 | SDL_SCANCODE_L, | ||
| 46 | |||
| 47 | // indirectly mapped keys | ||
| 48 | SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, SDL_SCANCODE_D, | ||
| 49 | }; | 46 | }; |
| 50 | 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 | |||
| 51 | void Config::ReadValues() { | 57 | void Config::ReadValues() { |
| 52 | // Controls | 58 | // Controls |
| 53 | for (int i = 0; i < Settings::NativeInput::NUM_INPUTS; ++i) { | 59 | for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { |
| 54 | Settings::values.input_mappings[Settings::NativeInput::All[i]] = | 60 | std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]); |
| 55 | sdl2_config->GetInteger("Controls", Settings::NativeInput::Mapping[i], defaults[i]); | 61 | Settings::values.buttons[i] = |
| 62 | sdl2_config->Get("Controls", Settings::NativeButton::mapping[i], default_param); | ||
| 63 | if (Settings::values.buttons[i].empty()) | ||
| 64 | Settings::values.buttons[i] = default_param; | ||
| 65 | } | ||
| 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; | ||
| 56 | } | 75 | } |
| 57 | Settings::values.pad_circle_modifier_scale = | ||
| 58 | (float)sdl2_config->GetReal("Controls", "pad_circle_modifier_scale", 0.5); | ||
| 59 | 76 | ||
| 60 | // Core | 77 | // Core |
| 61 | 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); |
diff --git a/src/citra/default_ini.h b/src/citra/default_ini.h index 435ba6f00..af9f7aa2a 100644 --- a/src/citra/default_ini.h +++ b/src/citra/default_ini.h | |||
| @@ -8,34 +8,47 @@ namespace DefaultINI { | |||
| 8 | 8 | ||
| 9 | const char* sdl2_config_file = R"( | 9 | const char* sdl2_config_file = R"( |
| 10 | [Controls] | 10 | [Controls] |
| 11 | pad_start = | 11 | # The input devices and parameters for each 3DS native input |
| 12 | pad_select = | 12 | # It should be in the format of "engine:[engine_name],[param1]:[value1],[param2]:[value2]..." |
| 13 | pad_home = | 13 | # Escape characters $0 (for ':'), $1 (for ',') and $2 (for '$') can be used in values |
| 14 | pad_dup = | 14 | |
| 15 | pad_ddown = | 15 | # for button input, the following devices are avaible: |
| 16 | pad_dleft = | 16 | # - "keyboard" (default) for keyboard input. Required parameters: |
| 17 | pad_dright = | 17 | # - "code": the code of the key to bind |
| 18 | pad_a = | 18 | # - "sdl" for joystick input using SDL. Required parameters: |
| 19 | pad_b = | 19 | # - "joystick": the index of the joystick to bind |
| 20 | pad_x = | 20 | # - "button"(optional): the index of the button to bind |
| 21 | pad_y = | 21 | # - "hat"(optional): the index of the hat to bind as direction buttons |
| 22 | pad_l = | 22 | # - "direction"(only used for hat): the direction name of the hat to bind. Can be "up", "down", "left" or "right" |
| 23 | pad_r = | 23 | button_a= |
| 24 | pad_zl = | 24 | button_b= |
| 25 | pad_zr = | 25 | button_x= |
| 26 | pad_cup = | 26 | button_y= |
| 27 | pad_cdown = | 27 | button_up= |
| 28 | pad_cleft = | 28 | button_down= |
| 29 | pad_cright = | 29 | button_left= |
| 30 | pad_circle_up = | 30 | button_right= |
| 31 | pad_circle_down = | 31 | button_l= |
| 32 | pad_circle_left = | 32 | button_r= |
| 33 | pad_circle_right = | 33 | button_start= |
| 34 | pad_circle_modifier = | 34 | button_select= |
| 35 | 35 | button_zl= | |
| 36 | # The applied modifier scale to circle pad. | 36 | button_zr= |
| 37 | # Must be in range of 0.0-1.0. Defaults to 0.5 | 37 | button_home= |
| 38 | pad_circle_modifier_scale = | 38 | |
| 39 | # for analog input, the following devices are avaible: | ||
| 40 | # - "analog_from_button" (default) for emulating analog input from direction buttons. Required parameters: | ||
| 41 | # - "up", "down", "left", "right": sub-devices for each direction. | ||
| 42 | # Should be in the format as a button input devices using escape characters, for example, "engine$0keyboard$1code$00" | ||
| 43 | # - "modifier": sub-devices as a modifier. | ||
| 44 | # - "modifier_scale": a float number representing the applied modifier scale to the analog input. | ||
| 45 | # Must be in range of 0.0-1.0. Defaults to 0.5 | ||
| 46 | # - "sdl" for joystick input using SDL. Required parameters: | ||
| 47 | # - "joystick": the index of the joystick to bind | ||
| 48 | # - "axis_x": the index of the axis to bind as x-axis (default to 0) | ||
| 49 | # - "axis_y": the index of the axis to bind as y-axis (default to 1) | ||
| 50 | circle_pad= | ||
| 51 | c_stick= | ||
| 39 | 52 | ||
| 40 | [Core] | 53 | [Core] |
| 41 | # Whether to use the Just-In-Time (JIT) compiler for CPU emulation | 54 | # Whether to use the Just-In-Time (JIT) compiler for CPU emulation |
diff --git a/src/citra/emu_window/emu_window_sdl2.cpp b/src/citra/emu_window/emu_window_sdl2.cpp index 00d00905a..6bc0b0d00 100644 --- a/src/citra/emu_window/emu_window_sdl2.cpp +++ b/src/citra/emu_window/emu_window_sdl2.cpp | |||
| @@ -12,9 +12,9 @@ | |||
| 12 | #include "common/logging/log.h" | 12 | #include "common/logging/log.h" |
| 13 | #include "common/scm_rev.h" | 13 | #include "common/scm_rev.h" |
| 14 | #include "common/string_util.h" | 14 | #include "common/string_util.h" |
| 15 | #include "core/frontend/key_map.h" | ||
| 16 | #include "core/hle/service/hid/hid.h" | ||
| 17 | #include "core/settings.h" | 15 | #include "core/settings.h" |
| 16 | #include "input_common/keyboard.h" | ||
| 17 | #include "input_common/main.h" | ||
| 18 | #include "video_core/video_core.h" | 18 | #include "video_core/video_core.h" |
| 19 | 19 | ||
| 20 | void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) { | 20 | void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) { |
| @@ -40,9 +40,9 @@ void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) { | |||
| 40 | 40 | ||
| 41 | void EmuWindow_SDL2::OnKeyEvent(int key, u8 state) { | 41 | void EmuWindow_SDL2::OnKeyEvent(int key, u8 state) { |
| 42 | if (state == SDL_PRESSED) { | 42 | if (state == SDL_PRESSED) { |
| 43 | KeyMap::PressKey(*this, {key, keyboard_id}); | 43 | InputCommon::GetKeyboard()->PressKey(key); |
| 44 | } else if (state == SDL_RELEASED) { | 44 | } else if (state == SDL_RELEASED) { |
| 45 | KeyMap::ReleaseKey(*this, {key, keyboard_id}); | 45 | InputCommon::GetKeyboard()->ReleaseKey(key); |
| 46 | } | 46 | } |
| 47 | } | 47 | } |
| 48 | 48 | ||
| @@ -57,9 +57,8 @@ void EmuWindow_SDL2::OnResize() { | |||
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | EmuWindow_SDL2::EmuWindow_SDL2() { | 59 | EmuWindow_SDL2::EmuWindow_SDL2() { |
| 60 | keyboard_id = KeyMap::NewDeviceId(); | 60 | InputCommon::Init(); |
| 61 | 61 | ||
| 62 | ReloadSetKeymaps(); | ||
| 63 | motion_emu = std::make_unique<Motion::MotionEmu>(*this); | 62 | motion_emu = std::make_unique<Motion::MotionEmu>(*this); |
| 64 | 63 | ||
| 65 | SDL_SetMainReady(); | 64 | SDL_SetMainReady(); |
| @@ -117,6 +116,7 @@ EmuWindow_SDL2::~EmuWindow_SDL2() { | |||
| 117 | SDL_GL_DeleteContext(gl_context); | 116 | SDL_GL_DeleteContext(gl_context); |
| 118 | SDL_Quit(); | 117 | SDL_Quit(); |
| 119 | motion_emu = nullptr; | 118 | motion_emu = nullptr; |
| 119 | InputCommon::Shutdown(); | ||
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | void EmuWindow_SDL2::SwapBuffers() { | 122 | void EmuWindow_SDL2::SwapBuffers() { |
| @@ -169,15 +169,6 @@ void EmuWindow_SDL2::DoneCurrent() { | |||
| 169 | SDL_GL_MakeCurrent(render_window, nullptr); | 169 | SDL_GL_MakeCurrent(render_window, nullptr); |
| 170 | } | 170 | } |
| 171 | 171 | ||
| 172 | void EmuWindow_SDL2::ReloadSetKeymaps() { | ||
| 173 | KeyMap::ClearKeyMapping(keyboard_id); | ||
| 174 | for (int i = 0; i < Settings::NativeInput::NUM_INPUTS; ++i) { | ||
| 175 | KeyMap::SetKeyMapping( | ||
| 176 | {Settings::values.input_mappings[Settings::NativeInput::All[i]], keyboard_id}, | ||
| 177 | KeyMap::mapping_targets[i]); | ||
| 178 | } | ||
| 179 | } | ||
| 180 | |||
| 181 | void EmuWindow_SDL2::OnMinimalClientAreaChangeRequest( | 172 | void EmuWindow_SDL2::OnMinimalClientAreaChangeRequest( |
| 182 | const std::pair<unsigned, unsigned>& minimal_size) { | 173 | const std::pair<unsigned, unsigned>& minimal_size) { |
| 183 | 174 | ||
diff --git a/src/citra/emu_window/emu_window_sdl2.h b/src/citra/emu_window/emu_window_sdl2.h index b1cbf16d7..1ce2991f7 100644 --- a/src/citra/emu_window/emu_window_sdl2.h +++ b/src/citra/emu_window/emu_window_sdl2.h | |||
| @@ -31,9 +31,6 @@ public: | |||
| 31 | /// Whether the window is still open, and a close request hasn't yet been sent | 31 | /// Whether the window is still open, and a close request hasn't yet been sent |
| 32 | bool IsOpen() const; | 32 | bool IsOpen() const; |
| 33 | 33 | ||
| 34 | /// Load keymap from configuration | ||
| 35 | void ReloadSetKeymaps() override; | ||
| 36 | |||
| 37 | private: | 34 | private: |
| 38 | /// Called by PollEvents when a key is pressed or released. | 35 | /// Called by PollEvents when a key is pressed or released. |
| 39 | void OnKeyEvent(int key, u8 state); | 36 | void OnKeyEvent(int key, u8 state); |
| @@ -61,9 +58,6 @@ private: | |||
| 61 | /// The OpenGL context associated with the window | 58 | /// The OpenGL context associated with the window |
| 62 | SDL_GLContext gl_context; | 59 | SDL_GLContext gl_context; |
| 63 | 60 | ||
| 64 | /// Device id of keyboard for use with KeyMap | ||
| 65 | int keyboard_id; | ||
| 66 | |||
| 67 | /// Motion sensors emulation | 61 | /// Motion sensors emulation |
| 68 | std::unique_ptr<Motion::MotionEmu> motion_emu; | 62 | std::unique_ptr<Motion::MotionEmu> motion_emu; |
| 69 | }; | 63 | }; |