From e24521b1890ca324063e7b4415af0bd9198bca5d Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Wed, 9 Sep 2020 22:04:46 +1000 Subject: [PATCH] - SW: Uplift `playerSetHoriz()` similar to uplift to `playerSetAngle()` in b832442e3125da548145e761b039cf69c717ab7f. --- source/sw/src/game.h | 2 +- source/sw/src/input.cpp | 13 ++++++++++++- source/sw/src/player.cpp | 11 ++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/source/sw/src/game.h b/source/sw/src/game.h index 8c7ae8645..6d0c38a38 100644 --- a/source/sw/src/game.h +++ b/source/sw/src/game.h @@ -1009,7 +1009,7 @@ struct PLAYERstruct // Input helper variables and setters. double horizAdjust, angAdjust, pitchAdjust; - fixed_t angTarget; + fixed_t horizTarget, angTarget; void addang(int v) { q16ang = (q16ang + IntToFixed(v)) & 0x7FFFFFF; } void setang(int v) { q16ang = IntToFixed(v); } void addhoriz(int v) { q16horiz += (IntToFixed(v)); } diff --git a/source/sw/src/input.cpp b/source/sw/src/input.cpp index 33f588a97..f1bec201e 100644 --- a/source/sw/src/input.cpp +++ b/source/sw/src/input.cpp @@ -284,7 +284,18 @@ static void processMovement(PLAYERp const pp, ControlInfo* const hidInput, bool DoPlayerHorizon(pp, q16horz, scaleAdjust); } - if (pp->horizAdjust) + if (pp->horizTarget) + { + fixed_t horizDelta = pp->horizTarget - pp->q16horiz; + pp->q16horiz += xs_CRoundToInt(scaleAdjust * horizDelta); + + if (abs(pp->q16horiz) >= abs(horizDelta)) + { + pp->q16horiz = pp->horizTarget; + pp->horizTarget = 0; + } + } + else if (pp->horizAdjust) { pp->q16horiz += FloatToFixed(scaleAdjust * pp->horizAdjust); } diff --git a/source/sw/src/player.cpp b/source/sw/src/player.cpp index 51593e82c..7fe6e18fa 100644 --- a/source/sw/src/player.cpp +++ b/source/sw/src/player.cpp @@ -7834,7 +7834,16 @@ void playerSetHoriz(PLAYERp pp, double horiz) { if (!cl_syncinput) { - pp->horizAdjust += -1. * ((pp->q16horiz / 65536.) - horiz); + // Cancel out any horizon adjustments as we're setting horizon now. + pp->horizAdjust = 0; + + // Add slight offset if input horizon is coming in as absolute 0. + if (horiz == 0) + { + horiz += 0.1; + } + + pp->horizTarget = FloatToFixed(horiz); } else {