Skip to content

Commit

Permalink
- Split out view angle stuff out of PlayerAngles::applyYaw() into `…
Browse files Browse the repository at this point in the history
…PlayerAngles::doViewYaw()`.

* Do all the view angle stuff as interpolated changes in the playsim as well, there's no need for these to be done at ticrate.
  • Loading branch information
mjr4077au committed Nov 26, 2022
1 parent e707af2 commit 038fdcc
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 35 deletions.
35 changes: 23 additions & 12 deletions source/core/gameinput.cpp
Expand Up @@ -80,7 +80,7 @@ inline static DAngle getscaledangle(const DAngle value, const double scaleAdjust
return ((object.Normalized180() * getTicrateScale(value)) + push) * getCorrectedScale(scaleAdjust);
}

inline static void scaletozero(DAngle& object, const DAngle value, const double scaleAdjust, const DAngle push = DAngle::fromDeg(32. / 465.))
inline static void scaletozero(DAngle& object, const DAngle value, const double scaleAdjust = 1, const DAngle push = DAngle::fromDeg(32. / 465.))
{
if (auto sgn = object.Sgn())
{
Expand Down Expand Up @@ -222,17 +222,7 @@ void PlayerAngles::applyPitch(float const horz, ESyncBits* actions, double const

void PlayerAngles::applyYaw(float const avel, ESyncBits* actions, double const scaleAdjust)
{
// Process angle return to zeros.
scaletozero(ViewAngles.Roll, YAW_LOOKRETURN, scaleAdjust);
scaletozero(ViewAngles.Yaw, YAW_LOOKRETURN, scaleAdjust);

// Process keyboard input.
if (auto looking = !!(*actions & SB_LOOK_RIGHT) - !!(*actions & SB_LOOK_LEFT))
{
ViewAngles.Yaw += getTicrateScale(YAW_LOOKINGSPEED) * getCorrectedScale(scaleAdjust) * looking;
ViewAngles.Roll -= getTicrateScale(YAW_ROTATESPEED) * getCorrectedScale(scaleAdjust) * looking;
}

// Process only if movement isn't locked.
if (!lockedYaw())
{
// add player's input
Expand Down Expand Up @@ -322,6 +312,27 @@ void PlayerAngles::doViewPitch(const DVector2& pos, DAngle const ang, bool const
}


//---------------------------------------------------------------------------
//
// Player's slope tilt when playing without a mouse and on a slope.
//
//---------------------------------------------------------------------------

void PlayerAngles::doViewYaw(const ESyncBits actions)
{
// Process angle return to zeros.
scaletozero(ViewAngles.Roll, YAW_LOOKRETURN);
scaletozero(ViewAngles.Yaw, YAW_LOOKRETURN);

// Process keyboard input.
if (auto looking = !!(actions & SB_LOOK_RIGHT) - !!(actions & SB_LOOK_LEFT))
{
ViewAngles.Yaw += getTicrateScale(YAW_LOOKINGSPEED) * looking;
ViewAngles.Roll -= getTicrateScale(YAW_ROTATESPEED) * looking;
}
}


//---------------------------------------------------------------------------
//
//
Expand Down
14 changes: 6 additions & 8 deletions source/core/gameinput.h
Expand Up @@ -31,6 +31,7 @@ struct PlayerAngles

// 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 doViewYaw(const ESyncBits actions);

// General methods.
void resetAdjustments() { Adjustments = {}; }
Expand Down Expand Up @@ -77,13 +78,13 @@ struct PlayerAngles
}

// Miscellaneous helpers.
double angLOOKANGHALF(double const interpfrac) { return angRENDERLOOKANG(interpfrac).Normalized180().Degrees() * (128. / 45.); }
double angLOOKINGARC(double const interpfrac) { return fabs(angRENDERLOOKANG(interpfrac).Normalized180().Degrees() * (1024. / 1620.)); }
double angLOOKANGHALF(double const interpfrac) { return angLERPLOOKANG(interpfrac).Normalized180().Degrees() * (128. / 45.); }
double angLOOKINGARC(double const interpfrac) { return fabs(angLERPLOOKANG(interpfrac).Normalized180().Degrees() * (1024. / 1620.)); }

// Crosshair x/y offsets based on look_ang's tangent.
DVector2 angCROSSHAIROFFSETS(const double interpfrac)
{
return DVector2(159.72, 145.5 * angRENDERROTSCRN(interpfrac).Sin()) * -angRENDERLOOKANG(interpfrac).Tan() * (1. / tan(r_fov * pi::pi() / 360.));
return DVector2(159.72, 145.5 * angLERPROTSCRN(interpfrac).Sin()) * -angLERPLOOKANG(interpfrac).Tan() * (1. / tan(r_fov * pi::pi() / 360.));
}

// Weapon x/y offsets based on the above.
Expand All @@ -98,14 +99,11 @@ struct PlayerAngles
DAngle horizOLDSUM() { return ZzOLDHORIZON() + PrevViewAngles.Pitch; }
DAngle horizSUM() { return ZzHORIZON() + ViewAngles.Pitch; }
DAngle horizLERPSUM(double const interpfrac) { return interpolatedvalue(horizOLDSUM(), horizSUM(), interpfrac); }
DAngle angOLDSUM() { return ZzOLDANGLE() + PrevViewAngles.Yaw; }
DAngle angSUM() { return ZzANGLE() + ViewAngles.Yaw; }
DAngle angLERPSUM(double const interpfrac) { return interpolatedvalue(angOLDSUM(), angSUM(), 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); }
DAngle angLERPLOOKANG(double const interpfrac) { return interpolatedvalue(PrevViewAngles.Yaw, ViewAngles.Yaw, interpfrac); }
DAngle angLERPROTSCRN(double const interpfrac) { return interpolatedvalue(PrevViewAngles.Roll, ViewAngles.Roll, interpfrac); }
DAngle angRENDERLOOKANG(double const interpfrac) { return !SyncInput() ? ViewAngles.Yaw : angLERPLOOKANG(interpfrac); }
DAngle angRENDERROTSCRN(double const interpfrac) { return !SyncInput() ? ViewAngles.Roll : angLERPROTSCRN(interpfrac); }

private:
// DRotator indices.
Expand Down
2 changes: 2 additions & 0 deletions source/games/blood/src/player.cpp
Expand Up @@ -1585,6 +1585,8 @@ void ProcessInput(PLAYER* pPlayer)
actor->vel.XY() += DVector2(pInput->fvel * fvAccel, pInput->svel * svAccel).Rotated(actor->spr.Angles.Yaw) * speed;
}

pPlayer->Angles.doViewYaw(pInput->actions);

if (SyncInput())
{
pPlayer->Angles.applyYaw(pInput->avel, &pInput->actions);
Expand Down
7 changes: 3 additions & 4 deletions source/games/blood/src/view.cpp
Expand Up @@ -445,7 +445,7 @@ static void DrawMap(PLAYER* pPlayer, const double interpfrac)
setViewport(Hud_Stbar);
tm = 1;
}
auto ang = !SyncInput() ? pPlayer->Angles.angSUM() : pPlayer->Angles.angLERPSUM(interpfrac);
auto ang = !SyncInput() ? pPlayer->Angles.angSUM(interpfrac) : pPlayer->Angles.angLERPSUM(interpfrac);
DrawOverheadMap(pPlayer->actor->interpolatedpos(interpfrac).XY(), ang, interpfrac);
if (tm)
setViewport(hud_size);
Expand Down Expand Up @@ -500,16 +500,15 @@ static void SetupView(PLAYER* pPlayer, DVector3& cPos, DAngle& cA, DAngle& cH, s

if (!SyncInput())
{
cA = pPlayer->Angles.angSUM();
cA = pPlayer->Angles.angSUM(interpfrac);
cH = pPlayer->Angles.horizSUM();
rotscrnang = pPlayer->Angles.ViewAngles.Roll;
}
else
{
cA = pPlayer->Angles.angLERPSUM(interpfrac);
cH = pPlayer->Angles.horizLERPSUM(interpfrac);
rotscrnang = pPlayer->Angles.angLERPROTSCRN(interpfrac);
}
rotscrnang = pPlayer->Angles.angLERPROTSCRN(interpfrac);
}

viewUpdateShake(pPlayer, cPos, cA, cH, shakeX, shakeY);
Expand Down
2 changes: 1 addition & 1 deletion source/games/duke/src/hudweapon_d.cpp
Expand Up @@ -232,7 +232,7 @@ void displayweapon_d(int snum, double interpfrac)
auto horiz = !SyncInput() ? p->Angles.horizSUM() : p->Angles.horizLERPSUM(interpfrac);
auto pitchoffset = -interpolatedvalue(0., 16., horiz / DAngle90);
auto yawinput = getavel(snum) * (1. / 16.);
auto angle = p->Angles.angRENDERROTSCRN(interpfrac);
auto angle = p->Angles.angLERPROTSCRN(interpfrac);
auto weapon_xoffset = 160 - 90 - (BobVal(512 + weapon_sway * 0.5) * (16384. / 1536.)) - 58 - p->weapon_ang;
auto shade = min(p->GetActor()->spr.shade, (int8_t)24);

Expand Down
1 change: 1 addition & 0 deletions source/games/duke/src/player_d.cpp
Expand Up @@ -2883,6 +2883,7 @@ void processinput_d(int snum)
p->psectlotag = psectlotag;

//Do the quick lefts and rights
p->Angles.doViewYaw(actions);

if (movementBlocked(p))
{
Expand Down
1 change: 1 addition & 0 deletions source/games/duke/src/player_r.cpp
Expand Up @@ -3544,6 +3544,7 @@ void processinput_r(int snum)
p->psectlotag = psectlotag;

//Do the quick lefts and rights
p->Angles.doViewYaw(actions);

if (movementBlocked(p))
{
Expand Down
4 changes: 2 additions & 2 deletions source/games/duke/src/render.cpp
Expand Up @@ -271,7 +271,7 @@ void displayrooms(int snum, double interpfrac, bool sceneonly)
setgamepalette(setpal(p));

// set screen rotation.
rotscrnang = !SyncInput() ? p->Angles.ViewAngles.Roll : p->Angles.angLERPROTSCRN(interpfrac);
rotscrnang = p->Angles.angLERPROTSCRN(interpfrac);

// use player's actor initially.
viewer = p->GetActor();
Expand Down Expand Up @@ -304,7 +304,7 @@ void displayrooms(int snum, double interpfrac, bool sceneonly)
else
{
// This is for real time updating of the view direction.
cang = p->Angles.angSUM();
cang = p->Angles.angSUM(interpfrac);
choriz = p->Angles.horizSUM();
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/games/exhumed/src/map.cpp
Expand Up @@ -55,7 +55,7 @@ void DrawMap(double const interpfrac)
if (!nFreeze && automapMode != am_off)
{
auto pPlayerActor = PlayerList[nLocalPlayer].pActor;
auto ang = !SyncInput() ? PlayerList[nLocalPlayer].Angles.angSUM() : PlayerList[nLocalPlayer].Angles.angLERPSUM(interpfrac);
auto ang = !SyncInput() ? PlayerList[nLocalPlayer].Angles.angSUM(interpfrac) : PlayerList[nLocalPlayer].Angles.angLERPSUM(interpfrac);
DrawOverheadMap(pPlayerActor->interpolatedpos(interpfrac).XY(), ang, interpfrac);
}
}
Expand Down
2 changes: 2 additions & 0 deletions source/games/exhumed/src/player.cpp
Expand Up @@ -980,6 +980,8 @@ void AIPlayer::Tick(RunListEvent* ev)
}
}

PlayerList[nPlayer].Angles.doViewYaw(sPlayerInput[nLocalPlayer].actions);

// loc_1A494:
if (SyncInput())
{
Expand Down
6 changes: 3 additions & 3 deletions source/games/exhumed/src/view.cpp
Expand Up @@ -235,15 +235,15 @@ void DrawView(double interpfrac, bool sceneonly)
if (!SyncInput())
{
nCamerapan = PlayerList[nLocalPlayer].Angles.horizSUM();
nCameraang = PlayerList[nLocalPlayer].Angles.angSUM();
rotscrnang = PlayerList[nLocalPlayer].Angles.ViewAngles.Roll;
nCameraang = PlayerList[nLocalPlayer].Angles.angSUM(interpfrac);
}
else
{
nCamerapan = PlayerList[nLocalPlayer].Angles.horizLERPSUM(interpfrac);
nCameraang = PlayerList[nLocalPlayer].Angles.angLERPSUM(interpfrac);
rotscrnang = PlayerList[nLocalPlayer].Angles.angLERPROTSCRN(interpfrac);

}
rotscrnang = PlayerList[nLocalPlayer].Angles.angLERPROTSCRN(interpfrac);

if (!bCamera)
{
Expand Down
5 changes: 2 additions & 3 deletions source/games/sw/src/draw.cpp
Expand Up @@ -1246,14 +1246,13 @@ void drawscreen(PLAYER* pp, double interpfrac, bool sceneonly)
{
tang = camerapp->Angles.angLERPSUM(interpfrac);
thoriz = camerapp->Angles.horizLERPSUM(interpfrac);
trotscrnang = camerapp->Angles.angLERPROTSCRN(interpfrac);
}
else
{
tang = pp->Angles.angSUM();
tang = pp->Angles.angSUM(interpfrac);
thoriz = pp->Angles.horizSUM();
trotscrnang = pp->Angles.ViewAngles.Roll;
}
trotscrnang = camerapp->Angles.angLERPROTSCRN(interpfrac);
tsect = camerapp->cursector;

updatesector(tpos, &tsect);
Expand Down
2 changes: 1 addition & 1 deletion source/games/sw/src/panel.cpp
Expand Up @@ -7429,7 +7429,7 @@ void pDisplaySprites(PLAYER* pp, double interpfrac)
int flags;

const auto offsets = pp->Angles.angWEAPONOFFSETS(interpfrac);
const auto angle = pp->Angles.angRENDERROTSCRN(interpfrac).Buildfang();
const auto angle = pp->Angles.angLERPROTSCRN(interpfrac).Buildfang();

auto list = pp->GetPanelSpriteList();
for (auto psp = list->Next; next = psp->Next, psp != list; psp = next)
Expand Down
2 changes: 2 additions & 0 deletions source/games/sw/src/player.cpp
Expand Up @@ -2069,6 +2069,8 @@ void DoPlayerMove(PLAYER* pp)

SlipSlope(pp);

pp->Angles.doViewYaw(pp->input.actions);

if (!SyncInput())
{
pp->Flags2 |= (PF2_INPUT_CAN_TURN_GENERAL);
Expand Down

0 comments on commit 038fdcc

Please sign in to comment.