diff options
| author | 2016-05-12 13:09:36 +0300 | |
|---|---|---|
| committer | 2016-05-15 13:24:22 +0300 | |
| commit | 03631f9b8fe75cf1c3a70a3094aeddcebffa4cf9 (patch) | |
| tree | 95edc62b3b8520a533e534bf4991159875fef3e5 /src/core | |
| parent | AudioCore: Implement time stretcher (#1737) (diff) | |
| download | yuzu-03631f9b8fe75cf1c3a70a3094aeddcebffa4cf9.tar.gz yuzu-03631f9b8fe75cf1c3a70a3094aeddcebffa4cf9.tar.xz yuzu-03631f9b8fe75cf1c3a70a3094aeddcebffa4cf9.zip | |
Refactor input subsystem
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/hle/service/hid/hid.cpp | 68 | ||||
| -rw-r--r-- | src/core/hle/service/hid/hid.h | 3 | ||||
| -rw-r--r-- | src/core/settings.h | 18 |
3 files changed, 49 insertions, 40 deletions
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index d216cecb4..a48184495 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp | |||
| @@ -19,8 +19,6 @@ | |||
| 19 | namespace Service { | 19 | namespace Service { |
| 20 | namespace HID { | 20 | namespace HID { |
| 21 | 21 | ||
| 22 | static const int MAX_CIRCLEPAD_POS = 0x9C; ///< Max value for a circle pad position | ||
| 23 | |||
| 24 | // Handle to shared memory region designated to HID_User service | 22 | // Handle to shared memory region designated to HID_User service |
| 25 | static Kernel::SharedPtr<Kernel::SharedMemory> shared_mem; | 23 | static Kernel::SharedPtr<Kernel::SharedMemory> shared_mem; |
| 26 | 24 | ||
| @@ -39,38 +37,48 @@ static u32 next_gyroscope_index; | |||
| 39 | static int enable_accelerometer_count = 0; // positive means enabled | 37 | static int enable_accelerometer_count = 0; // positive means enabled |
| 40 | static int enable_gyroscope_count = 0; // positive means enabled | 38 | static int enable_gyroscope_count = 0; // positive means enabled |
| 41 | 39 | ||
| 42 | const std::array<Service::HID::PadState, Settings::NativeInput::NUM_INPUTS> pad_mapping = {{ | 40 | static PadState GetCirclePadDirectionState(s16 circle_pad_x, s16 circle_pad_y) { |
| 43 | Service::HID::PAD_A, Service::HID::PAD_B, Service::HID::PAD_X, Service::HID::PAD_Y, | 41 | constexpr float TAN30 = 0.577350269, TAN60 = 1 / TAN30; // 30 degree and 60 degree are angular thresholds for directions |
| 44 | Service::HID::PAD_L, Service::HID::PAD_R, Service::HID::PAD_ZL, Service::HID::PAD_ZR, | 42 | constexpr int CIRCLE_PAD_THRESHOLD_SQUARE = 40 * 40; // a circle pad radius greater than 40 will trigger circle pad direction |
| 45 | Service::HID::PAD_START, Service::HID::PAD_SELECT, Service::HID::PAD_NONE, | 43 | PadState state; |
| 46 | Service::HID::PAD_UP, Service::HID::PAD_DOWN, Service::HID::PAD_LEFT, Service::HID::PAD_RIGHT, | 44 | state.hex = 0; |
| 47 | Service::HID::PAD_CIRCLE_UP, Service::HID::PAD_CIRCLE_DOWN, Service::HID::PAD_CIRCLE_LEFT, Service::HID::PAD_CIRCLE_RIGHT, | 45 | |
| 48 | Service::HID::PAD_C_UP, Service::HID::PAD_C_DOWN, Service::HID::PAD_C_LEFT, Service::HID::PAD_C_RIGHT | 46 | if (circle_pad_x * circle_pad_x + circle_pad_y * circle_pad_y > CIRCLE_PAD_THRESHOLD_SQUARE) { |
| 49 | }}; | 47 | float t = std::abs(static_cast<float>(circle_pad_y) / circle_pad_x); |
| 50 | 48 | ||
| 51 | 49 | if (circle_pad_x != 0 && t < TAN60) { | |
| 52 | // TODO(peachum): | 50 | if (circle_pad_x > 0) |
| 53 | // Add a method for setting analog input from joystick device for the circle Pad. | 51 | state.circle_right.Assign(1); |
| 54 | // | 52 | else |
| 55 | // This method should: | 53 | state.circle_left.Assign(1); |
| 56 | // * Be called after both PadButton<Press, Release>(). | 54 | } |
| 57 | // * Be called before PadUpdateComplete() | 55 | |
| 58 | // * Set current PadEntry.circle_pad_<axis> using analog data | 56 | if (circle_pad_x == 0 || t > TAN30) { |
| 59 | // * Set PadData.raw_circle_pad_data | 57 | if (circle_pad_y > 0) |
| 60 | // * Set PadData.current_state.circle_right = 1 if current PadEntry.circle_pad_x >= 41 | 58 | state.circle_up.Assign(1); |
| 61 | // * Set PadData.current_state.circle_up = 1 if current PadEntry.circle_pad_y >= 41 | 59 | else |
| 62 | // * Set PadData.current_state.circle_left = 1 if current PadEntry.circle_pad_x <= -41 | 60 | state.circle_down.Assign(1); |
| 63 | // * Set PadData.current_state.circle_right = 1 if current PadEntry.circle_pad_y <= -41 | 61 | } |
| 62 | } | ||
| 63 | |||
| 64 | return state; | ||
| 65 | } | ||
| 64 | 66 | ||
| 65 | void Update() { | 67 | void Update() { |
| 66 | SharedMem* mem = reinterpret_cast<SharedMem*>(shared_mem->GetPointer()); | 68 | SharedMem* mem = reinterpret_cast<SharedMem*>(shared_mem->GetPointer()); |
| 67 | const PadState state = VideoCore::g_emu_window->GetPadState(); | ||
| 68 | 69 | ||
| 69 | if (mem == nullptr) { | 70 | if (mem == nullptr) { |
| 70 | LOG_DEBUG(Service_HID, "Cannot update HID prior to mapping shared memory!"); | 71 | LOG_DEBUG(Service_HID, "Cannot update HID prior to mapping shared memory!"); |
| 71 | return; | 72 | return; |
| 72 | } | 73 | } |
| 73 | 74 | ||
| 75 | PadState state = VideoCore::g_emu_window->GetPadState(); | ||
| 76 | |||
| 77 | // Get current circle pad positon and update circle pad direction | ||
| 78 | s16 circle_pad_x, circle_pad_y; | ||
| 79 | std::tie(circle_pad_x, circle_pad_y) = VideoCore::g_emu_window->GetCirclePadState(); | ||
| 80 | state.hex |= GetCirclePadDirectionState(circle_pad_x, circle_pad_y).hex; | ||
| 81 | |||
| 74 | mem->pad.current_state.hex = state.hex; | 82 | mem->pad.current_state.hex = state.hex; |
| 75 | mem->pad.index = next_pad_index; | 83 | mem->pad.index = next_pad_index; |
| 76 | next_pad_index = (next_pad_index + 1) % mem->pad.entries.size(); | 84 | next_pad_index = (next_pad_index + 1) % mem->pad.entries.size(); |
| @@ -88,13 +96,9 @@ void Update() { | |||
| 88 | // Update entry properties | 96 | // Update entry properties |
| 89 | pad_entry.current_state.hex = state.hex; | 97 | pad_entry.current_state.hex = state.hex; |
| 90 | pad_entry.delta_additions.hex = changed.hex & state.hex; | 98 | pad_entry.delta_additions.hex = changed.hex & state.hex; |
| 91 | pad_entry.delta_removals.hex = changed.hex & old_state.hex;; | 99 | pad_entry.delta_removals.hex = changed.hex & old_state.hex; |
| 92 | 100 | pad_entry.circle_pad_x = circle_pad_x; | |
| 93 | // Set circle Pad | 101 | pad_entry.circle_pad_y = circle_pad_y; |
| 94 | pad_entry.circle_pad_x = state.circle_left ? -MAX_CIRCLEPAD_POS : | ||
| 95 | state.circle_right ? MAX_CIRCLEPAD_POS : 0x0; | ||
| 96 | pad_entry.circle_pad_y = state.circle_down ? -MAX_CIRCLEPAD_POS : | ||
| 97 | state.circle_up ? MAX_CIRCLEPAD_POS : 0x0; | ||
| 98 | 102 | ||
| 99 | // If we just updated index 0, provide a new timestamp | 103 | // If we just updated index 0, provide a new timestamp |
| 100 | if (mem->pad.index == 0) { | 104 | if (mem->pad.index == 0) { |
diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index 170d19ea8..669b1f723 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h | |||
| @@ -215,9 +215,6 @@ const PadState PAD_CIRCLE_LEFT = {{1u << 29}}; | |||
| 215 | const PadState PAD_CIRCLE_UP = {{1u << 30}}; | 215 | const PadState PAD_CIRCLE_UP = {{1u << 30}}; |
| 216 | const PadState PAD_CIRCLE_DOWN = {{1u << 31}}; | 216 | const PadState PAD_CIRCLE_DOWN = {{1u << 31}}; |
| 217 | 217 | ||
| 218 | |||
| 219 | extern const std::array<Service::HID::PadState, Settings::NativeInput::NUM_INPUTS> pad_mapping; | ||
| 220 | |||
| 221 | /** | 218 | /** |
| 222 | * HID::GetIPCHandles service function | 219 | * HID::GetIPCHandles service function |
| 223 | * Inputs: | 220 | * Inputs: |
diff --git a/src/core/settings.h b/src/core/settings.h index ce2a31164..df5915442 100644 --- a/src/core/settings.h +++ b/src/core/settings.h | |||
| @@ -13,29 +13,37 @@ namespace Settings { | |||
| 13 | 13 | ||
| 14 | namespace NativeInput { | 14 | namespace NativeInput { |
| 15 | enum Values { | 15 | enum Values { |
| 16 | // directly mapped keys | ||
| 16 | A, B, X, Y, | 17 | A, B, X, Y, |
| 17 | L, R, ZL, ZR, | 18 | L, R, ZL, ZR, |
| 18 | START, SELECT, HOME, | 19 | START, SELECT, HOME, |
| 19 | DUP, DDOWN, DLEFT, DRIGHT, | 20 | DUP, DDOWN, DLEFT, DRIGHT, |
| 20 | SUP, SDOWN, SLEFT, SRIGHT, | ||
| 21 | CUP, CDOWN, CLEFT, CRIGHT, | 21 | CUP, CDOWN, CLEFT, CRIGHT, |
| 22 | |||
| 23 | // indirectly mapped keys | ||
| 24 | CIRCLE_UP, CIRCLE_DOWN, CIRCLE_LEFT, CIRCLE_RIGHT, | ||
| 25 | |||
| 22 | NUM_INPUTS | 26 | NUM_INPUTS |
| 23 | }; | 27 | }; |
| 28 | |||
| 24 | static const std::array<const char*, NUM_INPUTS> Mapping = {{ | 29 | static const std::array<const char*, NUM_INPUTS> Mapping = {{ |
| 30 | // directly mapped keys | ||
| 25 | "pad_a", "pad_b", "pad_x", "pad_y", | 31 | "pad_a", "pad_b", "pad_x", "pad_y", |
| 26 | "pad_l", "pad_r", "pad_zl", "pad_zr", | 32 | "pad_l", "pad_r", "pad_zl", "pad_zr", |
| 27 | "pad_start", "pad_select", "pad_home", | 33 | "pad_start", "pad_select", "pad_home", |
| 28 | "pad_dup", "pad_ddown", "pad_dleft", "pad_dright", | 34 | "pad_dup", "pad_ddown", "pad_dleft", "pad_dright", |
| 29 | "pad_sup", "pad_sdown", "pad_sleft", "pad_sright", | 35 | "pad_cup", "pad_cdown", "pad_cleft", "pad_cright", |
| 30 | "pad_cup", "pad_cdown", "pad_cleft", "pad_cright" | 36 | |
| 37 | // indirectly mapped keys | ||
| 38 | "pad_circle_up", "pad_circle_down", "pad_circle_left", "pad_circle_right" | ||
| 31 | }}; | 39 | }}; |
| 32 | static const std::array<Values, NUM_INPUTS> All = {{ | 40 | static const std::array<Values, NUM_INPUTS> All = {{ |
| 33 | A, B, X, Y, | 41 | A, B, X, Y, |
| 34 | L, R, ZL, ZR, | 42 | L, R, ZL, ZR, |
| 35 | START, SELECT, HOME, | 43 | START, SELECT, HOME, |
| 36 | DUP, DDOWN, DLEFT, DRIGHT, | 44 | DUP, DDOWN, DLEFT, DRIGHT, |
| 37 | SUP, SDOWN, SLEFT, SRIGHT, | 45 | CUP, CDOWN, CLEFT, CRIGHT, |
| 38 | CUP, CDOWN, CLEFT, CRIGHT | 46 | CIRCLE_UP, CIRCLE_DOWN, CIRCLE_LEFT, CIRCLE_RIGHT, |
| 39 | }}; | 47 | }}; |
| 40 | } | 48 | } |
| 41 | 49 | ||