diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index c73f990a5..a3fc34094 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -240,30 +240,31 @@ void PlayerAngles::doYawKeys(ESyncBits* actions) // //--------------------------------------------------------------------------- -void PlayerAngles::doViewPitch(const DVector2& pos, DAngle const ang, bool const aimmode, bool const canslopetilt, sectortype* const cursectnum, bool const climbing) +void PlayerAngles::doViewPitch(const bool canslopetilt, const bool climbing) { - if (cl_slopetilting && cursectnum != nullptr) + if (cl_slopetilting) { - if (aimmode && canslopetilt) // If the floor is sloped + const auto actorsect = pActor->sector(); + if (actorsect && (actorsect->floorstat & CSTAT_SECTOR_SLOPE) && canslopetilt) // If the floor is sloped { // Get a point, 512 (64 for Blood) units ahead of player's position - auto rotpt = pos + ang.ToVector() * (!isBlood() ? 32 : 4); - auto tempsect = cursectnum; + const auto rotpt = pActor->spr.pos.XY() + pActor->spr.Angles.Yaw.ToVector() * (!isBlood() ? 32 : 4); + auto tempsect = actorsect; updatesector(rotpt, &tempsect); if (tempsect != nullptr) // If the new point is inside a valid sector... { // Get the floorz as if the new (x,y) point was still in // your sector, unless it's Blood. - double const j = getflorzofslopeptr(cursectnum, pos); - double const k = getflorzofslopeptr(!isBlood() ? cursectnum : tempsect, rotpt); + const double j = getflorzofslopeptr(actorsect, pActor->spr.pos.XY()); + const double k = getflorzofslopeptr(!isBlood() ? actorsect : tempsect, rotpt); // If extended point is in same sector as you or the slopes // of the sector of the extended point and your sector match // closely (to avoid accidently looking straight out when // you're at the edge of a sector line) then adjust horizon // accordingly - if (cursectnum == tempsect || (!isBlood() && abs(getflorzofslopeptr(tempsect, rotpt) - k) <= 4)) + if (actorsect == tempsect || (!isBlood() && abs(getflorzofslopeptr(tempsect, rotpt) - k) <= 4)) { ViewAngles.Pitch -= maphoriz((j - k) * (!isBlood() ? 0.625 : 5.5)); } diff --git a/source/core/gameinput.h b/source/core/gameinput.h index 9973dab7d..d7a4e2164 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -22,7 +22,7 @@ struct PlayerAngles // Prototypes. void doPitchKeys(ESyncBits* actions, const bool stopcentering); void doYawKeys(ESyncBits* actions); - void doViewPitch(const DVector2& pos, DAngle const ang, bool const aimmode, bool const canslopetilt, sectortype* const cursectnum, bool const climbing = false); + void doViewPitch(const bool canslopetilt, const bool climbing = false); void doViewYaw(const ESyncBits actions); // General methods. diff --git a/source/games/blood/src/player.cpp b/source/games/blood/src/player.cpp index 8081cec34..0394fa357 100644 --- a/source/games/blood/src/player.cpp +++ b/source/games/blood/src/player.cpp @@ -1493,20 +1493,6 @@ int ActionScan(PLAYER* pPlayer, HitInfo* out) return -1; } -//--------------------------------------------------------------------------- -// -// Player's slope tilting wrapper function function, called in ProcessInput() or from gi->GetInput() as required. -// -//--------------------------------------------------------------------------- - -void doslopetilting(PLAYER* pPlayer) -{ - auto plActor = pPlayer->actor; - int const florhit = pPlayer->actor->hit.florhit.type; - bool const va = plActor->xspr.height < 16 && (florhit == kHitSector || florhit == 0) ? 1 : 0; - pPlayer->Angles.doViewPitch(plActor->spr.pos.XY(), plActor->spr.Angles.Yaw, va, plActor->sector()->floorstat & CSTAT_SECTOR_SLOPE, plActor->sector()); -} - //--------------------------------------------------------------------------- // // @@ -1717,8 +1703,9 @@ void ProcessInput(PLAYER* pPlayer) pPlayer->actor->spr.Angles.Pitch += DAngle::fromDeg(pInput->horz); } + const int florhit = pPlayer->actor->hit.florhit.type; + pPlayer->Angles.doViewPitch(actor->xspr.height < 16 && (florhit == kHitSector || florhit == 0)); pPlayer->Angles.doPitchKeys(&pInput->actions, pInput->horz); - doslopetilting(pPlayer); pPlayer->slope = pPlayer->actor->spr.Angles.Pitch.Tan(); if (pInput->actions & SB_INVPREV) diff --git a/source/games/duke/src/inlines.h b/source/games/duke/src/inlines.h index e7eacdfe9..5648de43d 100644 --- a/source/games/duke/src/inlines.h +++ b/source/games/duke/src/inlines.h @@ -234,8 +234,7 @@ inline bool playrunning() inline void doslopetilting(player_struct* p) { - bool const canslopetilt = p->on_ground && p->insector() && p->cursector->lotag != ST_2_UNDERWATER && (p->cursector->floorstat & CSTAT_SECTOR_SLOPE); - p->Angles.doViewPitch(p->GetActor()->spr.pos.XY(), p->GetActor()->spr.Angles.Yaw, p->aim_mode == 0, canslopetilt, p->cursector); + p->Angles.doViewPitch(p->aim_mode == 0 && p->on_ground && p->cursector->lotag != ST_2_UNDERWATER); } //--------------------------------------------------------------------------- diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 40b3176d9..7abc652c7 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -1663,8 +1663,8 @@ void SlipSlope(PLAYER* pp) void DoPlayerSlopeTilting(PLAYER* pp) { - bool const canslopetilt = !(pp->Flags & (PF_FLYING|PF_SWIMMING|PF_DIVING|PF_CLIMBING|PF_JUMPING|PF_FALLING)) && pp->cursector && (pp->cursector->floorstat & CSTAT_SECTOR_SLOPE); - pp->Angles.doViewPitch(pp->actor->spr.pos.XY(), pp->actor->spr.Angles.Yaw, pp->input.actions & SB_AIMMODE, canslopetilt, pp->cursector, (pp->Flags & PF_CLIMBING)); + const bool canslopetilt = (pp->input.actions & SB_AIMMODE) && !(pp->Flags & (PF_FLYING|PF_SWIMMING|PF_DIVING|PF_CLIMBING|PF_JUMPING|PF_FALLING)); + pp->Angles.doViewPitch(canslopetilt, pp->Flags & PF_CLIMBING); } //---------------------------------------------------------------------------