From 992de0210164b1b4ba58940b6820bf4e816634f7 Mon Sep 17 00:00:00 2001 From: terminx Date: Sat, 17 Nov 2012 16:47:58 +0000 Subject: [PATCH] Change key bindings to use dynamic allocation and remove the previous limit of 128 characters per key bind git-svn-id: https://svn.eduke32.com/eduke32@3197 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/config.c | 20 ++++++---- polymer/eduke32/source/jmact/control.c | 32 +++++++++++----- polymer/eduke32/source/jmact/control.h | 3 +- polymer/eduke32/source/jmact/keyboard.h | 2 +- polymer/eduke32/source/menus.c | 13 ++++++- polymer/eduke32/source/osdcmds.c | 51 +++++++++++++++++-------- 6 files changed, 83 insertions(+), 38 deletions(-) diff --git a/polymer/eduke32/source/config.c b/polymer/eduke32/source/config.c index 6f6e064ee..e0b385adb 100644 --- a/polymer/eduke32/source/config.c +++ b/polymer/eduke32/source/config.c @@ -350,7 +350,7 @@ void CONFIG_MapKey(int32_t which, kb_scancode key1, kb_scancode oldkey1, kb_scan CONTROL_KeyBinds[ii[k]].key=Bstrdup(ConsoleKeys[j].name); CONTROL_KeyBinds[ii[k]].repeat = 1; - CONTROL_KeyBinds[ii[k]].cmd[0] = 0; + tempbuf[0] = 0; for (i=NUMGAMEFUNCTIONS-1; i>=0; i--) @@ -362,11 +362,13 @@ void CONFIG_MapKey(int32_t which, kb_scancode key1, kb_scancode oldkey1, kb_scan } } - Bstrncpyz(CONTROL_KeyBinds[ii[k]].cmd, tempbuf, MAXBINDSTRINGLENGTH); + CONTROL_KeyBinds[ii[k]].cmdstr = (char *)Brealloc(CONTROL_KeyBinds[ii[k]].cmdstr, Bstrlen(tempbuf)); - i = Bstrlen(CONTROL_KeyBinds[ii[k]].cmd); + Bstrncpyz(CONTROL_KeyBinds[ii[k]].cmdstr, tempbuf, Bstrlen(tempbuf)); + + i = Bstrlen(CONTROL_KeyBinds[ii[k]].cmdstr); if (i) - CONTROL_KeyBinds[ii[k]].cmd[i-2] = 0; // cut off the trailing "; " + CONTROL_KeyBinds[ii[k]].cmdstr[i-2] = 0; // cut off the trailing "; " } } @@ -734,12 +736,14 @@ void CONFIG_WriteBinds(void) // save binds and aliases to _settings.cfg Bfprintf(fp,"unbindall\n"); for (i=0; inext) if (symb->func == (void *)OSD_ALIAS) diff --git a/polymer/eduke32/source/jmact/control.c b/polymer/eduke32/source/jmact/control.c index 87ef416c7..098d1cbbc 100644 --- a/polymer/eduke32/source/jmact/control.c +++ b/polymer/eduke32/source/jmact/control.c @@ -118,10 +118,10 @@ int32_t CONTROL_KeyboardFunctionPressed(int32_t which) if (!CONTROL_Flags[which].used) return FALSE; - if (CONTROL_KeyMapping[which].key1 != KEYUNDEFINED && !KeyBindings[CONTROL_KeyMapping[which].key1].cmd[0]) + if (CONTROL_KeyMapping[which].key1 != KEYUNDEFINED && !KeyBindings[CONTROL_KeyMapping[which].key1].cmdstr) key1 = KB_KeyDown[ CONTROL_KeyMapping[which].key1 ] ? TRUE : FALSE; - if (CONTROL_KeyMapping[which].key2 != KEYUNDEFINED && !KeyBindings[CONTROL_KeyMapping[which].key2].cmd[0]) + if (CONTROL_KeyMapping[which].key2 != KEYUNDEFINED && !KeyBindings[CONTROL_KeyMapping[which].key2].cmdstr) key2 = KB_KeyDown[ CONTROL_KeyMapping[which].key2 ] ? TRUE : FALSE; return (key1 | key2); @@ -663,7 +663,7 @@ static void CONTROL_ButtonFunctionState(int32_t *p1) do { - if (!CONTROL_MouseBinds[i].cmd[0]) + if (!CONTROL_MouseBinds[i].cmdstr) { j = CONTROL_MouseButtonMapping[i].doubleclicked; if (j != KEYUNDEFINED) @@ -677,10 +677,10 @@ static void CONTROL_ButtonFunctionState(int32_t *p1) if (!CONTROL_BindsEnabled) continue; - if (CONTROL_MouseBinds[i].cmd[0] && CONTROL_MouseButtonState[i]) + if (CONTROL_MouseBinds[i].cmdstr && CONTROL_MouseButtonState[i]) { if (CONTROL_MouseBinds[i].repeat || (CONTROL_MouseBinds[i].laststate == 0)) - OSD_Dispatch(CONTROL_MouseBinds[i].cmd); + OSD_Dispatch(CONTROL_MouseBinds[i].cmdstr); } CONTROL_MouseBinds[i].laststate = CONTROL_MouseButtonState[i]; } @@ -721,12 +721,10 @@ void CONTROL_ProcessBinds(void) do { - if (CONTROL_KeyBinds[i].cmd[0]) + if (CONTROL_KeyBinds[i].cmdstr) { if (KB_KeyPressed(i) && (CONTROL_KeyBinds[i].repeat || (CONTROL_KeyBinds[i].laststate == 0))) - { - OSD_Dispatch(CONTROL_KeyBinds[i].cmd); - } + OSD_Dispatch(CONTROL_KeyBinds[i].cmdstr); CONTROL_KeyBinds[i].laststate = KB_KeyPressed(i); } @@ -830,9 +828,23 @@ int32_t CONTROL_Startup(controltype which, int32_t(*TimeFunction)(void), int32_t void CONTROL_Shutdown(void) { + int32_t i; + if (!CONTROL_Started) return; - CONTROL_JoyPresent = FALSE; + for (i=0; i>1][whichkey&1] = x; CONTROL_MapButton(x, whichkey>>1, whichkey&1, controldevice_mouse); - CONTROL_MouseBinds[whichkey>>1].cmd[0] = 0; // kill the bind when changing the button in the menu + if (CONTROL_MouseBinds[whichkey>>1].cmdstr) + { + Bfree(CONTROL_MouseBinds[whichkey>>1].cmdstr); + CONTROL_MouseBinds[whichkey>>1].cmdstr = NULL; + } } else { ud.config.MouseFunctions[whichkey-NUMDOUBLEMBTNS][0] = x; CONTROL_MapButton(x, whichkey-NUMDOUBLEMBTNS, 0, controldevice_mouse); - CONTROL_MouseBinds[whichkey-NUMDOUBLEMBTNS].cmd[0] = 0; + if (CONTROL_MouseBinds[whichkey-NUMDOUBLEMBTNS].cmdstr) + { + Bfree(CONTROL_MouseBinds[whichkey-NUMDOUBLEMBTNS].cmdstr); + CONTROL_MouseBinds[whichkey-NUMDOUBLEMBTNS].cmdstr = NULL; + } + } M_ChangeMenu(205); probey = whichkey; diff --git a/polymer/eduke32/source/osdcmds.c b/polymer/eduke32/source/osdcmds.c index fc1057f78..7f335bf46 100644 --- a/polymer/eduke32/source/osdcmds.c +++ b/polymer/eduke32/source/osdcmds.c @@ -921,19 +921,19 @@ static int32_t osdcmd_bind(const osdfuncparm_t *parm) OSD_Printf("Current key bindings:\n"); for (i=0; inumparms < 2) { - OSD_Printf("%-9s %s\"%s\"\n", ConsoleButtons[i], CONTROL_MouseBinds[i].repeat?"":"norepeat ", - CONTROL_MouseBinds[i].cmd); + if (CONTROL_MouseBinds[i].cmdstr && CONTROL_MouseBinds[i].key) + OSD_Printf("%-9s %s\"%s\"\n", ConsoleButtons[i], CONTROL_MouseBinds[i].repeat?"":"norepeat ", + CONTROL_MouseBinds[i].cmdstr); return OSDCMD_OK; } @@ -976,7 +977,10 @@ static int32_t osdcmd_bind(const osdfuncparm_t *parm) Bstrcat(tempbuf," "); Bstrcat(tempbuf,parm->parms[j++]); } - Bstrncpy(CONTROL_MouseBinds[i].cmd,tempbuf, MAXBINDSTRINGLENGTH-1); + + CONTROL_MouseBinds[i].cmdstr = (char *)Brealloc(CONTROL_MouseBinds[i].cmdstr, Bstrlen(tempbuf)); + + Bstrncpyz(CONTROL_MouseBinds[i].cmdstr, tempbuf, Bstrlen(tempbuf)); CONTROL_MouseBinds[i].key=ConsoleButtons[i]; if (!OSD_ParsingScript()) @@ -986,8 +990,9 @@ static int32_t osdcmd_bind(const osdfuncparm_t *parm) if (parm->numparms < 2) { + if (CONTROL_KeyBinds[ConsoleKeys[i].id].cmdstr && CONTROL_KeyBinds[ConsoleKeys[i].id].key) OSD_Printf("%-9s %s\"%s\"\n", ConsoleKeys[i].name, CONTROL_KeyBinds[ConsoleKeys[i].id].repeat?"":"norepeat ", - CONTROL_KeyBinds[ConsoleKeys[i].id].cmd); + CONTROL_KeyBinds[ConsoleKeys[i].id].cmdstr); return OSDCMD_OK; } @@ -1006,7 +1011,9 @@ static int32_t osdcmd_bind(const osdfuncparm_t *parm) Bstrcat(tempbuf," "); Bstrcat(tempbuf,parm->parms[j++]); } - Bstrncpy(CONTROL_KeyBinds[ConsoleKeys[i].id].cmd,tempbuf, MAXBINDSTRINGLENGTH-1); + + CONTROL_KeyBinds[ConsoleKeys[i].id].cmdstr = (char *)Brealloc(CONTROL_KeyBinds[ConsoleKeys[i].id].cmdstr, Bstrlen(tempbuf)); + Bstrncpyz(CONTROL_KeyBinds[ConsoleKeys[i].id].cmdstr,tempbuf, Bstrlen(tempbuf)); CONTROL_KeyBinds[ConsoleKeys[i].id].key=ConsoleKeys[i].name; @@ -1055,12 +1062,18 @@ static int32_t osdcmd_unbindall(const osdfuncparm_t *parm) UNREFERENCED_PARAMETER(parm); for (i=0; i