From 0e1a91c655f8996aae3c1f715ab4f6efc3e7cea9 Mon Sep 17 00:00:00 2001
From: Lonsfor <827632-Lonsfor@users.noreply.gitlab.com>
Date: Wed, 1 Sep 2021 18:57:37 -0400
Subject: [PATCH] Separate deadzones for players 2 3 and 4

---
 src/d_netcmd.c |   9 ++--
 src/g_game.c   | 140 +++++++++++++++++++++++++++++++++----------------
 src/g_game.h   |   6 +--
 3 files changed, 103 insertions(+), 52 deletions(-)

diff --git a/src/d_netcmd.c b/src/d_netcmd.c
index 2bd45b114..057bdf2a2 100644
--- a/src/d_netcmd.c
+++ b/src/d_netcmd.c
@@ -914,9 +914,12 @@ void D_RegisterClientCommands(void)
 	CV_RegisterVar(&cv_driftaxis4);
 	CV_RegisterVar(&cv_xdeadzone);
 	CV_RegisterVar(&cv_ydeadzone);
-	CV_RegisterVar(&cv_deadzone2);
-	CV_RegisterVar(&cv_deadzone3);
-	CV_RegisterVar(&cv_deadzone4);
+	CV_RegisterVar(&cv_xdeadzone2);
+	CV_RegisterVar(&cv_ydeadzone2);
+	CV_RegisterVar(&cv_xdeadzone3);
+	CV_RegisterVar(&cv_ydeadzone3);
+	CV_RegisterVar(&cv_xdeadzone4);
+	CV_RegisterVar(&cv_ydeadzone4);
 
 	// filesrch.c
 	CV_RegisterVar(&cv_addons_option);
diff --git a/src/g_game.c b/src/g_game.c
index d125f2652..404e233da 100644
--- a/src/g_game.c
+++ b/src/g_game.c
@@ -503,7 +503,8 @@ consvar_t cv_aimaxis2 = {"joyaxis2_aim", "Y-Axis", CV_SAVE, joyaxis_cons_t, NULL
 consvar_t cv_lookaxis2 = {"joyaxis2_look", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL};
 consvar_t cv_fireaxis2 = {"joyaxis2_fire", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL};
 consvar_t cv_driftaxis2 = {"joyaxis2_drift", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL};
-consvar_t cv_deadzone2 = {"joy2_deadzone", "0.5", CV_FLOAT|CV_SAVE, deadzone_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL};
+consvar_t cv_xdeadzone2 = {"joy2_xdeadzone", "0.3", CV_FLOAT|CV_SAVE, deadzone_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL};
+consvar_t cv_ydeadzone2 = {"joy2_ydeadzone", "0.5", CV_FLOAT|CV_SAVE, deadzone_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL};
 
 consvar_t cv_turnaxis3 = {"joyaxis3_turn", "X-Axis", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL};
 consvar_t cv_moveaxis3 = {"joyaxis3_move", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL};
@@ -512,7 +513,8 @@ consvar_t cv_aimaxis3 = {"joyaxis3_aim", "Y-Axis", CV_SAVE, joyaxis_cons_t, NULL
 consvar_t cv_lookaxis3 = {"joyaxis3_look", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL};
 consvar_t cv_fireaxis3 = {"joyaxis3_fire", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL};
 consvar_t cv_driftaxis3 = {"joyaxis3_drift", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL};
-consvar_t cv_deadzone3 = {"joy3_deadzone", "0.5", CV_FLOAT|CV_SAVE, deadzone_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL};
+consvar_t cv_xdeadzone3 = {"joy3_xdeadzone", "0.3", CV_FLOAT|CV_SAVE, deadzone_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL};
+consvar_t cv_ydeadzone3 = {"joy3_ydeadzone", "0.5", CV_FLOAT|CV_SAVE, deadzone_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL};
 
 consvar_t cv_turnaxis4 = {"joyaxis4_turn", "X-Axis", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL};
 consvar_t cv_moveaxis4 = {"joyaxis4_move", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL};
@@ -521,7 +523,8 @@ consvar_t cv_aimaxis4 = {"joyaxis4_aim", "Y-Axis", CV_SAVE, joyaxis_cons_t, NULL
 consvar_t cv_lookaxis4 = {"joyaxis4_look", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL};
 consvar_t cv_fireaxis4 = {"joyaxis4_fire", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL};
 consvar_t cv_driftaxis4 = {"joyaxis4_drift", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL};
-consvar_t cv_deadzone4 = {"joy4_deadzone", "0.5", CV_FLOAT|CV_SAVE, deadzone_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL};
+consvar_t cv_xdeadzone4 = {"joy4_xdeadzone", "0.3", CV_FLOAT|CV_SAVE, deadzone_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL};
+consvar_t cv_ydeadzone4 = {"joy4_ydeadzone", "0.5", CV_FLOAT|CV_SAVE, deadzone_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL};
 
 
 #if MAXPLAYERS > 16
@@ -964,7 +967,7 @@ static INT32 Joy1Axis(axis_input_e axissel)
 		if (flp) retaxis = -retaxis; //flip it around
 		return retaxis;
 	}
-	}
+}
 
 #ifdef _arch_dreamcast
 	skipDC:
@@ -1025,32 +1028,47 @@ static INT32 Joy2Axis(axis_input_e axissel)
 	{
 		axisval /= 2;
 		retaxis = joy2xmove[axisval];
+
+		if (retaxis < (-JOYAXISRANGE))
+			retaxis = -JOYAXISRANGE;
+		if (retaxis > (+JOYAXISRANGE))
+			retaxis = +JOYAXISRANGE;
+		if (!Joystick2.bGamepadStyle && axissel < AXISDEAD)
+		{
+			const INT32 jdeadzone = ((JOYAXISRANGE-1) * cv_xdeadzone2.value) >> FRACBITS;
+			if (-jdeadzone < retaxis && retaxis < jdeadzone)
+				return 0;
+		}
+		if (flp) retaxis = -retaxis; //flip it around
+		return retaxis;
+
 	}
 	else
 	{
 		axisval--;
 		axisval /= 2;
 		retaxis = joy2ymove[axisval];
+
+		if (retaxis < (-JOYAXISRANGE))
+			retaxis = -JOYAXISRANGE;
+		if (retaxis > (+JOYAXISRANGE))
+			retaxis = +JOYAXISRANGE;
+		if (!Joystick2.bGamepadStyle && axissel < AXISDEAD)
+		{
+			const INT32 jdeadzone = ((JOYAXISRANGE-1) * cv_ydeadzone2.value) >> FRACBITS;
+			if (-jdeadzone < retaxis && retaxis < jdeadzone)
+				return 0;
+		}
+		if (flp) retaxis = -retaxis; //flip it around
+		return retaxis;
+
 	}
+}
 
 #ifdef _arch_dreamcast
 	skipDC:
 #endif
 
-	if (retaxis < (-JOYAXISRANGE))
-		retaxis = -JOYAXISRANGE;
-	if (retaxis > (+JOYAXISRANGE))
-		retaxis = +JOYAXISRANGE;
-	if (!Joystick2.bGamepadStyle && axissel < AXISDEAD)
-	{
-		const INT32 jdeadzone = ((JOYAXISRANGE-1) * cv_deadzone2.value) >> FRACBITS;
-		if (-jdeadzone < retaxis && retaxis < jdeadzone)
-			return 0;
-	}
-	if (flp) retaxis = -retaxis; //flip it around
-	return retaxis;
-}
-
 static INT32 Joy3Axis(axis_input_e axissel)
 {
 	INT32 retaxis;
@@ -1106,32 +1124,47 @@ static INT32 Joy3Axis(axis_input_e axissel)
 	{
 		axisval /= 2;
 		retaxis = joy3xmove[axisval];
+
+		if (retaxis < (-JOYAXISRANGE))
+			retaxis = -JOYAXISRANGE;
+		if (retaxis > (+JOYAXISRANGE))
+			retaxis = +JOYAXISRANGE;
+		if (!Joystick3.bGamepadStyle && axissel < AXISDEAD)
+		{
+			const INT32 jdeadzone = ((JOYAXISRANGE-1) * cv_xdeadzone3.value) >> FRACBITS;
+			if (-jdeadzone < retaxis && retaxis < jdeadzone)
+				return 0;
+		}
+		if (flp) retaxis = -retaxis; //flip it around
+		return retaxis;
+		
 	}
 	else
 	{
 		axisval--;
 		axisval /= 2;
 		retaxis = joy3ymove[axisval];
+
+		if (retaxis < (-JOYAXISRANGE))
+			retaxis = -JOYAXISRANGE;
+		if (retaxis > (+JOYAXISRANGE))
+			retaxis = +JOYAXISRANGE;
+		if (!Joystick3.bGamepadStyle && axissel < AXISDEAD)
+		{
+			const INT32 jdeadzone = ((JOYAXISRANGE-1) * cv_ydeadzone3.value) >> FRACBITS;
+			if (-jdeadzone < retaxis && retaxis < jdeadzone)
+				return 0;
+		}
+		if (flp) retaxis = -retaxis; //flip it around
+		return retaxis;
+		
 	}
+}
 
 #ifdef _arch_dreamcast
 	skipDC:
 #endif
 
-	if (retaxis < (-JOYAXISRANGE))
-		retaxis = -JOYAXISRANGE;
-	if (retaxis > (+JOYAXISRANGE))
-		retaxis = +JOYAXISRANGE;
-	if (!Joystick3.bGamepadStyle && axissel < AXISDEAD)
-	{
-		const INT32 jdeadzone = ((JOYAXISRANGE-1) * cv_deadzone3.value) >> FRACBITS;
-		if (-jdeadzone < retaxis && retaxis < jdeadzone)
-			return 0;
-	}
-	if (flp) retaxis = -retaxis; //flip it around
-	return retaxis;
-}
-
 static INT32 Joy4Axis(axis_input_e axissel)
 {
 	INT32 retaxis;
@@ -1186,32 +1219,47 @@ static INT32 Joy4Axis(axis_input_e axissel)
 	{
 		axisval /= 2;
 		retaxis = joy4xmove[axisval];
+
+		if (retaxis < (-JOYAXISRANGE))
+			retaxis = -JOYAXISRANGE;
+		if (retaxis > (+JOYAXISRANGE))
+			retaxis = +JOYAXISRANGE;
+		if (!Joystick4.bGamepadStyle && axissel < AXISDEAD)
+		{
+			const INT32 jdeadzone = ((JOYAXISRANGE-1) * cv_xdeadzone4.value) >> FRACBITS;
+			if (-jdeadzone < retaxis && retaxis < jdeadzone)
+				return 0;
+		}
+		if (flp) retaxis = -retaxis; //flip it around
+		return retaxis;
+		
 	}
 	else
 	{
 		axisval--;
 		axisval /= 2;
 		retaxis = joy4ymove[axisval];
+
+		if (retaxis < (-JOYAXISRANGE))
+			retaxis = -JOYAXISRANGE;
+		if (retaxis > (+JOYAXISRANGE))
+			retaxis = +JOYAXISRANGE;
+		if (!Joystick4.bGamepadStyle && axissel < AXISDEAD)
+		{
+			const INT32 jdeadzone = ((JOYAXISRANGE-1) * cv_ydeadzone4.value) >> FRACBITS;
+			if (-jdeadzone < retaxis && retaxis < jdeadzone)
+				return 0;
+		}
+		if (flp) retaxis = -retaxis; //flip it around
+		return retaxis;
+		
 	}
+}
 
 #ifdef _arch_dreamcast
 	skipDC:
 #endif
 
-	if (retaxis < (-JOYAXISRANGE))
-		retaxis = -JOYAXISRANGE;
-	if (retaxis > (+JOYAXISRANGE))
-		retaxis = +JOYAXISRANGE;
-	if (!Joystick4.bGamepadStyle && axissel < AXISDEAD)
-	{
-		const INT32 jdeadzone = ((JOYAXISRANGE-1) * cv_deadzone4.value) >> FRACBITS;
-		if (-jdeadzone < retaxis && retaxis < jdeadzone)
-			return 0;
-	}
-	if (flp) retaxis = -retaxis; //flip it around
-	return retaxis;
-}
-
 boolean InputDown(INT32 gc, UINT8 p)
 {
 	switch (p)
diff --git a/src/g_game.h b/src/g_game.h
index 05225164a..0dcc69c39 100644
--- a/src/g_game.h
+++ b/src/g_game.h
@@ -119,9 +119,9 @@ extern consvar_t cv_invertmouse2/*, cv_alwaysfreelook2, cv_chasefreelook2, cv_mo
 extern consvar_t cv_useranalog, cv_useranalog2, cv_useranalog3, cv_useranalog4;
 extern consvar_t cv_analog, cv_analog2, cv_analog3, cv_analog4;
 extern consvar_t cv_turnaxis,cv_moveaxis,cv_brakeaxis,cv_aimaxis,cv_lookaxis,cv_fireaxis,cv_driftaxis,cv_xdeadzone,cv_ydeadzone;
-extern consvar_t cv_turnaxis2,cv_moveaxis2,cv_brakeaxis2,cv_aimaxis2,cv_lookaxis2,cv_fireaxis2,cv_driftaxis2,cv_deadzone2;
-extern consvar_t cv_turnaxis3,cv_moveaxis3,cv_brakeaxis3,cv_aimaxis3,cv_lookaxis3,cv_fireaxis3,cv_driftaxis3,cv_deadzone3;
-extern consvar_t cv_turnaxis4,cv_moveaxis4,cv_brakeaxis4,cv_aimaxis4,cv_lookaxis4,cv_fireaxis4,cv_driftaxis4,cv_deadzone4;
+extern consvar_t cv_turnaxis2,cv_moveaxis2,cv_brakeaxis2,cv_aimaxis2,cv_lookaxis2,cv_fireaxis2,cv_driftaxis2,cv_xdeadzone2,cv_ydeadzone2;
+extern consvar_t cv_turnaxis3,cv_moveaxis3,cv_brakeaxis3,cv_aimaxis3,cv_lookaxis3,cv_fireaxis3,cv_driftaxis3,cv_xdeadzone3,cv_ydeadzone3;
+extern consvar_t cv_turnaxis4,cv_moveaxis4,cv_brakeaxis4,cv_aimaxis4,cv_lookaxis4,cv_fireaxis4,cv_driftaxis4,cv_xdeadzone4,cv_ydeadzone4;
 extern consvar_t cv_ghost_besttime, cv_ghost_bestlap, cv_ghost_last, cv_ghost_guest, cv_ghost_staff;
 
 typedef enum
-- 
GitLab