diff --git a/source/common/utility/vectors.h b/source/common/utility/vectors.h index df032037f..766a8f1fb 100644 --- a/source/common/utility/vectors.h +++ b/source/common/utility/vectors.h @@ -1485,28 +1485,10 @@ inline TVector2 clamp(const TVector2 &vec, const TVector2 &min, const T return TVector2(clamp(vec.X, min.X, max.X), clamp(vec.Y, min.Y, max.Y)); } -template -inline TVector2 interpolatedvec2(const TVector2 &ovec, const TVector2 &vec, const double scale) +template +inline T interpolatedvalue(const T& oval, const T& val, const double interpfrac) { - return ovec + ((vec - ovec) * scale); -} - -template -inline TVector3 interpolatedvec3(const TVector3 &ovec, const TVector3 &vec, const double scale) -{ - return ovec + ((vec - ovec) * scale); -} - -template -inline TVector4 interpolatedvec4(const TVector4 &ovec, const TVector4 &vec, const double scale) -{ - return ovec + ((vec - ovec) * scale); -} - -template -inline TAngle interpolatedangle(const TAngle &oang, const TAngle &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? diff --git a/source/core/coreactor.h b/source/core/coreactor.h index 80ab3345f..7fcb1bf1a 100644 --- a/source/core/coreactor.h +++ b/source/core/coreactor.h @@ -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() diff --git a/source/core/gameinput.h b/source/core/gameinput.h index 96da19187..0e86c2330 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -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. diff --git a/source/games/blood/src/qav.cpp b/source/games/blood/src/qav.cpp index 459b964de..a720f402f 100644 --- a/source/games/blood/src/qav.cpp +++ b/source/games/blood/src/qav.cpp @@ -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.; diff --git a/source/games/blood/src/view.cpp b/source/games/blood/src/view.cpp index 71d98bb0c..d27ff3353 100644 --- a/source/games/blood/src/view.cpp +++ b/source/games/blood/src/view.cpp @@ -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) diff --git a/source/games/duke/src/animatesprites_d.cpp b/source/games/duke/src/animatesprites_d.cpp index b846edc23..5854f0ec5 100644 --- a/source/games/duke/src/animatesprites_d.cpp +++ b/source/games/duke/src/animatesprites_d.cpp @@ -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 diff --git a/source/games/duke/src/animatesprites_r.cpp b/source/games/duke/src/animatesprites_r.cpp index 75fd3f8a0..df550d64f 100644 --- a/source/games/duke/src/animatesprites_r.cpp +++ b/source/games/duke/src/animatesprites_r.cpp @@ -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 diff --git a/source/games/duke/src/game_misc.cpp b/source/games/duke/src/game_misc.cpp index 0c2a979e8..d7ab515e9 100644 --- a/source/games/duke/src/game_misc.cpp +++ b/source/games/duke/src/game_misc.cpp @@ -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) diff --git a/source/games/duke/src/hudweapon_d.cpp b/source/games/duke/src/hudweapon_d.cpp index 5e472e742..b50c85465 100644 --- a/source/games/duke/src/hudweapon_d.cpp +++ b/source/games/duke/src/hudweapon_d.cpp @@ -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)); diff --git a/source/games/duke/src/hudweapon_r.cpp b/source/games/duke/src/hudweapon_r.cpp index 55f9ada46..27e157f6a 100644 --- a/source/games/duke/src/hudweapon_r.cpp +++ b/source/games/duke/src/hudweapon_r.cpp @@ -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)); diff --git a/source/games/duke/src/render.cpp b/source/games/duke/src/render.cpp index d18a44001..42518a5c7 100644 --- a/source/games/duke/src/render.cpp +++ b/source/games/duke/src/render.cpp @@ -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 { diff --git a/source/games/exhumed/src/gun.cpp b/source/games/exhumed/src/gun.cpp index aa6af97af..66a78b4a5 100644 --- a/source/games/exhumed/src/gun.cpp +++ b/source/games/exhumed/src/gun.cpp @@ -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; diff --git a/source/games/sw/src/draw.cpp b/source/games/sw/src/draw.cpp index 2b9d7a5f4..454f8f780 100644 --- a/source/games/sw/src/draw.cpp +++ b/source/games/sw/src/draw.cpp @@ -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)); } } diff --git a/source/games/sw/src/panel.cpp b/source/games/sw/src/panel.cpp index f0db03665..f4c734e47 100644 --- a/source/games/sw/src/panel.cpp +++ b/source/games/sw/src/panel.cpp @@ -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)