diff --git a/source/rr/src/game.cpp b/source/rr/src/game.cpp index 276881fc3..aef87308e 100644 --- a/source/rr/src/game.cpp +++ b/source/rr/src/game.cpp @@ -1123,11 +1123,8 @@ void G_DrawRooms(int32_t playerNum, int32_t smoothRatio) omypos.z + mulscale16(mypos.z - omypos.z, smoothRatio) }; CAMERA(pos) = camVect; - CAMERA(q16ang) = omyang - + mulscale16(((myang + F16(1024) - omyang) & 0x7FFFFFF) - F16(1024), smoothRatio) - + fix16_from_int(pPlayer->look_ang); - CAMERA(q16horiz) = omyhoriz + omyhorizoff - + mulscale16((myhoriz + myhorizoff - omyhoriz - omyhorizoff), smoothRatio); + CAMERA(q16ang) = myang + fix16_from_int(pPlayer->look_ang); + CAMERA(q16horiz) = myhoriz + myhorizoff; CAMERA(sect) = mycursectnum; } else @@ -1137,11 +1134,8 @@ void G_DrawRooms(int32_t playerNum, int32_t smoothRatio) pPlayer->opos.z + mulscale16(pPlayer->pos.z - pPlayer->opos.z, smoothRatio) }; CAMERA(pos) = camVect; - CAMERA(q16ang) = pPlayer->oq16ang - + mulscale16(((pPlayer->q16ang + F16(1024) - pPlayer->oq16ang) & 0x7FFFFFF) - F16(1024), smoothRatio) - + fix16_from_int(pPlayer->look_ang); - CAMERA(q16horiz) = pPlayer->oq16horiz + pPlayer->oq16horizoff - + mulscale16((pPlayer->q16horiz + pPlayer->q16horizoff - pPlayer->oq16horiz - pPlayer->oq16horizoff), smoothRatio); + CAMERA(q16ang) = pPlayer->q16ang + fix16_from_int(pPlayer->look_ang); + CAMERA(q16horiz) = pPlayer->q16horiz + pPlayer->q16horizoff; } if (cl_viewbob) @@ -7428,7 +7422,6 @@ MAIN_LOOP_RESTART: frameJustDrawn = false; -#ifdef NETCODE_DISABLE if (RRRA && g_player[myconnectindex].ps->on_motorcycle) P_GetInputMotorcycle(myconnectindex); else if (RRRA && g_player[myconnectindex].ps->on_boat) @@ -7436,14 +7429,25 @@ MAIN_LOOP_RESTART: else P_GetInput(myconnectindex); - inputfifo[g_player[myconnectindex].movefifoend&(MOVEFIFOSIZ-1)][myconnectindex] = localInput; + // this is where we fill the input_t struct that is actually processed by P_ProcessInput() + auto const pPlayer = g_player[myconnectindex].ps; + int16_t const q16ang = fix16_to_int(pPlayer->q16ang); + auto & input = inputfifo[g_player[myconnectindex].movefifoend&(MOVEFIFOSIZ-1)][myconnectindex]; + + input = localInput; + input.fvel = mulscale9(localInput.fvel, sintable[(q16ang + 2560) & 2047]) + + mulscale9(localInput.svel, sintable[(q16ang + 2048) & 2047]) + + pPlayer->fric.x; + input.svel = mulscale9(localInput.fvel, sintable[(q16ang + 2048) & 2047]) + + mulscale9(localInput.svel, sintable[(q16ang + 1536) & 2047]) + + pPlayer->fric.y; + localInput = {}; + g_player[myconnectindex].movefifoend++; -#endif do { if (ready2send == 0) break; - Net_GetInput(); ototalclock += TICSPERFRAME; @@ -7490,6 +7494,13 @@ MAIN_LOOP_RESTART: } else */if (G_FPSLimit()) { + if (RRRA && g_player[myconnectindex].ps->on_motorcycle) + P_GetInputMotorcycle(myconnectindex); + else if (RRRA && g_player[myconnectindex].ps->on_boat) + P_GetInputBoat(myconnectindex); + else + P_GetInput(myconnectindex); + int const smoothRatio = calc_smoothratio(totalclock, ototalclock); G_DrawRooms(screenpeek, smoothRatio); diff --git a/source/rr/src/player.cpp b/source/rr/src/player.cpp index cf35ec919..d69bf581d 100644 --- a/source/rr/src/player.cpp +++ b/source/rr/src/player.cpp @@ -3156,13 +3156,13 @@ enddisplayweapon: } #define TURBOTURNTIME (TICRATE/8) // 7 -#define NORMALTURN 15 -#define PREAMBLETURN 5 +#define NORMALTURN 15 +#define PREAMBLETURN 5 #define NORMALKEYMOVE 40 -#define MAXVEL ((NORMALKEYMOVE*2)+10) -#define MAXSVEL ((NORMALKEYMOVE*2)+10) -#define MAXANGVEL 1024 -#define MAXHORIZ 256 +#define MAXVEL ((NORMALKEYMOVE*2)+10) +#define MAXSVEL ((NORMALKEYMOVE*2)+10) +#define MAXANGVEL 1024 +#define MAXHORIZVEL 256 int32_t g_myAimStat = 0, g_oldAimStat = 0; int32_t mouseyaxismode = -1; @@ -3170,12 +3170,16 @@ int32_t mouseyaxismode = -1; static int P_CheckLockedMovement(int const playerNum) { auto const pPlayer = g_player[playerNum].ps; - return (pPlayer->fist_incs || pPlayer->transporter_hold > 2 || pPlayer->hard_landing || pPlayer->access_incs > 0 || pPlayer->knee_incs > 0 + return (pPlayer->dead_flag || pPlayer->fist_incs || pPlayer->transporter_hold > 2 || pPlayer->hard_landing || pPlayer->access_incs > 0 || pPlayer->knee_incs > 0 || (PWEAPON(playerNum, pPlayer->curr_weapon, WorksLike) == TRIPBOMB_WEAPON && pPlayer->kickback_pic > 1 && pPlayer->kickback_pic < PWEAPON(playerNum, pPlayer->curr_weapon, FireDelay))); } -void P_GetInput(int playerNum) +static bool g_horizRecenter; +static float g_horizAngleAdjust; +static fix16_t g_horizSkew; + +void P_GetInput(int const playerNum) { auto const pPlayer = g_player[playerNum].ps; ControlInfo info; @@ -3185,8 +3189,7 @@ void P_GetInput(int playerNum) if (!(pPlayer->gm&MODE_MENU)) CONTROL_GetInput(&info); - Bmemset(&localInput, 0, sizeof(input_t)); - + localInput = {}; localInput.bits = (((int32_t)g_gameQuit) << SK_GAMEQUIT); localInput.extbits |= (1 << 7); @@ -3210,11 +3213,11 @@ void P_GetInput(int playerNum) // JBF: Run key behaviour is selectable - int const playerRunning = G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run)); - int const turnAmount = playerRunning ? (NORMALTURN << 1) : NORMALTURN; - constexpr int const analogTurnAmount = (NORMALTURN << 1); - int const keyMove = playerRunning ? (NORMALKEYMOVE << 1) : NORMALKEYMOVE; - constexpr int const analogExtent = 32767; // KEEPINSYNC sdlayer.cpp + int const playerRunning = G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run)); + int const turnAmount = playerRunning ? (NORMALTURN << 1) : NORMALTURN; + constexpr int analogTurnAmount = (NORMALTURN << 1); + int const keyMove = playerRunning ? (NORMALKEYMOVE << 1) : NORMALKEYMOVE; + constexpr int analogExtent = 32767; // KEEPINSYNC sdlayer.cpp input_t input {}; @@ -3229,12 +3232,12 @@ void P_GetInput(int playerNum) } else { - input.q16avel = fix16_div(fix16_from_int(info.mousex), F16(32)); + input.q16avel += fix16_div(fix16_from_int(info.mousex), F16(32)); 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_div(fix16_from_int(info.mousey), F16(64)); else input.fvel = -(info.mousey >> 3); @@ -3244,95 +3247,106 @@ void P_GetInput(int playerNum) input.svel -= info.dx * keyMove / analogExtent; input.fvel -= info.dz * keyMove / analogExtent; + static double lastInputTicks; + auto const currentHiTicks = timerGetHiTicks(); + double const elapsedInputTicks = currentHiTicks - lastInputTicks; + + lastInputTicks = currentHiTicks; + + auto scaleAdjustmentToInterval = [=](double x) { return x * REALGAMETICSPERSEC / (1000.0 / elapsedInputTicks); }; + if (buttonMap.ButtonDown(gamefunc_Strafe)) { - if (buttonMap.ButtonDown(gamefunc_Turn_Left) && !(pPlayer->movement_lock&4)) - input.svel -= -keyMove; + if (!localInput.svel) + { + if (buttonMap.ButtonDown(gamefunc_Turn_Left) && !(pPlayer->movement_lock & 4) && !localInput.svel) + input.svel = -keyMove; - if (buttonMap.ButtonDown(gamefunc_Turn_Right) && !(pPlayer->movement_lock&8)) - input.svel -= keyMove; + if (buttonMap.ButtonDown(gamefunc_Turn_Right) && !(pPlayer->movement_lock & 8) && !localInput.svel) + input.svel = keyMove; + } } else { - static int32_t turnHeldTime = 0; - static int32_t lastInputClock = 0; // MED - int32_t const elapsedTics = (int32_t) totalclock - lastInputClock; + static int32_t turnHeldTime; + static int32_t lastInputClock; // MED + int32_t const elapsedTics = (int32_t)totalclock - lastInputClock; lastInputClock = (int32_t) totalclock; if (buttonMap.ButtonDown(gamefunc_Turn_Left)) { turnHeldTime += elapsedTics; - input.q16avel -= fix16_from_int((turnHeldTime >= TURBOTURNTIME) ? (turnAmount << 1) : (PREAMBLETURN << 1)); + 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_int((turnHeldTime >= TURBOTURNTIME) ? (turnAmount << 1) : (PREAMBLETURN << 1)); + input.q16avel += fix16_from_float(scaleAdjustmentToInterval((turnHeldTime >= TURBOTURNTIME) ? (turnAmount << 1) : (PREAMBLETURN << 1))); } else - turnHeldTime=0; + turnHeldTime = 0; } - if (buttonMap.ButtonDown(gamefunc_Strafe_Left) && !(pPlayer->movement_lock & 4)) - input.svel += keyMove; - - if (buttonMap.ButtonDown(gamefunc_Strafe_Right) && !(pPlayer->movement_lock & 8)) - input.svel += -keyMove; - - if (RR) + if (localInput.svel < keyMove && localInput.svel > -keyMove) { - /*if (buttonMap.ButtonDown(gamefunc_Quick_Kick)) - { - localInput.bits |= buttonMap.ButtonDown(gamefunc_Move_Forward)<drink_amt >= 66 && pPlayer->drink_amt <= 87) - { - if (buttonMap.ButtonDown(gamefunc_Move_Forward)) - { - input.fvel += keyMove; - if (pPlayer->drink_amt & 1) - input.svel += keyMove; - else - input.svel -= keyMove; - } + if (buttonMap.ButtonDown(gamefunc_Strafe_Left) && !(pPlayer->movement_lock & 4)) + input.svel += keyMove; - if (buttonMap.ButtonDown(gamefunc_Move_Backward)) + if (buttonMap.ButtonDown(gamefunc_Strafe_Right) && !(pPlayer->movement_lock & 8)) + input.svel += -keyMove; + } + + if (localInput.fvel < keyMove && localInput.fvel > -keyMove) + { + if (RR) + { + /*if (buttonMap.ButtonDown(gamefunc_Quick_Kick)) + { + localInput.bits |= buttonMap.ButtonDown(gamefunc_Move_Forward)<drink_amt >= 66 && pPlayer->drink_amt <= 87) { - input.fvel += -keyMove; - if (pPlayer->drink_amt & 1) - input.svel -= keyMove; - else - input.svel += keyMove; + if (buttonMap.ButtonDown(gamefunc_Move_Forward)) + { + input.fvel += keyMove; + if (pPlayer->drink_amt & 1) + input.svel += keyMove; + else + input.svel -= keyMove; + } + + if (buttonMap.ButtonDown(gamefunc_Move_Backward)) + { + input.fvel += -keyMove; + if (pPlayer->drink_amt & 1) + input.svel -= keyMove; + else + input.svel += keyMove; + } + } + else + { + if (buttonMap.ButtonDown(gamefunc_Move_Forward)) + input.fvel += keyMove; + + if (buttonMap.ButtonDown(gamefunc_Move_Backward)) + input.fvel += -keyMove; } } - else - { - if (buttonMap.ButtonDown(gamefunc_Move_Forward)) - input.fvel += keyMove; + } + else + { + if (buttonMap.ButtonDown(gamefunc_Move_Forward) && !(pPlayer->movement_lock & 1)) + input.fvel += keyMove; - if (buttonMap.ButtonDown(gamefunc_Move_Backward)) - input.fvel += -keyMove; - } + if (buttonMap.ButtonDown(gamefunc_Move_Backward) && !(pPlayer->movement_lock & 2)) + input.fvel += -keyMove; } } - else - { - if (buttonMap.ButtonDown(gamefunc_Move_Forward) && !(g_player[playerNum].ps->movement_lock & 1)) - input.fvel += keyMove; - - if (buttonMap.ButtonDown(gamefunc_Move_Backward) && !(g_player[playerNum].ps->movement_lock & 2)) - input.fvel += -keyMove; - } - - input.fvel = clamp(input.fvel, -MAXVEL, MAXVEL); - input.svel = clamp(input.svel, -MAXSVEL, MAXSVEL); - - input.q16avel = fix16_clamp(input.q16avel, F16(-MAXANGVEL), F16(MAXANGVEL)); - input.q16horz = fix16_clamp(input.q16horz, F16(-MAXHORIZ), F16(MAXHORIZ)); int weaponSelection; @@ -3356,7 +3370,10 @@ void P_GetInput(int playerNum) else if (weaponSelection == gamefunc_Weapon_1-1) weaponSelection = 0; - localInput.bits = (weaponSelection << SK_WEAPON_BITS) | (buttonMap.ButtonDown(gamefunc_Fire) << SK_FIRE); + if ((localInput.bits & 0xf00) == 0) + localInput.bits |= (weaponSelection << SK_WEAPON_BITS); + + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Fire) << SK_FIRE); localInput.bits |= (buttonMap.ButtonDown(gamefunc_Open) << SK_OPEN); int const sectorLotag = pPlayer->cursectnum != -1 ? sector[pPlayer->cursectnum].lotag : 0; @@ -3422,39 +3439,96 @@ void P_GetInput(int playerNum) else if (buttonMap.ButtonDown(gamefunc_Dpad_Aiming)) input.fvel = 0; - localInput.extbits = (buttonMap.ButtonDown(gamefunc_Move_Forward) || (input.fvel > 0)); + localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Move_Forward) || (input.fvel > 0)); localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Move_Backward) || (input.fvel < 0)) << 1; localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Strafe_Left) || (input.svel > 0)) << 2; localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Strafe_Right) || (input.svel < 0)) << 3; localInput.extbits |= buttonMap.ButtonDown(gamefunc_Turn_Left)<<4; localInput.extbits |= buttonMap.ButtonDown(gamefunc_Turn_Right)<<5; - if (ud.scrollmode && ud.overhead_on) + if ((ud.scrollmode && ud.overhead_on) || P_CheckLockedMovement(playerNum)) { - ud.folfvel = input.fvel; - ud.folavel = fix16_to_int(input.q16avel); + if (ud.scrollmode && ud.overhead_on) + { + ud.folfvel = input.fvel; + ud.folavel = fix16_to_int(input.q16avel); + } localInput.fvel = 0; localInput.svel = 0; localInput.q16avel = 0; localInput.q16horz = 0; + } + else + { + localInput.q16avel = fix16_add(localInput.q16avel, input.q16avel); + localInput.q16horz = fix16_clamp(fix16_add(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); - return; + pPlayer->q16ang = fix16_add(pPlayer->q16ang, input.q16avel); + pPlayer->q16ang &= 0x7FFFFFF; + + pPlayer->q16horiz = fix16_clamp(fix16_add(pPlayer->q16horiz, input.q16horz), F16(HORIZ_MIN), F16(HORIZ_MAX)); } - int16_t const q16ang = fix16_to_int(pPlayer->q16ang); + // A horiz diff of 128 equal 45 degrees, + // so we convert horiz to 1024 angle units - localInput.fvel = mulscale9(input.fvel, sintable[(q16ang + 2560) & 2047]) + - mulscale9(input.svel, sintable[(q16ang + 2048) & 2047]) + - pPlayer->fric.x; + if (g_horizAngleAdjust) + { + float const horizAngle + = atan2f(pPlayer->q16horiz - F16(100), F16(128)) * (512.f / fPI) + scaleAdjustmentToInterval(g_horizAngleAdjust); + pPlayer->q16horiz = F16(100) + Blrintf(F16(128) * tanf(horizAngle * (fPI / 512.f))); + } + else if (pPlayer->return_to_center > 0 || g_horizRecenter) + { + pPlayer->q16horiz += fix16_from_float(scaleAdjustmentToInterval(fix16_to_float(F16(33) - fix16_div(pPlayer->q16horiz, F16(3))))); - localInput.svel = mulscale9(input.fvel, sintable[(q16ang + 2048) & 2047]) + - mulscale9(input.svel, sintable[(q16ang + 1536) & 2047]) + - pPlayer->fric.y; + if (pPlayer->q16horiz >= F16(99.9) && pPlayer->q16horiz <= F16(100.1)) + { + pPlayer->q16horiz = F16(100); + g_horizRecenter = 0; + } - localInput.q16avel = input.q16avel; - localInput.q16horz = input.q16horz; + if (pPlayer->q16horizoff >= F16(-0.1) && pPlayer->q16horizoff <= F16(0.1)) + pPlayer->q16horizoff = 0; + } + + // calculates automatic view angle for playing without a mouse + if (!pPlayer->aim_mode && pPlayer->on_ground && sectorLotag != ST_2_UNDERWATER && (sector[pPlayer->cursectnum].floorstat & 2)) + { + // this is some kind of horse shit approximation of where the player is looking, I guess? + vec2_t const adjustedPosition = { pPlayer->pos.x + (sintable[(fix16_to_int(pPlayer->q16ang) + 512) & 2047] >> 5), + pPlayer->pos.y + (sintable[fix16_to_int(pPlayer->q16ang) & 2047] >> 5) }; + int16_t currentSector = pPlayer->cursectnum; + + updatesector(adjustedPosition.x, adjustedPosition.y, ¤tSector); + + if (currentSector >= 0) + { + 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))); + } + } + + if (pPlayer->q16horizoff > 0) + { + 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_min(pPlayer->q16horizoff, 0); + } + + if (g_horizSkew) + pPlayer->q16horiz += fix16_from_float(scaleAdjustmentToInterval(fix16_to_float(g_horizSkew))); + + pPlayer->q16horiz = fix16_clamp(pPlayer->q16horiz, F16(HORIZ_MIN), F16(HORIZ_MAX)); } void P_GetInputMotorcycle(int playerNum) @@ -3467,8 +3541,7 @@ void P_GetInputMotorcycle(int playerNum) if (!(pPlayer->gm&MODE_MENU)) CONTROL_GetInput(&info); - Bmemset(&localInput, 0, sizeof(input_t)); - + localInput = {}; localInput.bits = (((int32_t)g_gameQuit) << SK_GAMEQUIT); localInput.extbits |= (1 << 7); @@ -3489,17 +3562,17 @@ void P_GetInputMotorcycle(int playerNum) CONTROL_GetInput(&info); // JBF: Run key behaviour is selectable - int const playerRunning = G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run)); - constexpr int const analogTurnAmount = (NORMALTURN << 1); - int const keyMove = playerRunning ? (NORMALKEYMOVE << 1) : NORMALKEYMOVE; - constexpr int const analogExtent = 32767; // KEEPINSYNC sdlayer.cpp + int const playerRunning = G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run)); + constexpr int analogTurnAmount = (NORMALTURN << 1); + int const keyMove = playerRunning ? (NORMALKEYMOVE << 1) : NORMALKEYMOVE; + constexpr int analogExtent = 32767; // KEEPINSYNC sdlayer.cpp input_t input {}; - input.q16avel = fix16_div(fix16_from_int(info.mousex), F16(32)); + input.q16avel += fix16_div(fix16_from_int(info.mousex), F16(32)); input.q16avel += fix16_from_int(info.dyaw) / analogExtent * (analogTurnAmount << 1); - input.q16horz = fix16_div(fix16_from_int(info.mousey), F16(64)); + input.q16horz += fix16_div(fix16_from_int(info.mousey), F16(64)); if (!in_mouseflip) input.q16horz = -input.q16horz; @@ -3507,15 +3580,17 @@ void P_GetInputMotorcycle(int playerNum) input.svel -= info.dx * keyMove / analogExtent; input.fvel -= info.dz * keyMove / analogExtent; - input.fvel = clamp(input.fvel, -MAXVEL, MAXVEL); - input.svel = clamp(input.svel, -MAXSVEL, MAXSVEL); + static double lastInputTicks; + auto const currentHiTicks = timerGetHiTicks(); + double const elapsedInputTicks = currentHiTicks - lastInputTicks; - input.q16avel = fix16_clamp(input.q16avel, F16(-MAXANGVEL), F16(MAXANGVEL)); - input.q16horz = fix16_clamp(input.q16horz, F16(-MAXHORIZ), F16(MAXHORIZ)); + lastInputTicks = currentHiTicks; + + auto scaleAdjustmentToInterval = [=](double x) { return x * REALGAMETICSPERSEC / (1000.0 / elapsedInputTicks); }; pPlayer->crouch_toggle = 0; - localInput.bits = buttonMap.ButtonDown(gamefunc_Fire) << SK_FIRE; + localInput.bits |= buttonMap.ButtonDown(gamefunc_Fire) << SK_FIRE; localInput.bits |= buttonMap.ButtonDown(gamefunc_Steroids) << SK_STEROIDS; localInput.bits |= buttonMap.ButtonDown(gamefunc_NightVision) << SK_NIGHTVISION; localInput.bits |= buttonMap.ButtonDown(gamefunc_MedKit) << SK_MEDKIT; @@ -3541,7 +3616,7 @@ void P_GetInputMotorcycle(int playerNum) if (buttonMap.ButtonDown(gamefunc_Dpad_Aiming)) input.fvel = 0; - localInput.extbits = (buttonMap.ButtonDown(gamefunc_Move_Forward) || (input.fvel > 0)); + localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Move_Forward) || (input.fvel > 0)); localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Move_Backward) || (input.fvel < 0)) << 1; localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Strafe_Left) || (input.svel > 0)) << 2; localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Strafe_Right) || (input.svel < 0)) << 3; @@ -3571,9 +3646,9 @@ void P_GetInputMotorcycle(int playerNum) localInput.bits |= turnLeft << SK_AIM_DOWN; localInput.bits |= turnRight << SK_LOOK_LEFT; - static int32_t turnHeldTime = 0; - static int32_t lastInputClock = 0; // MED - int32_t const elapsedTics = (int32_t) totalclock - lastInputClock; + static int32_t turnHeldTime; + static int32_t lastInputClock; // MED + int32_t const elapsedTics = (int32_t)totalclock - lastInputClock; int const moveBack = buttonMap.ButtonDown(gamefunc_Move_Backward) && pPlayer->moto_speed <= 0; @@ -3694,34 +3769,71 @@ void P_GetInputMotorcycle(int playerNum) input.fvel += pPlayer->moto_speed; - input.fvel = clamp(input.fvel, -15, 120); - input.svel = clamp(input.svel, -MAXSVEL, MAXSVEL); - input.q16avel = fix16_clamp(input.q16avel, F16(-MAXANGVEL), F16(MAXANGVEL)); - input.q16horz = fix16_clamp(input.q16horz, F16(-MAXHORIZ), F16(MAXHORIZ)); - - if (ud.scrollmode && ud.overhead_on) + if ((ud.scrollmode && ud.overhead_on) || P_CheckLockedMovement(playerNum)) { - ud.folfvel = input.fvel; - ud.folavel = fix16_to_int(input.q16avel); - localInput.fvel = 0; - localInput.svel = 0; - localInput.q16avel = 0; - localInput.q16horz = 0; - return; + if (ud.scrollmode && ud.overhead_on) + { + ud.folfvel = input.fvel; + ud.folavel = fix16_to_int(input.q16avel); + } + + localInput.fvel = 0; + localInput.svel = 0; + + localInput.q16avel = 0; + localInput.q16horz = 0; + } + else + { + localInput.q16avel = fix16_add(localInput.q16avel, input.q16avel); + localInput.q16horz = fix16_clamp(fix16_add(localInput.q16horz, input.q16horz), F16(-MAXHORIZVEL), F16(MAXHORIZVEL)); + localInput.fvel = clamp(localInput.fvel + input.fvel, -15, 120); + localInput.svel = clamp(localInput.svel + input.svel, -MAXSVEL, MAXSVEL); + + pPlayer->q16ang = fix16_add(pPlayer->q16ang, input.q16avel); + pPlayer->q16ang &= 0x7FFFFFF; + + pPlayer->q16horiz = fix16_clamp(fix16_add(pPlayer->q16horiz, input.q16horz), F16(HORIZ_MIN), F16(HORIZ_MAX)); } - int16_t const q16ang = fix16_to_int(pPlayer->q16ang); + // A horiz diff of 128 equal 45 degrees, + // so we convert horiz to 1024 angle units - localInput.fvel = mulscale9(input.fvel, sintable[(q16ang + 2560) & 2047]) + - mulscale9(input.svel, sintable[(q16ang + 2048) & 2047]) + - pPlayer->fric.x; + if (g_horizAngleAdjust) + { + float const horizAngle + = atan2f(pPlayer->q16horiz - F16(100), F16(128)) * (512.f / fPI) + scaleAdjustmentToInterval(g_horizAngleAdjust); + pPlayer->q16horiz = F16(100) + Blrintf(F16(128) * tanf(horizAngle * (fPI / 512.f))); + } + else if (pPlayer->return_to_center > 0 || g_horizRecenter) + { + pPlayer->q16horiz += fix16_from_float(scaleAdjustmentToInterval(fix16_to_float(F16(33) - fix16_div(pPlayer->q16horiz, F16(3))))); - localInput.svel = mulscale9(input.fvel, sintable[(q16ang + 2048) & 2047]) + - mulscale9(input.svel, sintable[(q16ang + 1536) & 2047]) + - pPlayer->fric.y; + if (pPlayer->q16horiz >= F16(99.9) && pPlayer->q16horiz <= F16(100.1)) + { + pPlayer->q16horiz = F16(100); + g_horizRecenter = 0; + } - localInput.q16avel = input.q16avel; - localInput.q16horz = input.q16horz; + if (pPlayer->q16horizoff >= F16(-0.1) && pPlayer->q16horizoff <= F16(0.1)) + pPlayer->q16horizoff = 0; + } + + if (pPlayer->q16horizoff > 0) + { + 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_min(pPlayer->q16horizoff, 0); + } + + if (g_horizSkew) + pPlayer->q16horiz += fix16_from_float(scaleAdjustmentToInterval(fix16_to_float(g_horizSkew))); + + pPlayer->q16horiz = fix16_clamp(pPlayer->q16horiz, F16(HORIZ_MIN), F16(HORIZ_MAX)); if (TEST_SYNC_KEY(localInput.bits, SK_JUMP)) { @@ -3739,8 +3851,7 @@ void P_GetInputBoat(int playerNum) if (!(pPlayer->gm&MODE_MENU)) CONTROL_GetInput(&info); - Bmemset(&localInput, 0, sizeof(input_t)); - + localInput = {}; localInput.bits = (((int32_t)g_gameQuit) << SK_GAMEQUIT); localInput.extbits |= (1 << 7); @@ -3761,17 +3872,17 @@ void P_GetInputBoat(int playerNum) CONTROL_GetInput(&info); // JBF: Run key behaviour is selectable - int const playerRunning = G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run)); - constexpr int const analogTurnAmount = (NORMALTURN << 1); - int const keyMove = playerRunning ? (NORMALKEYMOVE << 1) : NORMALKEYMOVE; - constexpr int const analogExtent = 32767; // KEEPINSYNC sdlayer.cpp + int const playerRunning = G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run)); + constexpr int analogTurnAmount = (NORMALTURN << 1); + int const keyMove = playerRunning ? (NORMALKEYMOVE << 1) : NORMALKEYMOVE; + constexpr int analogExtent = 32767; // KEEPINSYNC sdlayer.cpp input_t input {}; - input.q16avel = fix16_div(fix16_from_int(info.mousex), F16(32)); + input.q16avel += fix16_div(fix16_from_int(info.mousex), F16(32)); input.q16avel += fix16_from_int(info.dyaw) / analogExtent * (analogTurnAmount << 1); - input.q16horz = fix16_div(fix16_from_int(info.mousey), F16(64)); + input.q16horz += fix16_div(fix16_from_int(info.mousey), F16(64)); if (!in_mouseflip) input.q16horz = -input.q16horz; @@ -3779,15 +3890,17 @@ void P_GetInputBoat(int playerNum) input.svel -= info.dx * keyMove / analogExtent; input.fvel -= info.dz * keyMove / analogExtent; - input.fvel = clamp(input.fvel, -MAXVEL, MAXVEL); - input.svel = clamp(input.svel, -MAXSVEL, MAXSVEL); + static double lastInputTicks; + auto const currentHiTicks = timerGetHiTicks(); + double const elapsedInputTicks = currentHiTicks - lastInputTicks; - input.q16avel = fix16_clamp(input.q16avel, F16(-MAXANGVEL), F16(MAXANGVEL)); - input.q16horz = fix16_clamp(input.q16horz, F16(-MAXHORIZ), F16(MAXHORIZ)); + lastInputTicks = currentHiTicks; + + auto scaleAdjustmentToInterval = [=](double x) { return x * REALGAMETICSPERSEC / (1000.0 / elapsedInputTicks); }; pPlayer->crouch_toggle = 0; - localInput.bits = buttonMap.ButtonDown(gamefunc_Fire) << SK_FIRE; + localInput.bits |= buttonMap.ButtonDown(gamefunc_Fire) << SK_FIRE; localInput.bits |= buttonMap.ButtonDown(gamefunc_Steroids) << SK_STEROIDS; localInput.bits |= buttonMap.ButtonDown(gamefunc_NightVision) << SK_NIGHTVISION; localInput.bits |= buttonMap.ButtonDown(gamefunc_MedKit) << SK_MEDKIT; @@ -3813,7 +3926,7 @@ void P_GetInputBoat(int playerNum) if (buttonMap.ButtonDown(gamefunc_Dpad_Aiming)) input.fvel = 0; - localInput.extbits = (buttonMap.ButtonDown(gamefunc_Move_Forward) || (input.fvel > 0)); + localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Move_Forward) || (input.fvel > 0)); localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Move_Backward) || (input.fvel < 0)) << 1; localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Strafe_Left) || (input.svel > 0)) << 2; localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Strafe_Right) || (input.svel < 0)) << 3; @@ -3840,9 +3953,9 @@ void P_GetInputBoat(int playerNum) localInput.bits |= turnLeft << SK_AIM_DOWN; localInput.bits |= turnRight << SK_LOOK_LEFT; - static int32_t turnHeldTime = 0; - static int32_t lastInputClock = 0; // MED - int32_t const elapsedTics = (int32_t) totalclock - lastInputClock; + static int32_t turnHeldTime; + static int32_t lastInputClock; // MED + int32_t const elapsedTics = (int32_t)totalclock - lastInputClock; if (pPlayer->moto_speed != 0) { @@ -3958,34 +4071,71 @@ void P_GetInputBoat(int playerNum) input.q16avel = fix16_mul(input.q16avel, avelScale); - input.fvel = clamp(input.fvel, -15, 120); - input.svel = clamp(input.svel, -MAXSVEL, MAXSVEL); - input.q16avel = fix16_clamp(input.q16avel, F16(-MAXANGVEL), F16(MAXANGVEL)); - input.q16horz = fix16_clamp(input.q16horz, F16(-MAXHORIZ), F16(MAXHORIZ)); - - if (ud.scrollmode && ud.overhead_on) + if ((ud.scrollmode && ud.overhead_on) || P_CheckLockedMovement(playerNum)) { - ud.folfvel = input.fvel; - ud.folavel = fix16_to_int(input.q16avel); - localInput.fvel = 0; - localInput.svel = 0; - localInput.q16avel = 0; - localInput.q16horz = 0; - return; + if (ud.scrollmode && ud.overhead_on) + { + ud.folfvel = input.fvel; + ud.folavel = fix16_to_int(input.q16avel); + } + + localInput.fvel = 0; + localInput.svel = 0; + + localInput.q16avel = 0; + localInput.q16horz = 0; + } + else + { + localInput.q16avel = fix16_add(localInput.q16avel, input.q16avel); + localInput.q16horz = fix16_clamp(fix16_add(localInput.q16horz, input.q16horz), F16(-MAXHORIZVEL), F16(MAXHORIZVEL)); + localInput.fvel = clamp(localInput.fvel + input.fvel, -15, 120); + localInput.svel = clamp(localInput.svel + input.svel, -MAXSVEL, MAXSVEL); + + pPlayer->q16ang = fix16_add(pPlayer->q16ang, input.q16avel); + pPlayer->q16ang &= 0x7FFFFFF; + + pPlayer->q16horiz = fix16_clamp(fix16_add(pPlayer->q16horiz, input.q16horz), F16(HORIZ_MIN), F16(HORIZ_MAX)); } - int16_t const q16ang = fix16_to_int(pPlayer->q16ang); + // A horiz diff of 128 equal 45 degrees, + // so we convert horiz to 1024 angle units - localInput.fvel = mulscale9(input.fvel, sintable[(q16ang + 2560) & 2047]) + - mulscale9(input.svel, sintable[(q16ang + 2048) & 2047]) + - pPlayer->fric.x; + if (g_horizAngleAdjust) + { + float const horizAngle + = atan2f(pPlayer->q16horiz - F16(100), F16(128)) * (512.f / fPI) + scaleAdjustmentToInterval(g_horizAngleAdjust); + pPlayer->q16horiz = F16(100) + Blrintf(F16(128) * tanf(horizAngle * (fPI / 512.f))); + } + else if (pPlayer->return_to_center > 0 || g_horizRecenter) + { + pPlayer->q16horiz += fix16_from_float(scaleAdjustmentToInterval(fix16_to_float(F16(33) - fix16_div(pPlayer->q16horiz, F16(3))))); - localInput.svel = mulscale9(input.fvel, sintable[(q16ang + 2048) & 2047]) + - mulscale9(input.svel, sintable[(q16ang + 1536) & 2047]) + - pPlayer->fric.y; + if (pPlayer->q16horiz >= F16(99.9) && pPlayer->q16horiz <= F16(100.1)) + { + pPlayer->q16horiz = F16(100); + g_horizRecenter = 0; + } - localInput.q16avel = input.q16avel; - localInput.q16horz = input.q16horz; + if (pPlayer->q16horizoff >= F16(-0.1) && pPlayer->q16horizoff <= F16(0.1)) + pPlayer->q16horizoff = 0; + } + + if (pPlayer->q16horizoff > 0) + { + 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_min(pPlayer->q16horizoff, 0); + } + + if (g_horizSkew) + pPlayer->q16horiz += fix16_from_float(scaleAdjustmentToInterval(fix16_to_float(g_horizSkew))); + + pPlayer->q16horiz = fix16_clamp(pPlayer->q16horiz, F16(HORIZ_MIN), F16(HORIZ_MAX)); } int dword_A99D4, dword_A99D8, dword_A99DC, dword_A99E0; @@ -4017,8 +4167,7 @@ void P_DHGetInput(int const playerNum) if (!(pPlayer->gm&MODE_MENU)) CONTROL_GetInput(&info); - Bmemset(&localInput, 0, sizeof(input_t)); - + localInput = {}; localInput.bits = (((int32_t)g_gameQuit) << SK_GAMEQUIT); localInput.extbits |= (1 << 7); @@ -4032,13 +4181,13 @@ void P_DHGetInput(int const playerNum) CONTROL_GetInput(&info); // JBF: Run key behaviour is selectable - int const playerRunning = G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run)); - int const playerCrouch = sub_299D8(); - int const playerJump = buttonMap.ButtonDown(gamefunc_Jump) && !(pPlayer->cursectnum >= 0 && sector[pPlayer->cursectnum].hitag == 2003); - int const turnAmount = playerCrouch ? 2 : (playerRunning ? 16 : 8); - constexpr int const analogTurnAmount = 16; - int const keyMove = playerCrouch ? 3 : (playerRunning ? 24 : 12); - constexpr int const analogExtent = 32767; // KEEPINSYNC sdlayer.cpp + int const playerRunning = G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run)); + int const playerCrouch = sub_299D8(); + int const playerJump = buttonMap.ButtonDown(gamefunc_Jump) && !(pPlayer->cursectnum >= 0 && sector[pPlayer->cursectnum].hitag == 2003); + int const turnAmount = playerCrouch ? 2 : (playerRunning ? 16 : 8); + constexpr int analogTurnAmount = 16; + int const keyMove = playerCrouch ? 3 : (playerRunning ? 24 : 12); + constexpr int analogExtent = 32767; // KEEPINSYNC sdlayer.cpp input_t input {}; @@ -4053,12 +4202,12 @@ void P_DHGetInput(int const playerNum) } else { - input.q16avel = fix16_div(fix16_from_int(info.mousex), F16(32)); + input.q16avel += fix16_div(fix16_from_int(info.mousex), F16(32)); 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_div(fix16_from_int(info.mousey), F16(64)); else input.fvel = -(info.mousey >> 3); @@ -4068,58 +4217,69 @@ void P_DHGetInput(int const playerNum) input.svel -= info.dx * keyMove / analogExtent; input.fvel -= info.dz * keyMove / analogExtent; + static double lastInputTicks; + auto const currentHiTicks = timerGetHiTicks(); + double const elapsedInputTicks = currentHiTicks - lastInputTicks; + + lastInputTicks = currentHiTicks; + + auto scaleAdjustmentToInterval = [=](double x) { return x * REALGAMETICSPERSEC / (1000.0 / elapsedInputTicks); }; + if (buttonMap.ButtonDown(gamefunc_Strafe)) { - if (buttonMap.ButtonDown(gamefunc_Turn_Left) && !(pPlayer->movement_lock&4)) - input.svel -= -keyMove; + if (!localInput.svel) + { + if (buttonMap.ButtonDown(gamefunc_Turn_Left) && !(pPlayer->movement_lock & 4) && !localInput.svel) + input.svel = -keyMove; - if (buttonMap.ButtonDown(gamefunc_Turn_Right) && !(pPlayer->movement_lock&8)) - input.svel -= keyMove; + if (buttonMap.ButtonDown(gamefunc_Turn_Right) && !(pPlayer->movement_lock & 8) && !localInput.svel) + input.svel = keyMove; + } } else { - static int32_t turnHeldTime = 0; - static int32_t lastInputClock = 0; // MED - int32_t const elapsedTics = (int32_t) totalclock - lastInputClock; + static int32_t turnHeldTime; + static int32_t lastInputClock; // MED + int32_t const elapsedTics = (int32_t)totalclock - lastInputClock; lastInputClock = (int32_t) totalclock; if (buttonMap.ButtonDown(gamefunc_Turn_Left)) { turnHeldTime += elapsedTics; - input.q16avel -= fix16_from_int((turnHeldTime >= TURBOTURNTIME) ? (turnAmount << 1) : (PREAMBLETURN << 1)); + 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_int((turnHeldTime >= TURBOTURNTIME) ? (turnAmount << 1) : (PREAMBLETURN << 1)); + input.q16avel += fix16_from_float(scaleAdjustmentToInterval((turnHeldTime >= TURBOTURNTIME) ? (turnAmount << 1) : (PREAMBLETURN << 1))); } else - turnHeldTime=0; + turnHeldTime = 0; } - if (buttonMap.ButtonDown(gamefunc_Strafe_Left) && !(pPlayer->movement_lock & 4)) - input.svel += keyMove; + if (localInput.svel < keyMove && localInput.svel > -keyMove) + { + if (buttonMap.ButtonDown(gamefunc_Strafe_Left) && !(pPlayer->movement_lock & 4)) + input.svel += keyMove; - if (buttonMap.ButtonDown(gamefunc_Strafe_Right) && !(pPlayer->movement_lock & 8)) - input.svel += -keyMove; + if (buttonMap.ButtonDown(gamefunc_Strafe_Right) && !(pPlayer->movement_lock & 8)) + input.svel += -keyMove; + } - if (buttonMap.ButtonDown(gamefunc_Move_Forward) && !(pPlayer->movement_lock & 1)) - input.fvel += keyMove; + if (localInput.fvel < keyMove && localInput.fvel > -keyMove) + { + if (buttonMap.ButtonDown(gamefunc_Move_Forward) && !(pPlayer->movement_lock & 1)) + input.fvel += keyMove; - if (buttonMap.ButtonDown(gamefunc_Move_Backward) && !(pPlayer->movement_lock & 2)) - input.fvel += -(keyMove >> 1); + if (buttonMap.ButtonDown(gamefunc_Move_Backward) && !(pPlayer->movement_lock & 2)) + input.fvel += -keyMove; + } - input.fvel = clamp(input.fvel, -MAXVEL, MAXVEL); - input.svel = clamp(input.svel, -MAXSVEL, MAXSVEL); - if (playerRunning && sub_535EC()) input.fvel <<= 3; - input.q16avel = fix16_clamp(input.q16avel, F16(-MAXANGVEL), F16(MAXANGVEL)); - input.q16horz = fix16_clamp(input.q16horz, F16(-MAXHORIZ), F16(MAXHORIZ)); - - localInput.bits = (buttonMap.ButtonDown(gamefunc_Fire) << SK_FIRE); + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Fire) << SK_FIRE); localInput.bits |= (playerJump << SK_JUMP) | (playerCrouch << SK_CROUCH); @@ -4142,7 +4302,7 @@ void P_DHGetInput(int const playerNum) if (buttonMap.ButtonDown(gamefunc_Dpad_Aiming)) input.fvel = 0; - localInput.extbits = (buttonMap.ButtonDown(gamefunc_Move_Forward) || (input.fvel > 0)); + localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Move_Forward) || (input.fvel > 0)); localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Move_Backward) || (input.fvel < 0)) << 1; localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Strafe_Left) || (input.svel > 0)) << 2; localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Strafe_Right) || (input.svel < 0)) << 3; @@ -4152,19 +4312,45 @@ void P_DHGetInput(int const playerNum) if (pPlayer->cursectnum >= 0 && sector[pPlayer->cursectnum].hitag == 2003) input.fvel >>= 1; - int16_t const q16ang = fix16_to_int(pPlayer->q16ang); + // A horiz diff of 128 equal 45 degrees, + // so we convert horiz to 1024 angle units - localInput.fvel = mulscale9(input.fvel, sintable[(q16ang + 2560) & 2047]) + - mulscale9(input.svel, sintable[(q16ang + 2048) & 2047]) + - pPlayer->fric.x; + if (g_horizAngleAdjust) + { + float const horizAngle + = atan2f(pPlayer->q16horiz - F16(100), F16(128)) * (512.f / fPI) + scaleAdjustmentToInterval(g_horizAngleAdjust); + pPlayer->q16horiz = F16(100) + Blrintf(F16(128) * tanf(horizAngle * (fPI / 512.f))); + } + else if (pPlayer->return_to_center > 0 || g_horizRecenter) + { + pPlayer->q16horiz += fix16_from_float(scaleAdjustmentToInterval(fix16_to_float(F16(33) - fix16_div(pPlayer->q16horiz, F16(3))))); - localInput.svel = mulscale9(input.fvel, sintable[(q16ang + 2048) & 2047]) + - mulscale9(input.svel, sintable[(q16ang + 1536) & 2047]) + - pPlayer->fric.y; + if (pPlayer->q16horiz >= F16(99.9) && pPlayer->q16horiz <= F16(100.1)) + { + pPlayer->q16horiz = F16(100); + g_horizRecenter = 0; + } - localInput.q16avel = input.q16avel; - localInput.q16horz = input.q16horz; + if (pPlayer->q16horizoff >= F16(-0.1) && pPlayer->q16horizoff <= F16(0.1)) + pPlayer->q16horizoff = 0; + } + if (pPlayer->q16horizoff > 0) + { + 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_min(pPlayer->q16horizoff, 0); + } + + if (g_horizSkew) + pPlayer->q16horiz += fix16_from_float(scaleAdjustmentToInterval(fix16_to_float(g_horizSkew))); + + pPlayer->q16horiz = fix16_clamp(pPlayer->q16horiz, F16(HORIZ_MIN), F16(HORIZ_MAX)); + if (input.fvel || input.svel || input.q16avel || TEST_SYNC_KEY(input.bits, SK_FIRE) || dword_A99E0 != pPlayer->pos.z) pPlayer->dhat60f = 1; dword_A99E0 = pPlayer->pos.z; @@ -6939,6 +7125,9 @@ static void P_HandlePal(DukePlayer_t *const pPlayer) void P_ProcessInput(int playerNum) { + g_horizAngleAdjust = 0; + g_horizSkew = 0; + if (DEER) { P_DHProcessInput(playerNum); @@ -7569,36 +7758,6 @@ void P_ProcessInput(int playerNum) pPlayer->oq16horiz = pPlayer->q16horiz; pPlayer->oq16horizoff = pPlayer->q16horizoff; - // calculates automatic view angle for playing without a mouse - if (pPlayer->aim_mode == 0 && pPlayer->on_ground && sectorLotag != ST_2_UNDERWATER - && (sector[pPlayer->cursectnum].floorstat & 2)) - { - vec2_t const adjustedPlayer = { pPlayer->pos.x + (sintable[(fix16_to_int(pPlayer->q16ang) + 512) & 2047] >> 5), - pPlayer->pos.y + (sintable[fix16_to_int(pPlayer->q16ang) & 2047] >> 5) }; - int16_t curSectNum = pPlayer->cursectnum; - - updatesector(adjustedPlayer.x, adjustedPlayer.y, &curSectNum); - - if (curSectNum >= 0) - { - int const slopeZ = getflorzofslope(pPlayer->cursectnum, adjustedPlayer.x, adjustedPlayer.y); - if ((pPlayer->cursectnum == curSectNum) || - (klabs(getflorzofslope(curSectNum, adjustedPlayer.x, adjustedPlayer.y) - slopeZ) <= ZOFFSET6)) - pPlayer->q16horizoff += fix16_from_int(mulscale16(trueFloorZ - slopeZ, 160)); - } - } - - if (pPlayer->q16horizoff > 0) - { - pPlayer->q16horizoff -= ((pPlayer->q16horizoff >> 3) + fix16_one); - pPlayer->q16horizoff = max(pPlayer->q16horizoff, 0); - } - else if (pPlayer->q16horizoff < 0) - { - pPlayer->q16horizoff += (((-pPlayer->q16horizoff) >> 3) + fix16_one); - pPlayer->q16horizoff = min(pPlayer->q16horizoff, 0); - } - if (highZhit >= 0 && (highZhit&49152) == 49152) { highZhit &= (MAXSPRITES-1); @@ -8197,16 +8356,8 @@ check_enemy_sprite: pPlayer->vel.x = 0; pPlayer->vel.y = 0; } - else if (g_player[playerNum].input->q16avel) //p->ang += syncangvel * constant - { - fix16_t const inputAng = g_player[playerNum].input->q16avel; - - pPlayer->q16angvel = (sectorLotag == ST_2_UNDERWATER) ? fix16_mul(inputAng - (inputAng >> 3), fix16_from_int(ksgn(velocityModifier))) - : fix16_mul(inputAng, fix16_from_int(ksgn(velocityModifier))); - pPlayer->q16ang += pPlayer->q16angvel; - pPlayer->q16ang &= 0x7FFFFFF; + else if (g_player[playerNum].input->q16avel) pPlayer->crack_time = 777; - } if (pPlayer->spritebridge == 0) { @@ -8740,7 +8891,11 @@ HORIZONLY:; } } - int centerHoriz = 0; + if (pPlayer->return_to_center > 0) + { + pPlayer->return_to_center--; + g_horizRecenter = true; + } if (TEST_SYNC_KEY(playerBits, SK_CENTER_VIEW) || pPlayer->hard_landing) if (VM_OnEvent(EVENT_RETURNTOCENTER, pPlayer->i,playerNum) == 0) @@ -8751,8 +8906,7 @@ HORIZONLY:; if (VM_OnEvent(EVENT_LOOKUP, pPlayer->i, playerNum) == 0) { pPlayer->return_to_center = 9; - pPlayer->q16horiz += fix16_from_int(12<<(int)(TEST_SYNC_KEY(playerBits, SK_RUN))); - centerHoriz++; + g_horizAngleAdjust = float(12<<(int)(TEST_SYNC_KEY(playerBits, SK_RUN))); } } else if (TEST_SYNC_KEY(playerBits, SK_LOOK_DOWN)) @@ -8760,24 +8914,23 @@ HORIZONLY:; if (VM_OnEvent(EVENT_LOOKDOWN,pPlayer->i,playerNum) == 0) { pPlayer->return_to_center = 9; - pPlayer->q16horiz -= fix16_from_int(12<<(int)(TEST_SYNC_KEY(playerBits, SK_RUN))); - centerHoriz++; + g_horizAngleAdjust = -float(12<<(int)(TEST_SYNC_KEY(playerBits, SK_RUN))); } } else if (TEST_SYNC_KEY(playerBits, SK_AIM_UP) && (!RRRA || !pPlayer->on_motorcycle)) { if (VM_OnEvent(EVENT_AIMUP,pPlayer->i,playerNum) == 0) { - pPlayer->q16horiz += fix16_from_int(6<<(int)(TEST_SYNC_KEY(playerBits, SK_RUN))); - centerHoriz++; + g_horizAngleAdjust = float(6 << (int)(TEST_SYNC_KEY(playerBits, SK_RUN))); + g_horizRecenter = false; } } else if (TEST_SYNC_KEY(playerBits, SK_AIM_DOWN) && (!RRRA || !pPlayer->on_motorcycle)) { if (VM_OnEvent(EVENT_AIMDOWN,pPlayer->i,playerNum) == 0) { - pPlayer->q16horiz -= fix16_from_int(6<<(int)(TEST_SYNC_KEY(playerBits, SK_RUN))); - centerHoriz++; + g_horizAngleAdjust = -float(6 << (int)(TEST_SYNC_KEY(playerBits, SK_RUN))); + g_horizRecenter = false; } } if (RR && pPlayer->recoil && *weaponFrame == 0) @@ -8787,25 +8940,11 @@ HORIZONLY:; pPlayer->recoil -= delta; pPlayer->q16horiz -= F16(delta); } - else if (pPlayer->return_to_center > 0 && !TEST_SYNC_KEY(playerBits, SK_LOOK_UP) && !TEST_SYNC_KEY(playerBits, SK_LOOK_DOWN)) - { - pPlayer->return_to_center--; - pPlayer->q16horiz += F16(33)-fix16_div(pPlayer->q16horiz, F16(3)); - centerHoriz++; - } if (pPlayer->hard_landing > 0) { + g_horizSkew = fix16_from_int(-(pPlayer->hard_landing << 4)); pPlayer->hard_landing--; - pPlayer->q16horiz -= fix16_from_int(pPlayer->hard_landing<<4); - } - - pPlayer->q16horiz = fix16_clamp(pPlayer->q16horiz + g_player[playerNum].input->q16horz, F16(HORIZ_MIN), F16(HORIZ_MAX)); - - if (centerHoriz && (!RR || !pPlayer->recoil)) - { - if (pPlayer->q16horiz > F16(95) && pPlayer->q16horiz < F16(105)) pPlayer->q16horiz = F16(100); - if (pPlayer->q16horizoff > F16(-5) && pPlayer->q16horizoff < F16(5)) pPlayer->q16horizoff = 0; } //Shooting code/changes @@ -8834,7 +8973,7 @@ HORIZONLY:; if (pPlayer->knee_incs > 0) { - pPlayer->q16horiz -= F16(48); + g_horizSkew = F16(-48); pPlayer->return_to_center = 9; if (++pPlayer->knee_incs > 15) @@ -8917,6 +9056,9 @@ HORIZONLY:; void P_DHProcessInput(int playerNum) { + g_horizAngleAdjust = 0; + g_horizSkew = 0; + if (g_player[playerNum].playerquitflag == 0) return; @@ -9270,16 +9412,8 @@ void P_DHProcessInput(int playerNum) pPlayer->vel.x = 0; pPlayer->vel.y = 0; } - else if (g_player[playerNum].input->q16avel) //p->ang += syncangvel * constant - { - fix16_t const inputAng = g_player[playerNum].input->q16avel; - - pPlayer->q16angvel = (sectorLotag == ST_2_UNDERWATER) ? fix16_mul(inputAng - (inputAng >> 3), fix16_from_int(ksgn(velocityModifier))) - : fix16_mul(inputAng, fix16_from_int(ksgn(velocityModifier))); - pPlayer->q16ang += pPlayer->q16angvel; - pPlayer->q16ang &= 0x7FFFFFF; + else if (g_player[playerNum].input->q16avel) pPlayer->crack_time = 777; - } if (pPlayer->vel.x || pPlayer->vel.y || g_player[playerNum].input->fvel || g_player[playerNum].input->svel) { @@ -9409,7 +9543,11 @@ void P_DHProcessInput(int playerNum) A_GetFurthestAngle(pPlayer->i, 8) < 512); } - int centerHoriz = 0; + if (pPlayer->return_to_center > 0) + { + pPlayer->return_to_center--; + g_horizRecenter = true; + } if (TEST_SYNC_KEY(playerBits, SK_CENTER_VIEW) || pPlayer->hard_landing) pPlayer->return_to_center = 9; @@ -9417,24 +9555,22 @@ void P_DHProcessInput(int playerNum) if (TEST_SYNC_KEY(playerBits, SK_LOOK_UP)) { pPlayer->return_to_center = 9; - pPlayer->q16horiz += fix16_from_int(12<<(int)(TEST_SYNC_KEY(playerBits, SK_RUN))); - centerHoriz++; + g_horizAngleAdjust = float(12<<(int)(TEST_SYNC_KEY(playerBits, SK_RUN))); } else if (TEST_SYNC_KEY(playerBits, SK_LOOK_DOWN)) { pPlayer->return_to_center = 9; - pPlayer->q16horiz -= fix16_from_int(12<<(int)(TEST_SYNC_KEY(playerBits, SK_RUN))); - centerHoriz++; + g_horizAngleAdjust = -float(12<<(int)(TEST_SYNC_KEY(playerBits, SK_RUN))); } else if (TEST_SYNC_KEY(playerBits, SK_AIM_UP) && !pPlayer->on_motorcycle) { - pPlayer->q16horiz += fix16_from_int(6<<(int)(TEST_SYNC_KEY(playerBits, SK_RUN))); - centerHoriz++; + g_horizAngleAdjust = float(6 << (int)(TEST_SYNC_KEY(playerBits, SK_RUN))); + g_horizRecenter = false; } else if (TEST_SYNC_KEY(playerBits, SK_AIM_DOWN) && !pPlayer->on_motorcycle) { - pPlayer->q16horiz -= fix16_from_int(6<<(int)(TEST_SYNC_KEY(playerBits, SK_RUN))); - centerHoriz++; + g_horizAngleAdjust = -float(6 << (int)(TEST_SYNC_KEY(playerBits, SK_RUN))); + g_horizRecenter = false; } if (RR && pPlayer->recoil && *weaponFrame == 0) { @@ -9443,25 +9579,11 @@ void P_DHProcessInput(int playerNum) pPlayer->recoil -= delta; pPlayer->q16horiz -= F16(delta); } - else if (pPlayer->return_to_center > 0 && !TEST_SYNC_KEY(playerBits, SK_LOOK_UP) && !TEST_SYNC_KEY(playerBits, SK_LOOK_DOWN)) - { - pPlayer->return_to_center--; - pPlayer->q16horiz += F16(33)-fix16_div(pPlayer->q16horiz, F16(3)); - centerHoriz++; - } if (pPlayer->hard_landing > 0) { + g_horizSkew = fix16_from_int(-(pPlayer->hard_landing << 4)); pPlayer->hard_landing--; - pPlayer->q16horiz -= fix16_from_int(pPlayer->hard_landing<<4); - } - - pPlayer->q16horiz = fix16_clamp(pPlayer->q16horiz? 0 : g_player[playerNum].input->q16horz, F16(HORIZ_MIN), F16(HORIZ_MAX)); - - if (centerHoriz && (!RR || !pPlayer->recoil)) - { - if (pPlayer->q16horiz > F16(95) && pPlayer->q16horiz < F16(105)) pPlayer->q16horiz = F16(100); - if (pPlayer->q16horizoff > F16(-5) && pPlayer->q16horizoff < F16(5)) pPlayer->q16horizoff = 0; } if (TEST_SYNC_KEY(playerBits, SK_FIRE))