Skip to content

Commit

Permalink
- gameinput.cpp: Block player input within sethorizon() and `applyl…
Browse files Browse the repository at this point in the history
…ook()` 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.
  • Loading branch information
mjr4077au committed Apr 2, 2021
1 parent 4ffe004 commit 9c01bde
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 70 deletions.
133 changes: 72 additions & 61 deletions source/core/gameinput.cpp
Expand Up @@ -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 (horz)
{
*actions &= ~SB_CENTERVIEW;
pitch += horz;
}

if (*actions & SB_AIM_UP)
pitch += scaleAdjust * amount;
}
// this is the locked type
if (*actions & (SB_AIM_UP|SB_AIM_DOWN))
{
*actions &= ~SB_CENTERVIEW;
double const amount = HorizToPitch(250. / GameTicRate);

// 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_AIM_DOWN)
pitch -= scaleAdjust * amount;

if (*actions & SB_LOOK_DOWN)
pitch -= scaleAdjust * amount;
if (*actions & SB_AIM_UP)
pitch += scaleAdjust * amount;
}

if (*actions & SB_LOOK_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);

// clamp before converting back to horizon
*horiz = q16horiz(clamp(PitchToHoriz(pitch), gi->playerHorizMin(), gi->playerHorizMax()));
if (*actions & SB_LOOK_DOWN)
pitch -= scaleAdjust * amount;

// return to center if conditions met.
if ((*actions & SB_CENTERVIEW) && !(*actions & (SB_LOOK_UP|SB_LOOK_DOWN)))
{
if (abs(horiz->asq16()) > FloatToFixed(0.25))
{
// move horiz back to 0
*horiz -= q16horiz(xs_CRoundToInt(scaleAdjust * horiz->asq16() * (10. / GameTicRate)));
if (*actions & SB_LOOK_UP)
pitch += scaleAdjust * amount;
}
else

// 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)))
{
// not looking anymore because horiz is back at 0
*horiz = q16horiz(0);
*actions &= ~SB_CENTERVIEW;
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;
}
}
}
}
Expand Down Expand Up @@ -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)
{
// 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)
{
// Don't overshoot our target. With variable factor this is possible.
add -= angle->spin;
// 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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/core/gameinput.h
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion source/games/blood/src/controls.cpp
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion source/games/blood/src/player.cpp
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion source/games/duke/src/input.cpp
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion source/games/duke/src/player_d.cpp
Expand Up @@ -3139,7 +3139,7 @@ void processinput_d(int snum)

if (SyncInput())
{
sethorizon(&p->horizon.horiz, PlayerHorizon(snum), &p->sync.actions);
sethorizon(&p->horizon, PlayerHorizon(snum), &p->sync.actions);
}

p->checkhardlanding();
Expand Down
2 changes: 1 addition & 1 deletion source/games/duke/src/player_r.cpp
Expand Up @@ -4001,7 +4001,7 @@ void processinput_r(int snum)

if (SyncInput())
{
sethorizon(&p->horizon.horiz, PlayerHorizon(snum), &p->sync.actions);
sethorizon(&p->horizon, PlayerHorizon(snum), &p->sync.actions);
}

p->checkhardlanding();
Expand Down
2 changes: 1 addition & 1 deletion source/games/exhumed/src/input.cpp
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion source/games/exhumed/src/player.cpp
Expand Up @@ -2656,7 +2656,7 @@ void FuncPlayer(int a, int nDamage, int nRun)
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
Expand Down
2 changes: 1 addition & 1 deletion source/games/sw/src/player.cpp
Expand Up @@ -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
Expand Down

0 comments on commit 9c01bde

Please sign in to comment.