- 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,59 +271,63 @@ 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)
{
// Store current horizon as true pitch.
double pitch = horiz->aspitch();
if (horz)
// Process only if no targeted horizon set.
if (!horizon->targetset())
{
*actions &= ~SB_CENTERVIEW;
pitch += horz;
}
// Store current horizon as true pitch.
double pitch = horizon->horiz.aspitch();
// this is the locked type
if (*actions & (SB_AIM_UP|SB_AIM_DOWN))
{
*actions &= ~SB_CENTERVIEW;
double const amount = HorizToPitch(250. / GameTicRate);
if (*actions & SB_AIM_DOWN)
pitch -= scaleAdjust * amount;
if (*actions & SB_AIM_UP)
pitch += scaleAdjust * amount;
}
// this is the unlocked type
if (*actions & (SB_LOOK_UP|SB_LOOK_DOWN))
{
*actions |= SB_CENTERVIEW;
double const amount = HorizToPitch(500. / GameTicRate);
if (*actions & SB_LOOK_DOWN)
pitch -= scaleAdjust * amount;
if (*actions & SB_LOOK_UP)
pitch += scaleAdjust * amount;
}
// clamp before converting back to horizon
*horiz = q16horiz(clamp(PitchToHoriz(pitch), gi->playerHorizMin(), gi->playerHorizMax()));
// return to center if conditions met.
if ((*actions & SB_CENTERVIEW) && !(*actions & (SB_LOOK_UP|SB_LOOK_DOWN)))
{
if (abs(horiz->asq16()) > FloatToFixed(0.25))
if (horz)
{
// move horiz back to 0
*horiz -= q16horiz(xs_CRoundToInt(scaleAdjust * horiz->asq16() * (10. / GameTicRate)));
}
else
{
// not looking anymore because horiz is back at 0
*horiz = q16horiz(0);
*actions &= ~SB_CENTERVIEW;
pitch += horz;
}
// this is the locked type
if (*actions & (SB_AIM_UP|SB_AIM_DOWN))
{
*actions &= ~SB_CENTERVIEW;
double const amount = HorizToPitch(250. / GameTicRate);
if (*actions & SB_AIM_DOWN)
pitch -= scaleAdjust * amount;
if (*actions & SB_AIM_UP)
pitch += scaleAdjust * amount;
}
// this is the unlocked type
if (*actions & (SB_LOOK_UP|SB_LOOK_DOWN))
{
*actions |= SB_CENTERVIEW;
double const amount = HorizToPitch(500. / GameTicRate);
if (*actions & SB_LOOK_DOWN)
pitch -= scaleAdjust * amount;
if (*actions & SB_LOOK_UP)
pitch += scaleAdjust * amount;
}
// clamp before converting back to horizon
horizon->horiz = q16horiz(clamp(PitchToHoriz(pitch), gi->playerHorizMin(), gi->playerHorizMax()));
// return to center if conditions met.
if ((*actions & SB_CENTERVIEW) && !(*actions & (SB_LOOK_UP|SB_LOOK_DOWN)))
{
if (abs(horizon->horiz.asq16()) > FloatToFixed(0.25))
{
// move horiz back to 0
horizon->horiz -= q16horiz(xs_CRoundToInt(scaleAdjust * horizon->horiz.asq16() * (10. / GameTicRate)));
}
else
{
// not looking anymore because horiz is back at 0
horizon->horiz = q16horiz(0);
*actions &= ~SB_CENTERVIEW;
}
}
}
}
@ -358,34 +362,41 @@ void applylook(PlayerAngle* angle, float const avel, ESyncBits* actions, double
angle->rotscrnang -= bamlook(xs_CRoundToInt(scaleAdjust * (720. / GameTicRate) * BAMUNIT));
}
if (*actions & SB_TURNAROUND)
if (!angle->targetset())
{
if (angle->spin.asbam() == 0)
if (*actions & SB_TURNAROUND)
{
// currently not spinning, so start a spin
angle->spin = buildlook(-1024);
if (angle->spin.asbam() == 0)
{
// currently not spinning, so start a spin
angle->spin = buildlook(-1024);
}
*actions &= ~SB_TURNAROUND;
}
*actions &= ~SB_TURNAROUND;
}
if (angle->spin.asbam() < 0)
{
// return spin to 0
lookangle add = bamlook(xs_CRoundToUInt(scaleAdjust * ((!(*actions & SB_CROUCH) ? 3840. : 1920.) / GameTicRate) * BAMUNIT));
angle->spin += add;
if (angle->spin.asbam() > 0)
if (angle->spin.asbam() < 0)
{
// Don't overshoot our target. With variable factor this is possible.
add -= angle->spin;
// return spin to 0
lookangle add = bamlook(xs_CRoundToUInt(scaleAdjust * ((!(*actions & SB_CROUCH) ? 3840. : 1920.) / GameTicRate) * BAMUNIT));
angle->spin += add;
if (angle->spin.asbam() > 0)
{
// Don't overshoot our target. With variable factor this is possible.
add -= angle->spin;
angle->spin = bamlook(0);
}
angle->ang += bamang(add.asbam());
}
if (avel)
{
// add player's input
angle->ang += degang(avel);
angle->spin = bamlook(0);
}
angle->ang += bamang(add.asbam());
}
if (avel)
else
{
// add player's input
angle->ang += degang(avel);
angle->spin = bamlook(0);
}
}

View file

@ -290,6 +290,6 @@ void updateTurnHeldAmt(double const scaleAdjust);
bool const isTurboTurnTime();
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 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 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)
{
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);
}

View file

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

View file

@ -842,7 +842,7 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput)
doslopetilting(p, scaleAdjust);
applylook(&p->angle, p->adjustavel(input.avel), &p->sync.actions, 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);

View file

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

View file

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

View file

@ -125,7 +125,7 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput)
if (!nFreeze)
{
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);

View file

@ -2656,7 +2656,7 @@ loc_1BD2E:
if (SyncInput())
{
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

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);
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