From 2919cdcb44776077ebf13bd1ac3389f3eb6dbf46 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Wed, 5 Aug 2020 19:56:49 +1000 Subject: [PATCH] - clamp the calculated `horizAngle` to -180/180 to stop overflowing if player moves the mouse stupidly quick while `cl_syncinput 1` is set. --- source/games/duke/src/player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index 38870bf51..cf38285f3 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -972,7 +972,7 @@ void sethorizon(int snum, int sb_snum, double factor, fixed_t adjustment) auto p = &ps[snum]; // Calculate adjustment as true pitch (Fixed point math really sucks...) - double horizAngle = atan2(p->q16horiz - F16(100), F16(128)) * (512. / pi::pi()) + (factor * p->pitchAdjust) + (adjustment / 65536.); + double horizAngle = clamp2(atan2(p->q16horiz - F16(100), F16(128)) * (512. / pi::pi()) + (factor * p->pitchAdjust) + (adjustment / 65536.), -180, 180); if (p->return_to_center > 0 && (sb_snum & (SKB_LOOK_UP | SKB_LOOK_DOWN)) == 0) // only snap back if no relevant button is pressed. {