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"
|
|
|
|
#include "gamestate.h"
|
2020-10-11 14:33:43 +00:00
|
|
|
#include "gameinput.h"
|
2022-06-11 08:36:20 +00:00
|
|
|
|
2022-09-27 07:08:01 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Static constants used throughout functions.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
BUILDTICRATE = 120,
|
|
|
|
TURBOTURNBASE = 590,
|
|
|
|
};
|
|
|
|
|
2022-09-28 02:33:22 +00:00
|
|
|
static constexpr double YAW_TURNSPEEDS[3] = { 41.1987304, 156.555175, 272.24121 };
|
2022-09-27 07:08:01 +00:00
|
|
|
static constexpr double YAW_PREAMBLESCALE = YAW_TURNSPEEDS[0] / YAW_TURNSPEEDS[1];
|
2022-12-07 05:06:03 +00:00
|
|
|
static constexpr double YAW_LOOKINGSPEED = 801.5625;
|
|
|
|
static constexpr double YAW_ROTATESPEED = 63.28125;
|
|
|
|
static constexpr double YAW_LOOKRETURN = 7.5;
|
|
|
|
static constexpr double YAW_SPINSTAND = 675.;
|
|
|
|
static constexpr double YAW_SPINCROUCH = YAW_SPINSTAND * 0.5;
|
|
|
|
static constexpr double PITCH_LOOKSPEED = 222.83185;
|
|
|
|
static constexpr double PITCH_AIMSPEED = PITCH_LOOKSPEED * 0.5;
|
|
|
|
static constexpr double PITCH_CENTERSPEED = 10.7375;
|
|
|
|
static constexpr double PITCH_HORIZOFFSPEED = 4.375;
|
2022-12-09 07:00:42 +00:00
|
|
|
static constexpr DAngle PITCH_CNTRSINEOFFSET = DAngle90 / 8.;
|
2022-12-07 02:11:59 +00:00
|
|
|
static constexpr DAngle PITCH_HORIZOFFCLIMB = DAngle::fromDeg(-38.);
|
2022-09-28 02:33:22 +00:00
|
|
|
static constexpr DAngle PITCH_HORIZOFFPUSH = DAngle::fromDeg(0.4476);
|
2023-03-18 08:48:18 +00:00
|
|
|
static InputPacket inputBuffer{};
|
2022-09-27 07:08:01 +00:00
|
|
|
|
|
|
|
|
2022-07-22 04:56:38 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Input scale helper functions.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2022-12-07 05:06:03 +00:00
|
|
|
static inline double getTicrateScale(const double value)
|
2022-07-22 04:56:38 +00:00
|
|
|
{
|
2022-12-07 05:06:03 +00:00
|
|
|
return value / GameTicRate;
|
2022-07-22 04:56:38 +00:00
|
|
|
}
|
|
|
|
|
2022-12-07 05:06:03 +00:00
|
|
|
static inline DAngle getscaledangle(const DAngle angle, const double scale, const DAngle push)
|
2022-07-22 04:56:38 +00:00
|
|
|
{
|
2022-12-07 05:06:03 +00:00
|
|
|
return (angle.Normalized180() * getTicrateScale(scale)) + push;
|
2022-08-28 02:09:44 +00:00
|
|
|
}
|
|
|
|
|
2023-02-04 08:01:01 +00:00
|
|
|
static inline bool scaletozero(DAngle& angle, const double scale, const DAngle push = DAngle::fromDeg(32. / 465.))
|
2022-07-22 04:56:38 +00:00
|
|
|
{
|
2023-03-13 10:33:37 +00:00
|
|
|
const auto sgn = angle.Sgn();
|
2023-02-04 21:27:44 +00:00
|
|
|
|
|
|
|
if (!sgn || sgn != (angle -= getscaledangle(angle, scale, push * sgn)).Sgn())
|
2022-07-22 04:56:38 +00:00
|
|
|
{
|
2023-02-04 21:27:44 +00:00
|
|
|
angle = nullAngle;
|
|
|
|
return true;
|
2022-07-22 04:56:38 +00:00
|
|
|
}
|
2023-02-04 08:01:01 +00:00
|
|
|
return false;
|
2022-07-22 04:56:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-01 22:53:03 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Functions for determining whether its turbo turn time (turn key held for a number of tics).
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static double turnheldtime;
|
|
|
|
|
2023-03-13 10:33:37 +00:00
|
|
|
void updateTurnHeldAmt(const double scaleAdjust)
|
2021-01-01 22:53:03 +00:00
|
|
|
{
|
2022-05-30 11:06:32 +00:00
|
|
|
turnheldtime += getTicrateScale(BUILDTICRATE) * scaleAdjust;
|
2021-01-01 22:53:03 +00:00
|
|
|
}
|
|
|
|
|
2021-10-08 17:06:41 +00:00
|
|
|
bool isTurboTurnTime()
|
2021-01-01 22:53:03 +00:00
|
|
|
{
|
2021-11-06 01:39:19 +00:00
|
|
|
return turnheldtime >= getTicrateScale(TURBOTURNBASE);
|
2021-01-01 22:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void resetTurnHeldAmt()
|
|
|
|
{
|
|
|
|
turnheldtime = 0;
|
|
|
|
}
|
|
|
|
|
2022-06-11 08:36:20 +00:00
|
|
|
|
2020-10-11 14:33:43 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Player's movement function, called from game's ticker or from gi->GetInput() as required.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2023-03-18 10:16:50 +00:00
|
|
|
void processMovement(HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust, const int drink_amt, const bool allowstrafe, const double turnscale)
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2022-09-19 23:54:01 +00:00
|
|
|
// set up variables.
|
2023-03-13 10:33:37 +00:00
|
|
|
const int keymove = 1 << int(!!(inputBuffer->actions & SB_RUN));
|
|
|
|
const float hidspeed = float(getTicrateScale(YAW_TURNSPEEDS[2]) * turnscale);
|
|
|
|
const float scaleAdjustf = float(scaleAdjust);
|
2022-09-19 23:54:01 +00:00
|
|
|
|
|
|
|
// determine player input.
|
2023-03-13 10:33:37 +00:00
|
|
|
const auto turning = buttonMap.ButtonDown(gamefunc_Turn_Right) - buttonMap.ButtonDown(gamefunc_Turn_Left);
|
2023-03-17 09:42:19 +00:00
|
|
|
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;
|
2022-09-19 23:54:01 +00:00
|
|
|
|
|
|
|
// process player angle input.
|
|
|
|
if (!(buttonMap.ButtonDown(gamefunc_Strafe) && allowstrafe))
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2023-03-13 10:33:37 +00:00
|
|
|
const float turndir = clamp(turning + strafing * !allowstrafe, -1.f, 1.f);
|
|
|
|
const float turnspeed = float(getTicrateScale(YAW_TURNSPEEDS[keymove]) * turnscale * (isTurboTurnTime() ? 1. : YAW_PREAMBLESCALE));
|
2023-03-17 09:42:19 +00:00
|
|
|
currInput->avel += hidInput->mouseturnx - (hidInput->joyaxes[JOYAXIS_Yaw] * hidspeed - turndir * turnspeed) * scaleAdjustf;
|
2022-09-19 23:54:01 +00:00
|
|
|
if (turndir) updateTurnHeldAmt(scaleAdjust); else resetTurnHeldAmt();
|
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-03-17 09:42:19 +00:00
|
|
|
currInput->svel += hidInput->mousemovex - (hidInput->joyaxes[JOYAXIS_Yaw] - turning) * keymove * scaleAdjustf;
|
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.
|
|
|
|
if (!(inputBuffer->actions & SB_AIMMODE))
|
2023-03-17 09:42:19 +00:00
|
|
|
currInput->horz += hidInput->mouseturny - hidInput->joyaxes[JOYAXIS_Pitch] * hidspeed * scaleAdjustf;
|
2022-06-11 07:12:56 +00:00
|
|
|
else
|
2023-03-17 09:42:19 +00:00
|
|
|
currInput->fvel -= hidInput->mousemovey - hidInput->joyaxes[JOYAXIS_Pitch] * keymove * scaleAdjustf;
|
2022-09-19 23:54:01 +00:00
|
|
|
|
|
|
|
// process movement input.
|
|
|
|
currInput->fvel += moving * keymove;
|
|
|
|
currInput->svel += strafing * keymove * allowstrafe;
|
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)
|
|
|
|
currInput->svel += drink_amt & 1 ? -currInput->fvel : currInput->fvel;
|
2020-10-11 14:33:43 +00:00
|
|
|
|
|
|
|
// add collected input to game's local input accumulation packet.
|
2022-11-07 08:38:22 +00:00
|
|
|
inputBuffer->fvel = clamp(inputBuffer->fvel + currInput->fvel, -(float)keymove, (float)keymove);
|
|
|
|
inputBuffer->svel = clamp(inputBuffer->svel + currInput->svel, -(float)keymove, (float)keymove);
|
|
|
|
inputBuffer->avel = clamp(inputBuffer->avel + currInput->avel, -179.f, 179.f);
|
|
|
|
inputBuffer->horz = clamp(inputBuffer->horz + currInput->horz, -179.f, 179.f);
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
|
|
|
|
2022-09-27 07:08:01 +00:00
|
|
|
|
2023-03-18 08:48:18 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Processes input and returns a packet if provided.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void clearLocalInputBuffer()
|
|
|
|
{
|
|
|
|
inputBuffer = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
void getInput(const double scaleAdjust, PlayerAngles* const plrAngles, InputPacket* packet)
|
|
|
|
{
|
|
|
|
if (paused || M_Active() || gamestate != GS_LEVEL || !plrAngles || !plrAngles->pActor)
|
|
|
|
{
|
|
|
|
clearLocalInputBuffer();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
InputPacket input{};
|
|
|
|
HIDInput hidInput{};
|
|
|
|
getHidInput(&hidInput);
|
|
|
|
ApplyGlobalInput(&hidInput, &inputBuffer);
|
2023-03-18 10:16:50 +00:00
|
|
|
gi->GetInput(&hidInput, &inputBuffer, &input, !SyncInput() ? scaleAdjust : 1.);
|
2023-03-18 08:48:18 +00:00
|
|
|
|
|
|
|
// Directly update the camera angles if we're unsynchronised.
|
|
|
|
if (!SyncInput())
|
|
|
|
{
|
|
|
|
plrAngles->CameraAngles.Yaw += DAngle::fromDeg(input.avel);
|
|
|
|
plrAngles->CameraAngles.Pitch += DAngle::fromDeg(input.horz);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (packet)
|
|
|
|
{
|
2023-03-22 07:16:32 +00:00
|
|
|
inputBuffer.actions |= gi->GetNeededInputBits();
|
2023-03-18 08:48:18 +00:00
|
|
|
*packet = inputBuffer;
|
|
|
|
clearLocalInputBuffer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-11 14:33:43 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2022-12-09 07:09:59 +00:00
|
|
|
// Adjust player's pitch by way of keyboard input.
|
2020-10-11 14:33:43 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2023-03-13 10:17:53 +00:00
|
|
|
void PlayerAngles::doPitchKeys(InputPacket* const input)
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2022-12-09 07:09:59 +00:00
|
|
|
// Cancel return to center if conditions met.
|
2023-03-13 10:17:53 +00:00
|
|
|
if (input->horz)
|
|
|
|
input->actions &= ~SB_CENTERVIEW;
|
2022-11-30 20:59:13 +00:00
|
|
|
|
|
|
|
// Process keyboard input.
|
2023-03-13 10:17:53 +00:00
|
|
|
if (const auto aiming = !!(input->actions & SB_AIM_DOWN) - !!(input->actions & SB_AIM_UP))
|
2021-04-02 12:23:24 +00:00
|
|
|
{
|
2023-03-13 10:17:53 +00:00
|
|
|
pActor->spr.Angles.Pitch += DAngle::fromDeg(getTicrateScale(PITCH_AIMSPEED) * aiming);
|
|
|
|
input->actions &= ~SB_CENTERVIEW;
|
2021-04-02 12:23:24 +00:00
|
|
|
}
|
2023-03-13 10:17:53 +00:00
|
|
|
if (const auto looking = !!(input->actions & SB_LOOK_DOWN) - !!(input->actions & SB_LOOK_UP))
|
2022-11-30 20:59:13 +00:00
|
|
|
{
|
2023-03-13 10:17:53 +00:00
|
|
|
pActor->spr.Angles.Pitch += DAngle::fromDeg(getTicrateScale(PITCH_LOOKSPEED) * looking);
|
|
|
|
input->actions |= SB_CENTERVIEW;
|
2022-11-30 20:59:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Do return to centre.
|
2023-03-13 10:17:53 +00:00
|
|
|
if ((input->actions & SB_CENTERVIEW) && !(input->actions & (SB_LOOK_UP|SB_LOOK_DOWN)))
|
2022-11-30 20:59:13 +00:00
|
|
|
{
|
2022-12-09 07:09:59 +00:00
|
|
|
const auto pitch = abs(pActor->spr.Angles.Pitch);
|
2022-11-30 20:59:13 +00:00
|
|
|
const auto scale = pitch > PITCH_CNTRSINEOFFSET ? (pitch - PITCH_CNTRSINEOFFSET).Cos() : 1.;
|
2023-02-04 08:01:01 +00:00
|
|
|
if (scaletozero(pActor->spr.Angles.Pitch, PITCH_CENTERSPEED * scale))
|
2023-03-13 10:17:53 +00:00
|
|
|
input->actions &= ~SB_CENTERVIEW;
|
2022-11-30 20:59:13 +00:00
|
|
|
}
|
|
|
|
|
2023-02-04 05:10:38 +00:00
|
|
|
// clamp before we finish, factoring in the player's view pitch offset.
|
|
|
|
const auto maximum = GetMaxPitch() - ViewAngles.Pitch * (ViewAngles.Pitch < nullAngle);
|
|
|
|
const auto minimum = GetMinPitch() - ViewAngles.Pitch * (ViewAngles.Pitch > nullAngle);
|
|
|
|
pActor->spr.Angles.Pitch = clamp(pActor->spr.Angles.Pitch, maximum, minimum);
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
|
|
|
|
2022-06-11 08:36:20 +00:00
|
|
|
|
2020-10-11 14:33:43 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2022-12-09 07:09:59 +00:00
|
|
|
// Adjust player's yaw by way of keyboard input.
|
2020-10-11 14:33:43 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2023-03-13 10:33:37 +00:00
|
|
|
void PlayerAngles::doYawKeys(InputPacket* const input)
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2023-03-13 10:33:37 +00:00
|
|
|
if (input->actions & SB_TURNAROUND)
|
2022-11-30 20:59:13 +00:00
|
|
|
{
|
|
|
|
if (YawSpin == nullAngle)
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2022-11-30 20:59:13 +00:00
|
|
|
// currently not spinning, so start a spin
|
|
|
|
YawSpin = -DAngle180;
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
2023-03-13 10:33:37 +00:00
|
|
|
input->actions &= ~SB_TURNAROUND;
|
2022-11-30 20:59:13 +00:00
|
|
|
}
|
2020-10-11 14:33:43 +00:00
|
|
|
|
2022-11-30 20:59:13 +00:00
|
|
|
if (YawSpin < nullAngle)
|
|
|
|
{
|
|
|
|
// return spin to 0
|
2023-03-13 10:33:37 +00:00
|
|
|
DAngle add = DAngle::fromDeg(getTicrateScale(!(input->actions & SB_CROUCH) ? YAW_SPINSTAND : YAW_SPINCROUCH));
|
2022-11-30 20:59:13 +00:00
|
|
|
YawSpin += add;
|
|
|
|
if (YawSpin > nullAngle)
|
2020-10-11 14:33:43 +00:00
|
|
|
{
|
2022-11-30 20:59:13 +00:00
|
|
|
// Don't overshoot our target. With variable factor this is possible.
|
|
|
|
add -= YawSpin;
|
|
|
|
YawSpin = nullAngle;
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
2022-12-09 07:09:59 +00:00
|
|
|
pActor->spr.Angles.Yaw += add;
|
2020-10-11 14:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-11 08:36:20 +00:00
|
|
|
|
2021-01-01 13:30:01 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Player's slope tilt when playing without a mouse and on a slope.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2023-03-13 10:17:33 +00:00
|
|
|
void PlayerAngles::doViewPitch(const bool canslopetilt, const bool climbing)
|
2021-01-01 13:30:01 +00:00
|
|
|
{
|
2023-03-15 05:36:56 +00:00
|
|
|
if (cl_slopetilting && canslopetilt)
|
2021-01-01 13:30:01 +00:00
|
|
|
{
|
2023-03-13 10:17:33 +00:00
|
|
|
const auto actorsect = pActor->sector();
|
2023-03-15 05:36:56 +00:00
|
|
|
if (actorsect && (actorsect->floorstat & CSTAT_SECTOR_SLOPE)) // If the floor is sloped
|
2021-01-01 13:30:01 +00:00
|
|
|
{
|
2021-01-02 03:40:35 +00:00
|
|
|
// Get a point, 512 (64 for Blood) units ahead of player's position
|
2023-03-13 10:17:33 +00:00
|
|
|
const auto rotpt = pActor->spr.pos.XY() + pActor->spr.Angles.Yaw.ToVector() * (!isBlood() ? 32 : 4);
|
|
|
|
auto tempsect = actorsect;
|
2022-09-27 05:51:42 +00:00
|
|
|
updatesector(rotpt, &tempsect);
|
2021-01-01 13:34:44 +00:00
|
|
|
|
2021-11-24 01:03:53 +00:00
|
|
|
if (tempsect != nullptr) // If the new point is inside a valid sector...
|
2021-01-01 13:30:01 +00:00
|
|
|
{
|
2021-01-01 13:34:44 +00:00
|
|
|
// Get the floorz as if the new (x,y) point was still in
|
2022-12-09 06:48:26 +00:00
|
|
|
// your sector, unless it's Blood.
|
2023-03-13 10:17:33 +00:00
|
|
|
const double j = getflorzofslopeptr(actorsect, pActor->spr.pos.XY());
|
|
|
|
const double k = getflorzofslopeptr(!isBlood() ? actorsect : tempsect, rotpt);
|
2021-01-01 13:34:44 +00:00
|
|
|
|
|
|
|
// If extended point is in same sector as you or the slopes
|
|
|
|
// of the sector of the extended point and your sector match
|
|
|
|
// closely (to avoid accidently looking straight out when
|
|
|
|
// you're at the edge of a sector line) then adjust horizon
|
|
|
|
// accordingly
|
2023-03-13 10:17:33 +00:00
|
|
|
if (actorsect == tempsect || (!isBlood() && abs(getflorzofslopeptr(tempsect, rotpt) - k) <= 4))
|
2021-01-01 13:34:44 +00:00
|
|
|
{
|
2022-11-25 10:18:36 +00:00
|
|
|
ViewAngles.Pitch -= maphoriz((j - k) * (!isBlood() ? 0.625 : 5.5));
|
2021-01-01 13:34:44 +00:00
|
|
|
}
|
2021-01-01 13:30:01 +00:00
|
|
|
}
|
|
|
|
}
|
2023-03-13 10:30:39 +00:00
|
|
|
}
|
2021-01-01 13:30:01 +00:00
|
|
|
|
2023-03-13 10:30:39 +00:00
|
|
|
if (cl_slopetilting && climbing)
|
|
|
|
{
|
|
|
|
// tilt when climbing but you can't even really tell it.
|
|
|
|
if (ViewAngles.Pitch > PITCH_HORIZOFFCLIMB)
|
|
|
|
ViewAngles.Pitch += getscaledangle(deltaangle(ViewAngles.Pitch, PITCH_HORIZOFFCLIMB), PITCH_HORIZOFFSPEED, PITCH_HORIZOFFPUSH);
|
2021-01-01 13:30:01 +00:00
|
|
|
}
|
2023-03-13 10:30:39 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Make horizoff grow towards 0 since horizoff is not modified when you're not on a slope.
|
|
|
|
scaletozero(ViewAngles.Pitch, PITCH_HORIZOFFSPEED, PITCH_HORIZOFFPUSH);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clamp off against the maximum allowed pitch.
|
|
|
|
ViewAngles.Pitch = ClampViewPitch(ViewAngles.Pitch);
|
2021-01-01 13:30:01 +00:00
|
|
|
}
|
|
|
|
|
2022-06-11 08:36:20 +00:00
|
|
|
|
2022-12-09 06:52:52 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Player's look left/right key angle handler.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2023-03-13 10:33:37 +00:00
|
|
|
void PlayerAngles::doViewYaw(InputPacket* const input)
|
2022-12-09 06:52:52 +00:00
|
|
|
{
|
|
|
|
// Process angle return to zeros.
|
|
|
|
scaletozero(ViewAngles.Yaw, YAW_LOOKRETURN);
|
|
|
|
scaletozero(ViewAngles.Roll, YAW_LOOKRETURN);
|
|
|
|
|
|
|
|
// Process keyboard input.
|
2023-03-13 10:33:37 +00:00
|
|
|
if (const auto looking = !!(input->actions & SB_LOOK_RIGHT) - !!(input->actions & SB_LOOK_LEFT))
|
2022-12-09 06:52:52 +00:00
|
|
|
{
|
2023-03-13 10:33:37 +00:00
|
|
|
ViewAngles.Yaw += DAngle::fromDeg(getTicrateScale(YAW_LOOKINGSPEED) * looking);
|
|
|
|
ViewAngles.Roll += DAngle::fromDeg(getTicrateScale(YAW_ROTATESPEED) * looking);
|
2022-12-09 06:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-11 08:36:20 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2022-11-25 06:09:11 +00:00
|
|
|
FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, PlayerAngles* def)
|
2020-10-11 14:55:12 +00:00
|
|
|
{
|
|
|
|
if (arc.BeginObject(keyname))
|
|
|
|
{
|
2022-11-27 03:48:37 +00:00
|
|
|
arc("viewangles", w.ViewAngles)
|
2022-11-25 05:31:44 +00:00
|
|
|
("spin", w.YawSpin)
|
2022-11-27 02:36:55 +00:00
|
|
|
("actor", w.pActor)
|
2020-10-11 14:55:12 +00:00
|
|
|
.EndObject();
|
|
|
|
|
|
|
|
if (arc.isReading())
|
|
|
|
{
|
2023-03-17 03:20:36 +00:00
|
|
|
w.resetCameraAngles();
|
2020-10-11 14:55:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return arc;
|
|
|
|
}
|