shithub: choc

Download patch

ref: c6a63b6286567001f80a5366648ea88265abb2ce
parent: 56383f628bfebc65f96b20fccf3abbf55c4e0925
author: Jonathan Dowland <[email protected]>
date: Tue Mar 21 03:03:39 EDT 2017

doom menu joystick handling cleanup

Introduce two macros (JOY_BUTTON_MAPPED and JOY_BUTTON_PRESSED) to
clean up the menu code that checks joystick button state and simulates
keyboard key presses depending on context.

Re-order the new context checks for Y/N questions so they are
nested under the existing checks for use/fire button presses.

This cleans up some double-presses and some undefined behaviour
with the unbound button X.

--- a/src/doom/m_menu.c
+++ b/src/doom/m_menu.c
@@ -1419,34 +1419,39 @@
 	    key = key_menu_right;
 	    joywait = I_GetTime() + 2;
 	}
-		
-	if (ev->data1&1)
-	{
-	    key = key_menu_forward;
-	    joywait = I_GetTime() + 5;
-	}
-	if (ev->data1&2)
-	{
-	    key = key_menu_back;
-	    joywait = I_GetTime() + 5;
-	}
-        if (joybmenu >= 0 && (ev->data1 & (1 << joybmenu)) != 0)
+
+#define JOY_BUTTON_MAPPED(x) ((x) >= 0)
+#define JOY_BUTTON_PRESSED(x) (JOY_BUTTON_MAPPED(x) && (ev->data1 & (1 << (x))) != 0)
+
+        if (JOY_BUTTON_PRESSED(joybfire))
         {
-            key = key_menu_activate;
-	    joywait = I_GetTime() + 5;
+            // Simulate a 'Y' keypress when Doom show a Y/N dialog with Fire button.
+            if (messageToPrint && messageNeedsInput)
+            {
+                key = key_menu_confirm;
+            }
+            else
+            {
+                key = key_menu_forward;
+            }
+            joywait = I_GetTime() + 5;
         }
-
-        // Simulate a 'Y' keypress when Doom show a Y/N dialog with Fire button.
-        if (messageToPrint && messageNeedsInput && joybmenu >= 0 && ev->data1&1)
+        if (JOY_BUTTON_PRESSED(joybuse))
         {
-            key = key_menu_confirm;
+            // Simulate a 'N' keypress when Doom show a Y/N dialog with Use button.
+            if (messageToPrint && messageNeedsInput)
+            {
+                key = key_menu_abort;
+            }
+            else
+            {
+                key = key_menu_back;
+            }
             joywait = I_GetTime() + 5;
         }
-
-        // Simulate a 'N' keypress when Doom show a Y/N dialog with Use button.
-        if (messageToPrint && messageNeedsInput && joybmenu >= 0 && ev->data1&2)
+        if (JOY_BUTTON_PRESSED(joybmenu))
         {
-            key = key_menu_abort;
+            key = key_menu_activate;
             joywait = I_GetTime() + 5;
         }
     }