- Move joyaxes[] array from getHidInput() directly into ControlInfo.

This commit is contained in:
Mitchell Richters 2023-03-17 20:42:19 +11:00
parent 08d22f49f4
commit eed9716d86
4 changed files with 44 additions and 68 deletions

View file

@ -119,27 +119,27 @@ void processMovement(InputPacket* const currInput, InputPacket* const inputBuffe
// determine player input.
const auto turning = buttonMap.ButtonDown(gamefunc_Turn_Right) - buttonMap.ButtonDown(gamefunc_Turn_Left);
const auto moving = buttonMap.ButtonDown(gamefunc_Move_Forward) - buttonMap.ButtonDown(gamefunc_Move_Backward) + hidInput->dforward * scaleAdjustf;
const auto strafing = buttonMap.ButtonDown(gamefunc_Strafe_Right) - buttonMap.ButtonDown(gamefunc_Strafe_Left) - hidInput->dside * scaleAdjustf;
const auto moving = buttonMap.ButtonDown(gamefunc_Move_Forward) - buttonMap.ButtonDown(gamefunc_Move_Backward) + hidInput->joyaxes[JOYAXIS_Forward] * scaleAdjustf;
const auto strafing = buttonMap.ButtonDown(gamefunc_Strafe_Right) - buttonMap.ButtonDown(gamefunc_Strafe_Left) - hidInput->joyaxes[JOYAXIS_Side] * scaleAdjustf;
// process player angle input.
if (!(buttonMap.ButtonDown(gamefunc_Strafe) && allowstrafe))
{
const float turndir = clamp(turning + strafing * !allowstrafe, -1.f, 1.f);
const float turnspeed = float(getTicrateScale(YAW_TURNSPEEDS[keymove]) * turnscale * (isTurboTurnTime() ? 1. : YAW_PREAMBLESCALE));
currInput->avel += hidInput->mouseturnx - (hidInput->dyaw * hidspeed - turndir * turnspeed) * scaleAdjustf;
currInput->avel += hidInput->mouseturnx - (hidInput->joyaxes[JOYAXIS_Yaw] * hidspeed - turndir * turnspeed) * scaleAdjustf;
if (turndir) updateTurnHeldAmt(scaleAdjust); else resetTurnHeldAmt();
}
else
{
currInput->svel += hidInput->mousemovex - (hidInput->dyaw - turning) * keymove * scaleAdjustf;
currInput->svel += hidInput->mousemovex - (hidInput->joyaxes[JOYAXIS_Yaw] - turning) * keymove * scaleAdjustf;
}
// process player pitch input.
if (!(inputBuffer->actions & SB_AIMMODE))
currInput->horz += hidInput->mouseturny - hidInput->dpitch * hidspeed * scaleAdjustf;
currInput->horz += hidInput->mouseturny - hidInput->joyaxes[JOYAXIS_Pitch] * hidspeed * scaleAdjustf;
else
currInput->fvel -= hidInput->mousemovey - hidInput->dpitch * keymove * scaleAdjustf;
currInput->fvel -= hidInput->mousemovey - hidInput->joyaxes[JOYAXIS_Pitch] * keymove * scaleAdjustf;
// process movement input.
currInput->fvel += moving * keymove;

View file

@ -195,30 +195,6 @@ int32_t handleevents(void)
return 0;
}
//==========================================================================
//
//
//
//==========================================================================
void getHidInput(HIDInput* const hidInput)
{
inputState.GetMouseDelta(hidInput);
if (use_joystick)
{
// Handle joysticks/game controllers.
float joyaxes[NUM_JOYAXIS];
I_GetAxes(joyaxes);
hidInput->dyaw += joyaxes[JOYAXIS_Yaw];
hidInput->dpitch += joyaxes[JOYAXIS_Pitch];
hidInput->dforward += joyaxes[JOYAXIS_Forward] * .5f;
hidInput->dside += joyaxes[JOYAXIS_Side] * .5f;
}
}
//---------------------------------------------------------------------------
//
//
@ -401,33 +377,33 @@ void ApplyGlobalInput(InputPacket& input, HIDInput* hidInput, bool const croucha
if (hidInput && buttonMap.ButtonDown(gamefunc_Dpad_Select))
{
// These buttons should not autorepeat. The game handlers are not really equipped for that.
if (hidInput->dforward > 0 && !(dpad_lock & 1)) { dpad_lock |= 1; input.setNewWeapon(WeaponSel_Prev); }
if (hidInput->joyaxes[JOYAXIS_Forward] > 0 && !(dpad_lock & 1)) { dpad_lock |= 1; input.setNewWeapon(WeaponSel_Prev); }
else dpad_lock &= ~1;
if (hidInput->dforward < 0 && !(dpad_lock & 2)) { dpad_lock |= 2; input.setNewWeapon(WeaponSel_Next); }
if (hidInput->joyaxes[JOYAXIS_Forward] < 0 && !(dpad_lock & 2)) { dpad_lock |= 2; input.setNewWeapon(WeaponSel_Next); }
else dpad_lock &= ~2;
if ((hidInput->dside < 0 || hidInput->dyaw > 0) && !(dpad_lock & 4)) { dpad_lock |= 4; input.actions |= SB_INVPREV; }
if ((hidInput->joyaxes[JOYAXIS_Side] < 0 || hidInput->joyaxes[JOYAXIS_Yaw] > 0) && !(dpad_lock & 4)) { dpad_lock |= 4; input.actions |= SB_INVPREV; }
else dpad_lock &= ~4;
if ((hidInput->dside > 0 || hidInput->dyaw < 0) && !(dpad_lock & 8)) { dpad_lock |= 8; input.actions |= SB_INVNEXT; }
if ((hidInput->joyaxes[JOYAXIS_Side] > 0 || hidInput->joyaxes[JOYAXIS_Yaw] < 0) && !(dpad_lock & 8)) { dpad_lock |= 8; input.actions |= SB_INVNEXT; }
else dpad_lock &= ~8;
// This eats the controller input for regular use
hidInput->dside = 0;
hidInput->dforward = 0;
hidInput->dyaw = 0;
hidInput->joyaxes[JOYAXIS_Side] = 0;
hidInput->joyaxes[JOYAXIS_Forward] = 0;
hidInput->joyaxes[JOYAXIS_Yaw] = 0;
}
else dpad_lock = 0;
input.actions |= ActionsToSend;
ActionsToSend = 0;
if (buttonMap.ButtonDown(gamefunc_Aim_Up) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && hidInput->dforward > 0))
if (buttonMap.ButtonDown(gamefunc_Aim_Up) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && hidInput->joyaxes[JOYAXIS_Forward] > 0))
input.actions |= SB_AIM_UP;
if ((buttonMap.ButtonDown(gamefunc_Aim_Down) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && hidInput->dforward < 0)))
if ((buttonMap.ButtonDown(gamefunc_Aim_Down) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && hidInput->joyaxes[JOYAXIS_Forward] < 0)))
input.actions |= SB_AIM_DOWN;
if (buttonMap.ButtonDown(gamefunc_Dpad_Aiming))
hidInput->dforward = 0;
hidInput->joyaxes[JOYAXIS_Forward] = 0;
if (buttonMap.ButtonDown(gamefunc_Jump))
input.actions |= SB_JUMP;

View file

@ -16,12 +16,7 @@
struct HIDInput
{
float dside;
float dup;
float dforward;
float dyaw;
float dpitch;
float droll;
float joyaxes[NUM_JOYAXIS];
float mouseturnx;
float mouseturny;
float mousemovex;
@ -63,7 +58,6 @@ public:
extern InputState inputState;
void getHidInput(HIDInput* const hidInput);
int32_t handleevents(void);
enum GameFunction_t
@ -116,6 +110,12 @@ inline float backendinputscale()
return (1.f / 16.f);
}
inline void getHidInput(HIDInput* const hidInput)
{
inputState.GetMouseDelta(hidInput);
if (use_joystick) I_GetAxes(hidInput->joyaxes);
}
//---------------------------------------------------------------------------
//
// Inline functions to help with edge cases where synchronised input is needed.

View file

@ -564,13 +564,13 @@ static float motoApplyTurn(player_struct* p, HIDInput* const hidInput, bool cons
{
resetTurnHeldAmt();
if (kbdLeft || hidInput->mouseturnx < 0 || hidInput->dyaw > 0)
if (kbdLeft || hidInput->mouseturnx < 0 || hidInput->joyaxes[JOYAXIS_Yaw] > 0)
{
p->TiltStatus -= (float)factor;
if (p->TiltStatus < -10)
p->TiltStatus = -10;
}
else if (kbdRight || hidInput->mouseturnx > 0 || hidInput->dyaw < 0)
else if (kbdRight || hidInput->mouseturnx > 0 || hidInput->joyaxes[JOYAXIS_Yaw] < 0)
{
p->TiltStatus += (float)factor;
if (p->TiltStatus > 10)
@ -579,12 +579,12 @@ static float motoApplyTurn(player_struct* p, HIDInput* const hidInput, bool cons
}
else
{
if (kbdLeft || kbdRight || p->moto_drink || hidInput->mouseturnx || hidInput->dyaw)
if (kbdLeft || kbdRight || p->moto_drink || hidInput->mouseturnx || hidInput->joyaxes[JOYAXIS_Yaw])
{
constexpr float velScale = (3.f / 10.f);
const float baseVel = (buttonMap.ButtonDown(gamefunc_Move_Backward) || hidInput->dforward < 0) && p->MotoSpeed <= 0 ? -VEHICLETURN : VEHICLETURN;
const float baseVel = (buttonMap.ButtonDown(gamefunc_Move_Backward) || hidInput->joyaxes[JOYAXIS_Forward] < 0) && p->MotoSpeed <= 0 ? -VEHICLETURN : VEHICLETURN;
if (kbdLeft || p->moto_drink < 0 || hidInput->mouseturnx < 0 || hidInput->dyaw > 0)
if (kbdLeft || p->moto_drink < 0 || hidInput->mouseturnx < 0 || hidInput->joyaxes[JOYAXIS_Yaw] > 0)
{
p->TiltStatus -= (float)factor;
@ -597,13 +597,13 @@ static float motoApplyTurn(player_struct* p, HIDInput* const hidInput, bool cons
if (hidInput->mouseturnx < 0)
turnvel -= Sgn(baseVel) * sqrtf(abs(p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * -(hidInput->mouseturnx / factor) * (7.f / 20.f));
if (hidInput->dyaw > 0)
turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * hidInput->dyaw;
if (hidInput->joyaxes[JOYAXIS_Yaw] > 0)
turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * hidInput->joyaxes[JOYAXIS_Yaw];
updateTurnHeldAmt(factor);
}
if (kbdRight || p->moto_drink > 0 || hidInput->mouseturnx > 0 || hidInput->dyaw < 0)
if (kbdRight || p->moto_drink > 0 || hidInput->mouseturnx > 0 || hidInput->joyaxes[JOYAXIS_Yaw] < 0)
{
p->TiltStatus += (float)factor;
@ -616,8 +616,8 @@ static float motoApplyTurn(player_struct* p, HIDInput* const hidInput, bool cons
if (hidInput->mouseturnx > 0)
turnvel += Sgn(baseVel) * sqrtf(abs(p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * (hidInput->mouseturnx / factor) * (7.f / 20.f));
if (hidInput->dyaw < 0)
turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * hidInput->dyaw;
if (hidInput->joyaxes[JOYAXIS_Yaw] < 0)
turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * hidInput->joyaxes[JOYAXIS_Yaw];
updateTurnHeldAmt(factor);
}
@ -652,12 +652,12 @@ static float boatApplyTurn(player_struct *p, HIDInput* const hidInput, bool cons
if (p->MotoSpeed)
{
if (kbdLeft || kbdRight || p->moto_drink || hidInput->mouseturnx || hidInput->dyaw)
if (kbdLeft || kbdRight || p->moto_drink || hidInput->mouseturnx || hidInput->joyaxes[JOYAXIS_Yaw])
{
const float velScale = !p->NotOnWater? 1.f : (6.f / 19.f);
const float baseVel = VEHICLETURN * velScale;
if (kbdLeft || p->moto_drink < 0 || hidInput->mouseturnx < 0 || hidInput->dyaw > 0)
if (kbdLeft || p->moto_drink < 0 || hidInput->mouseturnx < 0 || hidInput->joyaxes[JOYAXIS_Yaw] > 0)
{
if (!p->NotOnWater)
{
@ -672,13 +672,13 @@ static float boatApplyTurn(player_struct *p, HIDInput* const hidInput, bool cons
if (hidInput->mouseturnx < 0)
turnvel -= Sgn(baseVel) * sqrtf(abs(baseVel) * -(hidInput->mouseturnx / factor) * (7.f / 20.f));
if (hidInput->dyaw > 0)
turnvel += baseVel * hidInput->dyaw;
if (hidInput->joyaxes[JOYAXIS_Yaw] > 0)
turnvel += baseVel * hidInput->joyaxes[JOYAXIS_Yaw];
updateTurnHeldAmt(factor);
}
if (kbdRight || p->moto_drink > 0 || hidInput->mouseturnx > 0 || hidInput->dyaw < 0)
if (kbdRight || p->moto_drink > 0 || hidInput->mouseturnx > 0 || hidInput->joyaxes[JOYAXIS_Yaw] < 0)
{
if (!p->NotOnWater)
{
@ -693,8 +693,8 @@ static float boatApplyTurn(player_struct *p, HIDInput* const hidInput, bool cons
if (hidInput->mouseturnx > 0)
turnvel += Sgn(baseVel) * sqrtf(abs(baseVel) * (hidInput->mouseturnx / factor) * (7.f / 20.f));
if (hidInput->dyaw < 0)
turnvel += baseVel * hidInput->dyaw;
if (hidInput->joyaxes[JOYAXIS_Yaw] < 0)
turnvel += baseVel * hidInput->joyaxes[JOYAXIS_Yaw];
updateTurnHeldAmt(factor);
}
@ -739,13 +739,13 @@ static void processVehicleInput(player_struct *p, HIDInput* const hidInput, Inpu
// Cancel out micro-movement
if (fabs(hidInput->mouseturnx) < (m_sensitivity_x * m_yaw * backendinputscale() * 2.f)) hidInput->mouseturnx = 0;
p->vehTurnLeft = kbdLeft || hidInput->mouseturnx < 0 || hidInput->dyaw > 0;
p->vehTurnRight = kbdRight || hidInput->mouseturnx > 0 || hidInput->dyaw < 0;
p->vehTurnLeft = kbdLeft || hidInput->mouseturnx < 0 || hidInput->joyaxes[JOYAXIS_Yaw] > 0;
p->vehTurnRight = kbdRight || hidInput->mouseturnx > 0 || hidInput->joyaxes[JOYAXIS_Yaw] < 0;
if (p->OnBoat || !p->moto_underwater)
{
p->vehForwardScale = min((buttonMap.ButtonDown(gamefunc_Move_Forward) || buttonMap.ButtonDown(gamefunc_Strafe)) + hidInput->dforward, 1.f);
p->vehReverseScale = min(buttonMap.ButtonDown(gamefunc_Move_Backward) + -hidInput->dforward, 1.f);
p->vehForwardScale = min((buttonMap.ButtonDown(gamefunc_Move_Forward) || buttonMap.ButtonDown(gamefunc_Strafe)) + hidInput->joyaxes[JOYAXIS_Forward], 1.f);
p->vehReverseScale = min(buttonMap.ButtonDown(gamefunc_Move_Backward) + -hidInput->joyaxes[JOYAXIS_Forward], 1.f);
p->vehBraking = buttonMap.ButtonDown(gamefunc_Run);
}