From 9ad0af4479daa192bfacf67eb751a2c20186f804 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Mon, 25 Sep 2023 16:39:12 +1000 Subject: [PATCH] - Blood: Better fix for view rolling under all circumstances. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Why is everything so difficult in Blood? 😕 * Do StrafeVel drag/resistance before `MoveDude()` as it may never be called if there's no velocity. * Avoid using `mulscale16r()` in algorithm as we simply don't need to here. * Move `doRollInput()` call into same area where drag is applied so all the code is concentrated in one spot. --- source/games/blood/src/actor.cpp | 25 +++++++++++++++---------- source/games/blood/src/player.cpp | 9 +++------ 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/source/games/blood/src/actor.cpp b/source/games/blood/src/actor.cpp index d511bda71..830376b12 100644 --- a/source/games/blood/src/actor.cpp +++ b/source/games/blood/src/actor.cpp @@ -5142,19 +5142,13 @@ void MoveDude(DBloodActor* actor) return; } } - int nDrag = gDudeDrag; - if (actor->xspr.height > 0) - nDrag -= Scale(gDudeDrag, actor->xspr.height, 256); - - if (pPlayer) - { - pPlayer->Angles.StrafeVel += FixedToFloat(-mulscale16r(FloatToFixed(pPlayer->Angles.StrafeVel), nDrag)); - } - if (IsUnderwaterSector(actor->sector())) return; if (actor->xspr.height >= 0x100) return; + int nDrag = gDudeDrag; + if (actor->xspr.height > 0) + nDrag -= Scale(gDudeDrag, actor->xspr.height, 256); // this cannot be floatified due to the effect of mulscale16r on the value. actor->vel.X += FixedToFloat(-mulscale16r(FloatToFixed(actor->vel.X), nDrag)); @@ -5163,7 +5157,6 @@ void MoveDude(DBloodActor* actor) if (actor->vel.XY().Length() < 0.0625) { actor->vel.XY().Zero(); - if (pPlayer) pPlayer->Angles.StrafeVel = 0; } } } @@ -6053,6 +6046,18 @@ static void actCheckDudes() if (pXSector && pXSector->Underwater) actAirDrag(actor, 5376); else actAirDrag(actor, 128); + if (actor->IsPlayerActor()) + { + PLAYER* pPlayer = &gPlayer[actor->spr.type - kDudePlayer1]; + double nDrag = FixedToFloat(gDudeDrag); + if (actor->xspr.height > 0) + nDrag -= Scale(nDrag, (double)actor->xspr.height, 256.); + + constexpr auto maxVel = (36211. / 3000.); + pPlayer->Angles.doRollInput(&pPlayer->input, actor->vel.XY(), maxVel, pPlayer->posture == kPostureSwim); + pPlayer->Angles.StrafeVel -= pPlayer->Angles.StrafeVel * nDrag; + } + if ((actor->spr.flags & 4) || !actor->vel.isZero() || actor->sector()->velFloor || actor->sector()->velCeil) MoveDude(actor); } diff --git a/source/games/blood/src/player.cpp b/source/games/blood/src/player.cpp index 3aad36a9c..f1831d2c7 100644 --- a/source/games/blood/src/player.cpp +++ b/source/games/blood/src/player.cpp @@ -1578,9 +1578,9 @@ void ProcessInput(PLAYER* pPlayer) if ((pInput->fvel || pInput->svel) && (pPlayer->posture == 1 || actor->xspr.height < 256)) { - const double speed = pPlayer->posture == 1? 1. : 1. - (actor->xspr.height < 256 ? actor->xspr.height * (1. / 256.) : 0); - const double& fvAccel = pInput->fvel > 0 ? pPosture->frontAccel : pPosture->backAccel; - const double& svAccel = pPosture->sideAccel; + const double speed = pPlayer->posture == 1? 1. : 1. - (actor->xspr.height * (1. / 256.) * (actor->xspr.height < 256)); + const double fvAccel = pInput->fvel > 0 ? pPosture->frontAccel : pPosture->backAccel; + const double svAccel = pPosture->sideAccel; actor->vel.XY() += DVector2(pInput->fvel * fvAccel, pInput->svel * svAccel).Rotated(actor->spr.Angles.Yaw) * speed; pPlayer->Angles.StrafeVel += pInput->svel * svAccel * speed; } @@ -1588,9 +1588,6 @@ void ProcessInput(PLAYER* pPlayer) pPlayer->Angles.doViewYaw(pInput); pPlayer->Angles.doYawInput(pInput); - constexpr auto maxVel = (36211. / 3000.); - pPlayer->Angles.doRollInput(pInput, actor->vel.XY(), maxVel, pPlayer->posture == kPostureSwim); - if (!(pInput->actions & SB_JUMP)) pPlayer->cantJump = 0;