This commit is contained in:
Bryan Baraoidan 2017-12-03 22:51:17 +00:00 committed by GitHub
commit 78cee80efc
5 changed files with 185538 additions and 2 deletions

185505
TAGS Normal file

File diff suppressed because it is too large Load Diff

View File

@ -24,6 +24,11 @@
#define VIDEO_DEFAULT_HEIGHT 480
#define INPUT_MAX_CONTROLLERS 4
/* Default deadzone size taken from this thread https://forums.libsdl.org/viewtopic.php?p=39985 (specifically talks about xbox 360 controllers.
Other sources also have it around this number.
*/
#define DEFAULT_DEADZONE 4096
#define AUDIO_FRAME_SIZE 4 /* stereo / pcm16 */
#define AUDIO_FRAMES_TO_MS(frames) \
(int)(((float)frames * 1000.0f) / (float)AUDIO_FREQ)
@ -832,11 +837,22 @@ static void host_poll_events(struct host *host) {
case SDL_CONTROLLERAXISMOTION: {
int port = input_find_controller_port(host, ev.caxis.which);
int key = K_UNKNOWN;
uint16_t value = 0;
uint16_t value = 0;
int result = 0;
if (port >= 0) {
if (ev.caxis.value < -*(deadzones[port])) {
result = ev.caxis.value + *(deadzones[port]);
}
else if (ev.caxis.value > *(deadzones[port])) {
result = ev.caxis.value - *(deadzones[port]);
}
}
/* SDL provides axis input in the range of [INT16_MIN, INT16_MAX],
convert to [0, UINT16_MAX] */
int dir = axis_s16_to_u16(ev.caxis.value, &value);
int dir = axis_s16_to_u16(result, &value);
switch (ev.caxis.axis) {
case SDL_CONTROLLER_AXIS_LEFTX:

View File

@ -53,6 +53,14 @@ DEFINE_PERSISTENT_OPTION_INT(key_joyy_pos, 's', "Joystick +Y axis mapping");
DEFINE_PERSISTENT_OPTION_INT(key_ltrig, '[', "Left trigger mapping");
DEFINE_PERSISTENT_OPTION_INT(key_rtrig, ']', "Right trigger mapping");
/* Default value taken from this thread https://forums.libsdl.org/viewtopic.php?p=39985 */
DEFINE_PERSISTENT_OPTION_INT(deadzone_0, 4096, "The deadzone for the controller on port 0");
DEFINE_PERSISTENT_OPTION_INT(deadzone_1, 4096, "The deadzone for the controller on port 1");
DEFINE_PERSISTENT_OPTION_INT(deadzone_2, 4096, "The deadzone for the controller on port 2");
DEFINE_PERSISTENT_OPTION_INT(deadzone_3, 4096, "The deadzone for the controller on port 3");
int *deadzones[] = { &OPTION_deadzone_0, &OPTION_deadzone_1, &OPTION_deadzone_2, &OPTION_deadzone_3 };
/* emulator */
DEFINE_PERSISTENT_OPTION_STRING(aspect, "4:3", "Video aspect ratio");

View File

@ -14,6 +14,8 @@ extern const int NUM_ASPECT_RATIOS;
extern struct button_map BUTTONS[];
extern const int NUM_BUTTONS;
extern int *deadzones[];
/* host */
DECLARE_OPTION_STRING(sync);
DECLARE_OPTION_INT(bios);
@ -33,6 +35,10 @@ DECLARE_OPTION_INT(key_joyy_neg);
DECLARE_OPTION_INT(key_joyy_pos);
DECLARE_OPTION_INT(key_ltrig);
DECLARE_OPTION_INT(key_rtrig);
DECLARE_OPTION_INT(deadzone_0);
DECLARE_OPTION_INT(deadzone_1);
DECLARE_OPTION_INT(deadzone_2);
DECLARE_OPTION_INT(deadzone_3);
/* emulator */
DECLARE_OPTION_STRING(aspect);

View File

@ -518,6 +518,7 @@ static void ui_scan_games_f(struct ui *ui, const char *filename) {
snprintf(ui->scan_status, sizeof(ui->scan_status), "scanning %s", filename);
if (ui_has_game_ext(filename, game_exts, ARRAY_SIZE(game_exts))) {
struct disc *disc = disc_create(filename, 0);
if (disc) {