From 00b2467eeae2d185d4c84cb39de69a390dcbf5cc Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 2 Dec 2019 02:07:32 +0100 Subject: [PATCH] - WIP keybinding cleanup --- source/CMakeLists.txt | 2 +- source/blood/src/menu.cpp | 43 ---- source/blood/src/messages.cpp | 62 ------ source/common/console/c_bind.cpp | 213 ++++++++++++++++++++ source/common/console/c_bind.h | 9 + source/common/console/c_buttons.cpp | 293 ++++++---------------------- source/common/console/c_buttons.h | 21 +- source/common/gamecontrol.cpp | 232 +--------------------- source/common/gamecontrol.h | 15 -- source/duke3d/src/gamedef.cpp | 16 +- source/duke3d/src/gameexec.cpp | 5 +- source/rr/src/gamedef.cpp | 12 +- 12 files changed, 315 insertions(+), 608 deletions(-) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 7d9fa2135..844597972 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -860,7 +860,7 @@ add_executable( demolition WIN32 MACOSX_BUNDLE #zzautozend.cpp ) -set_source_files_properties( ${FASTMATH_SOURCES} PROPERTIES COMPILE_FLAGS ${DEM_FASTMATH_FLAG} ) +#set_source_files_properties( ${FASTMATH_SOURCES} PROPERTIES COMPILE_FLAGS ${DEM_FASTMATH_FLAG} ) set_source_files_properties( xlat/parse_xlat.cpp PROPERTIES OBJECT_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/xlat_parser.c" ) set_source_files_properties( utility/sc_man.cpp PROPERTIES OBJECT_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/sc_man_scanner.h" ) set_source_files_properties( ${NOT_COMPILED_SOURCE_FILES} PROPERTIES HEADER_FILE_ONLY TRUE ) diff --git a/source/blood/src/menu.cpp b/source/blood/src/menu.cpp index f37af27d3..7bfad8f96 100644 --- a/source/blood/src/menu.cpp +++ b/source/blood/src/menu.cpp @@ -1874,54 +1874,11 @@ void SetMouseYScale(CGameMenuItemSlider *pItem) void SetMouseDigitalAxis(CGameMenuItemZCycle *pItem) { -#if 0 - if (pItem == &itemOptionsControlMouseDigitalUp) - { - MouseDigitalFunctions[1][0] = nGamefuncsValues[pItem->m_nFocus]; - CONTROL_MapDigitalAxis(1, MouseDigitalFunctions[1][0], 0, controldevice_mouse); - } - else if (pItem == &itemOptionsControlMouseDigitalDown) - { - MouseDigitalFunctions[1][1] = nGamefuncsValues[pItem->m_nFocus]; - CONTROL_MapDigitalAxis(1, MouseDigitalFunctions[1][1], 1, controldevice_mouse); - } - else if (pItem == &itemOptionsControlMouseDigitalLeft) - { - MouseDigitalFunctions[0][0] = nGamefuncsValues[pItem->m_nFocus]; - CONTROL_MapDigitalAxis(0, MouseDigitalFunctions[0][0], 0, controldevice_mouse); - } - else if (pItem == &itemOptionsControlMouseDigitalRight) - { - MouseDigitalFunctions[0][1] = nGamefuncsValues[pItem->m_nFocus]; - CONTROL_MapDigitalAxis(0, MouseDigitalFunctions[0][1], 1, controldevice_mouse); - } -#endif } void SetupMouseMenu(CGameMenuItemChain *pItem) { UNREFERENCED_PARAMETER(pItem); -#if 0 - static CGameMenuItemZCycle *pMouseDigitalAxis[4] = { - &itemOptionsControlMouseDigitalLeft, - &itemOptionsControlMouseDigitalRight, - &itemOptionsControlMouseDigitalUp, - &itemOptionsControlMouseDigitalDown - }; - for (int i = 0; i < ARRAY_SSIZE(pMouseDigitalAxis); i++) - { - CGameMenuItemZCycle *pItem = pMouseDigitalAxis[i]; - pItem->m_nFocus = 0; - for (int j = 0; j < NUMGAMEFUNCTIONS+1; j++) - { - if (nGamefuncsValues[j] == MouseDigitalFunctions[i>>1][i&1]) - { - pItem->m_nFocus = j; - break; - } - } - } -#endif itemOptionsControlMouseAimFlipped.at20 = in_mouseflip; itemOptionsControlMouseFilterInput.at20 = in_mousesmoothing; itemOptionsControlMouseAimMode.at20 = in_aimmode; diff --git a/source/blood/src/messages.cpp b/source/blood/src/messages.cpp index 6993247c5..0ceafed93 100644 --- a/source/blood/src/messages.cpp +++ b/source/blood/src/messages.cpp @@ -53,16 +53,6 @@ void sub_5A928(void) buttonMap.ClearButton(i); } -void sub_5A944(int key) -{ - auto binding = Bindings.GetBind(key); - if (binding) - { - auto index = buttonMap.FindButtonIndex(binding); - if (index >= 0) buttonMap.ClearButton(index); - } -} - void SetGodMode(bool god) { playerSetGodMode(gMe, god); @@ -590,58 +580,6 @@ void CPlayerMsg::Send(void) void CPlayerMsg::ProcessKeys(void) { if (inputState.GetKeyStatus(sc_Escape)) Term(); -#if 0 - int key = inputState.keyGetScan(); - int ch; - if (key != 0) - { - bool ctrl = (inputState.CtrlPressed()); - bool shift = (inputState.ShiftPressed()); - switch (key) - { - case sc_Escape: - Term(); - break; - case sc_F1: - case sc_F2: - case sc_F3: - case sc_F4: - case sc_F5: - case sc_F6: - case sc_F7: - case sc_F8: - case sc_F9: - case sc_F10: - buttonMap.ClearButton(gamefunc_See_Chase_View); - Set(*CombatMacros[key-sc_F1]); - Send(); - inputState.ClearKeyStatus(key); - break; - case sc_BackSpace: - if (ctrl) - Clear(); - else - DelChar(); - break; - case sc_Enter: - case sc_kpad_Enter: - if (gCheatMgr.Check(text)) - Term(); - else - Send(); - break; - default: - if (key < 128) - { - ch = shift ? g_keyAsciiTableShift[key] : g_keyAsciiTable[key]; - if (ch) - AddChar(ch); - } - break; - } - sub_5A944(key); - } -#endif } bool CPlayerMsg::IsWhitespaceOnly(const char * const pzString) diff --git a/source/common/console/c_bind.cpp b/source/common/console/c_bind.cpp index bae950673..bdee36e85 100644 --- a/source/common/console/c_bind.cpp +++ b/source/common/console/c_bind.cpp @@ -808,3 +808,216 @@ bool C_DoKey (event_t *ev, FKeyBindings *binds, FKeyBindings *doublebinds) } return false; } + +// Todo: Move to a separate file. +//============================================================================= +// +// Interface for CON scripts to get descriptions for actions +// This code can query the 64 original game functions by index. +// +//============================================================================= + +static GameFuncDesc con_gamefuncs[] = { +{"+Move_Forward", "Move_Forward"}, +{"+Move_Backward", "Move_Backward"}, +{"+Turn_Left", "Turn_Left"}, +{"+Turn_Right", "Turn_Right"}, +{"+Strafe", "Strafe"}, +{"+Fire", "Fire"}, +{"+Open", "Open"}, +{"+Run", "Run"}, +{"+Alt_Fire", "Alt_Fire"}, +{"+Jump", "Jump"}, +{"+Crouch", "Crouch"}, +{"+Look_Up", "Look_Up"}, +{"+Look_Down", "Look_Down"}, +{"+Look_Left", "Look_Left"}, +{"+Look_Right", "Look_Right"}, +{"+Strafe_Left", "Strafe_Left"}, +{"+Strafe_Right", "Strafe_Right"}, +{"+Aim_Up", "Aim_Up"}, +{"+Aim_Down", "Aim_Down"}, +{"+Weapon_1", "Weapon_1"}, +{"+Weapon_2", "Weapon_2"}, +{"+Weapon_3", "Weapon_3"}, +{"+Weapon_4", "Weapon_4"}, +{"+Weapon_5", "Weapon_5"}, +{"+Weapon_6", "Weapon_6"}, +{"+Weapon_7", "Weapon_7"}, +{"+Weapon_8", "Weapon_8"}, +{"+Weapon_9", "Weapon_9"}, +{"+Weapon_10", "Weapon_10"}, +{"+Inventory", "Inventory"}, +{"+Inventory_Left", "Inventory_Left"}, +{"+Inventory_Right", "Inventory_Right"}, +{"+Holo_Duke", "Holo_Duke"}, +{"+Jetpack", "Jetpack"}, +{"+NightVision", "NightVision"}, +{"+MedKit", "MedKit"}, +{"+TurnAround", "TurnAround"}, +{"+SendMessage", "SendMessage"}, +{"+Map", "Map"}, +{"+Shrink_Screen", "Shrink_Screen"}, +{"+Enlarge_Screen", "Enlarge_Screen"}, +{"+Center_View", "Center_View"}, +{"+Holster_Weapon", "Holster_Weapon"}, +{"+Show_Opponents_Weapon", "Show_Opponents_Weapon"}, +{"+Map_Follow_Mode", "Map_Follow_Mode"}, +{"+See_Coop_View", "See_Coop_View"}, +{"+Mouse_Aiming", "Mouse_Aiming"}, +{"+Toggle_Crosshair", "Toggle_Crosshair"}, +{"+Steroids", "Steroids"}, +{"+Quick_Kick", "Quick_Kick"}, +{"+Next_Weapon", "Next_Weapon"}, +{"+Previous_Weapon", "Previous_Weapon"}, +{"+Show_Console", "Show_Console"}, +{"+Show_DukeMatch_Scores", "Show_Scoreboard"}, +{"+Dpad_Select", "Dpad_Select"}, +{"+Dpad_Aiming", "Dpad_Aiming"}, +{"+AutoRun", "AutoRun"}, +{"+Last_Used_Weapon", "Last_Used_Weapon"}, +{"+Quick_Save", "Quick_Save"}, +{"+Quick_Load", "Quick_Load"}, +{"+Alt_Weapon", "Alt_Weapon"}, +{"+Third_Person_View", "Third_Person_View"}, +{"+Toggle_Crouch", "Toggle_Crouch"} +}; + +//============================================================================= +// +// +// +//============================================================================= + +void C_CON_SetAliases() +{ + if (g_gameType & GAMEFLAG_NAM) + { + con_gamefuncs[32].description = "Holo_Soldier"; + con_gamefuncs[33].description = "Huey"; + con_gamefuncs[48].description = "Tank_Mode"; + } + if (g_gameType & GAMEFLAG_WW2GI) + { + con_gamefuncs[32].description = "Fire_Mission"; + con_gamefuncs[33].description = ""; + con_gamefuncs[48].description = "Smokes"; + } + +} + +static FString C_CON_GetGameFuncOnKeyboard(int gameFunc) +{ + if (gameFunc >= 0 && gameFunc < countof(con_gamefuncs)) + { + auto keys = Bindings.GetKeysForCommand(con_gamefuncs[gameFunc].action); + for (auto key : keys) + { + if (key < KEY_FIRSTMOUSEBUTTON) + { + auto scan = KB_ScanCodeToString(key); + if (scan) return scan; + } + } + } + return ""; +} + +static FString C_CON_GetGameFuncOnMouse(int gameFunc) +{ + if (gameFunc >= 0 && gameFunc < countof(con_gamefuncs)) + { + auto keys = Bindings.GetKeysForCommand(con_gamefuncs[gameFunc].action); + for (auto key : keys) + { + if ((key >= KEY_FIRSTMOUSEBUTTON && key < KEY_FIRSTJOYBUTTON) || (key >= KEY_MWHEELUP && key <= KEY_MWHEELLEFT)) + { + auto scan = KB_ScanCodeToString(key); + if (scan) return scan; + } + } + } + return ""; +} + +char const* C_CON_GetGameFuncOnJoystick(int gameFunc) +{ + if (gameFunc >= 0 && gameFunc < countof(con_gamefuncs)) + { + auto keys = Bindings.GetKeysForCommand(con_gamefuncs[gameFunc].action); + for (auto key : keys) + { + if (key >= KEY_FIRSTJOYBUTTON && !(key >= KEY_MWHEELUP && key <= KEY_MWHEELLEFT)) + { + auto scan = KB_ScanCodeToString(key); + if (scan) return scan; + } + } + } + return ""; +} + +FString C_CON_GetBoundKeyForLastInput(int gameFunc) +{ + if (CONTROL_LastSeenInput == LastSeenInput::Joystick) + { + FString name = C_CON_GetGameFuncOnJoystick(gameFunc); + if (name.IsNotEmpty()) + { + return name; + } + } + + FString name = C_CON_GetGameFuncOnKeyboard(gameFunc); + if (name.IsNotEmpty()) + { + return name; + } + + name = C_CON_GetGameFuncOnMouse(gameFunc); + if (name.IsNotEmpty()) + { + return name; + } + + name = C_CON_GetGameFuncOnJoystick(gameFunc); + if (name.IsNotEmpty()) + { + return name; + } + return "UNBOUND"; +} + + +//============================================================================= +// +// +// +//============================================================================= + +void C_CON_SetButtonAlias(int num, const char *text) +{ + if (num >= 0 && num < countof(con_gamefuncs)) + { + if (con_gamefuncs[num].replaced) free((void*)con_gamefuncs[num].description); + con_gamefuncs[num].description = strdup(text); + con_gamefuncs[num].replaced = true; + } +} + +//============================================================================= +// +// +// +//============================================================================= + +void C_CON_ClearButtonAlias(int num) +{ + if (num >= 0 && num < countof(con_gamefuncs)) + { + if (con_gamefuncs[num].replaced) free((void*)con_gamefuncs[num].description); + con_gamefuncs[num].description = ""; + con_gamefuncs[num].replaced = false; + } +} + diff --git a/source/common/console/c_bind.h b/source/common/console/c_bind.h index 11f5bd6d7..babfcd5c5 100644 --- a/source/common/console/c_bind.h +++ b/source/common/console/c_bind.h @@ -116,4 +116,13 @@ struct FKeySection }; extern TArray KeySections; +struct GameFuncDesc +{ + const char *action; + const char *description; + bool replaced; +}; #endif //__C_BINDINGS_H__ + + + diff --git a/source/common/console/c_buttons.cpp b/source/common/console/c_buttons.cpp index cf2c2ba67..bbfdab768 100644 --- a/source/common/console/c_buttons.cpp +++ b/source/common/console/c_buttons.cpp @@ -48,168 +48,73 @@ struct ButtonDesc }; 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_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_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, "Turn_Around"}, - { gamefunc_SendMessage, "Send_Message"}, - { gamefunc_Map, "Map"}, + { 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, "Turn_Around"}, + { gamefunc_SendMessage, "Send_Message"}, + { gamefunc_Map, "Map"}, { gamefunc_Shrink_Screen, "Shrink_Screen"}, { gamefunc_Enlarge_Screen, "Enlarge_Screen"}, - { gamefunc_Center_View, "Center_View"}, - { gamefunc_Holster_Weapon, "Holster_Weapon"}, + { 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_Map_Follow_Mode, "Map_Follow_Mode"}, { gamefunc_See_Coop_View, "See_Coop_View"}, - { gamefunc_Mouse_Aiming, "Mouse_Aiming"}, + { 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_Steroids, "Steroids"}, + { gamefunc_Quick_Kick, "Quick_Kick"}, + { gamefunc_Next_Weapon, "Next_Weapon"}, + { gamefunc_Previous_Weapon, "Previous_Weapon"}, + { 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_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_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" }, - -}; - -static const ButtonDesc gamealiases_Duke3D[] = { - { gamefunc_BeastVision, ""}, - { gamefunc_CrystalBall, ""}, - { gamefunc_ProximityBombs, ""}, - { gamefunc_RemoteBombs, ""}, - { gamefunc_Smoke_Bomb, "" }, - { gamefunc_Gas_Bomb, "" }, - { gamefunc_Flash_Bomb, "" }, - { gamefunc_Caltrops, "" }, - -}; - -static const ButtonDesc gamealiases_Nam[] = { - { gamefunc_Holo_Duke, "Holo_Soldier"}, - { gamefunc_Jetpack, "Huey"}, - { gamefunc_Steroids, "Tank_Mode"}, - { gamefunc_Show_DukeMatch_Scores, "Show_GruntMatch_Scores"}, - { gamefunc_BeastVision, ""}, - { gamefunc_CrystalBall, ""}, - { gamefunc_ProximityBombs, ""}, - { gamefunc_RemoteBombs, ""}, - { gamefunc_Smoke_Bomb, "" }, - { gamefunc_Gas_Bomb, "" }, - { gamefunc_Flash_Bomb, "" }, - { gamefunc_Caltrops, "" }, - -}; - -static const ButtonDesc gamealiases_WW2GI[] = { - { gamefunc_Holo_Duke, "Fire Mission"}, - { gamefunc_Jetpack, ""}, - { gamefunc_Steroids, "Smokes"}, - { gamefunc_Show_DukeMatch_Scores, "Show_GIMatch_Scores"}, - { gamefunc_BeastVision, ""}, - { gamefunc_CrystalBall, ""}, - { gamefunc_ProximityBombs, ""}, - { gamefunc_RemoteBombs, ""}, - { gamefunc_Smoke_Bomb, "" }, - { gamefunc_Gas_Bomb, "" }, - { gamefunc_Flash_Bomb, "" }, - { gamefunc_Caltrops, "" }, -}; - -static const ButtonDesc gamealiases_RR[] = { - { gamefunc_Holo_Duke, "Beer"}, - { gamefunc_Jetpack, "Cow Pie"}, - { gamefunc_NightVision, "Yeehaa"}, - { gamefunc_MedKit, "Whiskey"}, - { gamefunc_Steroids, "Moonshine"}, - { gamefunc_Quick_Kick, "Pee"}, - { gamefunc_Show_DukeMatch_Scores, "Show_Scores"}, - { gamefunc_Alt_Fire, ""}, - { gamefunc_BeastVision, ""}, - { gamefunc_CrystalBall, ""}, - { gamefunc_ProximityBombs, ""}, - { gamefunc_RemoteBombs, ""}, - { gamefunc_Smoke_Bomb, "" }, - { gamefunc_Gas_Bomb, "" }, - { gamefunc_Flash_Bomb, "" }, - { gamefunc_Caltrops, "" }, -}; - -static const ButtonDesc gamealiases_Blood[] = { - { gamefunc_Holo_Duke, ""}, - { gamefunc_JumpBoots, "JumpBoots"}, - { gamefunc_Steroids, ""}, - { gamefunc_Quick_Kick, ""}, - { gamefunc_Show_DukeMatch_Scores, ""}, - { gamefunc_Alt_Weapon, ""}, - { gamefunc_Smoke_Bomb, "" }, - { gamefunc_Gas_Bomb, "" }, - { gamefunc_Flash_Bomb, "" }, - { gamefunc_Caltrops, "" }, - -}; - -static const ButtonDesc gamealiases_SW[] = { - { gamefunc_Holo_Duke, ""}, - { gamefunc_Jetpack, ""}, - { gamefunc_NightVision, ""}, - { gamefunc_MedKit, ""}, - { gamefunc_Steroids, ""}, - { gamefunc_Quick_Kick, ""}, - { gamefunc_Show_DukeMatch_Scores, ""}, - { gamefunc_Smoke_Bomb, "" }, - { gamefunc_Gas_Bomb, "" }, - { gamefunc_Flash_Bomb, "" }, - { gamefunc_Caltrops, "" }, + { gamefunc_Alt_Weapon, "Alt_Weapon"}, + { gamefunc_Third_Person_View, "Third_Person_View"}, + { gamefunc_Toggle_Crouch, "Toggle_Crouch"}, + { gamefunc_CrystalBall, "CrystalBall"}, // the following were added by Blood + { gamefunc_ProximityBombs, "ProximityBombs"}, + { gamefunc_RemoteBombs, "RemoteBombs"}, + { gamefunc_Smoke_Bomb, "Smoke_Bomb" }, + { gamefunc_Gas_Bomb, "Gas_Bomb" }, + { gamefunc_Flash_Bomb, "Flash_Bomb" }, + { gamefunc_Caltrops, "Caltrops" }, }; @@ -234,60 +139,7 @@ ButtonMap::ButtonMap() for(auto &gf : gamefuncs) { NameToNum.Insert(gf.name, gf.index); - NumToAlias[gf.index] = NumToName[gf.index] = gf.name; - } -} - -//============================================================================= -// -// -// -//============================================================================= - -void ButtonMap::SetGameAliases() -{ - // Ion Fury hacks this together from the CON script and uses the same table as Duke Nukem - if (g_gameType & (GAMEFLAG_DUKE|GAMEFLAG_FURY)) - { - for (auto& gf : gamealiases_Duke3D) - { - NumToAlias[gf.index] = gf.name; - } - } - if (g_gameType & GAMEFLAG_NAM) - { - for (auto& gf : gamealiases_Nam) - { - NumToAlias[gf.index] = gf.name; - } - } - if (g_gameType & GAMEFLAG_WW2GI) - { - for (auto& gf : gamealiases_WW2GI) - { - NumToAlias[gf.index] = gf.name; - } - } - if (g_gameType & (GAMEFLAG_RR|GAMEFLAG_RRRA)) - { - for (auto& gf : gamealiases_RR) - { - NumToAlias[gf.index] = gf.name; - } - } - if (g_gameType & GAMEFLAG_BLOOD) - { - for (auto& gf : gamealiases_Blood) - { - NumToAlias[gf.index] = gf.name; - } - } - if (g_gameType & GAMEFLAG_SW) - { - for (auto& gf : gamealiases_SW) - { - NumToAlias[gf.index] = gf.name; - } + NumToName[gf.index] = gf.name; } } @@ -304,18 +156,16 @@ int ButtonMap::ListActionCommands (const char *pattern) 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]); + Printf ("+%s\n", NumToName[i].GetChars()); count++; } if (pattern == NULL || CheckWildcards (pattern, (snprintf (matcher, countof(matcher), "-%s", NumToName[i].GetChars()), matcher))) { - Printf ("-%s\n", NumToName[i]); + Printf ("-%s\n", NumToName[i].GetChars()); count++; } } @@ -372,34 +222,6 @@ void ButtonMap::ResetButtonStates () } } -//============================================================================= -// -// -// -//============================================================================= - -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] = ""; -} - - //============================================================================= // // @@ -495,4 +317,3 @@ bool FButtonStatus::ReleaseKey (int keynum) // 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 index 3a4746673..d8829dc3b 100644 --- a/source/common/console/c_buttons.h +++ b/source/common/console/c_buttons.h @@ -46,6 +46,7 @@ enum GameFunction_t gamefunc_JumpBoots = gamefunc_Jetpack, gamefunc_NightVision, gamefunc_Night_Vision = gamefunc_NightVision, + gamefunc_BeastVision = gamefunc_NightVision, gamefunc_MedKit, gamefunc_Med_Kit = gamefunc_MedKit, gamefunc_TurnAround, @@ -66,17 +67,18 @@ enum GameFunction_t gamefunc_Quick_Kick, gamefunc_Next_Weapon, gamefunc_Previous_Weapon, - gamefunc_Show_Console, + gamefunc_Unused1, // was gamefunc_Console. Cannot be deleted thanks to CON usuing numeric indiced for addressing this list. gamefunc_Show_DukeMatch_Scores, gamefunc_Dpad_Select, gamefunc_Dpad_Aiming, gamefunc_AutoRun, gamefunc_Last_Weapon, + gamefunc_Unused2, // was quickload/quicksave + gamefunc_Unused3, gamefunc_Alt_Weapon, gamefunc_Third_Person_View, - gamefunc_See_Chase_View = gamefunc_Third_Person_View, // this was added by Blood - gamefunc_Toggle_Crouch, - gamefunc_BeastVision, + gamefunc_See_Chase_View = gamefunc_Third_Person_View, + gamefunc_Toggle_Crouch, // This is the last one used by EDuke32. gamefunc_CrystalBall, gamefunc_ProximityBombs, gamefunc_RemoteBombs, @@ -111,7 +113,6 @@ 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: @@ -131,6 +132,7 @@ public: return index > -1? &Buttons[index] : nullptr; } + // This is still in use but all cases are scheduled for termination. const char* GetButtonName(int32_t func) const { if ((unsigned)func >= (unsigned)NumButtons()) @@ -138,15 +140,6 @@ public: 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); diff --git a/source/common/gamecontrol.cpp b/source/common/gamecontrol.cpp index 29909e7c5..96fbbc2b6 100644 --- a/source/common/gamecontrol.cpp +++ b/source/common/gamecontrol.cpp @@ -29,6 +29,7 @@ #include "enet.h" #endif +void C_CON_SetAliases(); InputState inputState; void SetClipshapes(); int ShowStartupWindow(TArray &); @@ -425,7 +426,7 @@ int CONFIG_Init() } GStrings.LoadStrings(); V_InitFonts(); - buttonMap.SetGameAliases(); + C_CON_SetAliases(); Mus_Init(); InitStatistics(); M_Init(); @@ -483,7 +484,7 @@ int32_t CONFIG_GetMapBestTime(char const* const mapname, uint8_t const* const ma if (GameConfig->SetSection("MapTimes")) { auto s = GameConfig->GetValueForKey(m); - if (s) (int)strtoull(s, nullptr, 0); + if (s) return (int)strtoull(s, nullptr, 0); } return -1; } @@ -504,7 +505,6 @@ int CONFIG_SetMapBestTime(uint8_t const* const mapmd4, int32_t tm) // //========================================================================== -int32_t MouseDigitalFunctions[MAXMOUSEAXES][2]; int32_t MouseAnalogueAxes[MAXMOUSEAXES]; int32_t JoystickFunctions[MAXJOYBUTTONSANDHATS][2]; int32_t JoystickDigitalFunctions[MAXJOYAXES][2]; @@ -521,51 +521,6 @@ static const char* mouseanalogdefaults[MAXMOUSEAXES] = }; -static const char* mousedigitaldefaults[MAXMOUSEDIGITAL] = -{ -}; - -static const char* joystickdefaults[MAXJOYBUTTONSANDHATS] = -{ -"Fire", -"Strafe", -"Run", -"Open", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"", -"Aim_Down", -"Look_Right", -"Aim_Up", -"Look_Left", -}; - - static const char* joystickclickeddefaults[MAXJOYBUTTONSANDHATS] = { "", @@ -583,18 +538,6 @@ static const char* joystickanalogdefaults[MAXJOYAXES] = }; -static const char* joystickdigitaldefaults[MAXJOYDIGITAL] = -{ -"", -"", -"", -"", -"", -"", -"Run", -}; - - //========================================================================== // // @@ -658,62 +601,6 @@ void CONFIG_SetupMouse(void) void CONFIG_SetupJoystick(void) { - const char* val; - FString section = currentGame + ".ControllerSettings"; - if (!GameConfig->SetSection(section)) return; - - for (int i = 0; i < MAXJOYBUTTONSANDHATS; i++) - { - section.Format("ControllerButton%d", i); - val = GameConfig->GetValueForKey(section); - if (val) - JoystickFunctions[i][0] = buttonMap.FindButtonIndex(val); - - section.Format("ControllerButtonClicked%d", i); - val = GameConfig->GetValueForKey(section); - if (val) - JoystickFunctions[i][1] = buttonMap.FindButtonIndex(val); - } - - // map over the axes - for (int i = 0; i < MAXJOYAXES; i++) - { - section.Format("ControllerAnalogAxes%d", i); - val = GameConfig->GetValueForKey(section); - if (val) - JoystickAnalogueAxes[i] = CONFIG_AnalogNameToNum(val); - - section.Format("ControllerDigitalAxes%d_0", i); - val = GameConfig->GetValueForKey(section); - if (val) - JoystickDigitalFunctions[i][0] = buttonMap.FindButtonIndex(val); - - section.Format("ControllerDigitalAxes%d_1", i); - val = GameConfig->GetValueForKey(section); - if (val) - JoystickDigitalFunctions[i][1] = buttonMap.FindButtonIndex(val); - - section.Format("ControllerAnalogScale%d", i); - val = GameConfig->GetValueForKey(section); - if (val) - JoystickAnalogueScale[i] = (int32_t)strtoull(val, nullptr, 0); - - section.Format("ControllerAnalogInvert%d", i); - val = GameConfig->GetValueForKey(section); - if (val) - JoystickAnalogueInvert[i] = (int32_t)strtoull(val, nullptr, 0); - - section.Format("ControllerAnalogDead%d", i); - val = GameConfig->GetValueForKey(section); - if (val) - JoystickAnalogueDead[i] = (int32_t)strtoull(val, nullptr, 0); - - section.Format("ControllerAnalogSaturate%d", i); - val = GameConfig->GetValueForKey(section); - if (val) - JoystickAnalogueSaturate[i] = (int32_t)strtoull(val, nullptr, 0); - } - for (int i = 0; i < MAXJOYAXES; i++) { CONTROL_MapAnalogAxis(i, JoystickAnalogueAxes[i], controldevice_joystick); @@ -877,14 +764,12 @@ void CONFIG_SetGameControllerDefaultsStandard() for (auto const& button : buttons) button.apply(); - /* - if (FURY) + if (g_gameType & GAMEFLAG_FURY) { for (auto const& button : buttonsFury) button.apply(); } else - */ { for (auto const& button : buttonsDuke) button.apply(); @@ -938,14 +823,12 @@ void CONFIG_SetGameControllerDefaultsPro() for (auto const& button : buttons) button.apply(); -#if 0 // ouch... - if (FURY) + if (g_gameType & GAMEFLAG_FURY) { for (auto const& button : buttonsFury) button.apply(); } else -#endif { for (auto const& button : buttonsDuke) button.apply(); @@ -955,99 +838,14 @@ void CONFIG_SetGameControllerDefaultsPro() digitalAxis.apply(); } -FString CONFIG_GetGameFuncOnKeyboard(int gameFunc) -{ - auto binding = buttonMap.GetButtonAlias(gameFunc); - auto keys = Bindings.GetKeysForCommand(binding); - for(auto key : keys) - { - if (key < KEY_FIRSTMOUSEBUTTON) - { - auto scan = KB_ScanCodeToString(key); - if (scan) return scan; - - } - } - return ""; -} - -FString CONFIG_GetGameFuncOnMouse(int gameFunc) -{ - auto binding = buttonMap.GetButtonAlias(gameFunc); - auto keys = Bindings.GetKeysForCommand(binding); - for (auto key : keys) - { - if ((key >= KEY_FIRSTMOUSEBUTTON && key < KEY_FIRSTJOYBUTTON) || (key >= KEY_MWHEELUP && key <= KEY_MWHEELLEFT)) - { - auto scan = KB_ScanCodeToString(key); - if (scan) return scan; - - } - } - return ""; -} - -char const* CONFIG_GetGameFuncOnJoystick(int gameFunc) -{ - auto binding = buttonMap.GetButtonAlias(gameFunc); - auto keys = Bindings.GetKeysForCommand(binding); - for (auto key : keys) - { - if (key >= KEY_FIRSTJOYBUTTON && !(key >= KEY_MWHEELUP && key <= KEY_MWHEELLEFT)) - { - auto scan = KB_ScanCodeToString(key); - if (scan) return scan; - } - } - return ""; -} - -// FIXME: Consider the mouse as well! -FString CONFIG_GetBoundKeyForLastInput(int gameFunc) -{ - if (CONTROL_LastSeenInput == LastSeenInput::Joystick) - { - FString name = CONFIG_GetGameFuncOnJoystick(gameFunc); - if (name.IsNotEmpty()) - { - return name; - } - } - - FString name = CONFIG_GetGameFuncOnKeyboard(gameFunc); - if (name.IsNotEmpty()) - { - return name; - } - - name = CONFIG_GetGameFuncOnMouse(gameFunc); - if (name.IsNotEmpty()) - { - return name; - } - - name = CONFIG_GetGameFuncOnJoystick(gameFunc); - if (name.IsNotEmpty()) - { - return name; - } - return "UNBOUND"; -} - void CONFIG_InitMouseAndController() { - memset(MouseDigitalFunctions, -1, sizeof(MouseDigitalFunctions)); memset(JoystickFunctions, -1, sizeof(JoystickFunctions)); memset(JoystickDigitalFunctions, -1, sizeof(JoystickDigitalFunctions)); for (int i = 0; i < MAXMOUSEAXES; i++) { - 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); - MouseAnalogueAxes[i] = CONFIG_AnalogNameToNum(mouseanalogdefaults[i]); CONTROL_MapAnalogAxis(i, MouseAnalogueAxes[i], controldevice_mouse); } @@ -1074,20 +872,6 @@ void CONFIG_WriteControllerSettings() { FString section = currentGame + ".ControllerSettings"; GameConfig->SetSection(section); - for (int dummy = 0; dummy < MAXJOYBUTTONSANDHATS; dummy++) - { - if (buttonMap.GetButtonName(JoystickFunctions[dummy][0])) - { - buf.Format("ControllerButton%d", dummy); - GameConfig->SetValueForKey(buf, buttonMap.GetButtonName(JoystickFunctions[dummy][0])); - } - - if (buttonMap.GetButtonName(JoystickFunctions[dummy][1])) - { - buf.Format("ControllerButtonClicked%d", dummy); - GameConfig->SetValueForKey(buf, buttonMap.GetButtonName(JoystickFunctions[dummy][1])); - } - } for (int dummy = 0; dummy < MAXJOYAXES; dummy++) { if (CONFIG_AnalogNumToName(JoystickAnalogueAxes[dummy])) @@ -1096,12 +880,6 @@ void CONFIG_WriteControllerSettings() GameConfig->SetValueForKey(buf, CONFIG_AnalogNumToName(JoystickAnalogueAxes[dummy])); } - if (buttonMap.GetButtonName(JoystickDigitalFunctions[dummy][0])) - { - buf.Format("ControllerDigitalAxes%d_0", dummy); - GameConfig->SetValueForKey(buf, buttonMap.GetButtonName(JoystickDigitalFunctions[dummy][0])); - } - if (buttonMap.GetButtonName(JoystickDigitalFunctions[dummy][1])) { buf.Format("ControllerDigitalAxes%d_1", dummy); diff --git a/source/common/gamecontrol.h b/source/common/gamecontrol.h index 4ef9187cd..740f3de80 100644 --- a/source/common/gamecontrol.h +++ b/source/common/gamecontrol.h @@ -38,19 +38,6 @@ void CONFIG_SetDefaultKeys(const char *defbinds); #define DEFAULTJOYSTICKANALOGUESATURATE 9500 -extern int32_t MouseDigitalFunctions[MAXMOUSEAXES][2]; -extern int32_t MouseAnalogueAxes[MAXMOUSEAXES]; -extern int32_t JoystickFunctions[MAXJOYBUTTONSANDHATS][2]; -extern int32_t JoystickDigitalFunctions[MAXJOYAXES][2]; -extern int32_t JoystickAnalogueAxes[MAXJOYAXES]; -extern int32_t JoystickAnalogueScale[MAXJOYAXES]; -extern int32_t JoystickAnalogueDead[MAXJOYAXES]; -extern int32_t JoystickAnalogueSaturate[MAXJOYAXES]; -extern int32_t JoystickAnalogueInvert[MAXJOYAXES]; - -int32_t CONFIG_AnalogNameToNum(const char* func); -const char* CONFIG_AnalogNumToName(int32_t func); -void CONFIG_SetupMouse(void); void CONFIG_SetupJoystick(void); void CONFIG_WriteControllerSettings(); void CONFIG_InitMouseAndController(); @@ -59,8 +46,6 @@ void CONFIG_SetGameControllerDefaultsStandard(); void CONFIG_SetGameControllerDefaultsPro(); void CONFIG_SetGameControllerDefaultsClear(); -FString CONFIG_GetBoundKeyForLastInput(int gameFunc); - extern FStringCVar* const CombatMacros[]; void CONFIG_ReadCombatMacros(); diff --git a/source/duke3d/src/gamedef.cpp b/source/duke3d/src/gamedef.cpp index 62d4b52dd..3a1c87e58 100644 --- a/source/duke3d/src/gamedef.cpp +++ b/source/duke3d/src/gamedef.cpp @@ -43,6 +43,9 @@ BEGIN_DUKE_NS #define LINE_NUMBER (g_lineNumber << 12) +void C_CON_SetButtonAlias(int num, const char* text); +void C_CON_ClearButtonAlias(int num); + int32_t g_scriptVersion = 13; // 13 = 1.3D-style CON files, 14 = 1.4/1.5 style CON files char g_scriptFileName[BMAX_PATH] = "(none)"; // file we're currently compiling @@ -2197,11 +2200,14 @@ void C_InitQuotes(void) #ifdef EDUKE32_TOUCH_DEVICES apStrings[QUOTE_DEAD] = 0; #else - // WTF ?!? - 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); + auto openkeys = Bindings.GetKeysForCommand("+open"); + if (openkeys.Size()) + { + auto OpenGameFunc = C_NameKeys(openkeys.Data(), 1); + C_ReplaceQuoteSubstring(QUOTE_DEAD, "SPACE", OpenGameFunc); + C_ReplaceQuoteSubstring(QUOTE_DEAD, "OPEN", OpenGameFunc); + C_ReplaceQuoteSubstring(QUOTE_DEAD, "USE", OpenGameFunc); + } #endif // most of these are based on Blood, obviously diff --git a/source/duke3d/src/gameexec.cpp b/source/duke3d/src/gameexec.cpp index 10be274c7..726a0f30d 100644 --- a/source/duke3d/src/gameexec.cpp +++ b/source/duke3d/src/gameexec.cpp @@ -55,6 +55,9 @@ BEGIN_DUKE_NS vmstate_t vm; +FString C_CON_GetBoundKeyForLastInput(int gameFunc); + + #if !defined LUNATIC int32_t g_tw; int32_t g_currentEvent = -1; @@ -3684,7 +3687,7 @@ badindex: static char const s_KeyboardFormat[] = "[%s]"; static char const s_JoystickFormat[] = "(%s)"; - auto binding = CONFIG_GetBoundKeyForLastInput(gameFunc); + auto binding = C_CON_GetBoundKeyForLastInput(gameFunc); if (binding.Len()) snprintf(apStrings[quoteIndex], MAXQUOTELEN, "(%s)", binding.GetChars()); dispatch(); } diff --git a/source/rr/src/gamedef.cpp b/source/rr/src/gamedef.cpp index a854e7146..226be8da0 100644 --- a/source/rr/src/gamedef.cpp +++ b/source/rr/src/gamedef.cpp @@ -937,10 +937,14 @@ void C_InitQuotes(void) #ifdef EDUKE32_TOUCH_DEVICES apStrings[QUOTE_DEAD] = 0; #else - 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); + auto openkeys = Bindings.GetKeysForCommand("+open"); + if (openkeys.Size()) + { + auto OpenGameFunc = C_NameKeys(openkeys.Data(), 1); + C_ReplaceQuoteSubstring(QUOTE_DEAD, "SPACE", OpenGameFunc); + C_ReplaceQuoteSubstring(QUOTE_DEAD, "OPEN", OpenGameFunc); + C_ReplaceQuoteSubstring(QUOTE_DEAD, "USE", OpenGameFunc); + } #endif // most of these are based on Blood, obviously