From fca4bdcafb15e0e991bd5aed5e17d562eb97a1ab Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 16 Jul 2020 18:58:31 +0200 Subject: [PATCH] - split out the main movement calculation out of P_PlayerInputBoat and used the original code for providing a replacement. --- source/games/duke/src/hudweapon_r.cpp | 8 +-- source/games/duke/src/input.cpp | 78 +++++++++++++++++++++++++++ source/games/duke/src/player_r.cpp | 8 +-- source/games/duke/src/render.cpp | 2 +- source/games/duke/src/types.h | 3 +- source/games/duke/src/zz_player.cpp | 67 ++--------------------- 6 files changed, 94 insertions(+), 72 deletions(-) diff --git a/source/games/duke/src/hudweapon_r.cpp b/source/games/duke/src/hudweapon_r.cpp index 7e0519ec8..222cf4c86 100644 --- a/source/games/duke/src/hudweapon_r.cpp +++ b/source/games/duke/src/hudweapon_r.cpp @@ -92,15 +92,15 @@ void displaymasks_r(int snum) // //--------------------------------------------------------------------------- -void ShowMotorcycle(double x, double y, int tilenum, int shade, int orientation, int p, int a) +void ShowMotorcycle(double x, double y, int tilenum, int shade, int orientation, int p, double a) { - hud_drawsprite(x, y, 34816, a, tilenum, shade, p, 2 | orientation); + hud_drawsprite(x, y, 34816, int(a), tilenum, shade, p, 2 | orientation); } -void ShowBoat(double x, double y, int tilenum, int shade, int orientation, int p, int a) +void ShowBoat(double x, double y, int tilenum, int shade, int orientation, int p, double a) { - hud_drawsprite(x, y, 66048, a, tilenum, shade, p, 2 | orientation); + hud_drawsprite(x, y, 66048, int(a), tilenum, shade, p, 2 | orientation); } diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 08ec1d9ce..244e6d63b 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -675,4 +675,82 @@ void hud_input(int snum) } } } + + +enum +{ + TURBOTURNTIME = (TICRATE/8) // 7 +}; + +//--------------------------------------------------------------------------- +// +// split out of playerinputboat for readability purposes and condensed using ?: operators +// +//--------------------------------------------------------------------------- + +int boatApplyTurn(player_struct *p, int turnl, int turnr, int bike_turn, double factor) +{ + static int turnheldtime; + static int lastcontroltime; + + int tics = totalclock - lastcontroltime; + lastcontroltime = totalclock; + + if (p->MotoSpeed) + { + if (turnl || p->moto_drink < 0) + { + turnheldtime += tics; + if (!p->NotOnWater) + { + p->TiltStatus -= (float)factor; + if (p->TiltStatus < -10) + p->TiltStatus = -10; + } + if (turnheldtime >= TURBOTURNTIME && p->MotoSpeed != 0) + { + if (p->NotOnWater) return bike_turn ? -6 : -3; + else return bike_turn ? -20 : -10; + } + else if (turnheldtime < TURBOTURNTIME && p->MotoSpeed != 0) + { + if (p->NotOnWater) return bike_turn ? -2 : -1; + else return bike_turn ? -6 : -3; + } + } + else if (turnr || p->moto_drink > 0) + { + turnheldtime += tics; + if (!p->NotOnWater) + { + p->TiltStatus += (float)factor; + if (p->TiltStatus > 10) + p->TiltStatus = 10; + } + if (turnheldtime >= TURBOTURNTIME && p->MotoSpeed != 0) + { + if (p->NotOnWater) return bike_turn ? 6 : 3; + else return bike_turn ? 20 : 10; + } + else if (turnheldtime < TURBOTURNTIME && p->MotoSpeed != 0) + { + if (p->NotOnWater) return bike_turn ? 2 : 1; + else return bike_turn ? 6 : 3; + } + } + else if (!p->NotOnWater) + { + turnheldtime = 0; + + if (p->TiltStatus > 0) + p->TiltStatus -= (float)factor; + else if (p->TiltStatus < 0) + p->TiltStatus += (float)factor; + + if (fabs(p->TiltStatus) < 0.025) + p->TiltStatus = 0; + } + } + return 0; +} END_DUKE_NS diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index 5afb41c80..2953fbf7a 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -2545,8 +2545,8 @@ void onMotorcycleHit(int snum, int var60) { if (numplayers == 1) { - fi.movesprite(var60, sintable[(p->TiltStatus * 20 + p->getang() + 512) & 2047] >> 8, - sintable[(p->TiltStatus * 20 + p->getang()) & 2047] >> 8, sprite[var60].zvel, CLIPMASK0); + fi.movesprite(var60, sintable[int(p->TiltStatus * 20 + p->getang() + 512) & 2047] >> 8, + sintable[int(p->TiltStatus * 20 + p->getang()) & 2047] >> 8, sprite[var60].zvel, CLIPMASK0); } } else @@ -2602,8 +2602,8 @@ void onBoatHit(int snum, int var60) { if (numplayers == 1) { - fi.movesprite(var60, sintable[(p->TiltStatus * 20 + p->getang() + 512) & 2047] >> 9, - sintable[(p->TiltStatus * 20 + p->getang()) & 2047] >> 9, sprite[var60].zvel, CLIPMASK0); + fi.movesprite(var60, sintable[int(p->TiltStatus * 20 + p->getang() + 512) & 2047] >> 9, + sintable[int(p->TiltStatus * 20 + p->getang()) & 2047] >> 9, sprite[var60].zvel, CLIPMASK0); } } else diff --git a/source/games/duke/src/render.cpp b/source/games/duke/src/render.cpp index 739364a09..b7d756940 100644 --- a/source/games/duke/src/render.cpp +++ b/source/games/duke/src/render.cpp @@ -540,7 +540,7 @@ void displayrooms(int snum, int smoothratio) else { // The fixed point fuckery at play here means we cannot do the interpolation at full precision. - auto oa = p->oq16rotscrnang >> FRACUNIT; + auto oa = p->oq16rotscrnang >> FRACBITS; renderSetRollAngle(oa + mulscale16(((p->getrotscrnang() - oa + 1024) & 2047) - 1024, smoothratio)); p->oq16rotscrnang = p->q16rotscrnang; // JBF: save it for next time } diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index 2ec8deffd..a4c26cd27 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -180,7 +180,8 @@ struct player_struct int drug_timer; int SeaSick; short MamaEnd; // raat609 - short MotoSpeed, TiltStatus, moto_drink; + short MotoSpeed, moto_drink; + float TiltStatus; short VBumpNow, VBumpTarget, TurbCount; short drug_stat[3]; // raat5f1..5 uint8_t DrugMode, lotag800kill; diff --git a/source/games/duke/src/zz_player.cpp b/source/games/duke/src/zz_player.cpp index 3a64181f1..fb52af24b 100644 --- a/source/games/duke/src/zz_player.cpp +++ b/source/games/duke/src/zz_player.cpp @@ -712,6 +712,8 @@ void P_GetInputMotorcycle(int playerNum) } } +int boatApplyTurn(player_struct* p, int turnl, int turnr, int bike_turn, double factor); + void P_GetInputBoat(int playerNum) { auto &thisPlayer = g_player[playerNum]; @@ -813,68 +815,9 @@ void P_GetInputBoat(int playerNum) static int32_t lastInputClock; // MED int32_t const elapsedTics = (int32_t)totalclock - lastInputClock; - if (pPlayer->MotoSpeed != 0) - { - if (turnLeft || pPlayer->moto_drink < 0) - { - turnHeldTime += elapsedTics; - if (!pPlayer->NotOnWater) - { - pPlayer->TiltStatus -= scaleAdjustmentToInterval(1); - if (pPlayer->TiltStatus < -10) - pPlayer->TiltStatus = -10; - if (turnHeldTime >= TURBOTURNTIME) - input.q16avel = fix16_ssub(input.q16avel, fix16_from_dbl(scaleAdjustmentToInterval(turn ? 40 : 20))); - else - input.q16avel = fix16_ssub(input.q16avel, fix16_from_dbl(scaleAdjustmentToInterval(turn ? 12 : 6))); - } - else - if (turnHeldTime >= TURBOTURNTIME) - input.q16avel = fix16_ssub(input.q16avel, fix16_from_dbl(scaleAdjustmentToInterval(turn ? 12 : 6))); - else - input.q16avel = fix16_ssub(input.q16avel, fix16_from_dbl(scaleAdjustmentToInterval(turn ? 4 : 2))); - } - else if (turnRight || pPlayer->moto_drink > 0) - { - turnHeldTime += elapsedTics; - if (!pPlayer->NotOnWater) - { - pPlayer->TiltStatus += scaleAdjustmentToInterval(1); - if (pPlayer->TiltStatus > 10) - pPlayer->TiltStatus = 10; - if (turnHeldTime >= TURBOTURNTIME) - input.q16avel = fix16_sadd(input.q16avel, fix16_from_dbl(scaleAdjustmentToInterval(turn ? 40 : 20))); - else - input.q16avel = fix16_sadd(input.q16avel, fix16_from_dbl(scaleAdjustmentToInterval(turn ? 12 : 6))); - } - else - if (turnHeldTime >= TURBOTURNTIME) - input.q16avel = fix16_sadd(input.q16avel, fix16_from_dbl(scaleAdjustmentToInterval(turn ? 12 : 6))); - else - input.q16avel = fix16_sadd(input.q16avel, fix16_from_dbl(scaleAdjustmentToInterval(turn ? 4 : 2))); - } - else if (!pPlayer->NotOnWater) - { - turnHeldTime = 0; - - if (pPlayer->TiltStatus > 0) - pPlayer->TiltStatus -= scaleAdjustmentToInterval(1); - else if (pPlayer->TiltStatus < 0) - pPlayer->TiltStatus += scaleAdjustmentToInterval(1); - } - } - else if (!pPlayer->NotOnWater) - { - turnHeldTime = 0; - - if (pPlayer->TiltStatus > 0) - pPlayer->TiltStatus -= scaleAdjustmentToInterval(1); - else if (pPlayer->TiltStatus < 0) - pPlayer->TiltStatus += scaleAdjustmentToInterval(1); - } - - if (pPlayer->TiltStatus > -0.025 && pPlayer->TiltStatus < 0.025) - pPlayer->TiltStatus = 0; + // turn is truncated to integer precision to avoid having micro-movement affect the result, which makes a significant difference here. + int turnvel = boatApplyTurn(pPlayer, turnLeft, turnRight, turn >> FRACBITS, scaleAdjust); + input.q16avel += int(turnvel * scaleAdjust * FRACUNIT); input.fvel += pPlayer->MotoSpeed; input.q16avel = fix16_mul(input.q16avel, avelScale);