- inputstate.cpp: Move checkCrouchToggle() from gameinput.ccp into ApplyGlobalInput() and use static bool for crouch toggling vs. game-side bool.

This commit is contained in:
Mitchell Richters 2020-11-07 18:16:16 +11:00
parent a153ebab7e
commit 6e3d414b3c
18 changed files with 26 additions and 60 deletions

View file

@ -49,9 +49,6 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput)
ApplyGlobalInput(gInput, hidInput); ApplyGlobalInput(gInput, hidInput);
processMovement(&input, &gInput, hidInput, scaleAdjust); processMovement(&input, &gInput, hidInput, scaleAdjust);
// Handle crouch toggling.
checkCrouchToggle(&gInput, &pPlayer->crouch_toggle);
if (!cl_syncinput && gamestate == GS_LEVEL) if (!cl_syncinput && gamestate == GS_LEVEL)
{ {
// Perform unsynchronised angle/horizon if not dead. // Perform unsynchronised angle/horizon if not dead.

View file

@ -183,7 +183,6 @@ struct PLAYER
int player_par; int player_par;
int nWaterPal; int nWaterPal;
POSTURE pPosture[kModeMax][kPostureMax]; POSTURE pPosture[kModeMax][kPostureMax];
bool crouch_toggle;
}; };
struct PROFILE struct PROFILE

View file

@ -353,31 +353,6 @@ 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) FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerAngle& w, PlayerAngle* def)
{ {
if (arc.BeginObject(keyname)) if (arc.BeginObject(keyname))

View file

@ -195,4 +195,3 @@ 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 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 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 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);

View file

@ -327,8 +327,9 @@ CCMD(pause)
} }
static bool crouch_toggle;
void ApplyGlobalInput(InputPacket& input, ControlInfo* hidInput) void ApplyGlobalInput(InputPacket& input, ControlInfo* hidInput, bool const crouchable, bool const disableToggle)
{ {
if (WeaponToSend != 0) input.setNewWeapon(WeaponToSend); if (WeaponToSend != 0) input.setNewWeapon(WeaponToSend);
WeaponToSend = 0; WeaponToSend = 0;
@ -366,9 +367,18 @@ void ApplyGlobalInput(InputPacket& input, ControlInfo* hidInput)
if (buttonMap.ButtonDown(gamefunc_Jump)) if (buttonMap.ButtonDown(gamefunc_Jump))
input.actions |= SB_JUMP; input.actions |= SB_JUMP;
if (buttonMap.ButtonDown(gamefunc_Crouch)) if (buttonMap.ButtonDown(gamefunc_Crouch) || buttonMap.ButtonDown(gamefunc_Toggle_Crouch) || crouch_toggle)
input.actions |= SB_CROUCH; input.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) || disableToggle)
crouch_toggle = false;
if (buttonMap.ButtonDown(gamefunc_Fire)) if (buttonMap.ButtonDown(gamefunc_Fire))
input.actions |= SB_FIRE; input.actions |= SB_FIRE;

View file

@ -102,6 +102,6 @@ enum GameFunction_t
}; };
void SetupGameButtons(); void SetupGameButtons();
void ApplyGlobalInput(InputPacket& input, ControlInfo* const hidInput); void ApplyGlobalInput(InputPacket& input, ControlInfo* const hidInput, bool const crouchable = true, bool const disableToggle = false);
extern ESyncBits ActionsToSend; extern ESyncBits ActionsToSend;
double InputScale(); double InputScale();

View file

@ -120,9 +120,6 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput)
processMovement(&input, &localInput, hidInput, scaleAdjust); processMovement(&input, &localInput, hidInput, scaleAdjust);
} }
// Handle crouch toggling.
checkCrouchToggle(&localInput, &pPlayer->crouch_toggle);
if (!cl_syncinput) if (!cl_syncinput)
{ {
if (!nFreeze) if (!nFreeze)

View file

@ -75,8 +75,6 @@ struct Player
PlayerHorizon horizon; PlayerHorizon horizon;
PlayerAngle angle; PlayerAngle angle;
vec3_t opos; vec3_t opos;
bool crouch_toggle;
}; };
extern short PlayerCount; extern short PlayerCount;

View file

@ -2080,7 +2080,7 @@ void movetransports_d(void)
if (onfloorz == 0 && abs(spr->z - ps[p].posz) < 6144) if (onfloorz == 0 && abs(spr->z - ps[p].posz) < 6144)
if ((ps[p].jetpack_on == 0) || (ps[p].jetpack_on && (PlayerInput(p, SB_JUMP))) || if ((ps[p].jetpack_on == 0) || (ps[p].jetpack_on && (PlayerInput(p, SB_JUMP))) ||
(ps[p].jetpack_on && (PlayerInput(p, SB_CROUCH) ^ !!ps[p].crouch_toggle))) (ps[p].jetpack_on && PlayerInput(p, SB_CROUCH)))
{ {
ps[p].oposx = ps[p].posx += Owner->s.x - spr->x; ps[p].oposx = ps[p].posx += Owner->s.x - spr->x;
ps[p].oposy = ps[p].posy += Owner->s.y - spr->y; ps[p].oposy = ps[p].posy += Owner->s.y - spr->y;

View file

@ -2390,7 +2390,7 @@ int ParseState::parse(void)
s = g_sp->xvel; s = g_sp->xvel;
// sigh.. this was yet another place where number literals were used as bit masks for every single value, making the code totally unreadable. // sigh.. this was yet another place where number literals were used as bit masks for every single value, making the code totally unreadable.
if( (l& pducking) && ps[g_p].on_ground && (PlayerInput(g_p, SB_CROUCH) ^ !!(ps[g_p].crouch_toggle) )) if( (l& pducking) && ps[g_p].on_ground && PlayerInput(g_p, SB_CROUCH))
j = 1; j = 1;
else if( (l& pfalling) && ps[g_p].jumping_counter == 0 && !ps[g_p].on_ground && ps[g_p].poszv > 2048 ) else if( (l& pfalling) && ps[g_p].jumping_counter == 0 && !ps[g_p].on_ground && ps[g_p].poszv > 2048 )
j = 1; j = 1;

View file

@ -522,7 +522,12 @@ enum
static void processInputBits(player_struct *p, ControlInfo* const hidInput) static void processInputBits(player_struct *p, ControlInfo* const hidInput)
{ {
ApplyGlobalInput(loc, hidInput); // Set-up crouch bools.
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);
bool const disableToggle = p->jetpack_on || (!crouchable && p->on_ground) || (isRRRA() && (p->OnMotorcycle || p->OnBoat));
ApplyGlobalInput(loc, hidInput, crouchable, disableToggle);
if (isRR() && (loc.actions & SB_CROUCH)) loc.actions &= ~SB_JUMP; if (isRR() && (loc.actions & SB_CROUCH)) loc.actions &= ~SB_JUMP;
if (p->OnMotorcycle || p->OnBoat) if (p->OnMotorcycle || p->OnBoat)
@ -859,7 +864,6 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput)
if (isRRRA() && (p->OnMotorcycle || p->OnBoat)) if (isRRRA() && (p->OnMotorcycle || p->OnBoat))
{ {
p->crouch_toggle = 0;
processInputBits(p, hidInput); processInputBits(p, hidInput);
processVehicleInput(p, hidInput, input, scaleAdjust); processVehicleInput(p, hidInput, input, scaleAdjust);
FinalizeInput(myconnectindex, input, true); FinalizeInput(myconnectindex, input, true);
@ -873,12 +877,6 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput)
{ {
processInputBits(p, hidInput); processInputBits(p, hidInput);
processMovement(&input, &loc, hidInput, scaleAdjust, p->drink_amt); processMovement(&input, &loc, hidInput, scaleAdjust, p->drink_amt);
// 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); FinalizeInput(myconnectindex, input, false);
} }
@ -889,7 +887,7 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput)
// Do these in the same order as the old code. // Do these in the same order as the old code.
calcviewpitch(p, scaleAdjust); calcviewpitch(p, scaleAdjust);
processavel(p, &input.avel); processavel(p, &input.avel);
applylook(&p->angle, input.avel, &p->sync.actions, scaleAdjust, p->crouch_toggle || p->sync.actions & SB_CROUCH); applylook(&p->angle, input.avel, &p->sync.actions, scaleAdjust, p->sync.actions & SB_CROUCH);
sethorizon(&p->horizon.horiz, input.horz, &p->sync.actions, scaleAdjust); sethorizon(&p->horizon.horiz, input.horz, &p->sync.actions, scaleAdjust);
} }

View file

@ -2892,7 +2892,7 @@ void processinput_d(int snum)
// may still be needed later for demo recording // may still be needed later for demo recording
processavel(p, &sb_avel); processavel(p, &sb_avel);
applylook(&p->angle, sb_avel, &p->sync.actions, 1, p->crouch_toggle || actions & SB_CROUCH); applylook(&p->angle, sb_avel, &p->sync.actions, 1, actions & SB_CROUCH);
} }
if (p->spritebridge == 0) if (p->spritebridge == 0)

View file

@ -3635,7 +3635,7 @@ void processinput_r(int snum)
// may still be needed later for demo recording // may still be needed later for demo recording
processavel(p, &sb_avel); processavel(p, &sb_avel);
applylook(&p->angle, sb_avel, &p->sync.actions, 1, p->crouch_toggle || actions & SB_CROUCH); applylook(&p->angle, sb_avel, &p->sync.actions, 1, actions & SB_CROUCH);
apply_seasick(p, 1); apply_seasick(p, 1);
} }

View file

@ -291,7 +291,6 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, player_struct& w,
("moto_on_oil", w.moto_on_oil) ("moto_on_oil", w.moto_on_oil)
("moto_on_mud", w.moto_on_mud) ("moto_on_mud", w.moto_on_mud)
// new stuff // new stuff
("crouch_toggle", w.crouch_toggle)
("actions", w.sync.actions) ("actions", w.sync.actions)
.EndObject(); .EndObject();
@ -305,7 +304,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, player_struct& w,
w.okickback_pic = w.kickback_pic; w.okickback_pic = w.kickback_pic;
w.orandom_club_frame = w.random_club_frame; w.orandom_club_frame = w.random_club_frame;
w.ohard_landing = w.hard_landing; w.ohard_landing = w.hard_landing;
w.sync.actions &= SB_CENTERVIEW; // this is the only bit we need to preserve. w.sync.actions &= SB_CENTERVIEW|SB_CROUCH; // these are the only bits we need to preserve.
} }
return arc; return arc;
} }

View file

@ -278,8 +278,6 @@ struct player_struct
double vehForwardScale, vehReverseScale, MotoSpeed; double vehForwardScale, vehReverseScale, MotoSpeed;
bool vehTurnLeft, vehTurnRight; bool vehTurnLeft, vehTurnRight;
bool crouch_toggle;
// input stuff. // input stuff.
InputPacket sync; InputPacket sync;

View file

@ -1004,7 +1004,6 @@ struct PLAYERstruct
int cookieTime; int cookieTime;
char WpnReloadState; char WpnReloadState;
bool crouch_toggle;
}; };
extern PLAYER Player[MAX_SW_PLAYERS_REG+1]; extern PLAYER Player[MAX_SW_PLAYERS_REG+1];

View file

@ -98,9 +98,6 @@ static void processInputBits(PLAYERp const pp, ControlInfo* const hidInput)
else else
RESET(Player[myconnectindex].Flags, PF_AUTO_AIM); RESET(Player[myconnectindex].Flags, PF_AUTO_AIM);
} }
// Handle crouch toggling.
checkCrouchToggle(&loc, &pp->crouch_toggle);
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View file

@ -1521,7 +1521,7 @@ UpdatePlayerSpriteAngle(PLAYERp pp)
void void
DoPlayerTurn(PLAYERp pp, float const avel, double const scaleAdjust) DoPlayerTurn(PLAYERp pp, float const avel, double const scaleAdjust)
{ {
applylook(&pp->angle, avel, &pp->input.actions, scaleAdjust, pp->input.actions & SB_CROUCH || pp->crouch_toggle); applylook(&pp->angle, avel, &pp->input.actions, scaleAdjust, pp->input.actions & SB_CROUCH);
UpdatePlayerSpriteAngle(pp); UpdatePlayerSpriteAngle(pp);
} }