Skip to content

Commit

Permalink
port: allow using N64 control schemes
Browse files Browse the repository at this point in the history
change from Ext to another control scheme to activate

note that this will require rebinding keys, as the default config is for the Ext scheme
  • Loading branch information
fgsfdsfgs committed Nov 26, 2023
1 parent 3a1d085 commit 600dae5
Show file tree
Hide file tree
Showing 18 changed files with 445 additions and 286 deletions.
1 change: 1 addition & 0 deletions port/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,6 @@ PD_CONSTRUCTOR static void gameConfigInit(void)
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.CrouchMode", i), &g_PlayerExtCfg[j].crouchmode, 0, CROUCHMODE_TOGGLE_ANALOG);
configRegisterInt(strFmt("Game.Player%d.ExtendedControls", i), &g_PlayerExtCfg[j].extcontrols, 0, 1);
}
}
35 changes: 21 additions & 14 deletions port/src/optionsmenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -886,22 +886,25 @@ struct menudialogdef g_ExtendedBindKeyMenuDialog = {
struct menubind {
u32 ck;
const char *name;
const char *n64name;
};

static const struct menubind menuBinds[] = {
{ CK_ZTRIG, "Fire [ZT]\n" },
{ CK_LTRIG, "Fire Mode [LT]\n" },
{ CK_RTRIG, "Aim Mode [RT]\n" },
{ CK_A, "Use / Accept [A]\n" },
{ CK_B, "Use / Cancel [B]\n" },
{ CK_X, "Reload [X]\n" },
{ CK_Y, "Next Weapon [Y]\n" },
{ CK_DPAD_L, "Prev Weapon [DL]\n" },
{ CK_DPAD_D, "Radial Menu [DD]\n" },
{ CK_START, "Pause Menu [ST]\n" },
{ CK_8000, "Cycle Crouch [+]\n" },
{ CK_4000, "Half Crouch [+]\n" },
{ CK_2000, "Full Crouch [+]\n" },
{ CK_ZTRIG, "Fire [ZT]\n", "N64 Z Trigger\n" },
{ CK_LTRIG, "Fire Mode [LT]\n", "N64 L Trigger\n"},
{ CK_RTRIG, "Aim Mode [RT]\n", "N64 R Trigger\n" },
{ CK_A, "Use / Accept [A]\n", "N64 A Button\n" },
{ CK_B, "Use / Cancel [B]\n", "N64 B Button\n" },
{ CK_X, "Reload [X]\n", "N64 Ext X\n" },
{ CK_Y, "Next Weapon [Y]\n", "N64 Ext Y\n" },
{ CK_DPAD_U, "D-Pad Up [DU]\n", "N64 D-Pad Up\n" },
{ CK_DPAD_R, "D-Pad Right [DR]\n", "N64 D-Pad Right\n" },
{ CK_DPAD_L, "Prev Weapon [DL]\n", "N64 D-Pad Left\n" },
{ CK_DPAD_D, "Radial Menu [DD]\n", "N64 D-Pad Down\n" },
{ CK_START, "Pause Menu [ST]\n", "N64 Start\n" },
{ CK_8000, "Cycle Crouch [+]\n", "N64 Ext 8000\n" },
{ CK_4000, "Half Crouch [+]\n", "N64 Ext 4000\n" },
{ CK_2000, "Full Crouch [+]\n", "N64 Ext 2000\n" },
};

static const char *menutextBind(struct menuitem *item);
Expand Down Expand Up @@ -932,6 +935,8 @@ struct menuitem g_ExtendedBindsMenuItems[] = {
DEFINE_MENU_BIND(),
DEFINE_MENU_BIND(),
DEFINE_MENU_BIND(),
DEFINE_MENU_BIND(),
DEFINE_MENU_BIND(),
{
MENUITEMTYPE_SEPARATOR,
0,
Expand Down Expand Up @@ -989,7 +994,9 @@ static MenuItemHandlerResult menuhandlerDoBind(s32 operation, struct menuitem *i

static const char *menutextBind(struct menuitem *item)
{
return menuBinds[item - g_ExtendedBindsMenuItems].name;
return g_PlayerExtCfg[g_ExtMenuPlayer].extcontrols ?
menuBinds[item - g_ExtendedBindsMenuItems].name :
menuBinds[item - g_ExtendedBindsMenuItems].n64name;
}

static MenuItemHandlerResult menuhandlerBind(s32 operation, struct menuitem *item, union handlerdata *data)
Expand Down
47 changes: 32 additions & 15 deletions src/game/activemenutick.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ void amTick(void)
s8 contpadnum = optionsGetContpadNum1(g_Vars.currentplayerstats->mpindex);
s32 numsamples = joyGetNumSamples();
s32 j;
u32 amask, lrtmask, umask, dmask, lmask, rmask;

if (controlmode == CONTROLMODE_PC) {
amask = D_JPAD;
lrtmask = R_TRIG;
umask = U_CBUTTONS;
dmask = D_CBUTTONS;
lmask = L_CBUTTONS;
rmask = R_CBUTTONS;
} else {
amask = A_BUTTON;
lrtmask = L_TRIG | R_TRIG;
umask = U_JPAD | U_CBUTTONS;
dmask = D_JPAD | D_CBUTTONS;
lmask = L_JPAD | L_CBUTTONS;
rmask = R_JPAD | R_CBUTTONS;
}

for (j = 0; j < numsamples; j++) {
s8 gotonextscreen = false;
Expand Down Expand Up @@ -94,19 +111,19 @@ void amTick(void)
#endif

if (g_Vars.currentplayer->activemenumode == AMMODE_EDIT) {
buttonsstate = buttonsstate & D_JPAD;
buttonsstate = buttonsstate & amask;
cstickx = 0;
csticky = 0;
buttonspressed = 0;
}

// JPN fixes the bug that's documented in amChangeScreen
if (controlmode == CONTROLMODE_13 || controlmode == CONTROLMODE_14) {
if ((buttonsstate & R_TRIG)) {
if (buttonsstate & (L_TRIG | R_TRIG)) {
stayopen = true;
}

if (buttonsstate & D_JPAD) {
if (buttonsstate & A_BUTTON) {
#if VERSION >= VERSION_JPN_FINAL || !defined(PLATFORM_N64)
if (g_Vars.currentplayer->numaibuddies > 0) {
g_AmMenus[g_AmIndex].allbots = true;
Expand All @@ -116,11 +133,11 @@ void amTick(void)
#endif
}
} else {
if (buttonsstate & D_JPAD) {
if (buttonsstate & amask) {
stayopen = true;
}

if ((buttonsstate & R_TRIG)) {
if (buttonsstate & lrtmask) {
#if VERSION >= VERSION_JPN_FINAL || !defined(PLATFORM_N64)
if (g_Vars.currentplayer->numaibuddies > 0) {
g_AmMenus[g_AmIndex].allbots = true;
Expand Down Expand Up @@ -148,19 +165,19 @@ void amTick(void)
amChangeScreen(0);
}

if (buttonsstate & U_CBUTTONS) {
if (buttonsstate & umask) {
row = 0;
}

if (buttonsstate & D_CBUTTONS) {
if (buttonsstate & dmask) {
row = 2;
}

if (buttonsstate & L_CBUTTONS) {
if (buttonsstate & lmask) {
column = 0;
}

if (buttonsstate & R_CBUTTONS) {
if (buttonsstate & rmask) {
column = 2;
}

Expand All @@ -175,33 +192,33 @@ void amTick(void)
u32 buttonspressed2 = joyGetButtonsPressedOnSample(j, contpadnum2, 0xffffffff);

if (g_Vars.currentplayer->activemenumode == AMMODE_EDIT) {
buttonsstate2 = buttonsstate2 & D_JPAD;
buttonsstate2 = buttonsstate2 & A_BUTTON;
cstickx2 = 0;
csticky2 = 0;
buttonspressed2 = 0;
}

if (buttonsstate2 & D_JPAD) {
if (buttonsstate2 & A_BUTTON) {
stayopen = true;
}

if (buttonspressed2 & Z_TRIG) {
toggle = true;
}

if (buttonsstate2 & U_CBUTTONS) {
if (buttonsstate2 & umask) {
row = 0;
}

if (buttonsstate2 & D_CBUTTONS) {
if (buttonsstate2 & dmask) {
row = 2;
}

if (buttonsstate2 & L_CBUTTONS) {
if (buttonsstate2 & lmask) {
column = 0;
}

if (buttonsstate2 & R_CBUTTONS) {
if (buttonsstate2 & rmask) {
column = 2;
}

Expand Down
22 changes: 16 additions & 6 deletions src/game/bondbike.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,24 @@ void bbikeApplyMoveData(struct movedata *data)
s8 contnum = optionsGetContpadNum1(g_Vars.currentplayerstats->mpindex);
f32 value1;
f32 tmp;
s32 contmode = optionsGetControlMode(g_Vars.currentplayerstats->mpindex);

if ((optionsGetControlMode(g_Vars.currentplayerstats->mpindex) == CONTROLMODE_12
|| optionsGetControlMode(g_Vars.currentplayerstats->mpindex) == CONTROLMODE_14
|| optionsGetControlMode(g_Vars.currentplayerstats->mpindex) == CONTROLMODE_13
|| optionsGetControlMode(g_Vars.currentplayerstats->mpindex) == CONTROLMODE_11)
if ((contmode == CONTROLMODE_12
|| contmode == CONTROLMODE_14
|| contmode == CONTROLMODE_13
|| contmode == CONTROLMODE_11
|| contmode == CONTROLMODE_PC)
&& !lvIsPaused()) {
data->digitalstepleft = joyCountButtonsOnSpecificSamples(0, contnum, L_CBUTTONS);
data->digitalstepright = joyCountButtonsOnSpecificSamples(0, contnum,R_CBUTTONS);
u32 lmask, rmask;
if (contmode == CONTROLMODE_PC) {
lmask = L_CBUTTONS;
rmask = R_CBUTTONS;
} else {
lmask = L_JPAD | L_CBUTTONS;
rmask = R_JPAD | R_CBUTTONS;
}
data->digitalstepleft = joyCountButtonsOnSpecificSamples(0, contnum, lmask);
data->digitalstepright = joyCountButtonsOnSpecificSamples(0, contnum, rmask);
}

// Forward/back
Expand Down
88 changes: 55 additions & 33 deletions src/game/bondeyespy.c
Original file line number Diff line number Diff line change
Expand Up @@ -720,20 +720,37 @@ void eyespyProcessInput(bool allowbuttons)
s32 contpad2;
u32 stack[5];
f32 tmp;
u32 umask, dmask, lmask, rmask;

if (controlmode >= CONTROLMODE_21) {
if (controlmode == CONTROLMODE_PC) {
umask = U_CBUTTONS;
dmask = D_CBUTTONS;
lmask = L_CBUTTONS;
rmask = R_CBUTTONS;
} else {
umask = U_JPAD | U_CBUTTONS;
dmask = D_JPAD | D_CBUTTONS;
lmask = L_JPAD | L_CBUTTONS;
rmask = R_JPAD | R_CBUTTONS;
}

if (controlmode >= CONTROLMODE_21 && controlmode < CONTROLMODE_PC) {
contpad2 = (s8) optionsGetContpadNum2(g_Vars.currentplayerstats->mpindex);
c2stickx = joyGetStickX(contpad2);
c2sticky = joyGetStickY(contpad2);

c2buttons = allowbuttons ? joyGetButtons(contpad2, 0xffffffff) : 0;
} else {
#ifndef PLATFORM_N64
c2stickx = joyGetRStickX(contpad1);
c2sticky = joyGetRStickY(contpad1);
if (controlmode == CONTROLMODE_PC) {
c2stickx = joyGetRStickX(contpad1);
c2sticky = joyGetRStickY(contpad1);
} else
#else
c2stickx = c1stickx;
c2sticky = c1sticky;
{
c2stickx = c1stickx;
c2sticky = c1sticky;
}
#endif
c2buttons = c1buttons;
}
Expand All @@ -743,16 +760,19 @@ void eyespyProcessInput(bool allowbuttons)
shootpressed = c1buttons & A_BUTTON;
exitpressed = c1buttons & R_TRIG;
activatepressed = c1buttons & B_BUTTON;
} else if (controlmode <= CONTROLMODE_14) {
} else if (controlmode <= CONTROLMODE_14 || controlmode == CONTROLMODE_PC) {
aimpressed = c1buttons & (R_TRIG);
shootpressed = c1buttons & Z_TRIG;
#ifdef PLATFORM_N64
exitpressed = (c1buttons | c2buttons) & A_BUTTON;
activatepressed = (c1buttons | c2buttons) & B_BUTTON;
#else
exitpressed = (c1buttons | c2buttons) & (BUTTON_WPNBACK | BUTTON_RADIAL);
activatepressed = (c1buttons | c2buttons) & (BUTTON_CANCEL_USE | BUTTON_ACCEPT_USE);
#ifndef PLATFORM_N64
if (controlmode == CONTROLMODE_PC) {
exitpressed = (c1buttons | c2buttons) & (BUTTON_WPNBACK | BUTTON_RADIAL);
activatepressed = (c1buttons | c2buttons) & (BUTTON_CANCEL_USE | BUTTON_ACCEPT_USE);
} else
#endif
{
exitpressed = (c1buttons | c2buttons) & A_BUTTON;
activatepressed = (c1buttons | c2buttons) & B_BUTTON;
}
} else {
if (controlmode >= CONTROLMODE_23) {
aimpressed = c1buttons & Z_TRIG;
Expand Down Expand Up @@ -829,23 +849,25 @@ void eyespyProcessInput(bool allowbuttons)
forwardspeed = c1sticky;
}

ascendspeed = (c1buttons & (U_CBUTTONS) ? 1 : 0) - (c1buttons & (D_CBUTTONS) ? 1 : 0);
sidespeed = (c1buttons & (R_CBUTTONS) ? 1 : 0) - (c1buttons & (L_CBUTTONS) ? 1 : 0);
} else if (controlmode <= CONTROLMODE_14) {
ascendspeed = (c1buttons & (U_CBUTTONS | U_JPAD) ? 1 : 0) - (c1buttons & (D_CBUTTONS | D_JPAD) ? 1 : 0);
sidespeed = (c1buttons & (R_CBUTTONS | R_JPAD) ? 1 : 0) - (c1buttons & (L_CBUTTONS | L_JPAD) ? 1 : 0);
} else if (controlmode <= CONTROLMODE_14 || controlmode == CONTROLMODE_PC) {
if (aimpressed) {
domovecentre = false;
pitchspeed = c1sticky;
} else {
ascendspeed = c1sticky * 0.25f;
forwardspeed = (c1buttons & (U_CBUTTONS) ? 24.0f : 0) - (c1buttons & (D_CBUTTONS) ? 24.0f : 0);
forwardspeed = (c1buttons & umask ? 24.0f : 0) - (c1buttons & dmask ? 24.0f : 0);
#ifndef PLATFORM_N64
forwardspeed += c2sticky;
if (controlmode == CONTROLMODE_PC) {
forwardspeed += c2sticky;
}
#endif
}

sidespeed = (c1buttons & (R_CBUTTONS) ? 1 : 0) - (c1buttons & (L_CBUTTONS) ? 1 : 0);
sidespeed = (c1buttons & rmask ? 1 : 0) - (c1buttons & lmask ? 1 : 0);
#ifndef PLATFORM_N64
if (!sidespeed) sidespeed = c2stickx * 0.0125f;
if (!sidespeed && controlmode == CONTROLMODE_PC) sidespeed = c2stickx * 0.0125f;
#endif
} else if (controlmode == CONTROLMODE_21 || controlmode == CONTROLMODE_23) {
forwardspeed = c1sticky;
Expand Down Expand Up @@ -994,23 +1016,23 @@ void eyespyProcessInput(bool allowbuttons)
// Make eyespy look horizontally
if (domovecentre) {
if (g_Vars.currentplayer->eyespy->verta > 0.0f && forwardspeed != 0) {
#ifdef PLATFORM_N64
if (g_Vars.currentplayer->eyespy->verta < 180.0f) {
tmp = g_Vars.currentplayer->eyespy->verta;

for (i = 0; i < g_Vars.lvupdate60; i++) {
tmp *= 0.04f;
g_Vars.currentplayer->eyespy->verta -= tmp;
}
} else {
tmp = 360.0f - g_Vars.currentplayer->eyespy->verta;
if (controlmode != CONTROLMODE_PC) {
if (g_Vars.currentplayer->eyespy->verta < 180.0f) {
tmp = g_Vars.currentplayer->eyespy->verta;

for (i = 0; i < g_Vars.lvupdate60; i++) {
tmp *= 0.04f;
g_Vars.currentplayer->eyespy->verta -= tmp;
}
} else {
tmp = 360.0f - g_Vars.currentplayer->eyespy->verta;

for (i = 0; i < g_Vars.lvupdate60; i++) {
tmp *= 0.04f;
g_Vars.currentplayer->eyespy->verta += tmp;
for (i = 0; i < g_Vars.lvupdate60; i++) {
tmp *= 0.04f;
g_Vars.currentplayer->eyespy->verta += tmp;
}
}
}
#endif

g_Vars.currentplayer->eyespy->cosverta = cosf(g_Vars.currentplayer->eyespy->verta * 0.017453292384744f);
g_Vars.currentplayer->eyespy->sinverta = sinf(g_Vars.currentplayer->eyespy->verta * 0.017453292384744f);
Expand Down
15 changes: 10 additions & 5 deletions src/game/bondgun.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,9 @@ void bgunRumble(s32 handnum, s32 weaponnum)
bool contpad2hasrumble;
s32 contpadtouse1;
s32 contpadtouse2;
s32 controlmode = optionsGetControlMode(g_Vars.currentplayerstats->mpindex);

if (optionsGetControlMode(g_Vars.currentplayerstats->mpindex) >= CONTROLMODE_21) {
if (controlmode >= CONTROLMODE_21 && controlmode < CONTROLMODE_PC) {
contpad1hasrumble = pakGetType(g_Vars.currentplayernum) == PAKTYPE_RUMBLE;
contpad2hasrumble = pakGetType(g_Vars.currentplayernum + PLAYERCOUNT()) == PAKTYPE_RUMBLE;

Expand Down Expand Up @@ -11798,16 +11799,20 @@ s32 bgunConsiderToggleGunFunction(s32 usedowntime, bool trigpressed, bool fromac

void bgun0f0a8c50(void)
{
#ifndef PLATFORM_N64
switch (bgunGetWeaponNum(HAND_RIGHT)) {
case WEAPON_RCP120:
case WEAPON_LAPTOPGUN:
case WEAPON_DRAGON:
case WEAPON_REMOTEMINE:
return;
default:
if (g_Vars.currentplayer->hands[HAND_RIGHT].activatesecondary == false) {
g_Vars.currentplayer->gunctrl.invertgunfunc = false;
if (PLAYER_EXTCFG().extcontrols) {
return;
}
break;
}
#endif
if (g_Vars.currentplayer->hands[HAND_RIGHT].activatesecondary == false) {
g_Vars.currentplayer->gunctrl.invertgunfunc = false;
}
}

Expand Down
Loading

0 comments on commit 600dae5

Please sign in to comment.