Re: [AD] minor fix

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


On Friday 02 July 2004 19:34, Julien Cugnière wrote:
> If we want to be on the safe side, can't we just put an upper limit on 
> the number of events to process every frame ? For example, stop 
> processing events when there is none left, of when we processed 100 of 
> them. This makes the joystick more responsive, and prevents hanging.

Agreed.
I've tested the following patch. From what I can tell, it doesn't change 
anything in the response of my gamepad, which I guess is a good thing...
I'd still like to know what the reservations against it are though... as it 
is, it doesn't buffer the input, meaning it is possible to lose events if 
the driver isn't being polled often enough. I'm not at all sure this is 
actually desired behavior.

Evert
--- allegro/src/linux/ljoy.c	2004-04-09 06:21:17.000000000 +0200
+++ alleg_work/src/linux/ljoy.c	2004-07-02 21:07:01.000000000 +0200
@@ -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,21 @@
 
 static int joy_poll(void)
 {
-   fd_set set;
-   struct timeval tv;
    struct js_event e;
-   int i, ready;
+   int i, c;
 
    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);
+      c = 0;
+      while (read(joy_fd[i], &e, sizeof(e)) == sizeof(e) && c<100)  {
+         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);
+         }
+         c++;
       }
    }
 


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