Re: [AD] Joystick polling bug under Linux

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


> http://www.allegro.cc/forums/view_thread.php?_id=354745&;

I suppose this is patch #943753 on SF's tracker.  I've attached it.

Peter, do you have an opinion on the patch?  I remember that you didn't like 
a patch that would have made the same change (read all events) to the Xlib 
event loop.

-- 
Eric Botcazou
--- ljoy.c.orig	Wed Apr 28 03:20:51 2004
+++ ljoy.c	Wed Apr 28 04:06:30 2004
@@ -13,6 +13,7 @@
  *      By George Foot.
  *
  *      Modified by Peter Wang.
+ *      joy_poll() modified by Greg Lee, 4/28/04.
  *
  *      See readme.txt for copyright information.
  */
@@ -22,7 +23,6 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
-#include <sys/time.h>
 
 #define ALLEGRO_NO_KEY_DEFINES
 
@@ -86,6 +86,8 @@
 	 }
       }
 
+      fcntl(joy_fd[i], F_SETFL, O_NONBLOCK);
+
       if (ioctl(joy_fd[i], JSIOCGVERSION, &raw_version) < 0) {
          /* NOTE: IOCTL fails if the joystick API is version 0.x */
          uszprintf(allegro_error, ALLEGRO_ERROR_SIZE, get_config_text("Your Linux joystick API is version 0.x which is unsupported."));
@@ -191,28 +193,19 @@
 
 static int joy_poll(void)
 {
-   fd_set set;
-   struct timeval tv;
    struct js_event e;
-   int i, ready;
+   int i;
 
    for (i = 0; i < num_joysticks; i++) {
-      tv.tv_sec = tv.tv_usec = 0;
-      FD_ZERO(&set);
-      FD_SET(joy_fd[i], &set);
-
-      ready = select(FD_SETSIZE, &set, NULL, NULL, &tv);
-      if (ready <= 0)
-	 continue;
-
-      read(joy_fd[i], &e, sizeof(e));
-      if (e.type & JS_EVENT_BUTTON) {
-	 if (e.number < MAX_JOYSTICK_BUTTONS)
-	    joy[i].button[e.number].b = e.value;
-      }
-      else if (e.type & JS_EVENT_AXIS) {
-	 if (e.number < TOTAL_JOYSTICK_AXES)
-	    set_axis (axis[i][e.number], e.value);
+      while (read(joy_fd[i], &e, sizeof(struct js_event)) == sizeof(struct js_event))  {
+         if (e.type & JS_EVENT_BUTTON) {
+	    if (e.number < MAX_JOYSTICK_BUTTONS)
+	       joy[i].button[e.number].b = e.value;
+         }
+         else if (e.type & JS_EVENT_AXIS) {
+	    if (e.number < TOTAL_JOYSTICK_AXES)
+	       set_axis (axis[i][e.number], e.value);
+         }
       }
    }
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/