From f806cdcec6288d2546e97ca07cf71f72d844e69b Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Mon, 21 Sep 2020 13:41:16 +1000 Subject: [PATCH] - Blood/Duke/RR/SW: Unify the player's angle/horizon helper functions. --- source/blood/src/controls.cpp | 34 +-------- source/blood/src/player.cpp | 72 +------------------- source/blood/src/player.h | 6 +- source/core/gamecontrol.cpp | 103 ++++++++++++++++++++++++++++ source/core/gamecontrol.h | 5 ++ source/games/duke/src/actors.cpp | 10 +-- source/games/duke/src/actors_d.cpp | 2 +- source/games/duke/src/actors_r.cpp | 2 +- source/games/duke/src/funct.h | 5 -- source/games/duke/src/gameexec.cpp | 4 +- source/games/duke/src/input.cpp | 11 +-- source/games/duke/src/player.cpp | 60 +--------------- source/games/duke/src/player_r.cpp | 34 ++++----- source/games/duke/src/types.h | 1 + source/sw/src/game.h | 6 +- source/sw/src/input.cpp | 34 +-------- source/sw/src/player.cpp | 106 ++++++----------------------- source/sw/src/player.h | 6 -- source/sw/src/track.cpp | 2 +- 19 files changed, 168 insertions(+), 335 deletions(-) diff --git a/source/blood/src/controls.cpp b/source/blood/src/controls.cpp index 8df024e9a..005fa9d0c 100644 --- a/source/blood/src/controls.cpp +++ b/source/blood/src/controls.cpp @@ -143,39 +143,7 @@ static void processMovement(ControlInfo* const hidInput) sethorizon(&pPlayer->q16horiz, input.q16horz, &pPlayer->input.actions, scaleAdjust); } - // Process angle amendments from the game's ticker. - 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); - } + playerProcessHelpers(&pPlayer->q16ang, &pPlayer->angAdjust, &pPlayer->angTarget, &pPlayer->q16horiz, &pPlayer->horizAdjust, &pPlayer->horizTarget, scaleAdjust); } gInput.fvel = clamp(gInput.fvel + input.fvel, -MAXFVEL, MAXFVEL); diff --git a/source/blood/src/player.cpp b/source/blood/src/player.cpp index 098aa8b97..46fca1854 100644 --- a/source/blood/src/player.cpp +++ b/source/blood/src/player.cpp @@ -1323,78 +1323,12 @@ void UpdatePlayerSpriteAngle(PLAYER *pPlayer) // //--------------------------------------------------------------------------- -void resetinputhelpers(PLAYER* pPlayer) +static void resetinputhelpers(PLAYER* pPlayer) { pPlayer->horizAdjust = 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) { enum @@ -1425,11 +1359,11 @@ void ProcessInput(PLAYER *pPlayer) if (pPlayer->fraggerId != -1) { 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; 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) pInput->setNewWeapon(pPlayer->curWeapon); if (pInput->actions & SB_OPEN) diff --git a/source/blood/src/player.h b/source/blood/src/player.h index 531c12d64..d9d558788 100644 --- a/source/blood/src/player.h +++ b/source/blood/src/player.h @@ -187,13 +187,9 @@ struct PLAYER fixed_t q16look_ang; fixed_t q16rotscrnang; - // Input helper variables and setters. + // Input helper variables. double horizAdjust, angAdjust; 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 diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index f7cd115f7..cb838ada8 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -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); + } +} diff --git a/source/core/gamecontrol.h b/source/core/gamecontrol.h index 58bfac0af..4939875e3 100644 --- a/source/core/gamecontrol.h +++ b/source/core/gamecontrol.h @@ -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 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 { diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index 058943ea7..03d9c44b1 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -468,7 +468,7 @@ void moveplayers(void) //Players 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) @@ -491,7 +491,7 @@ void moveplayers(void) //Players 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(); @@ -748,7 +748,7 @@ void movecrane(int i, int crane) s->owner = -2; ps[p].on_crane = 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 { @@ -2674,7 +2674,7 @@ void handle_se00(int i, int LASERLINE) { 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; @@ -2866,7 +2866,7 @@ void handle_se14(int i, bool checkstat, int RPG, int JIBS6) ps[p].bobposx += m; ps[p].bobposy += x; - playerAddAngle(&ps[p], q); + playerAddAngle(&ps[p].q16ang, &ps[p].angAdjust, q); if (numplayers > 1) { diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index c06230e9a..f13d10cf3 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -1852,7 +1852,7 @@ void moveweapons_d(void) if (s->picnum == SPIT) { - playerAddHoriz(&ps[p], 32); + playerAddHoriz(&ps[p].q16horiz, &ps[p].horizAdjust, 32); sync[p].actions |= SB_CENTERVIEW; if (ps[p].loogcnt == 0) diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index 61f517ba7..79f60ecf0 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -1399,7 +1399,7 @@ void moveweapons_r(void) guts_r(s, RABBITJIBC, 2, myconnectindex); } - playerAddHoriz(&ps[p], 32); + playerAddHoriz(&ps[p].q16horiz, &ps[p].horizAdjust, 32); sync[p].actions |= SB_CENTERVIEW; if (ps[p].loogcnt == 0) diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index 7fd6a94db..eae5f08e3 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -248,9 +248,4 @@ void resetinputhelpers(player_struct* p); void checkhardlanding(player_struct* p); 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 diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index c2b583c04..77b62973e 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -330,7 +330,7 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, int sActor, int sPl break; 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); break; @@ -452,7 +452,7 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, int sActor, int sPl break; 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); break; diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 536f208b7..02c57ca7b 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -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); apply_seasick(p, scaleAdjust); sethorizon(&p->q16horiz, input.q16horz, &sync[myconnectindex].actions, scaleAdjust); - - if (p->angAdjust) - { - p->q16ang += FloatToFixed(scaleAdjust * p->angAdjust); - } - - if (p->horizAdjust) - { - p->q16horiz += FloatToFixed(scaleAdjust * p->horizAdjust); - } + playerProcessHelpers(&p->q16ang, &p->angAdjust, &p->angTarget, &p->q16horiz, &p->horizAdjust, &p->horizTarget, scaleAdjust); } } diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index 169b99f71..3741ea8bc 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -164,7 +164,7 @@ void forceplayerangle(int snum) n = 128 - (krand() & 255); - playerAddHoriz(p, 64); + playerAddHoriz(&p->q16horiz, &p->horizAdjust, 64); sync[snum].actions |= SB_CENTERVIEW; p->setlookang(n >> 1); p->setrotscrnang(n >> 1); @@ -406,7 +406,7 @@ void dokneeattack(int snum, int pi, const std::initializer_list & respawnli if (p->knee_incs > 0) { p->knee_incs++; - playerAddHoriz(p, -48); + playerAddHoriz(&p->q16horiz, &p->horizAdjust, -48); sync[snum].actions |= SB_CENTERVIEW; if (p->knee_incs > 15) { @@ -887,7 +887,7 @@ void checkhardlanding(player_struct* p) { if (p->hard_landing > 0) { - playerAddHoriz(p, -(p->hard_landing << 4)); + playerAddHoriz(&p->q16horiz, &p->horizAdjust, -(p->hard_landing << 4)); 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. diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index 806c976f3..26d231e24 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -1733,7 +1733,7 @@ static void onMotorcycle(int snum, ESyncBits &actions) p->TurbCount--; p->moto_drink = (krand() & 3) - 2; } - playerSetHoriz(p, horiz); + playerSetHoriz(&p->q16horiz, &p->horizTarget, horiz); } else if (p->VBumpTarget > p->VBumpNow) { @@ -1743,7 +1743,7 @@ static void onMotorcycle(int snum, ESyncBits &actions) p->VBumpNow++; if (p->VBumpTarget < p->VBumpNow) 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) { @@ -1753,7 +1753,7 @@ static void onMotorcycle(int snum, ESyncBits &actions) p->VBumpNow--; if (p->VBumpTarget > p->VBumpNow) p->VBumpNow = p->VBumpTarget; - playerSetHoriz(p, 100 + p->VBumpNow / 3); + playerSetHoriz(&p->q16horiz, &p->horizTarget, 100 + p->VBumpNow / 3); } else { @@ -1812,7 +1812,7 @@ static void onMotorcycle(int snum, ESyncBits &actions) 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)) { @@ -2057,7 +2057,7 @@ static void onBoat(int snum, ESyncBits &actions) p->TurbCount--; p->moto_drink = (krand() & 3) - 2; } - playerSetHoriz(p, horiz); + playerSetHoriz(&p->q16horiz, &p->horizTarget, horiz); } else if (p->VBumpTarget > p->VBumpNow) { @@ -2067,7 +2067,7 @@ static void onBoat(int snum, ESyncBits &actions) p->VBumpNow++; if (p->VBumpTarget < p->VBumpNow) 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) { @@ -2077,7 +2077,7 @@ static void onBoat(int snum, ESyncBits &actions) p->VBumpNow--; if (p->VBumpTarget > p->VBumpNow) p->VBumpNow = p->VBumpTarget; - playerSetHoriz(p, 100 + p->VBumpNow / 3); + playerSetHoriz(&p->q16horiz, &p->horizTarget, 100 + p->VBumpNow / 3); } else { @@ -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, (vard8 - ang) & 2047); + playerSetAngle(&p->q16ang, &p->angTarget, (vard8 - ang) & 2047); } if (p->NotOnWater) if (p->MotoSpeed > 50) @@ -2455,7 +2455,7 @@ void onMotorcycleMove(int snum, int psect, int j) ang = -(p->MotoSpeed >> 1); break; } - playerAddAngle(p, ang); + playerAddAngle(&p->q16ang, &p->angAdjust, ang); if (var10c >= 441 && var10c <= 581) { var104 = (p->MotoSpeed * p->MotoSpeed) >> 8; @@ -2522,7 +2522,7 @@ void onBoatMove(int snum, int psect, int j) ang = -(p->MotoSpeed >> 2); break; } - playerAddAngle(p, ang); + playerAddAngle(&p->q16ang, &p->angAdjust, ang); if (var118 >= 441 && var118 <= 581) { 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: p->kickback_pic++; - playerAddHoriz(p, 1); + playerAddHoriz(&p->q16horiz, &p->horizAdjust, 1); p->recoil++; if (p->kickback_pic <= 12) @@ -3146,11 +3146,11 @@ static void operateweapon(int snum, ESyncBits actions, int psect) } if (p->kickback_pic == 2) { - playerAddAngle(p, 16); + playerAddAngle(&p->q16ang, &p->angAdjust, 16); } else if (p->kickback_pic == 4) { - playerAddAngle(p, -16); + playerAddAngle(&p->q16ang, &p->angAdjust, -16); } if (p->kickback_pic > 4) p->kickback_pic = 1; @@ -3176,11 +3176,11 @@ static void operateweapon(int snum, ESyncBits actions, int psect) } if (p->kickback_pic == 2) { - playerAddAngle(p, 4); + playerAddAngle(&p->q16ang, &p->angAdjust, 4); } else if (p->kickback_pic == 4) { - playerAddAngle(p, -4); + playerAddAngle(&p->q16ang, &p->angAdjust, -4); } if (p->kickback_pic > 4) 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->posyv -= sintable[p->getang() & 2047] << 4; - playerAddHoriz(p, 20); + playerAddHoriz(&p->q16horiz, &p->horizAdjust, 20); p->recoil += 20; } if (p->kickback_pic > 20) @@ -4088,7 +4088,7 @@ HORIZONLY: if (!d) d = 1; p->recoil -= d; - playerAddHoriz(p, -d); + playerAddHoriz(&p->q16horiz, &p->horizAdjust, -d); } if (cl_syncinput) diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index d537685f5..3e4cd1e40 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -209,6 +209,7 @@ struct player_struct // input stuff. double horizAdjust, angAdjust; + fixed_t horizTarget, angTarget; // Access helpers for the widened angle and horizon fields. diff --git a/source/sw/src/game.h b/source/sw/src/game.h index 8fd9ea8a2..e297550c7 100644 --- a/source/sw/src/game.h +++ b/source/sw/src/game.h @@ -1009,13 +1009,9 @@ struct PLAYERstruct char WpnReloadState; - // Input helper variables and setters. + // Input helper variables. double horizAdjust, angAdjust; 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]; diff --git a/source/sw/src/input.cpp b/source/sw/src/input.cpp index a1a70d553..9034e77a6 100644 --- a/source/sw/src/input.cpp +++ b/source/sw/src/input.cpp @@ -291,43 +291,11 @@ static void processMovement(PLAYERp const pp, ControlInfo* const hidInput, bool 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)) { 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)) { 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); } + + playerProcessHelpers(&pp->q16ang, &pp->angAdjust, &pp->angTarget, &pp->q16horiz, &pp->horizAdjust, &pp->horizTarget, scaleAdjust); } loc.fvel = clamp(loc.fvel + fvel, -MAXFVEL, MAXFVEL); diff --git a/source/sw/src/player.cpp b/source/sw/src/player.cpp index ce9721a88..50f05604e 100644 --- a/source/sw/src/player.cpp +++ b/source/sw/src/player.cpp @@ -1059,6 +1059,18 @@ STATEp sg_PlayerNinjaFly[] = ///////////////////////////////////////////////////////////////////////////// +//--------------------------------------------------------------------------- +// +// Unsynchronised input helper. +// +//--------------------------------------------------------------------------- + +static void resetinputhelpers(PLAYERp pp) +{ + pp->horizAdjust = 0; + pp->angAdjust = 0; +} + void DoPlayerSpriteThrow(PLAYERp pp) { @@ -3657,7 +3669,7 @@ DoPlayerClimb(PLAYERp pp) pp->lx = lsp->x + nx * 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->ly = lsp->y + ny * 5; - playerSetAngle(pp, pp->LadderAngle); + playerSetAngle(&pp->q16ang, &pp->angTarget, pp->LadderAngle); return true; } @@ -5355,7 +5367,7 @@ DoPlayerBeginOperate(PLAYERp pp) pp->sop = pp->sop_control = sop; sop->controller = pp->SpriteP; - playerSetAngle(pp, sop->ang); + playerSetAngle(&pp->q16ang, &pp->angTarget, sop->ang); pp->posx = sop->xmid; pp->posy = sop->ymid; COVERupdatesector(pp->posx, pp->posy, &pp->cursectnum); @@ -5442,7 +5454,7 @@ DoPlayerBeginRemoteOperate(PLAYERp pp, SECTOR_OBJECTp sop) save_sectnum = pp->cursectnum; - playerSetAngle(pp, sop->ang); + playerSetAngle(&pp->q16ang, &pp->angTarget, sop->ang); pp->posx = sop->xmid; pp->posy = sop->ymid; COVERupdatesector(pp->posx, pp->posy, &pp->cursectnum); @@ -6127,12 +6139,12 @@ DoPlayerDeathHoriz(PLAYERp pp, short target, short speed) { if ((pp->q16horiz - IntToFixed(target)) > FRACUNIT) { - playerAddHoriz(pp, -speed); + playerAddHoriz(&pp->q16horiz, &pp->horizAdjust, -speed); } 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)) { - 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 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)) @@ -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); - } -} - //--------------------------------------------------------------------------- // // diff --git a/source/sw/src/player.h b/source/sw/src/player.h index 527b50742..9f3ca775b 100644 --- a/source/sw/src/player.h +++ b/source/sw/src/player.h @@ -144,12 +144,6 @@ void PlaySOsound(short sectnum,short sound_num); void DoSpawnTeleporterEffectPlace(SPRITEp sp); 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 #endif diff --git a/source/sw/src/track.cpp b/source/sw/src/track.cpp index 41e2234c2..b36178bf2 100644 --- a/source/sw/src/track.cpp +++ b/source/sw/src/track.cpp @@ -1678,7 +1678,7 @@ MovePlayer(PLAYERp pp, SECTOR_OBJECTp sop, int nx, int ny) // New angle is formed by taking last known angle and // 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); }