From f88493870a7796c944feb6747ca818f5aa37609e Mon Sep 17 00:00:00 2001 From: Catherine Reprobate Date: Sun, 20 Aug 2023 21:54:10 -0700 Subject: [PATCH] Address multiple extended input nits - Q for radial menu - mapped remaining xbla buttons, but the menus follow switch controller handfeel - based on @Phnod's switch-weapons PR: https://github.com/fgsfdsfgs/perfect_dark/pull/57 --- include/PR/os_cont.h | 30 +++++++++ port/src/input.c | 15 ++--- src/game/bondbike.c | 2 +- src/game/bondeyespy.c | 5 ++ src/game/bondgrab.c | 4 +- src/game/bondmove.c | 148 ++++++++++++++++++++++++------------------ src/game/bondwalk.c | 2 +- src/game/menu.c | 11 ++++ 8 files changed, 142 insertions(+), 75 deletions(-) diff --git a/include/PR/os_cont.h b/include/PR/os_cont.h index 5d81bab62..d176c7701 100644 --- a/include/PR/os_cont.h +++ b/include/PR/os_cont.h @@ -171,6 +171,36 @@ typedef struct { #define CONT_ERR_VOICE_NO_RESPONSE 15 + + +#ifdef PLATFORM_N64 + +#define BUTTON_ACCEPT_WPNFORWARD CONT_A +#define BUTTON_CANCEL_USE CONT_B + +#define BUTTON_USE BUTTON_CANCEL_USE +#define BUTTON_CANCEL BUTTON_CANCEL_USE +#define BUTTON_RELOAD BUTTON_USE +#define BUTTON_ACCEPT BUTTON_ACCEPT_WPNFORWARD +#define BUTTON_WPNFORWARD BUTTON_ACCEPT_WPNFORWARD + +#else + +// xbla behavior +#define BUTTON_ACCEPT_USE A_BUTTON +// 1964 behavior +#define BUTTON_CANCEL_USE B_BUTTON + +#define BUTTON_RELOAD X_BUTTON +// dedicated button for mousewheel / xbla parity +#define BUTTON_WPNBACK L_JPAD +// dedicated button for mousewheel / xbla parity +#define BUTTON_WPNFORWARD Y_BUTTON +#define BUTTON_RADIAL D_JPAD +#define BUTTON_ALTMODE L_TRIG +#endif + + #if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) /************************************************************************** diff --git a/port/src/input.c b/port/src/input.c index 185645096..eb3c6d87e 100644 --- a/port/src/input.c +++ b/port/src/input.c @@ -57,18 +57,16 @@ void inputSetDefaultKeyBinds(void) { // TODO: make VK constants for all these static const u32 kbbinds[][3] = { - { CK_A, SDL_SCANCODE_Q, 0 }, { CK_B, SDL_SCANCODE_E, 0 }, { CK_X, SDL_SCANCODE_R, 0 }, - { CK_Y, SDL_SCANCODE_R, 0 }, { CK_RTRIG, VK_MOUSE_RIGHT, SDL_SCANCODE_Z }, { CK_LTRIG, SDL_SCANCODE_F, SDL_SCANCODE_X }, { CK_ZTRIG, VK_MOUSE_LEFT, SDL_SCANCODE_SPACE }, { CK_START, SDL_SCANCODE_RETURN, SDL_SCANCODE_TAB }, - { CK_DPAD_D, SDL_SCANCODE_G, VK_MOUSE_MIDDLE }, + { CK_DPAD_D, SDL_SCANCODE_Q, VK_MOUSE_MIDDLE }, { CK_DPAD_U, 0, 0 }, - { CK_DPAD_R, VK_MOUSE_WHEEL_UP, 0 }, - { CK_DPAD_L, VK_MOUSE_WHEEL_DN, 0 }, + { CK_Y, VK_MOUSE_WHEEL_DN, 0 }, + { CK_DPAD_L, VK_MOUSE_WHEEL_UP, 0 }, { CK_C_D, SDL_SCANCODE_S, 0 }, { CK_C_U, SDL_SCANCODE_W, 0 }, { CK_C_R, SDL_SCANCODE_D, 0 }, @@ -80,12 +78,11 @@ void inputSetDefaultKeyBinds(void) }; static const u32 joybinds[][2] = { - // { CK_A, SDL_CONTROLLER_BUTTON_A }, { CK_B, SDL_CONTROLLER_BUTTON_A }, + { CK_A, SDL_CONTROLLER_BUTTON_B }, { CK_X, SDL_CONTROLLER_BUTTON_X }, - { CK_Y, SDL_CONTROLLER_BUTTON_BACK }, - { CK_DPAD_L, SDL_CONTROLLER_BUTTON_Y, }, - { CK_DPAD_R, SDL_CONTROLLER_BUTTON_B, }, + { CK_Y, SDL_CONTROLLER_BUTTON_Y }, + { CK_DPAD_L, SDL_CONTROLLER_BUTTON_B, }, { CK_DPAD_D, SDL_CONTROLLER_BUTTON_LEFTSHOULDER }, { CK_LTRIG, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER }, { CK_RTRIG, VK_JOY1_LTRIG - VK_JOY1_BEGIN }, diff --git a/src/game/bondbike.c b/src/game/bondbike.c index ce29b43f5..b08e91856 100644 --- a/src/game/bondbike.c +++ b/src/game/bondbike.c @@ -192,7 +192,7 @@ void bbikeHandleActivate(void) bmoveSetMode(MOVEMODE_WALK); } - g_Vars.currentplayer->bondactivateorreload = 0; + // g_Vars.currentplayer->bondactivateorreload = 0; } } diff --git a/src/game/bondeyespy.c b/src/game/bondeyespy.c index 900e0ec38..8ffe51e9a 100644 --- a/src/game/bondeyespy.c +++ b/src/game/bondeyespy.c @@ -752,8 +752,13 @@ void eyespyProcessInput(bool allowbuttons) shootpressed = c1buttons & Z_TRIG; } + #ifdef PLATFORM_N64 exitpressed = (c1buttons | c2buttons) & A_BUTTON; activatepressed = (c1buttons | c2buttons) & B_BUTTON; + #else + exitpressed = (c1buttons | c2buttons) & BUTTON_ACCEPT_USE; + activatepressed = (c1buttons | c2buttons) & BUTTON_CANCEL_USE; + #endif } // Apply safe zone for c1stickx diff --git a/src/game/bondgrab.c b/src/game/bondgrab.c index cfca0b60f..a7ebbbb96 100644 --- a/src/game/bondgrab.c +++ b/src/game/bondgrab.c @@ -891,9 +891,9 @@ void bgrabUpdateVertical(void) void bgrabHandleActivate(void) { if (currentPlayerTryMountHoverbike(g_Vars.currentplayer->grabbedprop)) { - g_Vars.currentplayer->bondactivateorreload = 0; + // g_Vars.currentplayer->bondactivateorreload = 0; } else { - g_Vars.currentplayer->bondactivateorreload = 0; + // g_Vars.currentplayer->bondactivateorreload = 0; bmoveSetMode(MOVEMODE_WALK); } } diff --git a/src/game/bondmove.c b/src/game/bondmove.c index da0e3ae41..d1cc1c8dd 100644 --- a/src/game/bondmove.c +++ b/src/game/bondmove.c @@ -903,14 +903,15 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i } } else { for (i = 0; i < numsamples; i++) { - if (joyGetButtonsPressedOnSample(i, contpad1, c1allowedbuttons & L_JPAD)) { + #ifndef PLATFORM_N64 + if (joyGetButtonsPressedOnSample(i, contpad1, c1allowedbuttons & BUTTON_WPNFORWARD)) { movedata.weaponforwardoffset++; g_Vars.currentplayer->invdowntime = -1; - } else - if (joyGetButtonsPressedOnSample(i, contpad1, c1allowedbuttons & R_JPAD)) { + } else if (joyGetButtonsPressedOnSample(i, contpad1, c1allowedbuttons & BUTTON_WPNBACK)) { movedata.weaponbackoffset++; g_Vars.currentplayer->invdowntime = -1; } + #else if (joyGetButtonsOnSample(i, contpad1, c1allowedbuttons & A_BUTTON) || joyGetButtonsOnSample(i, contpad2, c2allowedbuttons & A_BUTTON)) { if (g_Vars.currentplayer->invdowntime > -2) { @@ -937,10 +938,12 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i g_Vars.currentplayer->invdowntime = 0; } + #endif } } } + #ifdef PLATFORM_N64 // Handle B button activation if (allowc1buttons) { for (i = 0; i < numsamples; i++) { @@ -982,6 +985,7 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i } } } + #endif // Handle manual zoom in and out (sniper, farsight and horizon scanner) if (canmanualzoom && g_Vars.currentplayer->insightaimmode) { @@ -1283,14 +1287,15 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i } } else { for (i = 0; i < numsamples; i++) { - if (joyGetButtonsPressedOnSample(i, contpad1, c1allowedbuttons & L_JPAD)) { + #ifndef PLATFORM_N64 + if (joyGetButtonsPressedOnSample(i, contpad1, c1allowedbuttons & BUTTON_WPNFORWARD)) { movedata.weaponforwardoffset++; g_Vars.currentplayer->invdowntime = -1; - } else - if (joyGetButtonsPressedOnSample(i, contpad1, c1allowedbuttons & R_JPAD)) { + } else if (joyGetButtonsPressedOnSample(i, contpad1, c1allowedbuttons & BUTTON_WPNBACK)) { movedata.weaponbackoffset++; g_Vars.currentplayer->invdowntime = -1; } + #else if (joyGetButtonsOnSample(i, contpad1, invbuttons & c1allowedbuttons)) { if (g_Vars.currentplayer->invdowntime > -2) { if (joyGetButtonsPressedOnSample(i, contpad1, shootbuttons & c1allowedbuttons)) { @@ -1318,10 +1323,12 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i g_Vars.currentplayer->invdowntime = 0; } + #endif } } } + #ifdef PLATFORM_N64 // Handle B button if (allowc1buttons) { for (i = 0; i < numsamples; i++) { @@ -1364,75 +1371,92 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i } } } + #endif - // handle L button - for (i = 0; i< numsamples; i++) { - if (joyGetButtonsOnSample(i, contpad1, c1allowedbuttons & L_TRIG)) { - if (g_Vars.currentplayer->altdowntime >= -1) { - if (joyGetButtonsPressedOnSample(i, contpad1, shootbuttons & c1allowedbuttons) - && g_Vars.currentplayer->altdowntime >= 0 - && bgunConsiderToggleGunFunction(g_Vars.currentplayer->altdowntime, true, false, true) != USETIMER_CONTINUE) { - g_Vars.currentplayer->altdowntime = -3; + #ifndef PLATFORM_N64 + if (allowc1buttons) { + // handle B / A: cancel_use + for (i = 0; i < numsamples; i++) { + if (joyGetButtonsOnSample(i, contpad1, c1allowedbuttons & (BUTTON_CANCEL_USE | BUTTON_ACCEPT_USE))) { + g_Vars.currentplayer->usedowntime++; + } else { + if (g_Vars.currentplayer->usedowntime > 0) { + movedata.btapcount++; + g_Vars.currentplayer->usedowntime = 0; } + } - if (g_Vars.currentplayer->altdowntime != -4) { - if (g_Vars.currentplayer->altdowntime <= 0) { - g_Vars.currentplayer->altdowntime++; + } + // handle L button : alt switching + for (i = 0; i< numsamples; i++) { + if (joyGetButtonsOnSample(i, contpad1, c1allowedbuttons & BUTTON_ALTMODE)) { + if (g_Vars.currentplayer->altdowntime >= -1) { + if (joyGetButtonsPressedOnSample(i, contpad1, shootbuttons & c1allowedbuttons) + && g_Vars.currentplayer->altdowntime >= 0 + && bgunConsiderToggleGunFunction(g_Vars.currentplayer->altdowntime, true, false, true) != USETIMER_CONTINUE) { + g_Vars.currentplayer->altdowntime = -3; } - } - } else { - if (g_Vars.currentplayer->altdowntime == -2) { - bgunConsiderToggleGunFunction(g_Vars.currentplayer->altdowntime, false, false, true); - g_Vars.currentplayer->altdowntime = -4; - } - } - } else { - // Released L - if (g_Vars.currentplayer->altdowntime != 0) { - s32 result = bgunConsiderToggleGunFunction(g_Vars.currentplayer->altdowntime, (g_Vars.currentplayer->altdowntime == -3 ? true: false), false, true); - if (result == USETIMER_STOP) { - g_Vars.currentplayer->altdowntime = -1; - } else if (result == USETIMER_REPEAT) { - g_Vars.currentplayer->altdowntime = -2; - } - } - g_Vars.currentplayer->altdowntime = 0; - } - } - - // Handle ALT1 / MI Reload Hack - for (i = 0; i < numsamples; i++) { - if (joyGetButtonsOnSample(i, contpad1, c1allowedbuttons & X_BUTTON)) { - movedata.alt1tapcount++; - } - } - - - // Handle radial menu (D-Down) - for (i = 0; i < numsamples; i++) { - if (joyGetButtonsOnSample(i, contpad1, c1allowedbuttons & D_JPAD)) { - if (g_Vars.currentplayer->amdowntime < -2) { - g_Vars.currentplayer->amdowntime += numsamples; - - if (g_Vars.currentplayer->amdowntime > -3) { - g_Vars.currentplayer->amdowntime = 0; + if (g_Vars.currentplayer->altdowntime != -4) { + if (g_Vars.currentplayer->altdowntime <= 0) { + g_Vars.currentplayer->altdowntime++; + } + } + } else { + if (g_Vars.currentplayer->altdowntime == -2) { + bgunConsiderToggleGunFunction(g_Vars.currentplayer->altdowntime, false, false, true); + g_Vars.currentplayer->altdowntime = -4; + } } } else { - if (g_Vars.currentplayer->amdowntime >= 0) { - if (joyGetButtonsPressedOnSample(i, contpad1, c1allowedbuttons & D_JPAD)) { - amOpen(); - g_Vars.currentplayer->amdowntime = -1; - } else { - g_Vars.currentplayer->amdowntime++; + // Released L + if (g_Vars.currentplayer->altdowntime != 0) { + s32 result = bgunConsiderToggleGunFunction(g_Vars.currentplayer->altdowntime, (g_Vars.currentplayer->altdowntime == -3 ? true: false), false, true); + + if (result == USETIMER_STOP) { + g_Vars.currentplayer->altdowntime = -1; + } else if (result == USETIMER_REPEAT) { + g_Vars.currentplayer->altdowntime = -2; } } + g_Vars.currentplayer->altdowntime = 0; + } + } + + // Handle ALT1 / MI Reload Hack + for (i = 0; i < numsamples; i++) { + if (joyGetButtonsOnSample(i, contpad1, c1allowedbuttons & BUTTON_RELOAD)) { + movedata.alt1tapcount++; + } + } + + + // Handle radial menu (D-Down) + for (i = 0; i < numsamples; i++) { + if (joyGetButtonsOnSample(i, contpad1, c1allowedbuttons & BUTTON_RADIAL)) { + if (g_Vars.currentplayer->amdowntime < -2) { + g_Vars.currentplayer->amdowntime += numsamples; + + if (g_Vars.currentplayer->amdowntime > -3) { + g_Vars.currentplayer->amdowntime = 0; + } + } else { + if (g_Vars.currentplayer->amdowntime >= 0) { + if (joyGetButtonsPressedOnSample(i, contpad1, c1allowedbuttons & BUTTON_RADIAL)) { + amOpen(); + g_Vars.currentplayer->amdowntime = -1; + } else { + g_Vars.currentplayer->amdowntime++; + } + } + } + } else { + g_Vars.currentplayer->amdowntime = 0; } - } else { - g_Vars.currentplayer->amdowntime = 0; } } + #endif // Handle manual zoom in and out (sniper, farsight and horizon scanner) if (canmanualzoom && g_Vars.currentplayer->insightaimmode) { diff --git a/src/game/bondwalk.c b/src/game/bondwalk.c index 45120d8b3..b364cfe4d 100644 --- a/src/game/bondwalk.c +++ b/src/game/bondwalk.c @@ -1280,7 +1280,7 @@ void bwalkUpdatePrevPos(void) void bwalkHandleActivate(void) { if (g_Vars.currentplayer->walkinitmove) { - g_Vars.currentplayer->bondactivateorreload = 0; + // g_Vars.currentplayer->bondactivateorreload = 0; } } diff --git a/src/game/menu.c b/src/game/menu.c index cc88cc78d..e95c69c68 100644 --- a/src/game/menu.c +++ b/src/game/menu.c @@ -4607,6 +4607,17 @@ void menuProcessInput(void) inputs.select = 1; } + #ifndef PLATFORM_N64 + // this seems sensible to achieve 1964 parity + if (buttonsnow & BUTTON_RADIAL) { + inputs.select = 1; + } + // this will naturally feel nice w/ a switch layout + // with the default mapping for weapon-back + if (buttonsnow & BUTTON_WPNBACK) { + inputs.select = 1; + } + #endif if (buttonsnow & B_BUTTON) { inputs.back = 1; }