- Remove interpolators for TVector and TAngle objects, replacing with single generic version.

This commit is contained in:
Mitchell Richters 2022-09-07 14:10:01 +10:00 committed by Christoph Oelckers
parent 06e772b44b
commit 74167e1a7c
14 changed files with 36 additions and 54 deletions

View file

@ -1485,28 +1485,10 @@ inline TVector2<T> clamp(const TVector2<T> &vec, const TVector2<T> &min, const T
return TVector2<T>(clamp(vec.X, min.X, max.X), clamp(vec.Y, min.Y, max.Y));
}
template<class T>
inline TVector2<T> interpolatedvec2(const TVector2<T> &ovec, const TVector2<T> &vec, const double scale)
template <class T>
inline T interpolatedvalue(const T& oval, const T& val, const double interpfrac)
{
return ovec + ((vec - ovec) * scale);
}
template<class T>
inline TVector3<T> interpolatedvec3(const TVector3<T> &ovec, const TVector3<T> &vec, const double scale)
{
return ovec + ((vec - ovec) * scale);
}
template<class T>
inline TVector4<T> interpolatedvec4(const TVector4<T> &ovec, const TVector4<T> &vec, const double scale)
{
return ovec + ((vec - ovec) * scale);
}
template<class T>
inline TAngle<T> interpolatedangle(const TAngle<T> &oang, const TAngle<T> &ang, const double scale)
{
return oang + (deltaangle(oang, ang) * scale);
return T(oval + (val - oval) * interpfrac);
}
// Much of this is copied from TVector3. Is all that functionality really appropriate?

View file

@ -224,9 +224,9 @@ public:
return __interpvaluef(opos.Z, spr.pos.Z, smoothratio, scale);
}
DVector3 interpolatedvec3(double const smoothratio)
DVector3 interpolatedvec3(double const interpfrac)
{
return ::interpolatedvec3(opos, spr.pos, smoothratio);
return ::interpolatedvalue(opos, spr.pos, interpfrac);
}
@ -245,9 +245,9 @@ public:
return interpolatedz(smoothratio, scale) * zworldtoint;
}
DAngle interpolatedangle(double const smoothratio)
DAngle interpolatedangle(double const interpfrac)
{
return ::interpolatedangle(oang, spr.angle, smoothratio);
return ::interpolatedvalue(oang, spr.angle, interpfrac);
}
void backupz()

View file

@ -140,10 +140,10 @@ struct PlayerAngle
// Commonly used getters.
DAngle osum() { return oang + olook_ang; }
DAngle sum() { return ang + look_ang; }
DAngle interpolatedsum(double const smoothratio) { return interpolatedangle(osum(), sum(), smoothratio); }
DAngle interpolatedang(double const smoothratio) { return interpolatedangle(oang, ang, smoothratio); }
DAngle interpolatedlookang(double const smoothratio) { return interpolatedangle(olook_ang, look_ang, smoothratio); }
DAngle interpolatedrotscrn(double const smoothratio) { return interpolatedangle(orotscrnang, rotscrnang, smoothratio); }
DAngle interpolatedsum(double const smoothratio) { return interpolatedvalue(osum(), sum(), smoothratio); }
DAngle interpolatedang(double const smoothratio) { return interpolatedvalue(oang, ang, smoothratio); }
DAngle interpolatedlookang(double const smoothratio) { return interpolatedvalue(olook_ang, look_ang, smoothratio); }
DAngle interpolatedrotscrn(double const smoothratio) { return interpolatedvalue(orotscrnang, rotscrnang, smoothratio); }
DAngle renderlookang(double const smoothratio) { return !SyncInput() ? look_ang : interpolatedlookang(smoothratio); }
// Ticrate playsim adjustment helpers.

View file

@ -198,7 +198,7 @@ void QAV::Draw(double x, double y, int ticks, int stat, int shade, int palnum, b
tileX += __interpvaluef(prevTile->x, thisTile->x, smoothratio);
tileY += __interpvaluef(prevTile->y, thisTile->y, smoothratio);
tileZ = __interpvaluef(prevTile->z, thisTile->z, smoothratio);
tileA = interpolatedangle(DAngle::fromBuild(prevTile->angle), DAngle::fromBuild(thisTile->angle), smoothratio * (1. / MaxSmoothRatio)).Buildfang();
tileA = interpolatedvalue(DAngle::fromBuild(prevTile->angle), DAngle::fromBuild(thisTile->angle), smoothratio * (1. / MaxSmoothRatio)).Buildfang();
tileShade = __interpvalue(prevTile->shade, thisTile->shade, smoothratio) + shade;
auto prevAlpha = ((stat | prevTile->stat) & RS_TRANS1) ? glblend[0].def[!!((stat | prevTile->stat) & RS_TRANS2)].alpha : 1.;
auto thisAlpha = (tileStat & RS_TRANS1) ? glblend[0].def[!!(tileStat & RS_TRANS2)].alpha : 1.;

View file

@ -511,9 +511,9 @@ void SetupView(int& cX, int& cY, int& cZ, DAngle& cA, fixedhoriz& cH, sectortype
}
else
{
cA = interpolatedangle(predictOld.angle + predictOld.look_ang, predict.angle + predict.look_ang, gInterpolate * (1. / MaxSmoothRatio));
cA = interpolatedvalue(predictOld.angle + predictOld.look_ang, predict.angle + predict.look_ang, gInterpolate * (1. / MaxSmoothRatio));
cH = interpolatedhorizon(predictOld.horiz + predictOld.horizoff, predict.horiz + predict.horizoff, gInterpolate);
rotscrnang = interpolatedangle(predictOld.rotscrnang, predict.rotscrnang, gInterpolate * (1. / MaxSmoothRatio));
rotscrnang = interpolatedvalue(predictOld.rotscrnang, predict.rotscrnang, gInterpolate * (1. / MaxSmoothRatio));
}
}
else
@ -686,7 +686,7 @@ void viewDrawScreen(bool sceneonly)
double shakeX, shakeY;
SetupView(cX, cY, cZ, cA, cH, pSector, zDelta, shakeX, shakeY, rotscrnang);
DAngle tilt = interpolatedangle(gScreenTiltO, gScreenTilt, gInterpolate * (1. / MaxSmoothRatio));
DAngle tilt = interpolatedvalue(gScreenTiltO, gScreenTilt, gInterpolate * (1. / MaxSmoothRatio));
bool bDelirium = powerupCheck(gView, kPwUpDeliriumShroom) > 0;
static bool bDeliriumOld = false;
//int tiltcs, tiltdim;
@ -735,7 +735,7 @@ void viewDrawScreen(bool sceneonly)
}
}
g_relvisibility = (int32_t)(ClipLow(gVisibility - 32 * gView->visibility - brightness, 0)) - g_visibility;
cA += interpolatedangle(deliriumTurnO, deliriumTurn, gInterpolate * (1. / MaxSmoothRatio));
cA += interpolatedvalue(deliriumTurnO, deliriumTurn, gInterpolate * (1. / MaxSmoothRatio));
if (pSector != nullptr)
{
@ -765,7 +765,7 @@ void viewDrawScreen(bool sceneonly)
}
}
if (!sceneonly) hudDraw(gView, pSector, shakeX, shakeY, zDelta, basepal, gInterpolate);
if (!sceneonly) hudDraw(gView, pSector, shakeX, shakeY, zDelta, basepal, gInterpolate * (1. / MaxSmoothRatio));
fixedhoriz deliriumPitchI = interpolatedhorizon(q16horiz(deliriumPitchO), q16horiz(deliriumPitch), gInterpolate);
auto bakCstat = gView->actor->spr.cstat;
gView->actor->spr.cstat |= (gViewPos == 0) ? CSTAT_SPRITE_INVISIBLE : CSTAT_SPRITE_TRANSLUCENT | CSTAT_SPRITE_TRANS_FLIP;
@ -778,7 +778,7 @@ void viewDrawScreen(bool sceneonly)
Collision c1, c2;
GetZRange(gView->actor, &vf4, &c1, &vec, &c2, nClipDist, 0);
if (sceneonly) return;
double look_anghalf = gView->angle.look_anghalf(gInterpolate);
double look_anghalf = gView->angle.look_anghalf(gInterpolate * (1. / MaxSmoothRatio));
DrawCrosshair(kCrosshairTile, gView->actor->xspr.health >> 4, -look_anghalf, 0, 2);
#if 0 // This currently does not work. May have to be redone as a hardware effect.
if (v4 && gNetPlayers > 1)

View file

@ -310,7 +310,7 @@ void animatesprites_d(tspriteArray& tsprites, int x, int y, int a, int smoothrat
t->x = __interpvalue(omyx, myx, smoothratio);
t->y = __interpvalue(omyy, myy, smoothratio);
t->z = __interpvalue(omyz, myz, smoothratio) + gs_playerheight;
t->ang = interpolatedangle(omyang, myang, smoothratio * (1. / MaxSmoothRatio)).asbuild();
t->ang = interpolatedvalue(omyang, myang, smoothratio * (1. / MaxSmoothRatio)).asbuild();
t->sector = mycursectnum;
}
#endif

View file

@ -352,7 +352,7 @@ void animatesprites_r(tspriteArray& tsprites, int x, int y, int a, int smoothrat
t->x = __interpvalue(omyx, myx, smoothratio);
t->y = __interpvalue(omyy, myy, smoothratio);
t->z = __interpvalue(omyz, myz, smoothratio) + gs.playerheight;
t->ang = interpolatedangle(omyang, myang, smoothratio * (1. / MaxSmoothRatio)).asbuild();
t->ang = interpolatedvalue(omyang, myang, smoothratio * (1. / MaxSmoothRatio)).asbuild();
t->sector = mycursectnum;
}
#endif

View file

@ -267,12 +267,12 @@ void drawoverlays(double smoothratio)
if (screenpeek == myconnectindex && numplayers > 1)
{
cposxy = DVector2(__interpvalue(omyx, myx, smoothratio), __interpvalue(omyy, myy, smoothratio)) * inttoworld;
cang = !SyncInput() ? myang : interpolatedangle(omyang, myang, smoothratio * (1. / MaxSmoothRatio));
cang = !SyncInput() ? myang : interpolatedvalue(omyang, myang, smoothratio * (1. / MaxSmoothRatio));
}
else
{
cposxy = interpolatedvec3(pp->opos, pp->pos, smoothratio * (1. / MaxSmoothRatio)).XY();
cang = !SyncInput() ? pp->angle.ang : interpolatedangle(pp->angle.oang, pp->angle.ang, smoothratio * (1. / MaxSmoothRatio));
cposxy = interpolatedvalue(pp->opos, pp->pos, smoothratio * (1. / MaxSmoothRatio)).XY();
cang = !SyncInput() ? pp->angle.ang : interpolatedvalue(pp->angle.oang, pp->angle.ang, smoothratio * (1. / MaxSmoothRatio));
}
}
else
@ -289,7 +289,7 @@ void drawoverlays(double smoothratio)
if (ps[myconnectindex].newOwner == nullptr && ud.cameraactor == nullptr)
{
DrawCrosshair(TILE_CROSSHAIR, ps[screenpeek].last_extra, -pp->angle.look_anghalf(smoothratio), pp->over_shoulder_on ? 2.5 : 0, isRR() ? 0.5 : 1);
DrawCrosshair(TILE_CROSSHAIR, ps[screenpeek].last_extra, -pp->angle.look_anghalf(smoothratio * (1. / MaxSmoothRatio)), pp->over_shoulder_on ? 2.5 : 0, isRR() ? 0.5 : 1);
}
if (paused == 2)

View file

@ -232,8 +232,8 @@ void displayweapon_d(int snum, double smoothratio)
plravel = getavel(snum) * (1. / 16.);
horiz16th = p->horizon.horizsumfrac(smoothratio);
look_anghalf = p->angle.look_anghalf(smoothratio);
looking_arc = p->angle.looking_arc(smoothratio);
look_anghalf = p->angle.look_anghalf(smoothratio * (1. / MaxSmoothRatio));
looking_arc = p->angle.looking_arc(smoothratio * (1. / MaxSmoothRatio));
hard_landing *= 8.;
gun_pos -= fabs(p->GetActor()->spr.xrepeat < 32 ? bsinf(weapon_sway * 4., -9) : bsinf(weapon_sway * 0.5, -10));

View file

@ -133,8 +133,8 @@ void displayweapon_r(int snum, double smoothratio)
TiltStatus = p->TiltStatus;
}
look_anghalf = p->angle.look_anghalf(smoothratio);
looking_arc = p->angle.looking_arc(smoothratio);
look_anghalf = p->angle.look_anghalf(smoothratio * (1. / MaxSmoothRatio));
looking_arc = p->angle.looking_arc(smoothratio * (1. / MaxSmoothRatio));
hard_landing *= 8.;
gun_pos -= fabs(p->GetActor()->spr.xrepeat < 8 ? bsinf(weapon_sway * 4., -9) : bsinf(weapon_sway * 0.5, -10));

View file

@ -258,7 +258,7 @@ void displayrooms(int snum, double smoothratio, bool sceneonly)
if (act->spr.yint < 0) act->spr.yint = -100;
else if (act->spr.yint > 199) act->spr.yint = 300;
cang = interpolatedangle(DAngle::fromBuild(ud.cameraactor->tempang), act->spr.angle, smoothratio * (1. / MaxSmoothRatio));
cang = interpolatedvalue(DAngle::fromBuild(ud.cameraactor->tempang), act->spr.angle, smoothratio * (1. / MaxSmoothRatio));
auto bh = buildhoriz(act->spr.yint);
auto cstat = act->spr.cstat;
@ -292,7 +292,7 @@ void displayrooms(int snum, double smoothratio, bool sceneonly)
if (SyncInput())
{
choriz = interpolatedhorizon(omyhoriz + omyhorizoff, myhoriz + myhorizoff, smoothratio);
cang = interpolatedangle(omyang, myang, smoothratio * (1. / MaxSmoothRatio));
cang = interpolatedvalue(omyang, myang, smoothratio * (1. / MaxSmoothRatio));
}
else
{

View file

@ -910,7 +910,7 @@ void DrawWeapons(double smooth)
if (cl_hudinterpolation)
{
nBobAngle = interpolatedangle(DAngle::fromBuild(obobangle), DAngle::fromBuild(bobangle), smooth * (1. / MaxSmoothRatio)).Buildfang();
nBobAngle = interpolatedvalue(DAngle::fromBuild(obobangle), DAngle::fromBuild(bobangle), smooth * (1. / MaxSmoothRatio)).Buildfang();
nVal = __interpvaluef(PlayerList[nLocalPlayer].ototalvel, PlayerList[nLocalPlayer].totalvel, smooth, 16) * 0.5;
}
else
@ -943,8 +943,8 @@ void DrawWeapons(double smooth)
nShade = PlayerList[nLocalPlayer].pActor->spr.shade;
}
double const look_anghalf = PlayerList[nLocalPlayer].angle.look_anghalf(smooth);
double const looking_arc = PlayerList[nLocalPlayer].angle.looking_arc(smooth);
double const look_anghalf = PlayerList[nLocalPlayer].angle.look_anghalf(smooth * (1. / MaxSmoothRatio));
double const looking_arc = PlayerList[nLocalPlayer].angle.looking_arc(smooth * (1. / MaxSmoothRatio));
xOffset -= look_anghalf;
yOffset += looking_arc;

View file

@ -1068,7 +1068,7 @@ void DrawCrosshair(PLAYER* pp)
{
if (!(CameraTestMode))
{
::DrawCrosshair(2326, pp->actor->user.Health, -pp->angle.look_anghalf(smoothratio), (pp->Flags & PF_VIEW_FROM_OUTSIDE) ? 5 : 0, 2, shadeToLight(10));
::DrawCrosshair(2326, pp->actor->user.Health, -pp->angle.look_anghalf(smoothratio * (1. / MaxSmoothRatio)), (pp->Flags & PF_VIEW_FROM_OUTSIDE) ? 5 : 0, 2, shadeToLight(10));
}
}

View file

@ -6376,8 +6376,8 @@ void pDisplaySprites(PLAYER* pp, double smoothratio)
short ang;
int flags;
double const look_anghalf = pp->angle.look_anghalf(smoothratio);
double const looking_arc = pp->angle.looking_arc(smoothratio);
double const look_anghalf = pp->angle.look_anghalf(smoothratio * (1. / MaxSmoothRatio));
double const looking_arc = pp->angle.looking_arc(smoothratio * (1. / MaxSmoothRatio));
auto list = pp->GetPanelSpriteList();
for (auto psp = list->Next; next = psp->Next, psp != list; psp = next)