From 71f1fa270fcf2044a2e401c8b9b0d0ea05b22c95 Mon Sep 17 00:00:00 2001 From: Spoike Date: Sat, 17 Jul 2021 15:10:22 +0000 Subject: [PATCH] Clean up key held statuses a little, to try to fix issues with dual-controller splitscreen. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5968 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/client/cl_cg.c | 1 - engine/client/cl_ui.c | 1 - engine/client/keys.c | 53 +++++++++++++------------------------ engine/client/keys.h | 5 ++-- engine/client/m_download.c | 1 - engine/client/m_items.c | 4 +-- engine/client/m_master.c | 3 --- engine/client/m_multi.c | 1 - engine/client/m_options.c | 2 -- engine/client/m_single.c | 1 - engine/client/menu.c | 1 - engine/client/pr_menu.c | 1 - engine/client/textedit.c | 1 - engine/common/cmd.c | 1 - plugins/ezhud/ezquakeisms.c | 2 +- plugins/ezhud/hud_editor.c | 8 +++--- 16 files changed, 26 insertions(+), 60 deletions(-) diff --git a/engine/client/cl_cg.c b/engine/client/cl_cg.c index ab1b7383f..9511bcf92 100644 --- a/engine/client/cl_cg.c +++ b/engine/client/cl_cg.c @@ -1068,7 +1068,6 @@ static qintptr_t CG_SystemCalls(void *offset, quintptr_t mask, qintptr_t fn, con case CG_KEY_ISDOWN: { - extern qboolean keydown[K_MAX]; if (keydown[VM_LONG(arg[0])]) VM_LONG(ret) = 1; else diff --git a/engine/client/cl_ui.c b/engine/client/cl_ui.c index 9562d1eee..ee9f7b2e4 100644 --- a/engine/client/cl_ui.c +++ b/engine/client/cl_ui.c @@ -1233,7 +1233,6 @@ static qintptr_t UI_SystemCalls(void *offset, quintptr_t mask, qintptr_t fn, con case UI_KEY_ISDOWN: { - extern qboolean keydown[K_MAX]; unsigned int k = VM_LONG(arg[0]); if (k < K_MAX && keydown[k]) VM_LONG(ret) = 1; diff --git a/engine/client/keys.c b/engine/client/keys.c index 121c81d2c..b474c8b33 100644 --- a/engine/client/keys.c +++ b/engine/client/keys.c @@ -34,7 +34,6 @@ void Key_ClearTyping (void); unsigned char *key_lines[CON_EDIT_LINES_MASK+1]; int key_linepos; int shift_down=false; -int key_lastpress; int edit_line=0; int history_line=0; @@ -45,15 +44,13 @@ unsigned int key_dest_absolutemouse; struct key_cursor_s key_customcursor[kc_max]; -int key_count; // incremented every key event - int key_bindmaps[2]; char *keybindings[K_MAX][KEY_MODIFIERSTATES]; qbyte bindcmdlevel[K_MAX][KEY_MODIFIERSTATES]; //should be a struct, but not due to 7 bytes wasted per on 64bit machines qboolean consolekeys[K_MAX]; // if true, can't be rebound while in console int keyshift[K_MAX]; // key to map to if shift held down in console -int key_repeats[K_MAX]; // if > 1, it is autorepeating -qboolean keydown[K_MAX]; +unsigned int keydown[K_MAX]; // bitmask, for each device (to block autorepeat binds per-seat). +//unsigned int key_modifier[K_MAX]; #define MAX_INDEVS 8 @@ -64,15 +61,15 @@ extern cvar_t con_displaypossibilities; cvar_t con_echochat = CVAR("con_echochat", "0"); extern cvar_t cl_chatmode; -static int KeyModifier (qboolean shift, qboolean alt, qboolean ctrl) +static int KeyModifier (unsigned int shift, unsigned int alt, unsigned int ctrl, unsigned int devbit) { int stateset = 0; - if (shift) - stateset |= 1; - if (alt) - stateset |= 2; - if (ctrl) - stateset |= 4; + if (shift&devbit) + stateset |= KEY_MODIFIER_SHIFT; + if (alt&devbit) + stateset |= KEY_MODIFIER_ALT; + if (ctrl&devbit) + stateset |= KEY_MODIFIER_CTRL; return stateset; } @@ -2896,11 +2893,13 @@ On some systems, keys and (uni)char codes will be entirely separate events. */ void Key_Event (unsigned int devid, int key, unsigned int unicode, qboolean down) { + unsigned int devbit = 1u<0)); //if the input line is empty, allow ` to toggle the console, otherwise enter it as actual text. + qboolean wasdown = !!(keydown[key]&devbit); // Con_Printf ("%i : %i : %i\n", key, unicode, down); //@@@ @@ -2912,25 +2911,15 @@ void Key_Event (unsigned int devid, int key, unsigned int unicode, qboolean down if (key == K_RSHIFT && !keydown[K_RSHIFT] && keydown[K_LSHIFT]) Key_Event(devid, K_LSHIFT, 0, false); - modifierstate = KeyModifier(keydown[K_LSHIFT]|keydown[K_RSHIFT], keydown[K_LALT]|keydown[K_RALT], keydown[K_LCTRL]|keydown[K_RCTRL]); + modifierstate = KeyModifier(keydown[K_LSHIFT]|keydown[K_RSHIFT], keydown[K_LALT]|keydown[K_RALT], keydown[K_LCTRL]|keydown[K_RCTRL], devbit); - keydown[key] = down; + if (down) + keydown[key] |= devbit; + else + keydown[key] &= ~devbit; - if (!down) - key_repeats[key] = 0; - - key_lastpress = key; - key_count++; - if (key_count <= 0) - { - return; // just catching keys for Con_NotifyBox - } - -// update auto-repeat status if (down) { - key_repeats[key]++; - // if (key >= 200 && !keybindings[key]) //is this too annoying? // Con_Printf ("%s is unbound, hit F4 to set.\n", Key_KeynumToString (key) ); } @@ -3144,7 +3133,7 @@ void Key_Event (unsigned int devid, int key, unsigned int unicode, qboolean down //anything else is a key binding. /*don't auto-repeat binds as it breaks too many scripts*/ - if (key_repeats[key] > 1) + if (down && wasdown) return; //first player is normally assumed anyway. @@ -3255,10 +3244,7 @@ defaultedbind: bl = bindcmdlevel[bkey][modifierstate]; } else if (!Key_MouseShouldBeFree()) - { - key_repeats[key] = 0; return; - } } } } @@ -3303,9 +3289,6 @@ void Key_ClearStates (void) int i; for (i=0 ; iframe.common.posy; option->frame.common.width = 16; option->frame.common.posx = vid.width - option->frame.common.width - xpos; @@ -1986,7 +1985,6 @@ void M_Complex_Key(emenu_t *currentmenu, int key, int unicode) if (key != K_ESCAPE && key != '`') { int modifiers = 0; - extern qboolean keydown[]; if (keydown[K_LSHIFT] && key != K_LSHIFT) modifiers |= 1; if (keydown[K_RSHIFT] && key != K_RSHIFT) @@ -2370,7 +2368,7 @@ void M_Menu_Main_f (void) b->common.height = 20; y += 20; - b=MC_AddConsoleCommandHexen2BigFont (mainm, 80, y, "Mods", "menu_modshelp\n"); + b=MC_AddConsoleCommandHexen2BigFont (mainm, 80, y, "Mods", "menu_mods\n"); b->common.width = 12*20; b->common.height = 20; y += 20; diff --git a/engine/client/m_master.c b/engine/client/m_master.c index f4cdd2b23..f9acbc2c8 100644 --- a/engine/client/m_master.c +++ b/engine/client/m_master.c @@ -323,7 +323,6 @@ static qboolean SL_ServerKey (menucustom_t *ths, emenu_t *menu, int key, unsigne int oldselection; serverlist_t *info = (serverlist_t*)(menu + 1); serverinfo_t *server; - extern qboolean keydown[]; qboolean ctrl = keydown[K_LCTRL] || keydown[K_RCTRL]; if (key == K_MOUSE1) @@ -743,7 +742,6 @@ static qboolean SL_Key (int key, emenu_t *menu) { char buf[64]; serverinfo_t *server = selectedserver.inuse?Master_InfoForServer(&selectedserver.adr, selectedserver.brokerid):NULL; - extern qboolean keydown[]; qboolean ctrldown = keydown[K_LCTRL] || keydown[K_RCTRL]; if (key == K_ESCAPE || key == K_GP_BACK || key == K_MOUSE2) @@ -954,7 +952,6 @@ static void SL_ServerPlayer (int x, int y, menucustom_t *ths, emenu_t *menu) static void SL_SliderDraw (int x, int y, menucustom_t *ths, emenu_t *menu) { - extern qboolean keydown[K_MAX]; serverlist_t *info = (serverlist_t*)(menu + 1); mpic_t *pic; diff --git a/engine/client/m_multi.c b/engine/client/m_multi.c index 59dd80aed..b90560521 100644 --- a/engine/client/m_multi.c +++ b/engine/client/m_multi.c @@ -215,7 +215,6 @@ static unsigned int hsvtorgb(float inh, float s, float v) qboolean SetupMenuColour (union menuoption_s *option,struct emenu_s *menu, int key) { - extern qboolean keydown[K_MAX]; setupmenu_t *info = menu->data; unsigned int *ptr = (*option->button.text == 'T')?&info->topcolour:&info->lowercolour; diff --git a/engine/client/m_options.c b/engine/client/m_options.c index 47cd795cc..e85a87b85 100644 --- a/engine/client/m_options.c +++ b/engine/client/m_options.c @@ -3375,7 +3375,6 @@ static unsigned int tobit(unsigned int bitmask) } static void M_ModelViewerDraw(int x, int y, struct menucustom_s *c, struct emenu_s *m) { - extern qboolean keydown[]; static playerview_t pv; entity_t ent; vec3_t fwd, rgt, up; @@ -4003,7 +4002,6 @@ static void M_ModelViewerDraw(int x, int y, struct menucustom_s *c, struct emenu } static qboolean M_ModelViewerKey(struct menucustom_s *c, struct emenu_s *m, int key, unsigned int unicode) { - extern qboolean keydown[]; modelview_t *mods = c->dptr; if ((key == 'w' && !keydown[K_MOUSE1]) || key == K_MWHEELUP) diff --git a/engine/client/m_single.c b/engine/client/m_single.c index cddda30a3..f628c72d2 100644 --- a/engine/client/m_single.c +++ b/engine/client/m_single.c @@ -611,7 +611,6 @@ typedef struct { static void M_DemoDraw(int x, int y, menucustom_t *control, emenu_t *menu) { - extern qboolean keydown[K_MAX]; char *text; demomenu_t *info = menu->data; demoitem_t *item, *lostit; diff --git a/engine/client/menu.c b/engine/client/menu.c index 0c1f4d548..79a02ef68 100644 --- a/engine/client/menu.c +++ b/engine/client/menu.c @@ -430,7 +430,6 @@ static qboolean Prompt_MenuKeyEvent(struct menu_s *gm, qboolean isdown, unsigned promptbutton_t action; void (*callback)(void *, promptbutton_t) = m->callback; void *ctx = m->ctx; - extern qboolean keydown[]; if (key == K_MOUSE1) { //mouse events fire their action on release. diff --git a/engine/client/pr_menu.c b/engine/client/pr_menu.c index e29bcf120..a87d09f2a 100644 --- a/engine/client/pr_menu.c +++ b/engine/client/pr_menu.c @@ -2815,7 +2815,6 @@ static qboolean MP_KeyEvent(menu_t *menu, qboolean isdown, unsigned int devid, i #ifdef _DEBUG if (key == 'c') { - extern qboolean keydown[K_MAX]; if ((keydown[K_LCTRL] || keydown[K_RCTRL]) && (keydown[K_LSHIFT] || keydown[K_RSHIFT])) { MP_Shutdown(); diff --git a/engine/client/textedit.c b/engine/client/textedit.c index 58ff79841..2c387cfb8 100644 --- a/engine/client/textedit.c +++ b/engine/client/textedit.c @@ -494,7 +494,6 @@ static void Con_Editor_LineChanged(console_t *con, conline_t *line) } qboolean Con_Editor_Key(console_t *con, unsigned int unicode, int key) { - extern qboolean keydown[K_MAX]; qboolean altdown = keydown[K_LALT] || keydown[K_RALT]; qboolean ctrldown = keydown[K_LCTRL] || keydown[K_RCTRL]; qboolean shiftdown = keydown[K_LSHIFT] || keydown[K_RSHIFT]; diff --git a/engine/common/cmd.c b/engine/common/cmd.c index 240338111..76c1f68c2 100644 --- a/engine/common/cmd.c +++ b/engine/common/cmd.c @@ -2798,7 +2798,6 @@ static void Cmd_ExecuteStringGlobalsAreEvil (const char *text, int level) int execlevel; #ifdef HAVE_CLIENT //an emergency escape mechansim, to avoid infinatly recursing aliases. - extern qboolean keydown[]; extern unsigned int con_splitmodifier; if (keydown[K_SHIFT] && (keydown[K_LCTRL]||keydown[K_RCTRL]) && (keydown[K_LALT]||keydown[K_RALT]) && !isDedicated) diff --git a/plugins/ezhud/ezquakeisms.c b/plugins/ezhud/ezquakeisms.c index ce080da38..58a6fec57 100644 --- a/plugins/ezhud/ezquakeisms.c +++ b/plugins/ezhud/ezquakeisms.c @@ -692,7 +692,7 @@ int EZHud_Draw(int seat, float viewx, float viewy, float viewwidth, float viewhe return true; } -int keydown[K_MAX]; +unsigned int keydown[K_MAX]; float cursor_x; float cursor_y; float mouse_x; diff --git a/plugins/ezhud/hud_editor.c b/plugins/ezhud/hud_editor.c index be51075e1..58322e9aa 100644 --- a/plugins/ezhud/hud_editor.c +++ b/plugins/ezhud/hud_editor.c @@ -40,10 +40,10 @@ along with this program. If not, see . #include "hud.h" #include "hud_editor.h" -extern int keydown[]; -#define isShiftDown() false -#define isCtrlDown() false -#define isAltDown() false +extern unsigned int keydown[]; +#define isShiftDown() (keydown[K_LSHIFT]||keydown[K_RSHIFT]) +#define isCtrlDown() (keydown[K_LCTRL]||keydown[K_RCTRL]) +#define isAltDown() (keydown[K_LALT]||keydown[K_RALT]) #ifdef HAXX ez_tree_t help_control_tree;