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
This commit is contained in:
Spoike 2021-07-17 15:10:22 +00:00
parent 9735064a89
commit 71f1fa270f
16 changed files with 26 additions and 60 deletions

View File

@ -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

View File

@ -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;

View File

@ -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<<devid;
int bl, bkey;
char *dc, *uc;
char p[16];
int modifierstate;
int conkey = consolekeys[key] || ((unicode || key == '`') && (key != '`' || key_linepos>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 ; i<K_MAX ; i++)
{
keydown[i] = false;
key_repeats[i] = false;
}
keydown[i] = 0;
}

View File

@ -266,9 +266,8 @@ typedef enum //highest has priority
extern unsigned int key_dest_absolutemouse; //if the active key dest bit is set, the mouse is absolute.
extern unsigned int key_dest_mask;
extern char *keybindings[K_MAX][KEY_MODIFIERSTATES];
extern int key_repeats[K_MAX];
extern int key_count; // incremented every key event
extern int key_lastpress;
extern unsigned int keydown[K_MAX]; //bitmask of devices.
enum
{

View File

@ -4946,7 +4946,6 @@ static void MD_Draw (int x, int y, struct menucustom_s *c, struct emenu_s *m)
static qboolean MD_Key (struct menucustom_s *c, struct emenu_s *m, int key, unsigned int unicode)
{
extern qboolean keydown[];
qboolean ctrl = keydown[K_LCTRL] || keydown[K_RCTRL];
package_t *p, *p2;
struct packagedep_s *dep, *dep2;

View File

@ -584,7 +584,6 @@ static void MenuDrawItems(int xpos, int ypos, menuoption_t *option, emenu_t *men
{
srect_t srect;
menuoption_t *opt2;
extern qboolean keydown[];
int maxy = option->frame.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;

View File

@ -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;

View File

@ -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;

View File

@ -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)

View File

@ -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;

View File

@ -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.

View File

@ -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();

View File

@ -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];

View File

@ -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)

View File

@ -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;

View File

@ -40,10 +40,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#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;