shithub: choc

Download patch

ref: 5aa5e1fed5f7245a942bbfee43935d58a990deb5
parent: 66d22ab030630378c2feb57a5d8cd65669713c2a
author: Simon Howard <[email protected]>
date: Thu Jun 14 17:15:52 EDT 2007

Support up to 20 joystick buttons. Justification: most modern joysticks
and joypads have many more than four buttons. Keeping the limit at four
buttons restricts the player into using the first four buttons on his
joystick/pad, which could be any arbitrary four set of buttons.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 905

--- a/src/g_game.c
+++ b/src/g_game.c
@@ -220,10 +220,12 @@
 static boolean  dclickstate2;
 static int      dclicks2;
 
+#define MAX_JOY_BUTTONS 20
+
 // joystick values are repeated 
 static int      joyxmove;
 static int      joyymove;
-static boolean  joyarray[5]; 
+static boolean  joyarray[MAX_JOY_BUTTONS + 1]; 
 static boolean *joybuttons = &joyarray[1];		// allow [-1] 
  
 static int      savegameslot; 
@@ -392,7 +394,7 @@
     // allowed an autorun effect
 
     speed = key_speed >= NUMKEYS
-         || joybspeed >= 20
+         || joybspeed >= MAX_JOY_BUTTONS
          || gamekeydown[key_speed] 
          || joybuttons[joybspeed];
  
@@ -657,6 +659,16 @@
     }
 } 
  
+
+static void SetJoyButtons(unsigned int buttons_mask)
+{
+    int i;
+
+    for (i=0; i<MAX_JOY_BUTTONS; ++i)
+    {
+        joybuttons[i] = (buttons_mask & (1 << i)) != 0;
+    }
+}
  
 //
 // G_Responder  
@@ -752,10 +764,7 @@
 	return true;    // eat events 
  
       case ev_joystick: 
-	joybuttons[0] = ev->data1 & 1; 
-	joybuttons[1] = ev->data1 & 2; 
-	joybuttons[2] = ev->data1 & 4; 
-	joybuttons[3] = ev->data1 & 8; 
+        SetJoyButtons(ev->data1);
 	joyxmove = ev->data2; 
 	joyymove = ev->data3; 
 	return true;    // eat events