- gameinput.cpp: Block player input within sethorizon() and applylook() if target for each has been set by the ticker.

* Stops players having the ability to provide input and fight the system trying to set an input.
This commit is contained in:
Mitchell Richters 2021-04-02 22:41:47 +11:00
parent 4ffe004483
commit 9c01bde44e
10 changed files with 87 additions and 76 deletions

View file

@ -271,10 +271,13 @@ void processMovement(InputPacket* currInput, InputPacket* inputBuffer, ControlIn
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void sethorizon(fixedhoriz* horiz, float const horz, ESyncBits* actions, double const scaleAdjust) void sethorizon(PlayerHorizon* horizon, float const horz, ESyncBits* actions, double const scaleAdjust)
{
// Process only if no targeted horizon set.
if (!horizon->targetset())
{ {
// Store current horizon as true pitch. // Store current horizon as true pitch.
double pitch = horiz->aspitch(); double pitch = horizon->horiz.aspitch();
if (horz) if (horz)
{ {
@ -309,24 +312,25 @@ void sethorizon(fixedhoriz* horiz, float const horz, ESyncBits* actions, double
} }
// clamp before converting back to horizon // clamp before converting back to horizon
*horiz = q16horiz(clamp(PitchToHoriz(pitch), gi->playerHorizMin(), gi->playerHorizMax())); horizon->horiz = q16horiz(clamp(PitchToHoriz(pitch), gi->playerHorizMin(), gi->playerHorizMax()));
// return to center if conditions met. // return to center if conditions met.
if ((*actions & SB_CENTERVIEW) && !(*actions & (SB_LOOK_UP|SB_LOOK_DOWN))) if ((*actions & SB_CENTERVIEW) && !(*actions & (SB_LOOK_UP|SB_LOOK_DOWN)))
{ {
if (abs(horiz->asq16()) > FloatToFixed(0.25)) if (abs(horizon->horiz.asq16()) > FloatToFixed(0.25))
{ {
// move horiz back to 0 // move horiz back to 0
*horiz -= q16horiz(xs_CRoundToInt(scaleAdjust * horiz->asq16() * (10. / GameTicRate))); horizon->horiz -= q16horiz(xs_CRoundToInt(scaleAdjust * horizon->horiz.asq16() * (10. / GameTicRate)));
} }
else else
{ {
// not looking anymore because horiz is back at 0 // not looking anymore because horiz is back at 0
*horiz = q16horiz(0); horizon->horiz = q16horiz(0);
*actions &= ~SB_CENTERVIEW; *actions &= ~SB_CENTERVIEW;
} }
} }
} }
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// //
@ -358,6 +362,8 @@ void applylook(PlayerAngle* angle, float const avel, ESyncBits* actions, double
angle->rotscrnang -= bamlook(xs_CRoundToInt(scaleAdjust * (720. / GameTicRate) * BAMUNIT)); angle->rotscrnang -= bamlook(xs_CRoundToInt(scaleAdjust * (720. / GameTicRate) * BAMUNIT));
} }
if (!angle->targetset())
{
if (*actions & SB_TURNAROUND) if (*actions & SB_TURNAROUND)
{ {
if (angle->spin.asbam() == 0) if (angle->spin.asbam() == 0)
@ -389,6 +395,11 @@ void applylook(PlayerAngle* angle, float const avel, ESyncBits* actions, double
angle->spin = bamlook(0); angle->spin = bamlook(0);
} }
} }
else
{
angle->spin = bamlook(0);
}
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// //

View file

@ -290,6 +290,6 @@ void updateTurnHeldAmt(double const scaleAdjust);
bool const isTurboTurnTime(); bool const isTurboTurnTime();
void resetTurnHeldAmt(); void resetTurnHeldAmt();
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 = 1); void sethorizon(PlayerHorizon* horizon, float const horz, ESyncBits* actions, double const scaleAdjust = 1);
void applylook(PlayerAngle* angle, float const avel, ESyncBits* actions, double const scaleAdjust = 1); void applylook(PlayerAngle* angle, float const avel, ESyncBits* actions, double const scaleAdjust = 1);
void calcviewpitch(vec2_t const pos, fixedhoriz* horizoff, binangle const ang, bool const aimmode, bool const canslopetilt, int const cursectnum, double const scaleAdjust = 1, bool const climbing = false); void calcviewpitch(vec2_t const pos, fixedhoriz* horizoff, binangle const ang, bool const aimmode, bool const canslopetilt, int const cursectnum, double const scaleAdjust = 1, bool const climbing = false);

View file

@ -59,7 +59,7 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput)
if (gView->pXSprite->health != 0) if (gView->pXSprite->health != 0)
{ {
applylook(&pPlayer->angle, input.avel, &pPlayer->input.actions, scaleAdjust); applylook(&pPlayer->angle, input.avel, &pPlayer->input.actions, scaleAdjust);
sethorizon(&pPlayer->horizon.horiz, input.horz, &pPlayer->input.actions, scaleAdjust); sethorizon(&pPlayer->horizon, input.horz, &pPlayer->input.actions, scaleAdjust);
doslopetilting(pPlayer, scaleAdjust); doslopetilting(pPlayer, scaleAdjust);
} }

View file

@ -1548,7 +1548,7 @@ void ProcessInput(PLAYER *pPlayer)
if (SyncInput()) if (SyncInput())
{ {
sethorizon(&pPlayer->horizon.horiz, pInput->horz, &pInput->actions); sethorizon(&pPlayer->horizon, pInput->horz, &pInput->actions);
doslopetilting(pPlayer); doslopetilting(pPlayer);
} }

View file

@ -842,7 +842,7 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput)
doslopetilting(p, scaleAdjust); doslopetilting(p, scaleAdjust);
applylook(&p->angle, p->adjustavel(input.avel), &p->sync.actions, scaleAdjust); applylook(&p->angle, p->adjustavel(input.avel), &p->sync.actions, scaleAdjust);
p->apply_seasick(scaleAdjust); p->apply_seasick(scaleAdjust);
sethorizon(&p->horizon.horiz, input.horz, &p->sync.actions, scaleAdjust); sethorizon(&p->horizon, input.horz, &p->sync.actions, scaleAdjust);
} }
p->angle.processhelpers(scaleAdjust); p->angle.processhelpers(scaleAdjust);

View file

@ -3139,7 +3139,7 @@ HORIZONLY:
if (SyncInput()) if (SyncInput())
{ {
sethorizon(&p->horizon.horiz, PlayerHorizon(snum), &p->sync.actions); sethorizon(&p->horizon, PlayerHorizon(snum), &p->sync.actions);
} }
p->checkhardlanding(); p->checkhardlanding();

View file

@ -4001,7 +4001,7 @@ HORIZONLY:
if (SyncInput()) if (SyncInput())
{ {
sethorizon(&p->horizon.horiz, PlayerHorizon(snum), &p->sync.actions); sethorizon(&p->horizon, PlayerHorizon(snum), &p->sync.actions);
} }
p->checkhardlanding(); p->checkhardlanding();

View file

@ -125,7 +125,7 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput)
if (!nFreeze) if (!nFreeze)
{ {
applylook(&pPlayer->angle, input.avel, &sPlayerInput[nLocalPlayer].actions, scaleAdjust); applylook(&pPlayer->angle, input.avel, &sPlayerInput[nLocalPlayer].actions, scaleAdjust);
sethorizon(&pPlayer->horizon.horiz, input.horz, &sPlayerInput[nLocalPlayer].actions, scaleAdjust); sethorizon(&pPlayer->horizon, input.horz, &sPlayerInput[nLocalPlayer].actions, scaleAdjust);
} }
pPlayer->angle.processhelpers(scaleAdjust); pPlayer->angle.processhelpers(scaleAdjust);

View file

@ -2656,7 +2656,7 @@ loc_1BD2E:
if (SyncInput()) if (SyncInput())
{ {
Player* pPlayer = &PlayerList[nPlayer]; Player* pPlayer = &PlayerList[nPlayer];
sethorizon(&pPlayer->horizon.horiz, sPlayerInput[nPlayer].pan, &sPlayerInput[nLocalPlayer].actions); sethorizon(&pPlayer->horizon, sPlayerInput[nPlayer].pan, &sPlayerInput[nLocalPlayer].actions);
} }
} }
else // else, player's health is less than 0 else // else, player's health is less than 0

View file

@ -1669,7 +1669,7 @@ DoPlayerHorizon(PLAYERp pp, float const horz, double const scaleAdjust)
{ {
bool const canslopetilt = !TEST(pp->Flags, PF_FLYING|PF_SWIMMING|PF_DIVING|PF_CLIMBING|PF_JUMPING|PF_FALLING) && TEST(sector[pp->cursectnum].floorstat, FLOOR_STAT_SLOPE); bool const canslopetilt = !TEST(pp->Flags, PF_FLYING|PF_SWIMMING|PF_DIVING|PF_CLIMBING|PF_JUMPING|PF_FALLING) && TEST(sector[pp->cursectnum].floorstat, FLOOR_STAT_SLOPE);
calcviewpitch(pp->pos.vec2, &pp->horizon.horizoff, pp->angle.ang, pp->input.actions & SB_AIMMODE, canslopetilt, pp->cursectnum, scaleAdjust, TEST(pp->Flags, PF_CLIMBING)); calcviewpitch(pp->pos.vec2, &pp->horizon.horizoff, pp->angle.ang, pp->input.actions & SB_AIMMODE, canslopetilt, pp->cursectnum, scaleAdjust, TEST(pp->Flags, PF_CLIMBING));
sethorizon(&pp->horizon.horiz, horz, &pp->input.actions, scaleAdjust); sethorizon(&pp->horizon, horz, &pp->input.actions, scaleAdjust);
} }
void void