2020-10-11 14:33:43 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
Copyright (C) 2019 Christoph Oelckers
|
|
|
|
Copyright (C) 2020 Mitchell Richters
|
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
2023-03-18 08:48:18 +00:00
|
|
|
#include "menu.h"
|
2020-10-11 14:33:43 +00:00
|
|
|
#include "gameinput.h"
|
2023-09-28 02:29:06 +00:00
|
|
|
#include "g_input.h"
|
2022-06-11 08:36:20 +00:00
|
|
|
|
2023-03-30 12:44:12 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2023-09-24 03:31:32 +00:00
|
|
|
// CVARs to control input.
|
2023-03-30 12:44:12 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2023-09-24 03:31:32 +00:00
|
|
|
CVAR(Bool, cl_noturnscaling, false, CVAR_GLOBALCONFIG | CVAR_ARCHIVE);
|
2023-03-30 12:44:12 +00:00
|
|
|
CVAR(Float, m_pitch, 1.f, CVAR_GLOBALCONFIG | CVAR_ARCHIVE)
|
|
|
|
CVAR(Float, m_yaw, 1.f, CVAR_GLOBALCONFIG | CVAR_ARCHIVE)
|
|
|
|
CVAR(Float, m_forward, 1.f, CVAR_GLOBALCONFIG | CVAR_ARCHIVE)
|
|
|
|
CVAR(Float, m_side, 1.f, CVAR_GLOBALCONFIG | CVAR_ARCHIVE)
|
2023-04-02 08:32:36 +00:00
|
|
|
|
|
|
|
|
2022-09-27 07:08:01 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2023-04-03 08:46:36 +00:00
|
|
|
// Initialised variables.
|
2022-09-27 07:08:01 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2023-04-03 08:46:36 +00:00
|
|
|
GameInput gameInput{};
|
2023-09-24 03:40:15 +00:00
|
|
|
bool crouch_toggle = false;
|
2022-09-27 07:08:01 +00:00
|
|
|
|
|
|
|
|
2023-09-24 05:53:39 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2023-09-24 07:50:06 +00:00
|
|
|
// Clears crouch toggle state for new games.
|
2023-09-24 05:53:39 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2023-09-24 07:50:06 +00:00
|
|
|
void GameInput::resetCrouchToggle()
|
2023-09-24 05:53:39 +00:00
|
|
|
{
|
|
|
|
crouch_toggle = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-04 05:05:00 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Default player movement function for the games. Can be overridden.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2023-10-04 05:08:03 +00:00
|
|
|
void GameInterface::doPlayerMovement()
|
2023-10-04 05:05:00 +00:00
|
|
|
{
|
2023-10-04 05:08:03 +00:00
|
|
|
gameInput.processMovement();
|
2023-10-04 05:05:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-11 14:33:43 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2023-04-03 09:35:35 +00:00
|
|
|
// Player's movement function, called from game's ticker or from gi->doPlayerMovement() as required.
|
2020-10-11 14:33:43 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2023-10-04 05:08:03 +00:00
|
|
|
void GameInput::processMovement(const double turnscale, const bool allowstrafe, const int drink_amt)
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2022-09-19 23:54:01 +00:00
|
|
|
// set up variables.
|
2023-04-23 09:19:26 +00:00
|
|
|
InputPacket thisInput{};
|
2023-10-03 21:56:08 +00:00
|
|
|
keymove = 1 << int(!!(inputBuffer.actions & SB_RUN));
|
2023-10-06 22:37:45 +00:00
|
|
|
const auto hidspeed = getTicrateAngle(YAW_TURNSPEEDS[2]);
|
2022-09-19 23:54:01 +00:00
|
|
|
|
2023-04-23 09:19:26 +00:00
|
|
|
// get all input amounts.
|
|
|
|
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) +
|
|
|
|
joyAxes[JOYAXIS_Forward] * scaleAdjust;
|
|
|
|
|
|
|
|
const auto strafing = buttonMap.ButtonDown(gamefunc_Strafe_Right) -
|
|
|
|
buttonMap.ButtonDown(gamefunc_Strafe_Left) -
|
|
|
|
joyAxes[JOYAXIS_Side] * scaleAdjust;
|
|
|
|
|
2023-04-23 09:34:59 +00:00
|
|
|
const auto soaring = buttonMap.ButtonDown(gamefunc_Move_Up) -
|
|
|
|
buttonMap.ButtonDown(gamefunc_Move_Down) +
|
|
|
|
joyAxes[JOYAXIS_Up] * scaleAdjust;
|
|
|
|
|
2023-04-23 09:19:26 +00:00
|
|
|
// process player yaw input.
|
2022-09-19 23:54:01 +00:00
|
|
|
if (!(buttonMap.ButtonDown(gamefunc_Strafe) && allowstrafe))
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2023-10-03 09:58:38 +00:00
|
|
|
const double turndir = clamp(turning + strafing * !allowstrafe, -1., 1.);
|
2023-10-31 03:44:58 +00:00
|
|
|
const double tttscale = (cl_noturnscaling || isTurboTurnTime()) ? 1 : (5. / 19.);
|
|
|
|
const DAngle turnspeed = getTicrateAngle(YAW_TURNSPEEDS[keymove] * tttscale);
|
2023-10-03 09:58:38 +00:00
|
|
|
thisInput.ang.Yaw += MOUSE_SCALE * mouseInput.X * m_yaw;
|
|
|
|
thisInput.ang.Yaw -= hidspeed * joyAxes[JOYAXIS_Yaw] * scaleAdjust;
|
|
|
|
thisInput.ang.Yaw += turnspeed * turndir * scaleAdjust;
|
2023-10-03 06:56:12 +00:00
|
|
|
thisInput.ang.Yaw *= turnscale;
|
2023-10-04 05:08:03 +00:00
|
|
|
if (turndir) updateTurnHeldAmt(); else turnheldtime = 0;
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
2022-06-11 07:12:56 +00:00
|
|
|
else
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2023-10-03 09:58:38 +00:00
|
|
|
thisInput.vel.Y += mouseInput.X * MOUSE_SCALE.Degrees() * m_side;
|
2023-10-03 05:17:00 +00:00
|
|
|
thisInput.vel.Y -= joyAxes[JOYAXIS_Yaw] * keymove * scaleAdjust;
|
|
|
|
thisInput.vel.Y += turning * keymove * scaleAdjust;
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
2022-06-11 07:12:56 +00:00
|
|
|
|
2022-09-19 23:54:01 +00:00
|
|
|
// process player pitch input.
|
2023-03-30 12:14:26 +00:00
|
|
|
if (!(inputBuffer.actions & SB_AIMMODE))
|
2023-04-03 09:35:35 +00:00
|
|
|
{
|
2023-10-03 09:58:38 +00:00
|
|
|
thisInput.ang.Pitch -= MOUSE_SCALE * mouseInput.Y * m_pitch;
|
|
|
|
thisInput.ang.Pitch -= hidspeed * joyAxes[JOYAXIS_Pitch] * scaleAdjust;
|
2023-10-03 06:56:12 +00:00
|
|
|
thisInput.ang.Pitch *= turnscale;
|
2023-04-03 09:35:35 +00:00
|
|
|
}
|
2022-06-11 07:12:56 +00:00
|
|
|
else
|
2023-04-03 09:35:35 +00:00
|
|
|
{
|
2023-10-03 09:58:38 +00:00
|
|
|
thisInput.vel.X += mouseInput.Y * MOUSE_SCALE.Degrees() * m_forward;
|
2023-10-03 05:17:00 +00:00
|
|
|
thisInput.vel.X += joyAxes[JOYAXIS_Pitch] * keymove * scaleAdjust;
|
2023-04-03 09:35:35 +00:00
|
|
|
}
|
2022-09-19 23:54:01 +00:00
|
|
|
|
|
|
|
// process movement input.
|
2023-10-03 05:17:00 +00:00
|
|
|
thisInput.vel.X += moving * keymove;
|
|
|
|
thisInput.vel.Y += strafing * keymove * allowstrafe;
|
|
|
|
thisInput.vel.Z += soaring; // this isn't scaled by running.
|
2022-10-27 22:43:56 +00:00
|
|
|
|
|
|
|
// process RR's drunk state.
|
2023-03-18 10:16:50 +00:00
|
|
|
if (isRR() && drink_amt >= 66 && drink_amt <= 87)
|
2023-04-23 09:19:26 +00:00
|
|
|
{
|
2023-10-03 05:17:00 +00:00
|
|
|
thisInput.vel.Y += drink_amt & 1 ? -thisInput.vel.X : thisInput.vel.X;
|
2023-04-23 09:19:26 +00:00
|
|
|
}
|
2020-10-11 14:33:43 +00:00
|
|
|
|
|
|
|
// add collected input to game's local input accumulation packet.
|
2023-10-03 21:56:08 +00:00
|
|
|
inputBuffer.vel += thisInput.vel;
|
|
|
|
inputBuffer.ang += thisInput.ang;
|
2023-04-03 09:35:35 +00:00
|
|
|
|
|
|
|
// directly update player angles if we can.
|
|
|
|
if (scaleAdjust < 1)
|
|
|
|
{
|
2023-10-31 03:44:58 +00:00
|
|
|
PlayerArray[myconnectindex]->CameraAngles += thisInput.ang;
|
2023-04-03 09:35:35 +00:00
|
|
|
}
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
|
|
|
|
2022-09-27 07:08:01 +00:00
|
|
|
|
2023-04-02 08:32:36 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Player's vehicle movement function.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2023-10-04 05:08:03 +00:00
|
|
|
void GameInput::processVehicle(const double baseVel, const double velScale, const unsigned flags)
|
2023-04-02 08:32:36 +00:00
|
|
|
{
|
2023-04-03 09:35:35 +00:00
|
|
|
// open up input packet for this session.
|
|
|
|
InputPacket thisInput{};
|
|
|
|
|
2023-04-02 08:32:36 +00:00
|
|
|
// mask out all actions not compatible with vehicles.
|
2023-03-30 12:14:26 +00:00
|
|
|
inputBuffer.actions &= ~(SB_WEAPONMASK_BITS | SB_TURNAROUND | SB_CENTERVIEW | SB_HOLSTER | SB_JUMP | SB_CROUCH | SB_RUN |
|
2023-04-02 08:32:36 +00:00
|
|
|
SB_AIM_UP | SB_AIM_DOWN | SB_AIMMODE | SB_LOOK_UP | SB_LOOK_DOWN | SB_LOOK_LEFT | SB_LOOK_RIGHT);
|
|
|
|
|
2023-10-03 21:56:08 +00:00
|
|
|
if ((keymove = !!(flags & VEH_CANMOVE)))
|
2023-04-02 08:32:36 +00:00
|
|
|
{
|
2023-04-03 08:37:38 +00:00
|
|
|
const auto kbdForwards = buttonMap.ButtonDown(gamefunc_Move_Forward) || buttonMap.ButtonDown(gamefunc_Strafe);
|
|
|
|
const auto kbdBackward = buttonMap.ButtonDown(gamefunc_Move_Backward);
|
2023-10-03 05:17:00 +00:00
|
|
|
thisInput.vel.X = kbdForwards - kbdBackward + joyAxes[JOYAXIS_Forward];
|
2023-10-03 21:56:08 +00:00
|
|
|
inputBuffer.vel.X += thisInput.vel.X;
|
2023-04-23 09:19:26 +00:00
|
|
|
|
|
|
|
// This sync bit is the brake key.
|
2023-03-30 12:14:26 +00:00
|
|
|
if (buttonMap.ButtonDown(gamefunc_Run)) inputBuffer.actions |= SB_CROUCH;
|
2023-04-02 08:32:36 +00:00
|
|
|
}
|
|
|
|
|
2023-09-25 09:51:53 +00:00
|
|
|
if (flags & VEH_CANTURN)
|
2023-04-02 08:32:36 +00:00
|
|
|
{
|
2023-04-23 09:19:26 +00:00
|
|
|
// Keyboard turning.
|
2023-04-03 08:37:38 +00:00
|
|
|
const auto kbdLeft = buttonMap.ButtonDown(gamefunc_Turn_Left) || buttonMap.ButtonDown(gamefunc_Strafe_Left);
|
|
|
|
const auto kbdRight = buttonMap.ButtonDown(gamefunc_Turn_Right) || buttonMap.ButtonDown(gamefunc_Strafe_Right);
|
2023-04-23 09:19:26 +00:00
|
|
|
const auto kbdDir = kbdRight - kbdLeft;
|
|
|
|
|
|
|
|
// Input device turning.
|
2023-04-03 08:40:34 +00:00
|
|
|
const auto hidLeft = mouseInput.X < 0 || joyAxes[JOYAXIS_Yaw] > 0;
|
|
|
|
const auto hidRight = mouseInput.X > 0 || joyAxes[JOYAXIS_Yaw] < 0;
|
2023-09-27 01:41:40 +00:00
|
|
|
const auto hidDir = hidRight - hidLeft;
|
2023-04-23 09:19:26 +00:00
|
|
|
|
|
|
|
// Velocity setup.
|
2023-09-27 01:41:40 +00:00
|
|
|
const auto scaleVel = !(flags & VEH_SCALETURN) && (cl_noturnscaling || hidDir || isTurboTurnTime());
|
|
|
|
const auto turnVel = scaleVel ? baseVel : baseVel * velScale;
|
2023-10-05 08:06:39 +00:00
|
|
|
const auto mouseVel = abs(turnVel * mouseInput.X * m_yaw) * (45. / 2048.) / scaleAdjust;
|
2023-04-03 08:37:38 +00:00
|
|
|
|
2023-04-23 09:19:26 +00:00
|
|
|
// Apply inputs.
|
2023-10-05 08:06:39 +00:00
|
|
|
thisInput.ang.Yaw += DAngle::fromDeg(((mouseVel > 1) ? g_sqrt(mouseVel) : mouseVel) * Sgn(turnVel) * Sgn(mouseInput.X) * Sgn(m_yaw));
|
2023-10-06 22:37:45 +00:00
|
|
|
thisInput.ang.Yaw -= DAngle::fromDeg(turnVel * joyAxes[JOYAXIS_Yaw] - turnVel * kbdDir);
|
2023-10-03 06:56:12 +00:00
|
|
|
thisInput.ang.Yaw *= scaleAdjust;
|
2023-10-03 21:56:08 +00:00
|
|
|
inputBuffer.ang.Yaw += thisInput.ang.Yaw;
|
2023-10-04 05:08:03 +00:00
|
|
|
if (kbdDir) updateTurnHeldAmt(); else turnheldtime = 0;
|
2023-04-02 08:32:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-04-03 08:46:36 +00:00
|
|
|
turnheldtime = 0;
|
2023-04-02 08:32:36 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 09:35:35 +00:00
|
|
|
// directly update player angles if we can.
|
|
|
|
if (scaleAdjust < 1)
|
|
|
|
{
|
2023-10-31 03:44:58 +00:00
|
|
|
PlayerArray[myconnectindex]->CameraAngles += thisInput.ang;
|
2023-04-03 09:35:35 +00:00
|
|
|
}
|
2023-04-02 08:32:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-04-03 08:40:34 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Processes all the input bits.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
2023-03-30 13:31:59 +00:00
|
|
|
|
2023-04-03 08:40:34 +00:00
|
|
|
void GameInput::processInputBits()
|
|
|
|
{
|
2023-03-30 12:14:26 +00:00
|
|
|
if (WeaponToSend != 0) inputBuffer.setNewWeapon(WeaponToSend);
|
2023-03-30 12:10:27 +00:00
|
|
|
WeaponToSend = 0;
|
2023-04-03 08:40:34 +00:00
|
|
|
if (buttonMap.ButtonDown(gamefunc_Dpad_Select))
|
2023-03-30 12:10:27 +00:00
|
|
|
{
|
|
|
|
// These buttons should not autorepeat. The game handlers are not really equipped for that.
|
2023-04-03 08:40:34 +00:00
|
|
|
if (joyAxes[JOYAXIS_Forward] > 0 && !(dpad_lock & 1)) { dpad_lock |= 1; inputBuffer.setNewWeapon(WeaponSel_Prev); }
|
2023-03-30 12:10:27 +00:00
|
|
|
else dpad_lock &= ~1;
|
2023-04-03 08:40:34 +00:00
|
|
|
if (joyAxes[JOYAXIS_Forward] < 0 && !(dpad_lock & 2)) { dpad_lock |= 2; inputBuffer.setNewWeapon(WeaponSel_Next); }
|
2023-03-30 12:10:27 +00:00
|
|
|
else dpad_lock &= ~2;
|
2023-04-03 08:40:34 +00:00
|
|
|
if ((joyAxes[JOYAXIS_Side] < 0 || joyAxes[JOYAXIS_Yaw] > 0) && !(dpad_lock & 4)) { dpad_lock |= 4; inputBuffer.actions |= SB_INVPREV; }
|
2023-03-30 12:10:27 +00:00
|
|
|
else dpad_lock &= ~4;
|
2023-04-03 08:40:34 +00:00
|
|
|
if ((joyAxes[JOYAXIS_Side] > 0 || joyAxes[JOYAXIS_Yaw] < 0) && !(dpad_lock & 8)) { dpad_lock |= 8; inputBuffer.actions |= SB_INVNEXT; }
|
2023-03-30 12:10:27 +00:00
|
|
|
else dpad_lock &= ~8;
|
|
|
|
|
2023-03-30 12:14:26 +00:00
|
|
|
// This eats the controller input for regular use
|
2023-04-03 08:40:34 +00:00
|
|
|
joyAxes[JOYAXIS_Side] = 0;
|
|
|
|
joyAxes[JOYAXIS_Forward] = 0;
|
|
|
|
joyAxes[JOYAXIS_Yaw] = 0;
|
2023-03-30 12:10:27 +00:00
|
|
|
}
|
|
|
|
else dpad_lock = 0;
|
|
|
|
|
2023-09-24 03:40:15 +00:00
|
|
|
const auto crouchState = gi->getCrouchState();
|
2023-10-03 22:27:15 +00:00
|
|
|
inputBuffer.actions |= ActionsToSend | GetPersistentActions();
|
2023-03-30 12:10:27 +00:00
|
|
|
ActionsToSend = 0;
|
|
|
|
|
2023-04-03 08:40:34 +00:00
|
|
|
if (buttonMap.ButtonDown(gamefunc_Aim_Up) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && joyAxes[JOYAXIS_Forward] > 0))
|
2023-03-30 12:10:27 +00:00
|
|
|
{
|
2023-03-30 12:14:26 +00:00
|
|
|
inputBuffer.actions |= SB_AIM_UP;
|
|
|
|
inputBuffer.actions &= ~SB_CENTERVIEW;
|
2023-03-30 12:10:27 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 08:40:34 +00:00
|
|
|
if ((buttonMap.ButtonDown(gamefunc_Aim_Down) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && joyAxes[JOYAXIS_Forward] < 0)))
|
2023-03-30 12:10:27 +00:00
|
|
|
{
|
2023-03-30 12:14:26 +00:00
|
|
|
inputBuffer.actions |= SB_AIM_DOWN;
|
|
|
|
inputBuffer.actions &= ~SB_CENTERVIEW;
|
2023-03-30 12:10:27 +00:00
|
|
|
}
|
|
|
|
|
2023-09-24 03:40:15 +00:00
|
|
|
if (buttonMap.ButtonDown(gamefunc_Toggle_Crouch))
|
|
|
|
{
|
|
|
|
const bool canCrouch = crouchState & CS_CANCROUCH;
|
|
|
|
crouch_toggle = !crouch_toggle && canCrouch;
|
|
|
|
if (canCrouch) buttonMap.ClearButton(gamefunc_Toggle_Crouch);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Crouch) || buttonMap.ButtonDown(gamefunc_Jump) || (crouchState & CS_DISABLETOGGLE))
|
|
|
|
crouch_toggle = false;
|
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Crouch) || buttonMap.ButtonDown(gamefunc_Toggle_Crouch) || crouch_toggle)
|
|
|
|
inputBuffer.actions |= SB_CROUCH;
|
|
|
|
|
2023-03-30 12:10:27 +00:00
|
|
|
if (buttonMap.ButtonDown(gamefunc_Dpad_Aiming))
|
2023-04-03 08:40:34 +00:00
|
|
|
joyAxes[JOYAXIS_Forward] = 0;
|
2023-03-30 12:10:27 +00:00
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Jump))
|
2023-03-30 12:14:26 +00:00
|
|
|
inputBuffer.actions |= SB_JUMP;
|
2023-03-30 12:10:27 +00:00
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Fire))
|
2023-03-30 12:14:26 +00:00
|
|
|
inputBuffer.actions |= SB_FIRE;
|
2023-03-30 12:10:27 +00:00
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Alt_Fire))
|
2023-03-30 12:14:26 +00:00
|
|
|
inputBuffer.actions |= SB_ALTFIRE;
|
2023-03-30 12:10:27 +00:00
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Open))
|
|
|
|
{
|
2023-09-22 23:51:45 +00:00
|
|
|
if (isBlood() || isExhumed()) buttonMap.ClearButton(gamefunc_Open);
|
2023-03-30 12:14:26 +00:00
|
|
|
inputBuffer.actions |= SB_OPEN;
|
2023-03-30 12:10:27 +00:00
|
|
|
}
|
2023-09-24 03:40:15 +00:00
|
|
|
|
2023-03-30 12:10:27 +00:00
|
|
|
if (G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run)))
|
2023-03-30 12:14:26 +00:00
|
|
|
inputBuffer.actions |= SB_RUN;
|
2023-03-30 12:10:27 +00:00
|
|
|
|
|
|
|
if (!in_mousemode && !buttonMap.ButtonDown(gamefunc_Mouse_Aiming))
|
2023-03-30 12:14:26 +00:00
|
|
|
inputBuffer.actions |= SB_AIMMODE;
|
2023-03-30 12:10:27 +00:00
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Look_Up))
|
2023-03-30 12:14:26 +00:00
|
|
|
inputBuffer.actions |= SB_LOOK_UP;
|
2023-03-30 12:10:27 +00:00
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Look_Down))
|
2023-03-30 12:14:26 +00:00
|
|
|
inputBuffer.actions |= SB_LOOK_DOWN;
|
2023-03-30 12:10:27 +00:00
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Look_Left))
|
2023-03-30 12:14:26 +00:00
|
|
|
inputBuffer.actions |= SB_LOOK_LEFT;
|
2023-03-30 12:10:27 +00:00
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Look_Right))
|
2023-03-30 12:14:26 +00:00
|
|
|
inputBuffer.actions |= SB_LOOK_RIGHT;
|
2023-03-30 12:10:27 +00:00
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Quick_Kick))
|
2023-03-30 12:14:26 +00:00
|
|
|
inputBuffer.actions |= SB_QUICK_KICK;
|
2023-03-30 12:10:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-18 08:48:18 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Processes input and returns a packet if provided.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2023-10-04 05:08:03 +00:00
|
|
|
void GameInput::getInput(InputPacket* packet)
|
2023-03-18 08:48:18 +00:00
|
|
|
{
|
2023-09-28 02:29:06 +00:00
|
|
|
I_GetEvent();
|
|
|
|
|
2023-10-05 04:08:24 +00:00
|
|
|
if (paused || M_Active() || gamestate != GS_LEVEL)
|
2023-03-18 08:48:18 +00:00
|
|
|
{
|
2023-03-30 12:20:18 +00:00
|
|
|
inputBuffer = {};
|
2023-03-18 08:48:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-04-04 10:05:03 +00:00
|
|
|
I_GetAxes(joyAxes);
|
2023-04-03 08:40:34 +00:00
|
|
|
processInputBits();
|
2023-10-04 05:08:03 +00:00
|
|
|
gi->doPlayerMovement();
|
2023-04-04 10:05:03 +00:00
|
|
|
mouseInput.Zero();
|
2023-03-18 08:48:18 +00:00
|
|
|
|
|
|
|
if (packet)
|
|
|
|
{
|
2023-10-03 21:56:08 +00:00
|
|
|
const DVector3& maxVel = MAXVEL[keymove];
|
|
|
|
*packet = { clamp(inputBuffer.vel, -maxVel, maxVel), clamp(inputBuffer.ang, -MAXANG, MAXANG), inputBuffer.actions };
|
2023-03-30 12:20:18 +00:00
|
|
|
inputBuffer = {};
|
2023-03-18 08:48:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-30 12:10:27 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
CCMD(slot)
|
|
|
|
{
|
|
|
|
// The max differs between games so we have to handle this here.
|
|
|
|
const bool isDukeShareware = (g_gameType & (GAMEFLAG_DUKE | GAMEFLAG_SHAREWARE)) == (GAMEFLAG_DUKE | GAMEFLAG_SHAREWARE);
|
2023-04-05 00:22:18 +00:00
|
|
|
const int max = isExhumed() || isDukeShareware ? WeaponSel_MaxExhumed : isBlood() ? WeaponSel_MaxBlood : WeaponSel_Max;
|
2023-03-30 12:10:27 +00:00
|
|
|
|
|
|
|
if (argv.argc() != 2)
|
|
|
|
{
|
|
|
|
Printf("slot <weaponslot>: select a weapon from the given slot (1-%d)", max);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto slot = atoi(argv[1]);
|
|
|
|
|
|
|
|
if (slot >= 1 && slot <= max)
|
|
|
|
{
|
2023-04-03 08:46:36 +00:00
|
|
|
gameInput.SendWeapon(slot);
|
2023-03-30 12:10:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CCMD(weapprev)
|
|
|
|
{
|
2023-04-03 08:46:36 +00:00
|
|
|
gameInput.SendWeapon(WeaponSel_Prev);
|
2023-03-30 12:10:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CCMD(weapnext)
|
|
|
|
{
|
2023-04-03 08:46:36 +00:00
|
|
|
gameInput.SendWeapon(WeaponSel_Next);
|
2023-03-30 12:10:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CCMD(weapalt)
|
|
|
|
{
|
2023-04-03 08:46:36 +00:00
|
|
|
gameInput.SendWeapon(WeaponSel_Alt); // Only used by SW - should also be made usable by Blood ans Duke which put multiple weapons in the same slot.
|
2023-03-30 12:10:27 +00:00
|
|
|
}
|
2023-04-02 08:26:22 +00:00
|
|
|
|
|
|
|
CCMD(useitem)
|
|
|
|
{
|
|
|
|
const int max = isExhumed() ? 6 : isSWALL() ? 7 : isBlood() ? 4 : 5;
|
|
|
|
|
|
|
|
if (argv.argc() != 2)
|
|
|
|
{
|
|
|
|
Printf("useitem <itemnum>: activates an inventory item (1-%d)", max);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto slot = atoi(argv[1]);
|
|
|
|
|
|
|
|
if (slot >= 1 && slot <= max)
|
|
|
|
{
|
2023-04-03 08:46:36 +00:00
|
|
|
gameInput.SendAction(ESyncBits::FromInt(SB_ITEM_BIT_1 << (slot - 1)));
|
2023-04-02 08:26:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CCMD(invprev)
|
|
|
|
{
|
2023-04-03 08:46:36 +00:00
|
|
|
gameInput.SendAction(SB_INVPREV);
|
2023-04-02 08:26:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CCMD(invnext)
|
|
|
|
{
|
2023-04-03 08:46:36 +00:00
|
|
|
gameInput.SendAction(SB_INVNEXT);
|
2023-04-02 08:26:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CCMD(invuse)
|
|
|
|
{
|
2023-04-03 08:46:36 +00:00
|
|
|
gameInput.SendAction(SB_INVUSE);
|
2023-04-02 08:26:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CCMD(centerview)
|
|
|
|
{
|
2023-04-03 08:46:36 +00:00
|
|
|
gameInput.SendAction(SB_CENTERVIEW);
|
2023-04-02 08:26:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CCMD(turnaround)
|
|
|
|
{
|
2023-04-03 08:46:36 +00:00
|
|
|
gameInput.SendAction(SB_TURNAROUND);
|
2023-04-02 08:26:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CCMD(holsterweapon)
|
|
|
|
{
|
2023-04-03 08:46:36 +00:00
|
|
|
gameInput.SendAction(SB_HOLSTER);
|
2023-04-02 08:26:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CCMD(third_person_view)
|
|
|
|
{
|
|
|
|
gi->ToggleThirdPerson();
|
|
|
|
}
|
|
|
|
|
|
|
|
CCMD(coop_view)
|
|
|
|
{
|
|
|
|
gi->SwitchCoopView();
|
|
|
|
}
|
|
|
|
|
|
|
|
CCMD(show_weapon)
|
|
|
|
{
|
|
|
|
gi->ToggleShowWeapon();
|
|
|
|
}
|