- Blood/Duke/RR/SW: Unify the player's angle/horizon helper functions.

This commit is contained in:
Mitchell Richters 2020-09-21 13:41:16 +10:00
parent 7bf1cacc7f
commit f806cdcec6
19 changed files with 168 additions and 335 deletions

View file

@ -143,39 +143,7 @@ static void processMovement(ControlInfo* const hidInput)
sethorizon(&pPlayer->q16horiz, input.q16horz, &pPlayer->input.actions, scaleAdjust); sethorizon(&pPlayer->q16horiz, input.q16horz, &pPlayer->input.actions, scaleAdjust);
} }
// Process angle amendments from the game's ticker. playerProcessHelpers(&pPlayer->q16ang, &pPlayer->angAdjust, &pPlayer->angTarget, &pPlayer->q16horiz, &pPlayer->horizAdjust, &pPlayer->horizTarget, scaleAdjust);
if (pPlayer->angTarget)
{
fixed_t angDelta = getincangleq16(pPlayer->q16ang, pPlayer->angTarget);
pPlayer->q16ang = (pPlayer->q16ang + xs_CRoundToInt(scaleAdjust * angDelta));
if (abs(pPlayer->q16ang - pPlayer->angTarget) < FRACUNIT)
{
pPlayer->q16ang = pPlayer->angTarget;
pPlayer->angTarget = 0;
}
}
else if (pPlayer->angAdjust)
{
pPlayer->q16ang = (pPlayer->q16ang + FloatToFixed(scaleAdjust * pPlayer->angAdjust)) & 0x7FFFFFF;
}
// Process horizon amendments from the game's ticker.
if (pPlayer->horizTarget)
{
fixed_t horizDelta = pPlayer->horizTarget - pPlayer->q16horiz;
pPlayer->q16horiz += xs_CRoundToInt(scaleAdjust * horizDelta);
if (abs(pPlayer->q16horiz - pPlayer->horizTarget) < FRACUNIT)
{
pPlayer->q16horiz = pPlayer->horizTarget;
pPlayer->horizTarget = 0;
}
}
else if (pPlayer->horizAdjust)
{
pPlayer->q16horiz += FloatToFixed(scaleAdjust * pPlayer->horizAdjust);
}
} }
gInput.fvel = clamp(gInput.fvel + input.fvel, -MAXFVEL, MAXFVEL); gInput.fvel = clamp(gInput.fvel + input.fvel, -MAXFVEL, MAXFVEL);

View file

@ -1323,78 +1323,12 @@ void UpdatePlayerSpriteAngle(PLAYER *pPlayer)
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void resetinputhelpers(PLAYER* pPlayer) static void resetinputhelpers(PLAYER* pPlayer)
{ {
pPlayer->horizAdjust = 0; pPlayer->horizAdjust = 0;
pPlayer->angAdjust = 0; pPlayer->angAdjust = 0;
} }
void playerAddAngle(PLAYER* pPlayer, double ang)
{
if (!cl_syncinput)
{
pPlayer->angAdjust += ang;
}
else
{
pPlayer->addang(ang);
}
}
void playerSetAngle(PLAYER* pPlayer, double ang)
{
if (!cl_syncinput)
{
// Cancel out any angle adjustments as we're setting angle now.
pPlayer->angAdjust = 0;
// Add slight offset if input angle is coming in as absolute 0.
if (ang == 0)
{
ang += 0.1;
}
pPlayer->angTarget = pPlayer->q16ang + getincangleq16(pPlayer->q16ang, FloatToFixed(ang));
}
else
{
pPlayer->setang(ang);
}
}
void playerAddHoriz(PLAYER* pPlayer, double horiz)
{
if (!cl_syncinput)
{
pPlayer->horizAdjust += horiz;
}
else
{
pPlayer->addhoriz(horiz);
}
}
void playerSetHoriz(PLAYER* pPlayer, double horiz)
{
if (!cl_syncinput)
{
// Cancel out any horizon adjustments as we're setting horizon now.
pPlayer->horizAdjust = 0;
// Add slight offset if input horizon is coming in as absolute 0.
if (horiz == 0)
{
horiz += 0.1;
}
pPlayer->horizTarget = FloatToFixed(horiz);
}
else
{
pPlayer->sethoriz(horiz);
}
}
void ProcessInput(PLAYER *pPlayer) void ProcessInput(PLAYER *pPlayer)
{ {
enum enum
@ -1425,11 +1359,11 @@ void ProcessInput(PLAYER *pPlayer)
if (pPlayer->fraggerId != -1) if (pPlayer->fraggerId != -1)
{ {
pPlayer->angold = pSprite->ang = getangle(sprite[pPlayer->fraggerId].x - pSprite->x, sprite[pPlayer->fraggerId].y - pSprite->y); pPlayer->angold = pSprite->ang = getangle(sprite[pPlayer->fraggerId].x - pSprite->x, sprite[pPlayer->fraggerId].y - pSprite->y);
playerSetAngle(pPlayer, pSprite->ang); playerSetAngle(&pPlayer->q16ang, &pPlayer->angTarget, pSprite->ang);
} }
pPlayer->deathTime += 4; pPlayer->deathTime += 4;
if (!bSeqStat) if (!bSeqStat)
playerSetHoriz(pPlayer, FixedToFloat(mulscale16(0x8000-(Cos(ClipHigh(pPlayer->deathTime<<3, 1024))>>15), IntToFixed(120)))); playerSetHoriz(&pPlayer->q16horiz, &pPlayer->horizTarget, FixedToFloat(mulscale16(0x8000-(Cos(ClipHigh(pPlayer->deathTime<<3, 1024))>>15), IntToFixed(120))));
if (pPlayer->curWeapon) if (pPlayer->curWeapon)
pInput->setNewWeapon(pPlayer->curWeapon); pInput->setNewWeapon(pPlayer->curWeapon);
if (pInput->actions & SB_OPEN) if (pInput->actions & SB_OPEN)

View file

@ -187,13 +187,9 @@ struct PLAYER
fixed_t q16look_ang; fixed_t q16look_ang;
fixed_t q16rotscrnang; fixed_t q16rotscrnang;
// Input helper variables and setters. // Input helper variables.
double horizAdjust, angAdjust; double horizAdjust, angAdjust;
fixed_t horizTarget, angTarget; fixed_t horizTarget, angTarget;
void addang(int v) { q16ang = (q16ang + IntToFixed(v)) & 0x7FFFFFF; }
void setang(int v) { q16ang = IntToFixed(v); }
void addhoriz(int v) { q16horiz += (IntToFixed(v)); }
void sethoriz(int v) { q16horiz = IntToFixed(v); }
}; };
struct PROFILE struct PROFILE

View file

@ -1610,3 +1610,106 @@ void applylook(fixed_t* q16ang, fixed_t* q16look_ang, fixed_t* q16rotscrnang, fi
} }
} }
} }
//---------------------------------------------------------------------------
//
// Player's ticrate helper functions.
//
//---------------------------------------------------------------------------
void playerAddAngle(fixed_t* q16ang, double* helper, double adjustment)
{
if (!cl_syncinput)
{
*helper += adjustment;
}
else
{
*q16ang = (*q16ang + FloatToFixed(adjustment)) & 0x7FFFFFF;
}
}
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);
*helper = *q16ang + getincangleq16(*q16ang, FloatToFixed(adjustment));
}
else
{
*q16ang = FloatToFixed(adjustment);
}
}
void playerAddHoriz(fixed_t* q16horiz, double* helper, double adjustment)
{
if (!cl_syncinput)
{
*helper += adjustment;
}
else
{
*q16horiz += FloatToFixed(adjustment);
}
}
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);
*helper = FloatToFixed(adjustment);
}
else
{
*q16horiz = FloatToFixed(adjustment);
}
}
//---------------------------------------------------------------------------
//
// Player's ticrate helper processor.
//
//---------------------------------------------------------------------------
void playerProcessHelpers(fixed_t* q16ang, double* angAdjust, fixed_t* angTarget, fixed_t* q16horiz, double* horizAdjust, fixed_t* horizTarget, double const scaleAdjust)
{
// Process angle amendments from the game's ticker.
if (*angTarget)
{
fixed_t angDelta = getincangleq16(*q16ang, *angTarget);
*q16ang = (*q16ang + xs_CRoundToInt(scaleAdjust * angDelta));
if (abs(*q16ang - *angTarget) < FRACUNIT)
{
*q16ang = *angTarget;
*angTarget = 0;
}
}
else if (*angAdjust)
{
*q16ang = (*q16ang + FloatToFixed(scaleAdjust * *angAdjust)) & 0x7FFFFFF;
}
// Process horizon amendments from the game's ticker.
if (*horizTarget)
{
fixed_t horizDelta = *horizTarget - *q16horiz;
*q16horiz += xs_CRoundToInt(scaleAdjust * horizDelta);
if (abs(*q16horiz - *horizTarget) < FRACUNIT)
{
*q16horiz = *horizTarget;
*horizTarget = 0;
}
}
else if (*horizAdjust)
{
*q16horiz += FloatToFixed(scaleAdjust * *horizAdjust);
}
}

View file

@ -69,6 +69,11 @@ fixed_t getincangleq16(fixed_t c, fixed_t n);
void sethorizon(fixed_t* q16horiz, fixed_t const q16horz, ESyncBits* actions, double const scaleAdjust); 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 dead, 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);
void playerSetHoriz(fixed_t* q16horiz, fixed_t* helper, double adjustment);
void playerProcessHelpers(fixed_t* q16ang, double* angAdjust, fixed_t* angTarget, fixed_t* q16horiz, double* horizAdjust, fixed_t* horizTarget, double const scaleAdjust);
struct UserConfig struct UserConfig
{ {

View file

@ -468,7 +468,7 @@ void moveplayers(void) //Players
if (p->actorsqu >= 0) if (p->actorsqu >= 0)
{ {
playerAddAngle(p, getincangle(p->getang(), getangle(sprite[p->actorsqu].x - p->posx, sprite[p->actorsqu].y - p->posy)) >> 2); playerAddAngle(&p->q16ang, &p->angAdjust, getincangle(p->getang(), getangle(sprite[p->actorsqu].x - p->posx, sprite[p->actorsqu].y - p->posy)) >> 2);
} }
if (s->extra > 0) if (s->extra > 0)
@ -491,7 +491,7 @@ void moveplayers(void) //Players
if (p->wackedbyactor >= 0 && sprite[p->wackedbyactor].statnum < MAXSTATUS) if (p->wackedbyactor >= 0 && sprite[p->wackedbyactor].statnum < MAXSTATUS)
{ {
playerAddAngle(p, getincangle(p->getang(), getangle(sprite[p->wackedbyactor].x - p->posx, sprite[p->wackedbyactor].y - p->posy)) >> 1); playerAddAngle(&p->q16ang, &p->angAdjust, getincangle(p->getang(), getangle(sprite[p->wackedbyactor].x - p->posx, sprite[p->wackedbyactor].y - p->posy)) >> 1);
} }
} }
s->ang = p->getang(); s->ang = p->getang();
@ -748,7 +748,7 @@ void movecrane(int i, int crane)
s->owner = -2; s->owner = -2;
ps[p].on_crane = i; ps[p].on_crane = i;
S_PlayActorSound(isRR() ? 390 : DUKE_GRUNT, ps[p].i); S_PlayActorSound(isRR() ? 390 : DUKE_GRUNT, ps[p].i);
playerSetAngle(&ps[p], s->ang + 1024); playerSetAngle(&ps[p].q16ang, &ps[p].angTarget, s->ang + 1024);
} }
else else
{ {
@ -2674,7 +2674,7 @@ void handle_se00(int i, int LASERLINE)
{ {
if (ps[p].cursectnum == s->sectnum && ps[p].on_ground == 1) if (ps[p].cursectnum == s->sectnum && ps[p].on_ground == 1)
{ {
playerAddAngle(&ps[p], l * q); playerAddAngle(&ps[p].q16ang, &ps[p].angAdjust, l * q);
ps[p].posz += zchange; ps[p].posz += zchange;
@ -2866,7 +2866,7 @@ void handle_se14(int i, bool checkstat, int RPG, int JIBS6)
ps[p].bobposx += m; ps[p].bobposx += m;
ps[p].bobposy += x; ps[p].bobposy += x;
playerAddAngle(&ps[p], q); playerAddAngle(&ps[p].q16ang, &ps[p].angAdjust, q);
if (numplayers > 1) if (numplayers > 1)
{ {

View file

@ -1852,7 +1852,7 @@ void moveweapons_d(void)
if (s->picnum == SPIT) if (s->picnum == SPIT)
{ {
playerAddHoriz(&ps[p], 32); playerAddHoriz(&ps[p].q16horiz, &ps[p].horizAdjust, 32);
sync[p].actions |= SB_CENTERVIEW; sync[p].actions |= SB_CENTERVIEW;
if (ps[p].loogcnt == 0) if (ps[p].loogcnt == 0)

View file

@ -1399,7 +1399,7 @@ void moveweapons_r(void)
guts_r(s, RABBITJIBC, 2, myconnectindex); guts_r(s, RABBITJIBC, 2, myconnectindex);
} }
playerAddHoriz(&ps[p], 32); playerAddHoriz(&ps[p].q16horiz, &ps[p].horizAdjust, 32);
sync[p].actions |= SB_CENTERVIEW; sync[p].actions |= SB_CENTERVIEW;
if (ps[p].loogcnt == 0) if (ps[p].loogcnt == 0)

View file

@ -248,9 +248,4 @@ void resetinputhelpers(player_struct* p);
void checkhardlanding(player_struct* p); void checkhardlanding(player_struct* p);
void playerweaponsway(player_struct* p, spritetype* s); void playerweaponsway(player_struct* p, spritetype* s);
void playerAddAngle(player_struct* p, int ang);
void playerSetAngle(player_struct* p, int ang);
void playerAddHoriz(player_struct* p, int horiz);
void playerSetHoriz(player_struct* p, int horiz);
END_DUKE_NS END_DUKE_NS

View file

@ -330,7 +330,7 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, int sActor, int sPl
break; break;
case PLAYER_HORIZ: case PLAYER_HORIZ:
if (bSet) playerSetHoriz(&ps[iPlayer], lValue); if (bSet) playerSetHoriz(&ps[iPlayer].q16horiz, &ps[iPlayer].horizTarget, lValue);
else SetGameVarID((int)lVar2, FixedToInt(ps[iPlayer].q16horiz), sActor, sPlayer); else SetGameVarID((int)lVar2, FixedToInt(ps[iPlayer].q16horiz), sActor, sPlayer);
break; break;
@ -452,7 +452,7 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, int sActor, int sPl
break; break;
case PLAYER_ANG: case PLAYER_ANG:
if (bSet) playerSetAngle(&ps[iPlayer], lValue); if (bSet) playerSetAngle(&ps[iPlayer].q16ang, &ps[iPlayer].angTarget, lValue);
else SetGameVarID((int)lVar2, ps[iPlayer].getang(), sActor, sPlayer); else SetGameVarID((int)lVar2, ps[iPlayer].getang(), sActor, sPlayer);
break; break;

View file

@ -1026,16 +1026,7 @@ static void GetInputInternal(InputPacket &locInput, ControlInfo* const hidInput)
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); 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); apply_seasick(p, scaleAdjust);
sethorizon(&p->q16horiz, input.q16horz, &sync[myconnectindex].actions, scaleAdjust); sethorizon(&p->q16horiz, input.q16horz, &sync[myconnectindex].actions, scaleAdjust);
playerProcessHelpers(&p->q16ang, &p->angAdjust, &p->angTarget, &p->q16horiz, &p->horizAdjust, &p->horizTarget, scaleAdjust);
if (p->angAdjust)
{
p->q16ang += FloatToFixed(scaleAdjust * p->angAdjust);
}
if (p->horizAdjust)
{
p->q16horiz += FloatToFixed(scaleAdjust * p->horizAdjust);
}
} }
} }

View file

@ -164,7 +164,7 @@ void forceplayerangle(int snum)
n = 128 - (krand() & 255); n = 128 - (krand() & 255);
playerAddHoriz(p, 64); playerAddHoriz(&p->q16horiz, &p->horizAdjust, 64);
sync[snum].actions |= SB_CENTERVIEW; sync[snum].actions |= SB_CENTERVIEW;
p->setlookang(n >> 1); p->setlookang(n >> 1);
p->setrotscrnang(n >> 1); p->setrotscrnang(n >> 1);
@ -406,7 +406,7 @@ void dokneeattack(int snum, int pi, const std::initializer_list<int> & respawnli
if (p->knee_incs > 0) if (p->knee_incs > 0)
{ {
p->knee_incs++; p->knee_incs++;
playerAddHoriz(p, -48); playerAddHoriz(&p->q16horiz, &p->horizAdjust, -48);
sync[snum].actions |= SB_CENTERVIEW; sync[snum].actions |= SB_CENTERVIEW;
if (p->knee_incs > 15) if (p->knee_incs > 15)
{ {
@ -887,7 +887,7 @@ void checkhardlanding(player_struct* p)
{ {
if (p->hard_landing > 0) if (p->hard_landing > 0)
{ {
playerAddHoriz(p, -(p->hard_landing << 4)); playerAddHoriz(&p->q16horiz, &p->horizAdjust, -(p->hard_landing << 4));
p->hard_landing--; p->hard_landing--;
} }
} }
@ -1021,60 +1021,6 @@ void playerAimDown(int snum, ESyncBits actions)
} }
} }
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void playerAddAngle(player_struct* p, int ang)
{
if (!cl_syncinput)
{
p->angAdjust += ang;
}
else
{
p->addang(ang);
}
}
void playerSetAngle(player_struct* p, int ang)
{
if (!cl_syncinput)
{
p->angAdjust += -1. * ((p->q16ang / 65536.) - ang);
}
else
{
p->setang(ang);
}
}
void playerAddHoriz(player_struct* p, int horiz)
{
if (!cl_syncinput)
{
p->horizAdjust += horiz;
}
else
{
p->addhoriz(horiz);
}
}
void playerSetHoriz(player_struct* p, int horiz)
{
if (!cl_syncinput)
{
p->horizAdjust += -1. * ((p->q16horiz / 65536.) - horiz);
}
else
{
p->sethoriz(horiz);
}
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// //
// split out so that the weapon check can be done right. // split out so that the weapon check can be done right.

View file

@ -1733,7 +1733,7 @@ static void onMotorcycle(int snum, ESyncBits &actions)
p->TurbCount--; p->TurbCount--;
p->moto_drink = (krand() & 3) - 2; p->moto_drink = (krand() & 3) - 2;
} }
playerSetHoriz(p, horiz); playerSetHoriz(&p->q16horiz, &p->horizTarget, horiz);
} }
else if (p->VBumpTarget > p->VBumpNow) else if (p->VBumpTarget > p->VBumpNow)
{ {
@ -1743,7 +1743,7 @@ static void onMotorcycle(int snum, ESyncBits &actions)
p->VBumpNow++; p->VBumpNow++;
if (p->VBumpTarget < p->VBumpNow) if (p->VBumpTarget < p->VBumpNow)
p->VBumpNow = p->VBumpTarget; p->VBumpNow = p->VBumpTarget;
playerSetHoriz(p, 100 + p->VBumpNow / 3); playerSetHoriz(&p->q16horiz, &p->horizTarget, 100 + p->VBumpNow / 3);
} }
else if (p->VBumpTarget < p->VBumpNow) else if (p->VBumpTarget < p->VBumpNow)
{ {
@ -1753,7 +1753,7 @@ static void onMotorcycle(int snum, ESyncBits &actions)
p->VBumpNow--; p->VBumpNow--;
if (p->VBumpTarget > p->VBumpNow) if (p->VBumpTarget > p->VBumpNow)
p->VBumpNow = p->VBumpTarget; p->VBumpNow = p->VBumpTarget;
playerSetHoriz(p, 100 + p->VBumpNow / 3); playerSetHoriz(&p->q16horiz, &p->horizTarget, 100 + p->VBumpNow / 3);
} }
else else
{ {
@ -1812,7 +1812,7 @@ static void onMotorcycle(int snum, ESyncBits &actions)
ang = var98 >> 7; ang = var98 >> 7;
} }
} }
playerSetAngle(p, (var90 - ang) & 2047); playerSetAngle(&p->q16ang, &p->angTarget, (var90 - ang) & 2047);
} }
else if (p->MotoSpeed >= 20 && p->on_ground == 1 && (p->moto_on_mud || p->moto_on_oil)) else if (p->MotoSpeed >= 20 && p->on_ground == 1 && (p->moto_on_mud || p->moto_on_oil))
{ {
@ -2057,7 +2057,7 @@ static void onBoat(int snum, ESyncBits &actions)
p->TurbCount--; p->TurbCount--;
p->moto_drink = (krand() & 3) - 2; p->moto_drink = (krand() & 3) - 2;
} }
playerSetHoriz(p, horiz); playerSetHoriz(&p->q16horiz, &p->horizTarget, horiz);
} }
else if (p->VBumpTarget > p->VBumpNow) else if (p->VBumpTarget > p->VBumpNow)
{ {
@ -2067,7 +2067,7 @@ static void onBoat(int snum, ESyncBits &actions)
p->VBumpNow++; p->VBumpNow++;
if (p->VBumpTarget < p->VBumpNow) if (p->VBumpTarget < p->VBumpNow)
p->VBumpNow = p->VBumpTarget; p->VBumpNow = p->VBumpTarget;
playerSetHoriz(p, 100 + p->VBumpNow / 3); playerSetHoriz(&p->q16horiz, &p->horizTarget, 100 + p->VBumpNow / 3);
} }
else if (p->VBumpTarget < p->VBumpNow) else if (p->VBumpTarget < p->VBumpNow)
{ {
@ -2077,7 +2077,7 @@ static void onBoat(int snum, ESyncBits &actions)
p->VBumpNow--; p->VBumpNow--;
if (p->VBumpTarget > p->VBumpNow) if (p->VBumpTarget > p->VBumpNow)
p->VBumpNow = p->VBumpTarget; p->VBumpNow = p->VBumpTarget;
playerSetHoriz(p, 100 + p->VBumpNow / 3); playerSetHoriz(&p->q16horiz, &p->horizTarget, 100 + p->VBumpNow / 3);
} }
else else
{ {
@ -2111,7 +2111,7 @@ static void onBoat(int snum, ESyncBits &actions)
p->posyv += (vard4 >> 7) * (sintable[(vardc * -51 + vard8) & 2047] << 4); p->posyv += (vard4 >> 7) * (sintable[(vardc * -51 + vard8) & 2047] << 4);
ang = vare0 >> 6; ang = vare0 >> 6;
} }
playerSetAngle(p, (vard8 - ang) & 2047); playerSetAngle(&p->q16ang, &p->angTarget, (vard8 - ang) & 2047);
} }
if (p->NotOnWater) if (p->NotOnWater)
if (p->MotoSpeed > 50) if (p->MotoSpeed > 50)
@ -2455,7 +2455,7 @@ void onMotorcycleMove(int snum, int psect, int j)
ang = -(p->MotoSpeed >> 1); ang = -(p->MotoSpeed >> 1);
break; break;
} }
playerAddAngle(p, ang); playerAddAngle(&p->q16ang, &p->angAdjust, ang);
if (var10c >= 441 && var10c <= 581) if (var10c >= 441 && var10c <= 581)
{ {
var104 = (p->MotoSpeed * p->MotoSpeed) >> 8; var104 = (p->MotoSpeed * p->MotoSpeed) >> 8;
@ -2522,7 +2522,7 @@ void onBoatMove(int snum, int psect, int j)
ang = -(p->MotoSpeed >> 2); ang = -(p->MotoSpeed >> 2);
break; break;
} }
playerAddAngle(p, ang); playerAddAngle(&p->q16ang, &p->angAdjust, ang);
if (var118 >= 441 && var118 <= 581) if (var118 >= 441 && var118 <= 581)
{ {
p->MotoSpeed = ((p->MotoSpeed >> 1) + (p->MotoSpeed >> 2)) >> 2; p->MotoSpeed = ((p->MotoSpeed >> 1) + (p->MotoSpeed >> 2)) >> 2;
@ -3056,7 +3056,7 @@ static void operateweapon(int snum, ESyncBits actions, int psect)
case RIFLEGUN_WEAPON: case RIFLEGUN_WEAPON:
p->kickback_pic++; p->kickback_pic++;
playerAddHoriz(p, 1); playerAddHoriz(&p->q16horiz, &p->horizAdjust, 1);
p->recoil++; p->recoil++;
if (p->kickback_pic <= 12) if (p->kickback_pic <= 12)
@ -3146,11 +3146,11 @@ static void operateweapon(int snum, ESyncBits actions, int psect)
} }
if (p->kickback_pic == 2) if (p->kickback_pic == 2)
{ {
playerAddAngle(p, 16); playerAddAngle(&p->q16ang, &p->angAdjust, 16);
} }
else if (p->kickback_pic == 4) else if (p->kickback_pic == 4)
{ {
playerAddAngle(p, -16); playerAddAngle(&p->q16ang, &p->angAdjust, -16);
} }
if (p->kickback_pic > 4) if (p->kickback_pic > 4)
p->kickback_pic = 1; p->kickback_pic = 1;
@ -3176,11 +3176,11 @@ static void operateweapon(int snum, ESyncBits actions, int psect)
} }
if (p->kickback_pic == 2) if (p->kickback_pic == 2)
{ {
playerAddAngle(p, 4); playerAddAngle(&p->q16ang, &p->angAdjust, 4);
} }
else if (p->kickback_pic == 4) else if (p->kickback_pic == 4)
{ {
playerAddAngle(p, -4); playerAddAngle(&p->q16ang, &p->angAdjust, -4);
} }
if (p->kickback_pic > 4) if (p->kickback_pic > 4)
p->kickback_pic = 1; p->kickback_pic = 1;
@ -3228,7 +3228,7 @@ static void operateweapon(int snum, ESyncBits actions, int psect)
{ {
p->posxv -= sintable[(p->getang() + 512) & 2047] << 4; p->posxv -= sintable[(p->getang() + 512) & 2047] << 4;
p->posyv -= sintable[p->getang() & 2047] << 4; p->posyv -= sintable[p->getang() & 2047] << 4;
playerAddHoriz(p, 20); playerAddHoriz(&p->q16horiz, &p->horizAdjust, 20);
p->recoil += 20; p->recoil += 20;
} }
if (p->kickback_pic > 20) if (p->kickback_pic > 20)
@ -4088,7 +4088,7 @@ HORIZONLY:
if (!d) if (!d)
d = 1; d = 1;
p->recoil -= d; p->recoil -= d;
playerAddHoriz(p, -d); playerAddHoriz(&p->q16horiz, &p->horizAdjust, -d);
} }
if (cl_syncinput) if (cl_syncinput)

View file

@ -209,6 +209,7 @@ struct player_struct
// input stuff. // input stuff.
double horizAdjust, angAdjust; double horizAdjust, angAdjust;
fixed_t horizTarget, angTarget;
// Access helpers for the widened angle and horizon fields. // Access helpers for the widened angle and horizon fields.

View file

@ -1009,13 +1009,9 @@ struct PLAYERstruct
char WpnReloadState; char WpnReloadState;
// Input helper variables and setters. // Input helper variables.
double horizAdjust, angAdjust; double horizAdjust, angAdjust;
fixed_t horizTarget, angTarget; fixed_t horizTarget, angTarget;
void addang(int v) { q16ang = (q16ang + IntToFixed(v)) & 0x7FFFFFF; }
void setang(int v) { q16ang = IntToFixed(v); }
void addhoriz(int v) { q16horiz += (IntToFixed(v)); }
void sethoriz(int v) { q16horiz = IntToFixed(v); }
}; };
extern PLAYER Player[MAX_SW_PLAYERS_REG+1]; extern PLAYER Player[MAX_SW_PLAYERS_REG+1];

View file

@ -291,43 +291,11 @@ static void processMovement(PLAYERp const pp, ControlInfo* const hidInput, bool
DoPlayerHorizon(pp, q16horz, scaleAdjust); DoPlayerHorizon(pp, q16horz, scaleAdjust);
} }
if (pp->horizTarget)
{
fixed_t horizDelta = pp->horizTarget - pp->q16horiz;
pp->q16horiz += xs_CRoundToInt(scaleAdjust * horizDelta);
if (abs(pp->q16horiz - pp->horizTarget) < FRACUNIT)
{
pp->q16horiz = pp->horizTarget;
pp->horizTarget = 0;
}
}
else if (pp->horizAdjust)
{
pp->q16horiz += FloatToFixed(scaleAdjust * pp->horizAdjust);
}
if (TEST(pp->Flags2, PF2_INPUT_CAN_TURN_GENERAL)) if (TEST(pp->Flags2, PF2_INPUT_CAN_TURN_GENERAL))
{ {
DoPlayerTurn(pp, q16avel, scaleAdjust); DoPlayerTurn(pp, q16avel, scaleAdjust);
} }
if (pp->angTarget)
{
fixed_t angDelta = getincangleq16(pp->q16ang, pp->angTarget);
pp->q16ang = (pp->q16ang + xs_CRoundToInt(scaleAdjust * angDelta));
if (abs(pp->q16ang - pp->angTarget) < FRACUNIT)
{
pp->q16ang = pp->angTarget;
pp->angTarget = 0;
}
}
else if (pp->angAdjust)
{
pp->q16ang = (pp->q16ang + FloatToFixed(scaleAdjust * pp->angAdjust)) & 0x7FFFFFF;
}
if (TEST(pp->Flags2, PF2_INPUT_CAN_TURN_VEHICLE)) if (TEST(pp->Flags2, PF2_INPUT_CAN_TURN_VEHICLE))
{ {
DoPlayerTurnVehicle(pp, q16avel, pp->posz + Z(10), labs(pp->posz + Z(10) - pp->sop->floor_loz)); DoPlayerTurnVehicle(pp, q16avel, pp->posz + Z(10), labs(pp->posz + Z(10) - pp->sop->floor_loz));
@ -337,6 +305,8 @@ static void processMovement(PLAYERp const pp, ControlInfo* const hidInput, bool
{ {
DoPlayerTurnTurret(pp, q16avel); DoPlayerTurnTurret(pp, q16avel);
} }
playerProcessHelpers(&pp->q16ang, &pp->angAdjust, &pp->angTarget, &pp->q16horiz, &pp->horizAdjust, &pp->horizTarget, scaleAdjust);
} }
loc.fvel = clamp(loc.fvel + fvel, -MAXFVEL, MAXFVEL); loc.fvel = clamp(loc.fvel + fvel, -MAXFVEL, MAXFVEL);

View file

@ -1059,6 +1059,18 @@ STATEp sg_PlayerNinjaFly[] =
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------
//
// Unsynchronised input helper.
//
//---------------------------------------------------------------------------
static void resetinputhelpers(PLAYERp pp)
{
pp->horizAdjust = 0;
pp->angAdjust = 0;
}
void void
DoPlayerSpriteThrow(PLAYERp pp) DoPlayerSpriteThrow(PLAYERp pp)
{ {
@ -3657,7 +3669,7 @@ DoPlayerClimb(PLAYERp pp)
pp->lx = lsp->x + nx * 5; pp->lx = lsp->x + nx * 5;
pp->ly = lsp->y + ny * 5; pp->ly = lsp->y + ny * 5;
playerSetAngle(pp, pp->LadderAngle); playerSetAngle(&pp->q16ang, &pp->angTarget, pp->LadderAngle);
} }
} }
} }
@ -4116,7 +4128,7 @@ PlayerOnLadder(PLAYERp pp)
pp->lx = lsp->x + nx * 5; pp->lx = lsp->x + nx * 5;
pp->ly = lsp->y + ny * 5; pp->ly = lsp->y + ny * 5;
playerSetAngle(pp, pp->LadderAngle); playerSetAngle(&pp->q16ang, &pp->angTarget, pp->LadderAngle);
return true; return true;
} }
@ -5355,7 +5367,7 @@ DoPlayerBeginOperate(PLAYERp pp)
pp->sop = pp->sop_control = sop; pp->sop = pp->sop_control = sop;
sop->controller = pp->SpriteP; sop->controller = pp->SpriteP;
playerSetAngle(pp, sop->ang); playerSetAngle(&pp->q16ang, &pp->angTarget, sop->ang);
pp->posx = sop->xmid; pp->posx = sop->xmid;
pp->posy = sop->ymid; pp->posy = sop->ymid;
COVERupdatesector(pp->posx, pp->posy, &pp->cursectnum); COVERupdatesector(pp->posx, pp->posy, &pp->cursectnum);
@ -5442,7 +5454,7 @@ DoPlayerBeginRemoteOperate(PLAYERp pp, SECTOR_OBJECTp sop)
save_sectnum = pp->cursectnum; save_sectnum = pp->cursectnum;
playerSetAngle(pp, sop->ang); playerSetAngle(&pp->q16ang, &pp->angTarget, sop->ang);
pp->posx = sop->xmid; pp->posx = sop->xmid;
pp->posy = sop->ymid; pp->posy = sop->ymid;
COVERupdatesector(pp->posx, pp->posy, &pp->cursectnum); COVERupdatesector(pp->posx, pp->posy, &pp->cursectnum);
@ -6127,12 +6139,12 @@ DoPlayerDeathHoriz(PLAYERp pp, short target, short speed)
{ {
if ((pp->q16horiz - IntToFixed(target)) > FRACUNIT) if ((pp->q16horiz - IntToFixed(target)) > FRACUNIT)
{ {
playerAddHoriz(pp, -speed); playerAddHoriz(&pp->q16horiz, &pp->horizAdjust, -speed);
} }
if ((IntToFixed(target) - pp->q16horiz) > FRACUNIT) if ((IntToFixed(target) - pp->q16horiz) > FRACUNIT)
{ {
playerAddHoriz(pp, speed); playerAddHoriz(&pp->q16horiz, &pp->horizAdjust, speed);
} }
} }
@ -6229,7 +6241,7 @@ void DoPlayerDeathFollowKiller(PLAYERp pp)
if (FAFcansee(kp->x, kp->y, SPRITEp_TOS(kp), kp->sectnum, pp->posx, pp->posy, pp->posz, pp->cursectnum)) if (FAFcansee(kp->x, kp->y, SPRITEp_TOS(kp), kp->sectnum, pp->posx, pp->posy, pp->posz, pp->cursectnum))
{ {
playerAddAngle(pp, getincangleq16(pp->q16ang, gethiq16angle(kp->x - pp->posx, kp->y - pp->posy)) / (double)(FRACUNIT << 4)); playerAddAngle(&pp->q16ang, &pp->angAdjust, getincangleq16(pp->q16ang, gethiq16angle(kp->x - pp->posx, kp->y - pp->posy)) / (double)(FRACUNIT << 4));
} }
} }
} }
@ -7269,7 +7281,7 @@ domovethings(void)
// auto tracking mode for single player multi-game // auto tracking mode for single player multi-game
if (numplayers <= 1 && PlayerTrackingMode && pnum == screenpeek && screenpeek != myconnectindex) if (numplayers <= 1 && PlayerTrackingMode && pnum == screenpeek && screenpeek != myconnectindex)
{ {
playerSetAngle(&Player[screenpeek], FixedToFloat(gethiq16angle(Player[myconnectindex].posx - Player[screenpeek].posx, Player[myconnectindex].posy - Player[screenpeek].posy))); playerSetAngle(&Player[screenpeek].q16ang, &Player[screenpeek].angTarget, FixedToFloat(gethiq16angle(Player[myconnectindex].posx - Player[screenpeek].posx, Player[myconnectindex].posy - Player[screenpeek].posy)));
} }
if (!TEST(pp->Flags, PF_DEAD)) if (!TEST(pp->Flags, PF_DEAD))
@ -7617,84 +7629,6 @@ void CheckFootPrints(PLAYERp pp)
} }
} }
//---------------------------------------------------------------------------
//
// Unsynchronised input helpers.
//
//---------------------------------------------------------------------------
void resetinputhelpers(PLAYERp pp)
{
pp->horizAdjust = 0;
pp->angAdjust = 0;
}
void playerAddAngle(PLAYERp pp, double ang)
{
if (!cl_syncinput)
{
pp->angAdjust += ang;
}
else
{
pp->addang(ang);
}
}
void playerSetAngle(PLAYERp pp, double ang)
{
if (!cl_syncinput)
{
// Cancel out any angle adjustments as we're setting angle now.
pp->angAdjust = 0;
// Add slight offset if input angle is coming in as absolute 0.
if (ang == 0)
{
ang += 0.1;
}
pp->angTarget = pp->q16ang + getincangleq16(pp->q16ang, FloatToFixed(ang));
}
else
{
pp->setang(ang);
}
}
void playerAddHoriz(PLAYERp pp, double horiz)
{
if (!cl_syncinput)
{
pp->horizAdjust += horiz;
}
else
{
pp->addhoriz(horiz);
}
}
void playerSetHoriz(PLAYERp pp, double horiz)
{
if (!cl_syncinput)
{
// Cancel out any horizon adjustments as we're setting horizon now.
pp->horizAdjust = 0;
// Add slight offset if input horizon is coming in as absolute 0.
if (horiz == 0)
{
horiz += 0.1;
}
pp->horizTarget = FloatToFixed(horiz);
}
else
{
pp->sethoriz(horiz);
}
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// //
// //

View file

@ -144,12 +144,6 @@ void PlaySOsound(short sectnum,short sound_num);
void DoSpawnTeleporterEffectPlace(SPRITEp sp); void DoSpawnTeleporterEffectPlace(SPRITEp sp);
void FindMainSector(SECTOR_OBJECTp sop); void FindMainSector(SECTOR_OBJECTp sop);
void resetinputhelpers(PLAYERp pp);
void playerAddAngle(PLAYERp pp, double ang);
void playerSetAngle(PLAYERp pp, double ang);
void playerAddHoriz(PLAYERp pp, double horiz);
void playerSetHoriz(PLAYERp pp, double horiz);
END_SW_NS END_SW_NS
#endif #endif

View file

@ -1678,7 +1678,7 @@ MovePlayer(PLAYERp pp, SECTOR_OBJECTp sop, int nx, int ny)
// New angle is formed by taking last known angle and // New angle is formed by taking last known angle and
// adjusting by the delta angle // adjusting by the delta angle
playerAddAngle(pp, getincangleq16(pp->q16ang, pp->RevolveQ16Ang + IntToFixed(pp->RevolveDeltaAng))); playerAddAngle(&pp->q16ang, &pp->angAdjust, FixedToFloat(getincangleq16(pp->q16ang, pp->RevolveQ16Ang + IntToFixed(pp->RevolveDeltaAng))));
UpdatePlayerSprite(pp); UpdatePlayerSprite(pp);
} }