diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index a36edaa7a..3172631d9 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -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 (*actions & SB_AIM_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); - - if (*actions & SB_LOOK_DOWN) - pitch -= scaleAdjust * amount; - - if (*actions & SB_LOOK_UP) - pitch += scaleAdjust * amount; - } - - // clamp before converting back to 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))) - { - if (abs(horiz->asq16()) > FloatToFixed(0.25)) + if (horz) { - // move horiz back to 0 - *horiz -= q16horiz(xs_CRoundToInt(scaleAdjust * horiz->asq16() * (10. / GameTicRate))); - } - else - { - // not looking anymore because horiz is back at 0 - *horiz = q16horiz(0); *actions &= ~SB_CENTERVIEW; + pitch += horz; + } + + // 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 (*actions & SB_AIM_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); + + if (*actions & SB_LOOK_DOWN) + pitch -= scaleAdjust * amount; + + if (*actions & SB_LOOK_UP) + pitch += scaleAdjust * amount; + } + + // 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))) + { + 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; + } } } } @@ -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) { - // Don't overshoot our target. With variable factor this is possible. - add -= angle->spin; + // 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) + { + // 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); } } diff --git a/source/core/gameinput.h b/source/core/gameinput.h index 40a6b70f3..2fdc94b9a 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -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); diff --git a/source/games/blood/src/controls.cpp b/source/games/blood/src/controls.cpp index 4b7de23eb..9da34ba1e 100644 --- a/source/games/blood/src/controls.cpp +++ b/source/games/blood/src/controls.cpp @@ -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); } diff --git a/source/games/blood/src/player.cpp b/source/games/blood/src/player.cpp index 98fe8e48a..cda8a9355 100644 --- a/source/games/blood/src/player.cpp +++ b/source/games/blood/src/player.cpp @@ -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); } diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index d8cbaa751..c05c1fa83 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -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); diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index 16de421c8..3d5832434 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -3139,7 +3139,7 @@ HORIZONLY: if (SyncInput()) { - sethorizon(&p->horizon.horiz, PlayerHorizon(snum), &p->sync.actions); + sethorizon(&p->horizon, 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 9747b4e40..bd43f3bb4 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -4001,7 +4001,7 @@ HORIZONLY: if (SyncInput()) { - sethorizon(&p->horizon.horiz, PlayerHorizon(snum), &p->sync.actions); + sethorizon(&p->horizon, PlayerHorizon(snum), &p->sync.actions); } p->checkhardlanding(); diff --git a/source/games/exhumed/src/input.cpp b/source/games/exhumed/src/input.cpp index e2af84093..9f67a2773 100644 --- a/source/games/exhumed/src/input.cpp +++ b/source/games/exhumed/src/input.cpp @@ -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); diff --git a/source/games/exhumed/src/player.cpp b/source/games/exhumed/src/player.cpp index 1bef13e45..322fb6ecf 100644 --- a/source/games/exhumed/src/player.cpp +++ b/source/games/exhumed/src/player.cpp @@ -2656,7 +2656,7 @@ loc_1BD2E: 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 diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 78b614554..351df2422 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -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