- Clean up other PlayerAngles interfaces for consistency.

This commit is contained in:
Mitchell Richters 2023-03-13 21:33:37 +11:00
parent 62561d863e
commit a90665732c
7 changed files with 34 additions and 41 deletions

View file

@ -21,11 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
#include "gamecontrol.h"
#include "gameinput.h" #include "gameinput.h"
#include "gamestruct.h"
#include "serializer.h"
#include "gamefuncs.h"
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// //
@ -73,7 +69,7 @@ static inline DAngle getscaledangle(const DAngle angle, const double scale, cons
static inline bool scaletozero(DAngle& angle, const double scale, const DAngle push = DAngle::fromDeg(32. / 465.)) static inline bool scaletozero(DAngle& angle, const double scale, const DAngle push = DAngle::fromDeg(32. / 465.))
{ {
auto sgn = angle.Sgn(); const auto sgn = angle.Sgn();
if (!sgn || sgn != (angle -= getscaledangle(angle, scale, push * sgn)).Sgn()) if (!sgn || sgn != (angle -= getscaledangle(angle, scale, push * sgn)).Sgn())
{ {
@ -92,7 +88,7 @@ static inline bool scaletozero(DAngle& angle, const double scale, const DAngle p
static double turnheldtime; static double turnheldtime;
void updateTurnHeldAmt(double const scaleAdjust) void updateTurnHeldAmt(const double scaleAdjust)
{ {
turnheldtime += getTicrateScale(BUILDTICRATE) * scaleAdjust; turnheldtime += getTicrateScale(BUILDTICRATE) * scaleAdjust;
} }
@ -114,23 +110,23 @@ void resetTurnHeldAmt()
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void processMovement(InputPacket* const currInput, InputPacket* const inputBuffer, ControlInfo* const hidInput, double const scaleAdjust, int const drink_amt, bool const allowstrafe, double const turnscale) void processMovement(InputPacket* const currInput, InputPacket* const inputBuffer, ControlInfo* const hidInput, const double scaleAdjust, const int drink_amt, const bool allowstrafe, const double turnscale)
{ {
// set up variables. // set up variables.
int const keymove = 1 << int(!!(inputBuffer->actions & SB_RUN)); const int keymove = 1 << int(!!(inputBuffer->actions & SB_RUN));
float const hidspeed = float(getTicrateScale(YAW_TURNSPEEDS[2]) * turnscale); const float hidspeed = float(getTicrateScale(YAW_TURNSPEEDS[2]) * turnscale);
float const scaleAdjustf = float(scaleAdjust); const float scaleAdjustf = float(scaleAdjust);
// determine player input. // determine player input.
auto const turning = buttonMap.ButtonDown(gamefunc_Turn_Right) - buttonMap.ButtonDown(gamefunc_Turn_Left); const auto turning = buttonMap.ButtonDown(gamefunc_Turn_Right) - buttonMap.ButtonDown(gamefunc_Turn_Left);
auto const moving = buttonMap.ButtonDown(gamefunc_Move_Forward) - buttonMap.ButtonDown(gamefunc_Move_Backward) + hidInput->dz * scaleAdjustf; const auto moving = buttonMap.ButtonDown(gamefunc_Move_Forward) - buttonMap.ButtonDown(gamefunc_Move_Backward) + hidInput->dz * scaleAdjustf;
auto const strafing = buttonMap.ButtonDown(gamefunc_Strafe_Right) - buttonMap.ButtonDown(gamefunc_Strafe_Left) - hidInput->dx * scaleAdjustf; const auto strafing = buttonMap.ButtonDown(gamefunc_Strafe_Right) - buttonMap.ButtonDown(gamefunc_Strafe_Left) - hidInput->dx * scaleAdjustf;
// process player angle input. // process player angle input.
if (!(buttonMap.ButtonDown(gamefunc_Strafe) && allowstrafe)) if (!(buttonMap.ButtonDown(gamefunc_Strafe) && allowstrafe))
{ {
float const turndir = clamp(turning + strafing * !allowstrafe, -1.f, 1.f); const float turndir = clamp(turning + strafing * !allowstrafe, -1.f, 1.f);
float const 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->dyaw * hidspeed + turndir * turnspeed) * scaleAdjustf;
if (turndir) updateTurnHeldAmt(scaleAdjust); else resetTurnHeldAmt(); if (turndir) updateTurnHeldAmt(scaleAdjust); else resetTurnHeldAmt();
} }
@ -207,22 +203,22 @@ void PlayerAngles::doPitchKeys(InputPacket* const input)
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void PlayerAngles::doYawKeys(ESyncBits* actions) void PlayerAngles::doYawKeys(InputPacket* const input)
{ {
if (*actions & SB_TURNAROUND) if (input->actions & SB_TURNAROUND)
{ {
if (YawSpin == nullAngle) if (YawSpin == nullAngle)
{ {
// currently not spinning, so start a spin // currently not spinning, so start a spin
YawSpin = -DAngle180; YawSpin = -DAngle180;
} }
*actions &= ~SB_TURNAROUND; input->actions &= ~SB_TURNAROUND;
} }
if (YawSpin < nullAngle) if (YawSpin < nullAngle)
{ {
// return spin to 0 // return spin to 0
DAngle add = DAngle::fromDeg(getTicrateScale(!(*actions & SB_CROUCH) ? YAW_SPINSTAND : YAW_SPINCROUCH)); DAngle add = DAngle::fromDeg(getTicrateScale(!(input->actions & SB_CROUCH) ? YAW_SPINSTAND : YAW_SPINCROUCH));
YawSpin += add; YawSpin += add;
if (YawSpin > nullAngle) if (YawSpin > nullAngle)
{ {
@ -296,17 +292,17 @@ void PlayerAngles::doViewPitch(const bool canslopetilt, const bool climbing)
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void PlayerAngles::doViewYaw(const ESyncBits actions) void PlayerAngles::doViewYaw(InputPacket* const input)
{ {
// Process angle return to zeros. // Process angle return to zeros.
scaletozero(ViewAngles.Yaw, YAW_LOOKRETURN); scaletozero(ViewAngles.Yaw, YAW_LOOKRETURN);
scaletozero(ViewAngles.Roll, YAW_LOOKRETURN); scaletozero(ViewAngles.Roll, YAW_LOOKRETURN);
// Process keyboard input. // Process keyboard input.
if (auto looking = !!(actions & SB_LOOK_RIGHT) - !!(actions & SB_LOOK_LEFT)) if (const auto looking = !!(input->actions & SB_LOOK_RIGHT) - !!(input->actions & SB_LOOK_LEFT))
{ {
ViewAngles.Yaw += DAngle::fromDeg(getTicrateScale(YAW_LOOKINGSPEED)) * looking; ViewAngles.Yaw += DAngle::fromDeg(getTicrateScale(YAW_LOOKINGSPEED) * looking);
ViewAngles.Roll += DAngle::fromDeg(getTicrateScale(YAW_ROTATESPEED)) * looking; ViewAngles.Roll += DAngle::fromDeg(getTicrateScale(YAW_ROTATESPEED) * looking);
} }
} }

View file

@ -1,10 +1,7 @@
#pragma once #pragma once
#include "m_fixed.h" #include "serializer.h"
#include "gamecvars.h"
#include "gamestruct.h"
#include "gamefuncs.h" #include "gamefuncs.h"
#include "packet.h"
struct PlayerAngles struct PlayerAngles
{ {
@ -21,9 +18,9 @@ struct PlayerAngles
// Prototypes. // Prototypes.
void doPitchKeys(InputPacket* const input); void doPitchKeys(InputPacket* const input);
void doYawKeys(ESyncBits* actions); void doYawKeys(InputPacket* const input);
void doViewPitch(const bool canslopetilt, const bool climbing = false); void doViewPitch(const bool canslopetilt, const bool climbing = false);
void doViewYaw(const ESyncBits actions); void doViewYaw(InputPacket* const input);
// General methods. // General methods.
void initialize(DCoreActor* const actor, const DAngle viewyaw = nullAngle) void initialize(DCoreActor* const actor, const DAngle viewyaw = nullAngle)
@ -83,7 +80,7 @@ class FSerializer;
FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, PlayerAngles* def); FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, PlayerAngles* def);
void updateTurnHeldAmt(double const scaleAdjust); void updateTurnHeldAmt(const double scaleAdjust);
bool isTurboTurnTime(); bool isTurboTurnTime();
void resetTurnHeldAmt(); void resetTurnHeldAmt();
void processMovement(InputPacket* const currInput, InputPacket* const inputBuffer, ControlInfo* const hidInput, double const scaleAdjust, int const drink_amt = 0, bool const allowstrafe = true, double const turnscale = 1); void processMovement(InputPacket* const currInput, InputPacket* const inputBuffer, ControlInfo* const hidInput, const double scaleAdjust, const int drink_amt = 0, const bool allowstrafe = true, const double turnscale = 1);

View file

@ -1569,14 +1569,14 @@ void ProcessInput(PLAYER* pPlayer)
actor->vel.XY() += DVector2(pInput->fvel * fvAccel, pInput->svel * svAccel).Rotated(actor->spr.Angles.Yaw) * speed; actor->vel.XY() += DVector2(pInput->fvel * fvAccel, pInput->svel * svAccel).Rotated(actor->spr.Angles.Yaw) * speed;
} }
pPlayer->Angles.doViewYaw(pInput->actions); pPlayer->Angles.doViewYaw(pInput);
if (SyncInput()) if (SyncInput())
{ {
pPlayer->actor->spr.Angles.Yaw += DAngle::fromDeg(pInput->avel); pPlayer->actor->spr.Angles.Yaw += DAngle::fromDeg(pInput->avel);
} }
pPlayer->Angles.doYawKeys(&pInput->actions); pPlayer->Angles.doYawKeys(pInput);
if (!(pInput->actions & SB_JUMP)) if (!(pInput->actions & SB_JUMP))
pPlayer->cantJump = 0; pPlayer->cantJump = 0;

View file

@ -2756,7 +2756,7 @@ void processinput_d(int snum)
p->psectlotag = psectlotag; p->psectlotag = psectlotag;
//Do the quick lefts and rights //Do the quick lefts and rights
p->Angles.doViewYaw(actions); p->Angles.doViewYaw(&p->sync);
if (movementBlocked(p)) if (movementBlocked(p))
{ {
@ -2773,7 +2773,7 @@ void processinput_d(int snum)
p->GetActor()->spr.Angles.Yaw += p->adjustavel(PlayerInputAngVel(snum)); p->GetActor()->spr.Angles.Yaw += p->adjustavel(PlayerInputAngVel(snum));
} }
p->Angles.doYawKeys(&actions); p->Angles.doYawKeys(&p->sync);
purplelavacheck(p); purplelavacheck(p);
if (p->spritebridge == 0 && pact->insector()) if (p->spritebridge == 0 && pact->insector())

View file

@ -3442,7 +3442,7 @@ void processinput_r(int snum)
p->psectlotag = psectlotag; p->psectlotag = psectlotag;
//Do the quick lefts and rights //Do the quick lefts and rights
p->Angles.doViewYaw(actions); p->Angles.doViewYaw(&p->sync);
if (movementBlocked(p)) if (movementBlocked(p))
{ {
@ -3459,7 +3459,7 @@ void processinput_r(int snum)
p->GetActor()->spr.Angles.Yaw += p->adjustavel(PlayerInputAngVel(snum)); p->GetActor()->spr.Angles.Yaw += p->adjustavel(PlayerInputAngVel(snum));
} }
p->Angles.doYawKeys(&actions); p->Angles.doYawKeys(&p->sync);
purplelavacheck(p); purplelavacheck(p);
if (p->spritebridge == 0 && pact->insector()) if (p->spritebridge == 0 && pact->insector())

View file

@ -976,7 +976,7 @@ void AIPlayer::Tick(RunListEvent* ev)
} }
} }
PlayerList[nPlayer].Angles.doViewYaw(sPlayerInput[nLocalPlayer].actions); PlayerList[nPlayer].Angles.doViewYaw(&PlayerList[nLocalPlayer].input);
// loc_1A494: // loc_1A494:
if (SyncInput()) if (SyncInput())
@ -984,7 +984,7 @@ void AIPlayer::Tick(RunListEvent* ev)
PlayerList[nPlayer].pActor->spr.Angles.Yaw += DAngle::fromDeg(PlayerList[nPlayer].input.avel); PlayerList[nPlayer].pActor->spr.Angles.Yaw += DAngle::fromDeg(PlayerList[nPlayer].input.avel);
} }
PlayerList[nPlayer].Angles.doYawKeys(&sPlayerInput[nLocalPlayer].actions); PlayerList[nPlayer].Angles.doYawKeys(&PlayerList[nLocalPlayer].input);
UpdatePlayerSpriteAngle(&PlayerList[nPlayer]); UpdatePlayerSpriteAngle(&PlayerList[nPlayer]);
// player.zvel is modified within Gravity() // player.zvel is modified within Gravity()

View file

@ -2024,7 +2024,7 @@ void DoPlayerMove(PLAYER* pp)
SlipSlope(pp); SlipSlope(pp);
pp->Angles.doViewYaw(pp->input.actions); pp->Angles.doViewYaw(&pp->input);
if (!SyncInput()) if (!SyncInput())
{ {
@ -2035,7 +2035,7 @@ void DoPlayerMove(PLAYER* pp)
pp->actor->spr.Angles.Yaw += DAngle::fromDeg(pp->input.avel); pp->actor->spr.Angles.Yaw += DAngle::fromDeg(pp->input.avel);
} }
pp->Angles.doYawKeys(&pp->input.actions); pp->Angles.doYawKeys(&pp->input);
UpdatePlayerSpriteAngle(pp); UpdatePlayerSpriteAngle(pp);
pp->lastcursector = pp->cursector; pp->lastcursector = pp->cursector;