From 4ef0d20e0e09157d0bf6176bb40b6282a3d6087b Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sat, 7 Nov 2020 13:44:25 +1100 Subject: [PATCH] - gameinput.cpp: Consolidate `checkCrouchToggle()` from Duke with discrete implementations from Blood in 7c8efde38c0352310e5680d7a2e4f3eb94a3ed82 and Exhumed in 032db82f8221347a5bf40bf217bc5f8bcb1f4b17 to unify the functionality. --- source/blood/src/controls.cpp | 14 +------------- source/core/gameinput.cpp | 25 ++++++++++++++++++++++++ source/core/gameinput.h | 2 +- source/exhumed/src/input.cpp | 14 +------------- source/games/duke/src/input.cpp | 34 ++++++--------------------------- source/games/duke/src/types.h | 2 +- 6 files changed, 35 insertions(+), 56 deletions(-) diff --git a/source/blood/src/controls.cpp b/source/blood/src/controls.cpp index f6dc157ea..c2784f905 100644 --- a/source/blood/src/controls.cpp +++ b/source/blood/src/controls.cpp @@ -50,19 +50,7 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput) processMovement(&input, &gInput, hidInput, scaleAdjust); // Handle crouch toggling. - if (buttonMap.ButtonDown(gamefunc_Toggle_Crouch) || pPlayer->crouch_toggle) - { - gInput.actions |= SB_CROUCH; - } - if (buttonMap.ButtonDown(gamefunc_Toggle_Crouch)) - { - pPlayer->crouch_toggle = !pPlayer->crouch_toggle; - buttonMap.ClearButton(gamefunc_Toggle_Crouch); - } - if (buttonMap.ButtonDown(gamefunc_Crouch) || buttonMap.ButtonDown(gamefunc_Jump)) - { - pPlayer->crouch_toggle = false; - } + checkCrouchToggle(&gInput, &pPlayer->crouch_toggle); if (!cl_syncinput && gamestate == GS_LEVEL) { diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index 431b8c720..eb7cbe8b2 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -353,6 +353,31 @@ void applylook(PlayerAngle* angle, float const avel, ESyncBits* actions, double } } +//--------------------------------------------------------------------------- +// +// Crouch toggle functionality used within Duke/RR, Blood and Exhumed. +// +//--------------------------------------------------------------------------- + +void checkCrouchToggle(InputPacket* inputBuffer, bool* crouch_toggle, bool const crouchable, bool const forceoff) +{ + if (buttonMap.ButtonDown(gamefunc_Toggle_Crouch) || *crouch_toggle) + { + inputBuffer->actions |= SB_CROUCH; + } + + if (buttonMap.ButtonDown(gamefunc_Toggle_Crouch)) + { + *crouch_toggle = !*crouch_toggle && crouchable; + + if (crouchable) + buttonMap.ClearButton(gamefunc_Toggle_Crouch); + } + + if (buttonMap.ButtonDown(gamefunc_Crouch) || buttonMap.ButtonDown(gamefunc_Jump) || forceoff) + *crouch_toggle = false; +} + FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngle& w, PlayerAngle* def) { if (arc.BeginObject(keyname)) diff --git a/source/core/gameinput.h b/source/core/gameinput.h index 23f21659a..c8617dcc0 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -195,4 +195,4 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerHorizon& w, void processMovement(InputPacket* currInput, InputPacket* inputBuffer, ControlInfo* const hidInput, double const scaleAdjust, int const drink_amt = 0, bool const allowstrafe = true, double const turnscale = 1); void sethorizon(fixedhoriz* horiz, float const horz, ESyncBits* actions, double const scaleAdjust); void applylook(PlayerAngle* angle, float const avel, ESyncBits* actions, double const scaleAdjust, bool const crouching); - +void checkCrouchToggle(InputPacket* inputBuffer, bool* crouch_toggle, bool const crouchable = true, bool const forceoff = false); diff --git a/source/exhumed/src/input.cpp b/source/exhumed/src/input.cpp index 73b12f5bf..83f807924 100644 --- a/source/exhumed/src/input.cpp +++ b/source/exhumed/src/input.cpp @@ -121,19 +121,7 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput) } // Handle crouch toggling. - if (buttonMap.ButtonDown(gamefunc_Toggle_Crouch) || pPlayer->crouch_toggle) - { - localInput.actions |= SB_CROUCH; - } - if (buttonMap.ButtonDown(gamefunc_Toggle_Crouch)) - { - pPlayer->crouch_toggle = !pPlayer->crouch_toggle; - buttonMap.ClearButton(gamefunc_Toggle_Crouch); - } - if (buttonMap.ButtonDown(gamefunc_Crouch) || buttonMap.ButtonDown(gamefunc_Jump)) - { - pPlayer->crouch_toggle = false; - } + checkCrouchToggle(&localInput, &pPlayer->crouch_toggle); if (!cl_syncinput) { diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index e85ddd888..af615b5fe 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -536,38 +536,11 @@ static void processInputBits(player_struct *p, ControlInfo* const hidInput) if (buttonMap.ButtonDown(gamefunc_Quick_Kick)) // this shares a bit with another function so cannot be in the common code. loc.actions |= SB_QUICK_KICK; - if (buttonMap.ButtonDown(gamefunc_Toggle_Crouch) || p->crouch_toggle) - { - loc.actions |= SB_CROUCH; - } if ((isRR() && p->drink_amt > 88)) loc.actions |= SB_LOOK_LEFT; if ((isRR() && p->drink_amt > 99)) loc.actions |= SB_LOOK_DOWN; } } -//--------------------------------------------------------------------------- -// -// split off so that it can later be integrated into the other games more easily. -// -//--------------------------------------------------------------------------- - -static void checkCrouchToggle(player_struct* p) -{ - int const sectorLotag = p->cursectnum != -1 ? sector[p->cursectnum].lotag : 0; - int const crouchable = sectorLotag != ST_2_UNDERWATER && (sectorLotag != ST_1_ABOVE_WATER || p->spritebridge); - - if (buttonMap.ButtonDown(gamefunc_Toggle_Crouch)) - { - p->crouch_toggle = !p->crouch_toggle && crouchable; - - if (crouchable) - buttonMap.ClearButton(gamefunc_Toggle_Crouch); - } - - if (buttonMap.ButtonDown(gamefunc_Crouch) || buttonMap.ButtonDown(gamefunc_Jump) || p->jetpack_on || (!crouchable && p->on_ground)) - p->crouch_toggle = 0; -} - //--------------------------------------------------------------------------- // // @@ -900,7 +873,12 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput) { processInputBits(p, hidInput); processMovement(&input, &loc, hidInput, scaleAdjust, p->drink_amt); - checkCrouchToggle(p); + + // Handle crouch toggling. + int const sectorLotag = p->cursectnum != -1 ? sector[p->cursectnum].lotag : 0; + bool const crouchable = sectorLotag != ST_2_UNDERWATER && (sectorLotag != ST_1_ABOVE_WATER || p->spritebridge); + checkCrouchToggle(&loc, &p->crouch_toggle, crouchable, p->jetpack_on || (!crouchable && p->on_ground)); + FinalizeInput(myconnectindex, input, false); } diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index 0d0aa363f..a30410e20 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -278,7 +278,7 @@ struct player_struct double vehForwardScale, vehReverseScale, MotoSpeed; bool vehTurnLeft, vehTurnRight; - int8_t crouch_toggle; + bool crouch_toggle; // input stuff. InputPacket sync;