From 547bf110b2b8cfeb64212e7bd63488a4802b8493 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Wed, 16 Sep 2020 12:31:32 +1000 Subject: [PATCH] - Blood: Create high-precision `Sinf()` and `Cosf()` inlines and use for player's horizon, using `calcSinTableValue()` from the backend, bypassing game's `costable[]`. --- source/blood/src/misc.h | 10 ++++++++++ source/blood/src/player.cpp | 4 ++-- source/blood/src/prediction.cpp | 4 ++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/source/blood/src/misc.h b/source/blood/src/misc.h index 6a3e9b442..3b539d1d0 100644 --- a/source/blood/src/misc.h +++ b/source/blood/src/misc.h @@ -90,6 +90,16 @@ inline int Cos(int ang) return costable[ang & 2047]; } +inline double Sinf(double ang) +{ + return (1 << 30) * sin(BANG2RAD * ang); +} + +inline double Cosf(double ang) +{ + return (1 << 30) * sin(BANG2RAD * (ang + 512.)); +} + inline int SinScale16(int ang) { return FixedToInt(costable[(ang - 512) & 2047]); diff --git a/source/blood/src/player.cpp b/source/blood/src/player.cpp index 42ab50308..6606e4498 100644 --- a/source/blood/src/player.cpp +++ b/source/blood/src/player.cpp @@ -1558,9 +1558,9 @@ void ProcessInput(PLAYER *pPlayer) } pPlayer->q16look = clamp(pPlayer->q16look+pInput->q16horz, IntToFixed(-60), IntToFixed(60)); if (pPlayer->q16look > 0) - pPlayer->q16horiz = IntToFixed(mulscale30(120, Sin(FixedToInt(pPlayer->q16look)<<3))); + pPlayer->q16horiz = FloatToFixed(fmulscale30(120., Sinf(FixedToFloat(pPlayer->q16look) * 8.))); else if (pPlayer->q16look < 0) - pPlayer->q16horiz = IntToFixed(mulscale30(180, Sin(FixedToInt(pPlayer->q16look)<<3))); + pPlayer->q16horiz = FloatToFixed(fmulscale30(180., Sinf(FixedToFloat(pPlayer->q16look) * 8.))); else pPlayer->q16horiz = 0; int nSector = pSprite->sectnum; diff --git a/source/blood/src/prediction.cpp b/source/blood/src/prediction.cpp index 0f0cf4111..03cfa333f 100644 --- a/source/blood/src/prediction.cpp +++ b/source/blood/src/prediction.cpp @@ -232,9 +232,9 @@ static void fakeProcessInput(PLAYER *pPlayer, InputPacket *pInput) predict.at20 = clamp(predict.at20+pInput->q16horz, IntToFixed(-60), IntToFixed(60)); if (predict.at20 > 0) - predict.at24 = mulscale30(IntToFixed(120), Sin(FixedToInt(predict.at20<<3))); + predict.at24 = FloatToFixed(fmulscale30(120., Sinf(FixedToFloat(predict.at20) * 8.))); else if (predict.at20 < 0) - predict.at24 = mulscale30(IntToFixed(180), Sin(FixedToInt(predict.at20<<3))); + predict.at24 = FloatToFixed(fmulscale30(180., Sinf(FixedToFloat(predict.at20) * 8.))); else predict.at24 = 0;