From 7499c84d0b8dc49deabaa2162938bb6e4c2d4210 Mon Sep 17 00:00:00 2001 From: Mitch Richters Date: Sat, 6 Nov 2021 14:00:41 +1100 Subject: [PATCH] - Add `interpolatedhorizon()` inlines to handle interpolating `fixedhoriz` objects without having to convert old and new values back to Q16.16 first. --- source/core/binaryangle.h | 10 ++++++++++ source/core/gameinput.h | 2 +- source/games/blood/src/prediction.cpp | 4 ++-- source/games/blood/src/view.cpp | 10 ++-------- source/games/duke/src/render.cpp | 2 +- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/source/core/binaryangle.h b/source/core/binaryangle.h index fcae89074..8fdd77a8e 100644 --- a/source/core/binaryangle.h +++ b/source/core/binaryangle.h @@ -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)); +} diff --git a/source/core/gameinput.h b/source/core/gameinput.h index b08b4b9f8..1920792aa 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -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)); } diff --git a/source/games/blood/src/prediction.cpp b/source/games/blood/src/prediction.cpp index 44ced83a6..f09280d1e 100644 --- a/source/games/blood/src/prediction.cpp +++ b/source/games/blood/src/prediction.cpp @@ -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); } diff --git a/source/games/blood/src/view.cpp b/source/games/blood/src/view.cpp index 3875d0cce..f367cdb5e 100644 --- a/source/games/blood/src/view.cpp +++ b/source/games/blood/src/view.cpp @@ -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); } } diff --git a/source/games/duke/src/render.cpp b/source/games/duke/src/render.cpp index 0aae20676..e75de10fd 100644 --- a/source/games/duke/src/render.cpp +++ b/source/games/duke/src/render.cpp @@ -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