diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 501cbd087..9373371b5 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -786,6 +786,7 @@ set (PCH_SOURCES common/gameconfigfile.cpp common/gamecvars.cpp common/gamecontrol.cpp + common/inputstate.cpp common/2d/v_2ddrawer.cpp common/2d/v_draw.cpp diff --git a/source/blood/src/messages.cpp b/source/blood/src/messages.cpp index 02cad3fad..f95a2fa97 100644 --- a/source/blood/src/messages.cpp +++ b/source/blood/src/messages.cpp @@ -616,7 +616,6 @@ void CPlayerMsg::ProcessKeys(void) Set(*CombatMacros[key-sc_F1]); Send(); inputState.ClearKeyStatus(key); - } break; case sc_BackSpace: if (ctrl) diff --git a/source/blood/src/osdcmd.cpp b/source/blood/src/osdcmd.cpp index 9926a7064..4a00e0e46 100644 --- a/source/blood/src/osdcmd.cpp +++ b/source/blood/src/osdcmd.cpp @@ -476,207 +476,6 @@ void onvideomodechange(int32_t newmode) UpdateDacs(gLastPal, false); } -const char *const ConsoleButtons[] = -{ - "mouse1", "mouse2", "mouse3", "mouse4", "mwheelup", - "mwheeldn", "mouse5", "mouse6", "mouse7", "mouse8" -}; - -static int osdcmd_bind(osdcmdptr_t parm) -{ - char buffer[256]; - if (parm->numparms==1 && !Bstrcasecmp(parm->parms[0],"showkeys")) - { - for (auto & s : sctokeylut) - OSD_Printf("%s\n", s.key); - for (auto ConsoleButton : ConsoleButtons) - OSD_Printf("%s\n",ConsoleButton); - return OSDCMD_OK; - } - - if (parm->numparms==0) - { - int j=0; - - OSD_Printf("Current key bindings:\n"); - - for (int i=0; iparms[0], sctokeylut[i].key)) - break; - } - - // didn't find the key - if (i == ARRAY_SSIZE(sctokeylut)) - { - for (i=0; iparms[0],ConsoleButtons[i])) - break; - - if (i >= MAXMOUSEBUTTONS) - return OSDCMD_SHOWHELP; - - if (parm->numparms < 2) - { - if (CONTROL_KeyBinds[MAXBOUNDKEYS + i].cmdstr && CONTROL_KeyBinds[MAXBOUNDKEYS + i ].key) - OSD_Printf("%-9s %s\"%s\"\n", ConsoleButtons[i], CONTROL_KeyBinds[MAXBOUNDKEYS + i].repeat?"":"norepeat ", - CONTROL_KeyBinds[MAXBOUNDKEYS + i].cmdstr); - else OSD_Printf("%s is unbound\n", ConsoleButtons[i]); - return OSDCMD_OK; - } - - j = 1; - - repeat = 1; - if (!Bstrcasecmp(parm->parms[j],"norepeat")) - { - repeat = 0; - j++; - } - - Bstrcpy(buffer,parm->parms[j++]); - for (; jnumparms; j++) - { - Bstrcat(buffer," "); - Bstrcat(buffer,parm->parms[j++]); - } - - CONTROL_BindMouse(i, buffer, repeat, ConsoleButtons[i]); - - if (!OSD_ParsingScript()) - OSD_Printf("%s\n",parm->raw); - return OSDCMD_OK; - } - - if (parm->numparms < 2) - { - if (CONTROL_KeyIsBound(sctokeylut[i].sc)) - OSD_Printf("%-9s %s\"%s\"\n", sctokeylut[i].key, CONTROL_KeyBinds[sctokeylut[i].sc].repeat?"":"norepeat ", - CONTROL_KeyBinds[sctokeylut[i].sc].cmdstr); - else OSD_Printf("%s is unbound\n", sctokeylut[i].key); - - return OSDCMD_OK; - } - - j = 1; - - repeat = 1; - if (!Bstrcasecmp(parm->parms[j],"norepeat")) - { - repeat = 0; - j++; - } - - Bstrcpy(buffer,parm->parms[j++]); - for (; jnumparms; j++) - { - Bstrcat(buffer," "); - Bstrcat(buffer,parm->parms[j++]); - } - - CONTROL_BindKey(sctokeylut[i].sc, buffer, repeat, sctokeylut[i].key); - - char *cp = buffer; - - // Populate the keyboard config menu based on the bind. - // Take care of processing one-to-many bindings properly, too. - static char const s_gamefunc_[] = "gamefunc_"; - int constexpr strlen_gamefunc_ = ARRAY_SIZE(s_gamefunc_) - 1; - - while ((cp = Bstrstr(cp, s_gamefunc_))) - { - cp += strlen_gamefunc_; - - char *semi = Bstrchr(cp, ';'); - - if (semi) - *semi = 0; - - j = CONFIG_FunctionNameToNum(cp); - - if (semi) - cp = semi+1; - - if (j != -1) - { - KeyboardKeys[j][1] = KeyboardKeys[j][0]; - KeyboardKeys[j][0] = sctokeylut[i].sc; -// CONTROL_MapKey(j, sctokeylut[i].sc, KeyboardKeys[j][0]); - - if (j == gamefunc_Show_Console) - OSD_CaptureKey(sctokeylut[i].sc); - } - } - - if (!OSD_ParsingScript()) - OSD_Printf("%s\n",parm->raw); - - return OSDCMD_OK; -} - -static int osdcmd_unbindall(osdcmdptr_t UNUSED(parm)) -{ - UNREFERENCED_CONST_PARAMETER(parm); - - for (int i = 0; i < MAXBOUNDKEYS; ++i) - CONTROL_FreeKeyBind(i); - - for (int i = 0; i < MAXMOUSEBUTTONS; ++i) - CONTROL_FreeMouseBind(i); - - for (auto &KeyboardKey : KeyboardKeys) - KeyboardKey[0] = KeyboardKey[1] = 0xff; - - if (!OSD_ParsingScript()) - OSD_Printf("unbound all controls\n"); - - return OSDCMD_OK; -} - -static int osdcmd_unbind(osdcmdptr_t parm) -{ - if (parm->numparms != 1) - return OSDCMD_SHOWHELP; - - for (auto ConsoleKey : sctokeylut) - { - if (ConsoleKey.key && !Bstrcasecmp(parm->parms[0], ConsoleKey.key)) - { - CONTROL_FreeKeyBind(ConsoleKey.sc); - OSD_Printf("unbound key %s\n", ConsoleKey.key); - return OSDCMD_OK; - } - } - - for (int i = 0; i < MAXMOUSEBUTTONS; i++) - { - if (!Bstrcasecmp(parm->parms[0], ConsoleButtons[i])) - { - CONTROL_FreeMouseBind(i); - OSD_Printf("unbound %s\n", ConsoleButtons[i]); - return OSDCMD_OK; - } - } - - return OSDCMD_SHOWHELP; -} - static int osdcmd_unbound(osdcmdptr_t parm) { if (parm->numparms != 1) diff --git a/source/build/include/scancodes.h b/source/build/include/scancodes.h index 2436e4926..052713cf7 100644 --- a/source/build/include/scancodes.h +++ b/source/build/include/scancodes.h @@ -1,4 +1,4 @@ - +#pragma once #define sc_None 0 #define sc_Bad 0xff #define sc_Comma 0x33 diff --git a/source/common/gameconfigfile.cpp b/source/common/gameconfigfile.cpp index 529f61cd9..e3892c665 100644 --- a/source/common/gameconfigfile.cpp +++ b/source/common/gameconfigfile.cpp @@ -433,7 +433,7 @@ void FGameConfigFile::ArchiveGameData (const char *gamename) strcpy(subsection, "Bindings"); if (SetSection(section, true)) { - for (int i = 0; i < MAXBOUNDKEYS + MAXMOUSEBUTTONS; i++) + for (int i = 0; i < NUMKEYS + MAXMOUSEBUTTONS; i++) { if (CONTROL_KeyIsBound(i)) { diff --git a/source/common/gamecontrol.cpp b/source/common/gamecontrol.cpp index 987cd933a..1a2a038ba 100644 --- a/source/common/gamecontrol.cpp +++ b/source/common/gamecontrol.cpp @@ -9,6 +9,7 @@ #include "gameconfigfile.h" #include "gamecvars.h" #include "build.h" +#include "inputstate.h" InputState inputState; @@ -1111,3 +1112,206 @@ void CONFIG_WriteControllerSettings() } } + +const char* const ConsoleButtons[] = +{ + "mouse1", "mouse2", "mouse3", "mouse4", "mwheelup", + "mwheeldn", "mouse5", "mouse6", "mouse7", "mouse8" +}; + +int osdcmd_bind(osdcmdptr_t parm) +{ + char tempbuf[256]; + + if (parm->numparms == 1 && !Bstrcasecmp(parm->parms[0], "showkeys")) + { + for (auto& s : sctokeylut) + OSD_Printf("%s\n", s.key); + for (auto ConsoleButton : ConsoleButtons) + OSD_Printf("%s\n", ConsoleButton); + return OSDCMD_OK; + } + + if (parm->numparms == 0) + { + int j = 0; + + OSD_Printf("Current key bindings:\n"); + + for (int i = 0; i < NUMKEYS + MAXMOUSEBUTTONS; i++) + if (CONTROL_KeyIsBound(i)) + { + j++; + OSD_Printf("%-9s %s\"%s\"\n", CONTROL_KeyBinds[i].key, CONTROL_KeyBinds[i].repeat ? "" : "norepeat ", + CONTROL_KeyBinds[i].cmdstr); + } + + if (j == 0) + OSD_Printf("No binds found.\n"); + + return OSDCMD_OK; + } + + int i, j, repeat; + + for (i = 0; i < ARRAY_SSIZE(sctokeylut); i++) + { + if (!Bstrcasecmp(parm->parms[0], sctokeylut[i].key)) + break; + } + + // didn't find the key + if (i == ARRAY_SSIZE(sctokeylut)) + { + for (i = 0; i < MAXMOUSEBUTTONS; i++) + if (!Bstrcasecmp(parm->parms[0], ConsoleButtons[i])) + break; + + if (i >= MAXMOUSEBUTTONS) + return OSDCMD_SHOWHELP; + + if (parm->numparms < 2) + { + if (CONTROL_KeyBinds[NUMKEYS + i].cmdstr && CONTROL_KeyBinds[NUMKEYS + i].key) + OSD_Printf("%-9s %s\"%s\"\n", ConsoleButtons[i], CONTROL_KeyBinds[NUMKEYS + i].repeat ? "" : "norepeat ", + CONTROL_KeyBinds[NUMKEYS + i].cmdstr); + else OSD_Printf("%s is unbound\n", ConsoleButtons[i]); + return OSDCMD_OK; + } + + j = 1; + + repeat = 1; + if (!Bstrcasecmp(parm->parms[j], "norepeat")) + { + repeat = 0; + j++; + } + + Bstrcpy(tempbuf, parm->parms[j++]); + for (; j < parm->numparms; j++) + { + Bstrcat(tempbuf, " "); + Bstrcat(tempbuf, parm->parms[j++]); + } + + CONTROL_BindMouse(i, tempbuf, repeat, ConsoleButtons[i]); + + if (!OSD_ParsingScript()) + OSD_Printf("%s\n", parm->raw); + return OSDCMD_OK; + } + + if (parm->numparms < 2) + { + if (CONTROL_KeyIsBound(sctokeylut[i].sc)) + OSD_Printf("%-9s %s\"%s\"\n", sctokeylut[i].key, CONTROL_KeyBinds[sctokeylut[i].sc].repeat ? "" : "norepeat ", + CONTROL_KeyBinds[sctokeylut[i].sc].cmdstr); + else OSD_Printf("%s is unbound\n", sctokeylut[i].key); + + return OSDCMD_OK; + } + + j = 1; + + repeat = 1; + if (!Bstrcasecmp(parm->parms[j], "norepeat")) + { + repeat = 0; + j++; + } + + Bstrcpy(tempbuf, parm->parms[j++]); + for (; j < parm->numparms; j++) + { + Bstrcat(tempbuf, " "); + Bstrcat(tempbuf, parm->parms[j++]); + } + + CONTROL_BindKey(sctokeylut[i].sc, tempbuf, repeat, sctokeylut[i].key); + + char* cp = tempbuf; + + // Populate the keyboard config menu based on the bind. + // Take care of processing one-to-many bindings properly, too. + static char const s_gamefunc_[] = "gamefunc_"; + int constexpr strlen_gamefunc_ = ARRAY_SIZE(s_gamefunc_) - 1; + + while ((cp = Bstrstr(cp, s_gamefunc_))) + { + cp += strlen_gamefunc_; + + char* semi = Bstrchr(cp, ';'); + + if (semi) + *semi = 0; + + j = CONFIG_FunctionNameToNum(cp); + + if (semi) + cp = semi + 1; + + if (j != -1) + { + KeyboardKeys[j][1] = KeyboardKeys[j][0]; + KeyboardKeys[j][0] = sctokeylut[i].sc; + // CONTROL_MapKey(j, sctokeylut[i].sc, KeyboardKeys[j][0]); + + if (j == gamefunc_Show_Console) + OSD_CaptureKey(sctokeylut[i].sc); + } + } + + if (!OSD_ParsingScript()) + OSD_Printf("%s\n", parm->raw); + + return OSDCMD_OK; +} + +int osdcmd_unbindall(osdcmdptr_t UNUSED(parm)) +{ + UNREFERENCED_CONST_PARAMETER(parm); + + for (int i = 0; i < NUMKEYS; ++i) + CONTROL_FreeKeyBind(i); + + for (int i = 0; i < MAXMOUSEBUTTONS; ++i) + CONTROL_FreeMouseBind(i); + + for (auto& KeyboardKey : KeyboardKeys) + KeyboardKey[0] = KeyboardKey[1] = 0xff; + + if (!OSD_ParsingScript()) + OSD_Printf("unbound all controls\n"); + + return OSDCMD_OK; +} + +int osdcmd_unbind(osdcmdptr_t parm) +{ + if (parm->numparms != 1) + return OSDCMD_SHOWHELP; + + for (auto& ConsoleKey : sctokeylut) + { + if (ConsoleKey.key && !Bstrcasecmp(parm->parms[0], ConsoleKey.key)) + { + CONTROL_FreeKeyBind(ConsoleKey.sc); + OSD_Printf("unbound key %s\n", ConsoleKey.key); + return OSDCMD_OK; + } + } + + for (int i = 0; i < MAXMOUSEBUTTONS; i++) + { + if (!Bstrcasecmp(parm->parms[0], ConsoleButtons[i])) + { + CONTROL_FreeMouseBind(i); + OSD_Printf("unbound %s\n", ConsoleButtons[i]); + return OSDCMD_OK; + } + } + + return OSDCMD_SHOWHELP; +} + diff --git a/source/common/gamecontrol.h b/source/common/gamecontrol.h index efe529b3f..fc3f9b0d9 100644 --- a/source/common/gamecontrol.h +++ b/source/common/gamecontrol.h @@ -61,6 +61,10 @@ void CONFIG_SetGameControllerDefaultsClear(); char const* CONFIG_GetGameFuncOnJoystick(int gameFunc); char const* CONFIG_GetGameFuncOnKeyboard(int gameFunc); +int osdcmd_bind(osdcmdptr_t parm); +int osdcmd_unbindall(osdcmdptr_t); +int osdcmd_unbind(osdcmdptr_t parm); + extern FStringCVar* const CombatMacros[]; void CONFIG_ReadCombatMacros(); diff --git a/source/common/inputstate.h b/source/common/inputstate.h index dc4cea964..f1062dd00 100644 --- a/source/common/inputstate.h +++ b/source/common/inputstate.h @@ -1,18 +1,33 @@ #pragma once -#include "keyboard.h" -#include "control.h" +#include +#include "tarray.h" #include "scancodes.h" +typedef uint8_t kb_scancode; + extern kb_scancode KB_LastScan; +typedef struct +{ + const char* key; + char* cmdstr; + char repeat; + char laststate; +} +consolekeybind_t; + // This encapsulates the entire game-readable input state which previously was spread out across several files. enum { NUMKEYS = 256, + MAXMOUSEBUTTONS = 10, + }; +extern consolekeybind_t CONTROL_KeyBinds[NUMKEYS + MAXMOUSEBUTTONS]; + // Order is that of EDuke32 by necessity because it exposes the key binds to scripting by index instead of by name. enum GameFunction_t @@ -164,7 +179,7 @@ public: return KeyStatus[key]; } - void SetKeyStatus(int key, int state) + void SetKeyStatus(int key, int state = 1) { KeyStatus[key] = (uint8_t)state; } @@ -186,7 +201,7 @@ public: bool CtrlPressed() { - KeyStatus[sc_LeftControl] || KeyStatus[sc_RightControl]; + return KeyStatus[sc_LeftControl] || KeyStatus[sc_RightControl]; } bool ShiftPressed() diff --git a/source/duke3d/src/game.h b/source/duke3d/src/game.h index 5b8ad4196..a4f9e6125 100644 --- a/source/duke3d/src/game.h +++ b/source/duke3d/src/game.h @@ -204,21 +204,6 @@ typedef struct { struct { int32_t AutoAim; int32_t ShowWeapons; - - // JBF 20031211: Store the input settings because - // (currently) mact can't regurgitate them - int32_t MouseFunctions[MAXMOUSEBUTTONS][2]; - int32_t MouseDigitalFunctions[MAXMOUSEAXES][2]; - int32_t MouseAnalogueAxes[MAXMOUSEAXES]; - int32_t MouseAnalogueScale[MAXMOUSEAXES]; - int32_t JoystickFunctions[MAXJOYBUTTONSANDHATS][2]; - int32_t JoystickDigitalFunctions[MAXJOYAXES][2]; - int32_t JoystickAnalogueAxes[MAXJOYAXES]; - int32_t JoystickAnalogueScale[MAXJOYAXES]; - int32_t JoystickAnalogueInvert[MAXJOYAXES]; - int32_t JoystickAnalogueDead[MAXJOYAXES]; - int32_t JoystickAnalogueSaturate[MAXJOYAXES]; - int32_t setupread; } config; diff --git a/source/duke3d/src/osdcmds.cpp b/source/duke3d/src/osdcmds.cpp index 62162ab11..f29de609a 100644 --- a/source/duke3d/src/osdcmds.cpp +++ b/source/duke3d/src/osdcmds.cpp @@ -857,206 +857,6 @@ void onvideomodechange(int32_t newmode) g_crosshairSum = -1; } -const char *const ConsoleButtons[] = -{ - "mouse1", "mouse2", "mouse3", "mouse4", "mwheelup", - "mwheeldn", "mouse5", "mouse6", "mouse7", "mouse8" -}; - -static int osdcmd_bind(osdcmdptr_t parm) -{ - if (parm->numparms==1 && !Bstrcasecmp(parm->parms[0],"showkeys")) - { - for (auto & s : sctokeylut) - OSD_Printf("%s\n", s.key); - for (auto ConsoleButton : ConsoleButtons) - OSD_Printf("%s\n",ConsoleButton); - return OSDCMD_OK; - } - - if (parm->numparms==0) - { - int j=0; - - OSD_Printf("Current key bindings:\n"); - - for (int i=0; iparms[0], sctokeylut[i].key)) - break; - } - - // didn't find the key - if (i == ARRAY_SSIZE(sctokeylut)) - { - for (i=0; iparms[0],ConsoleButtons[i])) - break; - - if (i >= MAXMOUSEBUTTONS) - return OSDCMD_SHOWHELP; - - if (parm->numparms < 2) - { - if (CONTROL_KeyBinds[MAXBOUNDKEYS + i].cmdstr && CONTROL_KeyBinds[MAXBOUNDKEYS + i ].key) - OSD_Printf("%-9s %s\"%s\"\n", ConsoleButtons[i], CONTROL_KeyBinds[MAXBOUNDKEYS + i].repeat?"":"norepeat ", - CONTROL_KeyBinds[MAXBOUNDKEYS + i].cmdstr); - else OSD_Printf("%s is unbound\n", ConsoleButtons[i]); - return OSDCMD_OK; - } - - j = 1; - - repeat = 1; - if (!Bstrcasecmp(parm->parms[j],"norepeat")) - { - repeat = 0; - j++; - } - - Bstrcpy(tempbuf,parm->parms[j++]); - for (; jnumparms; j++) - { - Bstrcat(tempbuf," "); - Bstrcat(tempbuf,parm->parms[j++]); - } - - CONTROL_BindMouse(i, tempbuf, repeat, ConsoleButtons[i]); - - if (!OSD_ParsingScript()) - OSD_Printf("%s\n",parm->raw); - return OSDCMD_OK; - } - - if (parm->numparms < 2) - { - if (CONTROL_KeyIsBound(sctokeylut[i].sc)) - OSD_Printf("%-9s %s\"%s\"\n", sctokeylut[i].key, CONTROL_KeyBinds[sctokeylut[i].sc].repeat?"":"norepeat ", - CONTROL_KeyBinds[sctokeylut[i].sc].cmdstr); - else OSD_Printf("%s is unbound\n", sctokeylut[i].key); - - return OSDCMD_OK; - } - - j = 1; - - repeat = 1; - if (!Bstrcasecmp(parm->parms[j],"norepeat")) - { - repeat = 0; - j++; - } - - Bstrcpy(tempbuf,parm->parms[j++]); - for (; jnumparms; j++) - { - Bstrcat(tempbuf," "); - Bstrcat(tempbuf,parm->parms[j++]); - } - - CONTROL_BindKey(sctokeylut[i].sc, tempbuf, repeat, sctokeylut[i].key); - - char *cp = tempbuf; - - // Populate the keyboard config menu based on the bind. - // Take care of processing one-to-many bindings properly, too. - static char const s_gamefunc_[] = "gamefunc_"; - int constexpr strlen_gamefunc_ = ARRAY_SIZE(s_gamefunc_) - 1; - - while ((cp = Bstrstr(cp, s_gamefunc_))) - { - cp += strlen_gamefunc_; - - char *semi = Bstrchr(cp, ';'); - - if (semi) - *semi = 0; - - j = CONFIG_FunctionNameToNum(cp); - - if (semi) - cp = semi+1; - - if (j != -1) - { - KeyboardKeys[j][1] = KeyboardKeys[j][0]; - KeyboardKeys[j][0] = sctokeylut[i].sc; -// CONTROL_MapKey(j, sctokeylut[i].sc, KeyboardKeys[j][0]); - - if (j == gamefunc_Show_Console) - OSD_CaptureKey(sctokeylut[i].sc); - } - } - - if (!OSD_ParsingScript()) - OSD_Printf("%s\n",parm->raw); - - return OSDCMD_OK; -} - -static int osdcmd_unbindall(osdcmdptr_t UNUSED(parm)) -{ - UNREFERENCED_CONST_PARAMETER(parm); - - for (int i = 0; i < MAXBOUNDKEYS; ++i) - CONTROL_FreeKeyBind(i); - - for (int i = 0; i < MAXMOUSEBUTTONS; ++i) - CONTROL_FreeMouseBind(i); - - for (auto &KeyboardKey : KeyboardKeys) - KeyboardKey[0] = KeyboardKey[1] = 0xff; - - if (!OSD_ParsingScript()) - OSD_Printf("unbound all controls\n"); - - return OSDCMD_OK; -} - -static int osdcmd_unbind(osdcmdptr_t parm) -{ - if (parm->numparms != 1) - return OSDCMD_SHOWHELP; - - for (auto & ConsoleKey : sctokeylut) - { - if (ConsoleKey.key && !Bstrcasecmp(parm->parms[0], ConsoleKey.key)) - { - CONTROL_FreeKeyBind(ConsoleKey.sc); - OSD_Printf("unbound key %s\n", ConsoleKey.key); - return OSDCMD_OK; - } - } - - for (int i = 0; i < MAXMOUSEBUTTONS; i++) - { - if (!Bstrcasecmp(parm->parms[0], ConsoleButtons[i])) - { - CONTROL_FreeMouseBind(i); - OSD_Printf("unbound %s\n", ConsoleButtons[i]); - return OSDCMD_OK; - } - } - - return OSDCMD_SHOWHELP; -} - static int osdcmd_unbound(osdcmdptr_t parm) { if (parm->numparms != 1) diff --git a/source/mact/include/control.h b/source/mact/include/control.h index 51377881a..446c2e27b 100644 --- a/source/mact/include/control.h +++ b/source/mact/include/control.h @@ -207,20 +207,8 @@ void CONTROL_ClearGameControllerDigitalAxisNeg(int32_t axis); ////////// KEY/MOUSE BIND STUFF ////////// -#define MAXBOUNDKEYS MAXKEYBOARDSCAN -#define MAXMOUSEBUTTONS 10 - -typedef struct -{ - const char *key; - char *cmdstr; - char repeat; - char laststate; -} -consolekeybind_t; // Direct use DEPRECATED: -extern consolekeybind_t CONTROL_KeyBinds[MAXBOUNDKEYS+MAXMOUSEBUTTONS]; extern bool CONTROL_BindsEnabled; void CONTROL_ClearAllBinds(void); diff --git a/source/mact/include/keyboard.h b/source/mact/include/keyboard.h index b52a34da3..027f7080a 100644 --- a/source/mact/include/keyboard.h +++ b/source/mact/include/keyboard.h @@ -33,8 +33,6 @@ Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au) #include "baselayer.h" // for the keyboard stuff #include "scancodes.h" -typedef uint8_t kb_scancode; - // translation table for taking key names to scancodes and back again static struct { @@ -58,8 +56,6 @@ static struct { "Down", 0xd0 }, { "PgDn", 0xd1 }, { "Insert", 0xd2 }, { "Delete", 0xd3 }, }; -#define MAXKEYBOARDSCAN 256 - extern kb_scancode KB_LastScan; #define KB_GetLastScanCode() (KB_LastScan) diff --git a/source/mact/src/control.cpp b/source/mact/src/control.cpp index 8bc3ba3ca..8b0a136e8 100644 --- a/source/mact/src/control.cpp +++ b/source/mact/src/control.cpp @@ -62,7 +62,7 @@ static int32_t(*ExtGetTime)(void); static uint8_t CONTROL_DoubleClickSpeed; int32_t CONTROL_ButtonFlags[CONTROL_NUM_FLAGS]; -consolekeybind_t CONTROL_KeyBinds[MAXBOUNDKEYS + MAXMOUSEBUTTONS]; +consolekeybind_t CONTROL_KeyBinds[NUMKEYS + MAXMOUSEBUTTONS]; bool CONTROL_BindsEnabled = 0; bool CONTROL_SmoothMouse = 0; @@ -71,7 +71,7 @@ bool CONTROL_SmoothMouse = 0; void CONTROL_ClearAllBinds(void) { - for (int i=0; inumparms==1 && !Bstrcasecmp(parm->parms[0],"showkeys")) - { - for (int i=0; sctokeylut[i].key; i++) - OSD_Printf("%s\n",sctokeylut[i].key); - for (auto ConsoleButton : ConsoleButtons) - OSD_Printf("%s\n",ConsoleButton); - return OSDCMD_OK; - } - - if (parm->numparms==0) - { - int j=0; - - OSD_Printf("Current key bindings:\n"); - - for (int i=0; iparms[0], sctokeylut[i].key)) - break; - } - - // didn't find the key - if (i == ARRAY_SSIZE(sctokeylut)) - { - for (i=0; iparms[0],ConsoleButtons[i])) - break; - - if (i >= MAXMOUSEBUTTONS) - return OSDCMD_SHOWHELP; - - if (parm->numparms < 2) - { - if (CONTROL_KeyBinds[MAXBOUNDKEYS + i].cmdstr && CONTROL_KeyBinds[MAXBOUNDKEYS + i ].key) - OSD_Printf("%-9s %s\"%s\"\n", ConsoleButtons[i], CONTROL_KeyBinds[MAXBOUNDKEYS + i].repeat?"":"norepeat ", - CONTROL_KeyBinds[MAXBOUNDKEYS + i].cmdstr); - else OSD_Printf("%s is unbound\n", ConsoleButtons[i]); - return OSDCMD_OK; - } - - j = 1; - - repeat = 1; - if (!Bstrcasecmp(parm->parms[j],"norepeat")) - { - repeat = 0; - j++; - } - - Bstrcpy(tempbuf,parm->parms[j++]); - for (; jnumparms; j++) - { - Bstrcat(tempbuf," "); - Bstrcat(tempbuf,parm->parms[j++]); - } - - CONTROL_BindMouse(i, tempbuf, repeat, ConsoleButtons[i]); - - if (!OSD_ParsingScript()) - OSD_Printf("%s\n",parm->raw); - return OSDCMD_OK; - } - - if (parm->numparms < 2) - { - if (CONTROL_KeyIsBound(sctokeylut[i].sc)) - OSD_Printf("%-9s %s\"%s\"\n", sctokeylut[i].key, CONTROL_KeyBinds[sctokeylut[i].sc].repeat?"":"norepeat ", - CONTROL_KeyBinds[sctokeylut[i].sc].cmdstr); - else OSD_Printf("%s is unbound\n", sctokeylut[i].key); - - return OSDCMD_OK; - } - - j = 1; - - repeat = 1; - if (!Bstrcasecmp(parm->parms[j],"norepeat")) - { - repeat = 0; - j++; - } - - Bstrcpy(tempbuf,parm->parms[j++]); - for (; jnumparms; j++) - { - Bstrcat(tempbuf," "); - Bstrcat(tempbuf,parm->parms[j++]); - } - - CONTROL_BindKey(sctokeylut[i].sc, tempbuf, repeat, sctokeylut[i].key); - - char *cp = tempbuf; - - // Populate the keyboard config menu based on the bind. - // Take care of processing one-to-many bindings properly, too. - static char const s_gamefunc_[] = "gamefunc_"; - int constexpr strlen_gamefunc_ = ARRAY_SIZE(s_gamefunc_) - 1; - - while ((cp = Bstrstr(cp, s_gamefunc_))) - { - cp += strlen_gamefunc_; - - char *semi = Bstrchr(cp, ';'); - - if (semi) - *semi = 0; - - j = CONFIG_FunctionNameToNum(cp); - - if (semi) - cp = semi+1; - - if (j != -1) - { - KeyboardKeys[j][1] = KeyboardKeys[j][0]; - KeyboardKeys[j][0] = sctokeylut[i].sc; -// CONTROL_MapKey(j, sctokeylut[i].sc, KeyboardKeys[j][0]); - - if (j == gamefunc_Show_Console) - OSD_CaptureKey(sctokeylut[i].sc); - } - } - - if (!OSD_ParsingScript()) - OSD_Printf("%s\n",parm->raw); - - return OSDCMD_OK; -} - -static int osdcmd_unbindall(osdcmdptr_t UNUSED(parm)) -{ - UNREFERENCED_CONST_PARAMETER(parm); - - for (int i = 0; i < MAXBOUNDKEYS; ++i) - CONTROL_FreeKeyBind(i); - - for (int i = 0; i < MAXMOUSEBUTTONS; ++i) - CONTROL_FreeMouseBind(i); - - for (auto &KeyboardKey : KeyboardKeys) - KeyboardKey[0] = KeyboardKey[1] = 0xff; - - if (!OSD_ParsingScript()) - OSD_Printf("unbound all controls\n"); - - return OSDCMD_OK; -} - -static int osdcmd_unbind(osdcmdptr_t parm) -{ - if (parm->numparms != 1) - return OSDCMD_SHOWHELP; - - for (auto ConsoleKey : sctokeylut) - { - if (ConsoleKey.key && !Bstrcasecmp(parm->parms[0], ConsoleKey.key)) - { - CONTROL_FreeKeyBind(ConsoleKey.sc); - OSD_Printf("unbound key %s\n", ConsoleKey.key); - return OSDCMD_OK; - } - } - - for (int i = 0; i < MAXMOUSEBUTTONS; i++) - { - if (!Bstrcasecmp(parm->parms[0], ConsoleButtons[i])) - { - CONTROL_FreeMouseBind(i); - OSD_Printf("unbound %s\n", ConsoleButtons[i]); - return OSDCMD_OK; - } - } - - return OSDCMD_SHOWHELP; -} - static int osdcmd_quicksave(osdcmdptr_t UNUSED(parm)) { UNREFERENCED_CONST_PARAMETER(parm); diff --git a/source/sw/src/draw.cpp b/source/sw/src/draw.cpp index df9710917..fe855a806 100644 --- a/source/sw/src/draw.cpp +++ b/source/sw/src/draw.cpp @@ -1058,7 +1058,7 @@ ResizeView(PLAYERp pp) { extern SWBOOL ScrollMode2D; - KEY_PRESSED(KEYSC_ESC) = 0; + inputState.ClearKeyStatus(sc_Escape); dimensionmode = 3; ScrollMode2D = FALSE; SetRedrawScreen(pp); @@ -1676,7 +1676,7 @@ void ScreenCaptureKeys(void) // screen capture if (KEY_PRESSED(KEYSC_F12)) { - KEY_PRESSED(KEYSC_F12) = 0; + inputState.ClearKeyStatus(KEYSC_F12); PauseAction(); videoCaptureScreenTGA("swcpxxxx.tga", KEY_PRESSED(KEYSC_LSHIFT) | KEY_PRESSED(KEYSC_RSHIFT)); ResumeAction(); diff --git a/source/sw/src/game.cpp b/source/sw/src/game.cpp index c7e5c1661..9be9b693c 100644 --- a/source/sw/src/game.cpp +++ b/source/sw/src/game.cpp @@ -1560,8 +1560,8 @@ NewLevel(void) if (DemoModeMenuInit) { DemoModeMenuInit = FALSE; - KEY_PRESSED(KEYSC_ESC) = TRUE; - } + inputState.ClearKeyStatus(sc_Escape); + } } DemoPlayBack(); @@ -1620,10 +1620,7 @@ ResetKeys(void) { int i; - for (i = 0; i < MAXKEYBOARDSCAN; i++) - { - KEY_PRESSED(i) = 0; - } + inputState.ClearAllKeyStatus(); } SWBOOL @@ -1631,7 +1628,7 @@ KeyPressed(void) { int i; - for (i = 0; i < MAXKEYBOARDSCAN; i++) + for (i = 0; i < NUMKEYS; i++) { if (KEY_PRESSED(i)) return TRUE; @@ -2152,8 +2149,8 @@ MenuLevel(void) // go to ordering menu only if shareware if (FinishAnim) { - KEY_PRESSED(KEYSC_ESC) = 1; - ControlPanelType = ct_ordermenu; + inputState.ClearKeyStatus(sc_Escape); + ControlPanelType = ct_ordermenu; FinishAnim = 0; } } @@ -2214,7 +2211,7 @@ MenuLevel(void) // force the use of menus at all time if (!UsingMenus && !ConPanel) { - KEY_PRESSED(KEYSC_ESC) = TRUE; + inputState.SetKeyStatus(sc_Escape); MNU_CheckForMenusAnyKey(); } @@ -2232,8 +2229,8 @@ MenuLevel(void) BorderAdjust = TRUE; //LoadGameOutsideMoveLoop = FALSE; - KEY_PRESSED(KEYSC_ESC) = FALSE; - KB_ClearKeysDown(); + inputState.ClearKeyStatus(sc_Escape); + KB_ClearKeysDown(); //ExitMenus(); UsingMenus = FALSE; InMenuLevel = FALSE; @@ -2793,8 +2790,8 @@ StatScreen(PLAYERp mpp) while (KeyPressed()) ; } - KEY_PRESSED(KEYSC_SPACE) = 0; - KEY_PRESSED(KEYSC_ENTER) = 0; + inputState.ClearKeyStatus(KEYSC_SPACE); + inputState.ClearKeyStatus(KEYSC_ENTER); if (mus_enabled) { @@ -4398,7 +4395,7 @@ FunctionKeys(PLAYERp pp) { if (rts_delay > 16 && fn_key && CommEnabled && !adult_lockout && !Global_PLock) { - KEY_PRESSED(sc_F1 + fn_key - 1) = 0; + inputState.ClearKeyStatus(sc_F1 + fn_key - 1); rts_delay = 0; @@ -4423,7 +4420,8 @@ FunctionKeys(PLAYERp pp) { if (fn_key && CommEnabled) { - KEY_PRESSED(sc_F1 + fn_key - 1) = 0; + inputState.ClearKeyStatus(sc_Escape); + inputState.ClearKeyStatus(sc_F1 + fn_key - 1); if (CommEnabled) { @@ -4452,22 +4450,22 @@ FunctionKeys(PLAYERp pp) // F2 save menu if (KEY_PRESSED(KEYSC_F2)) { - KEY_PRESSED(KEYSC_F2) = 0; + inputState.ClearKeyStatus(KEYSC_F2); if (!TEST(pp->Flags, PF_DEAD)) { - KEY_PRESSED(KEYSC_ESC) = 1; - ControlPanelType = ct_savemenu; + inputState.SetKeyStatus(sc_Escape); + ControlPanelType = ct_savemenu; } } // F3 load menu if (KEY_PRESSED(KEYSC_F3)) { - KEY_PRESSED(KEYSC_F3) = 0; - if (!TEST(pp->Flags, PF_DEAD)) + inputState.ClearKeyStatus(KEYSC_F3); + if (!TEST(pp->Flags, PF_DEAD)) { - KEY_PRESSED(KEYSC_ESC) = 1; - ControlPanelType = ct_loadmenu; + inputState.SetKeyStatus(sc_Escape); + ControlPanelType = ct_loadmenu; } } @@ -4475,11 +4473,11 @@ FunctionKeys(PLAYERp pp) if (KEY_PRESSED(KEYSC_F6)) { extern SWBOOL QuickSaveMode; - KEY_PRESSED(KEYSC_F6) = 0; - if (!TEST(pp->Flags, PF_DEAD)) + inputState.ClearKeyStatus(KEYSC_F6); + if (!TEST(pp->Flags, PF_DEAD)) { - KEY_PRESSED(KEYSC_ESC) = 1; - ControlPanelType = ct_savemenu; + inputState.SetKeyStatus(sc_Escape); + ControlPanelType = ct_savemenu; QuickSaveMode = TRUE; } } @@ -4487,7 +4485,7 @@ FunctionKeys(PLAYERp pp) // F9 quick load if (KEY_PRESSED(KEYSC_F9)) { - KEY_PRESSED(KEYSC_F9) = 0; + inputState.ClearKeyStatus(KEYSC_F9); if (!TEST(pp->Flags, PF_DEAD)) { @@ -4498,8 +4496,8 @@ FunctionKeys(PLAYERp pp) else { KB_ClearKeysDown(); - KEY_PRESSED(KEYSC_ESC) = 1; - ControlPanelType = ct_quickloadmenu; + inputState.SetKeyStatus(sc_Escape); + ControlPanelType = ct_quickloadmenu; } } } @@ -4510,16 +4508,16 @@ FunctionKeys(PLAYERp pp) // F4 sound menu if (KEY_PRESSED(KEYSC_F4)) { - KEY_PRESSED(KEYSC_F4) = 0; - KEY_PRESSED(KEYSC_ESC) = 1; - ControlPanelType = ct_soundmenu; + inputState.ClearKeyStatus(KEYSC_F4); + inputState.SetKeyStatus(sc_Escape); + ControlPanelType = ct_soundmenu; } // F7 VIEW control if (KEY_PRESSED(KEYSC_F7)) { - KEY_PRESSED(KEYSC_F7) = 0; + inputState.ClearKeyStatus(KEYSC_F7); if (KEY_PRESSED(KEYSC_LSHIFT) || KEY_PRESSED(KEYSC_RSHIFT)) { @@ -4543,7 +4541,7 @@ FunctionKeys(PLAYERp pp) // F8 toggle messages if (KEY_PRESSED(KEYSC_F8)) { - KEY_PRESSED(KEYSC_F8) = 0; + inputState.ClearKeyStatus(KEYSC_F8); hud_messages = !hud_messages; @@ -4556,15 +4554,15 @@ FunctionKeys(PLAYERp pp) // F10 quit menu if (KEY_PRESSED(KEYSC_F10)) { - KEY_PRESSED(KEYSC_F10) = 0; - KEY_PRESSED(KEYSC_ESC) = 1; - ControlPanelType = ct_quitmenu; + inputState.ClearKeyStatus(KEYSC_F10); + inputState.SetKeyStatus(sc_Escape); + ControlPanelType = ct_quitmenu; } // F11 gamma correction if (KEY_PRESSED(KEYSC_F11) > 0) { - KEY_PRESSED(KEYSC_F11) = 0; + inputState.ClearKeyStatus(KEYSC_F11); // Do this entirely in the video backend. } @@ -4578,7 +4576,7 @@ void PauseKey(PLAYERp pp) if (KEY_PRESSED(sc_Pause) && !CommEnabled && !InputMode && !UsingMenus && !CheatInputMode && !ConPanel) { - KEY_PRESSED(sc_Pause) = 0; + inputState.ClearKeyStatus(sc_Pause); PauseKeySet ^= 1; @@ -4612,8 +4610,8 @@ void PauseKey(PLAYERp pp) } else { - KEY_PRESSED(KEYSC_ESC) = 1; - ControlPanelType = ct_quickloadmenu; + inputState.SetKeyStatus(sc_Escape); + ControlPanelType = ct_quickloadmenu; } } } @@ -4844,8 +4842,8 @@ void GetHelpInput(PLAYERp pp) { if (KEY_PRESSED(KEYSC_F1)) { - KEY_PRESSED(KEYSC_F1) = FALSE; - HelpPage = 0; + inputState.ClearKeyStatus(KEYSC_F11); + HelpPage = 0; HelpInputMode = TRUE; PanelUpdateMode = FALSE; InputMode = TRUE; @@ -4857,8 +4855,8 @@ void GetHelpInput(PLAYERp pp) { if (KEY_PRESSED(KEYSC_ESC)) { - KEY_PRESSED(KEYSC_ESC) = 0; - KB_ClearKeysDown(); + inputState.ClearKeyStatus(sc_Escape); + KB_ClearKeysDown(); PanelUpdateMode = TRUE; HelpInputMode = FALSE; InputMode = FALSE; @@ -4869,13 +4867,14 @@ void GetHelpInput(PLAYERp pp) if (KEY_PRESSED(KEYSC_SPACE) || KEY_PRESSED(KEYSC_ENTER) || KEY_PRESSED(KEYSC_PGDN) || KEY_PRESSED(KEYSC_DOWN) || KEY_PRESSED(KEYSC_RIGHT) || KEY_PRESSED(sc_kpad_3) || KEY_PRESSED(sc_kpad_2) || KEY_PRESSED(sc_kpad_6)) { - KEY_PRESSED(KEYSC_SPACE) = KEY_PRESSED(KEYSC_ENTER) = 0; - KEY_PRESSED(KEYSC_PGDN) = 0; - KEY_PRESSED(KEYSC_DOWN) = 0; - KEY_PRESSED(KEYSC_RIGHT) = 0; - KEY_PRESSED(sc_kpad_3) = 0; - KEY_PRESSED(sc_kpad_2) = 0; - KEY_PRESSED(sc_kpad_6) = 0; + inputState.ClearKeyStatus(KEYSC_SPACE); + inputState.ClearKeyStatus(KEYSC_ENTER); + inputState.ClearKeyStatus(KEYSC_PGDN); + inputState.ClearKeyStatus(KEYSC_DOWN); + inputState.ClearKeyStatus(KEYSC_RIGHT); + inputState.ClearKeyStatus(sc_kpad_3); + inputState.ClearKeyStatus(sc_kpad_2); + inputState.ClearKeyStatus(sc_kpad_6); HelpPage++; if (HelpPage >= (int)SIZ(HelpPagePic)) @@ -4888,12 +4887,12 @@ void GetHelpInput(PLAYERp pp) if (KEY_PRESSED(KEYSC_PGUP) || KEY_PRESSED(KEYSC_UP) || KEY_PRESSED(KEYSC_LEFT) || KEY_PRESSED(sc_kpad_9) || KEY_PRESSED(sc_kpad_8) || KEY_PRESSED(sc_kpad_4)) { - KEY_PRESSED(KEYSC_PGUP) = 0; - KEY_PRESSED(KEYSC_UP) = 0; - KEY_PRESSED(KEYSC_LEFT) = 0; - KEY_PRESSED(sc_kpad_8) = 0; - KEY_PRESSED(sc_kpad_9) = 0; - KEY_PRESSED(sc_kpad_4) = 0; + inputState.ClearKeyStatus(KEYSC_PGUP); + inputState.ClearKeyStatus(KEYSC_UP); + inputState.ClearKeyStatus(KEYSC_LEFT); + inputState.ClearKeyStatus(sc_kpad_8); + inputState.ClearKeyStatus(sc_kpad_9); + inputState.ClearKeyStatus(sc_kpad_4); HelpPage--; if (HelpPage < 0) @@ -5167,8 +5166,8 @@ getinput(SW_PACKET *loc) else if (KEY_PRESSED(sc_Pause)) { SET_LOC_KEY(loc->bits, SK_PAUSE, KEY_PRESSED(sc_Pause)); - KEY_PRESSED(sc_Pause) = 0; - } + inputState.ClearKeyStatus(sc_Pause); + } SET_LOC_KEY(loc->bits, SK_CENTER_VIEW, BUTTON(gamefunc_Center_View)); diff --git a/source/sw/src/menus.cpp b/source/sw/src/menus.cpp index c61173b62..7afda7b56 100644 --- a/source/sw/src/menus.cpp +++ b/source/sw/src/menus.cpp @@ -728,7 +728,7 @@ SWBOOL MNU_KeySetupCustom(UserCall call, MenuItem *item) if (KEY_PRESSED(KEYSC_ESC) || inpt.button1) { - KEY_PRESSED(KEYSC_ESC) = FALSE; + inputState.ClearKeyStatus(sc_Escape); cust_callback = NULL; CONTROL_ClearUserInput(&inpt); return TRUE; @@ -1576,8 +1576,8 @@ MNU_OrderCustom(UserCall call, MenuItem *item) // Support a few other keys too if (KEY_PRESSED(KEYSC_SPACE)||KEY_PRESSED(KEYSC_ENTER)) { - KEY_PRESSED(KEYSC_SPACE) = FALSE; - KEY_PRESSED(KEYSC_ENTER) = FALSE; + inputState.ClearKeyStatus(KEYSC_SPACE); + inputState.ClearKeyStatus(KEYSC_ENTER); tst_input.dir = dir_South; } } @@ -1622,7 +1622,7 @@ MNU_OrderCustom(UserCall call, MenuItem *item) } else { - KEY_PRESSED(KEYSC_ESC) = FALSE; + inputState.ClearKeyStatus(sc_Escape); cust_callback = NULL; DidOrderSound = FALSE; on_screen = 0; @@ -4395,8 +4395,8 @@ SetupMenu(void) MNU_SetupMenu(); // Clear the previous ESC key press - KEY_PRESSED(KEYSC_ESC) = FALSE; - UsingMenus = TRUE; + inputState.ClearKeyStatus(sc_Escape); + UsingMenus = TRUE; } } @@ -4565,8 +4565,8 @@ MNU_CheckForMenus(void) { if ((KEY_PRESSED(KEYSC_ESC)) && dimensionmode == 3 && !ConPanel) { - KEY_PRESSED(KEYSC_ESC) = 0; - KB_ClearKeysDown(); + inputState.ClearKeyStatus(sc_Escape); + KB_ClearKeysDown(); // setup sliders/buttons MNU_InitMenus(); MNU_DoMenu(ct_mainmenu, Player + myconnectindex); diff --git a/source/sw/src/player.cpp b/source/sw/src/player.cpp index 23a59fdee..bb412e841 100644 --- a/source/sw/src/player.cpp +++ b/source/sw/src/player.cpp @@ -4117,8 +4117,8 @@ SWBOOL PlayerFlyKey(PLAYERp pp) key = KEY_PRESSED(KEYSC_J); - if (key) - KEY_PRESSED(KEYSC_J) = 0; + if (key) + inputState.ClearKeyStatus(KEYSC_J); return key; }