From f254eeb4656fe4b00050e70bda08a4c81c8de496 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sun, 11 Apr 2021 15:43:11 +1000 Subject: [PATCH 1/6] - binaryangle.h: Remove `lookangle` class and replace use with `binangle`. * Added in fca846272eb3795ddd3dd51ed48e494382c0a389 to deal with signed adjustments but its just not needed. * Made better use of `binangle`/`fixedhoriz` class getters and setters than before as well. --- source/core/binaryangle.h | 158 +----------------------- source/core/gameinput.cpp | 42 +++---- source/core/gameinput.h | 92 ++++++-------- source/core/rendering/hw_entrypoint.cpp | 6 +- source/core/rendering/render.h | 4 +- source/games/blood/src/common_game.h | 10 -- source/games/blood/src/player.cpp | 2 +- source/games/blood/src/prediction.cpp | 8 +- source/games/blood/src/view.cpp | 14 +-- source/games/blood/src/view.h | 6 +- source/games/duke/src/gameexec.cpp | 10 +- source/games/duke/src/input.cpp | 2 +- source/games/duke/src/player.cpp | 14 +-- source/games/duke/src/player_r.cpp | 4 +- source/games/duke/src/premap.cpp | 6 +- source/games/duke/src/render.cpp | 11 +- source/games/exhumed/src/view.cpp | 5 +- source/games/sw/src/draw.cpp | 3 +- source/games/sw/src/jsector.cpp | 2 +- source/games/sw/src/player.cpp | 3 +- 20 files changed, 115 insertions(+), 287 deletions(-) diff --git a/source/core/binaryangle.h b/source/core/binaryangle.h index a0690d734..028b9aad1 100644 --- a/source/core/binaryangle.h +++ b/source/core/binaryangle.h @@ -59,7 +59,6 @@ enum //--------------------------------------------------------------------------- constexpr double BAngRadian = pi::pi() * (1. / 1024.); -constexpr double BRadAngScale = 1. / BAngRadian; constexpr double BAngToDegree = 360. / 2048.; extern int16_t sintable[2048]; @@ -108,134 +107,6 @@ inline constexpr int64_t BAngToBAM(int ang) } -//--------------------------------------------------------------------------- -// -// -// -//--------------------------------------------------------------------------- - -class lookangle -{ - int32_t value; - - constexpr lookangle(int32_t v) : value(v) {} - - friend constexpr lookangle bamlook(int32_t v); - friend constexpr lookangle q16look(int32_t v); - friend constexpr lookangle buildlook(int32_t v); - friend lookangle buildflook(double v); - friend lookangle radlook(double v); - friend lookangle deglook(double v); - - friend FSerializer &Serialize(FSerializer &arc, const char *key, lookangle &obj, lookangle *defval); - - friend class binangle; - -public: - lookangle() = default; - lookangle(const lookangle &other) = default; - // This class intentionally makes no allowances for implicit type conversions because those would render it ineffective. - constexpr short asbuild() const { return value >> 21; } - constexpr double asbuildf() const { return value * (1. / BAMUNIT); } - constexpr fixed_t asq16() const { return value >> 5; } - constexpr double asrad() const { return value * (pi::pi() / 0x80000000u); } - constexpr double asdeg() const { return AngleToFloat(value); } - constexpr int32_t asbam() const { return value; } - - double fsin() const { return g_sin(asrad()); } - double fcos() const { return g_cos(asrad()); } - double ftan() const { return g_tan(asrad()); } - int bsin(const int8_t& shift = 0) const { return ::bsin(asbuild(), shift); } - int bcos(const int8_t& shift = 0) const { return ::bcos(asbuild(), shift); } - - bool operator< (lookangle other) const - { - return value < other.value; - } - - bool operator> (lookangle other) const - { - return value > other.value; - } - - bool operator<= (lookangle other) const - { - return value <= other.value; - } - - bool operator>= (lookangle other) const - { - return value >= other.value; - } - constexpr bool operator== (lookangle other) const - { - return value == other.value; - } - - constexpr bool operator!= (lookangle other) const - { - return value != other.value; - } - - constexpr lookangle &operator+= (lookangle other) - { - value += other.value; - return *this; - } - - constexpr lookangle &operator-= (lookangle other) - { - value -= other.value; - return *this; - } - - constexpr lookangle operator+ (lookangle other) const - { - return lookangle(value + other.value); - } - - constexpr lookangle operator- (lookangle other) const - { - return lookangle(value - other.value); - } - - constexpr lookangle &operator<<= (const uint8_t shift) - { - value <<= shift; - return *this; - } - - constexpr lookangle &operator>>= (const uint8_t shift) - { - value >>= shift; - return *this; - } - - constexpr lookangle operator<< (const uint8_t shift) const - { - return lookangle(value << shift); - } - - constexpr lookangle operator>> (const uint8_t shift) const - { - return lookangle(value >> shift); - } - -}; - -inline constexpr lookangle bamlook(int32_t v) { return lookangle(v); } -inline constexpr lookangle q16look(int32_t v) { return lookangle(v << 5); } -inline constexpr lookangle buildlook(int32_t v) { return lookangle(v << BAMBITS); } -inline lookangle buildflook(double v) { return lookangle(xs_CRoundToInt(v * BAMUNIT)); } -inline lookangle radlook(double v) { return lookangle(xs_CRoundToInt(v * (0x80000000u / pi::pi()))); } -inline lookangle deglook(double v) { return lookangle(FloatToAngle(v)); } - -inline FSerializer &Serialize(FSerializer &arc, const char *key, lookangle &obj, lookangle *defval) -{ - return Serialize(arc, key, obj.value, defval ? &defval->value : nullptr); -} - - //--------------------------------------------------------------------------- // // @@ -261,12 +132,17 @@ public: binangle() = default; binangle(const binangle &other) = default; // This class intentionally makes no allowances for implicit type conversions because those would render it ineffective. + constexpr int32_t tosigned() const { return value > BAngToBAM(1024) ? int64_t(value) - BAngToBAM(2048) : value; } constexpr short asbuild() const { return value >> 21; } constexpr double asbuildf() const { return value * (1. / BAMUNIT); } constexpr fixed_t asq16() const { return value >> 5; } + constexpr uint32_t asbam() const { return value; } constexpr double asrad() const { return value * (pi::pi() / 0x80000000u); } constexpr double asdeg() const { return AngleToFloat(value); } - constexpr uint32_t asbam() const { return value; } + constexpr short signedbuild() const { return tosigned() >> 21; } + constexpr double signedbuildf() const { return tosigned() * (1. / BAMUNIT); } + constexpr fixed_t signedq16() const { return tosigned() >> 5; } + constexpr int32_t signedbam() const { return tosigned(); } double fsin() const { return g_sin(asrad()); } double fcos() const { return g_cos(asrad()); } @@ -306,28 +182,6 @@ public: return binangle(value - other.value); } - constexpr binangle &operator+= (lookangle other) - { - value += other.value; - return *this; - } - - constexpr binangle &operator-= (lookangle other) - { - value -= other.value; - return *this; - } - - constexpr binangle operator+ (lookangle other) const - { - return binangle(value + other.value); - } - - constexpr binangle operator- (lookangle other) const - { - return binangle(value - other.value); - } - constexpr binangle &operator<<= (const uint8_t shift) { value <<= shift; diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index 4df8ccf80..0c31a9c23 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -78,7 +78,7 @@ fixed_t getincangleq16(fixed_t a, fixed_t na) return na-a; } -lookangle getincanglebam(binangle a, binangle na) +binangle getincanglebam(binangle a, binangle na) { int64_t cura = a.asbam() & 0xFFFFFFFF; int64_t newa = na.asbam() & 0xFFFFFFFF; @@ -89,7 +89,7 @@ lookangle getincanglebam(binangle a, binangle na) if(cura > BAngToBAM(1024)) cura -= BAngToBAM(2048); } - return bamlook(newa-cura); + return bamang(newa-cura); } //--------------------------------------------------------------------------- @@ -318,10 +318,10 @@ void sethorizon(PlayerHorizon* horizon, float const horz, ESyncBits* actions, do // return to center if conditions met. if ((*actions & SB_CENTERVIEW) && !(*actions & (SB_LOOK_UP|SB_LOOK_DOWN))) { - if (abs(horizon->horiz.asq16()) > FloatToFixed(0.25)) + if (abs(horizon->horiz.asq16()) > (FRACUNIT >> 2)) { // move horiz back to 0 - horizon->horiz -= q16horiz(xs_CRoundToInt(scaleAdjust * horizon->horiz.asq16() * (10. / GameTicRate))); + horizon->horiz -= buildfhoriz(scaleAdjust * horizon->horiz.asbuildf() * (10. / GameTicRate)); } else { @@ -346,63 +346,63 @@ void sethorizon(PlayerHorizon* horizon, float const horz, ESyncBits* actions, do void applylook(PlayerAngle* angle, float const avel, ESyncBits* actions, double const scaleAdjust) { // return q16rotscrnang to 0 and set to 0 if less than a quarter of a unit - angle->rotscrnang -= bamlook(xs_CRoundToInt(scaleAdjust * angle->rotscrnang.asbam() * (15. / GameTicRate))); - if (abs(angle->rotscrnang.asbam()) < (BAMUNIT >> 2)) angle->rotscrnang = bamlook(0); + angle->rotscrnang -= buildfang(scaleAdjust * angle->rotscrnang.signedbuildf() * (15. / GameTicRate)); + if (abs(angle->rotscrnang.signedbam()) < (BAMUNIT >> 2)) angle->rotscrnang = bamang(0); // return q16look_ang to 0 and set to 0 if less than a quarter of a unit - angle->look_ang -= bamlook(xs_CRoundToInt(scaleAdjust * angle->look_ang.asbam() * (7.5 / GameTicRate))); - if (abs(angle->look_ang.asbam()) < (BAMUNIT >> 2)) angle->look_ang = bamlook(0); + angle->look_ang -= buildfang(scaleAdjust * angle->look_ang.signedbuildf() * (7.5 / GameTicRate)); + if (abs(angle->look_ang.signedbam()) < (BAMUNIT >> 2)) angle->look_ang = bamang(0); if (*actions & SB_LOOK_LEFT) { // start looking left - angle->look_ang -= bamlook(xs_CRoundToInt(scaleAdjust * (4560. / GameTicRate) * BAMUNIT)); - angle->rotscrnang += bamlook(xs_CRoundToInt(scaleAdjust * (720. / GameTicRate) * BAMUNIT)); + angle->look_ang += buildfang(scaleAdjust * -(4560. / GameTicRate)); + angle->rotscrnang += buildfang(scaleAdjust * (720. / GameTicRate)); } if (*actions & SB_LOOK_RIGHT) { // start looking right - angle->look_ang += bamlook(xs_CRoundToInt(scaleAdjust * (4560. / GameTicRate) * BAMUNIT)); - angle->rotscrnang -= bamlook(xs_CRoundToInt(scaleAdjust * (720. / GameTicRate) * BAMUNIT)); + angle->look_ang += buildfang(scaleAdjust * (4560. / GameTicRate)); + angle->rotscrnang += buildfang(scaleAdjust * -(720. / GameTicRate)); } if (!angle->targetset()) { if (*actions & SB_TURNAROUND) { - if (angle->spin.asbam() == 0) + if (angle->spin == 0) { // currently not spinning, so start a spin - angle->spin = buildlook(-1024); + angle->spin = -1024.; } *actions &= ~SB_TURNAROUND; } - if (angle->spin.asbam() < 0) + if (angle->spin < 0) { // return spin to 0 - lookangle add = bamlook(xs_CRoundToUInt(scaleAdjust * ((!(*actions & SB_CROUCH) ? 3840. : 1920.) / GameTicRate) * BAMUNIT)); + double add = scaleAdjust * ((!(*actions & SB_CROUCH) ? 3840. : 1920.) / GameTicRate); angle->spin += add; - if (angle->spin.asbam() > 0) + if (angle->spin > 0) { // Don't overshoot our target. With variable factor this is possible. add -= angle->spin; - angle->spin = bamlook(0); + angle->spin = 0; } - angle->ang += bamang(add.asbam()); + angle->ang += buildfang(add); } if (avel) { // add player's input angle->ang += degang(avel); - angle->spin = bamlook(0); + angle->spin = 0; } } else { - angle->spin = bamlook(0); + angle->spin = 0; } } diff --git a/source/core/gameinput.h b/source/core/gameinput.h index 39f9a12ff..6d8901f88 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -9,7 +9,16 @@ int getincangle(int a, int na); double getincanglef(double a, double na); fixed_t getincangleq16(fixed_t a, fixed_t na); -lookangle getincanglebam(binangle a, binangle na); +binangle getincanglebam(binangle a, binangle na); + +inline binangle interpolatedbamang(binangle oang, binangle ang, double const smoothratio) +{ + double const ratio = smoothratio * (1. / FRACUNIT); + uint32_t const dang = UINT32_MAX >> 1; + int64_t const prev = oang.asbam(); + int64_t const curr = ang.asbam(); + return bamang(prev + xs_CRoundToUInt(ratio * (((curr + dang - prev) & 0xFFFFFFFF) - dang))); +} struct PlayerHorizon { @@ -29,7 +38,12 @@ struct PlayerHorizon void addadjustment(double value) { - __addadjustment(q16horiz(FloatToFixed(value))); + __addadjustment(buildfhoriz(value)); + } + + void addadjustment(fixedhoriz value) + { + __addadjustment(value); } void resetadjustment() @@ -37,11 +51,6 @@ struct PlayerHorizon adjustment = 0; } - void settarget(int value, bool backup = false) - { - __settarget(buildhoriz(clamp(value, FixedToInt(gi->playerHorizMin()), FixedToInt(gi->playerHorizMax()))), backup); - } - void settarget(double value, bool backup = false) { __settarget(buildfhoriz(clamp(value, FixedToFloat(gi->playerHorizMin()), FixedToFloat(gi->playerHorizMax()))), backup); @@ -61,11 +70,11 @@ struct PlayerHorizon { if (targetset()) { - auto delta = (target - horiz).asq16(); + auto delta = (target - horiz).asbuildf(); - if (abs(delta) > FRACUNIT) + if (abs(delta) > 1) { - horiz += q16horiz(xs_CRoundToInt(scaleAdjust * delta)); + horiz += buildfhoriz(scaleAdjust * delta); } else { @@ -75,7 +84,7 @@ struct PlayerHorizon } else if (adjustment) { - horiz += q16horiz(xs_CRoundToInt(scaleAdjust * adjustment)); + horiz += buildfhoriz(scaleAdjust * adjustment); } } @@ -105,7 +114,7 @@ private: { if (!SyncInput()) { - adjustment += value.asq16(); + adjustment += value.asbuildf(); } else { @@ -113,7 +122,7 @@ private: } } - void __settarget(fixedhoriz value, bool backup = false) + void __settarget(fixedhoriz value, bool backup) { if (!SyncInput() && !backup) { @@ -130,8 +139,8 @@ private: struct PlayerAngle { - binangle ang, oang; - lookangle look_ang, olook_ang, rotscrnang, orotscrnang, spin; + binangle ang, oang, look_ang, olook_ang, rotscrnang, orotscrnang; + double spin; void backup() { @@ -147,24 +156,14 @@ struct PlayerAngle rotscrnang = orotscrnang; } - void addadjustment(int value) - { - __addadjustment(buildlook(value)); - } - void addadjustment(double value) { - __addadjustment(buildflook(value)); - } - - void addadjustment(lookangle value) - { - __addadjustment(value); + __addadjustment(buildfang(value)); } void addadjustment(binangle value) { - __addadjustment(bamlook(value.asbam())); + __addadjustment(value); } void resetadjustment() @@ -172,14 +171,9 @@ struct PlayerAngle adjustment = 0; } - void settarget(int value, bool backup = false) - { - __settarget(buildang(value & 2047), backup); - } - void settarget(double value, bool backup = false) { - __settarget(buildfang(fmod(value, 2048)), backup); + __settarget(buildfang(value), backup); } void settarget(binangle value, bool backup = false) @@ -196,11 +190,11 @@ struct PlayerAngle { if (targetset()) { - auto delta = getincanglebam(ang, target).asbam(); + auto delta = getincanglebam(ang, target).signedbuildf(); - if (delta > BAMUNIT) + if (abs(delta) > 1) { - ang += bamang(xs_CRoundToUInt(scaleAdjust * delta)); + ang += buildfang(scaleAdjust * delta); } else { @@ -210,7 +204,7 @@ struct PlayerAngle } else if (adjustment) { - ang += bamang(xs_CRoundToUInt(scaleAdjust * adjustment)); + ang += buildfang(scaleAdjust * adjustment); } } @@ -226,39 +220,33 @@ struct PlayerAngle binangle interpolatedsum(double const smoothratio) { - double const ratio = smoothratio * (1. / FRACUNIT); - uint32_t const dang = UINT32_MAX >> 1; - int64_t const prev = osum().asbam(); - int64_t const curr = sum().asbam(); - return bamang(prev + xs_CRoundToUInt(ratio * (((curr + dang - prev) & 0xFFFFFFFF) - dang))); + return interpolatedbamang(osum(), sum(), smoothratio); } - lookangle interpolatedlookang(double const smoothratio) + binangle interpolatedlookang(double const smoothratio) { - double const ratio = smoothratio * (1. / FRACUNIT); - return bamlook(olook_ang.asbam() + xs_CRoundToInt(ratio * (look_ang - olook_ang).asbam())); + return interpolatedbamang(olook_ang, look_ang, smoothratio); } - lookangle interpolatedrotscrn(double const smoothratio) + binangle interpolatedrotscrn(double const smoothratio) { - double const ratio = smoothratio * (1. / FRACUNIT); - return bamlook(orotscrnang.asbam() + xs_CRoundToInt(ratio * (rotscrnang - orotscrnang).asbam())); + return interpolatedbamang(orotscrnang, rotscrnang, smoothratio); } double look_anghalf(double const smoothratio) { - return (!SyncInput() ? look_ang : interpolatedlookang(smoothratio)).asbam() * (0.5 / BAMUNIT); // Used within draw code for weapon and crosshair when looking left/right. + return (!SyncInput() ? look_ang : interpolatedlookang(smoothratio)).signedbuildf() * 0.5; // Used within draw code for weapon and crosshair when looking left/right. } private: binangle target; double adjustment; - void __addadjustment(lookangle value) + void __addadjustment(binangle value) { if (!SyncInput()) { - adjustment += value.asbam(); + adjustment += value.asbuildf(); } else { @@ -266,7 +254,7 @@ private: } } - void __settarget(binangle value, bool backup = false) + void __settarget(binangle value, bool backup) { if (!SyncInput() && !backup) { diff --git a/source/core/rendering/hw_entrypoint.cpp b/source/core/rendering/hw_entrypoint.cpp index 61d622034..d8325cf61 100644 --- a/source/core/rendering/hw_entrypoint.cpp +++ b/source/core/rendering/hw_entrypoint.cpp @@ -175,7 +175,7 @@ void RenderViewpoint(FRenderViewpoint& mainvp, IntRect* bounds, float fov, float // //=========================================================================== -FRenderViewpoint SetupViewpoint(spritetype* cam, const vec3_t& position, int sectnum, binangle angle, fixedhoriz horizon, lookangle rollang) +FRenderViewpoint SetupViewpoint(spritetype* cam, const vec3_t& position, int sectnum, binangle angle, fixedhoriz horizon, binangle rollang) { FRenderViewpoint r_viewpoint{}; r_viewpoint.CameraSprite = cam; @@ -275,7 +275,7 @@ static void CheckTimer(FRenderState &state, uint64_t ShaderStartTime) void animatecamsprite(double s); -void render_drawrooms(spritetype* playersprite, const vec3_t& position, int sectnum, binangle angle, fixedhoriz horizon, lookangle rollang) +void render_drawrooms(spritetype* playersprite, const vec3_t& position, int sectnum, binangle angle, fixedhoriz horizon, binangle rollang) { checkRotatedWalls(); @@ -328,7 +328,7 @@ void render_drawrooms(spritetype* playersprite, const vec3_t& position, int sect All.Unclock(); } -void render_camtex(spritetype* playersprite, const vec3_t& position, int sectnum, binangle angle, fixedhoriz horizon, lookangle rollang, FGameTexture* camtex, IntRect& rect, double smoothratio) +void render_camtex(spritetype* playersprite, const vec3_t& position, int sectnum, binangle angle, fixedhoriz horizon, binangle rollang, FGameTexture* camtex, IntRect& rect, double smoothratio) { int16_t sect = sectnum; updatesector(position.x, position.y, §); diff --git a/source/core/rendering/render.h b/source/core/rendering/render.h index ad4fb56f9..1214f4f8b 100644 --- a/source/core/rendering/render.h +++ b/source/core/rendering/render.h @@ -4,8 +4,8 @@ class FSerializer; struct IntRect; -void render_drawrooms(spritetype* playersprite, const vec3_t& position, int sectnum, binangle angle, fixedhoriz horizon, lookangle rollang); -void render_camtex(spritetype* playersprite, const vec3_t& position, int sectnum, binangle angle, fixedhoriz horizon, lookangle rollang, FGameTexture* camtex, IntRect& rect, double smoothratio); +void render_drawrooms(spritetype* playersprite, const vec3_t& position, int sectnum, binangle angle, fixedhoriz horizon, binangle rollang); +void render_camtex(spritetype* playersprite, const vec3_t& position, int sectnum, binangle angle, fixedhoriz horizon, binangle rollang, FGameTexture* camtex, IntRect& rect, double smoothratio); struct PortalDesc { diff --git a/source/games/blood/src/common_game.h b/source/games/blood/src/common_game.h index 2556e2336..4f24551e8 100644 --- a/source/games/blood/src/common_game.h +++ b/source/games/blood/src/common_game.h @@ -547,16 +547,6 @@ inline fixed_t interpolateangfix16(fixed_t a, fixed_t b, int c) return a+MulScale(((b-a+0x4000000)&0x7ffffff)-0x4000000, c, 16); } -inline binangle interpolateangbin(uint32_t a, uint32_t b, double c) -{ - return bamang(xs_CRoundToUInt(a + MulScaleF(b - a, c, 16))); -} - -inline lookangle interpolateanglook(int32_t a, int32_t b, double c) -{ - return bamlook(xs_CRoundToUInt(a + MulScaleF(b - a, c, 16))); -} - inline char Chance(int a1) { return wrand() < (a1>>1); diff --git a/source/games/blood/src/player.cpp b/source/games/blood/src/player.cpp index 28ae4aec8..344c95a62 100644 --- a/source/games/blood/src/player.cpp +++ b/source/games/blood/src/player.cpp @@ -700,7 +700,7 @@ void playerStart(int nPlayer, int bNewLevel) pPlayer->restTime = 0; pPlayer->kickPower = 0; pPlayer->laughCount = 0; - pPlayer->angle.spin = buildlook(0); + pPlayer->angle.spin = 0; pPlayer->posture = 0; pPlayer->voodooTarget = -1; pPlayer->voodooTargets = 0; diff --git a/source/games/blood/src/prediction.cpp b/source/games/blood/src/prediction.cpp index adc91f712..0fa230906 100644 --- a/source/games/blood/src/prediction.cpp +++ b/source/games/blood/src/prediction.cpp @@ -166,9 +166,9 @@ static void fakeProcessInput(PLAYER *pPlayer, InputPacket *pInput) if (pInput->avel) predict.angle = degang(pInput->avel); if (pInput->actions & SB_TURNAROUND) - if (!predict.spin.asbuild()) - predict.spin = buildlook(-1024); - if (predict.spin.asbuild() < 0) + if (!predict.spin) + predict.spin = -1024; + if (predict.spin < 0) { int speed; if (predict.at48 == 1) @@ -176,7 +176,7 @@ static void fakeProcessInput(PLAYER *pPlayer, InputPacket *pInput) else speed = 128; - predict.spin = buildlook(min(predict.spin.asbuild()+speed, 0)); + predict.spin = min(int(predict.spin) + speed, 0); predict.angle += buildang(speed); } diff --git a/source/games/blood/src/view.cpp b/source/games/blood/src/view.cpp index d7825c616..3f0f8950a 100644 --- a/source/games/blood/src/view.cpp +++ b/source/games/blood/src/view.cpp @@ -458,7 +458,7 @@ static void DrawMap(spritetype* pSprite) setViewport(hud_size); } -void SetupView(int &cX, int& cY, int& cZ, binangle& cA, fixedhoriz& cH, int& nSectnum, double& zDelta, double& shakeX, double& shakeY, lookangle& rotscrnang) +void SetupView(int &cX, int& cY, int& cZ, binangle& cA, fixedhoriz& cH, int& nSectnum, double& zDelta, double& shakeX, double& shakeY, binangle& rotscrnang) { int bobWidth, bobHeight; @@ -483,15 +483,15 @@ void SetupView(int &cX, int& cY, int& cZ, binangle& cA, fixedhoriz& cH, int& nSe } else { - uint32_t oang = predictOld.angle.asbam() + predictOld.look_ang.asbam(); - uint32_t ang = predict.angle.asbam() + predict.look_ang.asbam(); - cA = interpolateangbin(oang, ang, gInterpolate); + auto oang = predictOld.angle + predictOld.look_ang; + auto ang = predict.angle + predict.look_ang; + cA = interpolatedbamang(oang, ang, gInterpolate); fixed_t ohoriz = (predictOld.horiz + predictOld.horizoff).asq16(); fixed_t horiz = (predict.horiz + predict.horizoff).asq16(); cH = q16horiz(interpolate(ohoriz, horiz, gInterpolate)); - rotscrnang = interpolateanglook(predictOld.rotscrnang.asbam(), predict.rotscrnang.asbam(), gInterpolate); + rotscrnang = interpolatedbamang(predictOld.rotscrnang, predict.rotscrnang, gInterpolate); } } else @@ -685,7 +685,7 @@ void viewDrawScreen(bool sceneonly) int nSectnum; double zDelta; double shakeX, shakeY; - lookangle rotscrnang; + binangle rotscrnang; SetupView(cX, cY, cZ, cA, cH, nSectnum, zDelta, shakeX, shakeY, rotscrnang); int tilt = interpolateang(gScreenTiltO, gScreenTilt, gInterpolate); @@ -697,7 +697,7 @@ void viewDrawScreen(bool sceneonly) uint8_t otherview = powerupCheck(gView, kPwUpCrystalBall) > 0; if (tilt || bDelirium) { - rotscrnang = buildlook(tilt); + rotscrnang = buildang(tilt); } else if (otherview && gNetPlayers > 1) { diff --git a/source/games/blood/src/view.h b/source/games/blood/src/view.h index 22ca31e14..9b1d1399b 100644 --- a/source/games/blood/src/view.h +++ b/source/games/blood/src/view.h @@ -50,7 +50,7 @@ struct VIEW { int at40; int at44; int at48; // posture - lookangle spin; // spin + double spin; // spin int x; // x int y; // y int z; // z @@ -66,8 +66,8 @@ struct VIEW { char at72; // underwater short at73; // sprite flags SPRITEHIT at75; - lookangle look_ang; - lookangle rotscrnang; + binangle look_ang; + binangle rotscrnang; }; extern VIEW gPrevView[kMaxPlayers]; diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index 733879e4b..851a99a4c 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -484,7 +484,7 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor, break; case PLAYER_LOOK_ANG: - if (bSet) ps[iPlayer].angle.look_ang = buildlook(lValue); + if (bSet) ps[iPlayer].angle.look_ang = buildang(lValue); else SetGameVarID(lVar2, ps[iPlayer].angle.look_ang.asbuild(), sActor, sPlayer); break; @@ -645,8 +645,8 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor, break; case PLAYER_ONE_EIGHTY_COUNT: - if (bSet) ps[iPlayer].angle.spin = buildlook(lValue); - else SetGameVarID(lVar2, ps[iPlayer].angle.spin.asbuild(), sActor, sPlayer); + if (bSet) ps[iPlayer].angle.spin = lValue; + else SetGameVarID(lVar2, ps[iPlayer].angle.spin, sActor, sPlayer); break; case PLAYER_CHEAT_PHASE: @@ -705,7 +705,7 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor, break; case PLAYER_ROTSCRNANG: - if (bSet) ps[iPlayer].angle.rotscrnang = buildlook(lValue); + if (bSet) ps[iPlayer].angle.rotscrnang = buildang(lValue); else SetGameVarID(lVar2, ps[iPlayer].angle.rotscrnang.asbuild(), sActor, sPlayer); break; @@ -2267,7 +2267,7 @@ int ParseState::parse(void) ps[g_p].weapreccnt = 0; ps[g_p].ftq = 0; ps[g_p].posxv = ps[g_p].posyv = 0; - if (!isRR()) ps[g_p].angle.orotscrnang = ps[g_p].angle.rotscrnang = buildlook(0); + if (!isRR()) ps[g_p].angle.orotscrnang = ps[g_p].angle.rotscrnang = buildang(0); ps[g_p].falling_counter = 0; diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index c05c1fa83..8f0cc3d7f 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -477,7 +477,7 @@ void hud_input(int plnum) } } - if (PlayerInput(plnum, SB_TURNAROUND) && p->angle.spin.asbam() == 0 && p->on_crane == nullptr) + if (PlayerInput(plnum, SB_TURNAROUND) && p->angle.spin == 0 && p->on_crane == nullptr) { SetGameVarID(g_iReturnVarID, 0, nullptr, plnum); OnEvent(EVENT_TURNAROUND, plnum, nullptr, -1); diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index 32eda7fb8..0f36b8284 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -121,7 +121,7 @@ void forceplayerangle(int snum) p->horizon.addadjustment(64); p->sync.actions |= SB_CENTERVIEW; - p->angle.rotscrnang = p->angle.look_ang = buildlook(n >> 1); + p->angle.rotscrnang = p->angle.look_ang = buildang(n >> 1); } //--------------------------------------------------------------------------- @@ -630,7 +630,7 @@ void playerisdead(int snum, int psectlotag, int fz, int cz) pushmove(&p->posx, &p->posy, &p->posz, &p->cursectnum, 128L, (4 << 8), (20 << 8), CLIPMASK0); if (fz > cz + (16 << 8) && s->pal != 1) - p->angle.rotscrnang = buildlook(p->dead_flag + ((fz + p->posz) >> 7)); + p->angle.rotscrnang = buildang(p->dead_flag + ((fz + p->posz) >> 7)); p->on_warping_sector = 0; @@ -741,16 +741,16 @@ void player_struct::apply_seasick(double factor) if (SeaSick < 250) { if (SeaSick >= 180) - angle.rotscrnang += bamlook(xs_CRoundToUInt(24 * factor * BAMUNIT)); + angle.rotscrnang += bamang(xs_CRoundToUInt(24 * factor * BAMUNIT)); else if (SeaSick >= 130) - angle.rotscrnang -= bamlook(xs_CRoundToUInt(24 * factor * BAMUNIT)); + angle.rotscrnang -= bamang(xs_CRoundToUInt(24 * factor * BAMUNIT)); else if (SeaSick >= 70) - angle.rotscrnang += bamlook(xs_CRoundToUInt(24 * factor * BAMUNIT)); + angle.rotscrnang += bamang(xs_CRoundToUInt(24 * factor * BAMUNIT)); else if (SeaSick >= 20) - angle.rotscrnang -= bamlook(xs_CRoundToUInt(24 * factor * BAMUNIT)); + angle.rotscrnang -= bamang(xs_CRoundToUInt(24 * factor * BAMUNIT)); } if (SeaSick < 250) - angle.look_ang = bamlook(xs_CRoundToUInt(((krand() & 255) - 128) * factor * BAMUNIT)); + angle.look_ang = bamang(xs_CRoundToUInt(((krand() & 255) - 128) * factor * BAMUNIT)); } } diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index bd43f3bb4..e450255b3 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -1773,7 +1773,7 @@ static void onMotorcycle(int snum, ESyncBits &actions) if (p->MotoSpeed >= 20 && p->on_ground == 1 && (p->vehTurnLeft || p->vehTurnRight)) { velAdjustment = p->vehTurnLeft ? -10 : 10; - auto angAdjustment = buildlook(velAdjustment < 0 ? 350 : -350); + auto angAdjustment = buildang(velAdjustment < 0 ? 350 : -350); if (p->moto_on_mud || p->moto_on_oil || !p->NotOnWater) { @@ -2040,7 +2040,7 @@ static void onBoat(int snum, ESyncBits &actions) { int currSpeed = p->MotoSpeed * 4.; short velAdjustment = p->vehTurnLeft ? -10 : 10; - auto angAdjustment = buildlook(velAdjustment < 0 ? 350 : -350); + auto angAdjustment = buildang(velAdjustment < 0 ? 350 : -350); if (p->moto_do_bump) { diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index dbe8c2e71..6cb5b630a 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -140,8 +140,8 @@ void resetplayerstats(int snum) p->jetpack_on = 0; p->holoduke_on = nullptr; - p->angle.olook_ang = p->angle.look_ang = buildlook(512 - ((currentLevel->levelNumber & 1) << 10)); - p->angle.orotscrnang = p->angle.rotscrnang = buildlook(0); + p->angle.olook_ang = p->angle.look_ang = buildang(512 - ((currentLevel->levelNumber & 1) << 10)); + p->angle.orotscrnang = p->angle.rotscrnang = buildang(0); p->newOwner =nullptr; p->jumping_counter = 0; @@ -152,7 +152,7 @@ void resetplayerstats(int snum) p->fric.x = 0; p->fric.y = 0; p->somethingonplayer =nullptr; - p->angle.spin = bamlook(0); + p->angle.spin = 0; p->on_crane = nullptr; diff --git a/source/games/duke/src/render.cpp b/source/games/duke/src/render.cpp index 1d4de2663..16843ba42 100644 --- a/source/games/duke/src/render.cpp +++ b/source/games/duke/src/render.cpp @@ -67,7 +67,7 @@ BEGIN_DUKE_NS /*static*/ int tempsectorpicnum[MAXSECTORS]; //short tempcursectnum; -void renderView(spritetype* playersprite, int sectnum, int x, int y, int z, binangle a, fixedhoriz h, lookangle rotscrnang, int smoothratio) +void renderView(spritetype* playersprite, int sectnum, int x, int y, int z, binangle a, fixedhoriz h, binangle rotscrnang, int smoothratio) { if (!testnewrenderer) { @@ -126,7 +126,7 @@ void GameInterface::UpdateCameras(double smoothratio) } else { - render_camtex(camera, camera->pos, camera->sectnum, ang, buildhoriz(camera->shade), buildlook(0), tex, rect, smoothratio); + render_camtex(camera, camera->pos, camera->sectnum, ang, buildhoriz(camera->shade), buildang(0), tex, rect, smoothratio); } display_mirror = 0; }); @@ -256,8 +256,7 @@ void displayrooms(int snum, double smoothratio) { int cposx, cposy, cposz, fz, cz; short sect; - binangle cang; - lookangle rotscrnang; + binangle cang, rotscrnang; fixedhoriz choriz; struct player_struct* p; int tiltcs = 0; // JBF 20030807 @@ -301,7 +300,7 @@ void displayrooms(int snum, double smoothratio) cang = buildfang(ud.cameraactor->tempang + MulScaleF(((s->ang + 1024 - ud.cameraactor->tempang) & 2047) - 1024, smoothratio, 16)); auto bh = buildhoriz(s->yvel); - renderView(s, s->sectnum, s->x, s->y, s->z - (4 << 8), cang, bh, buildlook(0), smoothratio); + renderView(s, s->sectnum, s->x, s->y, s->z - (4 << 8), cang, bh, buildang(0), smoothratio); } else { @@ -365,7 +364,7 @@ void displayrooms(int snum, double smoothratio) cposy = spr->pos.y; cposz = spr->pos.z; sect = spr->sectnum; - rotscrnang = buildlook(0); + rotscrnang = buildang(0); smoothratio = MaxSmoothRatio; viewer = spr; } diff --git a/source/games/exhumed/src/view.cpp b/source/games/exhumed/src/view.cpp index 517b53d6b..685d76f2a 100644 --- a/source/games/exhumed/src/view.cpp +++ b/source/games/exhumed/src/view.cpp @@ -207,9 +207,8 @@ void DrawView(double smoothRatio, bool sceneonly) int playerY; int playerZ; short nSector; - binangle nAngle; + binangle nAngle, rotscrnang; fixedhoriz pan; - lookangle rotscrnang; fixed_t dang = IntToFixed(1024); @@ -231,7 +230,7 @@ void DrawView(double smoothRatio, bool sceneonly) playerZ = sprite[nSprite].z; nSector = sprite[nSprite].sectnum; nAngle = buildang(sprite[nSprite].ang); - rotscrnang = buildlook(0); + rotscrnang = buildang(0); SetGreenPal(); diff --git a/source/games/sw/src/draw.cpp b/source/games/sw/src/draw.cpp index 1b8e8b2e0..9516f4502 100644 --- a/source/games/sw/src/draw.cpp +++ b/source/games/sw/src/draw.cpp @@ -1468,8 +1468,7 @@ drawscreen(PLAYERp pp, double smoothratio) { extern bool CameraTestMode; int tx, ty, tz; - lookangle trotscrnang; - binangle tang; + binangle tang, trotscrnang; fixedhoriz thoriz; short tsectnum; short i,j; diff --git a/source/games/sw/src/jsector.cpp b/source/games/sw/src/jsector.cpp index 61329b92d..db6b48926 100644 --- a/source/games/sw/src/jsector.cpp +++ b/source/games/sw/src/jsector.cpp @@ -481,7 +481,7 @@ void drawroomstotile(int daposx, int daposy, int daposz, } else { - render_camtex(nullptr, { daposx, daposy, daposz }, dacursectnum, ang, horiz, buildlook(0), tileGetTexture(tilenume), rect, smoothratio); + render_camtex(nullptr, { daposx, daposy, daposz }, dacursectnum, ang, horiz, buildang(0), tileGetTexture(tilenume), rect, smoothratio); } }); diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index a8ab12403..338f7a58d 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -1606,8 +1606,7 @@ DoPlayerTurnVehicleRect(PLAYERp pp, int *x, int *y, int *ox, int *oy) void DoPlayerTurnTurret(PLAYERp pp, float avel) { - lookangle diff; - binangle new_ang; + binangle new_ang, diff; SECTOR_OBJECTp sop = pp->sop; if (sop->drive_angspeed) From e76f63e2c0d32af278104e391e8d2df119598e2a Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sun, 11 Apr 2021 16:45:19 +1000 Subject: [PATCH 2/6] - Consolidate all game interpolation code into inline functions. --- source/build/include/buildtypes.h | 18 ++++---- source/core/binaryangle.h | 27 ++++++++++++ source/core/gameinput.h | 15 ++----- source/games/blood/src/_polymost.cpp | 8 ++-- source/games/blood/src/common_game.h | 20 --------- source/games/blood/src/player.cpp | 4 +- source/games/blood/src/prediction.cpp | 8 ++-- source/games/blood/src/triggers.cpp | 12 +++--- source/games/blood/src/view.cpp | 48 +++++++++++----------- source/games/blood/src/weapon.cpp | 6 +-- source/games/duke/src/animatesprites_d.cpp | 10 ++--- source/games/duke/src/animatesprites_r.cpp | 10 ++--- source/games/duke/src/game_misc.cpp | 12 +++--- source/games/duke/src/hudweapon_d.cpp | 12 +++--- source/games/duke/src/hudweapon_r.cpp | 10 ++--- source/games/duke/src/render.cpp | 22 +++++----- source/games/exhumed/src/gun.cpp | 4 +- source/games/exhumed/src/view.cpp | 7 +--- source/games/exhumed/src/view.h | 5 --- source/games/sw/src/_polymost.cpp | 6 +-- source/games/sw/src/draw.cpp | 8 ++-- source/games/sw/src/panel.cpp | 4 +- 22 files changed, 130 insertions(+), 146 deletions(-) diff --git a/source/build/include/buildtypes.h b/source/build/include/buildtypes.h index 4d503f5d5..9cb4289e9 100644 --- a/source/build/include/buildtypes.h +++ b/source/build/include/buildtypes.h @@ -317,39 +317,41 @@ struct spritetype int32_t interpolatedx(double const smoothratio, int const scale = 16) { - return ox + MulScale(x - ox, smoothratio, scale); + return interpolatedvalue(ox, x, smoothratio, scale); } int32_t interpolatedy(double const smoothratio, int const scale = 16) { - return oy + MulScale(y - oy, smoothratio, scale); + return interpolatedvalue(oy, y, smoothratio, scale); } int32_t interpolatedz(double const smoothratio, int const scale = 16) { - return oz + MulScale(z - oz, smoothratio, scale); + return interpolatedvalue(oz, z, smoothratio, scale); } vec2_t interpolatedvec2(double const smoothratio, int const scale = 16) { - return vec2_t({ + return + { interpolatedx(smoothratio, scale), interpolatedy(smoothratio, scale) - }); + }; } vec3_t interpolatedvec3(double const smoothratio, int const scale = 16) { - return vec3_t({ + return + { interpolatedx(smoothratio, scale), interpolatedy(smoothratio, scale), interpolatedz(smoothratio, scale) - }); + }; } int16_t interpolatedang(double const smoothratio) { - return oang + MulScale(((ang + 1024 - oang) & 2047) - 1024, smoothratio, 16); + return interpolatedangle(oang, ang, smoothratio, 16); } }; diff --git a/source/core/binaryangle.h b/source/core/binaryangle.h index 028b9aad1..73ec90911 100644 --- a/source/core/binaryangle.h +++ b/source/core/binaryangle.h @@ -364,3 +364,30 @@ inline binangle bvectangbam(int32_t x, int32_t y) { return radang(atan2(y, x)); } + + +//--------------------------------------------------------------------------- +// +// Interpolation functions for use throughout games. +// +//--------------------------------------------------------------------------- + +inline int32_t interpolatedvalue(int32_t oval, int32_t val, double const smoothratio, int const scale = 16) +{ + return oval + MulScale(val - oval, smoothratio, scale); +} + +inline double interpolatedvaluef(double oval, double val, double const smoothratio, int const scale = 16) +{ + return oval + MulScaleF(val - oval, smoothratio, scale); +} + +inline int32_t interpolatedangle(int32_t oang, int32_t ang, double const smoothratio, int const scale = 16) +{ + return oang + MulScale(((ang + 1024 - oang) & 2047) - 1024, smoothratio, scale); +} + +inline binangle interpolatedangle(binangle oang, binangle ang, double const smoothratio, int const scale = 16) +{ + return bamang(oang.asbam() + MulScale(((ang.asbam() + 0x80000000 - oang.asbam()) & 0xFFFFFFFF) - 0x80000000, smoothratio, scale)); +} diff --git a/source/core/gameinput.h b/source/core/gameinput.h index 6d8901f88..047f027e0 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -11,15 +11,6 @@ double getincanglef(double a, double na); fixed_t getincangleq16(fixed_t a, fixed_t na); binangle getincanglebam(binangle a, binangle na); -inline binangle interpolatedbamang(binangle oang, binangle ang, double const smoothratio) -{ - double const ratio = smoothratio * (1. / FRACUNIT); - uint32_t const dang = UINT32_MAX >> 1; - int64_t const prev = oang.asbam(); - int64_t const curr = ang.asbam(); - return bamang(prev + xs_CRoundToUInt(ratio * (((curr + dang - prev) & 0xFFFFFFFF) - dang))); -} - struct PlayerHorizon { fixedhoriz horiz, ohoriz, horizoff, ohorizoff; @@ -220,17 +211,17 @@ struct PlayerAngle binangle interpolatedsum(double const smoothratio) { - return interpolatedbamang(osum(), sum(), smoothratio); + return interpolatedangle(osum(), sum(), smoothratio); } binangle interpolatedlookang(double const smoothratio) { - return interpolatedbamang(olook_ang, look_ang, smoothratio); + return interpolatedangle(olook_ang, look_ang, smoothratio); } binangle interpolatedrotscrn(double const smoothratio) { - return interpolatedbamang(orotscrnang, rotscrnang, smoothratio); + return interpolatedangle(orotscrnang, rotscrnang, smoothratio); } double look_anghalf(double const smoothratio) diff --git a/source/games/blood/src/_polymost.cpp b/source/games/blood/src/_polymost.cpp index de8a89b59..417da88b0 100644 --- a/source/games/blood/src/_polymost.cpp +++ b/source/games/blood/src/_polymost.cpp @@ -52,9 +52,9 @@ void collectTSpritesForPortal(int x, int y, int i, int interpolation) pTSprite->owner = pSprite->index; pTSprite->extra = pSprite->extra; pTSprite->flags = pSprite->hitag | 0x200; - pTSprite->x = dx + interpolate(pSprite->ox, pSprite->x, interpolation); - pTSprite->y = dy + interpolate(pSprite->oy, pSprite->y, interpolation); - pTSprite->z = dz + interpolate(pSprite->oz, pSprite->z, interpolation); + pTSprite->x = dx + interpolatedvalue(pSprite->ox, pSprite->x, interpolation); + pTSprite->y = dy + interpolatedvalue(pSprite->oy, pSprite->y, interpolation); + pTSprite->z = dz + interpolatedvalue(pSprite->oz, pSprite->z, interpolation); pTSprite->ang = pSprite->interpolatedang(interpolation); int nAnim = 0; @@ -147,7 +147,7 @@ RORHACK: int ror_status[16]; for (int i = 0; i < 16; i++) ror_status[i] = TestBitString(gotpic, 4080 + i); - fixed_t deliriumPitchI = interpolate(IntToFixed(deliriumPitchO), IntToFixed(deliriumPitch), gInterpolate); + fixed_t deliriumPitchI = interpolatedvalue(IntToFixed(deliriumPitchO), IntToFixed(deliriumPitch), gInterpolate); DrawMirrors(cX, cY, cZ, cA.asq16(), cH.asq16() + deliriumPitchI, gInterpolate, gViewIndex); int bakCstat = gView->pSprite->cstat; if (gViewPos == 0) diff --git a/source/games/blood/src/common_game.h b/source/games/blood/src/common_game.h index 4f24551e8..a313364e7 100644 --- a/source/games/blood/src/common_game.h +++ b/source/games/blood/src/common_game.h @@ -527,26 +527,6 @@ inline int ClipRange(int a, int b, int c) return a; } -inline int interpolate(int a, int b, int c) -{ - return a+MulScale(b-a,c, 16); -} - -inline double finterpolate(double a, double b, double c) -{ - return a+MulScaleF(b-a,c, 16); -} - -inline int interpolateang(int a, int b, int c) -{ - return a+MulScale(((b-a+1024)&2047)-1024, c, 16); -} - -inline fixed_t interpolateangfix16(fixed_t a, fixed_t b, int c) -{ - return a+MulScale(((b-a+0x4000000)&0x7ffffff)-0x4000000, c, 16); -} - inline char Chance(int a1) { return wrand() < (a1>>1); diff --git a/source/games/blood/src/player.cpp b/source/games/blood/src/player.cpp index 344c95a62..7161e3916 100644 --- a/source/games/blood/src/player.cpp +++ b/source/games/blood/src/player.cpp @@ -1640,14 +1640,14 @@ void playerProcess(PLAYER *pPlayer) } ProcessInput(pPlayer); int nSpeed = approxDist(xvel[nSprite], yvel[nSprite]); - pPlayer->zViewVel = interpolate(pPlayer->zViewVel, zvel[nSprite], 0x7000); + pPlayer->zViewVel = interpolatedvalue(pPlayer->zViewVel, zvel[nSprite], 0x7000); int dz = pPlayer->pSprite->z-pPosture->eyeAboveZ-pPlayer->zView; if (dz > 0) pPlayer->zViewVel += MulScale(dz<<8, 0xa000, 16); else pPlayer->zViewVel += MulScale(dz<<8, 0x1800, 16); pPlayer->zView += pPlayer->zViewVel>>8; - pPlayer->zWeaponVel = interpolate(pPlayer->zWeaponVel, zvel[nSprite], 0x5000); + pPlayer->zWeaponVel = interpolatedvalue(pPlayer->zWeaponVel, zvel[nSprite], 0x5000); dz = pPlayer->pSprite->z-pPosture->weaponAboveZ-pPlayer->zWeapon; if (dz > 0) pPlayer->zWeaponVel += MulScale(dz<<8, 0x8000, 16); diff --git a/source/games/blood/src/prediction.cpp b/source/games/blood/src/prediction.cpp index 0fa230906..8ace16d42 100644 --- a/source/games/blood/src/prediction.cpp +++ b/source/games/blood/src/prediction.cpp @@ -250,12 +250,12 @@ static void fakeProcessInput(PLAYER *pPlayer, InputPacket *pInput) if (nSector2 == nSector) { int z2 = getflorzofslope(nSector2, x2, y2); - predict.horizoff = q16horiz(interpolate(predict.horizoff.asq16(), IntToFixed(z1 - z2) >> 3, 0x4000)); + predict.horizoff = q16horiz(interpolatedvalue(predict.horizoff.asq16(), IntToFixed(z1 - z2) >> 3, 0x4000)); } } else { - predict.horizoff = q16horiz(interpolate(predict.horizoff.asq16(), 0, 0x4000)); + predict.horizoff = q16horiz(interpolatedvalue(predict.horizoff.asq16(), 0, 0x4000)); if (abs(predict.horizoff.asq16()) < 4) predict.horizoff = q16horiz(0); } @@ -289,7 +289,7 @@ void fakePlayerProcess(PLAYER *pPlayer, InputPacket *pInput) int nSpeed = approxDist(predict.xvel, predict.yvel); - predict.at3c = interpolate(predict.at3c, predict.zvel, 0x7000); + predict.at3c = interpolatedvalue(predict.at3c, predict.zvel, 0x7000); int dz = predict.z-pPosture->eyeAboveZ-predict.viewz; if (dz > 0) predict.at3c += MulScale(dz<<8, 0xa000, 16); @@ -297,7 +297,7 @@ void fakePlayerProcess(PLAYER *pPlayer, InputPacket *pInput) predict.at3c += MulScale(dz<<8, 0x1800, 16); predict.viewz += predict.at3c>>8; - predict.at44 = interpolate(predict.at44, predict.zvel, 0x5000); + predict.at44 = interpolatedvalue(predict.at44, predict.zvel, 0x5000); dz = predict.z-pPosture->weaponAboveZ-predict.at40; if (dz > 0) predict.at44 += MulScale(dz<<8, 0x8000, 16); diff --git a/source/games/blood/src/triggers.cpp b/source/games/blood/src/triggers.cpp index 5320726f6..d8ff64923 100644 --- a/source/games/blood/src/triggers.cpp +++ b/source/games/blood/src/triggers.cpp @@ -839,14 +839,14 @@ void TranslateSector(int nSector, int a2, int a3, int a4, int a5, int a6, int a7 int x, y; int nXSector = sector[nSector].extra; XSECTOR *pXSector = &xsector[nXSector]; - int v20 = interpolate(a6, a9, a2); - int vc = interpolate(a6, a9, a3); + int v20 = interpolatedvalue(a6, a9, a2); + int vc = interpolatedvalue(a6, a9, a3); int v28 = vc - v20; - int v24 = interpolate(a7, a10, a2); - int v8 = interpolate(a7, a10, a3); + int v24 = interpolatedvalue(a7, a10, a2); + int v8 = interpolatedvalue(a7, a10, a3); int v2c = v8 - v24; - int v44 = interpolate(a8, a11, a2); - int vbp = interpolate(a8, a11, a3); + int v44 = interpolatedvalue(a8, a11, a2); + int vbp = interpolatedvalue(a8, a11, a3); int v14 = vbp - v44; int nWall = sector[nSector].wallptr; if (a12) diff --git a/source/games/blood/src/view.cpp b/source/games/blood/src/view.cpp index 3f0f8950a..bb41ece4e 100644 --- a/source/games/blood/src/view.cpp +++ b/source/games/blood/src/view.cpp @@ -450,8 +450,8 @@ static void DrawMap(spritetype* pSprite) tm = 1; } VIEW* pView = &gPrevView[gViewIndex]; - int x = interpolate(pView->x, pSprite->x, gInterpolate); - int y = interpolate(pView->y, pSprite->y, gInterpolate); + int x = interpolatedvalue(pView->x, pSprite->x, gInterpolate); + int y = interpolatedvalue(pView->y, pSprite->y, gInterpolate); int ang = (!SyncInput() ? gView->angle.sum() : gView->angle.interpolatedsum(gInterpolate)).asbuild(); DrawOverheadMap(x, y, ang, gInterpolate); if (tm) @@ -466,14 +466,14 @@ void SetupView(int &cX, int& cY, int& cZ, binangle& cA, fixedhoriz& cH, int& nSe if (numplayers > 1 && gView == gMe && gPrediction && gMe->pXSprite->health > 0) { nSectnum = predict.sectnum; - cX = interpolate(predictOld.x, predict.x, gInterpolate); - cY = interpolate(predictOld.y, predict.y, gInterpolate); - cZ = interpolate(predictOld.viewz, predict.viewz, gInterpolate); - zDelta = finterpolate(predictOld.weaponZ, predict.weaponZ, gInterpolate); - bobWidth = interpolate(predictOld.bobWidth, predict.bobWidth, gInterpolate); - bobHeight = interpolate(predictOld.bobHeight, predict.bobHeight, gInterpolate); - shakeX = finterpolate(predictOld.shakeBobX, predict.shakeBobX, gInterpolate); - shakeY = finterpolate(predictOld.shakeBobY, predict.shakeBobY, gInterpolate); + cX = interpolatedvalue(predictOld.x, predict.x, gInterpolate); + cY = interpolatedvalue(predictOld.y, predict.y, gInterpolate); + cZ = interpolatedvalue(predictOld.viewz, predict.viewz, gInterpolate); + zDelta = interpolatedvaluef(predictOld.weaponZ, predict.weaponZ, gInterpolate); + bobWidth = interpolatedvalue(predictOld.bobWidth, predict.bobWidth, gInterpolate); + bobHeight = interpolatedvalue(predictOld.bobHeight, predict.bobHeight, gInterpolate); + shakeX = interpolatedvaluef(predictOld.shakeBobX, predict.shakeBobX, gInterpolate); + shakeY = interpolatedvaluef(predictOld.shakeBobY, predict.shakeBobY, gInterpolate); if (!SyncInput()) { @@ -485,26 +485,26 @@ void SetupView(int &cX, int& cY, int& cZ, binangle& cA, fixedhoriz& cH, int& nSe { auto oang = predictOld.angle + predictOld.look_ang; auto ang = predict.angle + predict.look_ang; - cA = interpolatedbamang(oang, ang, gInterpolate); + cA = interpolatedangle(oang, ang, gInterpolate); fixed_t ohoriz = (predictOld.horiz + predictOld.horizoff).asq16(); fixed_t horiz = (predict.horiz + predict.horizoff).asq16(); - cH = q16horiz(interpolate(ohoriz, horiz, gInterpolate)); + cH = q16horiz(interpolatedvalue(ohoriz, horiz, gInterpolate)); - rotscrnang = interpolatedbamang(predictOld.rotscrnang, predict.rotscrnang, gInterpolate); + rotscrnang = interpolatedangle(predictOld.rotscrnang, predict.rotscrnang, gInterpolate); } } else { VIEW* pView = &gPrevView[gViewIndex]; - cX = interpolate(pView->x, gView->pSprite->x, gInterpolate); - cY = interpolate(pView->y, gView->pSprite->y, gInterpolate); - cZ = interpolate(pView->viewz, gView->zView, gInterpolate); - zDelta = finterpolate(pView->weaponZ, gView->zWeapon - gView->zView - (12 << 8), gInterpolate); - bobWidth = interpolate(pView->bobWidth, gView->bobWidth, gInterpolate); - bobHeight = interpolate(pView->bobHeight, gView->bobHeight, gInterpolate); - shakeX = finterpolate(pView->shakeBobX, gView->swayWidth, gInterpolate); - shakeY = finterpolate(pView->shakeBobY, gView->swayHeight, gInterpolate); + cX = interpolatedvalue(pView->x, gView->pSprite->x, gInterpolate); + cY = interpolatedvalue(pView->y, gView->pSprite->y, gInterpolate); + cZ = interpolatedvalue(pView->viewz, gView->zView, gInterpolate); + zDelta = interpolatedvaluef(pView->weaponZ, gView->zWeapon - gView->zView - (12 << 8), gInterpolate); + bobWidth = interpolatedvalue(pView->bobWidth, gView->bobWidth, gInterpolate); + bobHeight = interpolatedvalue(pView->bobHeight, gView->bobHeight, gInterpolate); + shakeX = interpolatedvaluef(pView->shakeBobX, gView->swayWidth, gInterpolate); + shakeY = interpolatedvaluef(pView->shakeBobY, gView->swayHeight, gInterpolate); if (!SyncInput()) { @@ -688,7 +688,7 @@ void viewDrawScreen(bool sceneonly) binangle rotscrnang; SetupView(cX, cY, cZ, cA, cH, nSectnum, zDelta, shakeX, shakeY, rotscrnang); - int tilt = interpolateang(gScreenTiltO, gScreenTilt, gInterpolate); + int tilt = interpolatedangle(gScreenTiltO, gScreenTilt, gInterpolate); uint8_t v14 = 0; uint8_t v10 = 0; bool bDelirium = powerupCheck(gView, kPwUpDeliriumShroom) > 0; @@ -745,7 +745,7 @@ void viewDrawScreen(bool sceneonly) } } g_visibility = (int32_t)(ClipLow(gVisibility - 32 * gView->visibility - brightness, 0)); - cA += q16ang(interpolateangfix16(IntToFixed(deliriumTurnO), IntToFixed(deliriumTurn), gInterpolate)); + cA += interpolatedangle(buildang(deliriumTurnO), buildang(deliriumTurn), gInterpolate); int ceilingZ, floorZ; getzsofslope(nSectnum, cX, cY, &ceilingZ, &floorZ); @@ -773,7 +773,7 @@ void viewDrawScreen(bool sceneonly) if (testnewrenderer) { - fixedhoriz deliriumPitchI = q16horiz(interpolate(IntToFixed(deliriumPitchO), IntToFixed(deliriumPitch), gInterpolate)); + fixedhoriz deliriumPitchI = q16horiz(interpolatedvalue(IntToFixed(deliriumPitchO), IntToFixed(deliriumPitch), gInterpolate)); int bakCstat = gView->pSprite->cstat; gView->pSprite->cstat |= (gViewPos == 0) ? CSTAT_SPRITE_INVISIBLE : CSTAT_SPRITE_TRANSLUCENT | CSTAT_SPRITE_TRANSLUCENT_INVERT; render_drawrooms(gView->pSprite, { cX, cY, cZ }, nSectnum, cA, cH + deliriumPitchI, rotscrnang); diff --git a/source/games/blood/src/weapon.cpp b/source/games/blood/src/weapon.cpp index 130074dd5..eb7918260 100644 --- a/source/games/blood/src/weapon.cpp +++ b/source/games/blood/src/weapon.cpp @@ -466,9 +466,9 @@ void UpdateAimVector(PLAYER * pPlayer) aim2 = aim; RotateVector((int*)&aim2.dx, (int*)&aim2.dy, -pPSprite->ang); aim2.dz -= pPlayer->slope; - pPlayer->relAim.dx = interpolate(pPlayer->relAim.dx, aim2.dx, pWeaponTrack->aimSpeedHorz); - pPlayer->relAim.dy = interpolate(pPlayer->relAim.dy, aim2.dy, pWeaponTrack->aimSpeedHorz); - pPlayer->relAim.dz = interpolate(pPlayer->relAim.dz, aim2.dz, pWeaponTrack->aimSpeedVert); + pPlayer->relAim.dx = interpolatedvalue(pPlayer->relAim.dx, aim2.dx, pWeaponTrack->aimSpeedHorz); + pPlayer->relAim.dy = interpolatedvalue(pPlayer->relAim.dy, aim2.dy, pWeaponTrack->aimSpeedHorz); + pPlayer->relAim.dz = interpolatedvalue(pPlayer->relAim.dz, aim2.dz, pWeaponTrack->aimSpeedVert); pPlayer->aim = pPlayer->relAim; RotateVector((int*)&pPlayer->aim.dx, (int*)&pPlayer->aim.dy, pPSprite->ang); pPlayer->aim.dz += pPlayer->slope; diff --git a/source/games/duke/src/animatesprites_d.cpp b/source/games/duke/src/animatesprites_d.cpp index ed7823f80..ec371975e 100644 --- a/source/games/duke/src/animatesprites_d.cpp +++ b/source/games/duke/src/animatesprites_d.cpp @@ -177,7 +177,7 @@ void animatesprites_d(spritetype* tsprite, int& spritesortcnt, int x, int y, int { t->x -= MulScale(MaxSmoothRatio - smoothratio, ps[s->yvel].posx - ps[s->yvel].oposx, 16); t->y -= MulScale(MaxSmoothRatio - smoothratio, ps[s->yvel].posy - ps[s->yvel].oposy, 16); - t->z = ps[s->yvel].oposz + MulScale(smoothratio, ps[s->yvel].posz - ps[s->yvel].oposz, 16); + t->z = interpolatedvalue(ps[s->yvel].oposz, ps[s->yvel].posz, smoothratio); t->z += (40 << 8); } else if (s->picnum != CRANEPOLE) @@ -328,10 +328,10 @@ void animatesprites_d(spritetype* tsprite, int& spritesortcnt, int x, int y, int t->cstat |= 2; if (screenpeek == myconnectindex && numplayers >= 2) { - t->x = omyx + MulScale((int)(myx - omyx), smoothratio, 16); - t->y = omyy + MulScale((int)(myy - omyy), smoothratio, 16); - t->z = omyz + MulScale((int)(myz - omyz), smoothratio, 16) + (40 << 8); - t->ang = myang.asbuild() + MulScale((((myang.asbuild() + 1024 - myang.asbuild()) & 2047) - 1024), smoothratio, 16); + t->x = interpolatedvalue(omyx, myx, smoothratio); + t->y = interpolatedvalue(omyy, myy, smoothratio); + t->z = interpolatedvalue(omyz, myz, smoothratio) + (40 << 8); + t->ang = interpolatedangle(omyang, myang, smoothratio).asbuild(); t->sectnum = mycursectnum; } } diff --git a/source/games/duke/src/animatesprites_r.cpp b/source/games/duke/src/animatesprites_r.cpp index cd502219b..ebbdae136 100644 --- a/source/games/duke/src/animatesprites_r.cpp +++ b/source/games/duke/src/animatesprites_r.cpp @@ -163,7 +163,7 @@ void animatesprites_r(spritetype* tsprite, int& spritesortcnt, int x, int y, int { t->x -= MulScale(MaxSmoothRatio - smoothratio, ps[s->yvel].posx - ps[s->yvel].oposx, 16); t->y -= MulScale(MaxSmoothRatio - smoothratio, ps[s->yvel].posy - ps[s->yvel].oposy, 16); - t->z = ps[s->yvel].oposz + MulScale(smoothratio, ps[s->yvel].posz - ps[s->yvel].oposz, 16); + t->z = interpolatedvalue(ps[s->yvel].oposz, ps[s->yvel].posz, smoothratio); t->z += (40 << 8); s->xrepeat = 24; s->yrepeat = 17; @@ -374,10 +374,10 @@ void animatesprites_r(spritetype* tsprite, int& spritesortcnt, int x, int y, int t->cstat |= 2; if (screenpeek == myconnectindex && numplayers >= 2) { - t->x = omyx + MulScale((int)(myx - omyx), smoothratio, 16); - t->y = omyy + MulScale((int)(myy - omyy), smoothratio, 16); - t->z = omyz + MulScale((int)(myz - omyz), smoothratio, 16) + (40 << 8); - t->ang = omyang.asbuild() + MulScale((((myang.asbuild() + 1024 - omyang.asbuild()) & 2047) - 1024), smoothratio, 16); + t->x = interpolatedvalue(omyx, myx, smoothratio); + t->y = interpolatedvalue(omyy, myy, smoothratio); + t->z = interpolatedvalue(omyz, myz, smoothratio) + (40 << 8); + t->ang = interpolatedangle(omyang, myang, smoothratio).asbuild(); t->sectnum = mycursectnum; } } diff --git a/source/games/duke/src/game_misc.cpp b/source/games/duke/src/game_misc.cpp index f1a3cc1fd..48f1c093f 100644 --- a/source/games/duke/src/game_misc.cpp +++ b/source/games/duke/src/game_misc.cpp @@ -266,15 +266,15 @@ void drawoverlays(double smoothratio) { if (screenpeek == myconnectindex && numplayers > 1) { - cposx = omyx + MulScale(myx - omyx, smoothratio, 16); - cposy = omyy + MulScale(myy - omyy, smoothratio, 16); - cang = !SyncInput() ? myang.asbuild() : omyang.asbuild() + MulScale(((myang.asbuild() + 1024 - omyang.asbuild()) & 2047) - 1024, smoothratio, 16); + cposx = interpolatedvalue(omyx, myx, smoothratio); + cposy = interpolatedvalue(omyy, myy, smoothratio); + cang = (!SyncInput() ? myang : interpolatedangle(omyang, myang, smoothratio)).asbuild(); } else { - cposx = pp->oposx + MulScale(pp->posx - pp->oposx, smoothratio, 16); - cposy = pp->oposy + MulScale(pp->posy - pp->oposy, smoothratio, 16); - cang = !SyncInput() ? pp->angle.ang.asbuild() : pp->angle.oang.asbuild() + MulScale(((pp->angle.ang.asbuild() + 1024 - pp->angle.oang.asbuild()) & 2047) - 1024, smoothratio, 16); + cposx = interpolatedvalue(pp->oposx, pp->posx, smoothratio); + cposy = interpolatedvalue(pp->oposy, pp->posy, smoothratio); + cang = (!SyncInput() ? pp->angle.ang : interpolatedangle(pp->angle.oang, pp->angle.ang, smoothratio)).asbuild(); } } else diff --git a/source/games/duke/src/hudweapon_d.cpp b/source/games/duke/src/hudweapon_d.cpp index ba6e3e0a8..360032b9f 100644 --- a/source/games/duke/src/hudweapon_d.cpp +++ b/source/games/duke/src/hudweapon_d.cpp @@ -284,10 +284,10 @@ void displayweapon_d(int snum, double smoothratio) horiz16th = get16thOfHoriz(snum, SyncInput(), smoothratio); look_anghalf = p->angle.look_anghalf(smoothratio); looking_arc = fabs(look_anghalf) / 4.5; - weapon_sway = p->oweapon_sway + MulScaleF(p->weapon_sway - p->oweapon_sway, smoothratio, 16); - kickback_pic = p->okickback_pic + MulScaleF(*kb - p->okickback_pic, smoothratio, 16); - random_club_frame = p->orandom_club_frame + MulScaleF(p->random_club_frame - p->orandom_club_frame, smoothratio, 16); - hard_landing = p->ohard_landing + MulScaleF(p->hard_landing - p->ohard_landing, smoothratio, 16); + weapon_sway = interpolatedvaluef(p->oweapon_sway, p->weapon_sway, smoothratio); + kickback_pic = interpolatedvaluef(p->okickback_pic, p->kickback_pic, smoothratio); + random_club_frame = interpolatedvaluef(p->orandom_club_frame, p->random_club_frame, smoothratio); + hard_landing = interpolatedvaluef(p->ohard_landing, p->hard_landing, smoothratio); shade = p->GetActor()->s.shade; if(shade > 24) shade = 24; @@ -301,9 +301,7 @@ void displayweapon_d(int snum, double smoothratio) animateknee(shade,snum,hard_landing,look_anghalf,horiz16th); - int opos = p->oweapon_pos * p->oweapon_pos; - int npos = p->weapon_pos * p->weapon_pos; - gun_pos = 80 - (opos + MulScaleF(npos - opos, smoothratio, 16)); + gun_pos = 80 - interpolatedvaluef(p->oweapon_pos * p->oweapon_pos, p->weapon_pos * p->weapon_pos, smoothratio); weapon_xoffset = (160)-90; weapon_xoffset -= bcosf(weapon_sway * 0.5) * (1. / 1536.); diff --git a/source/games/duke/src/hudweapon_r.cpp b/source/games/duke/src/hudweapon_r.cpp index 346b2353e..4698ab3fa 100644 --- a/source/games/duke/src/hudweapon_r.cpp +++ b/source/games/duke/src/hudweapon_r.cpp @@ -127,8 +127,8 @@ void displayweapon_r(int snum, double smoothratio) look_anghalf = p->angle.look_anghalf(smoothratio); looking_arc = fabs(look_anghalf) / 4.5; - weapon_sway = p->oweapon_sway + MulScaleF((p->weapon_sway - p->oweapon_sway), smoothratio, 16); - TiltStatus = !SyncInput() ? p->TiltStatus : p->oTiltStatus + MulScaleF((p->TiltStatus - p->oTiltStatus), smoothratio, 16); + weapon_sway = interpolatedvaluef(p->oweapon_sway, p->weapon_sway, smoothratio); + TiltStatus = !SyncInput() ? p->TiltStatus : interpolatedvaluef(p->oTiltStatus, p->TiltStatus, smoothratio); if (shadedsector[p->cursectnum] == 1) shade = 16; @@ -139,9 +139,7 @@ void displayweapon_r(int snum, double smoothratio) if(p->newOwner != nullptr || ud.cameraactor != nullptr || p->over_shoulder_on > 0 || (p->GetActor()->s.pal != 1 && p->GetActor()->s.extra <= 0)) return; - int opos = p->oweapon_pos * p->oweapon_pos; - int npos = p->weapon_pos * p->weapon_pos; - gun_pos = 80 - (opos + MulScaleF(npos - opos, smoothratio, 16)); + gun_pos = 80 - interpolatedvaluef(p->oweapon_pos * p->oweapon_pos, p->weapon_pos * p->weapon_pos, smoothratio); weapon_xoffset = (160)-90; weapon_xoffset -= bcosf(weapon_sway * 0.5) * (1. / 1536.); @@ -150,7 +148,7 @@ void displayweapon_r(int snum, double smoothratio) gun_pos -= fabs(bsinf(weapon_sway * 4., -9)); else gun_pos -= fabs(bsinf(weapon_sway * 0.5, -10)); - gun_pos -= (p->ohard_landing + MulScaleF(p->hard_landing - p->ohard_landing, smoothratio, 16)) * 8.; + gun_pos -= interpolatedvaluef(p->ohard_landing, p->hard_landing, smoothratio) * 8.; if(p->last_weapon >= 0) cw = p->last_weapon; diff --git a/source/games/duke/src/render.cpp b/source/games/duke/src/render.cpp index 16843ba42..9f2aa11f4 100644 --- a/source/games/duke/src/render.cpp +++ b/source/games/duke/src/render.cpp @@ -297,7 +297,7 @@ void displayrooms(int snum, double smoothratio) if (s->yvel < 0) s->yvel = -100; else if (s->yvel > 199) s->yvel = 300; - cang = buildfang(ud.cameraactor->tempang + MulScaleF(((s->ang + 1024 - ud.cameraactor->tempang) & 2047) - 1024, smoothratio, 16)); + cang = buildang(interpolatedangle(ud.cameraactor->tempang, s->ang, smoothratio)); auto bh = buildhoriz(s->yvel); renderView(s, s->sectnum, s->x, s->y, s->z - (4 << 8), cang, bh, buildang(0), smoothratio); @@ -318,15 +318,13 @@ void displayrooms(int snum, double smoothratio) if ((snum == myconnectindex) && (numplayers > 1)) { - cposx = omyx + xs_CRoundToInt(MulScaleF(myx - omyx, smoothratio, 16)); - cposy = omyy + xs_CRoundToInt(MulScaleF(myy - omyy, smoothratio, 16)); - cposz = omyz + xs_CRoundToInt(MulScaleF(myz - omyz, smoothratio, 16)); + cposx = interpolatedvalue(omyx, myx, smoothratio); + cposy = interpolatedvalue(omyy, myy, smoothratio); + cposz = interpolatedvalue(omyz, myz, smoothratio); if (SyncInput()) { - fixed_t ohorz = (omyhoriz + omyhorizoff).asq16(); - fixed_t horz = (myhoriz + myhorizoff).asq16(); - choriz = q16horiz(ohorz + xs_CRoundToInt(MulScaleF(horz - ohorz, smoothratio, 16))); - cang = bamang(xs_CRoundToUInt(omyang.asbam() + MulScaleF((myang - omyang).asbam(), smoothratio, 16))); + choriz = q16horiz(interpolatedvalue((omyhoriz + omyhorizoff).asq16(), (myhoriz + myhorizoff).asq16(), smoothratio)); + cang = interpolatedangle(omyang, myang, smoothratio); } else { @@ -337,9 +335,9 @@ void displayrooms(int snum, double smoothratio) } else { - cposx = p->oposx + xs_CRoundToInt(MulScaleF(p->posx - p->oposx, smoothratio, 16)); - cposy = p->oposy + xs_CRoundToInt(MulScaleF(p->posy - p->oposy, smoothratio, 16)); - cposz = p->oposz + xs_CRoundToInt(MulScaleF(p->posz - p->oposz, smoothratio, 16)); + cposx = interpolatedvalue(p->oposx, p->posx, smoothratio); + cposy = interpolatedvalue(p->oposy, p->posy, smoothratio); + cposz = interpolatedvalue(p->oposz, p->posz, smoothratio);; if (SyncInput()) { // Original code for when the values are passed through the sync struct @@ -370,7 +368,7 @@ void displayrooms(int snum, double smoothratio) } else if (p->over_shoulder_on == 0) { - if (cl_viewbob) cposz += p->opyoff + xs_CRoundToInt(MulScaleF(p->pyoff - p->opyoff, smoothratio, 16)); + if (cl_viewbob) cposz += interpolatedvalue(p->opyoff, p->pyoff, smoothratio); viewer = &p->GetActor()->s; } else diff --git a/source/games/exhumed/src/gun.cpp b/source/games/exhumed/src/gun.cpp index 76320baeb..d01748a68 100644 --- a/source/games/exhumed/src/gun.cpp +++ b/source/games/exhumed/src/gun.cpp @@ -965,8 +965,8 @@ void DrawWeapons(double smooth) if (cl_weaponsway) { // CHECKME - not & 0x7FF? - double nBobAngle = obobangle + MulScaleF(((bobangle + 1024 - obobangle) & 2047) - 1024, smooth, 16); - double nVal = (ototalvel[nLocalPlayer] + MulScaleF(totalvel[nLocalPlayer] - ototalvel[nLocalPlayer], smooth, 16)) * 0.5; + double nBobAngle = interpolatedangle(buildang(obobangle), buildang(bobangle), smooth).asbuildf(); + double nVal = interpolatedvaluef(ototalvel[nLocalPlayer], totalvel[nLocalPlayer], smooth, 17); yOffset = MulScaleF(nVal, bsinf(fmod(nBobAngle, 1024.), -8), 9); if (var_34 == 1) diff --git a/source/games/exhumed/src/view.cpp b/source/games/exhumed/src/view.cpp index 685d76f2a..7eeefcc52 100644 --- a/source/games/exhumed/src/view.cpp +++ b/source/games/exhumed/src/view.cpp @@ -194,11 +194,6 @@ void ResetView() #endif } -static inline int interpolate16(int a, int b, int smooth) -{ - return a + MulScale(b - a, smooth, 16); -} - static TextOverlay subtitleOverlay; void DrawView(double smoothRatio, bool sceneonly) @@ -251,7 +246,7 @@ void DrawView(double smoothRatio, bool sceneonly) auto psp = &sprite[nPlayerSprite]; playerX = psp->interpolatedx(smoothRatio); playerY = psp->interpolatedy(smoothRatio); - playerZ = psp->interpolatedz(smoothRatio) + interpolate16(oeyelevel[nLocalPlayer], eyelevel[nLocalPlayer], smoothRatio); + playerZ = psp->interpolatedz(smoothRatio) + interpolatedvalue(oeyelevel[nLocalPlayer], eyelevel[nLocalPlayer], smoothRatio); nSector = nPlayerViewSect[nLocalPlayer]; updatesector(playerX, playerY, &nSector); diff --git a/source/games/exhumed/src/view.h b/source/games/exhumed/src/view.h index fbd54416d..255169453 100644 --- a/source/games/exhumed/src/view.h +++ b/source/games/exhumed/src/view.h @@ -43,10 +43,5 @@ extern int gFov; extern spritetype* mytsprite; extern int* myspritesortcnt; -static inline int angle_interpolate16(int a, int b, int smooth) -{ - return a + MulScale(((b+1024-a)&2047)-1024, smooth, 16); -} - END_PS_NS diff --git a/source/games/sw/src/_polymost.cpp b/source/games/sw/src/_polymost.cpp index 115f215cc..903fb96f2 100644 --- a/source/games/sw/src/_polymost.cpp +++ b/source/games/sw/src/_polymost.cpp @@ -218,9 +218,9 @@ void JS_DrawMirrors(PLAYERp pp, int tx, int ty, int tz, fixed_t tpq16ang, fixed mirrorinview = true; -// tx = pp->oposx + MulScale(pp->posx - pp->oposx, smoothratio, 16); -// ty = pp->oposy + MulScale(pp->posy - pp->oposy, smoothratio, 16); -// tz = pp->oposz + MulScale(pp->posz - pp->oposz, smoothratio, 16); +// tx = interpolatedvalue(pp->oposx, pp->posx, smoothratio); +// ty = interpolatedvalue(pp->oposy, pp->posy, smoothratio); +// tz = interpolatedvalue(pp->oposz, pp->posz, smoothratio); // tpq16ang = pp->angle.ang.asq16(); diff --git a/source/games/sw/src/draw.cpp b/source/games/sw/src/draw.cpp index 9516f4502..f62d7b4bc 100644 --- a/source/games/sw/src/draw.cpp +++ b/source/games/sw/src/draw.cpp @@ -1504,9 +1504,9 @@ drawscreen(PLAYERp pp, double smoothratio) else camerapp = pp; - tx = camerapp->oposx + xs_CRoundToInt(MulScaleF(camerapp->posx - camerapp->oposx, smoothratio, 16)); - ty = camerapp->oposy + xs_CRoundToInt(MulScaleF(camerapp->posy - camerapp->oposy, smoothratio, 16)); - tz = camerapp->oposz + xs_CRoundToInt(MulScaleF(camerapp->posz - camerapp->oposz, smoothratio, 16)); + tx = interpolatedvalue(camerapp->oposx, camerapp->posx, smoothratio); + ty = interpolatedvalue(camerapp->oposy, camerapp->posy, smoothratio); + tz = interpolatedvalue(camerapp->oposz, camerapp->posz, smoothratio); // Interpolate the player's angle while on a sector object, just like VoidSW. // This isn't needed for the turret as it was fixable, but moving sector objects are problematic. @@ -1595,7 +1595,7 @@ drawscreen(PLAYERp pp, double smoothratio) if (cl_viewbob) { tz += bob_amt; - tz += pp->obob_z + xs_CRoundToInt(MulScaleF(pp->bob_z - pp->obob_z, smoothratio, 16)); + tz += interpolatedvalue(pp->obob_z, pp->bob_z, smoothratio); } // recoil only when not in camera diff --git a/source/games/sw/src/panel.cpp b/source/games/sw/src/panel.cpp index bfa72e046..ceec9e530 100644 --- a/source/games/sw/src/panel.cpp +++ b/source/games/sw/src/panel.cpp @@ -6905,8 +6905,8 @@ pDisplaySprites(PLAYERp pp, double smoothratio) ang = psp->rotate_ang; shade = 0; flags = 0; - x = (psp->ox + MulScaleF(psp->x - psp->ox, smoothratio, 16)) - look_anghalf; - y = (psp->oy + MulScaleF(psp->y - psp->oy, smoothratio, 16)) + looking_arc; + x = interpolatedvaluef(psp->ox, psp->x, smoothratio) - look_anghalf; + y = interpolatedvaluef(psp->oy, psp->y, smoothratio) + looking_arc; // initilize pal here - jack with it below pal = psp->pal; From 656705bcd7cf155132c16502b177125ac7c913fb Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sun, 11 Apr 2021 17:02:44 +1000 Subject: [PATCH 3/6] - binangle: Add `signedrad()` and `signeddeg()` methods for consistency with the unsigned methods. * Left out from f254eeb4656fe4b00050e70bda08a4c81c8de496. --- source/core/binaryangle.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/core/binaryangle.h b/source/core/binaryangle.h index 73ec90911..dbb0fce8f 100644 --- a/source/core/binaryangle.h +++ b/source/core/binaryangle.h @@ -143,6 +143,8 @@ public: constexpr double signedbuildf() const { return tosigned() * (1. / BAMUNIT); } constexpr fixed_t signedq16() const { return tosigned() >> 5; } constexpr int32_t signedbam() const { return tosigned(); } + constexpr double signedrad() const { return tosigned() * (pi::pi() / 0x80000000u); } + constexpr double signeddeg() const { return AngleToFloat(tosigned()); } double fsin() const { return g_sin(asrad()); } double fcos() const { return g_cos(asrad()); } From 534271c62a9bfa3944939256a84f9ce35cedf538 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sun, 11 Apr 2021 17:50:32 +1000 Subject: [PATCH 4/6] - PlayerHorizon::interpolatedsum(): Cut over interpolation code to inline functions that was missed when doing e76f63e2c0d32af278104e391e8d2df119598e2a. --- source/core/gameinput.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/source/core/gameinput.h b/source/core/gameinput.h index 047f027e0..a3dcd0295 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -91,10 +91,7 @@ struct PlayerHorizon fixedhoriz interpolatedsum(double const smoothratio) { - double const ratio = smoothratio * (1. / FRACUNIT); - fixed_t const prev = osum().asq16(); - fixed_t const curr = sum().asq16(); - return q16horiz(prev + xs_CRoundToInt(ratio * (curr - prev))); + return q16horiz(interpolatedvalue(osum().asq16(), sum().asq16(), smoothratio)); } private: From f343bd8d5e5ab963aec354c98785ece217cbd329 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sun, 11 Apr 2021 17:52:29 +1000 Subject: [PATCH 5/6] - Fix death camera issues stemming from f254eeb4656fe4b00050e70bda08a4c81c8de496. * Adjustment in `__addadjustment()` needs to be signed. * Output of `bvectangbam()` needs to be signed before Duke/SW left-shift the value. --- source/core/gameinput.h | 2 +- source/games/duke/src/actors.cpp | 4 ++-- source/games/sw/src/player.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/core/gameinput.h b/source/core/gameinput.h index a3dcd0295..3280a1351 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -234,7 +234,7 @@ private: { if (!SyncInput()) { - adjustment += value.asbuildf(); + adjustment += value.signedbuildf(); } else { diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index ccce5da8c..39f746b42 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -464,7 +464,7 @@ void moveplayers(void) if (p->actorsqu != nullptr) { - p->angle.addadjustment(getincanglebam(p->angle.ang, bvectangbam(p->actorsqu->s.x - p->posx, p->actorsqu->s.y - p->posy)) >> 2); + p->angle.addadjustment(getincanglebam(p->angle.ang, bvectangbam(p->actorsqu->s.x - p->posx, p->actorsqu->s.y - p->posy)).signedbuild() >> 2); } if (spri->extra > 0) @@ -487,7 +487,7 @@ void moveplayers(void) if (p->wackedbyactor != nullptr && p->wackedbyactor->s.statnum < MAXSTATUS) { - p->angle.addadjustment(getincanglebam(p->angle.ang, bvectangbam(p->wackedbyactor->s.x - p->posx, p->wackedbyactor->s.y - p->posy)) >> 1); + p->angle.addadjustment(getincanglebam(p->angle.ang, bvectangbam(p->wackedbyactor->s.x - p->posx, p->wackedbyactor->s.y - p->posy)).signedbuild() >> 1); } } spri->ang = p->angle.ang.asbuild(); diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 338f7a58d..1364eff32 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -6125,7 +6125,7 @@ void DoPlayerDeathFollowKiller(PLAYERp pp) if (FAFcansee(kp->x, kp->y, SPRITEp_TOS(kp), kp->sectnum, pp->posx, pp->posy, pp->posz, pp->cursectnum)) { - pp->angle.addadjustment(getincanglebam(pp->angle.ang, bvectangbam(kp->x - pp->posx, kp->y - pp->posy)) >> 4); + pp->angle.addadjustment(getincanglebam(pp->angle.ang, bvectangbam(kp->x - pp->posx, kp->y - pp->posy)).signedbuild() >> 4); } } } From e959226914b3e1243cbb52ebbe90c5f7e91f85c2 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sun, 11 Apr 2021 18:34:07 +1000 Subject: [PATCH 6/6] - Fix RRRA bike/boat angle adjustments following changes in f343bd8d5e5ab963aec354c98785ece217cbd329. * Because we're wrapping a negative number around to be unsigned, we need to do that after we've done our bit-shift operations. --- source/games/duke/src/player_r.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index e450255b3..2100376f9 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -1773,7 +1773,7 @@ static void onMotorcycle(int snum, ESyncBits &actions) if (p->MotoSpeed >= 20 && p->on_ground == 1 && (p->vehTurnLeft || p->vehTurnRight)) { velAdjustment = p->vehTurnLeft ? -10 : 10; - auto angAdjustment = buildang(velAdjustment < 0 ? 350 : -350); + auto angAdjustment = (velAdjustment < 0 ? 350 : -350) << BAMBITS; if (p->moto_on_mud || p->moto_on_oil || !p->NotOnWater) { @@ -1811,7 +1811,7 @@ static void onMotorcycle(int snum, ESyncBits &actions) p->posxv += currSpeed * bcos(velAdjustment * -51 + p->angle.ang.asbuild(), 4); p->posyv += currSpeed * bsin(velAdjustment * -51 + p->angle.ang.asbuild(), 4); - p->angle.addadjustment(getincanglebam(p->angle.ang, p->angle.ang - angAdjustment)); + p->angle.addadjustment(getincanglebam(p->angle.ang, p->angle.ang - bamang(angAdjustment))); } else if (p->MotoSpeed >= 20 && p->on_ground == 1 && (p->moto_on_mud || p->moto_on_oil)) { @@ -2040,7 +2040,7 @@ static void onBoat(int snum, ESyncBits &actions) { int currSpeed = p->MotoSpeed * 4.; short velAdjustment = p->vehTurnLeft ? -10 : 10; - auto angAdjustment = buildang(velAdjustment < 0 ? 350 : -350); + auto angAdjustment = (velAdjustment < 0 ? 350 : -350) << BAMBITS; if (p->moto_do_bump) { @@ -2055,7 +2055,7 @@ static void onBoat(int snum, ESyncBits &actions) p->posxv += currSpeed * bcos(velAdjustment * -51 + p->angle.ang.asbuild(), 4); p->posyv += currSpeed * bsin(velAdjustment * -51 + p->angle.ang.asbuild(), 4); - p->angle.addadjustment(getincanglebam(p->angle.ang, p->angle.ang - angAdjustment)); + p->angle.addadjustment(getincanglebam(p->angle.ang, p->angle.ang - bamang(angAdjustment))); } if (p->NotOnWater && p->MotoSpeed > 50) p->MotoSpeed -= (p->MotoSpeed / 2.);