mirror of
https://github.com/DrBeef/Raze.git
synced 2024-11-25 05:21:28 +00:00
- Move joyaxes[]
array from getHidInput()
directly into ControlInfo
.
This commit is contained in:
parent
08d22f49f4
commit
eed9716d86
4 changed files with 44 additions and 68 deletions
|
@ -119,27 +119,27 @@ void processMovement(InputPacket* const currInput, InputPacket* const inputBuffe
|
||||||
|
|
||||||
// determine player input.
|
// determine player input.
|
||||||
const auto turning = buttonMap.ButtonDown(gamefunc_Turn_Right) - buttonMap.ButtonDown(gamefunc_Turn_Left);
|
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 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->dside * scaleAdjustf;
|
const auto strafing = buttonMap.ButtonDown(gamefunc_Strafe_Right) - buttonMap.ButtonDown(gamefunc_Strafe_Left) - hidInput->joyaxes[JOYAXIS_Side] * scaleAdjustf;
|
||||||
|
|
||||||
// process player angle input.
|
// process player angle input.
|
||||||
if (!(buttonMap.ButtonDown(gamefunc_Strafe) && allowstrafe))
|
if (!(buttonMap.ButtonDown(gamefunc_Strafe) && allowstrafe))
|
||||||
{
|
{
|
||||||
const float turndir = clamp(turning + strafing * !allowstrafe, -1.f, 1.f);
|
const float turndir = clamp(turning + strafing * !allowstrafe, -1.f, 1.f);
|
||||||
const float turnspeed = float(getTicrateScale(YAW_TURNSPEEDS[keymove]) * turnscale * (isTurboTurnTime() ? 1. : YAW_PREAMBLESCALE));
|
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();
|
if (turndir) updateTurnHeldAmt(scaleAdjust); else resetTurnHeldAmt();
|
||||||
}
|
}
|
||||||
else
|
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.
|
// process player pitch input.
|
||||||
if (!(inputBuffer->actions & SB_AIMMODE))
|
if (!(inputBuffer->actions & SB_AIMMODE))
|
||||||
currInput->horz += hidInput->mouseturny - hidInput->dpitch * hidspeed * scaleAdjustf;
|
currInput->horz += hidInput->mouseturny - hidInput->joyaxes[JOYAXIS_Pitch] * hidspeed * scaleAdjustf;
|
||||||
else
|
else
|
||||||
currInput->fvel -= hidInput->mousemovey - hidInput->dpitch * keymove * scaleAdjustf;
|
currInput->fvel -= hidInput->mousemovey - hidInput->joyaxes[JOYAXIS_Pitch] * keymove * scaleAdjustf;
|
||||||
|
|
||||||
// process movement input.
|
// process movement input.
|
||||||
currInput->fvel += moving * keymove;
|
currInput->fvel += moving * keymove;
|
||||||
|
|
|
@ -195,30 +195,6 @@ int32_t handleevents(void)
|
||||||
return 0;
|
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))
|
if (hidInput && buttonMap.ButtonDown(gamefunc_Dpad_Select))
|
||||||
{
|
{
|
||||||
// These buttons should not autorepeat. The game handlers are not really equipped for that.
|
// 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;
|
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;
|
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;
|
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;
|
else dpad_lock &= ~8;
|
||||||
|
|
||||||
// This eats the controller input for regular use
|
// This eats the controller input for regular use
|
||||||
hidInput->dside = 0;
|
hidInput->joyaxes[JOYAXIS_Side] = 0;
|
||||||
hidInput->dforward = 0;
|
hidInput->joyaxes[JOYAXIS_Forward] = 0;
|
||||||
hidInput->dyaw = 0;
|
hidInput->joyaxes[JOYAXIS_Yaw] = 0;
|
||||||
}
|
}
|
||||||
else dpad_lock = 0;
|
else dpad_lock = 0;
|
||||||
|
|
||||||
input.actions |= ActionsToSend;
|
input.actions |= ActionsToSend;
|
||||||
ActionsToSend = 0;
|
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;
|
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;
|
input.actions |= SB_AIM_DOWN;
|
||||||
|
|
||||||
if (buttonMap.ButtonDown(gamefunc_Dpad_Aiming))
|
if (buttonMap.ButtonDown(gamefunc_Dpad_Aiming))
|
||||||
hidInput->dforward = 0;
|
hidInput->joyaxes[JOYAXIS_Forward] = 0;
|
||||||
|
|
||||||
if (buttonMap.ButtonDown(gamefunc_Jump))
|
if (buttonMap.ButtonDown(gamefunc_Jump))
|
||||||
input.actions |= SB_JUMP;
|
input.actions |= SB_JUMP;
|
||||||
|
|
|
@ -16,12 +16,7 @@
|
||||||
|
|
||||||
struct HIDInput
|
struct HIDInput
|
||||||
{
|
{
|
||||||
float dside;
|
float joyaxes[NUM_JOYAXIS];
|
||||||
float dup;
|
|
||||||
float dforward;
|
|
||||||
float dyaw;
|
|
||||||
float dpitch;
|
|
||||||
float droll;
|
|
||||||
float mouseturnx;
|
float mouseturnx;
|
||||||
float mouseturny;
|
float mouseturny;
|
||||||
float mousemovex;
|
float mousemovex;
|
||||||
|
@ -63,7 +58,6 @@ public:
|
||||||
|
|
||||||
extern InputState inputState;
|
extern InputState inputState;
|
||||||
|
|
||||||
void getHidInput(HIDInput* const hidInput);
|
|
||||||
int32_t handleevents(void);
|
int32_t handleevents(void);
|
||||||
|
|
||||||
enum GameFunction_t
|
enum GameFunction_t
|
||||||
|
@ -116,6 +110,12 @@ inline float backendinputscale()
|
||||||
return (1.f / 16.f);
|
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.
|
// Inline functions to help with edge cases where synchronised input is needed.
|
||||||
|
|
|
@ -564,13 +564,13 @@ static float motoApplyTurn(player_struct* p, HIDInput* const hidInput, bool cons
|
||||||
{
|
{
|
||||||
resetTurnHeldAmt();
|
resetTurnHeldAmt();
|
||||||
|
|
||||||
if (kbdLeft || hidInput->mouseturnx < 0 || hidInput->dyaw > 0)
|
if (kbdLeft || hidInput->mouseturnx < 0 || hidInput->joyaxes[JOYAXIS_Yaw] > 0)
|
||||||
{
|
{
|
||||||
p->TiltStatus -= (float)factor;
|
p->TiltStatus -= (float)factor;
|
||||||
if (p->TiltStatus < -10)
|
if (p->TiltStatus < -10)
|
||||||
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;
|
p->TiltStatus += (float)factor;
|
||||||
if (p->TiltStatus > 10)
|
if (p->TiltStatus > 10)
|
||||||
|
@ -579,12 +579,12 @@ static float motoApplyTurn(player_struct* p, HIDInput* const hidInput, bool cons
|
||||||
}
|
}
|
||||||
else
|
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);
|
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;
|
p->TiltStatus -= (float)factor;
|
||||||
|
|
||||||
|
@ -597,13 +597,13 @@ static float motoApplyTurn(player_struct* p, HIDInput* const hidInput, bool cons
|
||||||
if (hidInput->mouseturnx < 0)
|
if (hidInput->mouseturnx < 0)
|
||||||
turnvel -= Sgn(baseVel) * sqrtf(abs(p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * -(hidInput->mouseturnx / factor) * (7.f / 20.f));
|
turnvel -= Sgn(baseVel) * sqrtf(abs(p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * -(hidInput->mouseturnx / factor) * (7.f / 20.f));
|
||||||
|
|
||||||
if (hidInput->dyaw > 0)
|
if (hidInput->joyaxes[JOYAXIS_Yaw] > 0)
|
||||||
turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * hidInput->dyaw;
|
turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * hidInput->joyaxes[JOYAXIS_Yaw];
|
||||||
|
|
||||||
updateTurnHeldAmt(factor);
|
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;
|
p->TiltStatus += (float)factor;
|
||||||
|
|
||||||
|
@ -616,8 +616,8 @@ static float motoApplyTurn(player_struct* p, HIDInput* const hidInput, bool cons
|
||||||
if (hidInput->mouseturnx > 0)
|
if (hidInput->mouseturnx > 0)
|
||||||
turnvel += Sgn(baseVel) * sqrtf(abs(p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * (hidInput->mouseturnx / factor) * (7.f / 20.f));
|
turnvel += Sgn(baseVel) * sqrtf(abs(p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * (hidInput->mouseturnx / factor) * (7.f / 20.f));
|
||||||
|
|
||||||
if (hidInput->dyaw < 0)
|
if (hidInput->joyaxes[JOYAXIS_Yaw] < 0)
|
||||||
turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * hidInput->dyaw;
|
turnvel += (p->MotoSpeed > 0 ? baseVel : baseVel * velScale) * hidInput->joyaxes[JOYAXIS_Yaw];
|
||||||
|
|
||||||
updateTurnHeldAmt(factor);
|
updateTurnHeldAmt(factor);
|
||||||
}
|
}
|
||||||
|
@ -652,12 +652,12 @@ static float boatApplyTurn(player_struct *p, HIDInput* const hidInput, bool cons
|
||||||
|
|
||||||
if (p->MotoSpeed)
|
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 velScale = !p->NotOnWater? 1.f : (6.f / 19.f);
|
||||||
const float baseVel = VEHICLETURN * velScale;
|
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)
|
if (!p->NotOnWater)
|
||||||
{
|
{
|
||||||
|
@ -672,13 +672,13 @@ static float boatApplyTurn(player_struct *p, HIDInput* const hidInput, bool cons
|
||||||
if (hidInput->mouseturnx < 0)
|
if (hidInput->mouseturnx < 0)
|
||||||
turnvel -= Sgn(baseVel) * sqrtf(abs(baseVel) * -(hidInput->mouseturnx / factor) * (7.f / 20.f));
|
turnvel -= Sgn(baseVel) * sqrtf(abs(baseVel) * -(hidInput->mouseturnx / factor) * (7.f / 20.f));
|
||||||
|
|
||||||
if (hidInput->dyaw > 0)
|
if (hidInput->joyaxes[JOYAXIS_Yaw] > 0)
|
||||||
turnvel += baseVel * hidInput->dyaw;
|
turnvel += baseVel * hidInput->joyaxes[JOYAXIS_Yaw];
|
||||||
|
|
||||||
updateTurnHeldAmt(factor);
|
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)
|
if (!p->NotOnWater)
|
||||||
{
|
{
|
||||||
|
@ -693,8 +693,8 @@ static float boatApplyTurn(player_struct *p, HIDInput* const hidInput, bool cons
|
||||||
if (hidInput->mouseturnx > 0)
|
if (hidInput->mouseturnx > 0)
|
||||||
turnvel += Sgn(baseVel) * sqrtf(abs(baseVel) * (hidInput->mouseturnx / factor) * (7.f / 20.f));
|
turnvel += Sgn(baseVel) * sqrtf(abs(baseVel) * (hidInput->mouseturnx / factor) * (7.f / 20.f));
|
||||||
|
|
||||||
if (hidInput->dyaw < 0)
|
if (hidInput->joyaxes[JOYAXIS_Yaw] < 0)
|
||||||
turnvel += baseVel * hidInput->dyaw;
|
turnvel += baseVel * hidInput->joyaxes[JOYAXIS_Yaw];
|
||||||
|
|
||||||
updateTurnHeldAmt(factor);
|
updateTurnHeldAmt(factor);
|
||||||
}
|
}
|
||||||
|
@ -739,13 +739,13 @@ static void processVehicleInput(player_struct *p, HIDInput* const hidInput, Inpu
|
||||||
// Cancel out micro-movement
|
// Cancel out micro-movement
|
||||||
if (fabs(hidInput->mouseturnx) < (m_sensitivity_x * m_yaw * backendinputscale() * 2.f)) hidInput->mouseturnx = 0;
|
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->vehTurnLeft = kbdLeft || hidInput->mouseturnx < 0 || hidInput->joyaxes[JOYAXIS_Yaw] > 0;
|
||||||
p->vehTurnRight = kbdRight || hidInput->mouseturnx > 0 || hidInput->dyaw < 0;
|
p->vehTurnRight = kbdRight || hidInput->mouseturnx > 0 || hidInput->joyaxes[JOYAXIS_Yaw] < 0;
|
||||||
|
|
||||||
if (p->OnBoat || !p->moto_underwater)
|
if (p->OnBoat || !p->moto_underwater)
|
||||||
{
|
{
|
||||||
p->vehForwardScale = min((buttonMap.ButtonDown(gamefunc_Move_Forward) || buttonMap.ButtonDown(gamefunc_Strafe)) + 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->dforward, 1.f);
|
p->vehReverseScale = min(buttonMap.ButtonDown(gamefunc_Move_Backward) + -hidInput->joyaxes[JOYAXIS_Forward], 1.f);
|
||||||
p->vehBraking = buttonMap.ButtonDown(gamefunc_Run);
|
p->vehBraking = buttonMap.ButtonDown(gamefunc_Run);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue