From e8451d3ddb706f5ce665980d1b44298a09a475eb Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Tue, 3 Oct 2023 20:58:38 +1100 Subject: [PATCH] - Take better advantage of `InputPacket::ang`'s `FRotator` status. * Change it to a DRotator as that's what the game is expecting. Too many narrowings against DAngle objects needed. * Utilise object methods where possible. * Do all math against the object where possible, not its members. --- source/common/utility/vectors.h | 81 +++++++++++++++++++++++------- source/core/d_net.cpp | 16 ++---- source/core/d_protocol.cpp | 29 ++++------- source/core/gameinput.cpp | 56 ++++++++++----------- source/core/gameinput.h | 13 ++--- source/core/gamestruct.h | 2 +- source/core/packet.h | 2 +- source/games/blood/src/blood.h | 2 +- source/games/blood/src/player.cpp | 3 +- source/games/duke/src/duke3d.h | 2 +- source/games/duke/src/input.cpp | 12 ++--- source/games/duke/src/player.cpp | 2 +- source/games/duke/src/player_d.cpp | 2 +- source/games/duke/src/player_r.cpp | 4 +- source/games/duke/src/types.h | 2 +- source/games/exhumed/src/exhumed.h | 2 +- source/games/exhumed/src/gun.cpp | 2 +- source/games/sw/src/game.h | 4 +- source/games/sw/src/player.cpp | 30 +++++------ 19 files changed, 144 insertions(+), 122 deletions(-) diff --git a/source/common/utility/vectors.h b/source/common/utility/vectors.h index 608705ef9..192eb90a8 100644 --- a/source/common/utility/vectors.h +++ b/source/common/utility/vectors.h @@ -1457,6 +1457,24 @@ public: } }; +typedef TAngle FAngle; +typedef TAngle DAngle; + +constexpr DAngle nullAngle = DAngle::fromDeg(0.); +constexpr FAngle nullFAngle = FAngle::fromDeg(0.); +constexpr DAngle minAngle = DAngle::fromDeg(1. / 65536.); +constexpr FAngle minFAngle = FAngle::fromDeg(1. / 65536.); + +constexpr DAngle DAngle1 = DAngle::fromDeg(1); +constexpr DAngle DAngle15 = DAngle::fromDeg(15); +constexpr DAngle DAngle22_5 = DAngle::fromDeg(22.5); +constexpr DAngle DAngle45 = DAngle::fromDeg(45); +constexpr DAngle DAngle60 = DAngle::fromDeg(60); +constexpr DAngle DAngle90 = DAngle::fromDeg(90); +constexpr DAngle DAngle180 = DAngle::fromDeg(180); +constexpr DAngle DAngle270 = DAngle::fromDeg(270); +constexpr DAngle DAngle360 = DAngle::fromDeg(360); + template inline TAngle fabs (const TAngle °) { @@ -1528,6 +1546,12 @@ inline TVector3 clamp(const TVector3 &vec, const TVector3 &min, const T return TVector3(clamp(vec.X, min.X, max.X), clamp(vec.Y, min.Y, max.Y), clamp(vec.Z, min.Z, max.Z)); } +template +inline TRotator clamp(const TRotator &rot, const TRotator &min, const TRotator &max) +{ + return TRotator(clamp(rot.Pitch, min.Pitch, max.Pitch), clamp(rot.Yaw, min.Yaw, max.Yaw), clamp(rot.Roll, min.Roll, max.Roll)); +} + template inline TAngle interpolatedvalue(const TAngle &oang, const TAngle &ang, const double interpfrac) { @@ -1570,6 +1594,16 @@ struct TRotator TRotator(const TRotator &other) = default; TRotator &operator= (const TRotator &other) = default; + void Zero() + { + Roll = Yaw = Pitch = nullAngle; + } + + bool isZero() const + { + return Pitch == nullAngle && Yaw == nullAngle && Roll == nullAngle; + } + // Access angles as an array Angle &operator[] (int index) { @@ -1584,13 +1618,27 @@ struct TRotator // Test for equality bool operator== (const TRotator &other) const { - return fabs(Pitch - other.Pitch) < Angle(EQUAL_EPSILON) && fabs(Yaw - other.Yaw) < Angle(EQUAL_EPSILON) && fabs(Roll - other.Roll) < Angle(EQUAL_EPSILON); + return Pitch == other.Pitch && Yaw == other.Yaw && Roll == other.Roll; } // Test for inequality bool operator!= (const TRotator &other) const { - return fabs(Pitch - other.Pitch) >= Angle(EQUAL_EPSILON) && fabs(Yaw - other.Yaw) >= Angle(EQUAL_EPSILON) && fabs(Roll - other.Roll) >= Angle(EQUAL_EPSILON); + return Pitch != other.Pitch || Yaw != other.Yaw || Roll != other.Roll; + } + + // Test for approximate equality + bool ApproximatelyEquals (const TRotator &other) const + { + constexpr auto epsilon = Angle(EQUAL_EPSILON); + return fabs(Pitch - other.Pitch) < epsilon && fabs(Yaw - other.Yaw) < epsilon && fabs(Roll - other.Roll) < epsilon; + } + + // Test for approximate inequality + bool DoesNotApproximatelyEqual (const TRotator &other) const + { + constexpr auto epsilon = Angle(EQUAL_EPSILON); + return fabs(Pitch - other.Pitch) >= epsilon && fabs(Yaw - other.Yaw) >= epsilon && fabs(Roll - other.Roll) >= epsilon; } // Unary negation @@ -1653,12 +1701,25 @@ struct TRotator return *this; } + TRotator &operator/= (const vec_t &scalar) + { + const auto mul = 1. / scalar; + Pitch *= mul, Yaw *= mul, Roll *= mul; + return *this; + } + TRotator operator/ (const Angle &scalar) const { Angle mul(1 / scalar.Degrees_); return TRotator(Pitch * mul, Yaw * mul, Roll * mul); } + TRotator operator/ (const vec_t &scalar) const + { + const auto mul = 1. / scalar; + return TRotator(Pitch * mul, Yaw * mul, Roll * mul); + } + // Vector addition TRotator &operator+= (const TRotator &other) { @@ -1719,28 +1780,12 @@ typedef TVector3 FVector3; typedef TVector4 FVector4; typedef TRotator FRotator; typedef TMatrix3x3 FMatrix3x3; -typedef TAngle FAngle; typedef TVector2 DVector2; typedef TVector3 DVector3; typedef TVector4 DVector4; typedef TRotator DRotator; typedef TMatrix3x3 DMatrix3x3; -typedef TAngle DAngle; - -constexpr DAngle nullAngle = DAngle::fromDeg(0.); -constexpr DAngle minAngle = DAngle::fromDeg(1. / 65536.); -constexpr FAngle nullFAngle = FAngle::fromDeg(0.); - -constexpr DAngle DAngle1 = DAngle::fromDeg(1); -constexpr DAngle DAngle15 = DAngle::fromDeg(15); -constexpr DAngle DAngle22_5 = DAngle::fromDeg(22.5); -constexpr DAngle DAngle45 = DAngle::fromDeg(45); -constexpr DAngle DAngle60 = DAngle::fromDeg(60); -constexpr DAngle DAngle90 = DAngle::fromDeg(90); -constexpr DAngle DAngle180 = DAngle::fromDeg(180); -constexpr DAngle DAngle270 = DAngle::fromDeg(270); -constexpr DAngle DAngle360 = DAngle::fromDeg(360); class Plane { diff --git a/source/core/d_net.cpp b/source/core/d_net.cpp index 82411b449..88024e7e6 100644 --- a/source/core/d_net.cpp +++ b/source/core/d_net.cpp @@ -1033,31 +1033,23 @@ void NetUpdate (void) int modp, tic; DVector3 vel{}; - float avel = 0; - float horz = 0; - float roll = 0; + DRotator ang{}; for (tic = 0; tic < ticdup; ++tic) { modp = (mod + tic) % LOCALCMDTICS; vel += localcmds[modp].ucmd.vel; - avel += localcmds[modp].ucmd.ang.Yaw.Degrees(); - horz += localcmds[modp].ucmd.ang.Pitch.Degrees(); - roll += localcmds[modp].ucmd.ang.Roll.Degrees(); + ang += localcmds[modp].ucmd.ang; } vel /= ticdup; - avel /= ticdup; - horz /= ticdup; - roll /= ticdup; + ang /= ticdup; for (tic = 0; tic < ticdup; ++tic) { modp = (mod + tic) % LOCALCMDTICS; localcmds[modp].ucmd.vel = vel; - localcmds[modp].ucmd.ang.Yaw = FAngle::fromDeg(avel); - localcmds[modp].ucmd.ang.Pitch = FAngle::fromDeg(horz); - localcmds[modp].ucmd.ang.Roll = FAngle::fromDeg(roll); + localcmds[modp].ucmd.ang = ang; } Net_NewMakeTic (); diff --git a/source/core/d_protocol.cpp b/source/core/d_protocol.cpp index 2fb3d27a2..e99ed4e86 100644 --- a/source/core/d_protocol.cpp +++ b/source/core/d_protocol.cpp @@ -160,9 +160,9 @@ int UnpackUserCmd (InputPacket *ucmd, const InputPacket *basis, uint8_t **stream if (flags & UCMDF_BUTTONS) ucmd->actions = ESyncBits::FromInt(ReadLong(stream)); if (flags & UCMDF_PITCH) - ucmd->ang.Pitch = FAngle::fromDeg(ReadFloat(stream)); + ucmd->ang.Pitch = DAngle::fromDeg(ReadFloat(stream)); if (flags & UCMDF_YAW) - ucmd->ang.Yaw = FAngle::fromDeg(ReadFloat(stream)); + ucmd->ang.Yaw = DAngle::fromDeg(ReadFloat(stream)); if (flags & UCMDF_FORWARDMOVE) ucmd->vel.X = ReadFloat(stream); if (flags & UCMDF_SIDEMOVE) @@ -170,7 +170,7 @@ int UnpackUserCmd (InputPacket *ucmd, const InputPacket *basis, uint8_t **stream if (flags & UCMDF_UPMOVE) ucmd->vel.Z = ReadFloat(stream); if (flags & UCMDF_ROLL) - ucmd->ang.Roll = FAngle::fromDeg(ReadFloat(stream)); + ucmd->ang.Roll = DAngle::fromDeg(ReadFloat(stream)); } return int(*stream - start); @@ -200,12 +200,12 @@ int PackUserCmd (const InputPacket *ucmd, const InputPacket *basis, uint8_t **st if (ucmd->ang.Pitch != basis->ang.Pitch) { flags |= UCMDF_PITCH; - WriteFloat (ucmd->ang.Pitch.Degrees(), stream); + WriteFloat ((float)ucmd->ang.Pitch.Degrees(), stream); } if (ucmd->ang.Yaw != basis->ang.Yaw) { flags |= UCMDF_YAW; - WriteFloat (ucmd->ang.Yaw.Degrees(), stream); + WriteFloat ((float)ucmd->ang.Yaw.Degrees(), stream); } if (ucmd->vel.X != basis->vel.X) { @@ -225,7 +225,7 @@ int PackUserCmd (const InputPacket *ucmd, const InputPacket *basis, uint8_t **st if (ucmd->ang.Roll != basis->ang.Roll) { flags |= UCMDF_ROLL; - WriteFloat (ucmd->ang.Roll.Degrees(), stream); + WriteFloat ((float)ucmd->ang.Roll.Degrees(), stream); } // Write the packing bits @@ -250,10 +250,8 @@ FSerializer &Serialize(FSerializer &arc, const char *key, InputPacket &cmd, Inpu if (arc.BeginObject(key)) { arc("actions", cmd.actions) - ("horz", cmd.ang.Pitch) - ("avel", cmd.ang.Yaw) ("vel", cmd.vel) - ("roll", cmd.ang.Roll) + ("ang", cmd.ang) .EndObject(); } return arc; @@ -263,22 +261,13 @@ int WriteUserCmdMessage (InputPacket *ucmd, const InputPacket *basis, uint8_t ** { if (basis == NULL) { - if (ucmd->actions != 0 || - ucmd->ang.Pitch.Degrees() != 0 || - ucmd->ang.Yaw.Degrees() != 0 || - !ucmd->vel.isZero() || - ucmd->ang.Roll.Degrees() != 0) + if (ucmd->actions != 0 || !ucmd->vel.isZero() || !ucmd->ang.isZero()) { WriteByte (DEM_USERCMD, stream); return PackUserCmd (ucmd, basis, stream) + 1; } } - else - if (ucmd->actions != basis->actions || - ucmd->ang.Pitch != basis->ang.Pitch || - ucmd->ang.Yaw != basis->ang.Yaw || - ucmd->vel != basis->vel || - ucmd->ang.Roll != basis->ang.Roll) + else if (ucmd->actions != basis->actions || ucmd->vel != basis->vel || ucmd->ang != basis->ang) { WriteByte (DEM_USERCMD, stream); return PackUserCmd (ucmd, basis, stream) + 1; diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index ba26c20f8..f28ab3809 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -100,12 +100,12 @@ void GameInput::resetCrouchToggle() // //--------------------------------------------------------------------------- -void GameInput::processMovement(PlayerAngles* const plrAngles, const float scaleAdjust, const int drink_amt, const bool allowstrafe, const float turnscale) +void GameInput::processMovement(PlayerAngles* const plrAngles, const double scaleAdjust, const int drink_amt, const bool allowstrafe, const double turnscale) { // set up variables. InputPacket thisInput{}; const auto keymove = 1 << int(!!(inputBuffer.actions & SB_RUN)); - const auto hidspeed = float(getTicrateScale(YAW_TURNSPEEDS[2])); + const auto hidspeed = DAngle::fromDeg(getTicrateScale(YAW_TURNSPEEDS[2])); // get all input amounts. const auto turning = buttonMap.ButtonDown(gamefunc_Turn_Right) - @@ -126,18 +126,18 @@ void GameInput::processMovement(PlayerAngles* const plrAngles, const float scale // process player yaw input. if (!(buttonMap.ButtonDown(gamefunc_Strafe) && allowstrafe)) { - const float turndir = clamp(turning + strafing * !allowstrafe, -1.f, 1.f); - const float tttscale = 1.f / (!(cl_noturnscaling || isTurboTurnTime()) * 2.8f + 1.f); - const float turnspeed = float(getTicrateScale(YAW_TURNSPEEDS[keymove]) * tttscale); - thisInput.ang.Yaw += FAngle::fromDeg(mouseInput.X * MOUSE_SCALE * m_yaw); - thisInput.ang.Yaw -= FAngle::fromDeg(joyAxes[JOYAXIS_Yaw] * hidspeed * scaleAdjust); - thisInput.ang.Yaw += FAngle::fromDeg(turndir * turnspeed * scaleAdjust); + const double turndir = clamp(turning + strafing * !allowstrafe, -1., 1.); + const double tttscale = 1. / (1 + !(cl_noturnscaling || isTurboTurnTime()) * 2.8); + const DAngle turnspeed = DAngle::fromDeg(getTicrateScale(YAW_TURNSPEEDS[keymove]) * tttscale); + thisInput.ang.Yaw += MOUSE_SCALE * mouseInput.X * m_yaw; + thisInput.ang.Yaw -= hidspeed * joyAxes[JOYAXIS_Yaw] * scaleAdjust; + thisInput.ang.Yaw += turnspeed * turndir * scaleAdjust; thisInput.ang.Yaw *= turnscale; if (turndir) updateTurnHeldAmt(scaleAdjust); else turnheldtime = 0; } else { - thisInput.vel.Y += mouseInput.X * MOUSE_SCALE * m_side; + thisInput.vel.Y += mouseInput.X * MOUSE_SCALE.Degrees() * m_side; thisInput.vel.Y -= joyAxes[JOYAXIS_Yaw] * keymove * scaleAdjust; thisInput.vel.Y += turning * keymove * scaleAdjust; } @@ -145,13 +145,13 @@ void GameInput::processMovement(PlayerAngles* const plrAngles, const float scale // process player pitch input. if (!(inputBuffer.actions & SB_AIMMODE)) { - thisInput.ang.Pitch -= FAngle::fromDeg(mouseInput.Y * MOUSE_SCALE * m_pitch); - thisInput.ang.Pitch -= FAngle::fromDeg(joyAxes[JOYAXIS_Pitch] * hidspeed * scaleAdjust); + thisInput.ang.Pitch -= MOUSE_SCALE * mouseInput.Y * m_pitch; + thisInput.ang.Pitch -= hidspeed * joyAxes[JOYAXIS_Pitch] * scaleAdjust; thisInput.ang.Pitch *= turnscale; } else { - thisInput.vel.X += mouseInput.Y * MOUSE_SCALE * m_forward; + thisInput.vel.X += mouseInput.Y * MOUSE_SCALE.Degrees() * m_forward; thisInput.vel.X += joyAxes[JOYAXIS_Pitch] * keymove * scaleAdjust; } @@ -168,18 +168,16 @@ void GameInput::processMovement(PlayerAngles* const plrAngles, const float scale // add collected input to game's local input accumulation packet. const DVector3 maxVel{ (double)keymove, (double)keymove, 1. }; + const DRotator maxAng{ MAXANG, MAXANG, MAXANG }; inputBuffer.vel.X = clamp(inputBuffer.vel.X + thisInput.vel.X, -(double)keymove, (double)keymove); inputBuffer.vel.Y = clamp(inputBuffer.vel.Y + thisInput.vel.Y, -(double)keymove, (double)keymove); inputBuffer.vel.Z = clamp(inputBuffer.vel.Z + thisInput.vel.Z, -1., 1.); - inputBuffer.ang.Yaw = clamp(inputBuffer.ang.Yaw + thisInput.ang.Yaw, FAngle::fromDeg(-179.f), FAngle::fromDeg(179.f)); - inputBuffer.ang.Pitch = clamp(inputBuffer.ang.Pitch + thisInput.ang.Pitch, FAngle::fromDeg(-179.f), FAngle::fromDeg(179.f)); + inputBuffer.ang = clamp(inputBuffer.ang + thisInput.ang, -maxAng, maxAng); // directly update player angles if we can. if (scaleAdjust < 1) { - plrAngles->CameraAngles.Yaw += DAngle::fromDeg(thisInput.ang.Yaw.Degrees()); - plrAngles->CameraAngles.Roll += DAngle::fromDeg(thisInput.ang.Roll.Degrees()); - plrAngles->CameraAngles.Pitch += DAngle::fromDeg(thisInput.ang.Pitch.Degrees()); + plrAngles->CameraAngles += thisInput.ang; } } @@ -190,7 +188,7 @@ void GameInput::processMovement(PlayerAngles* const plrAngles, const float scale // //--------------------------------------------------------------------------- -void GameInput::processVehicle(PlayerAngles* const plrAngles, const float scaleAdjust, const float baseVel, const float velScale, const unsigned flags) +void GameInput::processVehicle(PlayerAngles* const plrAngles, const double scaleAdjust, const double baseVel, const double velScale, const unsigned flags) { // open up input packet for this session. InputPacket thisInput{}; @@ -226,12 +224,12 @@ void GameInput::processVehicle(PlayerAngles* const plrAngles, const float scaleA const auto scaleVel = !(flags & VEH_SCALETURN) && (cl_noturnscaling || hidDir || isTurboTurnTime()); const auto turnVel = scaleVel ? baseVel : baseVel * velScale; const auto mouseVel = abs(turnVel * mouseInput.X * m_yaw) * (45.f / 2048.f) / scaleAdjust; - const auto maxVel = FAngle::fromDeg(abs(turnVel * 1.5f)); + const auto maxVel = DAngle::fromDeg(abs(turnVel * 1.5f)); // Apply inputs. - thisInput.ang.Yaw += FAngle::fromDeg(((mouseVel > 1) ? sqrtf(mouseVel) : mouseVel) * Sgn(turnVel) * Sgn(mouseInput.X) * Sgn(m_yaw)); - thisInput.ang.Yaw -= FAngle::fromDeg(turnVel * joyAxes[JOYAXIS_Yaw]); - thisInput.ang.Yaw += FAngle::fromDeg(turnVel * kbdDir); + thisInput.ang.Yaw += DAngle::fromDeg(((mouseVel > 1) ? sqrt(mouseVel) : mouseVel) * Sgn(turnVel) * Sgn(mouseInput.X) * Sgn(m_yaw)); + thisInput.ang.Yaw -= DAngle::fromDeg(turnVel * joyAxes[JOYAXIS_Yaw]); + thisInput.ang.Yaw += DAngle::fromDeg(turnVel * kbdDir); thisInput.ang.Yaw *= scaleAdjust; inputBuffer.ang.Yaw = clamp(inputBuffer.ang.Yaw + thisInput.ang.Yaw, -maxVel, maxVel); if (kbdDir) updateTurnHeldAmt(scaleAdjust); else turnheldtime = 0; @@ -244,9 +242,7 @@ void GameInput::processVehicle(PlayerAngles* const plrAngles, const float scaleA // directly update player angles if we can. if (scaleAdjust < 1) { - plrAngles->CameraAngles.Yaw += DAngle::fromDeg(thisInput.ang.Yaw.Degrees()); - plrAngles->CameraAngles.Roll += DAngle::fromDeg(thisInput.ang.Roll.Degrees()); - plrAngles->CameraAngles.Pitch += DAngle::fromDeg(thisInput.ang.Pitch.Degrees()); + plrAngles->CameraAngles += thisInput.ang; } } @@ -368,7 +364,7 @@ void GameInput::getInput(const double scaleAdjust, InputPacket* packet) I_GetAxes(joyAxes); processInputBits(); - gi->doPlayerMovement(!SyncInput() ? (float)scaleAdjust : 1.f); + gi->doPlayerMovement(!SyncInput() ? scaleAdjust : 1.); mouseInput.Zero(); if (packet) @@ -390,7 +386,7 @@ void PlayerAngles::doPitchInput(InputPacket* const input) // Add player's mouse/device input. if (input->ang.Pitch.Degrees()) { - pActor->spr.Angles.Pitch += DAngle::fromDeg(input->ang.Pitch.Degrees() * SyncInput()); + pActor->spr.Angles.Pitch += input->ang.Pitch * SyncInput(); input->actions &= ~SB_CENTERVIEW; } @@ -437,7 +433,7 @@ void PlayerAngles::doPitchInput(InputPacket* const input) void PlayerAngles::doYawInput(InputPacket* const input) { // Add player's mouse/device input. - pActor->spr.Angles.Yaw += DAngle::fromDeg(input->ang.Yaw.Degrees() * SyncInput()); + pActor->spr.Angles.Yaw += input->ang.Yaw * SyncInput(); if (input->actions & SB_TURNAROUND) { @@ -560,7 +556,7 @@ void PlayerAngles::doRollInput(InputPacket* const input, const DVector2& nVelVec if (cl_viewtilting == 1) { // Console-like yaw rolling. Adjustment == ~(90/32) for keyboard turning. Clamp is 1.5x this value. - const auto rollAdj = DAngle::fromDeg(input->ang.Yaw.Degrees() * ROLL_TILTAVELSCALE * rollAmp); + const auto rollAdj = input->ang.Yaw * ROLL_TILTAVELSCALE * rollAmp; const auto rollMax = DAngle::fromDeg((90. / 32. * 1.5) * cl_viewtiltscale); scaletozero(pActor->spr.Angles.Roll, ROLL_TILTRETURN); pActor->spr.Angles.Roll = clamp(pActor->spr.Angles.Roll + rollAdj, -rollMax, rollMax); @@ -588,7 +584,7 @@ void PlayerAngles::doRollInput(InputPacket* const input, const DVector2& nVelVec else { // Add player's device input. - pActor->spr.Angles.Roll += DAngle::fromDeg(input->ang.Roll.Degrees() * SyncInput()); + pActor->spr.Angles.Roll += input->ang.Roll * SyncInput(); } } diff --git a/source/core/gameinput.h b/source/core/gameinput.h index e4caa5934..3339dc6be 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -30,7 +30,8 @@ class GameInput }; static constexpr double YAW_TURNSPEEDS[3] = { 234.375 * (360. / 2048.), 890.625 * (360. / 2048.), 1548.75 * (360. / 2048.) }; - static constexpr float MOUSE_SCALE = (1.f / 16.f); + static constexpr DAngle MOUSE_SCALE = DAngle::fromDeg(1. / 16.); + static constexpr DAngle MAXANG = DAngle180 - minAngle; // Input received from the OS. float joyAxes[NUM_JOYAXIS]; @@ -44,7 +45,7 @@ class GameInput ESyncBits ActionsToSend; // Turn speed doubling after x amount of tics. - void updateTurnHeldAmt(const float scaleAdjust) + void updateTurnHeldAmt(const double scaleAdjust) { turnheldtime += getTicrateScale(BUILDTICRATE) * scaleAdjust; } @@ -81,8 +82,8 @@ public: } // Prototypes for large member functions. - void processMovement(PlayerAngles* const plrAngles, const float scaleAdjust, const int drink_amt = 0, const bool allowstrafe = true, const float turnscale = 1.f); - void processVehicle(PlayerAngles* const plrAngles, const float scaleAdjust, const float baseVel, const float velScale, const unsigned flags); + void processMovement(PlayerAngles* const plrAngles, const double scaleAdjust, const int drink_amt = 0, const bool allowstrafe = true, const double turnscale = 1.); + void processVehicle(PlayerAngles* const plrAngles, const double scaleAdjust, const double baseVel, const double velScale, const unsigned flags); void getInput(const double scaleAdjust, InputPacket* packet = nullptr); void resetCrouchToggle(); }; @@ -99,8 +100,8 @@ struct PlayerAngles DAngle YawSpin; friend FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngles& w, PlayerAngles* def); - friend void GameInput::processMovement(PlayerAngles* const plrAngles, const float scaleAdjust, const int drink_amt, const bool allowstrafe, const float turnscale); - friend void GameInput::processVehicle(PlayerAngles* const plrAngles, const float scaleAdjust, const float baseVel, const float velScale, const unsigned flags); + friend void GameInput::processMovement(PlayerAngles* const plrAngles, const double scaleAdjust, const int drink_amt, const bool allowstrafe, const double turnscale); + friend void GameInput::processVehicle(PlayerAngles* const plrAngles, const double scaleAdjust, const double baseVel, const double velScale, const unsigned flags); // Prototypes. void doPitchInput(InputPacket* const input); diff --git a/source/core/gamestruct.h b/source/core/gamestruct.h index b81355857..76c4a94d8 100644 --- a/source/core/gamestruct.h +++ b/source/core/gamestruct.h @@ -115,7 +115,7 @@ struct GameInterface virtual void RemoveQAVInterpProps(const int res_id) { } virtual bool WantEscape() { return false; } virtual void StartSoundEngine() = 0; - virtual void doPlayerMovement(const float scaleAdjust) = 0; + virtual void doPlayerMovement(const double scaleAdjust) = 0; virtual unsigned getCrouchState() = 0; virtual FString statFPS() diff --git a/source/core/packet.h b/source/core/packet.h index 1bed84f24..b51a995ca 100644 --- a/source/core/packet.h +++ b/source/core/packet.h @@ -71,7 +71,7 @@ enum struct InputPacket { DVector3 vel; - FRotator ang; + DRotator ang; ESyncBits actions; diff --git a/source/games/blood/src/blood.h b/source/games/blood/src/blood.h index ade318e89..37c76ef45 100644 --- a/source/games/blood/src/blood.h +++ b/source/games/blood/src/blood.h @@ -135,7 +135,7 @@ struct GameInterface : public ::GameInterface void AddQAVInterpProps(const int res_id, const FString& interptype, const bool loopable, const TMap>&& ignoredata) override; void RemoveQAVInterpProps(const int res_id) override; void StartSoundEngine() override; - void doPlayerMovement(const float scaleAdjust) override { gameInput.processMovement(&getPlayer(myconnectindex)->Angles, scaleAdjust); } + void doPlayerMovement(const double scaleAdjust) override { gameInput.processMovement(&getPlayer(myconnectindex)->Angles, scaleAdjust); } unsigned getCrouchState() override; }; diff --git a/source/games/blood/src/player.cpp b/source/games/blood/src/player.cpp index 71552dea8..114d052ca 100644 --- a/source/games/blood/src/player.cpp +++ b/source/games/blood/src/player.cpp @@ -856,10 +856,9 @@ void playerStart(int nPlayer, int bNewLevel) pPlayer->deathTime = 0; pPlayer->nextWeapon = kWeapNone; actor->vel.Zero(); - pInput->ang.Yaw = nullFAngle; pInput->actions = 0; pInput->vel.Zero(); - pInput->ang.Pitch = nullFAngle; + pInput->ang.Zero(); pPlayer->flickerEffect = 0; pPlayer->quakeEffect = 0; pPlayer->tiltEffect = 0; diff --git a/source/games/duke/src/duke3d.h b/source/games/duke/src/duke3d.h index 640e08f36..6ae8a1a6c 100644 --- a/source/games/duke/src/duke3d.h +++ b/source/games/duke/src/duke3d.h @@ -37,7 +37,7 @@ struct GameInterface : public ::GameInterface void SerializeGameState(FSerializer& arc) override; void ExitFromMenu() override; void DrawPlayerSprite(const DVector2& origin, bool onteam) override; - void doPlayerMovement(const float scaleAdjust) override; + void doPlayerMovement(const double scaleAdjust) override; unsigned getCrouchState() override; void UpdateSounds() override; void Startup() override; diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 660042b3f..09ae81e8c 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -509,25 +509,25 @@ unsigned GameInterface::getCrouchState() // //--------------------------------------------------------------------------- -void GameInterface::doPlayerMovement(const float scaleAdjust) +void GameInterface::doPlayerMovement(const double scaleAdjust) { const auto p = getPlayer(myconnectindex); if (isRRRA() && (p->OnMotorcycle || p->OnBoat)) { - static constexpr float VEHICLETURN = (20.f * 360.f / 2048.f); - float baseVel, velScale; unsigned vehFlags; + static constexpr double VEHICLETURN = (20.f * 360.f / 2048.f); + double baseVel, velScale; unsigned vehFlags; if (p->OnMotorcycle) { vehFlags = VEH_CANTURN | (VEH_CANMOVE * !p->moto_underwater) | (VEH_SCALETURN * (p->MotoSpeed <= 0)); - velScale = (3.f / 10.f); + velScale = (3. / 10.); baseVel = VEHICLETURN * Sgn(p->MotoSpeed); } else { vehFlags = VEH_CANMOVE | (VEH_CANTURN * (p->MotoSpeed || p->moto_drink)); - velScale = !p->NotOnWater? 1.f : (6.f / 19.f); + velScale = !p->NotOnWater? 1. : (6. / 19.); baseVel = VEHICLETURN * velScale; } @@ -535,7 +535,7 @@ void GameInterface::doPlayerMovement(const float scaleAdjust) } else { - gameInput.processMovement(&p->Angles, scaleAdjust, p->drink_amt, true, (p->psectlotag != ST_2_UNDERWATER) ? 1.f : 0.875f); + gameInput.processMovement(&p->Angles, scaleAdjust, p->drink_amt, true, (p->psectlotag != ST_2_UNDERWATER) ? 1. : 0.875); } } diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index 5f4f3bec3..12d8a2ac8 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -857,7 +857,7 @@ void playerCenterView(int snum) if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum).value() == 0) { p->cmd.ucmd.actions |= SB_CENTERVIEW; - p->cmd.ucmd.ang.Pitch = nullFAngle; + p->cmd.ucmd.ang.Pitch = nullAngle; setForcedSyncInput(snum); } else diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index 5a783b790..5049b3f11 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -1714,7 +1714,7 @@ void processinput_d(int snum) doubvel = 0; p->vel.X = 0; p->vel.Y = 0; - p->cmd.ucmd.ang.Yaw = nullFAngle; + p->cmd.ucmd.ang.Yaw = nullAngle; setForcedSyncInput(snum); } diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index 5260e7bd7..64e17ad8b 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -729,7 +729,7 @@ static unsigned outVehicleFlags(DDukePlayer* p, ESyncBits& actions) static void doVehicleTilting(DDukePlayer* const p, const bool canTilt) { - auto adj = DAngle::fromDeg(p->cmd.ucmd.ang.Yaw.Degrees() * (545943. / 3200000.) * canTilt); + auto adj = p->cmd.ucmd.ang.Yaw * (545943. / 3200000.) * canTilt; if (p->OnMotorcycle) adj *= 5 * Sgn(p->MotoSpeed); if (cl_rrvehicletilting) adj *= cl_viewtiltscale; p->oTiltStatus = p->TiltStatus; @@ -2541,7 +2541,7 @@ void processinput_r(int snum) doubvel = 0; p->vel.X = 0; p->vel.Y = 0; - p->cmd.ucmd.ang.Yaw = nullFAngle; + p->cmd.ucmd.ang.Yaw = nullAngle; setForcedSyncInput(snum); } diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index 39ef8da7d..167791468 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -387,7 +387,7 @@ public: if ((centertest && returnlock) || !cmd.ucmd.ang.Pitch.Degrees()) { setForcedSyncInput(snum); - cmd.ucmd.ang.Pitch = nullFAngle; + cmd.ucmd.ang.Pitch = nullAngle; } else { diff --git a/source/games/exhumed/src/exhumed.h b/source/games/exhumed/src/exhumed.h index 97b910936..85c990b27 100644 --- a/source/games/exhumed/src/exhumed.h +++ b/source/games/exhumed/src/exhumed.h @@ -238,7 +238,7 @@ struct GameInterface : public ::GameInterface void processSprites(tspriteArray& tsprites, const DVector3& view, DAngle viewang, double interpfrac) override; int GetCurrentSkill() override; void StartSoundEngine() override; - void doPlayerMovement(const float scaleAdjust) override { gameInput.processMovement(&getPlayer(nLocalPlayer)->Angles, scaleAdjust); } + void doPlayerMovement(const double scaleAdjust) override { gameInput.processMovement(&getPlayer(nLocalPlayer)->Angles, scaleAdjust); } unsigned getCrouchState() override; }; diff --git a/source/games/exhumed/src/gun.cpp b/source/games/exhumed/src/gun.cpp index 4eb6e01ec..f8b37d3ea 100644 --- a/source/games/exhumed/src/gun.cpp +++ b/source/games/exhumed/src/gun.cpp @@ -46,7 +46,7 @@ Weapon WeaponInfo[] = { }; static const uint8_t nMinAmmo[] = { 0, 24, 51, 50, 1, 0, 0 }; -static FAngle lastavel; +static DAngle lastavel; int isRed = 0; diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 0bff884f7..5fbebac78 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -1901,10 +1901,10 @@ struct GameInterface : public ::GameInterface int GetCurrentSkill() override; void StartSoundEngine() override; unsigned getCrouchState() override; - void doPlayerMovement(const float scaleAdjust) override + void doPlayerMovement(const double scaleAdjust) override { const auto pp = getPlayer(myconnectindex); - gameInput.processMovement(&pp->Angles, scaleAdjust, 0, !pp->sop, pp->sop_control ? (3.f / 1.40625f) : 1.f); + gameInput.processMovement(&pp->Angles, scaleAdjust, 0, !pp->sop, pp->sop_control ? (3. / 1.40625) : 1.); } }; diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 41dc255c3..30d74b323 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -1444,13 +1444,13 @@ void UpdatePlayerSpriteAngle(DSWPlayer* pp) // //--------------------------------------------------------------------------- -void DoPlayerVehicleInputScaling(DSWPlayer* const pp, FAngle FRotator::* angle, const float scale) +void DoPlayerVehicleInputScaling(DSWPlayer* const pp, DAngle DRotator::* angle, const float scale) { SECTOR_OBJECT* sop = pp->sop; if (sop->drive_angspeed) { - pp->cmd.ucmd.ang.*angle = FAngle::fromDeg(float((((pp->cmd.ucmd.ang.*angle).Degrees() * sop->drive_angspeed) + ((pp->lastcmd.ucmd.ang.*angle).Degrees() * (sop->drive_angslide - 1))) / sop->drive_angslide)); + pp->cmd.ucmd.ang.*angle = ((pp->cmd.ucmd.ang.*angle * sop->drive_angspeed) + (pp->lastcmd.ucmd.ang.*angle * (sop->drive_angslide - 1))) / sop->drive_angslide; } else { @@ -2231,7 +2231,7 @@ void DriveCrush(DSWPlayer* pp, DVector2* quad) return; // not moving - don't crush - if ((pp->vect.isZero()) == 0 && pp->cmd.ucmd.ang.Yaw == nullFAngle) + if ((pp->vect.isZero()) == 0 && pp->cmd.ucmd.ang.Yaw == nullAngle) return; // main sector @@ -2455,8 +2455,8 @@ void DoPlayerMoveVehicle(DSWPlayer* pp) double floordist = abs(zz - pp->sop->floor_loz); setForcedSyncInput(pp->pnum); - DoPlayerVehicleInputScaling(pp, &FRotator::Yaw, 0.125f); - DoPlayerVehicleInputScaling(pp, &FRotator::Pitch, 0.125f); + DoPlayerVehicleInputScaling(pp, &DRotator::Yaw, 0.125f); + DoPlayerVehicleInputScaling(pp, &DRotator::Pitch, 0.125f); if (RectClip) { @@ -2466,9 +2466,9 @@ void DoPlayerMoveVehicle(DSWPlayer* pp) auto save_cstat = plActor->spr.cstat; plActor->spr.cstat &= ~(CSTAT_SPRITE_BLOCK); - if (pp->cmd.ucmd.ang.Yaw != nullFAngle) + if (pp->cmd.ucmd.ang.Yaw != nullAngle) { - auto sum = plActor->spr.Angles.Yaw + DAngle::fromDeg(pp->cmd.ucmd.ang.Yaw.Degrees()); + auto sum = plActor->spr.Angles.Yaw + pp->cmd.ucmd.ang.Yaw; if (RectClipTurn(pp, sum, pos, opos)) { plActor->spr.Angles.Yaw = sum; @@ -2518,9 +2518,9 @@ void DoPlayerMoveVehicle(DSWPlayer* pp) } else { - if (pp->cmd.ucmd.ang.Yaw != nullFAngle) + if (pp->cmd.ucmd.ang.Yaw != nullAngle) { - auto sum = plActor->spr.Angles.Yaw + DAngle::fromDeg(pp->cmd.ucmd.ang.Yaw.Degrees()); + auto sum = plActor->spr.Angles.Yaw + pp->cmd.ucmd.ang.Yaw; if (MultiClipTurn(pp, sum, zz, floordist)) { plActor->spr.Angles.Yaw = sum; @@ -2590,12 +2590,12 @@ void DoPlayerMoveTurret(DSWPlayer* pp) setForcedSyncInput(pp->pnum); - DoPlayerVehicleInputScaling(pp, &FRotator::Yaw, 0.125f); - DoPlayerVehicleInputScaling(pp, &FRotator::Pitch, 0.125f); + DoPlayerVehicleInputScaling(pp, &DRotator::Yaw, 0.125f); + DoPlayerVehicleInputScaling(pp, &DRotator::Pitch, 0.125f); - if (fabs(pp->cmd.ucmd.ang.Yaw) >= FAngle::fromDeg(FLT_EPSILON)) + if (pp->cmd.ucmd.ang.Yaw != nullAngle) { - DAngle new_ang = pact->spr.Angles.Yaw + DAngle::fromDeg(pp->cmd.ucmd.ang.Yaw.Degrees()); + DAngle new_ang = pact->spr.Angles.Yaw + pp->cmd.ucmd.ang.Yaw; if (pp->sop->limit_ang_center >= nullAngle) { @@ -5769,7 +5769,7 @@ void DoPlayerDeathFollowKiller(DSWPlayer* pp) // allow turning if (pp->Flags & (PF_DEAD_HEAD|PF_HEAD_CONTROL)) { - pp->GetActor()->spr.Angles.Yaw += DAngle::fromDeg(pp->cmd.ucmd.ang.Yaw.Degrees()); + pp->GetActor()->spr.Angles.Yaw += pp->cmd.ucmd.ang.Yaw; UpdatePlayerSpriteAngle(pp); } @@ -6550,7 +6550,7 @@ void ChopsCheck(DSWPlayer* pp) { if (!M_Active() && !(pp->Flags & PF_DEAD) && !pp->sop_riding && numplayers <= 1) { - if (pp->cmd.ucmd.actions & ~SB_RUN || !pp->cmd.ucmd.vel.XY().isZero() || pp->cmd.ucmd.ang.Yaw.Degrees() || pp->cmd.ucmd.ang.Pitch.Degrees() || + if (pp->cmd.ucmd.actions & ~SB_RUN || !pp->cmd.ucmd.vel.XY().isZero() || !pp->cmd.ucmd.ang.isZero() || (pp->Flags & (PF_CLIMBING | PF_FALLING | PF_DIVING))) { // Hit a input key or other reason to stop chops