forked from devpack/mayhem
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mapping_joy.cpp
138 lines (133 loc) · 4.51 KB
/
mapping_joy.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "mapping_joy.h"
JoyButton mapping_joy::btn_sets[4][5] = {
{JoyButton::LEFT_STICK_X_LEFT, JoyButton::LEFT_STICK_X_RIGHT,
JoyButton::BUTTON_A, JoyButton::BUTTON_B,
JoyButton::BUTTON_RIGHT_SHOULDER},
{JoyButton::LEFT_STICK_X_LEFT, JoyButton::LEFT_STICK_X_RIGHT,
JoyButton::BUTTON_A, JoyButton::BUTTON_B,
JoyButton::BUTTON_RIGHT_SHOULDER},
{JoyButton::LEFT_STICK_X_LEFT, JoyButton::LEFT_STICK_X_RIGHT,
JoyButton::BUTTON_A, JoyButton::BUTTON_B,
JoyButton::BUTTON_RIGHT_SHOULDER},
{JoyButton::LEFT_STICK_X_LEFT, JoyButton::LEFT_STICK_X_RIGHT,
JoyButton::BUTTON_A, JoyButton::BUTTON_B,
JoyButton::BUTTON_RIGHT_SHOULDER}};
bool is_pressed(XC_STATE *joystick, JoyButton button) {
switch (button) {
case JoyButton::LEFT_STICK_X_LEFT:
return (joystick->left_stick_x <= -0.6);
case JoyButton::LEFT_STICK_X_RIGHT:
return (joystick->left_stick_x >= 0.6);
case JoyButton::LEFT_STICK_Y_UP:
return (joystick->left_stick_y <= -0.6);
case JoyButton::LEFT_STICK_Y_DOWN:
return (joystick->left_stick_y >= 0.6);
case JoyButton::LEFT_TRIGGER:
return (joystick->left_trigger >= 0.6);
case JoyButton::RIGHT_STICK_X_LEFT:
return (joystick->right_stick_x <= -0.6);
case JoyButton::RIGHT_STICK_X_RIGHT:
return (joystick->right_stick_x >= 0.6);
case JoyButton::RIGHT_STICK_Y_UP:
return (joystick->right_stick_y <= -0.6);
case JoyButton::RIGHT_STICK_Y_DOWN:
return (joystick->right_stick_y >= 0.6);
case JoyButton::RIGHT_TRIGGER:
return (joystick->right_trigger >= 0.6);
case JoyButton::DPAD_X_LEFT:
return (joystick->dpad_left);
case JoyButton::DPAD_X_RIGHT:
return (joystick->dpad_right);
case JoyButton::DPAD_Y_UP:
return (joystick->dpad_up);
case JoyButton::DPAD_Y_DOWN:
return (joystick->dpad_down);
case JoyButton::BUTTON_A:
return (joystick->button_a);
case JoyButton::BUTTON_B:
return (joystick->button_b);
case JoyButton::BUTTON_X:
return (joystick->button_x);
case JoyButton::BUTTON_Y:
return (joystick->button_y);
case JoyButton::BUTTON_LEFT_STICK:
return (joystick->button_left_stick);
case JoyButton::BUTTON_RIGHT_STICK:
return (joystick->button_right_stick);
case JoyButton::BUTTON_LEFT_SHOULDER:
return (joystick->button_left_shoulder);
case JoyButton::BUTTON_RIGHT_SHOULDER:
return (joystick->button_right_shoulder);
case JoyButton::BUTTON_START:
return (joystick->button_start);
case JoyButton::BUTTON_BACK:
return (joystick->button_back);
case JoyButton::BUTTON_XBOX:
return (joystick->button_xbox);
default:
return false;
}
}
const char *button_to_str(JoyButton button) {
switch (button) {
case JoyButton::LEFT_STICK_X_LEFT:
return ("Left Stick Left");
case JoyButton::LEFT_STICK_X_RIGHT:
return ("Left Stick Right");
case JoyButton::LEFT_STICK_Y_UP:
return ("Left Stick Up");
case JoyButton::LEFT_STICK_Y_DOWN:
return ("Left Stick Down");
case JoyButton::LEFT_TRIGGER:
return ("Left Trigger");
case JoyButton::RIGHT_STICK_X_LEFT:
return ("Right Stick Left");
case JoyButton::RIGHT_STICK_X_RIGHT:
return ("Right Stick Right");
case JoyButton::RIGHT_STICK_Y_UP:
return ("Right Stick Up");
case JoyButton::RIGHT_STICK_Y_DOWN:
return ("Right Stick Down");
case JoyButton::RIGHT_TRIGGER:
return ("Right Trigger");
case JoyButton::DPAD_X_LEFT:
return ("Dpad Left");
case JoyButton::DPAD_X_RIGHT:
return ("Dpad Right");
case JoyButton::DPAD_Y_UP:
return ("Dpad Up");
case JoyButton::DPAD_Y_DOWN:
return ("Dpad Down");
case JoyButton::BUTTON_A:
return ("A");
case JoyButton::BUTTON_B:
return ("B");
case JoyButton::BUTTON_X:
return ("X");
case JoyButton::BUTTON_Y:
return ("Y");
case JoyButton::BUTTON_LEFT_STICK:
return ("Left Stick Button");
case JoyButton::BUTTON_RIGHT_STICK:
return ("Right Stick Button");
case JoyButton::BUTTON_LEFT_SHOULDER:
return ("Left Shoulder");
case JoyButton::BUTTON_RIGHT_SHOULDER:
return ("Right Shoulder");
case JoyButton::BUTTON_START:
return ("Start");
case JoyButton::BUTTON_BACK:
return ("Back");
case JoyButton::BUTTON_XBOX:
return ("Xbox");
default:
return "?";
}
}
void init_mapping_joy(struct mapping_joy *joymap, int keysetno) {
joymap->left = mapping_joy::btn_sets[keysetno][0];
joymap->right = mapping_joy::btn_sets[keysetno][1];
joymap->thrust = mapping_joy::btn_sets[keysetno][2];
joymap->shield = mapping_joy::btn_sets[keysetno][3];
joymap->fire = mapping_joy::btn_sets[keysetno][4];
}