- Split out view angle stuff out of PlayerAngles::applyYaw() into 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.
This commit is contained in:
Mitchell Richters 2022-12-09 17:52:52 +11:00 committed by Christoph Oelckers
parent 2b9e3f804d
commit f9aeee5b4a
17 changed files with 58 additions and 44 deletions

View file

@ -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())
{
@ -224,17 +224,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
@ -324,6 +314,27 @@ void PlayerAngles::doViewPitch(const DVector2& pos, DAngle const ang, bool const
}
//---------------------------------------------------------------------------
//
// Player's look left/right key angle handler.
//
//---------------------------------------------------------------------------
void PlayerAngles::doViewYaw(const ESyncBits actions)
{
// Process angle return to zeros.
scaletozero(ViewAngles.Yaw, YAW_LOOKRETURN);
scaletozero(ViewAngles.Roll, 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;
}
}
//---------------------------------------------------------------------------
//
//

View file

@ -28,6 +28,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 = {}; }
@ -82,13 +83,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.
@ -103,14 +104,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.

View file

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

View file

@ -446,7 +446,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);
@ -501,16 +501,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);

View file

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

View file

@ -837,7 +837,6 @@ void GameInterface::GetInput(ControlInfo* const hidInput, double const scaleAdju
// 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);
}

View file

@ -729,23 +729,23 @@ void playerJump(int snum, double floorz, double ceilingz)
//
//---------------------------------------------------------------------------
void player_struct::apply_seasick(double factor)
void player_struct::apply_seasick()
{
if (isRRRA() && SeaSick && (dead_flag == 0 || (dead_flag && resurrected)))
{
if (SeaSick < 250)
{
if (SeaSick >= 180)
Angles.ViewAngles.Roll -= DAngle::fromDeg(24 * factor * BAngToDegree);
Angles.ViewAngles.Roll -= DAngle::fromDeg(24 * BAngToDegree);
else if (SeaSick >= 130)
Angles.ViewAngles.Roll += DAngle::fromDeg(24 * factor * BAngToDegree);
Angles.ViewAngles.Roll += DAngle::fromDeg(24 * BAngToDegree);
else if (SeaSick >= 70)
Angles.ViewAngles.Roll -= DAngle::fromDeg(24 * factor * BAngToDegree);
Angles.ViewAngles.Roll -= DAngle::fromDeg(24 * BAngToDegree);
else if (SeaSick >= 20)
Angles.ViewAngles.Roll += DAngle::fromDeg(24 * factor * BAngToDegree);
Angles.ViewAngles.Roll += DAngle::fromDeg(24 * BAngToDegree);
}
if (SeaSick < 250)
Angles.ViewAngles.Yaw = DAngle::fromDeg(((krand() & 255) - 128) * factor * BAngToDegree);
Angles.ViewAngles.Yaw = DAngle::fromDeg(((krand() & 255) - 128) * BAngToDegree);
}
}

View file

@ -2889,6 +2889,7 @@ void processinput_d(int snum)
p->psectlotag = psectlotag;
//Do the quick lefts and rights
p->Angles.doViewYaw(actions);
if (movementBlocked(p))
{

View file

@ -3497,7 +3497,7 @@ void processinput_r(int snum)
doubvel = TICSPERFRAME;
checklook(snum, actions);
p->apply_seasick(1);
p->apply_seasick();
auto oldpos = p->GetActor()->opos;
@ -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))
{

View file

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

View file

@ -309,7 +309,7 @@ struct player_struct
DDukeActor* GetActor();
int GetPlayerNum();
void apply_seasick(double factor);
void apply_seasick();
void backuppos(bool noclipping = false);
void backupweapon();
void checkhardlanding();

View file

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

View file

@ -980,6 +980,8 @@ void AIPlayer::Tick(RunListEvent* ev)
}
}
PlayerList[nPlayer].Angles.doViewYaw(sPlayerInput[nLocalPlayer].actions);
// loc_1A494:
if (SyncInput())
{

View file

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

View file

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

View file

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

View file

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