]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
block key events while in the event handler called from loading screens - might fix...
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 15 Apr 2010 10:09:45 +0000 (10:09 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 15 Apr 2010 10:09:45 +0000 (10:09 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10087 d7cf8633-e32d-0410-b094-e92efae38249

cl_screen.c
host.c
keys.c
keys.h

index c137b100b7cfa9b70174d90f7dfda57270824611..8fd9b4b9540c92a2216bab0ff670c39dfd18c6eb 100644 (file)
@@ -2029,7 +2029,7 @@ void SCR_UpdateLoadingScreen (qboolean clear)
        old_key_consoleactive = key_consoleactive;
        key_dest = key_void;
        key_consoleactive = false;
-       Sys_SendKeyEvents();
+       Key_EventQueue_Block(); Sys_SendKeyEvents();
        key_dest = old_key_dest;
        key_consoleactive = old_key_consoleactive;
 }
diff --git a/host.c b/host.c
index c935523708d6af14d461b6afb3f20f0d0d4527e5..58a212b36b70cb43a8cd4966594919ee84dd61c4 100644 (file)
--- a/host.c
+++ b/host.c
@@ -679,6 +679,7 @@ void Host_Main(void)
                cl.islocalgame = NetConn_IsLocalGame();
 
                // get new key events
+               Key_EventQueue_Unblock();
                SndSys_SendKeyEvents();
                Sys_SendKeyEvents();
 
diff --git a/keys.c b/keys.c
index 9915313ea7c6e17e90991cfdaf49e19e7d121e00..5339881f2070001662c561932dc0fad544bcdeda 100644 (file)
--- a/keys.c
+++ b/keys.c
@@ -1405,6 +1405,44 @@ Should NOT be called during an interrupt!
 static char tbl_keyascii[MAX_KEYS];
 static keydest_t tbl_keydest[MAX_KEYS];
 
+typedef struct eventqueueitem_s
+{
+       int key;
+       int ascii;
+       qboolean down;
+}
+eventqueueitem_t;
+static int events_blocked = 0;
+static eventqueueitem_t eventqueue[32];
+static unsigned eventqueue_idx = 0;
+
+static void Key_EventQueue_Add(int key, int ascii, qboolean down)
+{
+       if(eventqueue_idx < sizeof(eventqueue) / sizeof(*eventqueue))
+       {
+               eventqueue[eventqueue_idx].key = key;
+               eventqueue[eventqueue_idx].ascii = ascii;
+               eventqueue[eventqueue_idx].down = down;
+               ++eventqueue_idx;
+       }
+}
+
+void Key_EventQueue_Block(void)
+{
+       // block key events until call to Unblock
+       events_blocked = true;
+}
+
+void Key_EventQueue_Unblock(void)
+{
+       // unblocks key events again
+       unsigned i;
+       events_blocked = false;
+       for(i = 0; i < eventqueue_idx; ++i)
+               Key_Event(eventqueue[i].key, eventqueue[i].ascii, eventqueue[i].down);
+       eventqueue_idx = 0;
+}
+
 void
 Key_Event (int key, int ascii, qboolean down)
 {
@@ -1415,6 +1453,12 @@ Key_Event (int key, int ascii, qboolean down)
        if (key < 0 || key >= MAX_KEYS)
                return;
 
+       if(events_blocked)
+       {
+               Key_EventQueue_Add(key, ascii, down);
+               return;
+       }
+
        // get key binding
        bind = keybindings[key_bmap][key];
        if (!bind)
diff --git a/keys.h b/keys.h
index 2e5d859fc920d7d289e0ad38089e5e3cce759b9d..c270282b1e75cca6b1ba82ce7ff0c5c768032a28 100644 (file)
--- a/keys.h
+++ b/keys.h
@@ -346,6 +346,8 @@ void Key_Init_Cvars(void);
 void Key_Event(int key, int ascii, qboolean down);
 void Key_ClearStates (void);
 void Key_SetBinding (int keynum, int bindmap, const char *binding);
+void Key_EventQueue_Block(void);
+void Key_EventQueue_Unblock(void);
 
 #endif // __KEYS_H