- Game input: Fix miscellaneous issues.

* Duke/RR: Fix `SB_CENTERVIEW` not clearing while `cl_syncinput 1`.
* Duke/RR: Remove superfluous call to `apply_seasick()`.
* RR: Change two calls from `playerSetAngle()` to `playerAddAngle()` Updated version of `playerSetAngle()` doesn't stop setting angle until target is reached, a bit too strict for this and compromised vehicle turning.
* `applylook()`: Remove dead flag. Was only used with Duke, no other game called the function when dead anyway. Since the input helpers are processed outside of `applylook()` now this is not needed.
* `applylook()`: Extend function with a bit of commentary.
This commit is contained in:
Mitchell Richters 2020-09-21 15:51:33 +10:00
parent f806cdcec6
commit 59e4fae064
8 changed files with 63 additions and 56 deletions

View file

@ -138,7 +138,7 @@ static void processMovement(ControlInfo* const hidInput)
// Perform unsynchronised angle/horizon if not dead.
if (gView->pXSprite->health != 0)
{
applylook(&pPlayer->q16ang, &pPlayer->q16look_ang, &pPlayer->q16rotscrnang, &pPlayer->spin, input.q16avel, &pPlayer->input.actions, scaleAdjust, gView->pXSprite->health == 0, pPlayer->posture != 0);
applylook(&pPlayer->q16ang, &pPlayer->q16look_ang, &pPlayer->q16rotscrnang, &pPlayer->spin, input.q16avel, &pPlayer->input.actions, scaleAdjust, pPlayer->posture != 0);
UpdatePlayerSpriteAngle(pPlayer);
sethorizon(&pPlayer->q16horiz, input.q16horz, &pPlayer->input.actions, scaleAdjust);
}

View file

@ -1445,7 +1445,7 @@ void ProcessInput(PLAYER *pPlayer)
if (cl_syncinput)
{
applylook(&pPlayer->q16ang, &pPlayer->q16look_ang, &pPlayer->q16rotscrnang, &pPlayer->spin, pInput->q16avel, &pInput->actions, 1, gView->pXSprite->health == 0, pPlayer->posture != 0);
applylook(&pPlayer->q16ang, &pPlayer->q16look_ang, &pPlayer->q16rotscrnang, &pPlayer->spin, pInput->q16avel, &pInput->actions, 1, pPlayer->posture != 0);
UpdatePlayerSpriteAngle(pPlayer);
}

View file

@ -1560,54 +1560,58 @@ void sethorizon(fixed_t* q16horiz, fixed_t const q16horz, ESyncBits* actions, do
//
//---------------------------------------------------------------------------
void applylook(fixed_t* q16ang, fixed_t* q16look_ang, fixed_t* q16rotscrnang, fixed_t* spin, fixed_t const q16avel, ESyncBits* actions, double const scaleAdjust, bool const dead, bool const crouching)
void applylook(fixed_t* q16ang, fixed_t* q16look_ang, fixed_t* q16rotscrnang, fixed_t* spin, fixed_t const q16avel, ESyncBits* actions, double const scaleAdjust, bool const crouching)
{
if (!dead)
// return q16rotscrnang to 0 and set to 0 if less than a quarter of a FRACUNIT (16384)
*q16rotscrnang -= xs_CRoundToInt(scaleAdjust * (*q16rotscrnang * (15. / GameTicRate)));
if (abs(*q16rotscrnang) < (FRACUNIT >> 2)) *q16rotscrnang = 0;
// return q16look_ang to 0 and set to 0 if less than a quarter of a FRACUNIT (16384)
*q16look_ang -= xs_CRoundToInt(scaleAdjust * (*q16look_ang * (7.5 / GameTicRate)));
if (abs(*q16look_ang) < (FRACUNIT >> 2)) *q16look_ang = 0;
if (*actions & SB_LOOK_LEFT)
{
*q16rotscrnang -= xs_CRoundToInt(scaleAdjust * (*q16rotscrnang * (15. / GameTicRate)));
if (abs(*q16rotscrnang) < (FRACUNIT >> 2)) *q16rotscrnang = 0;
// start looking left
*q16look_ang -= FloatToFixed(scaleAdjust * (4560. / GameTicRate));
*q16rotscrnang += FloatToFixed(scaleAdjust * (720. / GameTicRate));
}
*q16look_ang -= xs_CRoundToInt(scaleAdjust * (*q16look_ang * (7.5 / GameTicRate)));
if (abs(*q16look_ang) < (FRACUNIT >> 2)) *q16look_ang = 0;
if (*actions & SB_LOOK_RIGHT)
{
// start looking right
*q16look_ang += FloatToFixed(scaleAdjust * (4560. / GameTicRate));
*q16rotscrnang -= FloatToFixed(scaleAdjust * (720. / GameTicRate));
}
if (*actions & SB_LOOK_LEFT)
if (*actions & SB_TURNAROUND)
{
if (*spin == 0)
{
*q16look_ang -= FloatToFixed(scaleAdjust * (4560. / GameTicRate));
*q16rotscrnang += FloatToFixed(scaleAdjust * (720. / GameTicRate));
// currently not spinning, so start a spin
*spin = IntToFixed(-1024);
}
*actions &= ~SB_TURNAROUND;
}
if (*actions & SB_LOOK_RIGHT)
if (*spin < 0)
{
// return spin to 0
fixed_t add = FloatToFixed(scaleAdjust * ((!crouching ? 3840. : 1920.) / GameTicRate));
*spin += add;
if (*spin > 0)
{
*q16look_ang += FloatToFixed(scaleAdjust * (4560. / GameTicRate));
*q16rotscrnang -= FloatToFixed(scaleAdjust * (720. / GameTicRate));
// Don't overshoot our target. With variable factor this is possible.
add -= *spin;
*spin = 0;
}
*q16ang += add;
}
if (*actions & SB_TURNAROUND)
{
if (*spin == 0)
{
*spin = IntToFixed(-1024);
}
*actions &= ~SB_TURNAROUND;
}
if (*spin < 0)
{
fixed_t add = FloatToFixed(scaleAdjust * ((!crouching ? 3840. : 1920.) / GameTicRate));
*spin += add;
if (*spin > 0)
{
// Don't overshoot our target. With variable factor this is possible.
add -= *spin;
*spin = 0;
}
*q16ang += add;
}
if (q16avel)
{
*q16ang = (*q16ang + q16avel) & 0x7FFFFFF;
}
if (q16avel)
{
// add player's input
*q16ang = (*q16ang + q16avel) & 0x7FFFFFF;
}
}
@ -1634,7 +1638,7 @@ void playerSetAngle(fixed_t* q16ang, fixed_t* helper, double adjustment)
if (!cl_syncinput)
{
// Add slight offset if adjustment is coming in as absolute 0.
if (adjustment == 0) adjustment += (1. / FRACUNIT);
if (adjustment == 0) adjustment += (1. / (FRACUNIT >> 1));
*helper = *q16ang + getincangleq16(*q16ang, FloatToFixed(adjustment));
}
@ -1661,7 +1665,7 @@ void playerSetHoriz(fixed_t* q16horiz, fixed_t* helper, double adjustment)
if (!cl_syncinput)
{
// Add slight offset if adjustment is coming in as absolute 0.
if (adjustment == 0) adjustment += (1. / FRACUNIT);
if (adjustment == 0) adjustment += (1. / (FRACUNIT >> 1));
*helper = FloatToFixed(adjustment);
}

View file

@ -68,7 +68,7 @@ int getincangle(int c, int n);
fixed_t getincangleq16(fixed_t c, fixed_t n);
void sethorizon(fixed_t* q16horiz, fixed_t const q16horz, ESyncBits* actions, double const scaleAdjust);
void applylook(fixed_t* q16ang, fixed_t* q16look_ang, fixed_t* q16rotscrnang, fixed_t* spin, fixed_t const q16avel, ESyncBits* actions, double const scaleAdjust, bool const dead, bool const crouching);
void applylook(fixed_t* q16ang, fixed_t* q16look_ang, fixed_t* q16rotscrnang, fixed_t* spin, fixed_t const q16avel, ESyncBits* actions, double const scaleAdjust, bool const crouching);
void playerAddAngle(fixed_t* q16ang, double* helper, double adjustment);
void playerSetAngle(fixed_t* q16ang, fixed_t* helper, double adjustment);
void playerAddHoriz(fixed_t* q16horiz, double* helper, double adjustment);

View file

@ -1020,12 +1020,15 @@ static void GetInputInternal(InputPacket &locInput, ControlInfo* const hidInput)
if (!cl_syncinput)
{
// Do these in the same order as the old code.
calcviewpitch(p, scaleAdjust);
processq16avel(p, &input.q16avel);
applylook(&p->q16ang, &p->q16look_ang, &p->q16rotscrnang, &p->one_eighty_count, input.q16avel, &sync[myconnectindex].actions, scaleAdjust, p->dead_flag != 0, p->crouch_toggle || sync[myconnectindex].actions & SB_CROUCH);
apply_seasick(p, scaleAdjust);
sethorizon(&p->q16horiz, input.q16horz, &sync[myconnectindex].actions, scaleAdjust);
if (p->dead_flag == 0)
{
// Do these in the same order as the old code.
calcviewpitch(p, scaleAdjust);
processq16avel(p, &input.q16avel);
applylook(&p->q16ang, &p->q16look_ang, &p->q16rotscrnang, &p->one_eighty_count, input.q16avel, &sync[myconnectindex].actions, scaleAdjust, p->crouch_toggle || sync[myconnectindex].actions & SB_CROUCH);
sethorizon(&p->q16horiz, input.q16horz, &sync[myconnectindex].actions, scaleAdjust);
}
playerProcessHelpers(&p->q16ang, &p->angAdjust, &p->angTarget, &p->q16horiz, &p->horizAdjust, &p->horizTarget, scaleAdjust);
}
}

View file

@ -2847,7 +2847,7 @@ void processinput_d(int snum)
// may still be needed later for demo recording
processq16avel(p, &sb_avel);
applylook(&p->q16ang, &p->q16look_ang, &p->q16rotscrnang, &p->one_eighty_count, sb_avel, &actions, 1, p->dead_flag != 0, p->crouch_toggle || actions & SB_CROUCH);
applylook(&p->q16ang, &p->q16look_ang, &p->q16rotscrnang, &p->one_eighty_count, sb_avel, &sync[snum].actions, 1, p->crouch_toggle || actions & SB_CROUCH);
}
if (p->spritebridge == 0)
@ -3079,7 +3079,7 @@ HORIZONLY:
if (cl_syncinput)
{
sethorizon(&p->q16horiz, PlayerHorizon(snum), &actions, 1);
sethorizon(&p->q16horiz, PlayerHorizon(snum), &sync[snum].actions, 1);
}
checkhardlanding(p);

View file

@ -1812,7 +1812,7 @@ static void onMotorcycle(int snum, ESyncBits &actions)
ang = var98 >> 7;
}
}
playerSetAngle(&p->q16ang, &p->angTarget, (var90 - ang) & 2047);
playerAddAngle(&p->q16ang, &p->angAdjust, FixedToFloat(getincangleq16(p->q16ang, IntToFixed(var90 - ang))));
}
else if (p->MotoSpeed >= 20 && p->on_ground == 1 && (p->moto_on_mud || p->moto_on_oil))
{
@ -2111,7 +2111,7 @@ static void onBoat(int snum, ESyncBits &actions)
p->posyv += (vard4 >> 7) * (sintable[(vardc * -51 + vard8) & 2047] << 4);
ang = vare0 >> 6;
}
playerSetAngle(&p->q16ang, &p->angTarget, (vard8 - ang) & 2047);
playerAddAngle(&p->q16ang, &p->angAdjust, FixedToFloat(getincangleq16(p->q16ang, IntToFixed(vard8 - ang))));
}
if (p->NotOnWater)
if (p->MotoSpeed > 50)
@ -3737,7 +3737,7 @@ void processinput_r(int snum)
// may still be needed later for demo recording
processq16avel(p, &sb_avel);
applylook(&p->q16ang, &p->q16look_ang, &p->q16rotscrnang, &p->one_eighty_count, sb_avel, &actions, 1, p->dead_flag != 0, p->crouch_toggle || actions & SB_CROUCH);
applylook(&p->q16ang, &p->q16look_ang, &p->q16rotscrnang, &p->one_eighty_count, sb_avel, &sync[snum].actions, 1, p->crouch_toggle || actions & SB_CROUCH);
apply_seasick(p, 1);
}
@ -4093,7 +4093,7 @@ HORIZONLY:
if (cl_syncinput)
{
sethorizon(&p->q16horiz, PlayerHorizon(snum), &actions, 1);
sethorizon(&p->q16horiz, PlayerHorizon(snum), &sync[snum].actions, 1);
}
checkhardlanding(p);

View file

@ -1525,7 +1525,7 @@ UpdatePlayerSpriteAngle(PLAYERp pp)
void
DoPlayerTurn(PLAYERp pp, fixed_t const q16avel, double const scaleAdjust)
{
applylook(&pp->q16ang, &pp->q16look_ang, &pp->q16rotscrnang, &pp->turn180_target, q16avel, &pp->input.actions, scaleAdjust, TEST(pp->Flags, PF_DEAD), pp->input.actions & (SB_CROUCH|SB_CROUCH_LOCK));
applylook(&pp->q16ang, &pp->q16look_ang, &pp->q16rotscrnang, &pp->turn180_target, q16avel, &pp->input.actions, scaleAdjust, pp->input.actions & (SB_CROUCH|SB_CROUCH_LOCK));
UpdatePlayerSpriteAngle(pp);
}