Skip to content

Commit

Permalink
- Rework PlayerAngles::doViewPitch() to apply at ticrate like `Play…
Browse files Browse the repository at this point in the history
…erAngles::doViewYaw()`.
  • Loading branch information
mjr4077au committed Nov 26, 2022
1 parent 0e39ef3 commit de0b696
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 32 deletions.
8 changes: 4 additions & 4 deletions source/core/gameinput.cpp
Expand Up @@ -265,7 +265,7 @@ void PlayerAngles::applyYaw(float const avel, ESyncBits* actions, double const s
//
//---------------------------------------------------------------------------

void PlayerAngles::doViewPitch(const DVector2& pos, DAngle const ang, bool const aimmode, bool const canslopetilt, sectortype* const cursectnum, double const scaleAdjust, bool const climbing)
void PlayerAngles::doViewPitch(const DVector2& pos, DAngle const ang, bool const aimmode, bool const canslopetilt, sectortype* const cursectnum, bool const climbing)
{
if (cl_slopetilting && cursectnum != nullptr)
{
Expand All @@ -290,20 +290,20 @@ void PlayerAngles::doViewPitch(const DVector2& pos, DAngle const ang, bool const
// accordingly
if (cursectnum == tempsect || (!isBlood() && abs(getflorzofslopeptr(tempsect, rotpt) - k) <= 4))
{
ViewAngles.Pitch -= maphoriz(scaleAdjust * ((j - k) * (!isBlood() ? 0.625 : 5.5)));
ViewAngles.Pitch -= maphoriz((j - k) * (!isBlood() ? 0.625 : 5.5));
}
}
}

if (climbing)
{
// tilt when climbing but you can't even really tell it.
if (ViewAngles.Pitch > PITCH_HORIZOFFCLIMB) ViewAngles.Pitch -= getscaledangle(PITCH_HORIZOFFSPEED, deltaangle(ViewAngles.Pitch, PITCH_HORIZOFFCLIMB), PITCH_HORIZOFFPUSH, scaleAdjust);
if (ViewAngles.Pitch > PITCH_HORIZOFFCLIMB) ViewAngles.Pitch -= getscaledangle(PITCH_HORIZOFFSPEED, deltaangle(ViewAngles.Pitch, PITCH_HORIZOFFCLIMB), PITCH_HORIZOFFPUSH);
}
else
{
// Make horizoff grow towards 0 since horizoff is not modified when you're not on a slope.
scaletozero(ViewAngles.Pitch, PITCH_HORIZOFFSPEED, scaleAdjust, PITCH_HORIZOFFPUSH);
scaletozero(ViewAngles.Pitch, PITCH_HORIZOFFSPEED, 1, PITCH_HORIZOFFPUSH);
}

// Clamp off against the maximum allowed pitch.
Expand Down
7 changes: 3 additions & 4 deletions source/core/gameinput.h
Expand Up @@ -30,7 +30,7 @@ struct PlayerAngles
void applyYaw(float const avel, ESyncBits* actions, double const scaleAdjust = 1);

// Prototypes for applying view.
void doViewPitch(const DVector2& pos, DAngle const ang, bool const aimmode, bool const canslopetilt, sectortype* const cursectnum, double const scaleAdjust = 1, bool const climbing = false);
void doViewPitch(const DVector2& pos, DAngle const ang, bool const aimmode, bool const canslopetilt, sectortype* const cursectnum, bool const climbing = false);
void doViewYaw(const ESyncBits actions);

// General methods.
Expand Down Expand Up @@ -96,9 +96,8 @@ struct PlayerAngles


// Legacy, to be removed.
DAngle horizOLDSUM() { return ZzOLDHORIZON() + PrevViewAngles.Pitch; }
DAngle horizSUM() { return ZzHORIZON() + ViewAngles.Pitch; }
DAngle horizLERPSUM(double const interpfrac) { return interpolatedvalue(horizOLDSUM(), horizSUM(), interpfrac); }
DAngle horizSUM(const double interpfrac = 1) { return ZzHORIZON() + interpolatedvalue(PrevViewAngles.Pitch, ViewAngles.Pitch, interpfrac); }
DAngle horizLERPSUM(double const interpfrac) { return interpolatedvalue(ZzOLDHORIZON() + PrevViewAngles.Pitch, ZzHORIZON() + ViewAngles.Pitch, interpfrac); }
DAngle angSUM(const double interpfrac) { return ZzANGLE() + angLERPLOOKANG(interpfrac); }
DAngle angLERPSUM(double const interpfrac) { return interpolatedvalue(ZzOLDANGLE() + PrevViewAngles.Yaw, ZzANGLE() + ViewAngles.Yaw, interpfrac); }
DAngle angLERPANG(double const interpfrac) { return interpolatedvalue(ZzOLDANGLE(), ZzANGLE(), interpfrac); }
Expand Down
3 changes: 0 additions & 3 deletions source/games/blood/src/controls.cpp
Expand Up @@ -34,8 +34,6 @@ BEGIN_BLD_NS

static InputPacket gInput;

void doslopetilting(PLAYER* pPlayer, double const scaleAdjust);

//---------------------------------------------------------------------------
//
//
Expand Down Expand Up @@ -63,7 +61,6 @@ void GameInterface::GetInput(ControlInfo* const hidInput, double const scaleAdju
{
pPlayer->Angles.applyYaw(input.avel, &pPlayer->input.actions, scaleAdjust);
pPlayer->Angles.applyPitch(input.horz, &pPlayer->input.actions, scaleAdjust);
doslopetilting(pPlayer, scaleAdjust);
}

pPlayer->Angles.applyScaledAdjustments(scaleAdjust);
Expand Down
7 changes: 4 additions & 3 deletions source/games/blood/src/player.cpp
Expand Up @@ -1498,12 +1498,12 @@ int ActionScan(PLAYER* pPlayer, HitInfo* out)
//
//---------------------------------------------------------------------------

void doslopetilting(PLAYER* pPlayer, double const scaleAdjust = 1)
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(), scaleAdjust);
pPlayer->Angles.doViewPitch(plActor->spr.pos.XY(), plActor->spr.Angles.Yaw, va, plActor->sector()->floorstat & CSTAT_SECTOR_SLOPE, plActor->sector());
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -1715,9 +1715,10 @@ void ProcessInput(PLAYER* pPlayer)
if (SyncInput())
{
pPlayer->Angles.applyPitch(pInput->horz, &pInput->actions);
doslopetilting(pPlayer);
}

doslopetilting(pPlayer);

pPlayer->Angles.unlockYaw();
pPlayer->Angles.unlockPitch();

Expand Down
2 changes: 1 addition & 1 deletion source/games/blood/src/view.cpp
Expand Up @@ -501,7 +501,7 @@ static void SetupView(PLAYER* pPlayer, DVector3& cPos, DAngle& cA, DAngle& cH, s
if (!SyncInput())
{
cA = pPlayer->Angles.angSUM(interpfrac);
cH = pPlayer->Angles.horizSUM();
cH = pPlayer->Angles.horizSUM(interpfrac);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion source/games/duke/src/hudweapon_d.cpp
Expand Up @@ -229,7 +229,7 @@ void displayweapon_d(int snum, double interpfrac)
gun_pos -= fabs(p->GetActor()->spr.scale.X < 0.5 ? BobVal(weapon_sway * 4.) * 32 : BobVal(weapon_sway * 0.5) * 16) + hard_landing;

auto offsets = p->Angles.angWEAPONOFFSETS(interpfrac);
auto horiz = !SyncInput() ? p->Angles.horizSUM() : p->Angles.horizLERPSUM(interpfrac);
auto horiz = !SyncInput() ? p->Angles.horizSUM(interpfrac) : p->Angles.horizLERPSUM(interpfrac);
auto pitchoffset = -interpolatedvalue(0., 16., horiz / DAngle90);
auto yawinput = getavel(snum) * (1. / 16.);
auto angle = p->Angles.angLERPROTSCRN(interpfrac);
Expand Down
4 changes: 2 additions & 2 deletions source/games/duke/src/inlines.h
Expand Up @@ -208,10 +208,10 @@ inline bool playrunning()
return (paused == 0 || (paused == 1 && (ud.recstat == 2 || ud.multimode > 1)));
}

inline void doslopetilting(player_struct* p, double const scaleAdjust = 1)
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->Angles.ZzANGLE(), p->aim_mode == 0, canslopetilt, p->cursector, scaleAdjust);
p->Angles.doViewPitch(p->GetActor()->spr.pos.XY(), p->Angles.ZzANGLE(), p->aim_mode == 0, canslopetilt, p->cursector);
}

//---------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion source/games/duke/src/input.cpp
Expand Up @@ -835,7 +835,6 @@ void GameInterface::GetInput(ControlInfo* const hidInput, double const scaleAdju
if (p->GetActor()->spr.extra > 0)
{
// Do these in the same order as the old code.
doslopetilting(p, scaleAdjust);
p->Angles.applyYaw(p->adjustavel(input.avel), &p->sync.actions, scaleAdjust);
p->apply_seasick(scaleAdjust);
p->Angles.applyPitch(input.horz, &p->sync.actions, scaleAdjust);
Expand Down
5 changes: 1 addition & 4 deletions source/games/duke/src/player_d.cpp
Expand Up @@ -2755,10 +2755,7 @@ void processinput_d(int snum)
pact->floorz = floorz;
pact->ceilingz = ceilingz;

if (SyncInput())
{
doslopetilting(p);
}
doslopetilting(p);

if (chz.type == kHitSprite)
{
Expand Down
5 changes: 1 addition & 4 deletions source/games/duke/src/player_r.cpp
Expand Up @@ -3347,10 +3347,7 @@ void processinput_r(int snum)
pact->floorz = floorz;
pact->ceilingz = ceilingz;

if (SyncInput())
{
doslopetilting(p);
}
doslopetilting(p);

if (chz.type == kHitSprite)
{
Expand Down
2 changes: 1 addition & 1 deletion source/games/duke/src/render.cpp
Expand Up @@ -305,7 +305,7 @@ void displayrooms(int snum, double interpfrac, bool sceneonly)
{
// This is for real time updating of the view direction.
cang = p->Angles.angSUM(interpfrac);
choriz = p->Angles.horizSUM();
choriz = p->Angles.horizSUM(interpfrac);
}
}

Expand Down
2 changes: 1 addition & 1 deletion source/games/exhumed/src/view.cpp
Expand Up @@ -234,7 +234,7 @@ void DrawView(double interpfrac, bool sceneonly)

if (!SyncInput())
{
nCamerapan = PlayerList[nLocalPlayer].Angles.horizSUM();
nCamerapan = PlayerList[nLocalPlayer].Angles.horizSUM(interpfrac);
nCameraang = PlayerList[nLocalPlayer].Angles.angSUM(interpfrac);
}
else
Expand Down
2 changes: 1 addition & 1 deletion source/games/sw/src/draw.cpp
Expand Up @@ -1250,7 +1250,7 @@ void drawscreen(PLAYER* pp, double interpfrac, bool sceneonly)
else
{
tang = pp->Angles.angSUM(interpfrac);
thoriz = pp->Angles.horizSUM();
thoriz = pp->Angles.horizSUM(interpfrac);
}
trotscrnang = camerapp->Angles.angLERPROTSCRN(interpfrac);
tsect = camerapp->cursector;
Expand Down
22 changes: 20 additions & 2 deletions source/games/sw/src/player.cpp
Expand Up @@ -1667,10 +1667,20 @@ void SlipSlope(PLAYER* pp)
//
//---------------------------------------------------------------------------

void DoPlayerHorizon(PLAYER* pp, float const horz, double const scaleAdjust)
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->Angles.ZzANGLE(), pp->input.actions & SB_AIMMODE, canslopetilt, pp->cursector, scaleAdjust, (pp->Flags & PF_CLIMBING));
pp->Angles.doViewPitch(pp->actor->spr.pos.XY(), pp->Angles.ZzANGLE(), pp->input.actions & SB_AIMMODE, canslopetilt, pp->cursector, (pp->Flags & PF_CLIMBING));
}

//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------

void DoPlayerHorizon(PLAYER* pp, float const horz, double const scaleAdjust)
{
pp->Angles.applyPitch(horz, &pp->input.actions, scaleAdjust);
}

Expand Down Expand Up @@ -2202,6 +2212,8 @@ void DoPlayerMove(PLAYER* pp)
DoPlayerHorizon(pp, pp->input.horz, 1);
}

DoPlayerSlopeTilting(pp);

if (pp->insector() && (pp->cursector->extra & SECTFX_DYNAMIC_AREA))
{
if (pp->Flags & (PF_FLYING|PF_JUMPING|PF_FALLING))
Expand Down Expand Up @@ -2776,6 +2788,8 @@ void DoPlayerMoveVehicle(PLAYER* pp)
DoPlayerHorizon(pp, pp->input.horz, 1);
}

DoPlayerSlopeTilting(pp);

DoTankTreads(pp);
}

Expand Down Expand Up @@ -2817,6 +2831,8 @@ void DoPlayerMoveTurret(PLAYER* pp)
{
DoPlayerHorizon(pp, pp->input.horz, 1);
}

DoPlayerSlopeTilting(pp);
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -3380,6 +3396,8 @@ void DoPlayerClimb(PLAYER* pp)
DoPlayerHorizon(pp, pp->input.horz, 1);
}

DoPlayerSlopeTilting(pp);

if (FAF_ConnectArea(pp->cursector))
{
updatesectorz(pp->actor->getPosWithOffsetZ(), &pp->cursector);
Expand Down

0 comments on commit de0b696

Please sign in to comment.