Skip to content

Commit

Permalink
port: add hold crouch
Browse files Browse the repository at this point in the history
  • Loading branch information
fgsfdsfgs committed Nov 24, 2023
1 parent 3328e14 commit e43d29f
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 41 deletions.
2 changes: 1 addition & 1 deletion port/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
44 changes: 28 additions & 16 deletions port/src/optionsmenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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,
Expand Down
56 changes: 34 additions & 22 deletions src/game/bondmove.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/game/mplayer/mplayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand Down
5 changes: 5 additions & 0 deletions src/include/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -6132,7 +6132,7 @@ struct extplayerconfig {
s32 mouseaimmode;
f32 mouseaimspeedx;
f32 mouseaimspeedy;
s32 classiccrouch;
s32 crouchmode;
f32 radialmenuspeed;
f32 crosshairsway;
};
Expand Down

0 comments on commit e43d29f

Please sign in to comment.