From 64b05b6f06a5b7473cf2f266593384dcb1856acf Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sun, 2 Apr 2023 18:26:22 +1000 Subject: [PATCH] - Move remaining CCMDs and non-inputstate related items to `gameinput.cpp`. --- source/core/console/d_event.cpp | 2 +- source/core/gameinput.cpp | 95 ++++++++++++++++++++++++++++++ source/core/gameinput.h | 2 + source/core/inputstate.cpp | 100 -------------------------------- source/core/inputstate.h | 1 - 5 files changed, 98 insertions(+), 102 deletions(-) diff --git a/source/core/console/d_event.cpp b/source/core/console/d_event.cpp index d454ab056..468d619e0 100644 --- a/source/core/console/d_event.cpp +++ b/source/core/console/d_event.cpp @@ -37,7 +37,7 @@ #include "d_event.h" #include "c_console.h" #include "d_gui.h" -#include "inputstate.h" +#include "gameinput.h" #include "razemenu.h" #include "gamestate.h" #include "gamecontrol.h" diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index 671a381ba..a239a7206 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -24,6 +24,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "menu.h" #include "gamestate.h" #include "gameinput.h" +#include "d_net.h" EXTERN_CVAR(Float, m_sensitivity_x) EXTERN_CVAR(Float, m_yaw) @@ -45,6 +46,8 @@ static InputPacket inputBuffer{}; static double turnheldtime = 0; static int WeaponToSend = 0; static int dpad_lock = 0; +ESyncBits ActionsToSend = 0; +bool crouch_toggle = false; static constexpr double YAW_TURNSPEEDS[3] = { 41.1987304, 156.555175, 272.24121 }; static constexpr double YAW_PREAMBLESCALE = YAW_TURNSPEEDS[0] / YAW_TURNSPEEDS[1]; @@ -341,6 +344,8 @@ static void ApplyGlobalInput(HIDInput* const hidInput) void clearLocalInputBuffer() { inputBuffer = {}; + crouch_toggle = false; + ActionsToSend = 0; WeaponToSend = 0; dpad_lock = 0; resetTurnHeldAmt(); @@ -598,3 +603,93 @@ CCMD(weapalt) { WeaponToSend = WeaponSel_Alt; // Only used by SW - should also be made usable by Blood ans Duke which put multiple weapons in the same slot. } + +CCMD(useitem) +{ + const int max = isExhumed() ? 6 : isSWALL() ? 7 : isBlood() ? 4 : 5; + + if (argv.argc() != 2) + { + Printf("useitem : activates an inventory item (1-%d)", max); + return; + } + + const auto slot = atoi(argv[1]); + + if (slot >= 1 && slot <= max) + { + ActionsToSend |= ESyncBits::FromInt(SB_ITEM_BIT_1 << (slot - 1)); + } +} + +CCMD(invprev) +{ + ActionsToSend |= SB_INVPREV; +} + +CCMD(invnext) +{ + ActionsToSend |= SB_INVNEXT; +} + +CCMD(invuse) +{ + ActionsToSend |= SB_INVUSE; +} + +CCMD(centerview) +{ + ActionsToSend |= SB_CENTERVIEW; +} + +CCMD(turnaround) +{ + ActionsToSend |= SB_TURNAROUND; +} + +CCMD(holsterweapon) +{ + ActionsToSend |= SB_HOLSTER; +} + +CCMD(warptocoords) +{ + if (netgame) + { + Printf("warptocoords cannot be used in multiplayer.\n"); + return; + } + if (argv.argc() < 4) + { + Printf("warptocoords [x] [y] [z] [yaw] (optional) [pitch] (optional): warps the player to the specified coordinates\n"); + return; + } + if (gamestate != GS_LEVEL) + { + Printf("warptocoords: must be in a level\n"); + return; + } + + if (const auto pActor = gi->getConsoleActor()) + { + pActor->spr.pos = DVector3(atof(argv[1]), atof(argv[2]), atof(argv[3])); + if (argv.argc() > 4) pActor->spr.Angles.Yaw = DAngle::fromDeg(atof(argv[4])); + if (argv.argc() > 5) pActor->spr.Angles.Pitch = DAngle::fromDeg(atof(argv[5])); + pActor->backuploc(); + } +} + +CCMD(third_person_view) +{ + gi->ToggleThirdPerson(); +} + +CCMD(coop_view) +{ + gi->SwitchCoopView(); +} + +CCMD(show_weapon) +{ + gi->ToggleShowWeapon(); +} diff --git a/source/core/gameinput.h b/source/core/gameinput.h index b7fef6434..77d403ee4 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -3,6 +3,8 @@ #include "serializer.h" #include "gamefuncs.h" +extern ESyncBits ActionsToSend; + struct PlayerAngles { // Player viewing angles, separate from the camera. diff --git a/source/core/inputstate.cpp b/source/core/inputstate.cpp index 80d50ba02..ef1b1ecd6 100644 --- a/source/core/inputstate.cpp +++ b/source/core/inputstate.cpp @@ -41,13 +41,9 @@ #include"packet.h" #include "gamecontrol.h" #include "gamestruct.h" -#include "d_net.h" #include "gamestate.h" #include "gameinput.h" -ESyncBits ActionsToSend = 0; -bool crouch_toggle; - // Mouse speeds CVAR(Float, m_pitch, 1.f, CVAR_GLOBALCONFIG | CVAR_ARCHIVE) CVAR(Float, m_yaw, 1.f, CVAR_GLOBALCONFIG | CVAR_ARCHIVE) @@ -132,8 +128,6 @@ void InputState::ClearAllInput() { memset(KeyStatus, 0, sizeof(KeyStatus)); AnyKeyStatus = false; - ActionsToSend = 0; - crouch_toggle = false; buttonMap.ResetButtonStates(); // this is important. If all input is cleared, the buttons must be cleared as well. clearLocalInputBuffer(); // also clear game local input state. } @@ -219,97 +213,3 @@ void SetupGameButtons() }; buttonMap.SetButtons(actions, NUM_ACTIONS); } - -//========================================================================== -// -// -// -//========================================================================== - -CCMD(useitem) -{ - int max = (g_gameType & GAMEFLAG_PSEXHUMED)? 6 : isSWALL()? 7 : isBlood() ? 4 : 5; - if (argv.argc() != 2) - { - Printf("useitem : activates an inventory item (1-%d)", max); - return; - } - - auto slot = atoi(argv[1]); - if (slot >= 1 && slot <= max) - { - ActionsToSend |= ESyncBits::FromInt(SB_ITEM_BIT_1 << (slot - 1)); - } -} - -CCMD(invprev) -{ - ActionsToSend |= SB_INVPREV; -} - -CCMD(invnext) -{ - ActionsToSend |= SB_INVNEXT; -} - -CCMD(invuse) -{ - ActionsToSend |= SB_INVUSE; -} - -CCMD(centerview) -{ - ActionsToSend |= SB_CENTERVIEW; -} - -CCMD(turnaround) -{ - ActionsToSend |= SB_TURNAROUND; -} - -CCMD(holsterweapon) -{ - ActionsToSend |= SB_HOLSTER; -} - -CCMD(warptocoords) -{ - if (netgame) - { - Printf("warptocoords cannot be used in multiplayer.\n"); - return; - } - if (argv.argc() < 4) - { - Printf("warptocoords [x] [y] [z] [yaw] (optional) [pitch] (optional): warps the player to the specified coordinates\n"); - return; - } - if (gamestate != GS_LEVEL) - { - Printf("warptocoords: must be in a level\n"); - return; - } - - if (const auto pActor = gi->getConsoleActor()) - { - pActor->spr.pos = DVector3(atof(argv[1]), atof(argv[2]), atof(argv[3])); - if (argv.argc() > 4) pActor->spr.Angles.Yaw = DAngle::fromDeg(atof(argv[4])); - if (argv.argc() > 5) pActor->spr.Angles.Pitch = DAngle::fromDeg(atof(argv[5])); - pActor->backuploc(); - } -} - -CCMD(third_person_view) -{ - gi->ToggleThirdPerson(); -} - -CCMD(coop_view) -{ - gi->SwitchCoopView(); -} - -CCMD(show_weapon) -{ - gi->ToggleShowWeapon(); -} diff --git a/source/core/inputstate.h b/source/core/inputstate.h index 721d6e1fc..0c20152e5 100644 --- a/source/core/inputstate.h +++ b/source/core/inputstate.h @@ -96,7 +96,6 @@ enum GameFunction_t }; void SetupGameButtons(); -extern ESyncBits ActionsToSend; inline float backendinputscale() {