diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index fcab71144..a5449c511 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -272,13 +272,13 @@ void processMovement(InputPacket* currInput, InputPacket* inputBuffer, ControlIn // //--------------------------------------------------------------------------- -void sethorizon(PlayerHorizon* horizon, float const horz, ESyncBits* actions, double const scaleAdjust) +void PlayerHorizon::sethorizon(float const horz, ESyncBits* actions, double const scaleAdjust) { // Process only if no targeted horizon set. - if (!horizon->targetset()) + if (!targetset()) { // Store current horizon as true pitch. - double pitch = horizon->horiz.aspitch(); + double pitch = horiz.aspitch(); if (horz) { @@ -313,20 +313,20 @@ void sethorizon(PlayerHorizon* horizon, float const horz, ESyncBits* actions, do } // clamp before converting back to horizon - horizon->horiz = q16horiz(clamp(PitchToHoriz(pitch), gi->playerHorizMin(), gi->playerHorizMax())); + 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()) > (FRACUNIT >> 2)) + if (abs(horiz.asq16()) > (FRACUNIT >> 2)) { // move horiz back to 0 - horizon->horiz -= buildfhoriz(scaleAdjust * horizon->horiz.asbuildf() * (10. / GameTicRate)); + horiz -= buildfhoriz(scaleAdjust * horiz.asbuildf() * (10. / GameTicRate)); } else { // not looking anymore because horiz is back at 0 - horizon->horiz = q16horiz(0); + horiz = q16horiz(0); *actions &= ~SB_CENTERVIEW; } } @@ -343,66 +343,66 @@ void sethorizon(PlayerHorizon* horizon, float const horz, ESyncBits* actions, do // //--------------------------------------------------------------------------- -void applylook(PlayerAngle* angle, float const avel, ESyncBits* actions, double const scaleAdjust) +void PlayerAngle::applylook(float const avel, ESyncBits* actions, double const scaleAdjust) { // return q16rotscrnang to 0 and set to 0 if less than a quarter of a unit - angle->rotscrnang -= buildfang(scaleAdjust * angle->rotscrnang.signedbuildf() * (15. / GameTicRate)); - if (abs(angle->rotscrnang.signedbam()) < (BAMUNIT >> 2)) angle->rotscrnang = bamang(0); + rotscrnang -= buildfang(scaleAdjust * rotscrnang.signedbuildf() * (15. / GameTicRate)); + if (abs(rotscrnang.signedbam()) < (BAMUNIT >> 2)) rotscrnang = bamang(0); // return q16look_ang to 0 and set to 0 if less than a quarter of a unit - angle->look_ang -= buildfang(scaleAdjust * angle->look_ang.signedbuildf() * (7.5 / GameTicRate)); - if (abs(angle->look_ang.signedbam()) < (BAMUNIT >> 2)) angle->look_ang = bamang(0); + look_ang -= buildfang(scaleAdjust * look_ang.signedbuildf() * (7.5 / GameTicRate)); + if (abs(look_ang.signedbam()) < (BAMUNIT >> 2)) look_ang = bamang(0); if (*actions & SB_LOOK_LEFT) { // start looking left - angle->look_ang += buildfang(scaleAdjust * -(4560. / GameTicRate)); - angle->rotscrnang += buildfang(scaleAdjust * (720. / GameTicRate)); + look_ang += buildfang(scaleAdjust * -(4560. / GameTicRate)); + rotscrnang += buildfang(scaleAdjust * (720. / GameTicRate)); } if (*actions & SB_LOOK_RIGHT) { // start looking right - angle->look_ang += buildfang(scaleAdjust * (4560. / GameTicRate)); - angle->rotscrnang += buildfang(scaleAdjust * -(720. / GameTicRate)); + look_ang += buildfang(scaleAdjust * (4560. / GameTicRate)); + rotscrnang += buildfang(scaleAdjust * -(720. / GameTicRate)); } - if (!angle->targetset()) + if (!targetset()) { if (*actions & SB_TURNAROUND) { - if (angle->spin == 0) + if (spin == 0) { // currently not spinning, so start a spin - angle->spin = -1024.; + spin = -1024.; } *actions &= ~SB_TURNAROUND; } - if (angle->spin < 0) + if (spin < 0) { // return spin to 0 double add = scaleAdjust * ((!(*actions & SB_CROUCH) ? 3840. : 1920.) / GameTicRate); - angle->spin += add; - if (angle->spin > 0) + spin += add; + if (spin > 0) { // Don't overshoot our target. With variable factor this is possible. - add -= angle->spin; - angle->spin = 0; + add -= spin; + spin = 0; } - angle->ang += buildfang(add); + ang += buildfang(add); } if (avel) { // add player's input - angle->ang += degang(avel); - angle->spin = 0; + ang += degang(avel); + spin = 0; } } else { - angle->spin = 0; + spin = 0; } } @@ -412,7 +412,7 @@ void applylook(PlayerAngle* angle, float const avel, ESyncBits* actions, double // //--------------------------------------------------------------------------- -void calcviewpitch(vec2_t const pos, fixedhoriz* horizoff, binangle const ang, bool const aimmode, bool const canslopetilt, int const cursectnum, double const scaleAdjust, bool const climbing) +void PlayerHorizon::calcviewpitch(vec2_t const pos, binangle const ang, bool const aimmode, bool const canslopetilt, int const cursectnum, double const scaleAdjust, bool const climbing) { if (cl_slopetilting) { @@ -439,7 +439,7 @@ void calcviewpitch(vec2_t const pos, fixedhoriz* horizoff, binangle const ang, b // accordingly if (cursectnum == tempsect || (!isBlood() && abs(getflorzofslope(tempsect, x, y) - k) <= (4 << 8))) { - *horizoff += q16horiz(xs_CRoundToInt(scaleAdjust * ((j - k) * (!isBlood() ? 160 : 1408)))); + horizoff += q16horiz(xs_CRoundToInt(scaleAdjust * ((j - k) * (!isBlood() ? 160 : 1408)))); } } } @@ -447,21 +447,21 @@ void calcviewpitch(vec2_t const pos, fixedhoriz* horizoff, binangle const ang, b if (climbing) { // tilt when climbing but you can't even really tell it. - if (horizoff->asq16() < IntToFixed(100)) - *horizoff += q16horiz(xs_CRoundToInt(scaleAdjust * (((IntToFixed(100) - horizoff->asq16()) >> 3) + FRACUNIT))); + if (horizoff.asq16() < IntToFixed(100)) + horizoff += q16horiz(xs_CRoundToInt(scaleAdjust * (((IntToFixed(100) - horizoff.asq16()) >> 3) + FRACUNIT))); } else { // Make horizoff grow towards 0 since horizoff is not modified when you're not on a slope. - if (horizoff->asq16() > 0) + if (horizoff.asq16() > 0) { - *horizoff += q16horiz(xs_CRoundToInt(-scaleAdjust * ((horizoff->asq16() >> 3) + FRACUNIT))); - if (horizoff->asq16() < 0) *horizoff = q16horiz(0); + horizoff += q16horiz(xs_CRoundToInt(-scaleAdjust * ((horizoff.asq16() >> 3) + FRACUNIT))); + if (horizoff.asq16() < 0) horizoff = q16horiz(0); } - if (horizoff->asq16() < 0) + if (horizoff.asq16() < 0) { - *horizoff += q16horiz(xs_CRoundToInt(-scaleAdjust * ((horizoff->asq16() >> 3) - FRACUNIT))); - if (horizoff->asq16() > 0) *horizoff = q16horiz(0); + horizoff += q16horiz(xs_CRoundToInt(-scaleAdjust * ((horizoff.asq16() >> 3) - FRACUNIT))); + if (horizoff.asq16() > 0) horizoff = q16horiz(0); } } } diff --git a/source/core/gameinput.h b/source/core/gameinput.h index 9e671e7c1..44e058ccd 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -99,6 +99,9 @@ struct PlayerHorizon return !precise ? sum().asq16() >> 20 : (!SyncInput() ? sum() : interpolatedsum(smoothratio)).asbuildf() * (1. / 16.); // Used within draw code for Duke. } + void sethorizon(float const horz, ESyncBits* actions, double const scaleAdjust = 1); + void calcviewpitch(vec2_t const pos, binangle const ang, bool const aimmode, bool const canslopetilt, int const cursectnum, double const scaleAdjust = 1, bool const climbing = false); + private: fixedhoriz target; double adjustment; @@ -236,6 +239,8 @@ struct PlayerAngle return !precise ? abs(look_ang.signedbuild()) / 9 : fabs((!SyncInput() ? look_ang : interpolatedlookang(smoothratio)).signedbuildf()) * (1. / 9.); // Used within draw code for weapon and crosshair when looking left/right. } + void applylook(float const avel, ESyncBits* actions, double const scaleAdjust = 1); + private: binangle target; double adjustment; @@ -276,6 +281,3 @@ 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(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); diff --git a/source/games/blood/src/controls.cpp b/source/games/blood/src/controls.cpp index 9da34ba1e..a4c92d2a8 100644 --- a/source/games/blood/src/controls.cpp +++ b/source/games/blood/src/controls.cpp @@ -58,8 +58,8 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput) // Perform unsynchronised angle/horizon if not dead. if (gView->pXSprite->health != 0) { - applylook(&pPlayer->angle, input.avel, &pPlayer->input.actions, scaleAdjust); - sethorizon(&pPlayer->horizon, input.horz, &pPlayer->input.actions, scaleAdjust); + pPlayer->angle.applylook(input.avel, &pPlayer->input.actions, scaleAdjust); + pPlayer->horizon.sethorizon(input.horz, &pPlayer->input.actions, scaleAdjust); doslopetilting(pPlayer, scaleAdjust); } diff --git a/source/games/blood/src/player.cpp b/source/games/blood/src/player.cpp index 45e10fb68..66dcc4ff3 100644 --- a/source/games/blood/src/player.cpp +++ b/source/games/blood/src/player.cpp @@ -1300,7 +1300,7 @@ void doslopetilting(PLAYER* pPlayer, double const scaleAdjust = 1) auto* const pXSprite = pPlayer->pXSprite; int const florhit = gSpriteHit[pSprite->extra].florhit & 0xc000; char const va = pXSprite->height < 16 && (florhit == 0x4000 || florhit == 0) ? 1 : 0; - calcviewpitch(pSprite->pos.vec2, &pPlayer->horizon.horizoff, buildang(pSprite->ang), va, sector[pSprite->sectnum].floorstat & 2, pSprite->sectnum, scaleAdjust); + pPlayer->horizon.calcviewpitch(pSprite->pos.vec2, buildang(pSprite->ang), va, sector[pSprite->sectnum].floorstat & 2, pSprite->sectnum, scaleAdjust); } void ProcessInput(PLAYER *pPlayer) @@ -1422,7 +1422,7 @@ void ProcessInput(PLAYER *pPlayer) if (SyncInput()) { - applylook(&pPlayer->angle, pInput->avel, &pInput->actions); + pPlayer->angle.applylook(pInput->avel, &pInput->actions); } // unconditionally update the player's sprite angle @@ -1549,7 +1549,7 @@ void ProcessInput(PLAYER *pPlayer) if (SyncInput()) { - sethorizon(&pPlayer->horizon, pInput->horz, &pInput->actions); + pPlayer->horizon.sethorizon(pInput->horz, &pInput->actions); doslopetilting(pPlayer); } diff --git a/source/games/duke/src/inlines.h b/source/games/duke/src/inlines.h index 90286e98b..38ed67616 100644 --- a/source/games/duke/src/inlines.h +++ b/source/games/duke/src/inlines.h @@ -190,7 +190,7 @@ inline bool playrunning() inline void doslopetilting(player_struct* p, double const scaleAdjust = 1) { bool const canslopetilt = p->on_ground && sector[p->cursectnum].lotag != ST_2_UNDERWATER && (sector[p->cursectnum].floorstat & 2); - calcviewpitch(p->pos.vec2, &p->horizon.horizoff, p->angle.ang, p->aim_mode == 0, canslopetilt, p->cursectnum, scaleAdjust); + p->horizon.calcviewpitch(p->pos.vec2, p->angle.ang, p->aim_mode == 0, canslopetilt, p->cursectnum, scaleAdjust); } diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index a36acd2cb..5b2f0f955 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -834,9 +834,9 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput) { // Do these in the same order as the old code. doslopetilting(p, scaleAdjust); - applylook(&p->angle, p->adjustavel(input.avel), &p->sync.actions, scaleAdjust); + p->angle.applylook(p->adjustavel(input.avel), &p->sync.actions, scaleAdjust); p->apply_seasick(scaleAdjust); - sethorizon(&p->horizon, input.horz, &p->sync.actions, scaleAdjust); + p->horizon.sethorizon(input.horz, &p->sync.actions, scaleAdjust); } p->angle.processhelpers(scaleAdjust); diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index b3dac8381..bcb32f03f 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -2906,7 +2906,7 @@ void processinput_d(int snum) // may still be needed later for demo recording sb_avel = p->adjustavel(sb_avel); - applylook(&p->angle, sb_avel, &p->sync.actions); + p->angle.applylook(sb_avel, &p->sync.actions); } if (p->spritebridge == 0) @@ -3139,7 +3139,7 @@ HORIZONLY: if (SyncInput()) { - sethorizon(&p->horizon, PlayerHorizon(snum), &p->sync.actions); + p->horizon.sethorizon(PlayerHorizon(snum), &p->sync.actions); } p->checkhardlanding(); diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index f515066b8..682fb497d 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -3639,7 +3639,7 @@ void processinput_r(int snum) // may still be needed later for demo recording sb_avel = p->adjustavel(sb_avel); - applylook(&p->angle, sb_avel, &p->sync.actions); + p->angle.applylook(sb_avel, &p->sync.actions); } if (p->spritebridge == 0) @@ -4001,7 +4001,7 @@ HORIZONLY: if (SyncInput()) { - sethorizon(&p->horizon, PlayerHorizon(snum), &p->sync.actions); + p->horizon.sethorizon(PlayerHorizon(snum), &p->sync.actions); } p->checkhardlanding(); diff --git a/source/games/exhumed/src/input.cpp b/source/games/exhumed/src/input.cpp index a471f6fc7..ad3488920 100644 --- a/source/games/exhumed/src/input.cpp +++ b/source/games/exhumed/src/input.cpp @@ -124,8 +124,8 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput) { if (!nFreeze) { - applylook(&pPlayer->angle, input.avel, &sPlayerInput[nLocalPlayer].actions, scaleAdjust); - sethorizon(&pPlayer->horizon, input.horz, &sPlayerInput[nLocalPlayer].actions, scaleAdjust); + pPlayer->angle.applylook(input.avel, &sPlayerInput[nLocalPlayer].actions, scaleAdjust); + pPlayer->horizon.sethorizon(input.horz, &sPlayerInput[nLocalPlayer].actions, scaleAdjust); if (input.horz) { diff --git a/source/games/exhumed/src/player.cpp b/source/games/exhumed/src/player.cpp index 547abc038..94e84740d 100644 --- a/source/games/exhumed/src/player.cpp +++ b/source/games/exhumed/src/player.cpp @@ -915,7 +915,7 @@ void FuncPlayer(int a, int nDamage, int nRun) if (SyncInput()) { Player* pPlayer = &PlayerList[nPlayer]; - applylook(&pPlayer->angle, sPlayerInput[nPlayer].nAngle, &sPlayerInput[nLocalPlayer].actions); + pPlayer->angle.applylook(sPlayerInput[nPlayer].nAngle, &sPlayerInput[nLocalPlayer].actions); UpdatePlayerSpriteAngle(pPlayer); } @@ -2651,7 +2651,7 @@ loc_1BD2E: if (SyncInput()) { - sethorizon(&pPlayer->horizon, sPlayerInput[nPlayer].pan, &sPlayerInput[nLocalPlayer].actions); + pPlayer->horizon.sethorizon(sPlayerInput[nPlayer].pan, &sPlayerInput[nLocalPlayer].actions); } if (sPlayerInput[nPlayer].pan) diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 1364eff32..f17f427a1 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -1516,7 +1516,7 @@ UpdatePlayerSpriteAngle(PLAYERp pp) void DoPlayerTurn(PLAYERp pp, float const avel, double const scaleAdjust) { - applylook(&pp->angle, avel, &pp->input.actions, scaleAdjust); + pp->angle.applylook(avel, &pp->input.actions, scaleAdjust); UpdatePlayerSpriteAngle(pp); } @@ -1667,8 +1667,8 @@ void 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, horz, &pp->input.actions, scaleAdjust); + pp->horizon.calcviewpitch(pp->pos.vec2, pp->angle.ang, pp->input.actions & SB_AIMMODE, canslopetilt, pp->cursectnum, scaleAdjust, TEST(pp->Flags, PF_CLIMBING)); + pp->horizon.sethorizon(horz, &pp->input.actions, scaleAdjust); } void