- Tidy up interface for PlayerAngles::doViewPitch() since we have internal access to the player's actor.

This commit is contained in:
Mitchell Richters 2023-03-13 21:17:33 +11:00
parent 41d7118099
commit 18ef460a99
5 changed files with 15 additions and 28 deletions

View file

@ -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));
}

View file

@ -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.

View file

@ -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)

View file

@ -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);
}
//---------------------------------------------------------------------------

View file

@ -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);
}
//---------------------------------------------------------------------------