From 31f8de3854458228361eef6b6d1ae7c4977370e9 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sun, 19 Mar 2023 20:54:19 +1100 Subject: [PATCH] - Duke/RR: Remove vehTurn variables from player struct. * Back in 2020, I was trying to tidy stuff up and had no idea about network awareness, etc. * The original game misused network bits here, however I don't see why the player's angle can't just be tested for signedness. Something I didn't see way back when... --- source/games/duke/src/input.cpp | 38 +++++++++-------- source/games/duke/src/player_r.cpp | 44 +++++++++++--------- source/games/duke/src/types.h | 2 +- source/games/duke/src/vmexports.cpp | 2 - wadsrc/static/zscript/games/duke/dukegame.zs | 2 +- 5 files changed, 47 insertions(+), 41 deletions(-) diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 095045602..5d7eadab4 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -545,36 +545,48 @@ static constexpr float VEHICLETURN = (20.f * 360.f / 2048.f); // //--------------------------------------------------------------------------- -static void doVehicleTilting(player_struct* const p, const float factor, const bool allowed = true) +static void doVehicleTilting(player_struct* const p, const int turndir, const float factor) { - if (const auto turndir = (p->vehTurnRight - p->vehTurnLeft) * allowed) + if (turndir) { + p->oTiltStatus = p->TiltStatus; p->TiltStatus += factor * turndir; if (abs(p->TiltStatus) > 10) p->TiltStatus = 10.f * turndir; } } -static float getVehicleTurnVel(player_struct* p, HIDInput* const hidInput, const int kbdDir, const float factor, const float baseVel, const float velScale) +static float getVehicleTurnVel(player_struct* p, HIDInput* const hidInput, const float factor, const float baseVel, const float velScale) { float turnvel = 0; - p->oTiltStatus = p->TiltStatus; + + // Cancel out micro-movement + if (fabs(hidInput->mouseturnx) < (m_sensitivity_x * m_yaw * backendinputscale() * 2.f)) + hidInput->mouseturnx = 0; + + // Yes, we need all these bools... + const bool kbdLeft = buttonMap.ButtonDown(gamefunc_Turn_Left) || buttonMap.ButtonDown(gamefunc_Strafe_Left); + const bool kbdRight = buttonMap.ButtonDown(gamefunc_Turn_Right) || buttonMap.ButtonDown(gamefunc_Strafe_Right); + const bool turnLeft = kbdLeft || hidInput->mouseturnx < 0 || hidInput->joyaxes[JOYAXIS_Yaw] > 0; + const bool turnRight = kbdRight || hidInput->mouseturnx > 0 || hidInput->joyaxes[JOYAXIS_Yaw] < 0; + const int turndir = turnRight - turnLeft; if (p->OnMotorcycle && (p->MotoSpeed == 0 || !p->on_ground)) { resetTurnHeldAmt(); - doVehicleTilting(p, factor); + doVehicleTilting(p, turndir, factor); } - else if ((p->OnMotorcycle || p->MotoSpeed) && (p->vehTurnLeft || p->vehTurnRight || p->moto_drink)) + else if ((p->OnMotorcycle || p->MotoSpeed) && (turndir || p->moto_drink)) { - doVehicleTilting(p, factor, p->OnMotorcycle || !p->NotOnWater); + if (p->OnMotorcycle || !p->NotOnWater) + doVehicleTilting(p, turndir, factor); const bool noattenuate = (isTurboTurnTime() || hidInput->mouseturnx || hidInput->joyaxes[JOYAXIS_Yaw]) && (!p->OnMotorcycle || p->MotoSpeed > 0); const auto vel = (noattenuate) ? (baseVel) : (baseVel * velScale); turnvel = vel * hidInput->joyaxes[JOYAXIS_Yaw]; - if (kbdDir) + if (const auto kbdDir = kbdRight - kbdLeft) { turnvel += vel * kbdDir; updateTurnHeldAmt(factor); @@ -604,14 +616,6 @@ static float getVehicleTurnVel(player_struct* p, HIDInput* const hidInput, const static void processVehicleInput(player_struct *p, HIDInput* const hidInput, InputPacket* const inputBuffer, InputPacket* const currInput, const double scaleAdjust) { float baseVel, velScale; - bool const kbdLeft = buttonMap.ButtonDown(gamefunc_Turn_Left) || buttonMap.ButtonDown(gamefunc_Strafe_Left); - bool const kbdRight = buttonMap.ButtonDown(gamefunc_Turn_Right) || buttonMap.ButtonDown(gamefunc_Strafe_Right); - - // Cancel out micro-movement - if (fabs(hidInput->mouseturnx) < (m_sensitivity_x * m_yaw * backendinputscale() * 2.f)) hidInput->mouseturnx = 0; - - p->vehTurnLeft = kbdLeft || hidInput->mouseturnx < 0 || hidInput->joyaxes[JOYAXIS_Yaw] > 0; - p->vehTurnRight = kbdRight || hidInput->mouseturnx > 0 || hidInput->joyaxes[JOYAXIS_Yaw] < 0; if (p->OnBoat || !p->moto_underwater) { @@ -633,7 +637,7 @@ static void processVehicleInput(player_struct *p, HIDInput* const hidInput, Inpu } inputBuffer->fvel = clamp((float)p->MotoSpeed, -(MAXVELMOTO >> 3), MAXVELMOTO) * (1.f / 40.f); - inputBuffer->avel += (currInput->avel = getVehicleTurnVel(p, hidInput, kbdRight - kbdLeft, (float)scaleAdjust, baseVel, velScale)); + inputBuffer->avel += (currInput->avel = getVehicleTurnVel(p, hidInput, (float)scaleAdjust, baseVel, velScale)); } diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index 8f77af202..b9dbb8a46 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -1472,6 +1472,9 @@ static void onMotorcycle(int snum, ESyncBits &actions) if (p->MotoSpeed < 0) p->MotoSpeed = 0; + bool turnLeft = p->sync.avel < 0; + bool turnRight = p->sync.avel > 0; + if (p->vehForwardScale != 0) { if (p->on_ground) @@ -1570,9 +1573,9 @@ static void onMotorcycle(int snum, ESyncBits &actions) if (p->vehReverseScale != 0 && p->MotoSpeed <= 0 && !p->vehBraking) { - bool temp = p->vehTurnRight; - p->vehTurnRight = p->vehTurnLeft; - p->vehTurnLeft = temp; + bool temp = turnRight; + turnRight = turnLeft; + turnLeft = temp; p->MotoSpeed = -15 * p->vehReverseScale; p->vehReverseScale = 0; } @@ -1582,12 +1585,12 @@ static void onMotorcycle(int snum, ESyncBits &actions) if (!p->VBumpNow && (krand() & 3) == 2) p->VBumpTarget = p->MotoSpeed * (1. / 16.) * ((krand() & 7) - 4); - if (p->vehTurnLeft || p->moto_drink < 0) + if (turnLeft || p->moto_drink < 0) { if (p->moto_drink < 0) p->moto_drink++; } - else if (p->vehTurnRight || p->moto_drink > 0) + else if (turnRight || p->moto_drink > 0) { if (p->moto_drink > 0) p->moto_drink--; @@ -1639,9 +1642,9 @@ static void onMotorcycle(int snum, ESyncBits &actions) DAngle velAdjustment; int currSpeed = int(p->MotoSpeed); - if (p->MotoSpeed >= 20 && p->on_ground == 1 && (p->vehTurnLeft || p->vehTurnRight)) + if (p->MotoSpeed >= 20 && p->on_ground == 1 && (turnLeft || turnRight)) { - velAdjustment = p->vehTurnLeft ? -adjust : adjust; + velAdjustment = adjust * Sgn(p->sync.avel); auto angAdjustment = velAdjustment > nullAngle ? 734003200 : -734003200; if (p->moto_on_mud || p->moto_on_oil || !p->NotOnWater) @@ -1690,7 +1693,7 @@ static void onMotorcycle(int snum, ESyncBits &actions) } p->moto_on_mud = p->moto_on_oil = 0; - p->vehTurnLeft = p->vehTurnRight = p->vehBraking = false; + p->vehBraking = false; } //--------------------------------------------------------------------------- @@ -1707,6 +1710,9 @@ static void onBoat(int snum, ESyncBits &actions) bool heeltoe; int rng; + bool turnLeft = p->sync.avel < 0; + bool turnRight = p->sync.avel > 0; + if (p->NotOnWater) { if (p->MotoSpeed > 0) @@ -1764,10 +1770,10 @@ static void onBoat(int snum, ESyncBits &actions) S_PlayActorSound(87, pact); } - if (p->vehTurnLeft && !S_CheckActorSoundPlaying(pact, 91) && p->MotoSpeed > 30 && !p->NotOnWater) + if (turnLeft && !S_CheckActorSoundPlaying(pact, 91) && p->MotoSpeed > 30 && !p->NotOnWater) S_PlayActorSound(91, pact); - if (p->vehTurnRight && !S_CheckActorSoundPlaying(pact, 91) && p->MotoSpeed > 30 && !p->NotOnWater) + if (turnRight && !S_CheckActorSoundPlaying(pact, 91) && p->MotoSpeed > 30 && !p->NotOnWater) S_PlayActorSound(91, pact); if (!p->NotOnWater) @@ -1840,9 +1846,9 @@ static void onBoat(int snum, ESyncBits &actions) if (p->vehReverseScale != 0 && p->MotoSpeed == 0 && !p->vehBraking) { - bool temp = p->vehTurnRight; - p->vehTurnRight = p->vehTurnLeft; - p->vehTurnLeft = temp; + bool temp = turnRight; + turnRight = turnLeft; + turnLeft = temp; p->MotoSpeed = -(!p->NotOnWater ? 25 : 20) * p->vehReverseScale; p->vehReverseScale = 0; } @@ -1852,11 +1858,11 @@ static void onBoat(int snum, ESyncBits &actions) if (!p->VBumpNow && (krand() & 15) == 14) p->VBumpTarget = p->MotoSpeed * (1. / 16.) * ((krand() & 3) - 2); - if (p->vehTurnLeft && p->moto_drink < 0) + if (turnLeft && p->moto_drink < 0) { p->moto_drink++; } - else if (p->vehTurnRight && p->moto_drink > 0) + else if (turnRight && p->moto_drink > 0) { p->moto_drink--; } @@ -1903,12 +1909,10 @@ static void onBoat(int snum, ESyncBits &actions) p->GetActor()->spr.Angles.Pitch = -maphoriz(horiz); } - if (p->MotoSpeed > 0 && p->on_ground == 1 && (p->vehTurnLeft || p->vehTurnRight)) + if (p->MotoSpeed > 0 && p->on_ground == 1 && (turnLeft || turnRight)) { - const DAngle adjust = mapangle(-510); - int currSpeed = int(p->MotoSpeed * 4.); - DAngle velAdjustment = p->vehTurnLeft ? -adjust : adjust; + DAngle velAdjustment = mapangle(-510) * Sgn(p->sync.avel); auto angAdjustment = velAdjustment > nullAngle ? 734003200 : -734003200; if (p->moto_do_bump) @@ -1928,7 +1932,7 @@ static void onBoat(int snum, ESyncBits &actions) if (p->NotOnWater && p->MotoSpeed > 50) p->MotoSpeed -= (p->MotoSpeed / 2.); - p->vehTurnLeft = p->vehTurnRight = p->vehBraking = false; + p->vehBraking = false; } //--------------------------------------------------------------------------- diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index 042cbde11..abf0c6628 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -309,7 +309,7 @@ struct player_struct uint8_t OnMotorcycle, OnBoat, moto_underwater, NotOnWater, MotoOnGround; uint8_t moto_do_bump, moto_bump_fast, moto_on_oil, moto_on_mud; double vehForwardScale, vehReverseScale, MotoSpeed; - bool vehTurnLeft, vehTurnRight, vehBraking; + bool vehBraking; TArray uservars; diff --git a/source/games/duke/src/vmexports.cpp b/source/games/duke/src/vmexports.cpp index 89ce890e4..06e9e746b 100644 --- a/source/games/duke/src/vmexports.cpp +++ b/source/games/duke/src/vmexports.cpp @@ -944,8 +944,6 @@ DEFINE_FIELD_X(DukePlayer, player_struct, moto_on_mud) DEFINE_FIELD_X(DukePlayer, player_struct, vehForwardScale) DEFINE_FIELD_X(DukePlayer, player_struct, vehReverseScale) DEFINE_FIELD_X(DukePlayer, player_struct, MotoSpeed) -DEFINE_FIELD_X(DukePlayer, player_struct, vehTurnLeft) -DEFINE_FIELD_X(DukePlayer, player_struct, vehTurnRight) DEFINE_FIELD_X(DukePlayer, player_struct, vehBraking) DEFINE_FIELD_X(DukePlayer, player_struct, holoduke_on) DEFINE_FIELD_X(DukePlayer, player_struct, actorsqu) diff --git a/wadsrc/static/zscript/games/duke/dukegame.zs b/wadsrc/static/zscript/games/duke/dukegame.zs index c6d6dd8f0..447b1fb19 100644 --- a/wadsrc/static/zscript/games/duke/dukegame.zs +++ b/wadsrc/static/zscript/games/duke/dukegame.zs @@ -335,7 +335,7 @@ struct DukePlayer native native uint8 OnMotorcycle, OnBoat, moto_underwater, NotOnWater, MotoOnGround; native uint8 moto_do_bump, moto_bump_fast, moto_on_oil, moto_on_mud; native double vehForwardScale, vehReverseScale, MotoSpeed; - native bool vehTurnLeft, vehTurnRight, vehBraking; + native bool vehBraking; // input stuff. //InputPacket sync;