From afcc65c33242275694174ec358e09a940eaa1203 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Mon, 24 Apr 2023 18:27:44 +1000 Subject: [PATCH] - Duke: Hook up `InputPacket::uvel` to remainder of relevant code. --- source/games/duke/src/actors_d.cpp | 6 +++--- source/games/duke/src/actors_r.cpp | 4 ++-- source/games/duke/src/player.cpp | 25 +++++++++++++++---------- source/games/duke/src/player_d.cpp | 14 +++++++------- source/games/duke/src/player_r.cpp | 2 +- 5 files changed, 28 insertions(+), 23 deletions(-) diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index dafee9036..12e9a02b9 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -335,8 +335,8 @@ void movetransports_d(void) else if (!(sectlotag == 1 && ps[p].on_ground == 1)) break; if (onfloorz == 0 && abs(act->spr.pos.Z - ps[p].GetActor()->getOffsetZ()) < 24) - if ((ps[p].jetpack_on == 0) || (ps[p].jetpack_on && (PlayerInput(p, SB_JUMP))) || - (ps[p].jetpack_on && PlayerInput(p, SB_CROUCH))) + if ((ps[p].jetpack_on == 0) || (ps[p].jetpack_on && (PlayerInput(p, SB_JUMP) || ps[p].sync.uvel > 0)) || + (ps[p].jetpack_on && (PlayerInput(p, SB_CROUCH) || ps[p].sync.uvel < 0))) { ps[p].GetActor()->spr.pos.XY() += Owner->spr.pos.XY() - act->spr.pos.XY(); ps[p].GetActor()->backupvec2(); @@ -376,7 +376,7 @@ void movetransports_d(void) } - if (onfloorz && sectlotag == ST_1_ABOVE_WATER && ps[p].on_ground && ps[p].GetActor()->getOffsetZ() > (sectp->floorz - 16) && (PlayerInput(p, SB_CROUCH) || ps[p].vel.Z > 8)) + if (onfloorz && sectlotag == ST_1_ABOVE_WATER && ps[p].on_ground && ps[p].GetActor()->getOffsetZ() > (sectp->floorz - 16) && (PlayerInput(p, SB_CROUCH) || ps[p].sync.uvel < 0 || ps[p].vel.Z > 8)) // if( onfloorz && sectlotag == 1 && ps[p].pos.z > (sectp->floorz-(6<<8)) ) { k = 1; diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index f47cd4559..845afedf1 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -310,8 +310,8 @@ void movetransports_r(void) else break; if (onfloorz == 0 && fabs(act->spr.pos.Z - ps[p].GetActor()->getOffsetZ()) < 24) - if ((ps[p].jetpack_on == 0) || (ps[p].jetpack_on && PlayerInput(p, SB_JUMP)) || - (ps[p].jetpack_on && PlayerInput(p, SB_CROUCH))) + if ((ps[p].jetpack_on == 0) || (ps[p].jetpack_on && (PlayerInput(p, SB_JUMP) || ps[p].sync.uvel > 0)) || + (ps[p].jetpack_on && (PlayerInput(p, SB_CROUCH) || ps[p].sync.uvel < 0))) { ps[p].GetActor()->spr.pos.XY() += Owner->spr.pos.XY() - act->spr.pos.XY(); ps[p].GetActor()->backupvec2(); diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index 5d59b367e..f79cadb2c 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -663,13 +663,15 @@ int timedexit(int snum) void playerCrouch(int snum) { - auto p = &ps[snum]; - // crouching - SetGameVarID(g_iReturnVarID, 0, p->GetActor(), snum); - OnEvent(EVENT_CROUCH, snum, p->GetActor(), -1); - if (GetGameVarID(g_iReturnVarID, p->GetActor(), snum).value() == 0) + const auto p = &ps[snum]; + const auto pact = p->GetActor(); + const auto nVelMoveDown = abs(p->sync.uvel * (p->sync.uvel < 0)); + constexpr double vel = 8 + 3; + SetGameVarID(g_iReturnVarID, 0, pact, snum); + OnEvent(EVENT_CROUCH, snum, pact, -1); + if (GetGameVarID(g_iReturnVarID, pact, snum).value() == 0) { - p->GetActor()->spr.pos.Z += 8 + 3; + pact->spr.pos.Z += clamp(vel * !!(p->sync.actions & SB_CROUCH) + vel * nVelMoveDown, -vel, vel); p->crack_time = CRACK_TIME; } } @@ -1570,6 +1572,9 @@ void underwater(int snum, ESyncBits actions, double floorz, double ceilingz) { const auto p = &ps[snum]; const auto pact = p->GetActor(); + constexpr double dist = (348. / 256.); + const auto kbdDir = ((actions & SB_JUMP) && !p->OnMotorcycle) - ((actions & SB_CROUCH) || p->OnMotorcycle); + const auto velZ = clamp(dist * kbdDir + dist * p->sync.uvel, -dist, dist); p->jumping_counter = 0; p->pycount += 32; @@ -1579,16 +1584,16 @@ void underwater(int snum, ESyncBits actions, double floorz, double ceilingz) if (!S_CheckActorSoundPlaying(pact, DUKE_UNDERWATER)) S_PlayActorSound(DUKE_UNDERWATER, pact); - if ((actions & SB_JUMP) && !p->OnMotorcycle) + if (velZ > 0) { if (p->vel.Z > 0) p->vel.Z = 0; - p->vel.Z -= (348 / 256.); + p->vel.Z -= velZ; if (p->vel.Z < -6) p->vel.Z = -6; } - else if ((actions & SB_CROUCH) || p->OnMotorcycle) + else if (velZ < 0) { if (p->vel.Z < 0) p->vel.Z = 0; - p->vel.Z += (348 / 256.); + p->vel.Z -= velZ; if (p->vel.Z > 6) p->vel.Z = 6; } else diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index f068c8434..33568b221 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -580,7 +580,9 @@ static void operateJetpack(int snum, ESyncBits actions, int psectlotag, double f { const auto p = &ps[snum]; const auto pact = p->GetActor(); + const auto kbdDir = !!(actions & SB_JUMP) - !!(actions & SB_CROUCH); const double dist = shrunk ? 2 : 8; + const double velZ = clamp(dist * kbdDir + dist * p->sync.uvel, -dist, dist); p->on_ground = 0; p->jumping_counter = 0; @@ -600,28 +602,26 @@ static void operateJetpack(int snum, ESyncBits actions, int psectlotag, double f S_PlayActorSound(DUKE_JETPACK_IDLE, pact); } - if ((actions & SB_JUMP) || p->sync.uvel > 0) //A (soar high) + if (velZ > 0) //A (soar high) { // jump SetGameVarID(g_iReturnVarID, 0, pact, snum); OnEvent(EVENT_SOARUP, snum, pact, -1); if (GetGameVarID(g_iReturnVarID, pact, snum).value() == 0) { - pact->spr.pos.Z -= dist * !!(actions & SB_JUMP); - pact->spr.pos.Z -= dist * p->sync.uvel; + pact->spr.pos.Z -= velZ; p->crack_time = CRACK_TIME; } } - if ((actions & SB_CROUCH) || p->sync.uvel < 0) //Z (soar low) + if (velZ < 0) //Z (soar low) { // crouch SetGameVarID(g_iReturnVarID, 0, pact, snum); OnEvent(EVENT_SOARDOWN, snum, pact, -1); if (GetGameVarID(g_iReturnVarID, pact, snum).value() == 0) { - pact->spr.pos.Z += dist * !!(actions & SB_CROUCH); - pact->spr.pos.Z -= dist * p->sync.uvel; + pact->spr.pos.Z -= velZ; p->crack_time = CRACK_TIME; } } @@ -767,7 +767,7 @@ static void movement(int snum, ESyncBits actions, sectortype* psect, double floo p->on_warping_sector = 0; - if (actions & SB_CROUCH) + if ((actions & SB_CROUCH) || p->sync.uvel < 0) { playerCrouch(snum); } diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index 28107cefc..3444ed2d9 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -1269,7 +1269,7 @@ static void movement(int snum, ESyncBits actions, sectortype* psect, double floo p->on_warping_sector = 0; - if ((actions & SB_CROUCH) && !p->OnMotorcycle) + if (((actions & SB_CROUCH) || p->sync.uvel < 0) && !p->OnMotorcycle) { playerCrouch(snum); }