From e427aaa89434a60fa91942541016d9b301dfb4e2 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Sun, 10 May 2020 18:41:46 +0300 Subject: [PATCH 1/5] make use of mouse buttons --- src/pc/controller/controller_sdl.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pc/controller/controller_sdl.c b/src/pc/controller/controller_sdl.c index 9e1b7a4..3284446 100644 --- a/src/pc/controller/controller_sdl.c +++ b/src/pc/controller/controller_sdl.c @@ -51,7 +51,11 @@ static void controller_sdl_read(OSContPad *pad) { else SDL_SetRelativeMouseMode(SDL_FALSE); - SDL_GetRelativeMouseState(&mouse_x, &mouse_y); + const u32 mbuttons = SDL_GetRelativeMouseState(&mouse_x, &mouse_y); + + if (mbuttons & SDL_BUTTON_LMASK) pad->button |= B_BUTTON; + if (mbuttons & SDL_BUTTON_RMASK) pad->button |= A_BUTTON; + if (mbuttons & SDL_BUTTON_MMASK) pad->button |= Z_TRIG; #endif SDL_GameControllerUpdate(); From 690283da13a948cfe2d2d1d7695c6a1d96f5c942 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Sun, 10 May 2020 19:05:54 +0300 Subject: [PATCH 2/5] allow rebinding of joystick and mouse buttons --- src/pc/configfile.c | 24 ++++++++++++++++++++++++ src/pc/configfile.h | 12 ++++++++++++ src/pc/controller/controller_sdl.c | 20 ++++++++++++-------- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/pc/configfile.c b/src/pc/configfile.c index a2de665..8f304ab 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -45,6 +45,19 @@ unsigned int configKeyStickUp = 0x11; unsigned int configKeyStickDown = 0x1F; unsigned int configKeyStickLeft = 0x1E; unsigned int configKeyStickRight = 0x20; +// Gamepad mappings (SDL_GameControllerButton values) +unsigned int configJoyA = 0; +unsigned int configJoyB = 2; +unsigned int configJoyStart = 6; +unsigned int configJoyL = 9; +unsigned int configJoyR = 10; +unsigned int configJoyZ = 7; +// Mouse button mappings (0 for none, 1 for left, 2 for middle, 3 for right) +unsigned int configMouseA = 3; +unsigned int configMouseB = 1; +unsigned int configMouseL = 4; +unsigned int configMouseR = 5; +unsigned int configMouseZ = 2; static const struct ConfigOption options[] = { @@ -63,6 +76,17 @@ static const struct ConfigOption options[] = { {.name = "key_stickdown", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyStickDown}, {.name = "key_stickleft", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyStickLeft}, {.name = "key_stickright", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyStickRight}, + {.name = "joy_a", .type = CONFIG_TYPE_UINT, .uintValue = &configJoyA}, + {.name = "joy_b", .type = CONFIG_TYPE_UINT, .uintValue = &configJoyB}, + {.name = "joy_start", .type = CONFIG_TYPE_UINT, .uintValue = &configJoyStart}, + {.name = "joy_l", .type = CONFIG_TYPE_UINT, .uintValue = &configJoyL}, + {.name = "joy_r", .type = CONFIG_TYPE_UINT, .uintValue = &configJoyR}, + {.name = "joy_z", .type = CONFIG_TYPE_UINT, .uintValue = &configJoyZ}, + {.name = "mouse_a", .type = CONFIG_TYPE_UINT, .uintValue = &configMouseA}, + {.name = "mouse_b", .type = CONFIG_TYPE_UINT, .uintValue = &configMouseB}, + {.name = "mouse_l", .type = CONFIG_TYPE_UINT, .uintValue = &configMouseL}, + {.name = "mouse_r", .type = CONFIG_TYPE_UINT, .uintValue = &configMouseR}, + {.name = "mouse_z", .type = CONFIG_TYPE_UINT, .uintValue = &configMouseZ}, }; // Reads an entire line from a file (excluding the newline character) and returns an allocated string diff --git a/src/pc/configfile.h b/src/pc/configfile.h index 7128aaa..1796816 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -16,6 +16,18 @@ extern unsigned int configKeyStickUp; extern unsigned int configKeyStickDown; extern unsigned int configKeyStickLeft; extern unsigned int configKeyStickRight; +extern unsigned int configJoyA; +extern unsigned int configJoyB; +extern unsigned int configJoyStart; +extern unsigned int configJoyL; +extern unsigned int configJoyR; +extern unsigned int configJoyZ; +extern unsigned int configMouseA; +extern unsigned int configMouseB; +extern unsigned int configMouseStart; +extern unsigned int configMouseL; +extern unsigned int configMouseR; +extern unsigned int configMouseZ; void configfile_load(const char *filename); void configfile_save(const char *filename); diff --git a/src/pc/controller/controller_sdl.c b/src/pc/controller/controller_sdl.c index 3284446..77e37d4 100644 --- a/src/pc/controller/controller_sdl.c +++ b/src/pc/controller/controller_sdl.c @@ -12,6 +12,8 @@ #include "controller_api.h" +#include "../configfile.h" + extern int16_t rightx; extern int16_t righty; @@ -53,9 +55,11 @@ static void controller_sdl_read(OSContPad *pad) { const u32 mbuttons = SDL_GetRelativeMouseState(&mouse_x, &mouse_y); - if (mbuttons & SDL_BUTTON_LMASK) pad->button |= B_BUTTON; - if (mbuttons & SDL_BUTTON_RMASK) pad->button |= A_BUTTON; - if (mbuttons & SDL_BUTTON_MMASK) pad->button |= Z_TRIG; + if (configMouseA && (mbuttons & SDL_BUTTON(configMouseA))) pad->button |= A_BUTTON; + if (configMouseB && (mbuttons & SDL_BUTTON(configMouseB))) pad->button |= B_BUTTON; + if (configMouseL && (mbuttons & SDL_BUTTON(configMouseL))) pad->button |= L_TRIG; + if (configMouseR && (mbuttons & SDL_BUTTON(configMouseR))) pad->button |= R_TRIG; + if (configMouseZ && (mbuttons & SDL_BUTTON(configMouseZ))) pad->button |= Z_TRIG; #endif SDL_GameControllerUpdate(); @@ -78,11 +82,11 @@ static void controller_sdl_read(OSContPad *pad) { } } - if (SDL_GameControllerGetButton(sdl_cntrl, SDL_CONTROLLER_BUTTON_START)) pad->button |= START_BUTTON; - if (SDL_GameControllerGetButton(sdl_cntrl, SDL_CONTROLLER_BUTTON_LEFTSHOULDER)) pad->button |= Z_TRIG; - if (SDL_GameControllerGetButton(sdl_cntrl, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER)) pad->button |= R_TRIG; - if (SDL_GameControllerGetButton(sdl_cntrl, SDL_CONTROLLER_BUTTON_A)) pad->button |= A_BUTTON; - if (SDL_GameControllerGetButton(sdl_cntrl, SDL_CONTROLLER_BUTTON_X)) pad->button |= B_BUTTON; + if (SDL_GameControllerGetButton(sdl_cntrl, configJoyStart)) pad->button |= START_BUTTON; + if (SDL_GameControllerGetButton(sdl_cntrl, configJoyL)) pad->button |= Z_TRIG; + if (SDL_GameControllerGetButton(sdl_cntrl, configJoyR)) pad->button |= R_TRIG; + if (SDL_GameControllerGetButton(sdl_cntrl, configJoyA)) pad->button |= A_BUTTON; + if (SDL_GameControllerGetButton(sdl_cntrl, configJoyB)) pad->button |= B_BUTTON; int16_t leftx = SDL_GameControllerGetAxis(sdl_cntrl, SDL_CONTROLLER_AXIS_LEFTX); int16_t lefty = SDL_GameControllerGetAxis(sdl_cntrl, SDL_CONTROLLER_AXIS_LEFTY); From d6820f6073e8fd6bd5bac2e92980e520a7d18ea8 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Sun, 10 May 2020 19:09:43 +0300 Subject: [PATCH 3/5] whoops, this is supposed to be the Z button --- src/pc/controller/controller_sdl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pc/controller/controller_sdl.c b/src/pc/controller/controller_sdl.c index 77e37d4..f7c8b81 100644 --- a/src/pc/controller/controller_sdl.c +++ b/src/pc/controller/controller_sdl.c @@ -83,7 +83,7 @@ static void controller_sdl_read(OSContPad *pad) { } if (SDL_GameControllerGetButton(sdl_cntrl, configJoyStart)) pad->button |= START_BUTTON; - if (SDL_GameControllerGetButton(sdl_cntrl, configJoyL)) pad->button |= Z_TRIG; + if (SDL_GameControllerGetButton(sdl_cntrl, configJoyZ)) pad->button |= Z_TRIG; if (SDL_GameControllerGetButton(sdl_cntrl, configJoyR)) pad->button |= R_TRIG; if (SDL_GameControllerGetButton(sdl_cntrl, configJoyA)) pad->button |= A_BUTTON; if (SDL_GameControllerGetButton(sdl_cntrl, configJoyB)) pad->button |= B_BUTTON; From 2234e28625f785fcfc71fab3529e76f42274f0d3 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Sun, 10 May 2020 19:14:59 +0300 Subject: [PATCH 4/5] rebind Z trigger back to L --- src/pc/configfile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pc/configfile.c b/src/pc/configfile.c index 8f304ab..57b9a4f 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -49,9 +49,9 @@ unsigned int configKeyStickRight = 0x20; unsigned int configJoyA = 0; unsigned int configJoyB = 2; unsigned int configJoyStart = 6; -unsigned int configJoyL = 9; +unsigned int configJoyL = 7; unsigned int configJoyR = 10; -unsigned int configJoyZ = 7; +unsigned int configJoyZ = 9; // Mouse button mappings (0 for none, 1 for left, 2 for middle, 3 for right) unsigned int configMouseA = 3; unsigned int configMouseB = 1; From d0b85785fe8956069fbda113816dc196b2606701 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Sun, 10 May 2020 19:15:13 +0300 Subject: [PATCH 5/5] might as well check for L while we're at it --- src/pc/controller/controller_sdl.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pc/controller/controller_sdl.c b/src/pc/controller/controller_sdl.c index f7c8b81..4812023 100644 --- a/src/pc/controller/controller_sdl.c +++ b/src/pc/controller/controller_sdl.c @@ -84,6 +84,7 @@ static void controller_sdl_read(OSContPad *pad) { if (SDL_GameControllerGetButton(sdl_cntrl, configJoyStart)) pad->button |= START_BUTTON; if (SDL_GameControllerGetButton(sdl_cntrl, configJoyZ)) pad->button |= Z_TRIG; + if (SDL_GameControllerGetButton(sdl_cntrl, configJoyL)) pad->button |= L_TRIG; if (SDL_GameControllerGetButton(sdl_cntrl, configJoyR)) pad->button |= R_TRIG; if (SDL_GameControllerGetButton(sdl_cntrl, configJoyA)) pad->button |= A_BUTTON; if (SDL_GameControllerGetButton(sdl_cntrl, configJoyB)) pad->button |= B_BUTTON;