summaryrefslogtreecommitdiff
path: root/src/core/frontend
diff options
context:
space:
mode:
authorGravatar wwylele2017-01-28 12:33:35 +0200
committerGravatar wwylele2017-03-01 23:30:57 +0200
commite02c4b71955021ecca294015aaf331add8d5c554 (patch)
tree9c3361df17c147453ba1e13c5a4f080b5e05c235 /src/core/frontend
parentQt: rework input configuration for new input system (diff)
downloadyuzu-e02c4b71955021ecca294015aaf331add8d5c554.tar.gz
yuzu-e02c4b71955021ecca294015aaf331add8d5c554.tar.xz
yuzu-e02c4b71955021ecca294015aaf331add8d5c554.zip
Input: remove unused stuff & clean up
1. removed zl, zr and c-stick from HID::PadState. They are handled by IR, not HID 2. removed button handling in EmuWindow 3. removed key_map 4. cleanup #include
Diffstat (limited to 'src/core/frontend')
-rw-r--r--src/core/frontend/emu_window.cpp26
-rw-r--r--src/core/frontend/emu_window.h52
-rw-r--r--src/core/frontend/key_map.cpp152
-rw-r--r--src/core/frontend/key_map.h93
4 files changed, 1 insertions, 322 deletions
diff --git a/src/core/frontend/emu_window.cpp b/src/core/frontend/emu_window.cpp
index a155b657d..73a44bfe7 100644
--- a/src/core/frontend/emu_window.cpp
+++ b/src/core/frontend/emu_window.cpp
@@ -7,33 +7,9 @@
7#include "common/assert.h" 7#include "common/assert.h"
8#include "core/core.h" 8#include "core/core.h"
9#include "core/frontend/emu_window.h" 9#include "core/frontend/emu_window.h"
10#include "core/frontend/key_map.h" 10#include "core/settings.h"
11#include "video_core/video_core.h" 11#include "video_core/video_core.h"
12 12
13void EmuWindow::ButtonPressed(Service::HID::PadState pad) {
14 pad_state.hex |= pad.hex;
15}
16
17void EmuWindow::ButtonReleased(Service::HID::PadState pad) {
18 pad_state.hex &= ~pad.hex;
19}
20
21void EmuWindow::CirclePadUpdated(float x, float y) {
22 constexpr int MAX_CIRCLEPAD_POS = 0x9C; // Max value for a circle pad position
23
24 // Make sure the coordinates are in the unit circle,
25 // otherwise normalize it.
26 float r = x * x + y * y;
27 if (r > 1) {
28 r = std::sqrt(r);
29 x /= r;
30 y /= r;
31 }
32
33 circle_pad_x = static_cast<s16>(x * MAX_CIRCLEPAD_POS);
34 circle_pad_y = static_cast<s16>(y * MAX_CIRCLEPAD_POS);
35}
36
37/** 13/**
38 * Check if the given x/y coordinates are within the touchpad specified by the framebuffer layout 14 * Check if the given x/y coordinates are within the touchpad specified by the framebuffer layout
39 * @param layout FramebufferLayout object describing the framebuffer size and screen positions 15 * @param layout FramebufferLayout object describing the framebuffer size and screen positions
diff --git a/src/core/frontend/emu_window.h b/src/core/frontend/emu_window.h
index de9b64953..36f2667fa 100644
--- a/src/core/frontend/emu_window.h
+++ b/src/core/frontend/emu_window.h
@@ -10,7 +10,6 @@
10#include "common/common_types.h" 10#include "common/common_types.h"
11#include "common/framebuffer_layout.h" 11#include "common/framebuffer_layout.h"
12#include "common/math_util.h" 12#include "common/math_util.h"
13#include "core/hle/service/hid/hid.h"
14 13
15/** 14/**
16 * Abstraction class used to provide an interface between emulation code and the frontend 15 * Abstraction class used to provide an interface between emulation code and the frontend
@@ -53,28 +52,6 @@ public:
53 virtual void DoneCurrent() = 0; 52 virtual void DoneCurrent() = 0;
54 53
55 /** 54 /**
56 * Signals a button press action to the HID module.
57 * @param pad_state indicates which button to press
58 * @note only handles real buttons (A/B/X/Y/...), excluding analog inputs like the circle pad.
59 */
60 void ButtonPressed(Service::HID::PadState pad_state);
61
62 /**
63 * Signals a button release action to the HID module.
64 * @param pad_state indicates which button to press
65 * @note only handles real buttons (A/B/X/Y/...), excluding analog inputs like the circle pad.
66 */
67 void ButtonReleased(Service::HID::PadState pad_state);
68
69 /**
70 * Signals a circle pad change action to the HID module.
71 * @param x new x-coordinate of the circle pad, in the range [-1.0, 1.0]
72 * @param y new y-coordinate of the circle pad, in the range [-1.0, 1.0]
73 * @note the coordinates will be normalized if the radius is larger than 1
74 */
75 void CirclePadUpdated(float x, float y);
76
77 /**
78 * Signal that a touch pressed event has occurred (e.g. mouse click pressed) 55 * Signal that a touch pressed event has occurred (e.g. mouse click pressed)
79 * @param framebuffer_x Framebuffer x-coordinate that was pressed 56 * @param framebuffer_x Framebuffer x-coordinate that was pressed
80 * @param framebuffer_y Framebuffer y-coordinate that was pressed 57 * @param framebuffer_y Framebuffer y-coordinate that was pressed
@@ -113,27 +90,6 @@ public:
113 void GyroscopeChanged(float x, float y, float z); 90 void GyroscopeChanged(float x, float y, float z);
114 91
115 /** 92 /**
116 * Gets the current pad state (which buttons are pressed).
117 * @note This should be called by the core emu thread to get a state set by the window thread.
118 * @note This doesn't include analog input like circle pad direction
119 * @todo Fix this function to be thread-safe.
120 * @return PadState object indicating the current pad state
121 */
122 Service::HID::PadState GetPadState() const {
123 return pad_state;
124 }
125
126 /**
127 * Gets the current circle pad state.
128 * @note This should be called by the core emu thread to get a state set by the window thread.
129 * @todo Fix this function to be thread-safe.
130 * @return std::tuple of (x, y), where `x` and `y` are the circle pad coordinates
131 */
132 std::tuple<s16, s16> GetCirclePadState() const {
133 return std::make_tuple(circle_pad_x, circle_pad_y);
134 }
135
136 /**
137 * Gets the current touch screen state (touch X/Y coordinates and whether or not it is pressed). 93 * Gets the current touch screen state (touch X/Y coordinates and whether or not it is pressed).
138 * @note This should be called by the core emu thread to get a state set by the window thread. 94 * @note This should be called by the core emu thread to get a state set by the window thread.
139 * @todo Fix this function to be thread-safe. 95 * @todo Fix this function to be thread-safe.
@@ -228,11 +184,8 @@ protected:
228 // TODO: Find a better place to set this. 184 // TODO: Find a better place to set this.
229 config.min_client_area_size = std::make_pair(400u, 480u); 185 config.min_client_area_size = std::make_pair(400u, 480u);
230 active_config = config; 186 active_config = config;
231 pad_state.hex = 0;
232 touch_x = 0; 187 touch_x = 0;
233 touch_y = 0; 188 touch_y = 0;
234 circle_pad_x = 0;
235 circle_pad_y = 0;
236 touch_pressed = false; 189 touch_pressed = false;
237 accel_x = 0; 190 accel_x = 0;
238 accel_y = -512; 191 accel_y = -512;
@@ -302,9 +255,6 @@ private:
302 u16 touch_x; ///< Touchpad X-position in native 3DS pixel coordinates (0-320) 255 u16 touch_x; ///< Touchpad X-position in native 3DS pixel coordinates (0-320)
303 u16 touch_y; ///< Touchpad Y-position in native 3DS pixel coordinates (0-240) 256 u16 touch_y; ///< Touchpad Y-position in native 3DS pixel coordinates (0-240)
304 257
305 s16 circle_pad_x; ///< Circle pad X-position in native 3DS pixel coordinates (-156 - 156)
306 s16 circle_pad_y; ///< Circle pad Y-position in native 3DS pixel coordinates (-156 - 156)
307
308 std::mutex accel_mutex; 258 std::mutex accel_mutex;
309 s16 accel_x; ///< Accelerometer X-axis value in native 3DS units 259 s16 accel_x; ///< Accelerometer X-axis value in native 3DS units
310 s16 accel_y; ///< Accelerometer Y-axis value in native 3DS units 260 s16 accel_y; ///< Accelerometer Y-axis value in native 3DS units
@@ -319,6 +269,4 @@ private:
319 * Clip the provided coordinates to be inside the touchscreen area. 269 * Clip the provided coordinates to be inside the touchscreen area.
320 */ 270 */
321 std::tuple<unsigned, unsigned> ClipToTouchScreen(unsigned new_x, unsigned new_y); 271 std::tuple<unsigned, unsigned> ClipToTouchScreen(unsigned new_x, unsigned new_y);
322
323 Service::HID::PadState pad_state;
324}; 272};
diff --git a/src/core/frontend/key_map.cpp b/src/core/frontend/key_map.cpp
deleted file mode 100644
index 15f0e079c..000000000
--- a/src/core/frontend/key_map.cpp
+++ /dev/null
@@ -1,152 +0,0 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <map>
6#include "core/frontend/emu_window.h"
7#include "core/frontend/key_map.h"
8
9namespace KeyMap {
10
11// TODO (wwylele): currently we treat c-stick as four direction buttons
12// and map it directly to EmuWindow::ButtonPressed.
13// It should go the analog input way like circle pad does.
14const std::array<KeyTarget, Settings::NativeInput::NUM_INPUTS> mapping_targets = {{
15 Service::HID::PAD_A,
16 Service::HID::PAD_B,
17 Service::HID::PAD_X,
18 Service::HID::PAD_Y,
19 Service::HID::PAD_L,
20 Service::HID::PAD_R,
21 Service::HID::PAD_ZL,
22 Service::HID::PAD_ZR,
23 Service::HID::PAD_START,
24 Service::HID::PAD_SELECT,
25 Service::HID::PAD_NONE,
26 Service::HID::PAD_UP,
27 Service::HID::PAD_DOWN,
28 Service::HID::PAD_LEFT,
29 Service::HID::PAD_RIGHT,
30 Service::HID::PAD_C_UP,
31 Service::HID::PAD_C_DOWN,
32 Service::HID::PAD_C_LEFT,
33 Service::HID::PAD_C_RIGHT,
34
35 IndirectTarget::CirclePadUp,
36 IndirectTarget::CirclePadDown,
37 IndirectTarget::CirclePadLeft,
38 IndirectTarget::CirclePadRight,
39 IndirectTarget::CirclePadModifier,
40}};
41
42static std::map<HostDeviceKey, KeyTarget> key_map;
43static int next_device_id = 0;
44
45static bool circle_pad_up = false;
46static bool circle_pad_down = false;
47static bool circle_pad_left = false;
48static bool circle_pad_right = false;
49static bool circle_pad_modifier = false;
50
51static void UpdateCirclePad(EmuWindow& emu_window) {
52 constexpr float SQRT_HALF = 0.707106781f;
53 int x = 0, y = 0;
54
55 if (circle_pad_right)
56 ++x;
57 if (circle_pad_left)
58 --x;
59 if (circle_pad_up)
60 ++y;
61 if (circle_pad_down)
62 --y;
63
64 float modifier = circle_pad_modifier ? Settings::values.pad_circle_modifier_scale : 1.0f;
65 emu_window.CirclePadUpdated(x * modifier * (y == 0 ? 1.0f : SQRT_HALF),
66 y * modifier * (x == 0 ? 1.0f : SQRT_HALF));
67}
68
69int NewDeviceId() {
70 return next_device_id++;
71}
72
73void SetKeyMapping(HostDeviceKey key, KeyTarget target) {
74 key_map[key] = target;
75}
76
77void ClearKeyMapping(int device_id) {
78 auto iter = key_map.begin();
79 while (iter != key_map.end()) {
80 if (iter->first.device_id == device_id)
81 key_map.erase(iter++);
82 else
83 ++iter;
84 }
85}
86
87void PressKey(EmuWindow& emu_window, HostDeviceKey key) {
88 auto target = key_map.find(key);
89 if (target == key_map.end())
90 return;
91
92 if (target->second.direct) {
93 emu_window.ButtonPressed({{target->second.target.direct_target_hex}});
94 } else {
95 switch (target->second.target.indirect_target) {
96 case IndirectTarget::CirclePadUp:
97 circle_pad_up = true;
98 UpdateCirclePad(emu_window);
99 break;
100 case IndirectTarget::CirclePadDown:
101 circle_pad_down = true;
102 UpdateCirclePad(emu_window);
103 break;
104 case IndirectTarget::CirclePadLeft:
105 circle_pad_left = true;
106 UpdateCirclePad(emu_window);
107 break;
108 case IndirectTarget::CirclePadRight:
109 circle_pad_right = true;
110 UpdateCirclePad(emu_window);
111 break;
112 case IndirectTarget::CirclePadModifier:
113 circle_pad_modifier = true;
114 UpdateCirclePad(emu_window);
115 break;
116 }
117 }
118}
119
120void ReleaseKey(EmuWindow& emu_window, HostDeviceKey key) {
121 auto target = key_map.find(key);
122 if (target == key_map.end())
123 return;
124
125 if (target->second.direct) {
126 emu_window.ButtonReleased({{target->second.target.direct_target_hex}});
127 } else {
128 switch (target->second.target.indirect_target) {
129 case IndirectTarget::CirclePadUp:
130 circle_pad_up = false;
131 UpdateCirclePad(emu_window);
132 break;
133 case IndirectTarget::CirclePadDown:
134 circle_pad_down = false;
135 UpdateCirclePad(emu_window);
136 break;
137 case IndirectTarget::CirclePadLeft:
138 circle_pad_left = false;
139 UpdateCirclePad(emu_window);
140 break;
141 case IndirectTarget::CirclePadRight:
142 circle_pad_right = false;
143 UpdateCirclePad(emu_window);
144 break;
145 case IndirectTarget::CirclePadModifier:
146 circle_pad_modifier = false;
147 UpdateCirclePad(emu_window);
148 break;
149 }
150 }
151}
152}
diff --git a/src/core/frontend/key_map.h b/src/core/frontend/key_map.h
deleted file mode 100644
index 040794578..000000000
--- a/src/core/frontend/key_map.h
+++ /dev/null
@@ -1,93 +0,0 @@
1// Copyright 2014 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 <array>
8#include <tuple>
9#include "core/hle/service/hid/hid.h"
10
11class EmuWindow;
12
13namespace KeyMap {
14
15/**
16 * Represents key mapping targets that are not real 3DS buttons.
17 * They will be handled by KeyMap and translated to 3DS input.
18 */
19enum class IndirectTarget {
20 CirclePadUp,
21 CirclePadDown,
22 CirclePadLeft,
23 CirclePadRight,
24 CirclePadModifier,
25};
26
27/**
28 * Represents a key mapping target. It can be a PadState that represents real 3DS buttons,
29 * or an IndirectTarget.
30 */
31struct KeyTarget {
32 bool direct;
33 union {
34 u32 direct_target_hex;
35 IndirectTarget indirect_target;
36 } target;
37
38 KeyTarget() : direct(true) {
39 target.direct_target_hex = 0;
40 }
41
42 KeyTarget(Service::HID::PadState pad) : direct(true) {
43 target.direct_target_hex = pad.hex;
44 }
45
46 KeyTarget(IndirectTarget i) : direct(false) {
47 target.indirect_target = i;
48 }
49};
50
51/**
52 * Represents a key for a specific host device.
53 */
54struct HostDeviceKey {
55 int key_code;
56 int device_id; ///< Uniquely identifies a host device
57
58 bool operator<(const HostDeviceKey& other) const {
59 return std::tie(key_code, device_id) < std::tie(other.key_code, other.device_id);
60 }
61
62 bool operator==(const HostDeviceKey& other) const {
63 return std::tie(key_code, device_id) == std::tie(other.key_code, other.device_id);
64 }
65};
66
67extern const std::array<KeyTarget, Settings::NativeInput::NUM_INPUTS> mapping_targets;
68
69/**
70 * Generates a new device id, which uniquely identifies a host device within KeyMap.
71 */
72int NewDeviceId();
73
74/**
75 * Maps a device-specific key to a target (a PadState or an IndirectTarget).
76 */
77void SetKeyMapping(HostDeviceKey key, KeyTarget target);
78
79/**
80 * Clears all key mappings belonging to one device.
81 */
82void ClearKeyMapping(int device_id);
83
84/**
85 * Maps a key press action and call the corresponding function in EmuWindow
86 */
87void PressKey(EmuWindow& emu_window, HostDeviceKey key);
88
89/**
90 * Maps a key release action and call the corresponding function in EmuWindow
91 */
92void ReleaseKey(EmuWindow& emu_window, HostDeviceKey key);
93}