changeset 33017:cc8cef372901

Make "stuck keys" problem impossibly by resetting the internal key state when our key fifo overflowed.
author reimar
date Thu, 24 Mar 2011 22:11:18 +0000
parents 88a7bd86e3ac
children d88b8a9e989e
files input/input.c input/input.h mp_fifo.c
diffstat 3 files changed, 12 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/input/input.c	Thu Mar 24 21:58:06 2011 +0000
+++ b/input/input.c	Thu Mar 24 22:11:18 2011 +0000
@@ -1100,6 +1100,13 @@
   unsigned int j;
   mp_cmd_t* ret;
 
+  if (code == MP_KEY_RELEASE_ALL) {
+      memset(key_down, 0, sizeof(key_down));
+      num_key_down = 0;
+      last_key_down = 0;
+      return NULL;
+  }
+
   if(mp_input_key_cb) {
       if (code & MP_KEY_DOWN)
 	  return NULL;
--- a/input/input.h	Thu Mar 24 21:58:06 2011 +0000
+++ b/input/input.h	Thu Mar 24 22:11:18 2011 +0000
@@ -191,6 +191,8 @@
 #define MP_KEY_DOWN (1<<29)
 // Use this when the key shouldn't be auto-repeated (like mouse buttons)
 #define MP_NO_REPEAT_KEY (1<<28)
+// Special value to mark all keys as "up"
+#define MP_KEY_RELEASE_ALL (1<<27)
 
 #ifndef MP_MAX_KEY_DOWN
 #define MP_MAX_KEY_DOWN 32
--- a/mp_fifo.c	Thu Mar 24 21:58:06 2011 +0000
+++ b/mp_fifo.c	Thu Mar 24 22:11:18 2011 +0000
@@ -35,6 +35,9 @@
   // reserve some space for key release events to avoid stuck keys
   if((code & MP_KEY_DOWN) && fifo_free < (key_fifo_size >> 1))
     return;
+  // in the worst case, just reset key state
+  if (fifo_free == 1)
+    code = MP_KEY_RELEASE_ALL;
   key_fifo_data[key_fifo_write % key_fifo_size]=code;
   key_fifo_write++;
 }