foxygit / doom Log in
commit 5aa5e1fed5f7245a942bbfee43935d58a990deb5
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Thu Jun 14 21:15:52 2007 +0000
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Thu Jun 14 21:15:52 2007 +0000

    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
---
 src/g_game.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/src/g_game.c b/src/g_game.c
index dd2c2669..0a2d5862 100644
--- a/src/g_game.c
+++ b/src/g_game.c
@@ -220,10 +220,12 @@ static int      dclicktime2;
 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 @@ void G_BuildTiccmd (ticcmd_t* cmd)
     // allowed an autorun effect

     speed = key_speed >= NUMKEYS
-         || joybspeed >= 20
+         || joybspeed >= MAX_JOY_BUTTONS
          || gamekeydown[key_speed]
          || joybuttons[joybspeed];

@@ -657,6 +659,16 @@ void G_DoLoadLevel (void)
     }
 }

+
+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 @@ boolean G_Responder (event_t* ev)
 	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