From 570696fc092136ded54ecbf51ed11a05279f9956 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 4 Nov 2019 23:01:50 +0100 Subject: [PATCH] - added ZDoom's CCMD code. Not tested yet. --- source/CMakeLists.txt | 2 + source/blood/src/blood.cpp | 10 +- source/blood/src/controls.cpp | 138 ++-- source/blood/src/gamemenu.cpp | 8 +- source/blood/src/menu.cpp | 16 +- source/blood/src/messages.cpp | 4 +- source/common/console/c_bind.cpp | 19 +- source/common/console/c_buttons.cpp | 351 +++++++++ source/common/console/c_buttons.h | 182 +++++ source/common/console/c_commandline.h | 6 +- source/common/console/c_cvars.cpp | 10 +- source/common/console/c_dispatch.cpp | 1027 +++++++++++++++++++++++++ source/common/console/c_dispatch.h | 146 ++++ source/common/gamecontrol.cpp | 261 +------ source/common/gamecontrol.h | 6 - source/common/inputstate.h | 130 +--- source/duke3d/src/demo.cpp | 4 +- source/duke3d/src/game.cpp | 52 +- source/duke3d/src/gamedef.cpp | 6 +- source/duke3d/src/gameexec.cpp | 2 +- source/duke3d/src/menus.cpp | 11 +- source/duke3d/src/player.cpp | 102 +-- source/duke3d/src/screens.cpp | 2 +- source/mact/src/control.cpp | 2 - source/mact/src/input.cpp | 38 +- source/rr/src/demo.cpp | 4 +- source/rr/src/game.cpp | 52 +- source/rr/src/gamedef.cpp | 2 +- source/rr/src/menus.cpp | 11 +- source/rr/src/player.cpp | 214 +++--- source/rr/src/screens.cpp | 2 +- source/sw/src/demo.cpp | 26 +- source/sw/src/draw.cpp | 8 +- source/sw/src/game.cpp | 114 +-- source/sw/src/menus.cpp | 16 +- source/sw/src/player.cpp | 22 +- 36 files changed, 2165 insertions(+), 841 deletions(-) create mode 100644 source/common/console/c_buttons.cpp create mode 100644 source/common/console/c_buttons.h create mode 100644 source/common/console/c_dispatch.cpp create mode 100644 source/common/console/c_dispatch.h diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 81f1f976b..56659c01f 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -782,7 +782,9 @@ set (PCH_SOURCES common/console/c_cvars.cpp common/console/c_bind.cpp + common/console/c_buttons.cpp common/console/c_commandline.cpp + common/console/c_dispatch.cpp common/console/d_event.cpp common/utility/i_time.cpp diff --git a/source/blood/src/blood.cpp b/source/blood/src/blood.cpp index 7b026e638..b08d84ed6 100644 --- a/source/blood/src/blood.cpp +++ b/source/blood/src/blood.cpp @@ -809,17 +809,17 @@ void LocalKeys(void) bool alt = inputState.AltPressed(); bool ctrl = inputState.CtrlPressed(); bool shift = inputState.ShiftPressed(); - if (inputState.BUTTON(gamefunc_See_Chase_View) && !alt && !shift) + if (buttonMap.ButtonDown(gamefunc_See_Chase_View) && !alt && !shift) { - inputState.ClearButton(gamefunc_See_Chase_View); + buttonMap.ClearButton(gamefunc_See_Chase_View); if (gViewPos > VIEWPOS_0) gViewPos = VIEWPOS_0; else gViewPos = VIEWPOS_1; } - if (inputState.BUTTON(gamefunc_See_Coop_View)) + if (buttonMap.ButtonDown(gamefunc_See_Coop_View)) { - inputState.ClearButton(gamefunc_See_Coop_View); + buttonMap.ClearButton(gamefunc_See_Coop_View); if (gGameOptions.nGameType == 1) { gViewIndex = connectpoint2[gViewIndex]; @@ -873,7 +873,7 @@ void LocalKeys(void) } inputState.keyFlushScans(); inputState.ClearKeyStatus(key); - inputState.ClearButton(gamefunc_See_Chase_View); + buttonMap.ClearButton(gamefunc_See_Chase_View); return; } switch (key) diff --git a/source/blood/src/controls.cpp b/source/blood/src/controls.cpp index c4900c5cf..3f3b1e380 100644 --- a/source/blood/src/controls.cpp +++ b/source/blood/src/controls.cpp @@ -124,13 +124,13 @@ void ctrlGetInput(void) if (in_aimmode) g_MyAimMode = 0; - if (inputState.BUTTON(gamefunc_Mouse_Aiming)) + if (buttonMap.ButtonDown(gamefunc_Mouse_Aiming)) { if (in_aimmode) g_MyAimMode = 1; else { - inputState.ClearButton(gamefunc_Mouse_Aiming); + buttonMap.ClearButton(gamefunc_Mouse_Aiming); g_MyAimMode = !g_MyAimMode; if (g_MyAimMode) { @@ -175,16 +175,16 @@ void ctrlGetInput(void) gInput.keyFlags.quit = 1; if (gGameStarted && gInputMode != kInputMessage && gInputMode != kInputMenu - && inputState.BUTTON(gamefunc_Send_Message)) + && buttonMap.ButtonDown(gamefunc_Send_Message)) { - inputState.ClearButton(gamefunc_Send_Message); + buttonMap.ClearButton(gamefunc_Send_Message); inputState.keyFlushScans(); gInputMode = kInputMessage; } - if (inputState.BUTTON(gamefunc_AutoRun)) + if (buttonMap.ButtonDown(gamefunc_AutoRun)) { - inputState.ClearButton(gamefunc_AutoRun); + buttonMap.ClearButton(gamefunc_AutoRun); gAutoRun = !gAutoRun; if (gAutoRun) viewSetMessage("Auto run ON"); @@ -192,24 +192,24 @@ void ctrlGetInput(void) viewSetMessage("Auto run OFF"); } - if (inputState.BUTTON(gamefunc_Map_Toggle)) + if (buttonMap.ButtonDown(gamefunc_Map_Toggle)) { - inputState.ClearButton(gamefunc_Map_Toggle); + buttonMap.ClearButton(gamefunc_Map_Toggle); viewToggle(gViewMode); } - if (inputState.BUTTON(gamefunc_Map_Follow_Mode)) + if (buttonMap.ButtonDown(gamefunc_Map_Follow_Mode)) { - inputState.ClearButton(gamefunc_Map_Follow_Mode); + buttonMap.ClearButton(gamefunc_Map_Follow_Mode); gFollowMap = !gFollowMap; gViewMap.FollowMode(gFollowMap); } - if (inputState.BUTTON(gamefunc_Shrink_Screen)) + if (buttonMap.ButtonDown(gamefunc_Shrink_Screen)) { if (gViewMode == 3) { - inputState.ClearButton(gamefunc_Shrink_Screen); + buttonMap.ClearButton(gamefunc_Shrink_Screen); G_ChangeHudLayout(-1); } if (gViewMode == 2 || gViewMode == 4) @@ -219,11 +219,11 @@ void ctrlGetInput(void) } } - if (inputState.BUTTON(gamefunc_Enlarge_Screen)) + if (buttonMap.ButtonDown(gamefunc_Enlarge_Screen)) { if (gViewMode == 3) { - inputState.ClearButton(gamefunc_Enlarge_Screen); + buttonMap.ClearButton(gamefunc_Enlarge_Screen); G_ChangeHudLayout(1); } if (gViewMode == 2 || gViewMode == 4) @@ -233,165 +233,165 @@ void ctrlGetInput(void) } } - if (inputState.BUTTON(gamefunc_Toggle_Crosshair)) + if (buttonMap.ButtonDown(gamefunc_Toggle_Crosshair)) { - inputState.ClearButton(gamefunc_Toggle_Crosshair); + buttonMap.ClearButton(gamefunc_Toggle_Crosshair); cl_crosshair = !cl_crosshair; } - if (inputState.BUTTON(gamefunc_Next_Weapon)) + if (buttonMap.ButtonDown(gamefunc_Next_Weapon)) { - inputState.ClearButton(gamefunc_Next_Weapon); + buttonMap.ClearButton(gamefunc_Next_Weapon); gInput.keyFlags.nextWeapon = 1; } - if (inputState.BUTTON(gamefunc_Previous_Weapon)) + if (buttonMap.ButtonDown(gamefunc_Previous_Weapon)) { - inputState.ClearButton(gamefunc_Previous_Weapon); + buttonMap.ClearButton(gamefunc_Previous_Weapon); gInput.keyFlags.prevWeapon = 1; } - if (inputState.BUTTON(gamefunc_Show_Opponents_Weapon)) + if (buttonMap.ButtonDown(gamefunc_Show_Opponents_Weapon)) { - inputState.ClearButton(gamefunc_Show_Opponents_Weapon); + buttonMap.ClearButton(gamefunc_Show_Opponents_Weapon); cl_showweapon = (cl_showweapon + 1) & 3; } - if (inputState.BUTTON(gamefunc_Jump)) + if (buttonMap.ButtonDown(gamefunc_Jump)) gInput.buttonFlags.jump = 1; - if (inputState.BUTTON(gamefunc_Crouch)) + if (buttonMap.ButtonDown(gamefunc_Crouch)) gInput.buttonFlags.crouch = 1; - if (inputState.BUTTON(gamefunc_Fire)) + if (buttonMap.ButtonDown(gamefunc_Fire)) gInput.buttonFlags.shoot = 1; - if (inputState.BUTTON(gamefunc_Alt_Fire)) + if (buttonMap.ButtonDown(gamefunc_Alt_Fire)) gInput.buttonFlags.shoot2 = 1; - if (inputState.BUTTON(gamefunc_Open)) + if (buttonMap.ButtonDown(gamefunc_Open)) { - inputState.ClearButton(gamefunc_Open); + buttonMap.ClearButton(gamefunc_Open); gInput.keyFlags.action = 1; } - gInput.buttonFlags.lookUp = inputState.BUTTON(gamefunc_Look_Up); - gInput.buttonFlags.lookDown = inputState.BUTTON(gamefunc_Look_Down); + gInput.buttonFlags.lookUp = buttonMap.ButtonDown(gamefunc_Look_Up); + gInput.buttonFlags.lookDown = buttonMap.ButtonDown(gamefunc_Look_Down); if (gInput.buttonFlags.lookUp || gInput.buttonFlags.lookDown) gInput.keyFlags.lookCenter = 1; else { - gInput.buttonFlags.lookUp = inputState.BUTTON(gamefunc_Aim_Up); - gInput.buttonFlags.lookDown = inputState.BUTTON(gamefunc_Aim_Down); + gInput.buttonFlags.lookUp = buttonMap.ButtonDown(gamefunc_Aim_Up); + gInput.buttonFlags.lookDown = buttonMap.ButtonDown(gamefunc_Aim_Down); } - if (inputState.BUTTON(gamefunc_Aim_Center)) + if (buttonMap.ButtonDown(gamefunc_Aim_Center)) { - inputState.ClearButton(gamefunc_Aim_Center); + buttonMap.ClearButton(gamefunc_Aim_Center); gInput.keyFlags.lookCenter = 1; } - gInput.keyFlags.spin180 = inputState.BUTTON(gamefunc_Turn_Around); + gInput.keyFlags.spin180 = buttonMap.ButtonDown(gamefunc_Turn_Around); - if (inputState.BUTTON(gamefunc_Inventory_Left)) + if (buttonMap.ButtonDown(gamefunc_Inventory_Left)) { - inputState.ClearButton(gamefunc_Inventory_Left); + buttonMap.ClearButton(gamefunc_Inventory_Left); gInput.keyFlags.prevItem = 1; } - if (inputState.BUTTON(gamefunc_Inventory_Right)) + if (buttonMap.ButtonDown(gamefunc_Inventory_Right)) { - inputState.ClearButton(gamefunc_Inventory_Right); + buttonMap.ClearButton(gamefunc_Inventory_Right); gInput.keyFlags.nextItem = 1; } - if (inputState.BUTTON(gamefunc_Inventory_Use)) + if (buttonMap.ButtonDown(gamefunc_Inventory_Use)) { - inputState.ClearButton(gamefunc_Inventory_Use); + buttonMap.ClearButton(gamefunc_Inventory_Use); gInput.keyFlags.useItem = 1; } - if (inputState.BUTTON(gamefunc_BeastVision)) + if (buttonMap.ButtonDown(gamefunc_BeastVision)) { - inputState.ClearButton(gamefunc_BeastVision); + buttonMap.ClearButton(gamefunc_BeastVision); gInput.useFlags.useBeastVision = 1; } - if (inputState.BUTTON(gamefunc_CrystalBall)) + if (buttonMap.ButtonDown(gamefunc_CrystalBall)) { - inputState.ClearButton(gamefunc_CrystalBall); + buttonMap.ClearButton(gamefunc_CrystalBall); gInput.useFlags.useCrystalBall = 1; } - if (inputState.BUTTON(gamefunc_JumpBoots)) + if (buttonMap.ButtonDown(gamefunc_JumpBoots)) { - inputState.ClearButton(gamefunc_JumpBoots); + buttonMap.ClearButton(gamefunc_JumpBoots); gInput.useFlags.useJumpBoots = 1; } - if (inputState.BUTTON(gamefunc_MedKit)) + if (buttonMap.ButtonDown(gamefunc_MedKit)) { - inputState.ClearButton(gamefunc_MedKit); + buttonMap.ClearButton(gamefunc_MedKit); gInput.useFlags.useMedKit = 1; } for (int i = 0; i < 10; i++) { - if (inputState.BUTTON(gamefunc_Weapon_1 + i)) + if (buttonMap.ButtonDown(gamefunc_Weapon_1 + i)) { - inputState.ClearButton(gamefunc_Weapon_1 + i); + buttonMap.ClearButton(gamefunc_Weapon_1 + i); gInput.newWeapon = 1 + i; } } - if (inputState.BUTTON(gamefunc_ProximityBombs)) + if (buttonMap.ButtonDown(gamefunc_ProximityBombs)) { - inputState.ClearButton(gamefunc_ProximityBombs); + buttonMap.ClearButton(gamefunc_ProximityBombs); gInput.newWeapon = 11; } - if (inputState.BUTTON(gamefunc_RemoteBombs)) + if (buttonMap.ButtonDown(gamefunc_RemoteBombs)) { - inputState.ClearButton(gamefunc_RemoteBombs); + buttonMap.ClearButton(gamefunc_RemoteBombs); gInput.newWeapon = 12; } - if (inputState.BUTTON(gamefunc_Holster_Weapon)) + if (buttonMap.ButtonDown(gamefunc_Holster_Weapon)) { - inputState.ClearButton(gamefunc_Holster_Weapon); + buttonMap.ClearButton(gamefunc_Holster_Weapon); gInput.keyFlags.holsterWeapon = 1; } - char run = G_CheckAutorun(inputState.BUTTON(gamefunc_Run)); - char run2 = false; // What??? inputState.BUTTON(gamefunc_Run); + char run = G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run)); + char run2 = false; // What??? buttonMap.ButtonDown(gamefunc_Run); gInput.syncFlags.run = run; - if (inputState.BUTTON(gamefunc_Move_Forward)) + if (buttonMap.ButtonDown(gamefunc_Move_Forward)) forward += (1+run)<<10; - if (inputState.BUTTON(gamefunc_Move_Backward)) + if (buttonMap.ButtonDown(gamefunc_Move_Backward)) forward -= (1+run)<<10; char turnLeft = 0, turnRight = 0; - if (inputState.BUTTON(gamefunc_Strafe)) + if (buttonMap.ButtonDown(gamefunc_Strafe)) { - if (inputState.BUTTON(gamefunc_Turn_Left)) + if (buttonMap.ButtonDown(gamefunc_Turn_Left)) strafe += (1 + run) << 10; - if (inputState.BUTTON(gamefunc_Turn_Right)) + if (buttonMap.ButtonDown(gamefunc_Turn_Right)) strafe -= (1 + run) << 10; } else { - if (inputState.BUTTON(gamefunc_Strafe_Left)) + if (buttonMap.ButtonDown(gamefunc_Strafe_Left)) strafe += (1 + run) << 10; - if (inputState.BUTTON(gamefunc_Strafe_Right)) + if (buttonMap.ButtonDown(gamefunc_Strafe_Right)) strafe -= (1 + run) << 10; - if (inputState.BUTTON(gamefunc_Turn_Left)) + if (buttonMap.ButtonDown(gamefunc_Turn_Left)) turnLeft = 1; - if (inputState.BUTTON(gamefunc_Turn_Right)) + if (buttonMap.ButtonDown(gamefunc_Turn_Right)) turnRight = 1; } @@ -408,7 +408,7 @@ void ctrlGetInput(void) if ((run2 || run) && iTurnCount > 24) turn <<= 1; - if (inputState.BUTTON(gamefunc_Strafe)) + if (buttonMap.ButtonDown(gamefunc_Strafe)) strafe = ClipRange(strafe - info.mousex, -2048, 2048); else turn = fix16_clamp(turn + fix16_div(fix16_from_int(info.mousex), F16(32)), F16(-1024)>>2, F16(1024)>>2); diff --git a/source/blood/src/gamemenu.cpp b/source/blood/src/gamemenu.cpp index b7f01a033..ab145a120 100644 --- a/source/blood/src/gamemenu.cpp +++ b/source/blood/src/gamemenu.cpp @@ -1128,9 +1128,9 @@ void CGameMenuItemKeyList::Draw(void) bool bClick = false; for (int i = 0; i < nRows; i++, y += height, k++) { - auto keys = Bindings.GetKeysForCommand(CONFIG_FunctionNumToName(k)); + auto keys = Bindings.GetKeysForCommand(buttonMap.GetButtonName(k)); FString text = C_NameKeys(keys.Data(), std::min(keys.Size(), 2u)); - sprintf(buffer, "%s", CONFIG_FunctionNumToName(k)); + sprintf(buffer, "%s", buttonMap.GetButtonName(k)); if (k == nFocus) { @@ -1192,7 +1192,7 @@ bool CGameMenuItemKeyList::Event(CGameMenuEvent &event) if (inputState.keyBufferWaiting()) inputState.keyGetChar(); - Bindings.SetBind(inputState.GetLastScanCode(), CONFIG_FunctionNumToName(nFocus)); + Bindings.SetBind(inputState.GetLastScanCode(), buttonMap.GetButtonName(nFocus)); inputState.keyFlushChars(); inputState.keyFlushScans(); inputState.ClearKeysDown(); @@ -1231,7 +1231,7 @@ bool CGameMenuItemKeyList::Event(CGameMenuEvent &event) return false; case kMenuEventBackSpace: case kMenuEventDelete: - Bindings.UnbindACommand(CONFIG_FunctionNumToName(nFocus)); + Bindings.UnbindACommand(buttonMap.GetButtonName(nFocus)); return false; case kMenuEventScrollUp: if (nFocus-nTopDelta > 0) diff --git a/source/blood/src/menu.cpp b/source/blood/src/menu.cpp index dcd0e366d..bc57a8afb 100644 --- a/source/blood/src/menu.cpp +++ b/source/blood/src/menu.cpp @@ -1314,7 +1314,7 @@ void SetupMenus(void) int k = 1; for (int i = 0; i < NUMGAMEFUNCTIONS; ++i) { - MenuGameFuncs[i] = CONFIG_FunctionNumToName(i); + MenuGameFuncs[i] = buttonMap.GetButtonName(i); MenuGameFuncs[i].Substitute('_', ' '); if (MenuGameFuncs[i][0] != '\0') @@ -1987,19 +1987,7 @@ void SetMouseButton(CGameMenuItemZCycle *pItem) void SetupMouseButtonMenu(CGameMenuItemChain *pItem) { UNREFERENCED_PARAMETER(pItem); - for (int i = 0; i < MENUMOUSEFUNCTIONS; i++) - { - auto pItem = pItemOptionsControlMouseButton[i]; - pItem->m_nFocus = 0; - for (int j = 0; j < NUMGAMEFUNCTIONS+1; j++) - { - if (MouseFunctions[MenuMouseDataIndex[i][0]][MenuMouseDataIndex[i][1]] == nGamefuncsValues[j]) - { - pItem->m_nFocus = j; - break; - } - } - } + // This functionality no longer exists as a separate item. } void SetupNetworkMenu(void) diff --git a/source/blood/src/messages.cpp b/source/blood/src/messages.cpp index bc3961f8c..9c2f633fe 100644 --- a/source/blood/src/messages.cpp +++ b/source/blood/src/messages.cpp @@ -50,7 +50,7 @@ CCheatMgr gCheatMgr; void sub_5A928(void) { for (int i = 0; i < NUMGAMEFUNCTIONS-1; i++) - inputState.ClearButton(i); + buttonMap.ClearButton(i); } void sub_5A944(int key) @@ -608,7 +608,7 @@ void CPlayerMsg::ProcessKeys(void) case sc_F8: case sc_F9: case sc_F10: - inputState.ClearButton(gamefunc_See_Chase_View); + buttonMap.ClearButton(gamefunc_See_Chase_View); Set(*CombatMacros[key-sc_F1]); Send(); inputState.ClearKeyStatus(key); diff --git a/source/common/console/c_bind.cpp b/source/common/console/c_bind.cpp index 55efe619a..47abb71af 100644 --- a/source/common/console/c_bind.cpp +++ b/source/common/console/c_bind.cpp @@ -38,6 +38,7 @@ #include "keydef.h" #include "c_commandline.h" #include "c_bind.h" +#include "c_dispatch.h" //#include "g_level.h" //#include "hu_stuff.h" #include "configfile.h" @@ -803,21 +804,3 @@ bool C_DoKey (event_t *ev, FKeyBindings *binds, FKeyBindings *doublebinds) } return false; } - - -#include "osd.h" -void AddCommandString(const char* copy, int keynum) -{ - // For the time being this still needs a bit of glue code to work as expected. - if (*copy == '+') - { - auto num = CONFIG_FunctionNameToNum(copy + 1); - if (num >= 0) inputState.UpdateButton(num, true); - } - else if (*copy == '-') - { - auto num = CONFIG_FunctionNameToNum(copy + 1); - if (num >= 0) inputState.UpdateButton(num, false); - } - else OSD_Dispatch(copy); -} diff --git a/source/common/console/c_buttons.cpp b/source/common/console/c_buttons.cpp new file mode 100644 index 000000000..0badf8309 --- /dev/null +++ b/source/common/console/c_buttons.cpp @@ -0,0 +1,351 @@ +/* +** c_dispatch.cpp +** Functions for executing console commands and aliases +** +**--------------------------------------------------------------------------- +** Copyright 1998-2007 Randy Heit +** Copyright 2019 Christoph Oelckers +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +*/ + +#include "c_buttons.h" +#include "printf.h" +#include "cmdlib.h" +#include "c_dispatch.h" + +ButtonMap buttonMap; + +struct ButtonDesc +{ + int index; + const char *name; +}; + +static const ButtonDesc gamefuncs[] = { + { gamefunc_Move_Forward, "Move_Forward"}, + { gamefunc_Move_Backward, "Move_Backward"}, + { gamefunc_Turn_Left, "Turn_Left"}, + { gamefunc_Turn_Right, "Turn_Right"}, + { gamefunc_Strafe, "Strafe"}, + { gamefunc_Fire, "Fire"}, + { gamefunc_Open, "Open"}, + { gamefunc_Run, "Run"}, + { gamefunc_Alt_Fire, "Alt_Fire"}, + { gamefunc_Jump, "Jump"}, + { gamefunc_Crouch, "Crouch"}, + { gamefunc_Look_Up, "Look_Up"}, + { gamefunc_Look_Down, "Look_Down"}, + { gamefunc_Look_Left, "Look_Left"}, + { gamefunc_Look_Right, "Look_Right"}, + { gamefunc_Strafe_Left, "Strafe_Left"}, + { gamefunc_Strafe_Right, "Strafe_Right"}, + { gamefunc_Aim_Up, "Aim_Up"}, + { gamefunc_Aim_Down, "Aim_Down"}, + { gamefunc_Weapon_1, "Weapon_1"}, + { gamefunc_Weapon_2, "Weapon_2"}, + { gamefunc_Weapon_3, "Weapon_3"}, + { gamefunc_Weapon_4, "Weapon_4"}, + { gamefunc_Weapon_5, "Weapon_5"}, + { gamefunc_Weapon_6, "Weapon_6"}, + { gamefunc_Weapon_7, "Weapon_7"}, + { gamefunc_Weapon_8, "Weapon_8"}, + { gamefunc_Weapon_9, "Weapon_9"}, + { gamefunc_Weapon_10, "Weapon_10"}, + { gamefunc_Inventory, "Inventory"}, + { gamefunc_Inventory_Left, "Inventory_Left"}, + { gamefunc_Inventory_Right, "Inventory_Right"}, + { gamefunc_Holo_Duke, "Holo_Duke"}, + { gamefunc_Jetpack, "Jetpack"}, + { gamefunc_NightVision, "NightVision"}, + { gamefunc_MedKit, "MedKit"}, + { gamefunc_TurnAround, "TurnAround"}, + { gamefunc_SendMessage, "SendMessage"}, + { gamefunc_Map, "Map"}, + { gamefunc_Shrink_Screen, "Shrink_Screen"}, + { gamefunc_Enlarge_Screen, "Enlarge_Screen"}, + { gamefunc_Center_View, "Center_View"}, + { gamefunc_Holster_Weapon, "Holster_Weapon"}, + { gamefunc_Show_Opponents_Weapon, "Show_Opponents_Weapon"}, + { gamefunc_Map_Follow_Mode, "Map_Follow_Mode"}, + { gamefunc_See_Coop_View, "See_Coop_View"}, + { gamefunc_Mouse_Aiming, "Mouse_Aiming"}, + { gamefunc_Toggle_Crosshair, "Toggle_Crosshair"}, + { gamefunc_Steroids, "Steroids"}, + { gamefunc_Quick_Kick, "Quick_Kick"}, + { gamefunc_Next_Weapon, "Next_Weapon"}, + { gamefunc_Previous_Weapon, "Previous_Weapon"}, + { gamefunc_Show_Console, "Show_Console"}, + { gamefunc_Show_DukeMatch_Scores, "Show_DukeMatch_Scores"}, + { gamefunc_Dpad_Select, "Dpad_Select"}, + { gamefunc_Dpad_Aiming, "Dpad_Aiming"}, + { gamefunc_AutoRun, "AutoRun"}, + { gamefunc_Last_Weapon, "Last_Used_Weapon"}, + { gamefunc_Quick_Save, "Quick_Save"}, + { gamefunc_Quick_Load, "Quick_Load"}, + { gamefunc_Alt_Weapon, "Alt_Weapon"}, + { gamefunc_Third_Person_View, "Third_Person_View"}, + { gamefunc_Toggle_Crouch, "Toggle_Crouch"}, + { gamefunc_See_Chase_View, "See_Chase_View"}, // the following were added by Blood + { gamefunc_Turn_Around, "Turn_Around"}, + { gamefunc_Aim_Center, "Aim_Center"}, + { gamefunc_Tilt_Left, "Tilt_Left"}, + { gamefunc_Tilt_Right, "Tilt_Right"}, + { gamefunc_Send_Message, "Send_Message"}, + { gamefunc_BeastVision, "BeastVision"}, + { gamefunc_CrystalBall, "CrystalBall"}, + { gamefunc_JumpBoots, "JumpBoots"}, + { gamefunc_ProximityBombs, "ProximityBombs"}, + { gamefunc_RemoteBombs, "RemoteBombs"}, + { gamefunc_Smoke_Bomb, "Smoke_Bomb" }, + { gamefunc_Gas_Bomb, "Gas_Bomb" }, + { gamefunc_Flash_Bomb, "Flash_Bomb" }, + { gamefunc_Caltrops, "Calitrops" }, + +}; + + +//============================================================================= +// +// +// +//============================================================================= + +ButtonMap::ButtonMap() +{ + for(auto &gf : gamefuncs) + { + NameToNum.Insert(gf.name, gf.index); + NumToAlias[gf.index] = NumToName[gf.index] = gf.name; + } +} + +//============================================================================= +// +// +// +//============================================================================= + +int ButtonMap::ListActionCommands (const char *pattern) +{ + char matcher[32]; + int count = 0; + + for (int i = 0; i < NumButtons(); i++) + { + if (NumToAlias[i].IsEmpty()) continue; // do not list buttons that were removed from the alias list + + if (pattern == NULL || CheckWildcards (pattern, + (snprintf (matcher, countof(matcher), "+%s", NumToName[i].GetChars()), matcher))) + { + Printf ("+%s\n", NumToName[i]); + count++; + } + if (pattern == NULL || CheckWildcards (pattern, + (snprintf (matcher, countof(matcher), "-%s", NumToName[i].GetChars()), matcher))) + { + Printf ("-%s\n", NumToName[i]); + count++; + } + } + return count; +} + + +//============================================================================= +// +// +// +//============================================================================= + +int ButtonMap::FindButtonIndex (const char *key) const +{ + if (!key) return -1; + + FName name(key, true); + if (name == NAME_None) return -1; + + auto res = NameToNum.CheckKey(name); + if (!res) return -1; + + return *res; +} + + +//============================================================================= +// +// +// +//============================================================================= + +void ButtonMap::ResetButtonTriggers () +{ + for (auto &button : Buttons) + { + button.ResetTriggers (); + } +} + +//============================================================================= +// +// +// +//============================================================================= + +void ButtonMap::ResetButtonStates () +{ + for (auto &button : Buttons) + { + button.ReleaseKey (0); + button.ResetTriggers (); + } +} + +//============================================================================= +// +// +// +//============================================================================= + +void ButtonMap::SetButtonAlias(int num, const char *text) +{ + if ((unsigned)num >= (unsigned)NUMGAMEFUNCTIONS) + return; + NumToAlias[num] = text; + NameToNum.Insert(text, num); +} + +//============================================================================= +// +// +// +//============================================================================= + +void ButtonMap::ClearButtonAlias(int num) +{ + if ((unsigned)num >= (unsigned)NUMGAMEFUNCTIONS) + return; + NumToAlias[num] = ""; +} + + +//============================================================================= +// +// +// +//============================================================================= + +bool FButtonStatus::PressKey (int keynum) +{ + int i, open; + + keynum &= KEY_DBLCLICKED-1; + + if (keynum == 0) + { // Issued from console instead of a key, so force on + Keys[0] = 0xffff; + for (i = MAX_KEYS-1; i > 0; --i) + { + Keys[i] = 0; + } + } + else + { + for (i = MAX_KEYS-1, open = -1; i >= 0; --i) + { + if (Keys[i] == 0) + { + open = i; + } + else if (Keys[i] == keynum) + { // Key is already down; do nothing + return false; + } + } + if (open < 0) + { // No free key slots, so do nothing + Printf ("More than %u keys pressed for a single action!\n", MAX_KEYS); + return false; + } + Keys[open] = keynum; + } + uint8_t wasdown = bDown; + bDown = bWentDown = true; + // Returns true if this key caused the button to go down. + return !wasdown; +} + +//============================================================================= +// +// +// +//============================================================================= + +bool FButtonStatus::ReleaseKey (int keynum) +{ + int i, numdown, match; + uint8_t wasdown = bDown; + + keynum &= KEY_DBLCLICKED-1; + + if (keynum == 0) + { // Issued from console instead of a key, so force off + for (i = MAX_KEYS-1; i >= 0; --i) + { + Keys[i] = 0; + } + bWentUp = true; + bDown = false; + } + else + { + for (i = MAX_KEYS-1, numdown = 0, match = -1; i >= 0; --i) + { + if (Keys[i] != 0) + { + ++numdown; + if (Keys[i] == keynum) + { + match = i; + } + } + } + if (match < 0) + { // Key was not down; do nothing + return false; + } + Keys[match] = 0; + bWentUp = true; + if (--numdown == 0) + { + bDown = false; + } + } + // Returns true if releasing this key caused the button to go up. + return wasdown && !bDown; +} + diff --git a/source/common/console/c_buttons.h b/source/common/console/c_buttons.h new file mode 100644 index 000000000..788a50356 --- /dev/null +++ b/source/common/console/c_buttons.h @@ -0,0 +1,182 @@ +#pragma once + +#include +#include "tarray.h" +#include "zstring.h" +#include "name.h" + +// Order is that of EDuke32 by necessity because it exposes the key binds to scripting by index instead of by name. +enum GameFunction_t +{ + gamefunc_Move_Forward, + gamefunc_Move_Backward, + gamefunc_Turn_Left, + gamefunc_Turn_Right, + gamefunc_Strafe, + gamefunc_Fire, + gamefunc_Open, + gamefunc_Run, + gamefunc_Alt_Fire, + gamefunc_Jump, + gamefunc_Crouch, + gamefunc_Look_Up, + gamefunc_Look_Down, + gamefunc_Look_Left, + gamefunc_Look_Right, + gamefunc_Strafe_Left, + gamefunc_Strafe_Right, + gamefunc_Aim_Up, + gamefunc_Aim_Down, + gamefunc_Weapon_1, + gamefunc_Weapon_2, + gamefunc_Weapon_3, + gamefunc_Weapon_4, + gamefunc_Weapon_5, + gamefunc_Weapon_6, + gamefunc_Weapon_7, + gamefunc_Weapon_8, + gamefunc_Weapon_9, + gamefunc_Weapon_10, + gamefunc_Inventory, + gamefunc_Inventory_Use = gamefunc_Inventory, + gamefunc_Inventory_Left, + gamefunc_Inventory_Right, + gamefunc_Holo_Duke, + gamefunc_Jetpack, + gamefunc_NightVision, + gamefunc_Night_Vision = gamefunc_NightVision, + gamefunc_MedKit, + gamefunc_Med_Kit = gamefunc_MedKit, + gamefunc_TurnAround, + gamefunc_SendMessage, + gamefunc_Map, + gamefunc_Map_Toggle = gamefunc_Map, + gamefunc_Shrink_Screen, + gamefunc_Enlarge_Screen, + gamefunc_Center_View, + gamefunc_Holster_Weapon, + gamefunc_Show_Opponents_Weapon, + gamefunc_Map_Follow_Mode, + gamefunc_See_Coop_View, + gamefunc_See_Co_Op_View = gamefunc_See_Coop_View, + gamefunc_Mouse_Aiming, + gamefunc_Toggle_Crosshair, + gamefunc_Steroids, + gamefunc_Quick_Kick, + gamefunc_Next_Weapon, + gamefunc_Previous_Weapon, + gamefunc_Show_Console, + gamefunc_Show_DukeMatch_Scores, + gamefunc_Dpad_Select, + gamefunc_Dpad_Aiming, + gamefunc_AutoRun, + gamefunc_Last_Weapon, + gamefunc_Quick_Save, + gamefunc_Quick_Load, + gamefunc_Alt_Weapon, + gamefunc_Third_Person_View, + gamefunc_Toggle_Crouch, + gamefunc_See_Chase_View, // this was added by Blood + gamefunc_Turn_Around, + gamefunc_Aim_Center, + gamefunc_Tilt_Left, + gamefunc_Tilt_Right, + gamefunc_Send_Message, + gamefunc_BeastVision, + gamefunc_CrystalBall, + gamefunc_JumpBoots, + gamefunc_ProximityBombs, + gamefunc_RemoteBombs, + gamefunc_Smoke_Bomb, // and these by ShadowWarrior (todo: There's quite a bit of potential for consolidation here - is it worth it?) + gamefunc_Gas_Bomb, + gamefunc_Flash_Bomb, + gamefunc_Caltrops, + + NUMGAMEFUNCTIONS +}; + + +// Actions +struct FButtonStatus +{ + enum { MAX_KEYS = 6 }; // Maximum number of keys that can press this button + + uint16_t Keys[MAX_KEYS]; + bool bDown; // Button is down right now + bool bWentDown; // Button went down this tic + bool bWentUp; // Button went up this tic + + bool PressKey (int keynum); // Returns true if this key caused the button to be pressed. + bool ReleaseKey (int keynum); // Returns true if this key is no longer pressed. + void ResetTriggers () { bWentDown = bWentUp = false; } + void Reset () { bDown = bWentDown = bWentUp = false; } +}; + + +class ButtonMap +{ + + FButtonStatus Buttons[NUMGAMEFUNCTIONS]; + FString NumToName[NUMGAMEFUNCTIONS]; // The internal name of the button + FString NumToAlias[NUMGAMEFUNCTIONS]; // The display name which can be altered by scripts. + TMap NameToNum; + +public: + ButtonMap(); + + constexpr int NumButtons() const + { + return NUMGAMEFUNCTIONS; + } + + int FindButtonIndex(const char* func) const; + + FButtonStatus *FindButton(const char *func) + { + int index = FindButtonIndex(func); + return index > -1? &Buttons[index] : nullptr; + } + + const char* GetButtonName(int32_t func) const + { + if ((unsigned)func >= (unsigned)NumButtons()) + return nullptr; + return NumToName[func]; + } + + const char* GetButtonAlias(int32_t func) const + { + if ((unsigned)func >= (unsigned)NumButtons()) + return nullptr; + return NumToAlias[func]; + } + + void SetButtonAlias(int num, const char* text); + void ClearButtonAlias(int num); + void ResetButtonTriggers (); // Call ResetTriggers for all buttons + void ResetButtonStates (); // Same as above, but also clear bDown + int ListActionCommands(const char* pattern); + + + bool ButtonDown(int x) const + { + return Buttons[x].bDown; + } + + bool ButtonPressed(int x) const + { + return Buttons[x].bWentDown; + } + + bool ButtonReleased(int x) const + { + return Buttons[x].bWentUp; + } + + void ClearButton(int x) + { + Buttons[x].Reset(); + } +}; + +extern ButtonMap buttonMap; diff --git a/source/common/console/c_commandline.h b/source/common/console/c_commandline.h index 7c03d822b..9a267dada 100644 --- a/source/common/console/c_commandline.h +++ b/source/common/console/c_commandline.h @@ -1,3 +1,4 @@ +#pragma once /* ** c_dispatch.h ** @@ -31,12 +32,9 @@ ** */ -#ifndef __C_DISPATCH_H__ -#define __C_DISPATCH_H__ class FConfigFile; -const int KEY_DBLCLICKED = 0x8000; // Class that can parse command lines class FCommandLine { @@ -56,5 +54,3 @@ private: bool noescapes; }; - -#endif //__C_DISPATCH_H__ diff --git a/source/common/console/c_cvars.cpp b/source/common/console/c_cvars.cpp index c51c72f8c..5022de8ca 100644 --- a/source/common/console/c_cvars.cpp +++ b/source/common/console/c_cvars.cpp @@ -41,8 +41,8 @@ #include "c_console.h" #include "gamecvars.h" -//#include "cmdlib.h" -//#include "c_dispatch.h" +#include "cmdlib.h" +#include "c_dispatch.h" //#include "g_game.h" //#include "d_player.h" @@ -1419,7 +1419,6 @@ void C_ArchiveCVars (FConfigFile *f, uint32_t filter) } } -#if 0 EXTERN_CVAR(Bool, sv_cheats); void FBaseCVar::CmdSet (const char *newval) @@ -1543,7 +1542,7 @@ void FBaseCVar::ListVars (const char *filter, bool plain) else { ++count; - Printf ("%c%c%c%c%c %s = %s\n", + Printf ("%c%c%c %s = %s\n", flags & CVAR_ARCHIVE ? 'A' : ' ', flags & CVAR_USERINFO ? 'U' : flags & CVAR_SERVERINFO ? 'S' : @@ -1551,8 +1550,6 @@ void FBaseCVar::ListVars (const char *filter, bool plain) flags & CVAR_NOSET ? '-' : flags & CVAR_LATCH ? 'L' : flags & CVAR_UNSETTABLE ? '*' : ' ', - flags & CVAR_MOD ? 'M' : ' ', - flags & CVAR_IGNORE ? 'X' : ' ', var->GetName(), var->GetHumanString()); } @@ -1596,4 +1593,3 @@ CCMD (archivecvar) } } } -#endif \ No newline at end of file diff --git a/source/common/console/c_dispatch.cpp b/source/common/console/c_dispatch.cpp new file mode 100644 index 000000000..feebae09e --- /dev/null +++ b/source/common/console/c_dispatch.cpp @@ -0,0 +1,1027 @@ +/* +** c_dispatch.cpp +** Functions for executing console commands and aliases +** +**--------------------------------------------------------------------------- +** Copyright 1998-2007 Randy Heit +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +*/ + +// HEADER FILES ------------------------------------------------------------ + +#include +#include +#include +#include + +#include "templates.h" +//#include "doomtype.h" +#include "cmdlib.h" +#include "c_console.h" +#include "c_dispatch.h" +#include "m_argv.h" +//#include "g_game.h" +//#include "d_player.h" +#include "configfile.h" +#include "printf.h" +#include "c_cvars.h" +#include "v_text.h" +#include "inputstate.h" +#include "c_buttons.h" +//#include "d_net.h" +//#include "d_main.h" +//#include "serializer.h" +//#include "menu/menu.h" +//#include "g_levellocals.h" + +// MACROS ------------------------------------------------------------------ + +// TYPES ------------------------------------------------------------------- + +class FDelayedCommand +{ +public: + virtual ~FDelayedCommand() {} + +protected: + virtual bool Tick() = 0; + + friend class FDelayedCommandQueue; +}; + +class FWaitingCommand : public FDelayedCommand +{ +public: + FWaitingCommand(const char *cmd, int tics) + : Command(cmd), TicsLeft(tics+1) + {} + + bool Tick() override + { + if (--TicsLeft == 0) + { + AddCommandString(Command); + return true; + } + return false; + } + + FString Command; + int TicsLeft; +}; + +class FStoredCommand : public FDelayedCommand +{ +public: + FStoredCommand(FConsoleCommand *com, const char *cmd) + : Command(com), Text(cmd) + {} + + bool Tick() override + { + if (Text.IsNotEmpty() && Command != nullptr) + { + FCommandLine args(Text); + Command->Run(args, /*current player*/nullptr, 0); + } + return true; + } + +private: + + FConsoleCommand *Command; + FString Text; +}; + +class FDelayedCommandQueue +{ + TDeletingArray delayedCommands; +public: + void Run() + { + for (unsigned i = 0; i < delayedCommands.Size(); i++) + { + if (delayedCommands[i]->Tick()) + { + delete delayedCommands[i]; + delayedCommands.Delete(i); + i--; + } + } + } + + void Clear() + { + delayedCommands.DeleteAndClear(); + } + + void AddCommand(FDelayedCommand * cmd) + { + delayedCommands.Push(cmd); + } +}; + +static FDelayedCommandQueue delayedCommandQueue; + +void C_RunDelayedCommands() +{ + delayedCommandQueue.Run(); +} + +void C_ClearDelayedCommands() +{ + delayedCommandQueue.Clear(); +} + + + +// EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- + +// PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- + +// PRIVATE FUNCTION PROTOTYPES --------------------------------------------- + +static long ParseCommandLine (const char *args, int *argc, char **argv, bool no_escapes); +static FConsoleCommand *FindNameInHashTable (FConsoleCommand **table, const char *name, size_t namelen); +static FConsoleCommand *ScanChainForName (FConsoleCommand *start, const char *name, size_t namelen, FConsoleCommand **prev); + +// EXTERNAL DATA DECLARATIONS ---------------------------------------------- + +// PUBLIC DATA DEFINITIONS ------------------------------------------------- + +CVAR (Bool, lookspring, true, CVAR_ARCHIVE); // Generate centerview when -mlook encountered? + +FConsoleCommand *Commands[FConsoleCommand::HASH_SIZE]; + + +// PRIVATE DATA DEFINITIONS ------------------------------------------------ + +// CODE -------------------------------------------------------------------- + +void C_DoCommand (const char *cmd, int keynum) +{ + FConsoleCommand *com; + const char *end; + const char *beg; + + // Skip any beginning whitespace + while (*cmd > 0 && *cmd <= ' ') + cmd++; + + // Find end of the command name + if (*cmd == '\"') + { + for (end = beg = cmd+1; *end && *end != '\"'; ++end) + ; + } + else + { + beg = cmd; + for (end = cmd+1; *end > ' ' || *end < 0; ++end) + ; + } + + const size_t len = end - beg; + + // Check if this is an action + if (*beg == '+' || *beg == '-') + { + auto button = buttonMap.FindButton(beg + 1); + if (button) + { + if (*beg == '+') + { + button->PressKey (keynum); + } + else + { + button->ReleaseKey (keynum); + /* + if (button == &Button_Mlook && lookspring) + { + Net_WriteByte (DEM_CENTERVIEW); + } + */ + } + return; + } + } + + // Parse it as a normal command + // Checking for matching commands follows this search order: + // 1. Check the Commands[] hash table + // 2. Check the CVars list + + if ( (com = FindNameInHashTable (Commands, beg, len)) ) + { + if (//gamestate != GS_STARTUP || + (len == 3 && strnicmp (beg, "set", 3) == 0) || + (len == 7 && strnicmp (beg, "logfile", 7) == 0) || + (len == 9 && strnicmp (beg, "unbindall", 9) == 0) || + (len == 4 && strnicmp (beg, "bind", 4) == 0) || + (len == 4 && strnicmp (beg, "exec", 4) == 0) || + (len ==10 && strnicmp (beg, "doublebind", 10) == 0) + ) + { + FCommandLine args (beg); + com->Run (args, /*current player*/nullptr, keynum); + } + else + { + if (len == 4 && strnicmp(beg, "warp", 4) == 0) + { + //StoredWarp = beg; + } + else + { + auto cmd = new FStoredCommand(com, beg); + delayedCommandQueue.AddCommand(cmd); + } + } + } + else + { // Check for any console vars that match the command + FBaseCVar *var = FindCVarSub (beg, int(len)); + + if (var != NULL) + { + FCommandLine args (beg); + + if (args.argc() >= 2) + { // Set the variable + var->CmdSet (args[1]); + } + else + { // Get the variable's value + Printf ("\"%s\" is \"%s\"\n", var->GetName(), var->GetHumanString()); + } + } + else + { // We don't know how to handle this command + Printf ("Unknown command \"%.*s\"\n", (int)len, beg); + } + } +} + +void AddCommandString (const char *text, int keynum) +{ + // Operate on a local copy instead of messing around with the data that's being passed in here. + TArray buffer(strlen(text) + 1, true); + memcpy(buffer.Data(), text, buffer.Size()); + char *cmd = buffer.Data(); + char *brkpt; + int more; + + if (cmd) + { + while (*cmd) + { + brkpt = cmd; + while (*brkpt != ';' && *brkpt != '\0') + { + if (*brkpt == '\"') + { + brkpt++; + while (*brkpt != '\0' && (*brkpt != '\"' || *(brkpt-1) == '\\')) + brkpt++; + } + if (*brkpt != '\0') + brkpt++; + } + if (*brkpt == ';') + { + *brkpt = '\0'; + more = 1; + } + else + { + more = 0; + } + // Intercept wait commands here. Note: wait must be lowercase + while (*cmd > 0 && *cmd <= ' ') + cmd++; + if (*cmd) + { + if (cmd[0] == 'w' && cmd[1] == 'a' && cmd[2] == 'i' && cmd[3] == 't' && + (cmd[4] == 0 || cmd[4] == ' ')) + { + int tics; + + if (cmd[4] == ' ') + { + tics = (int)strtoll (cmd + 5, NULL, 0); + } + else + { + tics = 1; + } + if (tics > 0) + { + if (more) + { // The remainder of the command will be executed later + // Note that deferred commands lose track of which key + // (if any) they were pressed from. + *brkpt = ';'; + auto cmd = new FWaitingCommand(brkpt, tics); + delayedCommandQueue.AddCommand(cmd); + } + return; + } + } + else + { + C_DoCommand (cmd, keynum); + } + } + if (more) + { + *brkpt = ';'; + } + cmd = brkpt + more; + } + } +} + +static FConsoleCommand *ScanChainForName (FConsoleCommand *start, const char *name, size_t namelen, FConsoleCommand **prev) +{ + int comp; + + *prev = NULL; + while (start) + { + comp = strnicmp (start->m_Name, name, namelen); + if (comp > 0) + return NULL; + else if (comp == 0 && start->m_Name[namelen] == 0) + return start; + + *prev = start; + start = start->m_Next; + } + return NULL; +} + +static FConsoleCommand *FindNameInHashTable (FConsoleCommand **table, const char *name, size_t namelen) +{ + FConsoleCommand *dummy; + + return ScanChainForName (table[MakeKey (name, namelen) % FConsoleCommand::HASH_SIZE], name, namelen, &dummy); +} + +bool FConsoleCommand::AddToHash (FConsoleCommand **table) +{ + unsigned int key; + FConsoleCommand *insert, **bucket; + + key = MakeKey (m_Name); + bucket = &table[key % HASH_SIZE]; + + if (ScanChainForName (*bucket, m_Name, strlen (m_Name), &insert)) + { + return false; + } + else + { + if (insert) + { + m_Next = insert->m_Next; + if (m_Next) + m_Next->m_Prev = &m_Next; + insert->m_Next = this; + m_Prev = &insert->m_Next; + } + else + { + m_Next = *bucket; + *bucket = this; + m_Prev = bucket; + if (m_Next) + m_Next->m_Prev = &m_Next; + } + } + return true; +} + +FConsoleCommand* FConsoleCommand::FindByName (const char* name) +{ + return FindNameInHashTable (Commands, name, strlen (name)); +} + +FConsoleCommand::FConsoleCommand (const char *name, CCmdRun runFunc) + : m_RunFunc (runFunc) +{ + static bool firstTime = true; + + if (firstTime) + { + unsigned int i; + + firstTime = false; + + // Add all the action commands for tab completion + for (i = 0; i < buttonMap.NumButtons(); i++) + { + FString tname = "+"; tname << buttonMap.GetButtonName(i); + C_AddTabCommand (tname); + tname.Substitute('+', '-'); + C_AddTabCommand (tname); + } + } + + int ag = strcmp (name, "kill"); + if (ag == 0) + ag=0; + m_Name = name; + + if (!AddToHash (Commands)) + Printf ("Adding CCMD %s twice.\n", name); + else + C_AddTabCommand (name); +} + +FConsoleCommand::~FConsoleCommand () +{ + *m_Prev = m_Next; + if (m_Next) + m_Next->m_Prev = m_Prev; + C_RemoveTabCommand (m_Name); +} + +void FConsoleCommand::Run (FCommandLine &argv, void *who, int key) +{ + m_RunFunc (argv, who, key); +} + +FConsoleAlias::FConsoleAlias (const char *name, const char *command, bool noSave) + : FConsoleCommand (name, NULL), + bRunning(false), bKill(false) +{ + m_Command[noSave] = command; + m_Command[!noSave] = FString(); + // If the command contains % characters, assume they are parameter markers + // for substitution when the command is executed. + bDoSubstitution = (strchr (command, '%') != NULL); +} + +FConsoleAlias::~FConsoleAlias () +{ + m_Command[1] = m_Command[0] = FString(); +} + +// Given an argument vector, reconstitute the command line it could have been produced from. +FString BuildString (int argc, FString *argv) +{ + if (argc == 1) + { + return *argv; + } + else + { + FString buf; + int arg; + + for (arg = 0; arg < argc; arg++) + { + if (argv[arg][0] == '\0') + { // It's an empty argument, we need to convert it to '""' + buf << "\"\" "; + } + else if (strchr(argv[arg], '"')) + { // If it contains one or more quotes, we need to escape them. + buf << '"'; + long substr_start = 0, quotepos; + while ((quotepos = argv[arg].IndexOf('"', substr_start)) >= 0) + { + if (substr_start < quotepos) + { + buf << argv[arg].Mid(substr_start, quotepos - substr_start); + } + buf << "\\\""; + substr_start = quotepos + 1; + } + buf << argv[arg].Mid(substr_start) << "\" "; + } + else if (strchr(argv[arg], ' ')) + { // If it contains a space, it needs to be quoted. + buf << '"' << argv[arg] << "\" "; + } + else + { + buf << argv[arg] << ' '; + } + } + return buf; + } +} + +//=========================================================================== +// +// SubstituteAliasParams +// +// Given an command line and a set of arguments, replace instances of +// %x or %{x} in the command line with argument x. If argument x does not +// exist, then the empty string is substituted in its place. +// +// Substitution is not done inside of quoted strings, unless that string is +// prepended with a % character. +// +// To avoid a substitution, use %%. The %% will be replaced by a single %. +// +//=========================================================================== + +FString SubstituteAliasParams (FString &command, FCommandLine &args) +{ + // Do substitution by replacing %x with the argument x. + // If there is no argument x, then %x is simply removed. + + // For some reason, strtoul's stop parameter is non-const. + char *p = command.LockBuffer(), *start = p; + unsigned long argnum; + FString buf; + bool inquote = false; + + while (*p != '\0') + { + if (p[0] == '%' && ((p[1] >= '0' && p[1] <= '9') || p[1] == '{')) + { + // Do a substitution. Output what came before this. + buf.AppendCStrPart (start, p - start); + + // Extract the argument number and substitute the corresponding argument. + argnum = strtoul (p + 1 + (p[1] == '{'), &start, 10); + if ((p[1] != '{' || *start == '}') && argnum < (unsigned long)args.argc()) + { + buf += args[argnum]; + } + p = (start += (p[1] == '{' && *start == '}')); + } + else if (p[0] == '%' && p[1] == '%') + { + // Do not substitute. Just collapse to a single %. + buf.AppendCStrPart (start, p - start + 1); + start = p = p + 2; + continue; + } + else if (p[0] == '%' && p[1] == '"') + { + // Collapse %" to " and remember that we're in a quote so when we + // see a " character again, we don't start skipping below. + if (!inquote) + { + inquote = true; + buf.AppendCStrPart(start, p - start); + start = p + 1; + } + else + { + inquote = false; + } + p += 2; + } + else if (p[0] == '\\' && p[1] == '"') + { + p += 2; + } + else if (p[0] == '"') + { + // Don't substitute inside quoted strings if it didn't start + // with a %" + if (!inquote) + { + p++; + while (*p != '\0' && (*p != '"' || *(p-1) == '\\')) + p++; + if (*p != '\0') + p++; + } + else + { + inquote = false; + p++; + } + } + else + { + p++; + } + } + // Return whatever was after the final substitution. + if (p > start) + { + buf.AppendCStrPart (start, p - start); + } + command.UnlockBuffer(); + + return buf; +} + +static int DumpHash (FConsoleCommand **table, bool aliases, const char *pattern=NULL) +{ + int bucket, count; + FConsoleCommand *cmd; + + for (bucket = count = 0; bucket < FConsoleCommand::HASH_SIZE; bucket++) + { + cmd = table[bucket]; + while (cmd) + { + if (CheckWildcards (pattern, cmd->m_Name)) + { + if (cmd->IsAlias()) + { + if (aliases) + { + ++count; + static_cast(cmd)->PrintAlias (); + } + } + else if (!aliases) + { + ++count; + cmd->PrintCommand (); + } + } + cmd = cmd->m_Next; + } + } + return count; +} + +void FConsoleAlias::PrintAlias () +{ + if (m_Command[0].IsNotEmpty()) + { + Printf (TEXTCOLOR_YELLOW "%s : %s\n", m_Name, m_Command[0].GetChars()); + } + if (m_Command[1].IsNotEmpty()) + { + Printf (TEXTCOLOR_ORANGE "%s : %s\n", m_Name, m_Command[1].GetChars()); + } +} + +void FConsoleAlias::Archive (FConfigFile *f) +{ + if (f != NULL && !m_Command[0].IsEmpty()) + { + f->SetValueForKey ("Name", m_Name, true); + f->SetValueForKey ("Command", m_Command[0], true); + } +} + +void C_ArchiveAliases (FConfigFile *f) +{ + int bucket; + FConsoleCommand *alias; + + for (bucket = 0; bucket < FConsoleCommand::HASH_SIZE; bucket++) + { + alias = Commands[bucket]; + while (alias) + { + if (alias->IsAlias()) + static_cast(alias)->Archive (f); + alias = alias->m_Next; + } + } +} + +void C_ClearAliases () +{ + int bucket; + FConsoleCommand *alias; + + for (bucket = 0; bucket < FConsoleCommand::HASH_SIZE; bucket++) + { + alias = Commands[bucket]; + while (alias) + { + FConsoleCommand *next = alias->m_Next; + if (alias->IsAlias()) + static_cast(alias)->SafeDelete(); + alias = next; + } + } +} + +CCMD(clearaliases) +{ + C_ClearAliases(); +} + + +// This is called only by the ini parser. +void C_SetAlias (const char *name, const char *cmd) +{ + FConsoleCommand *prev, *alias, **chain; + + chain = &Commands[MakeKey (name) % FConsoleCommand::HASH_SIZE]; + alias = ScanChainForName (*chain, name, strlen (name), &prev); + if (alias != NULL) + { + if (!alias->IsAlias ()) + { + //Printf (PRINT_BOLD, "%s is a command and cannot be an alias.\n", name); + return; + } + delete alias; + } + new FConsoleAlias (name, cmd, false); +} + +CCMD (alias) +{ + FConsoleCommand *prev, *alias, **chain; + + if (argv.argc() == 1) + { + Printf ("Current alias commands:\n"); + DumpHash (Commands, true); + } + else + { + chain = &Commands[MakeKey (argv[1]) % FConsoleCommand::HASH_SIZE]; + + if (argv.argc() == 2) + { // Remove the alias + + if ( (alias = ScanChainForName (*chain, argv[1], strlen (argv[1]), &prev))) + { + if (alias->IsAlias ()) + { + static_cast (alias)->SafeDelete (); + } + else + { + Printf ("%s is a normal command\n", alias->m_Name); + } + } + } + else + { // Add/change the alias + + alias = ScanChainForName (*chain, argv[1], strlen (argv[1]), &prev); + if (alias != NULL) + { + if (alias->IsAlias ()) + { + static_cast (alias)->Realias (argv[2], false); + } + else + { + Printf ("%s is a normal command\n", alias->m_Name); + alias = NULL; + } + } + else + { + new FConsoleAlias (argv[1], argv[2], false); + } + } + } +} + +CCMD (cmdlist) +{ + int count; + const char *filter = (argv.argc() == 1 ? NULL : argv[1]); + + count = buttonMap.ListActionCommands (filter); + count += DumpHash (Commands, false, filter); + Printf ("%d commands\n", count); +} + +CCMD (key) +{ + if (argv.argc() > 1) + { + int i; + + for (i = 1; i < argv.argc(); ++i) + { + unsigned int key = MakeKey (argv[i]); + Printf (" 0x%08x\n", key); + } + } +} + +// Execute any console commands specified on the command line. +// These all begin with '+' as opposed to '-'. +FExecList *C_ParseCmdLineParams(FExecList *exec) +{ + for (int currArg = 1; currArg < Args->NumArgs(); ) + { + if (*Args->GetArg (currArg++) == '+') + { + FString cmdString; + int cmdlen = 1; + int argstart = currArg - 1; + + while (currArg < Args->NumArgs()) + { + if (*Args->GetArg (currArg) == '-' || *Args->GetArg (currArg) == '+') + break; + currArg++; + cmdlen++; + } + + cmdString = BuildString (cmdlen, Args->GetArgList (argstart)); + if (!cmdString.IsEmpty()) + { + if (exec == NULL) + { + exec = new FExecList; + } + exec->AddCommand(&cmdString[1]); + } + } + } + return exec; +} + +bool FConsoleCommand::IsAlias () +{ + return false; +} + +bool FConsoleAlias::IsAlias () +{ + return true; +} + +void FConsoleAlias::Run (FCommandLine &args, void *who, int key) +{ + if (bRunning) + { + Printf ("Alias %s tried to recurse.\n", m_Name); + return; + } + + int index = !m_Command[1].IsEmpty(); + FString savedcommand = m_Command[index], mycommand; + m_Command[index] = FString(); + + if (bDoSubstitution) + { + mycommand = SubstituteAliasParams (savedcommand, args); + } + else + { + mycommand = savedcommand; + } + + bRunning = true; + AddCommandString (mycommand, key); + bRunning = false; + if (m_Command[index].IsEmpty()) + { // The alias is unchanged, so put the command back so it can be used again. + // If the command had been non-empty, then that means that executing this + // alias caused it to realias itself, so the old command will be forgotten + // once this function returns. + m_Command[index] = savedcommand; + } + if (bKill) + { // The alias wants to remove itself + delete this; + } +} + +void FConsoleAlias::Realias (const char *command, bool noSave) +{ + if (!noSave && !m_Command[1].IsEmpty()) + { + noSave = true; + } + m_Command[noSave] = command; + + // If the command contains % characters, assume they are parameter markers + // for substitution when the command is executed. + bDoSubstitution = (strchr (command, '%') != NULL); + bKill = false; +} + +void FConsoleAlias::SafeDelete () +{ + if (!bRunning) + { + delete this; + } + else + { + bKill = true; + } +} + +void FExecList::AddCommand(const char *cmd, const char *file) +{ + // Recursive exec: Parse this file now. + if (strnicmp(cmd, "exec", 4) == 0 && isspace(cmd[4])) + { + FCommandLine argv(cmd); + for (int i = 1; i < argv.argc(); ++i) + { + C_ParseExecFile(argv[i], this); + } + } + else + { + Commands.Push(cmd); + } +} + +void FExecList::ExecCommands() const +{ + for (unsigned i = 0; i < Commands.Size(); ++i) + { + AddCommandString(Commands[i]); + } +} + +FExecList *C_ParseExecFile(const char *file, FExecList *exec) +{ + char cmd[4096]; + int retval = 0; + + FileReader fr; + + if ( (fr.OpenFile(file)) ) + { + while (fr.Gets(cmd, countof(cmd)-1)) + { + // Comments begin with // + char *stop = cmd + strlen(cmd) - 1; + char *comment = cmd; + int inQuote = 0; + + if (*stop == '\n') + *stop-- = 0; + + while (comment < stop) + { + if (*comment == '\"') + { + inQuote ^= 1; + } + else if (!inQuote && *comment == '/' && *(comment + 1) == '/') + { + break; + } + comment++; + } + if (comment == cmd) + { // Comment at line beginning + continue; + } + else if (comment < stop) + { // Comment in middle of line + *comment = 0; + } + if (exec == NULL) + { + exec = new FExecList; + } + exec->AddCommand(cmd, file); + } + } + else + { + Printf ("Could not open \"%s\"\n", file); + } + return exec; +} + +bool C_ExecFile (const char *file) +{ + FExecList *exec = C_ParseExecFile(file, NULL); + if (exec != NULL) + { + exec->ExecCommands(); + delete exec; + } + return exec != NULL; +} + diff --git a/source/common/console/c_dispatch.h b/source/common/console/c_dispatch.h new file mode 100644 index 000000000..0fe7997a6 --- /dev/null +++ b/source/common/console/c_dispatch.h @@ -0,0 +1,146 @@ +/* +** c_dispatch.h +** +**--------------------------------------------------------------------------- +** Copyright 1998-2006 Randy Heit +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +*/ + +#ifndef __C_DISPATCH_H__ +#define __C_DISPATCH_H__ + +#include "printf.h" +#include "zstring.h" +#include "c_commandline.h" + +class FConfigFile; + +// Contains the contents of an exec'ed file +struct FExecList +{ + TArray Commands; + + void AddCommand(const char *cmd, const char *file = NULL); + void ExecCommands() const; +}; + + +extern bool CheckCheatmode (bool printmsg = true); + +FExecList *C_ParseCmdLineParams(FExecList *exec); + +// Add commands to the console as if they were typed in. Can handle wait +// and semicolon-separated commands. This function may modify the source +// string, but the string will be restored to its original state before +// returning. Therefore, commands passed must not be in read-only memory. +void AddCommandString (const char *text, int keynum=0); + +void C_RunDelayedCommands(); +void C_ClearDelayedCommands(); + +// Process a single console command. Does not handle wait. +void C_DoCommand (const char *cmd, int keynum=0); + +FExecList *C_ParseExecFile(const char *file, FExecList *source); +bool C_ExecFile(const char *file); + +// Write out alias commands to a file for all current aliases. +void C_ArchiveAliases (FConfigFile *f); + +void C_SetAlias (const char *name, const char *cmd); +void C_ClearAliases (); + +// build a single string out of multiple strings +FString BuildString (int argc, FString *argv); + +typedef void (*CCmdRun) (FCommandLine &argv, void *instigator, int key); + +class FConsoleCommand +{ +public: + FConsoleCommand (const char *name, CCmdRun RunFunc); + virtual ~FConsoleCommand (); + virtual bool IsAlias (); + void PrintCommand () { Printf ("%s\n", m_Name); } + + virtual void Run (FCommandLine &args, void *instigator, int key); + static FConsoleCommand* FindByName (const char* name); + + FConsoleCommand *m_Next, **m_Prev; + FString m_Name; + + enum { HASH_SIZE = 251 }; // Is this prime? + +protected: + FConsoleCommand (); + bool AddToHash (FConsoleCommand **table); + + CCmdRun m_RunFunc; + +}; + +#define CCMD(n) \ + void Cmd_##n (FCommandLine &, void *, int key); \ + FConsoleCommand Cmd_##n##_Ref (#n, Cmd_##n); \ + void Cmd_##n (FCommandLine &argv, void *who, int key) + +const int KEY_DBLCLICKED = 0x8000; + +class FConsoleAlias : public FConsoleCommand +{ +public: + FConsoleAlias (const char *name, const char *command, bool noSave); + ~FConsoleAlias (); + void Run (FCommandLine &args, void *instigator, int key); + bool IsAlias (); + void PrintAlias (); + void Archive (FConfigFile *f); + void Realias (const char *command, bool noSave); + void SafeDelete (); +protected: + FString m_Command[2]; // Slot 0 is saved to the ini, slot 1 is not. + bool bDoSubstitution; + bool bRunning; + bool bKill; +}; + +class FUnsafeConsoleAlias : public FConsoleAlias +{ +public: + FUnsafeConsoleAlias (const char *name, const char *command) + : FConsoleAlias (name, command, true) + { + } + + virtual void Run (FCommandLine &args, void *instigator, int key) override; +}; + + +void execLogfile(const char *fn, bool append = false); + +#endif //__C_DISPATCH_H__ diff --git a/source/common/gamecontrol.cpp b/source/common/gamecontrol.cpp index 71a9e5788..5ea65c604 100644 --- a/source/common/gamecontrol.cpp +++ b/source/common/gamecontrol.cpp @@ -24,123 +24,13 @@ int ShowStartupWindow(TArray &); void InitFileSystem(TArray&); int globalShadeDiv; -struct GameFuncNameDesc -{ - int index; - const char *name; -}; - -static const GameFuncNameDesc gamefuncs[] = { - { gamefunc_Move_Forward, "Move_Forward"}, - { gamefunc_Move_Backward, "Move_Backward"}, - { gamefunc_Turn_Left, "Turn_Left"}, - { gamefunc_Turn_Right, "Turn_Right"}, - { gamefunc_Strafe, "Strafe"}, - { gamefunc_Fire, "Fire"}, - { gamefunc_Open, "Open"}, - { gamefunc_Run, "Run"}, - { gamefunc_Alt_Fire, "Alt_Fire"}, - { gamefunc_Jump, "Jump"}, - { gamefunc_Crouch, "Crouch"}, - { gamefunc_Look_Up, "Look_Up"}, - { gamefunc_Look_Down, "Look_Down"}, - { gamefunc_Look_Left, "Look_Left"}, - { gamefunc_Look_Right, "Look_Right"}, - { gamefunc_Strafe_Left, "Strafe_Left"}, - { gamefunc_Strafe_Right, "Strafe_Right"}, - { gamefunc_Aim_Up, "Aim_Up"}, - { gamefunc_Aim_Down, "Aim_Down"}, - { gamefunc_Weapon_1, "Weapon_1"}, - { gamefunc_Weapon_2, "Weapon_2"}, - { gamefunc_Weapon_3, "Weapon_3"}, - { gamefunc_Weapon_4, "Weapon_4"}, - { gamefunc_Weapon_5, "Weapon_5"}, - { gamefunc_Weapon_6, "Weapon_6"}, - { gamefunc_Weapon_7, "Weapon_7"}, - { gamefunc_Weapon_8, "Weapon_8"}, - { gamefunc_Weapon_9, "Weapon_9"}, - { gamefunc_Weapon_10, "Weapon_10"}, - { gamefunc_Inventory, "Inventory"}, - { gamefunc_Inventory_Left, "Inventory_Left"}, - { gamefunc_Inventory_Right, "Inventory_Right"}, - { gamefunc_Holo_Duke, "Holo_Duke"}, - { gamefunc_Jetpack, "Jetpack"}, - { gamefunc_NightVision, "NightVision"}, - { gamefunc_MedKit, "MedKit"}, - { gamefunc_TurnAround, "TurnAround"}, - { gamefunc_SendMessage, "SendMessage"}, - { gamefunc_Map, "Map"}, - { gamefunc_Shrink_Screen, "Shrink_Screen"}, - { gamefunc_Enlarge_Screen, "Enlarge_Screen"}, - { gamefunc_Center_View, "Center_View"}, - { gamefunc_Holster_Weapon, "Holster_Weapon"}, - { gamefunc_Show_Opponents_Weapon, "Show_Opponents_Weapon"}, - { gamefunc_Map_Follow_Mode, "Map_Follow_Mode"}, - { gamefunc_See_Coop_View, "See_Coop_View"}, - { gamefunc_Mouse_Aiming, "Mouse_Aiming"}, - { gamefunc_Toggle_Crosshair, "Toggle_Crosshair"}, - { gamefunc_Steroids, "Steroids"}, - { gamefunc_Quick_Kick, "Quick_Kick"}, - { gamefunc_Next_Weapon, "Next_Weapon"}, - { gamefunc_Previous_Weapon, "Previous_Weapon"}, - { gamefunc_Show_Console, "Show_Console"}, - { gamefunc_Show_DukeMatch_Scores, "Show_DukeMatch_Scores"}, - { gamefunc_Dpad_Select, "Dpad_Select"}, - { gamefunc_Dpad_Aiming, "Dpad_Aiming"}, - { gamefunc_AutoRun, "AutoRun"}, - { gamefunc_Last_Weapon, "Last_Used_Weapon"}, - { gamefunc_Quick_Save, "Quick_Save"}, - { gamefunc_Quick_Load, "Quick_Load"}, - { gamefunc_Alt_Weapon, "Alt_Weapon"}, - { gamefunc_Third_Person_View, "Third_Person_View"}, - { gamefunc_Toggle_Crouch, "Toggle_Crouch"}, - { gamefunc_See_Chase_View, "See_Chase_View"}, // the following were added by Blood - { gamefunc_Turn_Around, "Turn_Around"}, - { gamefunc_Aim_Center, "Aim_Center"}, - { gamefunc_Tilt_Left, "Tilt_Left"}, - { gamefunc_Tilt_Right, "Tilt_Right"}, - { gamefunc_Send_Message, "Send_Message"}, - { gamefunc_BeastVision, "BeastVision"}, - { gamefunc_CrystalBall, "CrystalBall"}, - { gamefunc_JumpBoots, "JumpBoots"}, - { gamefunc_ProximityBombs, "ProximityBombs"}, - { gamefunc_RemoteBombs, "RemoteBombs"}, - { gamefunc_Smoke_Bomb, "Smoke_Bomb" }, - { gamefunc_Gas_Bomb, "Gas_Bomb" }, - { gamefunc_Flash_Bomb, "Flash_Bomb" }, - { gamefunc_Caltrops, "Calitrops" }, - -}; - FString currentGame; FString LumpFilter; -static TMap GF_NameToNum; -static FString GF_NumToName[NUMGAMEFUNCTIONS]; // This one will preserve the original name for writing to the config (which must be loaded before CON scripts can hack around with the alias array.) -static FString GF_NumToAlias[NUMGAMEFUNCTIONS]; // This is for CON scripts to hack apart. - -uint8_t KeyboardKeys[NUMGAMEFUNCTIONS][2]; CVAR(Int, cl_defaultconfiguration, 2, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -//========================================================================== -// -// -// -//========================================================================== - -void SetupButtonFunctions() -{ - unsigned index = 0; - for (auto& func : GF_NumToAlias) - { - if (func[0] == '\0') - continue; - - } - -} UserConfig userConfig; @@ -435,22 +325,13 @@ int CONFIG_Init() CheckFrontend(g_gameType); int index = 0; - for(auto &gf : gamefuncs) - { - GF_NameToNum.Insert(gf.name, gf.index); - GF_NumToAlias[gf.index] = GF_NumToName[gf.index] = gf.name; - - index += 2; - - } InitFileSystem(usedgroups); CONTROL_ClearAssignments(); CONFIG_InitMouseAndController(); CONFIG_SetGameControllerDefaultsStandard(); CONFIG_SetDefaultKeys(cl_defaultconfiguration == 1 ? "demolition/origbinds.txt" : cl_defaultconfiguration == 2 ? "demolition/leftbinds.txt" : "demolition/defbinds.txt"); - SetupButtonFunctions(); - + G_ReadConfig(currentGame); if (!GameConfig->IsInitialized()) { @@ -467,54 +348,6 @@ int CONFIG_Init() return gi->app_main(); } -//========================================================================== -// -// -// -//========================================================================== - -int32_t CONFIG_FunctionNameToNum(const char *func) -{ - if (!func) return -1; - - FName name(func, true); - if (name == NAME_None) return -1; - - auto res = GF_NameToNum.CheckKey(name); - if (!res) return -1; - - return *res; -} - -const char *CONFIG_FunctionNumToName(int32_t func) -{ - if ((unsigned)func >= (unsigned)NUMGAMEFUNCTIONS) - return NULL; - return GF_NumToAlias[func]; -} - -const char *CONFIG_FunctionNumToRealName(int32_t func) -{ - if ((unsigned)func >= (unsigned)NUMGAMEFUNCTIONS) - return NULL; - return GF_NumToName[func]; -} - -void CONFIG_ReplaceButtonName(int num, const char *text) -{ - if ((unsigned)num >= (unsigned)NUMGAMEFUNCTIONS) - return; - GF_NumToAlias[num] = text; - GF_NameToNum.Insert(text, num); -} - -void CONFIG_DeleteButtonName(int num) -{ - if ((unsigned)num >= (unsigned)NUMGAMEFUNCTIONS) - return; - GF_NumToAlias[num] = ""; -} - //========================================================================== // // @@ -586,7 +419,6 @@ int CONFIG_SetMapBestTime(uint8_t const* const mapmd4, int32_t tm) // //========================================================================== -int32_t MouseFunctions[MAXMOUSEBUTTONS][2]; int32_t MouseDigitalFunctions[MAXMOUSEAXES][2]; int32_t MouseAnalogueAxes[MAXMOUSEAXES]; int32_t MouseAnalogueScale[MAXMOUSEAXES]; @@ -756,19 +588,6 @@ void CONFIG_SetupMouse(void) FString section = currentGame + ".MouseSettings"; if (!GameConfig->SetSection(section)) return; - for (int i = 0; i < MAXMOUSEBUTTONS; i++) - { - section.Format("MouseButton%d", i); - val = GameConfig->GetValueForKey(section); - if (val) - MouseFunctions[i][0] = CONFIG_FunctionNameToNum(val); - - section.Format("MouseButtonClicked%d", i); - val = GameConfig->GetValueForKey(section); - if (val) - MouseFunctions[i][1] = CONFIG_FunctionNameToNum(val); - } - // map over the axes for (int i = 0; i < MAXMOUSEAXES; i++) { @@ -780,12 +599,12 @@ void CONFIG_SetupMouse(void) section.Format("MouseDigitalAxes%d_0", i); val = GameConfig->GetValueForKey(section); if (val) - MouseDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(val); + MouseDigitalFunctions[i][0] = buttonMap.FindButtonIndex(val); section.Format("MouseDigitalAxes%d_1", i); val = GameConfig->GetValueForKey(section); if (val) - MouseDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(val); + MouseDigitalFunctions[i][1] = buttonMap.FindButtonIndex(val); section.Format("MouseAnalogScale%d", i); val = GameConfig->GetValueForKey(section); @@ -793,11 +612,6 @@ void CONFIG_SetupMouse(void) MouseAnalogueScale[i] = (int32_t)strtoull(val, nullptr, 0); } - for (int i = 0; i < MAXMOUSEBUTTONS; i++) - { - CONTROL_MapButton(MouseFunctions[i][0], i, 0, controldevice_mouse); - CONTROL_MapButton(MouseFunctions[i][1], i, 1, controldevice_mouse); - } for (int i = 0; i < MAXMOUSEAXES; i++) { CONTROL_MapAnalogAxis(i, MouseAnalogueAxes[i], controldevice_mouse); @@ -820,12 +634,12 @@ void CONFIG_SetupJoystick(void) section.Format("ControllerButton%d", i); val = GameConfig->GetValueForKey(section); if (val) - JoystickFunctions[i][0] = CONFIG_FunctionNameToNum(val); + JoystickFunctions[i][0] = buttonMap.FindButtonIndex(val); section.Format("ControllerButtonClicked%d", i); val = GameConfig->GetValueForKey(section); if (val) - JoystickFunctions[i][1] = CONFIG_FunctionNameToNum(val); + JoystickFunctions[i][1] = buttonMap.FindButtonIndex(val); } // map over the axes @@ -839,12 +653,12 @@ void CONFIG_SetupJoystick(void) section.Format("ControllerDigitalAxes%d_0", i); val = GameConfig->GetValueForKey(section); if (val) - JoystickDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(val); + JoystickDigitalFunctions[i][0] = buttonMap.FindButtonIndex(val); section.Format("ControllerDigitalAxes%d_1", i); val = GameConfig->GetValueForKey(section); if (val) - JoystickDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(val); + JoystickDigitalFunctions[i][1] = buttonMap.FindButtonIndex(val); section.Format("ControllerAnalogScale%d", i); val = GameConfig->GetValueForKey(section); @@ -1115,7 +929,7 @@ void CONFIG_SetGameControllerDefaultsPro() FString CONFIG_GetGameFuncOnKeyboard(int gameFunc) { - auto binding = CONFIG_FunctionNumToRealName(gameFunc); + auto binding = buttonMap.GetButtonAlias(gameFunc); auto keys = Bindings.GetKeysForCommand(binding); for(auto key : keys) { @@ -1131,7 +945,7 @@ FString CONFIG_GetGameFuncOnKeyboard(int gameFunc) FString CONFIG_GetGameFuncOnMouse(int gameFunc) { - auto binding = CONFIG_FunctionNumToRealName(gameFunc); + auto binding = buttonMap.GetButtonAlias(gameFunc); auto keys = Bindings.GetKeysForCommand(binding); for (auto key : keys) { @@ -1147,7 +961,7 @@ FString CONFIG_GetGameFuncOnMouse(int gameFunc) char const* CONFIG_GetGameFuncOnJoystick(int gameFunc) { - auto binding = CONFIG_FunctionNumToRealName(gameFunc); + auto binding = buttonMap.GetButtonAlias(gameFunc); auto keys = Bindings.GetKeysForCommand(binding); for (auto key : keys) { @@ -1195,27 +1009,17 @@ FString CONFIG_GetBoundKeyForLastInput(int gameFunc) void CONFIG_InitMouseAndController() { - memset(MouseFunctions, -1, sizeof(MouseFunctions)); memset(MouseDigitalFunctions, -1, sizeof(MouseDigitalFunctions)); memset(JoystickFunctions, -1, sizeof(JoystickFunctions)); memset(JoystickDigitalFunctions, -1, sizeof(JoystickDigitalFunctions)); - for (int i = 0; i < MAXMOUSEBUTTONS; i++) - { - MouseFunctions[i][0] = CONFIG_FunctionNameToNum(mousedefaults[i]); - CONTROL_MapButton(MouseFunctions[i][0], i, 0, controldevice_mouse); - if (i >= 4) continue; - MouseFunctions[i][1] = CONFIG_FunctionNameToNum(mouseclickeddefaults[i]); - CONTROL_MapButton(MouseFunctions[i][1], i, 1, controldevice_mouse); - } - for (int i = 0; i < MAXMOUSEAXES; i++) { MouseAnalogueScale[i] = DEFAULTMOUSEANALOGUESCALE; CONTROL_SetAnalogAxisScale(i, MouseAnalogueScale[i], controldevice_mouse); - MouseDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(mousedigitaldefaults[i * 2]); - MouseDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(mousedigitaldefaults[i * 2 + 1]); + MouseDigitalFunctions[i][0] = buttonMap.FindButtonIndex(mousedigitaldefaults[i * 2]); + MouseDigitalFunctions[i][1] = buttonMap.FindButtonIndex(mousedigitaldefaults[i * 2 + 1]); CONTROL_MapDigitalAxis(i, MouseDigitalFunctions[i][0], 0, controldevice_mouse); CONTROL_MapDigitalAxis(i, MouseDigitalFunctions[i][1], 1, controldevice_mouse); @@ -1243,23 +1047,6 @@ void CONFIG_WriteControllerSettings() { FString section = currentGame + ".MouseSettings"; GameConfig->SetSection(section); - for (int i = 0; i < MAXMOUSEBUTTONS; i++) - { - if (CONFIG_FunctionNumToName(MouseFunctions[i][0])) - { - buf.Format("MouseButton%d", i); - GameConfig->SetValueForKey(buf, CONFIG_FunctionNumToName(MouseFunctions[i][0])); - } - - if (i >= (MAXMOUSEBUTTONS - 2)) continue; - - if (CONFIG_FunctionNumToName(MouseFunctions[i][1])) - { - buf.Format("MouseButtonClicked%d", i); - GameConfig->SetValueForKey(buf, CONFIG_FunctionNumToName(MouseFunctions[i][1])); - } - } - for (int i = 0; i < MAXMOUSEAXES; i++) { if (CONFIG_AnalogNumToName(MouseAnalogueAxes[i])) @@ -1268,16 +1055,16 @@ void CONFIG_WriteControllerSettings() GameConfig->SetValueForKey(buf, CONFIG_AnalogNumToName(MouseAnalogueAxes[i])); } - if (CONFIG_FunctionNumToName(MouseDigitalFunctions[i][0])) + if (buttonMap.GetButtonName(MouseDigitalFunctions[i][0])) { buf.Format("MouseDigitalAxes%d_0", i); - GameConfig->SetValueForKey(buf, CONFIG_FunctionNumToName(MouseDigitalFunctions[i][0])); + GameConfig->SetValueForKey(buf, buttonMap.GetButtonName(MouseDigitalFunctions[i][0])); } - if (CONFIG_FunctionNumToName(MouseDigitalFunctions[i][1])) + if (buttonMap.GetButtonName(MouseDigitalFunctions[i][1])) { buf.Format("MouseDigitalAxes%d_1", i); - GameConfig->SetValueForKey(buf, CONFIG_FunctionNumToName(MouseDigitalFunctions[i][1])); + GameConfig->SetValueForKey(buf, buttonMap.GetButtonName(MouseDigitalFunctions[i][1])); } buf.Format("MouseAnalogScale%d", i); @@ -1291,16 +1078,16 @@ void CONFIG_WriteControllerSettings() GameConfig->SetSection(section); for (int dummy = 0; dummy < MAXJOYBUTTONSANDHATS; dummy++) { - if (CONFIG_FunctionNumToName(JoystickFunctions[dummy][0])) + if (buttonMap.GetButtonName(JoystickFunctions[dummy][0])) { buf.Format("ControllerButton%d", dummy); - GameConfig->SetValueForKey(buf, CONFIG_FunctionNumToName(JoystickFunctions[dummy][0])); + GameConfig->SetValueForKey(buf, buttonMap.GetButtonName(JoystickFunctions[dummy][0])); } - if (CONFIG_FunctionNumToName(JoystickFunctions[dummy][1])) + if (buttonMap.GetButtonName(JoystickFunctions[dummy][1])) { buf.Format("ControllerButtonClicked%d", dummy); - GameConfig->SetValueForKey(buf, CONFIG_FunctionNumToName(JoystickFunctions[dummy][1])); + GameConfig->SetValueForKey(buf, buttonMap.GetButtonName(JoystickFunctions[dummy][1])); } } for (int dummy = 0; dummy < MAXJOYAXES; dummy++) @@ -1311,16 +1098,16 @@ void CONFIG_WriteControllerSettings() GameConfig->SetValueForKey(buf, CONFIG_AnalogNumToName(JoystickAnalogueAxes[dummy])); } - if (CONFIG_FunctionNumToName(JoystickDigitalFunctions[dummy][0])) + if (buttonMap.GetButtonName(JoystickDigitalFunctions[dummy][0])) { buf.Format("ControllerDigitalAxes%d_0", dummy); - GameConfig->SetValueForKey(buf, CONFIG_FunctionNumToName(JoystickDigitalFunctions[dummy][0])); + GameConfig->SetValueForKey(buf, buttonMap.GetButtonName(JoystickDigitalFunctions[dummy][0])); } - if (CONFIG_FunctionNumToName(JoystickDigitalFunctions[dummy][1])) + if (buttonMap.GetButtonName(JoystickDigitalFunctions[dummy][1])) { buf.Format("ControllerDigitalAxes%d_1", dummy); - GameConfig->SetValueForKey(buf, CONFIG_FunctionNumToName(JoystickDigitalFunctions[dummy][1])); + GameConfig->SetValueForKey(buf, buttonMap.GetButtonName(JoystickDigitalFunctions[dummy][1])); } buf.Format("ControllerAnalogScale%d", dummy); diff --git a/source/common/gamecontrol.h b/source/common/gamecontrol.h index 65d90be08..852109816 100644 --- a/source/common/gamecontrol.h +++ b/source/common/gamecontrol.h @@ -18,11 +18,6 @@ void D_AddWildFile(TArray& wadfiles, const char* value); int CONFIG_Init(); void CONFIG_SetDefaultKeys(const char *defbinds); -int32_t CONFIG_FunctionNameToNum(const char* func); -const char* CONFIG_FunctionNumToName(int32_t func); -const char* CONFIG_FunctionNumToRealName(int32_t func); -void CONFIG_ReplaceButtonName(int num, const char* text); -void CONFIG_DeleteButtonName(int num); // I am not sure if anything below will survive for long... @@ -39,7 +34,6 @@ void CONFIG_DeleteButtonName(int num); #define DEFAULTJOYSTICKANALOGUESATURATE 9500 -extern int32_t MouseFunctions[MAXMOUSEBUTTONS][2]; extern int32_t MouseDigitalFunctions[MAXMOUSEAXES][2]; extern int32_t MouseAnalogueAxes[MAXMOUSEAXES]; extern int32_t MouseAnalogueScale[MAXMOUSEAXES]; diff --git a/source/common/inputstate.h b/source/common/inputstate.h index d6d0f905f..99ae440a1 100644 --- a/source/common/inputstate.h +++ b/source/common/inputstate.h @@ -4,6 +4,7 @@ #include "tarray.h" #include "scancodes.h" #include "c_bind.h" +#include "c_buttons.h" #include "d_event.h" #include "osd.h" @@ -29,7 +30,6 @@ enum MAXMOUSEBUTTONS = 10, }; -extern int32_t CONTROL_ButtonFlags[NUMKEYS]; extern bool CONTROL_BindsEnabled; extern vec2_t g_mousePos; @@ -40,96 +40,6 @@ extern bool g_mouseInsideWindow; extern bool g_mouseLockedToWindow; -// Order is that of EDuke32 by necessity because it exposes the key binds to scripting by index instead of by name. -enum GameFunction_t -{ - gamefunc_Move_Forward, - gamefunc_Move_Backward, - gamefunc_Turn_Left, - gamefunc_Turn_Right, - gamefunc_Strafe, - gamefunc_Fire, - gamefunc_Open, - gamefunc_Run, - gamefunc_Alt_Fire, - gamefunc_Jump, - gamefunc_Crouch, - gamefunc_Look_Up, - gamefunc_Look_Down, - gamefunc_Look_Left, - gamefunc_Look_Right, - gamefunc_Strafe_Left, - gamefunc_Strafe_Right, - gamefunc_Aim_Up, - gamefunc_Aim_Down, - gamefunc_Weapon_1, - gamefunc_Weapon_2, - gamefunc_Weapon_3, - gamefunc_Weapon_4, - gamefunc_Weapon_5, - gamefunc_Weapon_6, - gamefunc_Weapon_7, - gamefunc_Weapon_8, - gamefunc_Weapon_9, - gamefunc_Weapon_10, - gamefunc_Inventory, - gamefunc_Inventory_Use = gamefunc_Inventory, - gamefunc_Inventory_Left, - gamefunc_Inventory_Right, - gamefunc_Holo_Duke, - gamefunc_Jetpack, - gamefunc_NightVision, - gamefunc_Night_Vision = gamefunc_NightVision, - gamefunc_MedKit, - gamefunc_Med_Kit = gamefunc_MedKit, - gamefunc_TurnAround, - gamefunc_SendMessage, - gamefunc_Map, - gamefunc_Map_Toggle = gamefunc_Map, - gamefunc_Shrink_Screen, - gamefunc_Enlarge_Screen, - gamefunc_Center_View, - gamefunc_Holster_Weapon, - gamefunc_Show_Opponents_Weapon, - gamefunc_Map_Follow_Mode, - gamefunc_See_Coop_View, - gamefunc_See_Co_Op_View = gamefunc_See_Coop_View, - gamefunc_Mouse_Aiming, - gamefunc_Toggle_Crosshair, - gamefunc_Steroids, - gamefunc_Quick_Kick, - gamefunc_Next_Weapon, - gamefunc_Previous_Weapon, - gamefunc_Show_Console, - gamefunc_Show_DukeMatch_Scores, - gamefunc_Dpad_Select, - gamefunc_Dpad_Aiming, - gamefunc_AutoRun, - gamefunc_Last_Weapon, - gamefunc_Quick_Save, - gamefunc_Quick_Load, - gamefunc_Alt_Weapon, - gamefunc_Third_Person_View, - gamefunc_Toggle_Crouch, - gamefunc_See_Chase_View, // this was added by Blood - gamefunc_Turn_Around, - gamefunc_Aim_Center, - gamefunc_Tilt_Left, - gamefunc_Tilt_Right, - gamefunc_Send_Message, - gamefunc_BeastVision, - gamefunc_CrystalBall, - gamefunc_JumpBoots, - gamefunc_ProximityBombs, - gamefunc_RemoteBombs, - gamefunc_Smoke_Bomb, // and these by ShadowWarrior (todo: There's quite a bit of potential for consolidation here - is it worth it?) - gamefunc_Gas_Bomb, - gamefunc_Flash_Bomb, - gamefunc_Caltrops, - - NUMGAMEFUNCTIONS -}; - enum EMouseBits { @@ -157,16 +67,7 @@ class InputState { KEYFIFOSIZ = 64, }; - // NOTE: This entire thing is mostly a band-aid to wrap something around MACT so that replacing it with a true event-driven system later - // won't result in a total disaster. None of this is meant to live for long because the input method at use here is fundamentally flawed - // because it does not track what triggered the button. - struct ButtonStateFlags - { - bool ButtonActive; // Button currently reports being active to the client - bool ButtonCleared; // Button has been cleared by the client, i.e. do not set to active until no input for this button is active anymore. - }; - ButtonStateFlags ButtonState[NUMGAMEFUNCTIONS]; uint8_t KeyStatus[NUMKEYS]; char g_keyFIFO[KEYFIFOSIZ]; @@ -182,35 +83,6 @@ class InputState uint8_t g_mouseClickState; public: - bool BUTTON(int x) - { - return ButtonState[x].ButtonActive; - } - - // Receive a status update - void UpdateButton(int x, bool set) - { - auto &b = ButtonState[x]; - if (!b.ButtonCleared) b.ButtonActive = set; - else if (!set) b.ButtonCleared = false; - - } - - void ClearButton(int x) - { - ButtonState[x].ButtonActive = false; - //ButtonState[x].ButtonCleared = true; - } - - void ClearAllButtons() - { - for (auto & b : ButtonState) - { - b.ButtonActive = false; - //b.ButtonCleared = true; - } - } - uint8_t GetKeyStatus(int key) { return KeyStatus[key]; diff --git a/source/duke3d/src/demo.cpp b/source/duke3d/src/demo.cpp index b8df2725d..53cb787a8 100644 --- a/source/duke3d/src/demo.cpp +++ b/source/duke3d/src/demo.cpp @@ -907,10 +907,10 @@ nextdemo_nomenu: { ControlInfo noshareinfo; CONTROL_GetInput(&noshareinfo); - if (inputState.BUTTON(gamefunc_SendMessage)) + if (buttonMap.ButtonDown(gamefunc_SendMessage)) { inputState.keyFlushChars(); - inputState.ClearButton(gamefunc_SendMessage); + buttonMap.ClearButton(gamefunc_SendMessage); g_player[myconnectindex].ps->gm = MODE_TYPE; typebuf[0] = 0; } diff --git a/source/duke3d/src/game.cpp b/source/duke3d/src/game.cpp index c6800284c..add0bd14e 100644 --- a/source/duke3d/src/game.cpp +++ b/source/duke3d/src/game.cpp @@ -4524,9 +4524,9 @@ void G_HandleLocalKeys(void) if (!ALT_IS_PRESSED && ud.overhead_on == 0 && (myplayer.gm & MODE_TYPE) == 0) { - if (inputState.BUTTON(gamefunc_Enlarge_Screen)) + if (buttonMap.ButtonDown(gamefunc_Enlarge_Screen)) { - inputState.ClearButton(gamefunc_Enlarge_Screen); + buttonMap.ClearButton(gamefunc_Enlarge_Screen); if (!SHIFTS_IS_PRESSED) { @@ -4543,9 +4543,9 @@ void G_HandleLocalKeys(void) G_UpdateScreenArea(); } - if (inputState.BUTTON(gamefunc_Shrink_Screen)) + if (buttonMap.ButtonDown(gamefunc_Shrink_Screen)) { - inputState.ClearButton(gamefunc_Shrink_Screen); + buttonMap.ClearButton(gamefunc_Shrink_Screen); if (!SHIFTS_IS_PRESSED) { @@ -4566,31 +4566,31 @@ void G_HandleLocalKeys(void) if (myplayer.cheat_phase == 1 || (myplayer.gm & (MODE_MENU|MODE_TYPE))) return; - if (inputState.BUTTON(gamefunc_See_Coop_View) && (GTFLAGS(GAMETYPE_COOPVIEW) || ud.recstat == 2)) + if (buttonMap.ButtonDown(gamefunc_See_Coop_View) && (GTFLAGS(GAMETYPE_COOPVIEW) || ud.recstat == 2)) { - inputState.ClearButton(gamefunc_See_Coop_View); + buttonMap.ClearButton(gamefunc_See_Coop_View); screenpeek = connectpoint2[screenpeek]; if (screenpeek == -1) screenpeek = 0; g_restorePalette = -1; } - if ((g_netServer || ud.multimode > 1) && inputState.BUTTON(gamefunc_Show_Opponents_Weapon)) + if ((g_netServer || ud.multimode > 1) && buttonMap.ButtonDown(gamefunc_Show_Opponents_Weapon)) { - inputState.ClearButton(gamefunc_Show_Opponents_Weapon); + buttonMap.ClearButton(gamefunc_Show_Opponents_Weapon); ud.config.ShowWeapons = ud.showweapons = 1-ud.showweapons; P_DoQuote(QUOTE_WEAPON_MODE_OFF-ud.showweapons, &myplayer); } - if (inputState.BUTTON(gamefunc_Toggle_Crosshair)) + if (buttonMap.ButtonDown(gamefunc_Toggle_Crosshair)) { - inputState.ClearButton(gamefunc_Toggle_Crosshair); + buttonMap.ClearButton(gamefunc_Toggle_Crosshair); cl_crosshair = !cl_crosshair; P_DoQuote(QUOTE_CROSSHAIR_OFF-cl_crosshair, &myplayer); } - if (ud.overhead_on && inputState.BUTTON(gamefunc_Map_Follow_Mode)) + if (ud.overhead_on && buttonMap.ButtonDown(gamefunc_Map_Follow_Mode)) { - inputState.ClearButton(gamefunc_Map_Follow_Mode); + buttonMap.ClearButton(gamefunc_Map_Follow_Mode); ud.scrollmode = 1-ud.scrollmode; if (ud.scrollmode) { @@ -4739,10 +4739,10 @@ void G_HandleLocalKeys(void) if (!ALT_IS_PRESSED && !SHIFTS_IS_PRESSED && !WIN_IS_PRESSED) { - if ((g_netServer || ud.multimode > 1) && inputState.BUTTON(gamefunc_SendMessage)) + if ((g_netServer || ud.multimode > 1) && buttonMap.ButtonDown(gamefunc_SendMessage)) { inputState.keyFlushChars(); - inputState.ClearButton(gamefunc_SendMessage); + buttonMap.ClearButton(gamefunc_SendMessage); myplayer.gm |= MODE_TYPE; typebuf[0] = 0; } @@ -4839,9 +4839,9 @@ FAKE_F3: P_DoQuote(QUOTE_MUSIC, g_player[myconnectindex].ps); } - if ((inputState.BUTTON(gamefunc_Quick_Save) || g_doQuickSave == 1) && (myplayer.gm & MODE_GAME)) + if ((buttonMap.ButtonDown(gamefunc_Quick_Save) || g_doQuickSave == 1) && (myplayer.gm & MODE_GAME)) { - inputState.ClearButton(gamefunc_Quick_Save); + buttonMap.ClearButton(gamefunc_Quick_Save); g_doQuickSave = 0; @@ -4876,9 +4876,9 @@ FAKE_F3: } } - if (inputState.BUTTON(gamefunc_Third_Person_View)) + if (buttonMap.ButtonDown(gamefunc_Third_Person_View)) { - inputState.ClearButton(gamefunc_Third_Person_View); + buttonMap.ClearButton(gamefunc_Third_Person_View); myplayer.over_shoulder_on = !myplayer.over_shoulder_on; @@ -4898,9 +4898,9 @@ FAKE_F3: ud.fta_on = fta; } - if ((inputState.BUTTON(gamefunc_Quick_Load) || g_doQuickSave == 2) && (myplayer.gm & MODE_GAME)) + if ((buttonMap.ButtonDown(gamefunc_Quick_Load) || g_doQuickSave == 2) && (myplayer.gm & MODE_GAME)) { - inputState.ClearButton(gamefunc_Quick_Load); + buttonMap.ClearButton(gamefunc_Quick_Load); g_doQuickSave = 0; @@ -4951,10 +4951,10 @@ FAKE_F3: int const timerOffset = ((int) totalclock - nonsharedtimer); nonsharedtimer += timerOffset; - if (inputState.BUTTON(gamefunc_Enlarge_Screen)) + if (buttonMap.ButtonDown(gamefunc_Enlarge_Screen)) myplayer.zoom += mulscale6(timerOffset, max(myplayer.zoom, 256)); - if (inputState.BUTTON(gamefunc_Shrink_Screen)) + if (buttonMap.ButtonDown(gamefunc_Shrink_Screen)) myplayer.zoom -= mulscale6(timerOffset, max(myplayer.zoom, 256)); myplayer.zoom = clamp(myplayer.zoom, 48, 2048); @@ -4970,16 +4970,16 @@ FAKE_F3: G_UpdateScreenArea(); } - if (inputState.BUTTON(gamefunc_AutoRun)) + if (buttonMap.ButtonDown(gamefunc_AutoRun)) { - inputState.ClearButton(gamefunc_AutoRun); + buttonMap.ClearButton(gamefunc_AutoRun); cl_autorun= 1-cl_autorun; P_DoQuote(QUOTE_RUN_MODE_OFF + cl_autorun, &myplayer); } - if (inputState.BUTTON(gamefunc_Map)) + if (buttonMap.ButtonDown(gamefunc_Map)) { - inputState.ClearButton(gamefunc_Map); + buttonMap.ClearButton(gamefunc_Map); if (ud.last_overhead != ud.overhead_on && ud.last_overhead) { ud.overhead_on = ud.last_overhead; diff --git a/source/duke3d/src/gamedef.cpp b/source/duke3d/src/gamedef.cpp index 9bf56cdf0..3b6ba716b 100644 --- a/source/duke3d/src/gamedef.cpp +++ b/source/duke3d/src/gamedef.cpp @@ -2198,7 +2198,7 @@ void C_InitQuotes(void) apStrings[QUOTE_DEAD] = 0; #else // WTF ?!? - char const * const OpenGameFunc = CONFIG_FunctionNumToName(gamefunc_Open); + char const * const OpenGameFunc = buttonMap.GetButtonName(gamefunc_Open); C_ReplaceQuoteSubstring(QUOTE_DEAD, "SPACE", OpenGameFunc); C_ReplaceQuoteSubstring(QUOTE_DEAD, "OPEN", OpenGameFunc); C_ReplaceQuoteSubstring(QUOTE_DEAD, "USE", OpenGameFunc); @@ -5090,7 +5090,7 @@ repeatcase: } } build.Push(0); - CONFIG_ReplaceButtonName(j, build.Data()); + buttonMap.SetButtonAlias(j, build.Data()); } continue; @@ -5109,7 +5109,7 @@ repeatcase: continue; } - CONFIG_DeleteButtonName(j); + buttonMap.ClearButtonAlias(j); continue; case CON_DEFINESKILLNAME: diff --git a/source/duke3d/src/gameexec.cpp b/source/duke3d/src/gameexec.cpp index d47f1f24a..3492f4f12 100644 --- a/source/duke3d/src/gameexec.cpp +++ b/source/duke3d/src/gameexec.cpp @@ -3656,7 +3656,7 @@ badindex: VM_ASSERT((unsigned)quoteIndex < MAXQUOTES && apStrings[quoteIndex], "invalid quote %d\n", quoteIndex); VM_ASSERT((unsigned)gameFunc < NUMGAMEFUNCTIONS, "invalid function %d\n", gameFunc); - auto bindings = Bindings.GetKeysForCommand(CONFIG_FunctionNumToRealName(gameFunc)); + auto bindings = Bindings.GetKeysForCommand(buttonMap.GetButtonAlias(gameFunc)); if ((unsigned)funcPos >= bindings.Size()) funcPos = 0; Bstrcpy(apStrings[quoteIndex], KB_ScanCodeToString(bindings[funcPos])); dispatch(); diff --git a/source/duke3d/src/menus.cpp b/source/duke3d/src/menus.cpp index b4aa013fc..1c631fe18 100644 --- a/source/duke3d/src/menus.cpp +++ b/source/duke3d/src/menus.cpp @@ -1643,7 +1643,7 @@ void Menu_Init(void) k = 1; for (i = 0; i < NUMGAMEFUNCTIONS; ++i) { - MenuGameFuncs[i] = CONFIG_FunctionNumToName(i); + MenuGameFuncs[i] = buttonMap.GetButtonName(i); MenuGameFuncs[i].Substitute('_', ' '); if (MenuGameFuncs[i][0] != '\0') @@ -1836,7 +1836,8 @@ void Menu_Init(void) ME_MOUSESETUPBTNS[i].name = MenuMouseNames[i]; ME_MOUSESETUPBTNS[i].entry = &MEO_MOUSESETUPBTNS[i]; MEO_MOUSESETUPBTNS[i] = MEO_MOUSEJOYSETUPBTNS_TEMPLATE; - MEO_MOUSESETUPBTNS[i].data = &MouseFunctions[MenuMouseDataIndex[i][0]][MenuMouseDataIndex[i][1]]; + static int32_t sink; + MEO_MOUSESETUPBTNS[i].data = &sink; } for (i = 0; i < 2*joystick.numButtons + 8*joystick.numHats; ++i) { @@ -2863,7 +2864,7 @@ static void Menu_PreInput(MenuEntry_t *entry) case MENU_KEYBOARDKEYS: if (inputState.GetKeyStatus(sc_Delete)) { - Bindings.UnbindACommand(CONFIG_FunctionNumToName(M_KEYBOARDKEYS.currentEntry)); + Bindings.UnbindACommand(buttonMap.GetButtonName(M_KEYBOARDKEYS.currentEntry)); S_PlaySound(KICK_HIT); inputState.ClearKeyStatus(sc_Delete); } @@ -2920,7 +2921,7 @@ static int32_t Menu_PreCustom2ColScreen(MenuEntry_t *entry) if (sc != sc_None) { S_PlaySound(PISTOL_BODYHIT); - Bindings.SetBind(sc, CONFIG_FunctionNumToName(M_KEYBOARDKEYS.currentEntry)); + Bindings.SetBind(sc, buttonMap.GetButtonName(M_KEYBOARDKEYS.currentEntry)); inputState.ClearKeyStatus(sc); return -1; @@ -4884,7 +4885,7 @@ static int32_t M_RunMenu_Menu(Menu_t *cm, MenuMenu_t *menu, MenuEntry_t *current const int32_t columny = origin.y + y_upper + y - menu->scrollPos; // Beware of hack job! - auto keys = Bindings.GetKeysForCommand(CONFIG_FunctionNumToName(object->buttonindex)); + auto keys = Bindings.GetKeysForCommand(buttonMap.GetButtonName(object->buttonindex)); FString text1; FString text2; if (keys.Size() > 0) text1 = C_NameKeys(&keys[0], 1); diff --git a/source/duke3d/src/player.cpp b/source/duke3d/src/player.cpp index 4af5cbbb4..88d7ae4b4 100644 --- a/source/duke3d/src/player.cpp +++ b/source/duke3d/src/player.cpp @@ -2910,11 +2910,11 @@ void P_GetInput(int const playerNum) D_ProcessEvents(); if (in_aimmode) - g_MyAimMode = inputState.BUTTON(gamefunc_Mouse_Aiming); + g_MyAimMode = buttonMap.ButtonDown(gamefunc_Mouse_Aiming); else { g_oldAimStat = g_myAimStat; - g_myAimStat = inputState.BUTTON(gamefunc_Mouse_Aiming); + g_myAimStat = buttonMap.ButtonDown(gamefunc_Mouse_Aiming); if (g_myAimStat > g_oldAimStat) { @@ -2947,7 +2947,7 @@ void P_GetInput(int const playerNum) } // JBF: Run key behaviour is selectable - int const playerRunning = G_CheckAutorun(inputState.BUTTON(gamefunc_Run)); + int const playerRunning = G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run)); int const turnAmount = playerRunning ? (NORMALTURN << 1) : NORMALTURN; constexpr int const analogTurnAmount = (NORMALTURN << 1); int const keyMove = playerRunning ? (NORMALKEYMOVE << 1) : NORMALKEYMOVE; @@ -2955,7 +2955,7 @@ void P_GetInput(int const playerNum) input_t input {}; - if (inputState.BUTTON(gamefunc_Strafe)) + if (buttonMap.ButtonDown(gamefunc_Strafe)) { static int strafeyaw; @@ -2981,12 +2981,12 @@ void P_GetInput(int const playerNum) input.svel -= info.dx * keyMove / analogExtent; input.fvel -= info.dz * keyMove / analogExtent; - if (inputState.BUTTON(gamefunc_Strafe)) + if (buttonMap.ButtonDown(gamefunc_Strafe)) { - if (inputState.BUTTON(gamefunc_Turn_Left) && !(pPlayer->movement_lock&4)) + if (buttonMap.ButtonDown(gamefunc_Turn_Left) && !(pPlayer->movement_lock&4)) input.svel -= -keyMove; - if (inputState.BUTTON(gamefunc_Turn_Right) && !(pPlayer->movement_lock&8)) + if (buttonMap.ButtonDown(gamefunc_Turn_Right) && !(pPlayer->movement_lock&8)) input.svel -= keyMove; } else @@ -2997,12 +2997,12 @@ void P_GetInput(int const playerNum) lastInputClock = (int32_t) totalclock; - if (inputState.BUTTON(gamefunc_Turn_Left)) + if (buttonMap.ButtonDown(gamefunc_Turn_Left)) { turnHeldTime += elapsedTics; input.q16avel -= fix16_from_int((turnHeldTime >= TURBOTURNTIME) ? (turnAmount << 1) : (PREAMBLETURN << 1)); } - else if (inputState.BUTTON(gamefunc_Turn_Right)) + else if (buttonMap.ButtonDown(gamefunc_Turn_Right)) { turnHeldTime += elapsedTics; input.q16avel += fix16_from_int((turnHeldTime >= TURBOTURNTIME) ? (turnAmount << 1) : (PREAMBLETURN << 1)); @@ -3011,16 +3011,16 @@ void P_GetInput(int const playerNum) turnHeldTime=0; } - if (inputState.BUTTON(gamefunc_Strafe_Left) && !(pPlayer->movement_lock & 4)) + if (buttonMap.ButtonDown(gamefunc_Strafe_Left) && !(pPlayer->movement_lock & 4)) input.svel += keyMove; - if (inputState.BUTTON(gamefunc_Strafe_Right) && !(pPlayer->movement_lock & 8)) + if (buttonMap.ButtonDown(gamefunc_Strafe_Right) && !(pPlayer->movement_lock & 8)) input.svel += -keyMove; - if (inputState.BUTTON(gamefunc_Move_Forward) && !(pPlayer->movement_lock & 1)) + if (buttonMap.ButtonDown(gamefunc_Move_Forward) && !(pPlayer->movement_lock & 1)) input.fvel += keyMove; - if (inputState.BUTTON(gamefunc_Move_Backward) && !(pPlayer->movement_lock & 2)) + if (buttonMap.ButtonDown(gamefunc_Move_Backward) && !(pPlayer->movement_lock & 2)) input.fvel += -keyMove; input.fvel = clamp(input.fvel, -MAXVEL, MAXVEL); @@ -3033,90 +3033,90 @@ void P_GetInput(int const playerNum) for (weaponSelection = gamefunc_Weapon_10; weaponSelection >= gamefunc_Weapon_1; --weaponSelection) { - if (inputState.BUTTON(weaponSelection)) + if (buttonMap.ButtonDown(weaponSelection)) { weaponSelection -= (gamefunc_Weapon_1 - 1); break; } } - if (inputState.BUTTON(gamefunc_Last_Weapon)) + if (buttonMap.ButtonDown(gamefunc_Last_Weapon)) weaponSelection = 14; - else if (inputState.BUTTON(gamefunc_Alt_Weapon)) + else if (buttonMap.ButtonDown(gamefunc_Alt_Weapon)) weaponSelection = 13; - else if (inputState.BUTTON(gamefunc_Next_Weapon) || (inputState.BUTTON(gamefunc_Dpad_Select) && input.fvel > 0)) + else if (buttonMap.ButtonDown(gamefunc_Next_Weapon) || (buttonMap.ButtonDown(gamefunc_Dpad_Select) && input.fvel > 0)) weaponSelection = 12; - else if (inputState.BUTTON(gamefunc_Previous_Weapon) || (inputState.BUTTON(gamefunc_Dpad_Select) && input.fvel < 0)) + else if (buttonMap.ButtonDown(gamefunc_Previous_Weapon) || (buttonMap.ButtonDown(gamefunc_Dpad_Select) && input.fvel < 0)) weaponSelection = 11; else if (weaponSelection == gamefunc_Weapon_1-1) weaponSelection = 0; - localInput.bits = (weaponSelection << SK_WEAPON_BITS) | (inputState.BUTTON(gamefunc_Fire) << SK_FIRE); - localInput.bits |= (inputState.BUTTON(gamefunc_Open) << SK_OPEN); + localInput.bits = (weaponSelection << SK_WEAPON_BITS) | (buttonMap.ButtonDown(gamefunc_Fire) << SK_FIRE); + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Open) << SK_OPEN); int const sectorLotag = pPlayer->cursectnum != -1 ? sector[pPlayer->cursectnum].lotag : 0; int const crouchable = sectorLotag != 2 && (sectorLotag != 1 || pPlayer->spritebridge); - if (pPlayer->cheat_phase == 0 && inputState.BUTTON(gamefunc_Toggle_Crouch)) + if (pPlayer->cheat_phase == 0 && buttonMap.ButtonDown(gamefunc_Toggle_Crouch)) { pPlayer->crouch_toggle = !pPlayer->crouch_toggle && crouchable; if (crouchable) - inputState.ClearButton(gamefunc_Toggle_Crouch); + buttonMap.ClearButton(gamefunc_Toggle_Crouch); } - if (inputState.BUTTON(gamefunc_Crouch) || inputState.BUTTON(gamefunc_Jump) || pPlayer->jetpack_on || (!crouchable && pPlayer->on_ground)) + if (buttonMap.ButtonDown(gamefunc_Crouch) || buttonMap.ButtonDown(gamefunc_Jump) || pPlayer->jetpack_on || (!crouchable && pPlayer->on_ground)) pPlayer->crouch_toggle = 0; - int const crouching = inputState.BUTTON(gamefunc_Crouch) || inputState.BUTTON(gamefunc_Toggle_Crouch) || pPlayer->crouch_toggle; + int const crouching = buttonMap.ButtonDown(gamefunc_Crouch) || buttonMap.ButtonDown(gamefunc_Toggle_Crouch) || pPlayer->crouch_toggle; - localInput.bits |= (inputState.BUTTON(gamefunc_Jump) << SK_JUMP) | (crouching << SK_CROUCH); + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Jump) << SK_JUMP) | (crouching << SK_CROUCH); - localInput.bits |= (inputState.BUTTON(gamefunc_Aim_Up) || (inputState.BUTTON(gamefunc_Dpad_Aiming) && input.fvel > 0)) << SK_AIM_UP; - localInput.bits |= (inputState.BUTTON(gamefunc_Aim_Down) || (inputState.BUTTON(gamefunc_Dpad_Aiming) && input.fvel < 0)) << SK_AIM_DOWN; - localInput.bits |= (inputState.BUTTON(gamefunc_Center_View) << SK_CENTER_VIEW); + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Aim_Up) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && input.fvel > 0)) << SK_AIM_UP; + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Aim_Down) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && input.fvel < 0)) << SK_AIM_DOWN; + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Center_View) << SK_CENTER_VIEW); - localInput.bits |= (inputState.BUTTON(gamefunc_Look_Left) << SK_LOOK_LEFT) | (inputState.BUTTON(gamefunc_Look_Right) << SK_LOOK_RIGHT); - localInput.bits |= (inputState.BUTTON(gamefunc_Look_Up) << SK_LOOK_UP) | (inputState.BUTTON(gamefunc_Look_Down) << SK_LOOK_DOWN); + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Look_Left) << SK_LOOK_LEFT) | (buttonMap.ButtonDown(gamefunc_Look_Right) << SK_LOOK_RIGHT); + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Look_Up) << SK_LOOK_UP) | (buttonMap.ButtonDown(gamefunc_Look_Down) << SK_LOOK_DOWN); localInput.bits |= (playerRunning << SK_RUN); - localInput.bits |= (inputState.BUTTON(gamefunc_Inventory_Left) || (inputState.BUTTON(gamefunc_Dpad_Select) && (input.svel > 0 || input.q16avel < 0))) << SK_INV_LEFT; - localInput.bits |= (inputState.BUTTON(gamefunc_Inventory_Right) || (inputState.BUTTON(gamefunc_Dpad_Select) && (input.svel < 0 || input.q16avel > 0))) << SK_INV_RIGHT; - localInput.bits |= (inputState.BUTTON(gamefunc_Inventory) << SK_INVENTORY); + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Inventory_Left) || (buttonMap.ButtonDown(gamefunc_Dpad_Select) && (input.svel > 0 || input.q16avel < 0))) << SK_INV_LEFT; + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Inventory_Right) || (buttonMap.ButtonDown(gamefunc_Dpad_Select) && (input.svel < 0 || input.q16avel > 0))) << SK_INV_RIGHT; + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Inventory) << SK_INVENTORY); - localInput.bits |= (inputState.BUTTON(gamefunc_Steroids) << SK_STEROIDS) | (inputState.BUTTON(gamefunc_NightVision) << SK_NIGHTVISION); - localInput.bits |= (inputState.BUTTON(gamefunc_MedKit) << SK_MEDKIT) | (inputState.BUTTON(gamefunc_Holo_Duke) << SK_HOLODUKE); - localInput.bits |= (inputState.BUTTON(gamefunc_Jetpack) << SK_JETPACK); + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Steroids) << SK_STEROIDS) | (buttonMap.ButtonDown(gamefunc_NightVision) << SK_NIGHTVISION); + localInput.bits |= (buttonMap.ButtonDown(gamefunc_MedKit) << SK_MEDKIT) | (buttonMap.ButtonDown(gamefunc_Holo_Duke) << SK_HOLODUKE); + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Jetpack) << SK_JETPACK); - localInput.bits |= inputState.BUTTON(gamefunc_Holster_Weapon) << SK_HOLSTER; - localInput.bits |= inputState.BUTTON(gamefunc_Quick_Kick) << SK_QUICK_KICK; - localInput.bits |= inputState.BUTTON(gamefunc_TurnAround) << SK_TURNAROUND; + localInput.bits |= buttonMap.ButtonDown(gamefunc_Holster_Weapon) << SK_HOLSTER; + localInput.bits |= buttonMap.ButtonDown(gamefunc_Quick_Kick) << SK_QUICK_KICK; + localInput.bits |= buttonMap.ButtonDown(gamefunc_TurnAround) << SK_TURNAROUND; localInput.bits |= (g_MyAimMode << SK_AIMMODE); localInput.bits |= (g_gameQuit << SK_GAMEQUIT); localInput.bits |= inputState.GetKeyStatus(sc_Pause) << SK_PAUSE; localInput.bits |= ((uint32_t)inputState.GetKeyStatus(sc_Escape)) << SK_ESCAPE; - if (inputState.BUTTON(gamefunc_Dpad_Select)) + if (buttonMap.ButtonDown(gamefunc_Dpad_Select)) { input.fvel = 0; input.svel = 0; input.q16avel = 0; } - else if (inputState.BUTTON(gamefunc_Dpad_Aiming)) + else if (buttonMap.ButtonDown(gamefunc_Dpad_Aiming)) input.fvel = 0; - if (PWEAPON(playerNum, pPlayer->curr_weapon, Flags) & WEAPON_SEMIAUTO && inputState.BUTTON(gamefunc_Fire)) - inputState.ClearButton(gamefunc_Fire); + if (PWEAPON(playerNum, pPlayer->curr_weapon, Flags) & WEAPON_SEMIAUTO && buttonMap.ButtonDown(gamefunc_Fire)) + buttonMap.ClearButton(gamefunc_Fire); - localInput.extbits = (inputState.BUTTON(gamefunc_Move_Forward) || (input.fvel > 0)); - localInput.extbits |= (inputState.BUTTON(gamefunc_Move_Backward) || (input.fvel < 0)) << 1; - localInput.extbits |= (inputState.BUTTON(gamefunc_Strafe_Left) || (input.svel > 0)) << 2; - localInput.extbits |= (inputState.BUTTON(gamefunc_Strafe_Right) || (input.svel < 0)) << 3; - localInput.extbits |= inputState.BUTTON(gamefunc_Turn_Left)<<4; - localInput.extbits |= inputState.BUTTON(gamefunc_Turn_Right)<<5; - localInput.extbits |= inputState.BUTTON(gamefunc_Alt_Fire)<<6; + localInput.extbits = (buttonMap.ButtonDown(gamefunc_Move_Forward) || (input.fvel > 0)); + localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Move_Backward) || (input.fvel < 0)) << 1; + localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Strafe_Left) || (input.svel > 0)) << 2; + localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Strafe_Right) || (input.svel < 0)) << 3; + localInput.extbits |= buttonMap.ButtonDown(gamefunc_Turn_Left)<<4; + localInput.extbits |= buttonMap.ButtonDown(gamefunc_Turn_Right)<<5; + localInput.extbits |= buttonMap.ButtonDown(gamefunc_Alt_Fire)<<6; if (ud.scrollmode && ud.overhead_on) { @@ -5144,7 +5144,7 @@ void P_ProcessInput(int playerNum) pPlayer->jumping_toggle = 2; if (myconnectindex == playerNum) - inputState.ClearButton(gamefunc_Jump); + buttonMap.ClearButton(gamefunc_Jump); } } } diff --git a/source/duke3d/src/screens.cpp b/source/duke3d/src/screens.cpp index 2628bb928..c4bbd8275 100644 --- a/source/duke3d/src/screens.cpp +++ b/source/duke3d/src/screens.cpp @@ -1210,7 +1210,7 @@ void G_DisplayRest(int32_t smoothratio) gametext_center(70, "Press F1 to Accept, F2 to Decline"); } - if (inputState.BUTTON(gamefunc_Show_DukeMatch_Scores)) + if (buttonMap.ButtonDown(gamefunc_Show_DukeMatch_Scores)) G_ShowScores(); if (g_Debug) diff --git a/source/mact/src/control.cpp b/source/mact/src/control.cpp index 0703546ed..959b285ff 100644 --- a/source/mact/src/control.cpp +++ b/source/mact/src/control.cpp @@ -590,8 +590,6 @@ static void CONTROL_GetFunctionInput(void) { CONTROL_ButtonFunctionState(CONTROL_ButtonFlags); CONTROL_AxisFunctionState(CONTROL_ButtonFlags); - - memset(CONTROL_ButtonFlags, 0, sizeof(CONTROL_ButtonFlags)); } void CONTROL_GetInput(ControlInfo *info) diff --git a/source/mact/src/input.cpp b/source/mact/src/input.cpp index 10183a245..ff53535fa 100644 --- a/source/mact/src/input.cpp +++ b/source/mact/src/input.cpp @@ -45,7 +45,7 @@ void I_ClearAllInput(void) inputState.ClearKeysDown(); inputState.MouseClearAllButtonss(); JOYSTICK_ClearAllButtons(); - inputState.ClearAllButtons(); + buttonMap.ResetButtonStates(); } @@ -101,9 +101,9 @@ int32_t I_GeneralTrigger(void) return I_AdvanceTrigger() || I_ReturnTrigger() - || inputState.BUTTON(gamefunc_Open) - //|| MOUSEINACTIVECONDITIONAL(inputState.BUTTON(gamefunc_Fire)) - || inputState.BUTTON(gamefunc_Crouch) + || buttonMap.ButtonDown(gamefunc_Open) + //|| MOUSEINACTIVECONDITIONAL(buttonMap.ButtonDown(gamefunc_Fire)) + || buttonMap.ButtonDown(gamefunc_Crouch) || (JOYSTICK_GetGameControllerButtons()&(1<gm = MODE_TYPE; typebuf[0] = 0; } diff --git a/source/rr/src/game.cpp b/source/rr/src/game.cpp index b27abf05c..1ad8508ee 100644 --- a/source/rr/src/game.cpp +++ b/source/rr/src/game.cpp @@ -6045,9 +6045,9 @@ void G_HandleLocalKeys(void) if (!ALT_IS_PRESSED && ud.overhead_on == 0 && (g_player[myconnectindex].ps->gm & MODE_TYPE) == 0) { - if (inputState.BUTTON(gamefunc_Enlarge_Screen)) + if (buttonMap.ButtonDown(gamefunc_Enlarge_Screen)) { - inputState.ClearButton(gamefunc_Enlarge_Screen); + buttonMap.ClearButton(gamefunc_Enlarge_Screen); if (!SHIFTS_IS_PRESSED) { @@ -6064,9 +6064,9 @@ void G_HandleLocalKeys(void) G_UpdateScreenArea(); } - if (inputState.BUTTON(gamefunc_Shrink_Screen)) + if (buttonMap.ButtonDown(gamefunc_Shrink_Screen)) { - inputState.ClearButton(gamefunc_Shrink_Screen); + buttonMap.ClearButton(gamefunc_Shrink_Screen); if (!SHIFTS_IS_PRESSED) { @@ -6087,31 +6087,31 @@ void G_HandleLocalKeys(void) if (g_player[myconnectindex].ps->cheat_phase == 1 || (g_player[myconnectindex].ps->gm&(MODE_MENU|MODE_TYPE))) return; - if (inputState.BUTTON(gamefunc_See_Coop_View) && (GTFLAGS(GAMETYPE_COOPVIEW) || ud.recstat == 2)) + if (buttonMap.ButtonDown(gamefunc_See_Coop_View) && (GTFLAGS(GAMETYPE_COOPVIEW) || ud.recstat == 2)) { - inputState.ClearButton(gamefunc_See_Coop_View); + buttonMap.ClearButton(gamefunc_See_Coop_View); screenpeek = connectpoint2[screenpeek]; if (screenpeek == -1) screenpeek = 0; g_restorePalette = -1; } - if ((g_netServer || ud.multimode > 1) && inputState.BUTTON(gamefunc_Show_Opponents_Weapon)) + if ((g_netServer || ud.multimode > 1) && buttonMap.ButtonDown(gamefunc_Show_Opponents_Weapon)) { - inputState.ClearButton(gamefunc_Show_Opponents_Weapon); + buttonMap.ClearButton(gamefunc_Show_Opponents_Weapon); ud.config.ShowOpponentWeapons = ud.showweapons = 1-ud.showweapons; P_DoQuote(QUOTE_WEAPON_MODE_OFF-ud.showweapons,g_player[screenpeek].ps); } - if (inputState.BUTTON(gamefunc_Toggle_Crosshair)) + if (buttonMap.ButtonDown(gamefunc_Toggle_Crosshair)) { - inputState.ClearButton(gamefunc_Toggle_Crosshair); + buttonMap.ClearButton(gamefunc_Toggle_Crosshair); cl_crosshair = !cl_crosshair; P_DoQuote(QUOTE_CROSSHAIR_OFF-cl_crosshair,g_player[screenpeek].ps); } - if (ud.overhead_on && inputState.BUTTON(gamefunc_Map_Follow_Mode)) + if (ud.overhead_on && buttonMap.ButtonDown(gamefunc_Map_Follow_Mode)) { - inputState.ClearButton(gamefunc_Map_Follow_Mode); + buttonMap.ClearButton(gamefunc_Map_Follow_Mode); ud.scrollmode = 1-ud.scrollmode; if (ud.scrollmode) { @@ -6257,10 +6257,10 @@ void G_HandleLocalKeys(void) if (!ALT_IS_PRESSED && !SHIFTS_IS_PRESSED && !WIN_IS_PRESSED) { - if ((g_netServer || ud.multimode > 1) && inputState.BUTTON(gamefunc_SendMessage)) + if ((g_netServer || ud.multimode > 1) && buttonMap.ButtonDown(gamefunc_SendMessage)) { inputState.keyFlushChars(); - inputState.ClearButton(gamefunc_SendMessage); + buttonMap.ClearButton(gamefunc_SendMessage); g_player[myconnectindex].ps->gm |= MODE_TYPE; typebuf[0] = 0; } @@ -6357,9 +6357,9 @@ FAKE_F3: P_DoQuote(QUOTE_MUSIC, g_player[myconnectindex].ps); } - if ((inputState.BUTTON(gamefunc_Quick_Save) || g_doQuickSave == 1) && (!RRRA || ud.player_skill != 4) && (!RR || RRRA || ud.player_skill != 5) && (g_player[myconnectindex].ps->gm&MODE_GAME)) + if ((buttonMap.ButtonDown(gamefunc_Quick_Save) || g_doQuickSave == 1) && (!RRRA || ud.player_skill != 4) && (!RR || RRRA || ud.player_skill != 5) && (g_player[myconnectindex].ps->gm&MODE_GAME)) { - inputState.ClearButton(gamefunc_Quick_Save); + buttonMap.ClearButton(gamefunc_Quick_Save); g_doQuickSave = 0; @@ -6394,9 +6394,9 @@ FAKE_F3: } } - if (inputState.BUTTON(gamefunc_Third_Person_View)) + if (buttonMap.ButtonDown(gamefunc_Third_Person_View)) { - inputState.ClearButton(gamefunc_Third_Person_View); + buttonMap.ClearButton(gamefunc_Third_Person_View); if (!RRRA || (!g_player[myconnectindex].ps->on_motorcycle && !g_player[myconnectindex].ps->on_boat)) { @@ -6419,9 +6419,9 @@ FAKE_F3: ud.fta_on = fta; } - if ((inputState.BUTTON(gamefunc_Quick_Load) || g_doQuickSave == 2) && (!RRRA || ud.player_skill != 4) && (!RR || RRRA || ud.player_skill != 5) && (g_player[myconnectindex].ps->gm&MODE_GAME)) + if ((buttonMap.ButtonDown(gamefunc_Quick_Load) || g_doQuickSave == 2) && (!RRRA || ud.player_skill != 4) && (!RR || RRRA || ud.player_skill != 5) && (g_player[myconnectindex].ps->gm&MODE_GAME)) { - inputState.ClearButton(gamefunc_Quick_Load); + buttonMap.ClearButton(gamefunc_Quick_Load); g_doQuickSave = 0; @@ -6472,10 +6472,10 @@ FAKE_F3: int const timerOffset = ((int) totalclock - nonsharedtimer); nonsharedtimer += timerOffset; - if (inputState.BUTTON(gamefunc_Enlarge_Screen)) + if (buttonMap.ButtonDown(gamefunc_Enlarge_Screen)) g_player[myconnectindex].ps->zoom += mulscale6(timerOffset, max(g_player[myconnectindex].ps->zoom, 256)); - if (inputState.BUTTON(gamefunc_Shrink_Screen)) + if (buttonMap.ButtonDown(gamefunc_Shrink_Screen)) g_player[myconnectindex].ps->zoom -= mulscale6(timerOffset, max(g_player[myconnectindex].ps->zoom, 256)); g_player[myconnectindex].ps->zoom = clamp(g_player[myconnectindex].ps->zoom, 48, 2048); @@ -6491,16 +6491,16 @@ FAKE_F3: G_UpdateScreenArea(); } - if (inputState.BUTTON(gamefunc_AutoRun)) + if (buttonMap.ButtonDown(gamefunc_AutoRun)) { - inputState.ClearButton(gamefunc_AutoRun); + buttonMap.ClearButton(gamefunc_AutoRun); cl_autorun = !cl_autorun; P_DoQuote(QUOTE_RUN_MODE_OFF+cl_autorun,g_player[myconnectindex].ps); } - if (inputState.BUTTON(gamefunc_Map)) + if (buttonMap.ButtonDown(gamefunc_Map)) { - inputState.ClearButton(gamefunc_Map); + buttonMap.ClearButton(gamefunc_Map); if (ud.last_overhead != ud.overhead_on && ud.last_overhead) { ud.overhead_on = ud.last_overhead; diff --git a/source/rr/src/gamedef.cpp b/source/rr/src/gamedef.cpp index 9fe518009..992076693 100644 --- a/source/rr/src/gamedef.cpp +++ b/source/rr/src/gamedef.cpp @@ -935,7 +935,7 @@ void C_InitQuotes(void) #ifdef EDUKE32_TOUCH_DEVICES apStrings[QUOTE_DEAD] = 0; #else - char const * OpenGameFunc = CONFIG_FunctionNumToName(gamefunc_Open); + char const * OpenGameFunc = buttonMap.GetButtonName(gamefunc_Open); C_ReplaceQuoteSubstring(QUOTE_DEAD, "SPACE", OpenGameFunc); C_ReplaceQuoteSubstring(QUOTE_DEAD, "OPEN", OpenGameFunc); C_ReplaceQuoteSubstring(QUOTE_DEAD, "USE", OpenGameFunc); diff --git a/source/rr/src/menus.cpp b/source/rr/src/menus.cpp index d5018b6df..dab13bd4e 100644 --- a/source/rr/src/menus.cpp +++ b/source/rr/src/menus.cpp @@ -1568,7 +1568,7 @@ void Menu_Init(void) k = 1; for (i = 0; i < NUMGAMEFUNCTIONS; ++i) { - MenuGameFuncs[i] = CONFIG_FunctionNumToName(i); + MenuGameFuncs[i] = buttonMap.GetButtonName(i); MenuGameFuncs[i].Substitute('_', ' '); } if (RR) @@ -1715,8 +1715,9 @@ void Menu_Init(void) ME_MOUSESETUPBTNS[i].name = MenuMouseNames[i]; ME_MOUSESETUPBTNS[i].entry = &MEO_MOUSESETUPBTNS[i]; MEO_MOUSESETUPBTNS[i] = MEO_MOUSEJOYSETUPBTNS_TEMPLATE; - MEO_MOUSESETUPBTNS[i].data = &MouseFunctions[MenuMouseDataIndex[i][0]][MenuMouseDataIndex[i][1]]; - } + static int32_t sink; + MEO_MOUSESETUPBTNS[i].data = &sink; + } for (i = 0; i < 2*joystick.numButtons + 8*joystick.numHats; ++i) { if (i < 2*joystick.numButtons) @@ -3225,7 +3226,7 @@ static void Menu_PreInput(MenuEntry_t *entry) case MENU_KEYBOARDKEYS: if (inputState.GetKeyStatus(sc_Delete)) { - Bindings.UnbindACommand(CONFIG_FunctionNumToName(M_KEYBOARDKEYS.currentEntry)); + Bindings.UnbindACommand(buttonMap.GetButtonName(M_KEYBOARDKEYS.currentEntry)); S_PlaySound(RR ? 335 : KICK_HIT); inputState.ClearKeyStatus(sc_Delete); } @@ -3283,7 +3284,7 @@ static int32_t Menu_PreCustom2ColScreen(MenuEntry_t *entry) { S_PlaySound(PISTOL_BODYHIT); *column->column[M_KEYBOARDKEYS.currentColumn] = sc; - Bindings.SetBind(sc, CONFIG_FunctionNumToName(M_KEYBOARDKEYS.currentEntry)); + Bindings.SetBind(sc, buttonMap.GetButtonName(M_KEYBOARDKEYS.currentEntry)); inputState.ClearKeyStatus(sc); return -1; diff --git a/source/rr/src/player.cpp b/source/rr/src/player.cpp index 90bb03c40..5a60bbdc0 100644 --- a/source/rr/src/player.cpp +++ b/source/rr/src/player.cpp @@ -2759,11 +2759,11 @@ void P_GetInput(int playerNum) D_ProcessEvents(); if (in_aimmode) - g_MyAimMode = inputState.BUTTON(gamefunc_Mouse_Aiming); + g_MyAimMode = buttonMap.ButtonDown(gamefunc_Mouse_Aiming); else { g_oldAimStat = g_myAimStat; - g_myAimStat = inputState.BUTTON(gamefunc_Mouse_Aiming); + g_myAimStat = buttonMap.ButtonDown(gamefunc_Mouse_Aiming); if (g_myAimStat > g_oldAimStat) { @@ -2797,7 +2797,7 @@ void P_GetInput(int playerNum) // JBF: Run key behaviour is selectable - int const playerRunning = G_CheckAutorun(inputState.BUTTON(gamefunc_Run)); + int const playerRunning = G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run)); int const turnAmount = playerRunning ? (NORMALTURN << 1) : NORMALTURN; constexpr int const analogTurnAmount = (NORMALTURN << 1); int const keyMove = playerRunning ? (NORMALKEYMOVE << 1) : NORMALKEYMOVE; @@ -2805,7 +2805,7 @@ void P_GetInput(int playerNum) input_t input {}; - if (inputState.BUTTON(gamefunc_Strafe)) + if (buttonMap.ButtonDown(gamefunc_Strafe)) { static int strafeyaw; @@ -2831,12 +2831,12 @@ void P_GetInput(int playerNum) input.svel -= info.dx * keyMove / analogExtent; input.fvel -= info.dz * keyMove / analogExtent; - if (inputState.BUTTON(gamefunc_Strafe)) + if (buttonMap.ButtonDown(gamefunc_Strafe)) { - if (inputState.BUTTON(gamefunc_Turn_Left) && !(pPlayer->movement_lock&4)) + if (buttonMap.ButtonDown(gamefunc_Turn_Left) && !(pPlayer->movement_lock&4)) input.svel -= -keyMove; - if (inputState.BUTTON(gamefunc_Turn_Right) && !(pPlayer->movement_lock&8)) + if (buttonMap.ButtonDown(gamefunc_Turn_Right) && !(pPlayer->movement_lock&8)) input.svel -= keyMove; } else @@ -2847,12 +2847,12 @@ void P_GetInput(int playerNum) lastInputClock = (int32_t) totalclock; - if (inputState.BUTTON(gamefunc_Turn_Left)) + if (buttonMap.ButtonDown(gamefunc_Turn_Left)) { turnHeldTime += elapsedTics; input.q16avel -= fix16_from_int((turnHeldTime >= TURBOTURNTIME) ? (turnAmount << 1) : (PREAMBLETURN << 1)); } - else if (inputState.BUTTON(gamefunc_Turn_Right)) + else if (buttonMap.ButtonDown(gamefunc_Turn_Right)) { turnHeldTime += elapsedTics; input.q16avel += fix16_from_int((turnHeldTime >= TURBOTURNTIME) ? (turnAmount << 1) : (PREAMBLETURN << 1)); @@ -2861,24 +2861,24 @@ void P_GetInput(int playerNum) turnHeldTime=0; } - if (inputState.BUTTON(gamefunc_Strafe_Left) && !(pPlayer->movement_lock & 4)) + if (buttonMap.ButtonDown(gamefunc_Strafe_Left) && !(pPlayer->movement_lock & 4)) input.svel += keyMove; - if (inputState.BUTTON(gamefunc_Strafe_Right) && !(pPlayer->movement_lock & 8)) + if (buttonMap.ButtonDown(gamefunc_Strafe_Right) && !(pPlayer->movement_lock & 8)) input.svel += -keyMove; if (RR) { - /*if (inputState.BUTTON(gamefunc_Quick_Kick)) + /*if (buttonMap.ButtonDown(gamefunc_Quick_Kick)) { - localInput.bits |= inputState.BUTTON(gamefunc_Move_Forward)<drink_amt >= 66 && pPlayer->drink_amt <= 87) { - if (inputState.BUTTON(gamefunc_Move_Forward)) + if (buttonMap.ButtonDown(gamefunc_Move_Forward)) { input.fvel += keyMove; if (pPlayer->drink_amt & 1) @@ -2887,7 +2887,7 @@ void P_GetInput(int playerNum) input.svel -= keyMove; } - if (inputState.BUTTON(gamefunc_Move_Backward)) + if (buttonMap.ButtonDown(gamefunc_Move_Backward)) { input.fvel += -keyMove; if (pPlayer->drink_amt & 1) @@ -2898,20 +2898,20 @@ void P_GetInput(int playerNum) } else { - if (inputState.BUTTON(gamefunc_Move_Forward)) + if (buttonMap.ButtonDown(gamefunc_Move_Forward)) input.fvel += keyMove; - if (inputState.BUTTON(gamefunc_Move_Backward)) + if (buttonMap.ButtonDown(gamefunc_Move_Backward)) input.fvel += -keyMove; } } } else { - if (inputState.BUTTON(gamefunc_Move_Forward) && !(g_player[playerNum].ps->movement_lock & 1)) + if (buttonMap.ButtonDown(gamefunc_Move_Forward) && !(g_player[playerNum].ps->movement_lock & 1)) input.fvel += keyMove; - if (inputState.BUTTON(gamefunc_Move_Backward) && !(g_player[playerNum].ps->movement_lock & 2)) + if (buttonMap.ButtonDown(gamefunc_Move_Backward) && !(g_player[playerNum].ps->movement_lock & 2)) input.fvel += -keyMove; } @@ -2925,65 +2925,65 @@ void P_GetInput(int playerNum) for (weaponSelection = gamefunc_Weapon_10; weaponSelection >= gamefunc_Weapon_1; --weaponSelection) { - if (inputState.BUTTON(weaponSelection)) + if (buttonMap.ButtonDown(weaponSelection)) { weaponSelection -= (gamefunc_Weapon_1 - 1); break; } } - if (inputState.BUTTON(gamefunc_Last_Weapon)) + if (buttonMap.ButtonDown(gamefunc_Last_Weapon)) weaponSelection = 14; - else if (inputState.BUTTON(gamefunc_Alt_Weapon)) + else if (buttonMap.ButtonDown(gamefunc_Alt_Weapon)) weaponSelection = 13; - else if (inputState.BUTTON(gamefunc_Next_Weapon) || (inputState.BUTTON(gamefunc_Dpad_Select) && input.fvel > 0)) + else if (buttonMap.ButtonDown(gamefunc_Next_Weapon) || (buttonMap.ButtonDown(gamefunc_Dpad_Select) && input.fvel > 0)) weaponSelection = 12; - else if (inputState.BUTTON(gamefunc_Previous_Weapon) || (inputState.BUTTON(gamefunc_Dpad_Select) && input.fvel < 0)) + else if (buttonMap.ButtonDown(gamefunc_Previous_Weapon) || (buttonMap.ButtonDown(gamefunc_Dpad_Select) && input.fvel < 0)) weaponSelection = 11; else if (weaponSelection == gamefunc_Weapon_1-1) weaponSelection = 0; - localInput.bits = (weaponSelection << SK_WEAPON_BITS) | (inputState.BUTTON(gamefunc_Fire) << SK_FIRE); - localInput.bits |= (inputState.BUTTON(gamefunc_Open) << SK_OPEN); + localInput.bits = (weaponSelection << SK_WEAPON_BITS) | (buttonMap.ButtonDown(gamefunc_Fire) << SK_FIRE); + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Open) << SK_OPEN); int const sectorLotag = pPlayer->cursectnum != -1 ? sector[pPlayer->cursectnum].lotag : 0; int const crouchable = sectorLotag != 2 && (sectorLotag != 1 || pPlayer->spritebridge); - if (inputState.BUTTON(gamefunc_Toggle_Crouch)) + if (buttonMap.ButtonDown(gamefunc_Toggle_Crouch)) { pPlayer->crouch_toggle = !pPlayer->crouch_toggle && crouchable; if (crouchable) - inputState.ClearButton(gamefunc_Toggle_Crouch); + buttonMap.ClearButton(gamefunc_Toggle_Crouch); } - if (inputState.BUTTON(gamefunc_Crouch) || inputState.BUTTON(gamefunc_Jump) || pPlayer->jetpack_on || (!crouchable && pPlayer->on_ground)) + if (buttonMap.ButtonDown(gamefunc_Crouch) || buttonMap.ButtonDown(gamefunc_Jump) || pPlayer->jetpack_on || (!crouchable && pPlayer->on_ground)) pPlayer->crouch_toggle = 0; - int const crouching = inputState.BUTTON(gamefunc_Crouch) || inputState.BUTTON(gamefunc_Toggle_Crouch) || pPlayer->crouch_toggle; + int const crouching = buttonMap.ButtonDown(gamefunc_Crouch) || buttonMap.ButtonDown(gamefunc_Toggle_Crouch) || pPlayer->crouch_toggle; - localInput.bits |= (inputState.BUTTON(gamefunc_Jump) << SK_JUMP) | (crouching << SK_CROUCH); + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Jump) << SK_JUMP) | (crouching << SK_CROUCH); - localInput.bits |= (inputState.BUTTON(gamefunc_Aim_Up) || (inputState.BUTTON(gamefunc_Dpad_Aiming) && input.fvel > 0)) << SK_AIM_UP; - localInput.bits |= (inputState.BUTTON(gamefunc_Aim_Down) || (inputState.BUTTON(gamefunc_Dpad_Aiming) && input.fvel < 0)) << SK_AIM_DOWN; - localInput.bits |= (inputState.BUTTON(gamefunc_Center_View) << SK_CENTER_VIEW); + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Aim_Up) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && input.fvel > 0)) << SK_AIM_UP; + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Aim_Down) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && input.fvel < 0)) << SK_AIM_DOWN; + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Center_View) << SK_CENTER_VIEW); - localInput.bits |= (inputState.BUTTON(gamefunc_Look_Left) << SK_LOOK_LEFT) | (inputState.BUTTON(gamefunc_Look_Right) << SK_LOOK_RIGHT); - localInput.bits |= (inputState.BUTTON(gamefunc_Look_Up) << SK_LOOK_UP) | (inputState.BUTTON(gamefunc_Look_Down) << SK_LOOK_DOWN); + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Look_Left) << SK_LOOK_LEFT) | (buttonMap.ButtonDown(gamefunc_Look_Right) << SK_LOOK_RIGHT); + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Look_Up) << SK_LOOK_UP) | (buttonMap.ButtonDown(gamefunc_Look_Down) << SK_LOOK_DOWN); localInput.bits |= (playerRunning << SK_RUN); - localInput.bits |= (inputState.BUTTON(gamefunc_Inventory_Left) || (inputState.BUTTON(gamefunc_Dpad_Select) && (input.svel > 0 || input.q16avel < 0))) << SK_INV_LEFT; - localInput.bits |= (inputState.BUTTON(gamefunc_Inventory_Right) || (inputState.BUTTON(gamefunc_Dpad_Select) && (input.svel < 0 || input.q16avel > 0))) << SK_INV_RIGHT; - localInput.bits |= (inputState.BUTTON(gamefunc_Inventory) << SK_INVENTORY); + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Inventory_Left) || (buttonMap.ButtonDown(gamefunc_Dpad_Select) && (input.svel > 0 || input.q16avel < 0))) << SK_INV_LEFT; + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Inventory_Right) || (buttonMap.ButtonDown(gamefunc_Dpad_Select) && (input.svel < 0 || input.q16avel > 0))) << SK_INV_RIGHT; + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Inventory) << SK_INVENTORY); - localInput.bits |= (inputState.BUTTON(gamefunc_Steroids) << SK_STEROIDS) | (inputState.BUTTON(gamefunc_NightVision) << SK_NIGHTVISION); - localInput.bits |= (inputState.BUTTON(gamefunc_MedKit) << SK_MEDKIT) | (inputState.BUTTON(gamefunc_Holo_Duke) << SK_HOLODUKE); - localInput.bits |= (inputState.BUTTON(gamefunc_Jetpack) << SK_JETPACK); + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Steroids) << SK_STEROIDS) | (buttonMap.ButtonDown(gamefunc_NightVision) << SK_NIGHTVISION); + localInput.bits |= (buttonMap.ButtonDown(gamefunc_MedKit) << SK_MEDKIT) | (buttonMap.ButtonDown(gamefunc_Holo_Duke) << SK_HOLODUKE); + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Jetpack) << SK_JETPACK); - localInput.bits |= inputState.BUTTON(gamefunc_Holster_Weapon) << SK_HOLSTER; - localInput.bits |= inputState.BUTTON(gamefunc_Quick_Kick) << SK_QUICK_KICK; - localInput.bits |= inputState.BUTTON(gamefunc_TurnAround) << SK_TURNAROUND; + localInput.bits |= buttonMap.ButtonDown(gamefunc_Holster_Weapon) << SK_HOLSTER; + localInput.bits |= buttonMap.ButtonDown(gamefunc_Quick_Kick) << SK_QUICK_KICK; + localInput.bits |= buttonMap.ButtonDown(gamefunc_TurnAround) << SK_TURNAROUND; localInput.bits |= (g_MyAimMode << SK_AIMMODE); localInput.bits |= (g_gameQuit << SK_GAMEQUIT); @@ -3000,21 +3000,21 @@ void P_GetInput(int playerNum) localInput.bits |= 1 << SK_LOOK_DOWN; } - if (inputState.BUTTON(gamefunc_Dpad_Select)) + if (buttonMap.ButtonDown(gamefunc_Dpad_Select)) { input.fvel = 0; input.svel = 0; input.q16avel = 0; } - else if (inputState.BUTTON(gamefunc_Dpad_Aiming)) + else if (buttonMap.ButtonDown(gamefunc_Dpad_Aiming)) input.fvel = 0; - localInput.extbits = (inputState.BUTTON(gamefunc_Move_Forward) || (input.fvel > 0)); - localInput.extbits |= (inputState.BUTTON(gamefunc_Move_Backward) || (input.fvel < 0)) << 1; - localInput.extbits |= (inputState.BUTTON(gamefunc_Strafe_Left) || (input.svel > 0)) << 2; - localInput.extbits |= (inputState.BUTTON(gamefunc_Strafe_Right) || (input.svel < 0)) << 3; - localInput.extbits |= inputState.BUTTON(gamefunc_Turn_Left)<<4; - localInput.extbits |= inputState.BUTTON(gamefunc_Turn_Right)<<5; + localInput.extbits = (buttonMap.ButtonDown(gamefunc_Move_Forward) || (input.fvel > 0)); + localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Move_Backward) || (input.fvel < 0)) << 1; + localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Strafe_Left) || (input.svel > 0)) << 2; + localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Strafe_Right) || (input.svel < 0)) << 3; + localInput.extbits |= buttonMap.ButtonDown(gamefunc_Turn_Left)<<4; + localInput.extbits |= buttonMap.ButtonDown(gamefunc_Turn_Right)<<5; if (ud.scrollmode && ud.overhead_on) { @@ -3065,11 +3065,11 @@ void P_GetInputMotorcycle(int playerNum) D_ProcessEvents(); if (in_aimmode) - g_MyAimMode = inputState.BUTTON(gamefunc_Mouse_Aiming); + g_MyAimMode = buttonMap.ButtonDown(gamefunc_Mouse_Aiming); else { g_oldAimStat = g_myAimStat; - g_myAimStat = inputState.BUTTON(gamefunc_Mouse_Aiming); + g_myAimStat = buttonMap.ButtonDown(gamefunc_Mouse_Aiming); if (g_myAimStat > g_oldAimStat) { @@ -3102,7 +3102,7 @@ void P_GetInputMotorcycle(int playerNum) } // JBF: Run key behaviour is selectable - int const playerRunning = G_CheckAutorun(inputState.BUTTON(gamefunc_Run)); + int const playerRunning = G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run)); constexpr int const analogTurnAmount = (NORMALTURN << 1); int const keyMove = playerRunning ? (NORMALKEYMOVE << 1) : NORMALKEYMOVE; constexpr int const analogExtent = 32767; // KEEPINSYNC sdlayer.cpp @@ -3128,40 +3128,40 @@ void P_GetInputMotorcycle(int playerNum) pPlayer->crouch_toggle = 0; - localInput.bits = inputState.BUTTON(gamefunc_Fire) << SK_FIRE; - localInput.bits |= inputState.BUTTON(gamefunc_Steroids) << SK_STEROIDS; - localInput.bits |= inputState.BUTTON(gamefunc_NightVision) << SK_NIGHTVISION; - localInput.bits |= inputState.BUTTON(gamefunc_MedKit) << SK_MEDKIT; - localInput.bits |= (inputState.BUTTON(gamefunc_Inventory_Left) || - (inputState.BUTTON(gamefunc_Dpad_Select) && (input.svel > 0 || input.q16avel < 0))) << SK_INV_LEFT; + localInput.bits = buttonMap.ButtonDown(gamefunc_Fire) << SK_FIRE; + localInput.bits |= buttonMap.ButtonDown(gamefunc_Steroids) << SK_STEROIDS; + localInput.bits |= buttonMap.ButtonDown(gamefunc_NightVision) << SK_NIGHTVISION; + localInput.bits |= buttonMap.ButtonDown(gamefunc_MedKit) << SK_MEDKIT; + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Inventory_Left) || + (buttonMap.ButtonDown(gamefunc_Dpad_Select) && (input.svel > 0 || input.q16avel < 0))) << SK_INV_LEFT; localInput.bits |= inputState.GetKeyStatus(sc_Pause) << SK_PAUSE; - localInput.bits |= inputState.BUTTON(gamefunc_Holo_Duke) << SK_HOLODUKE; - localInput.bits |= inputState.BUTTON(gamefunc_Jetpack) << SK_JETPACK; + localInput.bits |= buttonMap.ButtonDown(gamefunc_Holo_Duke) << SK_HOLODUKE; + localInput.bits |= buttonMap.ButtonDown(gamefunc_Jetpack) << SK_JETPACK; localInput.bits |= (g_gameQuit << SK_GAMEQUIT); - localInput.bits |= (inputState.BUTTON(gamefunc_Inventory_Right) || - (inputState.BUTTON(gamefunc_Dpad_Select) && (input.svel < 0 || input.q16avel > 0))) << SK_INV_RIGHT; - localInput.bits |= inputState.BUTTON(gamefunc_Open) << SK_OPEN; - localInput.bits |= inputState.BUTTON(gamefunc_Inventory) << SK_INVENTORY; + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Inventory_Right) || + (buttonMap.ButtonDown(gamefunc_Dpad_Select) && (input.svel < 0 || input.q16avel > 0))) << SK_INV_RIGHT; + localInput.bits |= buttonMap.ButtonDown(gamefunc_Open) << SK_OPEN; + localInput.bits |= buttonMap.ButtonDown(gamefunc_Inventory) << SK_INVENTORY; localInput.bits |= ((uint32_t)inputState.GetKeyStatus(sc_Escape)) << SK_ESCAPE; - if (inputState.BUTTON(gamefunc_Dpad_Select)) + if (buttonMap.ButtonDown(gamefunc_Dpad_Select)) { input.fvel = 0; input.svel = 0; input.q16avel = 0; } - if (inputState.BUTTON(gamefunc_Dpad_Aiming)) + if (buttonMap.ButtonDown(gamefunc_Dpad_Aiming)) input.fvel = 0; - localInput.extbits = (inputState.BUTTON(gamefunc_Move_Forward) || (input.fvel > 0)); - localInput.extbits |= (inputState.BUTTON(gamefunc_Move_Backward) || (input.fvel < 0)) << 1; - localInput.extbits |= (inputState.BUTTON(gamefunc_Strafe_Left) || (input.svel > 0)) << 2; - localInput.extbits |= (inputState.BUTTON(gamefunc_Strafe_Right) || (input.svel < 0)) << 3; + localInput.extbits = (buttonMap.ButtonDown(gamefunc_Move_Forward) || (input.fvel > 0)); + localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Move_Backward) || (input.fvel < 0)) << 1; + localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Strafe_Left) || (input.svel > 0)) << 2; + localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Strafe_Right) || (input.svel < 0)) << 3; int const turn = input.q16avel / 32; - int turnLeft = inputState.BUTTON(gamefunc_Turn_Left) || inputState.BUTTON(gamefunc_Strafe_Left); - int turnRight = inputState.BUTTON(gamefunc_Turn_Right) || inputState.BUTTON(gamefunc_Strafe_Right); + int turnLeft = buttonMap.ButtonDown(gamefunc_Turn_Left) || buttonMap.ButtonDown(gamefunc_Strafe_Left); + int turnRight = buttonMap.ButtonDown(gamefunc_Turn_Right) || buttonMap.ButtonDown(gamefunc_Strafe_Right); int avelScale = F16((turnLeft || turnRight) ? 1 : 0); if (turn) { @@ -3176,9 +3176,9 @@ void P_GetInputMotorcycle(int playerNum) if (!pPlayer->moto_underwater) { - localInput.bits |= (inputState.BUTTON(gamefunc_Move_Forward) || inputState.BUTTON(gamefunc_Strafe)) << SK_JUMP; - localInput.bits |= inputState.BUTTON(gamefunc_Move_Backward) << SK_AIM_UP; - localInput.bits |= inputState.BUTTON(gamefunc_Run) << SK_CROUCH; + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Move_Forward) || buttonMap.ButtonDown(gamefunc_Strafe)) << SK_JUMP; + localInput.bits |= buttonMap.ButtonDown(gamefunc_Move_Backward) << SK_AIM_UP; + localInput.bits |= buttonMap.ButtonDown(gamefunc_Run) << SK_CROUCH; } localInput.bits |= turnLeft << SK_AIM_DOWN; @@ -3188,7 +3188,7 @@ void P_GetInputMotorcycle(int playerNum) static int32_t lastInputClock = 0; // MED int32_t const elapsedTics = (int32_t) totalclock - lastInputClock; - int const moveBack = inputState.BUTTON(gamefunc_Move_Backward) && pPlayer->moto_speed <= 0; + int const moveBack = buttonMap.ButtonDown(gamefunc_Move_Backward) && pPlayer->moto_speed <= 0; if (pPlayer->moto_speed == 0 || !pPlayer->on_ground) { @@ -3363,11 +3363,11 @@ void P_GetInputBoat(int playerNum) D_ProcessEvents(); if (in_aimmode) - g_MyAimMode = inputState.BUTTON(gamefunc_Mouse_Aiming); + g_MyAimMode = buttonMap.ButtonDown(gamefunc_Mouse_Aiming); else { g_oldAimStat = g_myAimStat; - g_myAimStat = inputState.BUTTON(gamefunc_Mouse_Aiming); + g_myAimStat = buttonMap.ButtonDown(gamefunc_Mouse_Aiming); if (g_myAimStat > g_oldAimStat) { @@ -3400,7 +3400,7 @@ void P_GetInputBoat(int playerNum) } // JBF: Run key behaviour is selectable - int const playerRunning = G_CheckAutorun(inputState.BUTTON(gamefunc_Run)); + int const playerRunning = G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run)); constexpr int const analogTurnAmount = (NORMALTURN << 1); int const keyMove = playerRunning ? (NORMALKEYMOVE << 1) : NORMALKEYMOVE; constexpr int const analogExtent = 32767; // KEEPINSYNC sdlayer.cpp @@ -3426,40 +3426,40 @@ void P_GetInputBoat(int playerNum) pPlayer->crouch_toggle = 0; - localInput.bits = inputState.BUTTON(gamefunc_Fire) << SK_FIRE; - localInput.bits |= inputState.BUTTON(gamefunc_Steroids) << SK_STEROIDS; - localInput.bits |= inputState.BUTTON(gamefunc_NightVision) << SK_NIGHTVISION; - localInput.bits |= inputState.BUTTON(gamefunc_MedKit) << SK_MEDKIT; - localInput.bits |= (inputState.BUTTON(gamefunc_Inventory_Left) || - (inputState.BUTTON(gamefunc_Dpad_Select) && (input.svel > 0 || input.q16avel < 0))) << SK_INV_LEFT; + localInput.bits = buttonMap.ButtonDown(gamefunc_Fire) << SK_FIRE; + localInput.bits |= buttonMap.ButtonDown(gamefunc_Steroids) << SK_STEROIDS; + localInput.bits |= buttonMap.ButtonDown(gamefunc_NightVision) << SK_NIGHTVISION; + localInput.bits |= buttonMap.ButtonDown(gamefunc_MedKit) << SK_MEDKIT; + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Inventory_Left) || + (buttonMap.ButtonDown(gamefunc_Dpad_Select) && (input.svel > 0 || input.q16avel < 0))) << SK_INV_LEFT; localInput.bits |= inputState.GetKeyStatus(sc_Pause) << SK_PAUSE; - localInput.bits |= inputState.BUTTON(gamefunc_Holo_Duke) << SK_HOLODUKE; - localInput.bits |= inputState.BUTTON(gamefunc_Jetpack) << SK_JETPACK; + localInput.bits |= buttonMap.ButtonDown(gamefunc_Holo_Duke) << SK_HOLODUKE; + localInput.bits |= buttonMap.ButtonDown(gamefunc_Jetpack) << SK_JETPACK; localInput.bits |= (g_gameQuit << SK_GAMEQUIT); - localInput.bits |= (inputState.BUTTON(gamefunc_Inventory_Right) || - (inputState.BUTTON(gamefunc_Dpad_Select) && (input.svel < 0 || input.q16avel > 0))) << SK_INV_RIGHT; - localInput.bits |= inputState.BUTTON(gamefunc_Open) << SK_OPEN; - localInput.bits |= inputState.BUTTON(gamefunc_Inventory) << SK_INVENTORY; + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Inventory_Right) || + (buttonMap.ButtonDown(gamefunc_Dpad_Select) && (input.svel < 0 || input.q16avel > 0))) << SK_INV_RIGHT; + localInput.bits |= buttonMap.ButtonDown(gamefunc_Open) << SK_OPEN; + localInput.bits |= buttonMap.ButtonDown(gamefunc_Inventory) << SK_INVENTORY; localInput.bits |= ((uint32_t)inputState.GetKeyStatus(sc_Escape)) << SK_ESCAPE; - if (inputState.BUTTON(gamefunc_Dpad_Select)) + if (buttonMap.ButtonDown(gamefunc_Dpad_Select)) { input.fvel = 0; input.svel = 0; input.q16avel = 0; } - if (inputState.BUTTON(gamefunc_Dpad_Aiming)) + if (buttonMap.ButtonDown(gamefunc_Dpad_Aiming)) input.fvel = 0; - localInput.extbits = (inputState.BUTTON(gamefunc_Move_Forward) || (input.fvel > 0)); - localInput.extbits |= (inputState.BUTTON(gamefunc_Move_Backward) || (input.fvel < 0)) << 1; - localInput.extbits |= (inputState.BUTTON(gamefunc_Strafe_Left) || (input.svel > 0)) << 2; - localInput.extbits |= (inputState.BUTTON(gamefunc_Strafe_Right) || (input.svel < 0)) << 3; + localInput.extbits = (buttonMap.ButtonDown(gamefunc_Move_Forward) || (input.fvel > 0)); + localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Move_Backward) || (input.fvel < 0)) << 1; + localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Strafe_Left) || (input.svel > 0)) << 2; + localInput.extbits |= (buttonMap.ButtonDown(gamefunc_Strafe_Right) || (input.svel < 0)) << 3; int const turn = input.q16avel / 32; - int turnLeft = inputState.BUTTON(gamefunc_Turn_Left) || inputState.BUTTON(gamefunc_Strafe_Left); - int turnRight = inputState.BUTTON(gamefunc_Turn_Right) || inputState.BUTTON(gamefunc_Strafe_Right); + int turnLeft = buttonMap.ButtonDown(gamefunc_Turn_Left) || buttonMap.ButtonDown(gamefunc_Strafe_Left); + int turnRight = buttonMap.ButtonDown(gamefunc_Turn_Right) || buttonMap.ButtonDown(gamefunc_Strafe_Right); int avelScale = F16((turnLeft || turnRight) ? 1 : 0); if (turn) { @@ -3472,9 +3472,9 @@ void P_GetInputBoat(int playerNum) input.svel = input.fvel = input.q16avel = input.q16horz = 0; - localInput.bits |= (inputState.BUTTON(gamefunc_Move_Forward) || inputState.BUTTON(gamefunc_Strafe)) << SK_JUMP; - localInput.bits |= inputState.BUTTON(gamefunc_Move_Backward) << SK_AIM_UP; - localInput.bits |= inputState.BUTTON(gamefunc_Run) << SK_CROUCH; + localInput.bits |= (buttonMap.ButtonDown(gamefunc_Move_Forward) || buttonMap.ButtonDown(gamefunc_Strafe)) << SK_JUMP; + localInput.bits |= buttonMap.ButtonDown(gamefunc_Move_Backward) << SK_AIM_UP; + localInput.bits |= buttonMap.ButtonDown(gamefunc_Run) << SK_CROUCH; localInput.bits |= turnLeft << SK_AIM_DOWN; localInput.bits |= turnRight << SK_LOOK_LEFT; diff --git a/source/rr/src/screens.cpp b/source/rr/src/screens.cpp index bb7405def..337ddd612 100644 --- a/source/rr/src/screens.cpp +++ b/source/rr/src/screens.cpp @@ -1220,7 +1220,7 @@ void G_DisplayRest(int32_t smoothratio) gametext_center(70, "Press F1 to Accept, F2 to Decline"); } - if (inputState.BUTTON(gamefunc_Show_DukeMatch_Scores)) + if (buttonMap.ButtonDown(gamefunc_Show_DukeMatch_Scores)) G_ShowScores(); if (g_Debug) diff --git a/source/sw/src/demo.cpp b/source/sw/src/demo.cpp index 7eb1ac217..cc4e5e02e 100644 --- a/source/sw/src/demo.cpp +++ b/source/sw/src/demo.cpp @@ -471,9 +471,9 @@ DemoPlayBack(void) else { - if (inputState.BUTTON(gamefunc_See_Coop_View)) + if (buttonMap.ButtonDown(gamefunc_See_Coop_View)) { - inputState.ClearButton(gamefunc_See_Coop_View); + buttonMap.ClearButton(gamefunc_See_Coop_View); screenpeek = connectpoint2[screenpeek]; @@ -497,16 +497,16 @@ DemoPlayBack(void) // if a key is pressed, start recording from the point the key // was pressed - if (inputState.BUTTON(gamefunc_Move_Forward) || - inputState.BUTTON(gamefunc_Move_Backward) || - inputState.BUTTON(gamefunc_Turn_Left) || - inputState.BUTTON(gamefunc_Turn_Right) || - inputState.BUTTON(gamefunc_Fire) || - inputState.BUTTON(gamefunc_Open) || - inputState.BUTTON(gamefunc_Jump) || - inputState.BUTTON(gamefunc_Crouch) || - inputState.BUTTON(gamefunc_Look_Up) || - inputState.BUTTON(gamefunc_Look_Down)) + if (buttonMap.ButtonDown(gamefunc_Move_Forward) || + buttonMap.ButtonDown(gamefunc_Move_Backward) || + buttonMap.ButtonDown(gamefunc_Turn_Left) || + buttonMap.ButtonDown(gamefunc_Turn_Right) || + buttonMap.ButtonDown(gamefunc_Fire) || + buttonMap.ButtonDown(gamefunc_Open) || + buttonMap.ButtonDown(gamefunc_Jump) || + buttonMap.ButtonDown(gamefunc_Crouch) || + buttonMap.ButtonDown(gamefunc_Look_Up) || + buttonMap.ButtonDown(gamefunc_Look_Down)) { DemoBackupBuffer(); @@ -517,7 +517,7 @@ DemoPlayBack(void) } } - if (inputState.BUTTON(gamefunc_See_Co_Op_View)) + if (buttonMap.ButtonDown(gamefunc_See_Co_Op_View)) { screenpeek += 1; if (screenpeek > numplayers-1) diff --git a/source/sw/src/draw.cpp b/source/sw/src/draw.cpp index 4c5dbb484..fb26b8132 100644 --- a/source/sw/src/draw.cpp +++ b/source/sw/src/draw.cpp @@ -1066,16 +1066,16 @@ ResizeView(PLAYERp pp) } else { - if (inputState.BUTTON(gamefunc_Shrink_Screen)) // && + if (buttonMap.ButtonDown(gamefunc_Shrink_Screen)) // && { - inputState.ClearButton(gamefunc_Shrink_Screen); + buttonMap.ClearButton(gamefunc_Shrink_Screen); SetBorder(pp, gs.BorderNum + 1); SetRedrawScreen(pp); } - if (inputState.BUTTON(gamefunc_Enlarge_Screen)) // && + if (buttonMap.ButtonDown(gamefunc_Enlarge_Screen)) // && { - inputState.ClearButton(gamefunc_Enlarge_Screen); + buttonMap.ClearButton(gamefunc_Enlarge_Screen); SetBorder(pp, gs.BorderNum - 1); SetRedrawScreen(pp); } diff --git a/source/sw/src/game.cpp b/source/sw/src/game.cpp index 4ea41dac1..91954c987 100644 --- a/source/sw/src/game.cpp +++ b/source/sw/src/game.cpp @@ -3438,11 +3438,11 @@ SinglePlayInput(PLAYERp pp) int pnum = myconnectindex; uint8_t* kp; - if (inputState.BUTTON(gamefunc_See_Co_Op_View) && !UsingMenus && !ConPanel && dimensionmode == 3) + if (buttonMap.ButtonDown(gamefunc_See_Co_Op_View) && !UsingMenus && !ConPanel && dimensionmode == 3) { short oldscreenpeek = screenpeek; - inputState.ClearButton(gamefunc_See_Co_Op_View); + buttonMap.ClearButton(gamefunc_See_Co_Op_View); screenpeek = connectpoint2[screenpeek]; @@ -3839,9 +3839,9 @@ void GetMessageInput(PLAYERp pp) if (!MessageInputMode && !ConInputMode) { - if (inputState.BUTTON(gamefunc_SendMessage)) + if (buttonMap.ButtonDown(gamefunc_SendMessage)) { - inputState.ClearButton(gamefunc_SendMessage); + buttonMap.ClearButton(gamefunc_SendMessage); inputState.keyFlushChars(); MessageInputMode = TRUE; InputMode = TRUE; @@ -3876,7 +3876,7 @@ void GetMessageInput(PLAYERp pp) InputMode = FALSE; inputState.ClearKeysDown(); inputState.keyFlushChars(); - inputState.ClearButton(gamefunc_Inventory); + buttonMap.ClearButton(gamefunc_Inventory); } else { @@ -3910,11 +3910,11 @@ SEND_MESSAGE: InputMode = FALSE; inputState.ClearKeysDown(); inputState.keyFlushChars(); - inputState.ClearButton(gamefunc_Inventory); + buttonMap.ClearButton(gamefunc_Inventory); CON_ProcessUserCommand(); // Check to see if it's a cheat or command for (i = 0; i < NUMGAMEFUNCTIONS; i++) - inputState.ClearButton(i); + buttonMap.ClearButton(i); // Put who sent this sprintf(ds,"%s: %s",pp->PlayerName,MessageInputString); @@ -4006,7 +4006,7 @@ void GetConInput(PLAYERp pp) InputMode = FALSE; inputState.ClearKeysDown(); inputState.keyFlushChars(); - inputState.ClearButton(gamefunc_Inventory); + buttonMap.ClearButton(gamefunc_Inventory); memset(MessageInputString, '\0', sizeof(MessageInputString)); } else @@ -4014,7 +4014,7 @@ void GetConInput(PLAYERp pp) InputMode = FALSE; inputState.ClearKeysDown(); inputState.keyFlushChars(); - inputState.ClearButton(gamefunc_Inventory); + buttonMap.ClearButton(gamefunc_Inventory); CON_ConMessage("%s", MessageInputString); CON_ProcessUserCommand(); // Check to see if it's a cheat or command @@ -4162,13 +4162,13 @@ getinput(SW_PACKET *loc) if (in_aimmode) g_MyAimMode = 0; - if (inputState.BUTTON(gamefunc_Mouse_Aiming)) + if (buttonMap.ButtonDown(gamefunc_Mouse_Aiming)) { if (in_aimmode) g_MyAimMode = 1; else { - inputState.ClearButton(gamefunc_Mouse_Aiming); + buttonMap.ClearButton(gamefunc_Mouse_Aiming); g_MyAimMode = !g_MyAimMode; if (g_MyAimMode) { @@ -4200,9 +4200,9 @@ getinput(SW_PACKET *loc) } // MAP KEY - if (inputState.BUTTON(gamefunc_Map)) + if (buttonMap.ButtonDown(gamefunc_Map)) { - inputState.ClearButton(gamefunc_Map); + buttonMap.ClearButton(gamefunc_Map); // Init follow coords Follow_posx = pp->posx; @@ -4225,9 +4225,9 @@ getinput(SW_PACKET *loc) // Toggle follow map mode on/off if (dimensionmode == 5 || dimensionmode == 6) { - if (inputState.BUTTON(gamefunc_Map_Follow_Mode)) + if (buttonMap.ButtonDown(gamefunc_Map_Follow_Mode)) { - inputState.ClearButton(gamefunc_Map_Follow_Mode); + buttonMap.ClearButton(gamefunc_Map_Follow_Mode); ScrollMode2D = !ScrollMode2D; Follow_posx = pp->posx; Follow_posy = pp->posy; @@ -4244,11 +4244,11 @@ getinput(SW_PACKET *loc) if (MenuInputMode || UsingMenus || ScrollMode2D || InputMode) return; - SET_LOC_KEY(loc->bits, SK_SPACE_BAR, ((!!inputState.GetKeyStatus(KEYSC_SPACE)) | inputState.BUTTON(gamefunc_Open))); + SET_LOC_KEY(loc->bits, SK_SPACE_BAR, ((!!inputState.GetKeyStatus(KEYSC_SPACE)) | buttonMap.ButtonDown(gamefunc_Open))); - running = G_CheckAutorun(inputState.BUTTON(gamefunc_Run)); + running = G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run)); - if (inputState.BUTTON(gamefunc_Strafe) && !pp->sop) + if (buttonMap.ButtonDown(gamefunc_Strafe) && !pp->sop) svel = -info.dyaw; else { @@ -4286,16 +4286,16 @@ getinput(SW_PACKET *loc) keymove = NORMALKEYMOVE; } - if (inputState.BUTTON(gamefunc_Strafe) && !pp->sop) + if (buttonMap.ButtonDown(gamefunc_Strafe) && !pp->sop) { - if (inputState.BUTTON(gamefunc_Turn_Left)) + if (buttonMap.ButtonDown(gamefunc_Turn_Left)) svel -= -keymove; - if (inputState.BUTTON(gamefunc_Turn_Right)) + if (buttonMap.ButtonDown(gamefunc_Turn_Right)) svel -= keymove; } else { - if (inputState.BUTTON(gamefunc_Turn_Left)) + if (buttonMap.ButtonDown(gamefunc_Turn_Left)) { turnheldtime += synctics; if (turnheldtime >= TURBOTURNTIME) @@ -4303,7 +4303,7 @@ getinput(SW_PACKET *loc) else angvel -= PREAMBLETURN; } - else if (inputState.BUTTON(gamefunc_Turn_Right)) + else if (buttonMap.ButtonDown(gamefunc_Turn_Right)) { turnheldtime += synctics; if (turnheldtime >= TURBOTURNTIME) @@ -4317,13 +4317,13 @@ getinput(SW_PACKET *loc) } } - if (inputState.BUTTON(gamefunc_Strafe_Left) && !pp->sop) + if (buttonMap.ButtonDown(gamefunc_Strafe_Left) && !pp->sop) svel += keymove; - if (inputState.BUTTON(gamefunc_Strafe_Right) && !pp->sop) + if (buttonMap.ButtonDown(gamefunc_Strafe_Right) && !pp->sop) svel += -keymove; - if (inputState.BUTTON(gamefunc_Move_Forward)) + if (buttonMap.ButtonDown(gamefunc_Move_Forward)) { vel += keymove; //DSPRINTF(ds,"vel key %d",vel); @@ -4335,7 +4335,7 @@ getinput(SW_PACKET *loc) //DebugWriteString(ds); } - if (inputState.BUTTON(gamefunc_Move_Backward)) + if (buttonMap.ButtonDown(gamefunc_Move_Backward)) vel += -keymove; @@ -4378,36 +4378,36 @@ getinput(SW_PACKET *loc) inputState.ClearKeyStatus(sc_Pause); } - SET_LOC_KEY(loc->bits, SK_CENTER_VIEW, inputState.BUTTON(gamefunc_Center_View)); + SET_LOC_KEY(loc->bits, SK_CENTER_VIEW, buttonMap.ButtonDown(gamefunc_Center_View)); - SET_LOC_KEY(loc->bits, SK_RUN, inputState.BUTTON(gamefunc_Run)); - SET_LOC_KEY(loc->bits, SK_SHOOT, inputState.BUTTON(gamefunc_Fire)); + SET_LOC_KEY(loc->bits, SK_RUN, buttonMap.ButtonDown(gamefunc_Run)); + SET_LOC_KEY(loc->bits, SK_SHOOT, buttonMap.ButtonDown(gamefunc_Fire)); // actually snap - SET_LOC_KEY(loc->bits, SK_SNAP_UP, inputState.BUTTON(gamefunc_Aim_Up)); - SET_LOC_KEY(loc->bits, SK_SNAP_DOWN, inputState.BUTTON(gamefunc_Aim_Down)); + SET_LOC_KEY(loc->bits, SK_SNAP_UP, buttonMap.ButtonDown(gamefunc_Aim_Up)); + SET_LOC_KEY(loc->bits, SK_SNAP_DOWN, buttonMap.ButtonDown(gamefunc_Aim_Down)); // actually just look - SET_LOC_KEY(loc->bits, SK_LOOK_UP, inputState.BUTTON(gamefunc_Look_Up)); - SET_LOC_KEY(loc->bits, SK_LOOK_DOWN, inputState.BUTTON(gamefunc_Look_Down)); + SET_LOC_KEY(loc->bits, SK_LOOK_UP, buttonMap.ButtonDown(gamefunc_Look_Up)); + SET_LOC_KEY(loc->bits, SK_LOOK_DOWN, buttonMap.ButtonDown(gamefunc_Look_Down)); for (i = 0; i < MAX_WEAPONS_KEYS; i++) { - if (inputState.BUTTON(gamefunc_Weapon_1 + i)) + if (buttonMap.ButtonDown(gamefunc_Weapon_1 + i)) { SET(loc->bits, i + 1); break; } } - if (inputState.BUTTON(gamefunc_Next_Weapon)) + if (buttonMap.ButtonDown(gamefunc_Next_Weapon)) { USERp u = User[pp->PlayerSprite]; short next_weapon = u->WeaponNum + 1; short start_weapon; - inputState.ClearButton(gamefunc_Next_Weapon); + buttonMap.ClearButton(gamefunc_Next_Weapon); start_weapon = u->WeaponNum + 1; @@ -4441,13 +4441,13 @@ getinput(SW_PACKET *loc) } - if (inputState.BUTTON(gamefunc_Previous_Weapon)) + if (buttonMap.ButtonDown(gamefunc_Previous_Weapon)) { USERp u = User[pp->PlayerSprite]; short prev_weapon = u->WeaponNum - 1; short start_weapon; - inputState.ClearButton(gamefunc_Previous_Weapon); + buttonMap.ClearButton(gamefunc_Previous_Weapon); start_weapon = u->WeaponNum - 1; @@ -4479,42 +4479,42 @@ getinput(SW_PACKET *loc) } inv_hotkey = 0; - if (inputState.BUTTON(gamefunc_Med_Kit)) + if (buttonMap.ButtonDown(gamefunc_Med_Kit)) inv_hotkey = INVENTORY_MEDKIT+1; - if (inputState.BUTTON(gamefunc_Smoke_Bomb)) + if (buttonMap.ButtonDown(gamefunc_Smoke_Bomb)) inv_hotkey = INVENTORY_CLOAK+1; - if (inputState.BUTTON(gamefunc_Night_Vision)) + if (buttonMap.ButtonDown(gamefunc_Night_Vision)) inv_hotkey = INVENTORY_NIGHT_VISION+1; - if (inputState.BUTTON(gamefunc_Gas_Bomb)) + if (buttonMap.ButtonDown(gamefunc_Gas_Bomb)) inv_hotkey = INVENTORY_CHEMBOMB+1; - if (inputState.BUTTON(gamefunc_Flash_Bomb) && dimensionmode == 3) + if (buttonMap.ButtonDown(gamefunc_Flash_Bomb) && dimensionmode == 3) inv_hotkey = INVENTORY_FLASHBOMB+1; - if (inputState.BUTTON(gamefunc_Caltrops)) + if (buttonMap.ButtonDown(gamefunc_Caltrops)) inv_hotkey = INVENTORY_CALTROPS+1; SET(loc->bits, inv_hotkey<bits, SK_INV_USE, inputState.BUTTON(gamefunc_Inventory)); + SET_LOC_KEY(loc->bits, SK_INV_USE, buttonMap.ButtonDown(gamefunc_Inventory)); - SET_LOC_KEY(loc->bits, SK_OPERATE, inputState.BUTTON(gamefunc_Open)); - SET_LOC_KEY(loc->bits, SK_JUMP, inputState.BUTTON(gamefunc_Jump)); - SET_LOC_KEY(loc->bits, SK_CRAWL, inputState.BUTTON(gamefunc_Crouch)); + SET_LOC_KEY(loc->bits, SK_OPERATE, buttonMap.ButtonDown(gamefunc_Open)); + SET_LOC_KEY(loc->bits, SK_JUMP, buttonMap.ButtonDown(gamefunc_Jump)); + SET_LOC_KEY(loc->bits, SK_CRAWL, buttonMap.ButtonDown(gamefunc_Crouch)); - SET_LOC_KEY(loc->bits, SK_TURN_180, inputState.BUTTON(gamefunc_TurnAround)); + SET_LOC_KEY(loc->bits, SK_TURN_180, buttonMap.ButtonDown(gamefunc_TurnAround)); - SET_LOC_KEY(loc->bits, SK_INV_LEFT, inputState.BUTTON(gamefunc_Inventory_Left)); - SET_LOC_KEY(loc->bits, SK_INV_RIGHT, inputState.BUTTON(gamefunc_Inventory_Right)); + SET_LOC_KEY(loc->bits, SK_INV_LEFT, buttonMap.ButtonDown(gamefunc_Inventory_Left)); + SET_LOC_KEY(loc->bits, SK_INV_RIGHT, buttonMap.ButtonDown(gamefunc_Inventory_Right)); - SET_LOC_KEY(loc->bits, SK_HIDE_WEAPON, inputState.BUTTON(gamefunc_Holster_Weapon)); + SET_LOC_KEY(loc->bits, SK_HIDE_WEAPON, buttonMap.ButtonDown(gamefunc_Holster_Weapon)); // need BUTTON SET_LOC_KEY(loc->bits, SK_CRAWL_LOCK, inputState.GetKeyStatus(KEYSC_NUM)); if (gNet.MultiGameType == MULTI_GAME_COOPERATIVE) { - if (inputState.BUTTON(gamefunc_See_Co_Op_View)) + if (buttonMap.ButtonDown(gamefunc_See_Co_Op_View)) { - inputState.ClearButton(gamefunc_See_Co_Op_View); + buttonMap.ClearButton(gamefunc_See_Co_Op_View); screenpeek = connectpoint2[screenpeek]; @@ -4551,9 +4551,9 @@ getinput(SW_PACKET *loc) FunctionKeys(pp); - if (inputState.BUTTON(gamefunc_Toggle_Crosshair)) + if (buttonMap.ButtonDown(gamefunc_Toggle_Crosshair)) { - inputState.ClearButton(gamefunc_Toggle_Crosshair); + buttonMap.ClearButton(gamefunc_Toggle_Crosshair); pToggleCrosshair(pp); } } diff --git a/source/sw/src/menus.cpp b/source/sw/src/menus.cpp index 061500c98..f6ea10855 100644 --- a/source/sw/src/menus.cpp +++ b/source/sw/src/menus.cpp @@ -705,7 +705,7 @@ SWBOOL MNU_KeySetupCustom(UserCall call, MenuItem *item) for (i=0; i<(int)SIZ(strs); i++) { w = 0; - auto c = CONFIG_FunctionNumToName(currentkey); + auto c = buttonMap.GetButtonName(currentkey); sprintf(ds,strs[i],c,col[currentcol]); for (j=0; ds[j]; j++) if (ds[j] == '_') ds[j] = ' '; MNU_MeasureString(ds, &w, &h); @@ -738,7 +738,7 @@ SWBOOL MNU_KeySetupCustom(UserCall call, MenuItem *item) inputState.ClearKeyStatus(sc_Delete); if (currentkey != gamefunc_Show_Console) { - //Bindings.UnbindACommand(CONFIG_FunctionNumToName(M_KEYBOARDKEYS.currentEntry)); + //Bindings.UnbindACommand(buttonMap.GetButtonName(M_KEYBOARDKEYS.currentEntry)); } } else if (inputState.GetKeyStatus(sc_Home)) @@ -797,7 +797,7 @@ SWBOOL MNU_KeySetupCustom(UserCall call, MenuItem *item) for (i = topitem; i <= botitem; i++) { - auto c = CONFIG_FunctionNumToName(i); + auto c = buttonMap.GetButtonName(i); for (j = 0; c[j]; j++) { if (c[j] == '_') ds[j] = ' '; @@ -922,7 +922,7 @@ static int MNU_SelectButtonFunction(const char *buttonname, int *currentfunc) } else { - auto c = CONFIG_FunctionNumToName(i-1); + auto c = buttonMap.GetButtonName(i-1); for (j = 0; c[j]; j++) { if (c[j] == '_') ds[j] = ' '; @@ -1047,7 +1047,7 @@ static SWBOOL MNU_SetMouseButtonFunctions(MenuItem_p item) } else { - strcpy(MouseButtonFunctions[item->tics], CONFIG_FunctionNumToName(function)); + strcpy(MouseButtonFunctions[item->tics], buttonMap.GetButtonName(function)); for (p = MouseButtonFunctions[item->tics]; *p; p++) { if (*p == '_') @@ -1131,7 +1131,7 @@ static SWBOOL MNU_SetAdvancedMouseFunctions(MenuItem_p item) } else { - strcpy(AdvancedMouseAxisFunctions[axis], CONFIG_FunctionNumToName(MouseDigitalAxes[axis/2][axis%2])); + strcpy(AdvancedMouseAxisFunctions[axis], buttonMap.GetButtonName(MouseDigitalAxes[axis/2][axis%2])); for (p = AdvancedMouseAxisFunctions[axis]; *p; p++) { if (*p == '_') @@ -1359,7 +1359,7 @@ static SWBOOL MNU_SetJoystickButtonFunctions(MenuItem_p item) } else { - strcpy(JoystickButtonFunctions[button + clicked*MAXJOYBUTTONS], CONFIG_FunctionNumToName(function)); + strcpy(JoystickButtonFunctions[button + clicked*MAXJOYBUTTONS], buttonMap.GetButtonName(function)); for (p = JoystickButtonFunctions[button + clicked*MAXJOYBUTTONS]; *p; p++) { if (*p == '_') @@ -1473,7 +1473,7 @@ static SWBOOL MNU_SetJoystickAxisFunctions(MenuItem_p item) } else { - strcpy(JoystickAxisFunctions[item->tics], CONFIG_FunctionNumToName(function)); + strcpy(JoystickAxisFunctions[item->tics], buttonMap.GetButtonName(function)); for (p = JoystickAxisFunctions[item->tics]; *p; p++) { if (*p == '_') diff --git a/source/sw/src/player.cpp b/source/sw/src/player.cpp index dd565f9a8..ab2a1e9a9 100644 --- a/source/sw/src/player.cpp +++ b/source/sw/src/player.cpp @@ -2419,25 +2419,25 @@ MoveScrollMode2D(PLAYERp pp) return; // Recenter view if told - if (inputState.BUTTON(gamefunc_Center_View)) + if (buttonMap.ButtonDown(gamefunc_Center_View)) { Follow_posx = pp->posx; Follow_posy = pp->posy; } // Toggle follow map mode on/off - if (inputState.BUTTON(gamefunc_Map_Follow_Mode)) + if (buttonMap.ButtonDown(gamefunc_Map_Follow_Mode)) { - inputState.ClearButton(gamefunc_Map_Follow_Mode); + buttonMap.ClearButton(gamefunc_Map_Follow_Mode); ScrollMode2D = !ScrollMode2D; // Reset coords Follow_posx = pp->posx; Follow_posy = pp->posy; } - running = G_CheckAutorun(inputState.BUTTON(gamefunc_Run)); + running = G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run)); - if (inputState.BUTTON(gamefunc_Strafe)) + if (buttonMap.ButtonDown(gamefunc_Strafe)) mfsvel -= scrl_input.dyaw>>2; mfsvel -= scrl_input.dx>>2; mfvel = -scrl_input.dz>>2; @@ -2454,11 +2454,11 @@ MoveScrollMode2D(PLAYERp pp) if (!HelpInputMode && !ConPanel) { - if (inputState.BUTTON(gamefunc_Turn_Left)) + if (buttonMap.ButtonDown(gamefunc_Turn_Left)) { mfsvel -= -keymove; } - if (inputState.BUTTON(gamefunc_Turn_Right)) + if (buttonMap.ButtonDown(gamefunc_Turn_Right)) { mfsvel -= keymove; } @@ -2466,12 +2466,12 @@ MoveScrollMode2D(PLAYERp pp) if (!InputMode && !ConPanel) { - if (inputState.BUTTON(gamefunc_Strafe_Left)) + if (buttonMap.ButtonDown(gamefunc_Strafe_Left)) { mfsvel += keymove; } - if (inputState.BUTTON(gamefunc_Strafe_Right)) + if (buttonMap.ButtonDown(gamefunc_Strafe_Right)) { mfsvel += -keymove; } @@ -2479,12 +2479,12 @@ MoveScrollMode2D(PLAYERp pp) if (!UsingMenus && !HelpInputMode && !ConPanel) { - if (inputState.BUTTON(gamefunc_Move_Forward)) + if (buttonMap.ButtonDown(gamefunc_Move_Forward)) { mfvel += keymove; } - if (inputState.BUTTON(gamefunc_Move_Backward)) + if (buttonMap.ButtonDown(gamefunc_Move_Backward)) { mfvel += -keymove; }