Skip to content

Commit

Permalink
Merge pull request #28 from NeonNyan/port
Browse files Browse the repository at this point in the history
Implement some dedicated buttons for mouse+kb / gamepad
  • Loading branch information
fgsfdsfgs authored Aug 20, 2023
2 parents 170f264 + d007550 commit 3da1fd4
Show file tree
Hide file tree
Showing 15 changed files with 225 additions and 205 deletions.
50 changes: 27 additions & 23 deletions port/src/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,38 +52,42 @@ 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_TAB, 0 },
{ CK_Y, SDL_SCANCODE_R, 0 },
{ CK_RTRIG, VK_MOUSE_RIGHT, SDL_SCANCODE_Z },
{ CK_LTRIG, VK_MOUSE_X1, SDL_SCANCODE_X },
{ CK_ZTRIG, VK_MOUSE_LEFT, SDL_SCANCODE_SPACE },
{ CK_START, SDL_SCANCODE_RETURN, 0 },
{ CK_DPAD_D, SDL_SCANCODE_S, 0 },
{ CK_DPAD_U, SDL_SCANCODE_W, 0 },
{ CK_DPAD_R, SDL_SCANCODE_D, 0 },
{ CK_DPAD_L, SDL_SCANCODE_A, 0 },
{ CK_STICK_XNEG, SDL_SCANCODE_LEFT, 0 },
{ CK_STICK_XPOS, SDL_SCANCODE_RIGHT, 0 },
{ CK_STICK_YNEG, SDL_SCANCODE_DOWN, 0 },
{ CK_STICK_YPOS, SDL_SCANCODE_UP, 0 },
{ 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_U, 0, 0 },
{ CK_DPAD_R, 0, 0 },
{ CK_DPAD_L, 0, 0 },
{ CK_C_D, SDL_SCANCODE_S, 0 },
{ CK_C_U, SDL_SCANCODE_W, 0 },
{ CK_C_R, SDL_SCANCODE_D, 0 },
{ CK_C_L, SDL_SCANCODE_A, 0 },
{ CK_STICK_XNEG, SDL_SCANCODE_LEFT, 0 },
{ CK_STICK_XPOS, SDL_SCANCODE_RIGHT, 0 },
{ CK_STICK_YNEG, SDL_SCANCODE_DOWN, 0 },
{ CK_STICK_YPOS, SDL_SCANCODE_UP, 0 },
};

static const u32 joybinds[][2] = {
{ CK_A, SDL_CONTROLLER_BUTTON_A },
{ CK_B, SDL_CONTROLLER_BUTTON_B },
{ CK_X, SDL_CONTROLLER_BUTTON_X },
{ CK_Y, SDL_CONTROLLER_BUTTON_Y },
{ CK_LTRIG, SDL_CONTROLLER_BUTTON_LEFTSHOULDER },
{ CK_RTRIG, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER },
{ CK_ZTRIG, VK_JOY1_LTRIG - VK_JOY1_BEGIN },
{ CK_DPAD_D, SDL_CONTROLLER_BUTTON_LEFTSHOULDER },
{ CK_LTRIG, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER },
{ CK_RTRIG, VK_JOY1_LTRIG - VK_JOY1_BEGIN },
{ CK_ZTRIG, VK_JOY1_RTRIG - VK_JOY1_BEGIN },
{ CK_START, SDL_CONTROLLER_BUTTON_START },
{ CK_DPAD_D, SDL_CONTROLLER_BUTTON_DPAD_DOWN },
{ CK_DPAD_U, SDL_CONTROLLER_BUTTON_DPAD_UP },
{ CK_DPAD_R, SDL_CONTROLLER_BUTTON_DPAD_RIGHT },
{ CK_DPAD_L, SDL_CONTROLLER_BUTTON_DPAD_LEFT },
{ CK_C_D, SDL_CONTROLLER_BUTTON_DPAD_DOWN },
{ CK_C_U, SDL_CONTROLLER_BUTTON_DPAD_UP },
{ CK_C_R, SDL_CONTROLLER_BUTTON_DPAD_RIGHT },
{ CK_C_L, SDL_CONTROLLER_BUTTON_DPAD_LEFT },
};

for (u32 i = 0; i < sizeof(kbbinds) / sizeof(kbbinds[0]); ++i) {
Expand Down
48 changes: 8 additions & 40 deletions src/game/activemenutick.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void amTick(void)
g_AmIndex = g_Vars.currentplayernum;

if (g_AmMenus[g_AmIndex].togglefunc) {
if (bgunConsiderToggleGunFunction(60, false, true) > 0) {
if (bgunConsiderToggleGunFunction(60, false, true, 0) > 0) {
g_AmMenus[g_AmIndex].togglefunc = false;
}
} else {
Expand Down Expand Up @@ -64,19 +64,19 @@ void amTick(void)
g_AmMenus[g_AmIndex].allbots = false;

if (g_Vars.currentplayer->activemenumode == AMMODE_EDIT) {
buttonsstate = buttonsstate & A_BUTTON;
buttonsstate = buttonsstate & D_JPAD;
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) || (buttonsstate & L_TRIG)) {
if ((buttonsstate & R_TRIG)) {
stayopen = true;
}

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

if ((buttonsstate & R_TRIG) || (buttonsstate & L_TRIG)) {
if ((buttonsstate & R_TRIG)) {
#if VERSION >= VERSION_JPN_FINAL || !defined(PLATFORM_N64)
if (g_Vars.currentplayer->numaibuddies > 0) {
g_AmMenus[g_AmIndex].allbots = true;
Expand Down Expand Up @@ -134,22 +134,6 @@ void amTick(void)
column = 2;
}

if (buttonsstate & U_JPAD) {
row = 0;
}

if (buttonsstate & D_JPAD) {
row = 2;
}

if (buttonsstate & L_JPAD) {
column = 0;
}

if (buttonsstate & R_JPAD) {
column = 2;
}

if (controlmode == CONTROLMODE_23
|| controlmode == CONTROLMODE_24
|| controlmode == CONTROLMODE_22
Expand All @@ -161,13 +145,13 @@ void amTick(void)
u16 buttonspressed2 = joyGetButtonsPressedOnSample(j, contpadnum2, 0xffff);

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

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

Expand All @@ -191,22 +175,6 @@ void amTick(void)
column = 2;
}

if (buttonsstate2 & U_JPAD) {
row = 0;
}

if (buttonsstate2 & D_JPAD) {
row = 2;
}

if (buttonsstate2 & L_JPAD) {
column = 0;
}

if (buttonsstate2 & R_JPAD) {
column = 2;
}

absstickx = cstickx2 < 0 ? -cstickx2 : cstickx2;
abssticky = csticky2 < 0 ? -csticky2 : csticky2;

Expand Down
4 changes: 2 additions & 2 deletions src/game/bondbike.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ void bbikeApplyMoveData(struct movedata *data)
|| optionsGetControlMode(g_Vars.currentplayerstats->mpindex) == CONTROLMODE_13
|| optionsGetControlMode(g_Vars.currentplayerstats->mpindex) == CONTROLMODE_11)
&& !lvIsPaused()) {
data->digitalstepleft = joyCountButtonsOnSpecificSamples(0, contnum, L_JPAD | L_CBUTTONS);
data->digitalstepright = joyCountButtonsOnSpecificSamples(0, contnum, R_JPAD | R_CBUTTONS);
data->digitalstepleft = joyCountButtonsOnSpecificSamples(0, contnum, L_CBUTTONS);
data->digitalstepright = joyCountButtonsOnSpecificSamples(0, contnum,R_CBUTTONS);
}

// Forward/back
Expand Down
10 changes: 5 additions & 5 deletions src/game/bondeyespy.c
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ void eyespyProcessInput(bool allowbuttons)
exitpressed = c1buttons & R_TRIG;
activatepressed = c1buttons & B_BUTTON;
} else if (controlmode <= CONTROLMODE_14) {
aimpressed = c1buttons & (L_TRIG | R_TRIG);
aimpressed = c1buttons & (R_TRIG);
shootpressed = c1buttons & Z_TRIG;
exitpressed = c1buttons & A_BUTTON;
activatepressed = c1buttons & B_BUTTON;
Expand Down Expand Up @@ -819,18 +819,18 @@ void eyespyProcessInput(bool allowbuttons)
forwardspeed = c1sticky;
}

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);
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) {
if (aimpressed) {
domovecentre = false;
pitchspeed = c1sticky;
} else {
ascendspeed = c1sticky * 0.25f;
forwardspeed = (c1buttons & (U_CBUTTONS | U_JPAD) ? 24.0f : 0) - (c1buttons & (D_CBUTTONS | D_JPAD) ? 24.0f : 0);
forwardspeed = (c1buttons & (U_CBUTTONS) ? 24.0f : 0) - (c1buttons & (D_CBUTTONS) ? 24.0f : 0);
}

sidespeed = (c1buttons & (R_CBUTTONS | R_JPAD) ? 1 : 0) - (c1buttons & (L_CBUTTONS | L_JPAD) ? 1 : 0);
sidespeed = (c1buttons & (R_CBUTTONS) ? 1 : 0) - (c1buttons & (L_CBUTTONS) ? 1 : 0);
} else if (controlmode == CONTROLMODE_21 || controlmode == CONTROLMODE_23) {
forwardspeed = c1sticky;

Expand Down
31 changes: 23 additions & 8 deletions src/game/bondgun.c
Original file line number Diff line number Diff line change
Expand Up @@ -11686,20 +11686,27 @@ void bgunSetTriggerOn(s32 handnum, bool on)
* - USETIMER_STOP if the B button timer should stop (ie. the B press is consumed)
* - USETIMER_REPEAT if this function should be called again on each frame until B is released.
*/
s32 bgunConsiderToggleGunFunction(s32 usedowntime, bool trigpressed, bool fromactivemenu)
s32 bgunConsiderToggleGunFunction(s32 usedowntime, bool trigpressed, bool fromactivemenu, bool fromdedicatedbutton)
{
switch (bgunGetWeaponNum(HAND_RIGHT)) {
case WEAPON_SNIPERRIFLE:
// At 25 ticks (or B+Z), start showing the new function
if (usedowntime < 0) {
return USETIMER_CONTINUE;
}
// g_Vars.currentplayer->gunctrl.invertgunfunc = !g_Vars.currentplayer->gunctrl.invertgunfunc;
g_Vars.currentplayer->gunctrl.invertgunfunc = true;

// B+Z immediately triggers crouch or stand
if (trigpressed) {
g_Vars.currentplayer->hands[HAND_RIGHT].activatesecondary = true;
return USETIMER_STOP;
}
if (fromdedicatedbutton) {
g_Vars.currentplayer->hands[HAND_RIGHT].activatesecondary = true;
return USETIMER_CONTINUE;
}

// Don't do anything if B hasn't been held for 50/60ths of a second
if (usedowntime < TICKS(50)) {
if (ABS(usedowntime) < 0) {
return USETIMER_CONTINUE;
}

Expand All @@ -11709,13 +11716,13 @@ s32 bgunConsiderToggleGunFunction(s32 usedowntime, bool trigpressed, bool fromac

// Do crouch or stand
g_Vars.currentplayer->hands[HAND_RIGHT].activatesecondary = true;
return USETIMER_REPEAT;
return USETIMER_STOP;
case WEAPON_RCP120:
case WEAPON_LAPTOPGUN:
case WEAPON_DRAGON:
case WEAPON_REMOTEMINE:
// These weapons use temporary alt functions
g_Vars.currentplayer->gunctrl.invertgunfunc = true;
g_Vars.currentplayer->gunctrl.invertgunfunc = !g_Vars.currentplayer->gunctrl.invertgunfunc;

if (fromactivemenu && bgunIsUsingSecondaryFunction() == true) {
g_Vars.currentplayer->hands[HAND_RIGHT].activatesecondary = true;
Expand Down Expand Up @@ -11761,8 +11768,16 @@ s32 bgunConsiderToggleGunFunction(s32 usedowntime, bool trigpressed, bool fromac

void bgun0f0a8c50(void)
{
if (g_Vars.currentplayer->hands[HAND_RIGHT].activatesecondary == false) {
g_Vars.currentplayer->gunctrl.invertgunfunc = false;
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;
}
}
}

Expand Down
Loading

0 comments on commit 3da1fd4

Please sign in to comment.