Skip to content

Commit

Permalink
port: cleanup; camspy and slayer respect invert pitch option
Browse files Browse the repository at this point in the history
note: dual analog mode now only works if you set StickCButtons=0 in pd.ini
  • Loading branch information
fgsfdsfgs committed Oct 22, 2023
1 parent e2b1cdc commit d1817aa
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 89 deletions.
65 changes: 37 additions & 28 deletions port/src/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static f32 mouseSensY = 1.5f;

static f32 rumbleScale = 0.5f;

// NOTE: by default this gets inverted for 1.2
// NOTE: by default this gets inverted for 1.2: "right stick" here means left stick on your controller
static u32 axisMap[2][2] = {
{ SDL_CONTROLLER_AXIS_LEFTX, SDL_CONTROLLER_AXIS_LEFTY },
{ SDL_CONTROLLER_AXIS_RIGHTX, SDL_CONTROLLER_AXIS_RIGHTY },
Expand Down Expand Up @@ -73,22 +73,22 @@ static const char *ckNames[CK_TOTAL_COUNT] = {
"Z_TRIG",
"B_BUTTON",
"A_BUTTON",
"CK_0001",
"CK_0002",
"CK_0004",
"CK_0008",
"CK_0010",
"CK_0020",
"CK_0040",
"CK_0080",
"CK_0100",
"CK_0200",
"CK_0400",
"CK_0800",
"CK_1000",
"CK_2000",
"CK_4000",
"CK_8000"
"CK_0001",
"CK_0002",
"CK_0004",
"CK_0008",
"CK_0010",
"CK_0020",
"CK_0040",
"CK_0080",
"CK_0100",
"CK_0200",
"CK_0400",
"CK_0800",
"CK_1000",
"CK_2000",
"CK_4000",
"CK_8000"
"STICK_XNEG",
"STICK_XPOS",
"STICK_YNEG",
Expand Down Expand Up @@ -169,8 +169,8 @@ void inputSetDefaultKeyBinds(void)
{ CK_STICK_XPOS, SDL_SCANCODE_RIGHT, 0 },
{ CK_STICK_YNEG, SDL_SCANCODE_DOWN, 0 },
{ CK_STICK_YPOS, SDL_SCANCODE_UP, 0 },
{CK_4000, SDL_SCANCODE_LSHIFT, 0 },
{CK_2000, SDL_SCANCODE_LCTRL, 0 }
{ CK_4000, SDL_SCANCODE_LSHIFT, 0 },
{ CK_2000, SDL_SCANCODE_LCTRL, 0 }
};

static const u32 joybinds[][2] = {
Expand Down Expand Up @@ -461,7 +461,7 @@ s32 inputInit(void)
stickSens[2] = configGetFloat("Input.RStickScaleX", 1.f);
stickSens[3] = configGetFloat("Input.RStickScaleY", 1.f);

stickCButtons = configGetInt("Input.StickCButtons", 1);
stickCButtons = configGetInt("Input.StickCButtons", 0);

if (configGetInt("Input.SwapSticks", 1)) {
// invert axis map
Expand Down Expand Up @@ -544,7 +544,6 @@ s32 inputReadController(s32 idx, OSContPad *npad)
rightX = inputAxisScale(rightX, deadzone[axisMap[1][0]], stickSens[axisMap[1][0]]);
rightY = inputAxisScale(rightY, deadzone[axisMap[1][1]], stickSens[axisMap[1][1]]);


if (!npad->stick_x && leftX) {
npad->stick_x = leftX / 0x100;
}
Expand All @@ -554,13 +553,23 @@ s32 inputReadController(s32 idx, OSContPad *npad)
npad->stick_y = (stickY == 128) ? 127 : stickY;
}

if (!npad->rstick_x && rightX) {
npad->rstick_x = rightX / 0x100;
}

s32 rStickY = -rightY / 0x100;
if (!npad->rstick_y && rStickY) {
npad->rstick_y = (rStickY == 128) ? 127 : rStickY;
if (stickCButtons) {
// rstick emulates C buttons
if (rightX < -0x4000) npad->button |= L_CBUTTONS;
if (rightX > +0x4000) npad->button |= R_CBUTTONS;
if (rightY < -0x4000) npad->button |= U_CBUTTONS;
if (rightY > +0x4000) npad->button |= D_CBUTTONS;
npad->rstick_x = 0;
npad->rstick_y = 0;
} else {
// rstick is an analog input
if (rightX) {
npad->rstick_x = rightX / 0x100;
}
s32 rStickY = -rightY / 0x100;
if (rStickY) {
npad->rstick_y = (rStickY == 128) ? 127 : rStickY;
}
}

return 0;
Expand Down
12 changes: 9 additions & 3 deletions src/game/bondeyespy.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,13 +728,13 @@ void eyespyProcessInput(bool allowbuttons)

c2buttons = allowbuttons ? joyGetButtons(contpad2, 0xffffffff) : 0;
} else {
#ifndef PLATFORM_N64
#ifndef PLATFORM_N64
c2stickx = joyGetRStickX(contpad1);
c2sticky = joyGetRStickY(contpad1);
#else
#else
c2stickx = c1stickx;
c2sticky = c1sticky;
#endif
#endif
c2buttons = c1buttons;
}

Expand Down Expand Up @@ -953,6 +953,12 @@ void eyespyProcessInput(bool allowbuttons)
g_Vars.currentplayer->eyespy->sintheta = sinf(g_Vars.currentplayer->eyespy->theta * 0.017453292384744f);

// Update verta
#ifndef PLATFORM_N64
// respect the invert pitch setting
if (optionsGetForwardPitch(g_Vars.currentplayerstats->mpindex)) {
pitchspeed = -pitchspeed;
}
#endif
g_Vars.currentplayer->eyespy->verta -= pitchspeed * 0.0625f * g_Vars.lvupdate60freal;

if (prevverta != g_Vars.currentplayer->eyespy->verta) {
Expand Down
75 changes: 19 additions & 56 deletions src/game/bondmove.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@
#include "data.h"
#include "types.h"
#ifndef PLATFORM_N64
#include <math.h>
#include "input.h"
#include "video.h"
#endif

void handleProcessInputAltButton(struct movedata *data, s8 contpad, s32 i){
static void bgunProcessInputAltButton(struct movedata *data, s8 contpad, s32 i)
{
s32 buttons = joyGetButtonsOnSample(i, contpad, 0xffffffff);
if (buttons & (BUTTON_ALTMODE)) {
if (g_Vars.currentplayer->altdowntime >= -1) {
Expand All @@ -52,7 +53,6 @@ void handleProcessInputAltButton(struct movedata *data, s8 contpad, s32 i){
&& bgunConsiderToggleGunFunction(g_Vars.currentplayer->altdowntime, true, false, true) != USETIMER_CONTINUE) {
g_Vars.currentplayer->altdowntime = -3;
}

if (g_Vars.currentplayer->altdowntime != -4) {
if (g_Vars.currentplayer->altdowntime <= 0) {
g_Vars.currentplayer->altdowntime++;
Expand All @@ -64,22 +64,19 @@ void handleProcessInputAltButton(struct movedata *data, s8 contpad, s32 i){
g_Vars.currentplayer->altdowntime = -4;
}
}
}
else if (buttons & (BUTTON_CANCEL_USE | BUTTON_ACCEPT_USE)) {
} else if (buttons & (BUTTON_CANCEL_USE | BUTTON_ACCEPT_USE)) {
if (g_Vars.currentplayer->altdowntime >= -1) {
if (buttons & (Z_TRIG)
&& g_Vars.currentplayer->altdowntime >= 0
&& bgunConsiderToggleGunFunction(g_Vars.currentplayer->altdowntime, true, false, true) != USETIMER_CONTINUE) {
g_Vars.currentplayer->altdowntime = -3;
}

}
}
else {
}
} 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);

const bool trigpressed = (g_Vars.currentplayer->altdowntime == -3);
s32 result = bgunConsiderToggleGunFunction(g_Vars.currentplayer->altdowntime, trigpressed, false, true);
if (result == USETIMER_STOP) {
g_Vars.currentplayer->altdowntime = -1;
} else if (result == USETIMER_REPEAT) {
Expand All @@ -91,6 +88,8 @@ void handleProcessInputAltButton(struct movedata *data, s8 contpad, s32 i){
}
}

#endif // PLATFORM_N64

void bmoveSetControlDef(u32 controldef)
{
g_Vars.currentplayer->controldef = controldef;
Expand Down Expand Up @@ -808,14 +807,15 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i

c2allowedbuttons = 0xffffffff;

// NOTE: I'm not 100% sure of correctness here
if (g_Vars.currentplayer->joybutinhibit << 0 >> 32) {
inhibitedbuttons = g_Vars.currentplayer->joybutinhibit >> 32;
// NOTE: joybutinhibit used to store two copies of the 16-bit inhibited mask for some reason
// now it only stores one mask because it is 32 bits in size
if (g_Vars.currentplayer->joybutinhibit) {
inhibitedbuttons = g_Vars.currentplayer->joybutinhibit;
c2allowedbuttons = ~inhibitedbuttons;
inhibitedbuttons = joyGetButtons(contpad2, 0xffffffff) & inhibitedbuttons;
c2buttons &= ~inhibitedbuttons;
c2buttonsthisframe &= ~inhibitedbuttons;
g_Vars.currentplayer->joybutinhibit = (g_Vars.currentplayer->joybutinhibit & 0xffffffff) | (inhibitedbuttons << 32);
g_Vars.currentplayer->joybutinhibit |= inhibitedbuttons;
}

if (ignorec2) {
Expand Down Expand Up @@ -1501,45 +1501,10 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i

#ifndef PLATFORM_N64
if (allowc1buttons) {
// handle L button : alt switching
for (i = 0; i < numsamples; i++) {
handleProcessInputAltButton(&movedata, contpad1, i);
bgunProcessInputAltButton(&movedata, contpad1, i);
}
// 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;
// }
//
// 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 {
// // 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;
// bgun0f0a8c50();
// }
// }

// Handle ALT1 / MI Reload Hack
for (i = 0; i < numsamples; i++) {
Expand All @@ -1548,7 +1513,6 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i
}
}


// Handle radial menu (D-Down)
for (i = 0; i < numsamples; i++) {
if (joyGetButtonsOnSample(i, contpad1, c1allowedbuttons & BUTTON_RADIAL)) {
Expand Down Expand Up @@ -1614,7 +1578,7 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i
}
}

// // Handle xbla-style crouch cycling
// Handle xbla-style crouch cycling
for (i = 0; i < numsamples; i++) {
s32 crouchsample = joyGetButtonsPressedOnSample(i, contpad1, 0xffffffff) & BUTTON_CROUCH_CYCLE;
if (crouchsample) {
Expand All @@ -1625,7 +1589,7 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i
}
}

// handle 1964GEPD style crouch setting
// handle 1964GEPD style crouch setting
crouchsample = joyGetButtonsPressedOnSample(i, contpad1, c1allowedbuttons) & BUTTON_HALF_CROUCH;
if (crouchsample) {
if (g_Vars.currentplayer->crouchpos == CROUCHPOS_DUCK) {
Expand Down Expand Up @@ -1713,7 +1677,6 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i
}
#endif


// Handle shutting eyes in multiplayer
if (bmoveGetCrouchPos() == CROUCHPOS_SQUAT
&& g_Vars.currentplayer->crouchoffset == -90
Expand Down
2 changes: 1 addition & 1 deletion src/game/lv.c
Original file line number Diff line number Diff line change
Expand Up @@ -2050,7 +2050,7 @@ void lvTick(void)
g_Vars.lvupdate240 = 0;

for (j = 0; j < PLAYERCOUNT(); j++) {
g_Vars.players[j]->joybutinhibit = 0xefffefff;
g_Vars.players[j]->joybutinhibit = 0xefffffff;
}
} else {
s32 slowmo = lvGetSlowMotionType();
Expand Down
7 changes: 6 additions & 1 deletion src/game/player.c
Original file line number Diff line number Diff line change
Expand Up @@ -3598,6 +3598,11 @@ void playerTick(bool arg0)
sp174 = -stickx * LVUPDATE60FREAL() * 0.00025f;

#ifndef PLATFORM_N64
// respect the invert pitch setting
if (optionsGetForwardPitch(g_Vars.currentplayerstats->mpindex)) {
sp178 = -sp178;
}
// mouse control
if (g_Vars.currentplayernum == 0) {
f32 mdx, mdy;
inputMouseGetScaledDelta(&mdx, &mdy);
Expand Down Expand Up @@ -3672,7 +3677,7 @@ void playerTick(bool arg0)
targetspeed = 1;
}
#endif

newspeed = prevspeed;

if (prevspeed < targetspeed) {
Expand Down

0 comments on commit d1817aa

Please sign in to comment.