mirror of
https://github.com/ZDoom/Raze.git
synced 2024-11-15 00:42:08 +00:00
- gameinput.cpp: Consolidate checkCrouchToggle()
from Duke with discrete implementations from Blood in 7c8efde38c
and Exhumed in 032db82f82
to unify the functionality.
This commit is contained in:
parent
032db82f82
commit
4ef0d20e0e
6 changed files with 35 additions and 56 deletions
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue