From e43d29f357c8be9511aca39fd886b5d8f85c6360 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Fri, 24 Nov 2023 22:30:52 +0100 Subject: [PATCH] port: add hold crouch --- port/src/main.c | 2 +- port/src/optionsmenu.c | 44 +++++++++++++++++++----------- src/game/bondmove.c | 56 +++++++++++++++++++++++--------------- src/game/mplayer/mplayer.c | 2 +- src/include/constants.h | 5 ++++ src/include/types.h | 2 +- 6 files changed, 70 insertions(+), 41 deletions(-) diff --git a/port/src/main.c b/port/src/main.c index 24060be6d..b3b055079 100644 --- a/port/src/main.c +++ b/port/src/main.c @@ -160,6 +160,6 @@ PD_CONSTRUCTOR static void gameConfigInit(void) configRegisterFloat(strFmt("Game.Player%d.MouseAimSpeedY", i), &g_PlayerExtCfg[j].mouseaimspeedy, 0.f, 10.f); configRegisterFloat(strFmt("Game.Player%d.RadialMenuSpeed", i), &g_PlayerExtCfg[j].radialmenuspeed, 0.f, 10.f); configRegisterFloat(strFmt("Game.Player%d.CrosshairSway", i), &g_PlayerExtCfg[j].crosshairsway, 0.f, 10.f); - configRegisterInt(strFmt("Game.Player%d.ClassicCrouch", i), &g_PlayerExtCfg[j].classiccrouch, 0, 1); + configRegisterInt(strFmt("Game.Player%d.CrouchMode", i), &g_PlayerExtCfg[j].crouchmode, 0, CROUCHMODE_TOGGLE_ANALOG); } } diff --git a/port/src/optionsmenu.c b/port/src/optionsmenu.c index 4e428071c..9704c757d 100644 --- a/port/src/optionsmenu.c +++ b/port/src/optionsmenu.c @@ -723,32 +723,44 @@ struct menudialogdef g_ExtendedVideoMenuDialog = { NULL, }; -static MenuItemHandlerResult menuhandlerFieldOfView(s32 operation, struct menuitem *item, union handlerdata *data) +static MenuItemHandlerResult menuhandlerCrouchMode(s32 operation, struct menuitem *item, union handlerdata *data) { + static const char *opts[] = { + "Hold", + "Analog", + "Toggle", + "Toggle + Analog" + }; + switch (operation) { - case MENUOP_GETSLIDER: - data->slider.value = g_PlayerExtCfg[g_ExtMenuPlayer].fovy + 0.5f; + case MENUOP_GETOPTIONCOUNT: + data->dropdown.value = ARRAYCOUNT(opts); break; + case MENUOP_GETOPTIONTEXT: + return (intptr_t)opts[data->dropdown.value]; case MENUOP_SET: - if (data->slider.value >= 15) { - g_PlayerExtCfg[g_ExtMenuPlayer].fovy = data->slider.value; - if (g_PlayerExtCfg[g_ExtMenuPlayer].fovzoom) { - g_PlayerExtCfg[g_ExtMenuPlayer].fovzoommult = g_PlayerExtCfg[g_ExtMenuPlayer].fovy / 60.f; - } - } + g_PlayerExtCfg[g_ExtMenuPlayer].crouchmode = data->dropdown.value; break; + case MENUOP_GETSELECTEDINDEX: + data->dropdown.value = g_PlayerExtCfg[g_ExtMenuPlayer].crouchmode; } return 0; } -static MenuItemHandlerResult menuhandlerClassicCrouch(s32 operation, struct menuitem *item, union handlerdata *data) +static MenuItemHandlerResult menuhandlerFieldOfView(s32 operation, struct menuitem *item, union handlerdata *data) { switch (operation) { - case MENUOP_GET: - return g_PlayerExtCfg[g_ExtMenuPlayer].classiccrouch; + case MENUOP_GETSLIDER: + data->slider.value = g_PlayerExtCfg[g_ExtMenuPlayer].fovy + 0.5f; + break; case MENUOP_SET: - g_PlayerExtCfg[g_ExtMenuPlayer].classiccrouch = data->checkbox.value; + if (data->slider.value >= 15) { + g_PlayerExtCfg[g_ExtMenuPlayer].fovy = data->slider.value; + if (g_PlayerExtCfg[g_ExtMenuPlayer].fovzoom) { + g_PlayerExtCfg[g_ExtMenuPlayer].fovzoommult = g_PlayerExtCfg[g_ExtMenuPlayer].fovy / 60.f; + } + } break; } @@ -771,12 +783,12 @@ static MenuItemHandlerResult menuhandlerCrosshairSway(s32 operation, struct menu struct menuitem g_ExtendedGameMenuItems[] = { { - MENUITEMTYPE_CHECKBOX, + MENUITEMTYPE_DROPDOWN, 0, MENUITEMFLAG_LITERAL_TEXT, - (uintptr_t)"Allow Classic Crouch", + (uintptr_t)"Crouch Mode", 0, - menuhandlerClassicCrouch, + menuhandlerCrouchMode, }, { MENUITEMTYPE_SLIDER, diff --git a/src/game/bondmove.c b/src/game/bondmove.c index 45f75ea6c..5e44e837a 100644 --- a/src/game/bondmove.c +++ b/src/game/bondmove.c @@ -1565,31 +1565,43 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i // Handle xbla-style crouch cycling for (i = 0; i < numsamples; i++) { - s32 crouchsample = joyGetButtonsPressedOnSample(i, contpad1, 0xffffffff) & BUTTON_CROUCH_CYCLE; - if (crouchsample) { - if (g_Vars.currentplayer->crouchpos <= 0) { - g_Vars.currentplayer->crouchpos = CROUCHPOS_STAND; - } else { - g_Vars.currentplayer->crouchpos--; - } - } - // handle 1964GEPD style crouch setting - crouchsample = joyGetButtonsPressedOnSample(i, contpad1, c1allowedbuttons) & BUTTON_HALF_CROUCH; - if (crouchsample) { - if (g_Vars.currentplayer->crouchpos == CROUCHPOS_DUCK) { - g_Vars.currentplayer->crouchpos = CROUCHPOS_STAND; - } else { - g_Vars.currentplayer->crouchpos = CROUCHPOS_DUCK; + s32 crouchsample; + if (PLAYER_EXTCFG().crouchmode & CROUCHMODE_TOGGLE) { + // press to toggle crouch position + crouchsample = joyGetButtonsPressedOnSample(i, contpad1, 0xffffffff) & BUTTON_CROUCH_CYCLE; + if (crouchsample) { + if (g_Vars.currentplayer->crouchpos <= 0) { + g_Vars.currentplayer->crouchpos = CROUCHPOS_STAND; + } else { + g_Vars.currentplayer->crouchpos--; + } } - } - - crouchsample = joyGetButtonsPressedOnSample(i, contpad1, c1allowedbuttons) & BUTTON_FULL_CROUCH; - if (crouchsample) { - if (g_Vars.currentplayer->crouchpos == CROUCHPOS_SQUAT) { + crouchsample = joyGetButtonsPressedOnSample(i, contpad1, c1allowedbuttons) & BUTTON_HALF_CROUCH; + if (crouchsample) { + if (g_Vars.currentplayer->crouchpos == CROUCHPOS_DUCK) { + g_Vars.currentplayer->crouchpos = CROUCHPOS_STAND; + } else { + g_Vars.currentplayer->crouchpos = CROUCHPOS_DUCK; + } + } + crouchsample = joyGetButtonsPressedOnSample(i, contpad1, c1allowedbuttons) & BUTTON_FULL_CROUCH; + if (crouchsample) { + if (g_Vars.currentplayer->crouchpos == CROUCHPOS_SQUAT) { + g_Vars.currentplayer->crouchpos = CROUCHPOS_STAND; + } else { + g_Vars.currentplayer->crouchpos = CROUCHPOS_SQUAT; + } + } + } else if (PLAYER_EXTCFG().crouchmode == CROUCHMODE_HOLD) { + // hold to crouch + crouchsample = joyGetButtonsOnSample(i, contpad1, c1allowedbuttons) & (BUTTON_FULL_CROUCH | BUTTON_HALF_CROUCH); + if (!crouchsample) { g_Vars.currentplayer->crouchpos = CROUCHPOS_STAND; - } else { + } else if (crouchsample & BUTTON_FULL_CROUCH) { g_Vars.currentplayer->crouchpos = CROUCHPOS_SQUAT; + } else if (crouchsample & BUTTON_HALF_CROUCH) { + g_Vars.currentplayer->crouchpos = CROUCHPOS_DUCK; } } } @@ -1657,7 +1669,7 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i #endif // Handle C-button and analog crouch and uncrouch, if enabled - if (PLAYER_EXTCFG().classiccrouch && allowc1buttons) { + if ((PLAYER_EXTCFG().crouchmode & CROUCHMODE_ANALOG) && allowc1buttons) { for (i = 0; i < numsamples; i++) { if (!canmanualzoom && aimonhist[i]) { bool goUp = joyGetButtonsPressedOnSample(i, contpad1, c1allowedbuttons & (U_CBUTTONS)); diff --git a/src/game/mplayer/mplayer.c b/src/game/mplayer/mplayer.c index b389e6215..3faa30032 100644 --- a/src/game/mplayer/mplayer.c +++ b/src/game/mplayer/mplayer.c @@ -120,7 +120,7 @@ struct mpweapon g_MpWeapons[NUM_MPWEAPONS] = { .mouseaimspeedy = 0.7f, \ .radialmenuspeed = 4.f, \ .crosshairsway = 1.f, \ - .classiccrouch = true, \ + .crouchmode = CROUCHMODE_TOGGLE_ANALOG, \ } struct extplayerconfig g_PlayerExtCfg[MAX_PLAYERS] = { diff --git a/src/include/constants.h b/src/include/constants.h index cb7b93a7f..33eba0ed2 100644 --- a/src/include/constants.h +++ b/src/include/constants.h @@ -4701,6 +4701,11 @@ enum weaponnum { #define MOUSEAIM_CLASSIC 0 // crosshair moves around the screen in aim mode #define MOUSEAIM_LOCKED 1 // crosshair locked to the center of the screen in aim mode +#define CROUCHMODE_HOLD 0 // hold the crouch buttons to keep crouching +#define CROUCHMODE_ANALOG 1 // analog crouch like on n64 +#define CROUCHMODE_TOGGLE 2 // press the crouch buttons to toggle stance +#define CROUCHMODE_TOGGLE_ANALOG (CROUCHMODE_ANALOG | CROUCHMODE_TOGGLE) + #endif #endif diff --git a/src/include/types.h b/src/include/types.h index 171b0eda7..f307b8ada 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -6132,7 +6132,7 @@ struct extplayerconfig { s32 mouseaimmode; f32 mouseaimspeedx; f32 mouseaimspeedy; - s32 classiccrouch; + s32 crouchmode; f32 radialmenuspeed; f32 crosshairsway; };