- Add interpolatedhorizon() inlines to handle interpolating fixedhoriz objects without having to convert old and new values back to Q16.16 first.

This commit is contained in:
Mitch Richters 2021-11-06 14:00:41 +11:00
parent 5ec5321034
commit 7499c84d0b
5 changed files with 16 additions and 12 deletions

View file

@ -405,3 +405,13 @@ inline constexpr binangle interpolatedangle(binangle oang, binangle ang, int con
{
return bamang(oang.asbam() + MulScale(((ang.asbam() + 0x80000000 - oang.asbam()) & 0xFFFFFFFF) - 0x80000000, smoothratio, scale));
}
inline constexpr fixedhoriz interpolatedhorizon(fixedhoriz oval, fixedhoriz val, double const smoothratio, int const scale = 16)
{
return q16horiz(oval.asq16() + MulScale((val - oval).asq16(), int(smoothratio), scale));
}
inline constexpr fixedhoriz interpolatedhorizon(fixedhoriz oval, fixedhoriz val, int const smoothratio, int const scale = 16)
{
return q16horiz(oval.asq16() + MulScale((val - oval).asq16(), smoothratio, scale));
}

View file

@ -52,7 +52,7 @@ struct PlayerHorizon
// Commonly used getters.
fixedhoriz osum() { return ohoriz + ohorizoff; }
fixedhoriz sum() { return horiz + horizoff; }
fixedhoriz interpolatedsum(double const smoothratio) { return q16horiz(interpolatedvalue(osum().asq16(), sum().asq16(), smoothratio)); }
fixedhoriz interpolatedsum(double const smoothratio) { return interpolatedhorizon(osum(), sum(), smoothratio); }
// Ticrate playsim adjustment helpers.
void addadjustment(double value) { __addadjustment(buildfhoriz(value)); }

View file

@ -248,12 +248,12 @@ static void fakeProcessInput(PLAYER *pPlayer, InputPacket *pInput)
if (nSector2 == nSector)
{
int z2 = getflorzofslope(nSector2, x2, y2);
predict.horizoff = q16horiz(interpolatedvalue(predict.horizoff.asq16(), IntToFixed(z1 - z2) >> 3, 0x4000));
predict.horizoff = interpolatedhorizon(predict.horizoff, q16horiz((z1 - z2) << 13), 0x4000);
}
}
else
{
predict.horizoff = q16horiz(interpolatedvalue(predict.horizoff.asq16(), 0, 0x4000));
predict.horizoff = interpolatedhorizon(predict.horizoff, q16horiz(0), 0x4000);
if (abs(predict.horizoff.asq16()) < 4)
predict.horizoff = q16horiz(0);
}

View file

@ -445,14 +445,8 @@ void SetupView(int &cX, int& cY, int& cZ, binangle& cA, fixedhoriz& cH, int& nSe
}
else
{
auto oang = predictOld.angle + predictOld.look_ang;
auto ang = predict.angle + predict.look_ang;
cA = interpolatedangle(oang, ang, gInterpolate);
fixed_t ohoriz = (predictOld.horiz + predictOld.horizoff).asq16();
fixed_t horiz = (predict.horiz + predict.horizoff).asq16();
cH = q16horiz(interpolatedvalue(ohoriz, horiz, gInterpolate));
cA = interpolatedangle(predictOld.angle + predictOld.look_ang, predict.angle + predict.look_ang, gInterpolate);
cH = interpolatedhorizon(predictOld.horiz + predictOld.horizoff, predict.horiz + predict.horizoff, gInterpolate);
rotscrnang = interpolatedangle(predictOld.rotscrnang, predict.rotscrnang, gInterpolate);
}
}

View file

@ -322,7 +322,7 @@ void displayrooms(int snum, double smoothratio)
cposz = interpolatedvalue(omyz, myz, smoothratio);
if (SyncInput())
{
choriz = q16horiz(interpolatedvalue((omyhoriz + omyhorizoff).asq16(), (myhoriz + myhorizoff).asq16(), smoothratio));
choriz = interpolatedhorizon(omyhoriz + omyhorizoff, myhoriz + myhorizoff, smoothratio);
cang = interpolatedangle(omyang, myang, smoothratio);
}
else