From e94ce88b275dedb91fc5ee9869a3c7afde825034 Mon Sep 17 00:00:00 2001 From: terminx Date: Wed, 29 Jan 2020 11:36:55 +0000 Subject: [PATCH] Use the saturating versions of the fix16 functions for player input git-svn-id: https://svn.eduke32.com/eduke32@8554 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/duke3d/src/player.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/source/duke3d/src/player.cpp b/source/duke3d/src/player.cpp index 3ff45b6a0..043d7c7cb 100644 --- a/source/duke3d/src/player.cpp +++ b/source/duke3d/src/player.cpp @@ -2954,18 +2954,18 @@ void P_GetInput(int const playerNum) } else { - input.q16avel += fix16_div(fix16_from_int(info.mousex), F16(32)); - input.q16avel += fix16_from_int(info.dyaw) / analogExtent * (analogTurnAmount << 1); + input.q16avel = fix16_sadd(input.q16avel, fix16_sdiv(fix16_from_int(info.mousex), F16(32))); + input.q16avel = fix16_sadd(input.q16avel, fix16_from_int(info.dyaw / analogExtent * (analogTurnAmount << 1))); } if (mouseaim) - input.q16horz += fix16_div(fix16_from_int(info.mousey), F16(64)); + input.q16horz = fix16_sadd(input.q16horz, fix16_sdiv(fix16_from_int(info.mousey), F16(64))); else input.fvel = -(info.mousey >> 3); if (!in_mouseflip) input.q16horz = -input.q16horz; - input.q16horz -= fix16_from_int(info.dpitch) / analogExtent * analogTurnAmount; + input.q16horz = fix16_ssub(input.q16horz, fix16_from_int(info.dpitch * analogTurnAmount / analogExtent)); input.svel -= info.dx * keyMove / analogExtent; input.fvel -= info.dz * keyMove / analogExtent; @@ -2999,12 +2999,12 @@ void P_GetInput(int const playerNum) if (buttonMap.ButtonDown(gamefunc_Turn_Left)) { turnHeldTime += elapsedTics; - input.q16avel -= fix16_from_float(scaleAdjustmentToInterval((turnHeldTime >= TURBOTURNTIME) ? (turnAmount << 1) : (PREAMBLETURN << 1))); + input.q16avel = fix16_ssub(input.q16avel, fix16_from_float(scaleAdjustmentToInterval((turnHeldTime >= TURBOTURNTIME) ? (turnAmount << 1) : (PREAMBLETURN << 1)))); } else if (buttonMap.ButtonDown(gamefunc_Turn_Right)) { turnHeldTime += elapsedTics; - input.q16avel += fix16_from_float(scaleAdjustmentToInterval((turnHeldTime >= TURBOTURNTIME) ? (turnAmount << 1) : (PREAMBLETURN << 1))); + input.q16avel = fix16_sadd(input.q16avel, fix16_from_float(scaleAdjustmentToInterval((turnHeldTime >= TURBOTURNTIME) ? (turnAmount << 1) : (PREAMBLETURN << 1)))); } else turnHeldTime = 0; @@ -3140,15 +3140,15 @@ void P_GetInput(int const playerNum) } else { - localInput.q16avel = fix16_add(localInput.q16avel, input.q16avel); - localInput.q16horz = fix16_clamp(fix16_add(localInput.q16horz, input.q16horz), F16(-MAXHORIZVEL), F16(MAXHORIZVEL)); + localInput.q16avel = fix16_sadd(localInput.q16avel, input.q16avel); + localInput.q16horz = fix16_clamp(fix16_sadd(localInput.q16horz, input.q16horz), F16(-MAXHORIZVEL), F16(MAXHORIZVEL)); localInput.fvel = clamp(localInput.fvel + input.fvel, -MAXVEL, MAXVEL); localInput.svel = clamp(localInput.svel + input.svel, -MAXSVEL, MAXSVEL); - pPlayer->q16ang = fix16_add(pPlayer->q16ang, input.q16avel); + pPlayer->q16ang = fix16_sadd(pPlayer->q16ang, input.q16avel); pPlayer->q16ang &= 0x7FFFFFF; - pPlayer->q16horiz = fix16_clamp(fix16_add(pPlayer->q16horiz, input.q16horz), F16(HORIZ_MIN), F16(HORIZ_MAX)); + pPlayer->q16horiz = fix16_clamp(fix16_sadd(pPlayer->q16horiz, input.q16horz), F16(HORIZ_MIN), F16(HORIZ_MAX)); } // A horiz diff of 128 equal 45 degrees, @@ -3162,7 +3162,7 @@ void P_GetInput(int const playerNum) } else if (pPlayer->return_to_center > 0 || g_horizRecenter) { - pPlayer->q16horiz += fix16_from_float(scaleAdjustmentToInterval(fix16_to_float(F16(66.666) - fix16_div(pPlayer->q16horiz, F16(1.5))))); + pPlayer->q16horiz = fix16_sadd(pPlayer->q16horiz, fix16_from_float(scaleAdjustmentToInterval(fix16_to_float(F16(66.666) - fix16_sdiv(pPlayer->q16horiz, F16(1.5)))))); if ((!pPlayer->return_to_center && g_horizRecenter) || (pPlayer->q16horiz >= F16(99.9) && pPlayer->q16horiz <= F16(100.1))) { @@ -3188,23 +3188,23 @@ void P_GetInput(int const playerNum) { int const slopeZ = getflorzofslope(pPlayer->cursectnum, adjustedPosition.x, adjustedPosition.y); if ((pPlayer->cursectnum == currentSector) || (klabs(getflorzofslope(currentSector, adjustedPosition.x, adjustedPosition.y) - slopeZ) <= ZOFFSET6)) - pPlayer->q16horizoff += fix16_from_float(scaleAdjustmentToInterval(mulscale16(pPlayer->truefz - slopeZ, 160))); + pPlayer->q16horizoff = fix16_sadd(pPlayer->q16horizoff, fix16_from_float(scaleAdjustmentToInterval(mulscale16(pPlayer->truefz - slopeZ, 160)))); } } if (pPlayer->q16horizoff > 0) { - pPlayer->q16horizoff -= fix16_from_float(scaleAdjustmentToInterval(fix16_to_float((pPlayer->q16horizoff >> 3) + fix16_one))); + pPlayer->q16horizoff = fix16_ssub(pPlayer->q16horizoff, fix16_from_float(scaleAdjustmentToInterval(fix16_to_float((pPlayer->q16horizoff >> 3) + fix16_one)))); pPlayer->q16horizoff = fix16_max(pPlayer->q16horizoff, 0); } else if (pPlayer->q16horizoff < 0) { - pPlayer->q16horizoff += fix16_from_float(scaleAdjustmentToInterval(fix16_to_float((-pPlayer->q16horizoff >> 3) + fix16_one))); + pPlayer->q16horizoff = fix16_sadd(pPlayer->q16horizoff, fix16_from_float(scaleAdjustmentToInterval(fix16_to_float((-pPlayer->q16horizoff >> 3) + fix16_one)))); pPlayer->q16horizoff = fix16_min(pPlayer->q16horizoff, 0); } if (g_horizSkew) - pPlayer->q16horiz += fix16_from_float(scaleAdjustmentToInterval(fix16_to_float(g_horizSkew))); + pPlayer->q16horiz = fix16_sadd(pPlayer->q16horiz, fix16_from_float(scaleAdjustmentToInterval(fix16_to_float(g_horizSkew)))); pPlayer->q16horiz = fix16_clamp(pPlayer->q16horiz, F16(HORIZ_MIN), F16(HORIZ_MAX)); }