From 8cf2588badb20a86732fa9d55b71f7ee5ca7bd45 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Mon, 4 Jan 2021 22:16:09 +1100 Subject: [PATCH] - Replace `fmulscale##()` calls with `MulScaleF()` from common. * Regex for reference: fmulscale([0-9]+)\((.+)(\)+) --- source/blood/src/common_game.h | 6 +++--- source/blood/src/prediction.cpp | 4 ++-- source/build/include/pragmas.h | 1 - source/common/utility/m_fixed.h | 1 + source/core/automap.cpp | 4 ++-- source/exhumed/src/gun.cpp | 8 ++++---- source/games/duke/src/hudweapon_d.cpp | 10 +++++----- source/games/duke/src/hudweapon_r.cpp | 8 ++++---- source/games/duke/src/render.cpp | 22 +++++++++++----------- source/sw/src/draw.cpp | 8 ++++---- source/sw/src/jweapon.cpp | 2 +- source/sw/src/panel.cpp | 4 ++-- source/sw/src/player.cpp | 8 ++++---- source/sw/src/weapon.cpp | 10 +++++----- 14 files changed, 48 insertions(+), 48 deletions(-) diff --git a/source/blood/src/common_game.h b/source/blood/src/common_game.h index 9c2aa76fb..b86801ca3 100644 --- a/source/blood/src/common_game.h +++ b/source/blood/src/common_game.h @@ -535,7 +535,7 @@ inline int interpolate(int a, int b, int c) inline double finterpolate(double a, double b, double c) { - return a+fmulscale16(b-a,c); + return a+MulScaleF(b-a,c, 16); } inline int interpolateang(int a, int b, int c) @@ -550,12 +550,12 @@ inline fixed_t interpolateangfix16(fixed_t a, fixed_t b, int c) inline binangle interpolateangbin(uint32_t a, uint32_t b, double c) { - return bamang(xs_CRoundToUInt(a + fmulscale16(b - a, 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 + fmulscale16(b - a, c))); + return bamlook(xs_CRoundToUInt(a + MulScaleF(b - a, c, 16))); } inline char Chance(int a1) diff --git a/source/blood/src/prediction.cpp b/source/blood/src/prediction.cpp index 0379319ee..8d965d1be 100644 --- a/source/blood/src/prediction.cpp +++ b/source/blood/src/prediction.cpp @@ -227,9 +227,9 @@ static void fakeProcessInput(PLAYER *pPlayer, InputPacket *pInput) predict.at20 = clamp(predict.at20+pInput->horz, IntToFixed(-60), IntToFixed(60)); if (predict.at20 > 0) - predict.at24 = FloatToFixed(fmulscale30(120., bsinf(FixedToFloat(predict.at20) * 8., 16))); + predict.at24 = FloatToFixed(MulScaleF(120., bsinf(FixedToFloat(predict.at20) * 8., 16)), 30); else if (predict.at20 < 0) - predict.at24 = FloatToFixed(fmulscale30(180., bsinf(FixedToFloat(predict.at20) * 8., 16))); + predict.at24 = FloatToFixed(MulScaleF(180., bsinf(FixedToFloat(predict.at20) * 8., 16)), 30); else predict.at24 = 0; #endif diff --git a/source/build/include/pragmas.h b/source/build/include/pragmas.h index 769c564c7..5cf813dbc 100644 --- a/source/build/include/pragmas.h +++ b/source/build/include/pragmas.h @@ -56,7 +56,6 @@ static inline int32_t scale(int32_t eax, int32_t edx, int32_t ecx) #define EDUKE32_SCALER_PRAGMA(a) \ static FORCE_INLINE int32_t mulscale##a(int32_t eax, int32_t edx) { return dw((qw(eax) * edx) >> by(a)); } \ - static FORCE_INLINE double fmulscale##a(double eax, double edx) { return (eax * edx) / (double)(qw(1) << a); } \ EDUKE32_GENERATE_PRAGMAS diff --git a/source/common/utility/m_fixed.h b/source/common/utility/m_fixed.h index 60abea9e9..a7f23b870 100644 --- a/source/common/utility/m_fixed.h +++ b/source/common/utility/m_fixed.h @@ -7,6 +7,7 @@ __forceinline constexpr int32_t MulScale(int32_t a, int32_t b, int32_t shift) { return (int32_t)(((int64_t)a * b) >> shift); } +__forceinline constexpr int32_t MulScaleF(double a, double b, int32_t shift) { return (a * b) * (1. / (uint32_t(1) << shift)); } __forceinline constexpr int32_t DMulScale(int32_t a, int32_t b, int32_t c, int32_t d, int32_t shift) { return (int32_t)(((int64_t)a * b + (int64_t)c * d) >> shift); } __forceinline constexpr int32_t TMulScale(int32_t a, int32_t b, int32_t c, int32_t d, int32_t e, int32_t f, int32_t shift) { return (int32_t)(((int64_t)a * b + (int64_t)c * d + (int64_t)e * f) >> shift); } __forceinline constexpr int32_t DivScale(int32_t a, int32_t b, int shift) { return (int32_t)(((int64_t)a << shift) / b); } diff --git a/source/core/automap.cpp b/source/core/automap.cpp index 269e36f91..d4e6e350d 100644 --- a/source/core/automap.cpp +++ b/source/core/automap.cpp @@ -216,9 +216,9 @@ void AutomapControl() double j = interval * 35. / gZoom; if (buttonMap.ButtonDown(gamefunc_Enlarge_Screen)) - gZoom += (int)fmulscale6(j, max(gZoom, 256)); + gZoom += (int)MulScaleF(j, max(gZoom, 256), 6); if (buttonMap.ButtonDown(gamefunc_Shrink_Screen)) - gZoom -= (int)fmulscale6(j, max(gZoom, 256)); + gZoom -= (int)MulScaleF(j, max(gZoom, 256), 6); gZoom = clamp(gZoom, 48, 2048); diff --git a/source/exhumed/src/gun.cpp b/source/exhumed/src/gun.cpp index 8701267bd..277a8db5b 100644 --- a/source/exhumed/src/gun.cpp +++ b/source/exhumed/src/gun.cpp @@ -967,13 +967,13 @@ void DrawWeapons(double smooth) if (cl_weaponsway) { // CHECKME - not & 0x7FF? - double nBobAngle = obobangle + fmulscale16(((bobangle + 1024 - obobangle) & 2047) - 1024, smooth); - double nVal = (ototalvel[nLocalPlayer] + fmulscale16(totalvel[nLocalPlayer] - ototalvel[nLocalPlayer], smooth)) * 0.5; - yOffset = fmulscale9(nVal, bsinf(fmod(nBobAngle, 1024.), -8)); + double nBobAngle = obobangle + MulScaleF(((bobangle + 1024 - obobangle) & 2047) - 1024, smooth, 16); + double nVal = (ototalvel[nLocalPlayer] + MulScaleF(totalvel[nLocalPlayer] - ototalvel[nLocalPlayer], smooth, 16)) * 0.5; + yOffset = MulScaleF(nVal, bsinf(fmod(nBobAngle, 1024.), -8), 9); if (var_34 == 1) { - xOffset = fmulscale8(bcosf(nBobAngle, -8), nVal); + xOffset = MulScaleF(bcosf(nBobAngle, -8), nVal, 8); } } else diff --git a/source/games/duke/src/hudweapon_d.cpp b/source/games/duke/src/hudweapon_d.cpp index eb8ce6e76..30a38ccdf 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 + fmulscale16(p->weapon_sway - p->oweapon_sway, smoothratio); - kickback_pic = p->okickback_pic + fmulscale16(*kb - p->okickback_pic, smoothratio); - random_club_frame = p->orandom_club_frame + fmulscale16(p->random_club_frame - p->orandom_club_frame, smoothratio); - hard_landing = p->ohard_landing + fmulscale16(p->hard_landing - p->ohard_landing, smoothratio); + 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); shade = p->GetActor()->s.shade; if(shade > 24) shade = 24; @@ -303,7 +303,7 @@ void displayweapon_d(int snum, double smoothratio) int opos = p->oweapon_pos * p->oweapon_pos; int npos = p->weapon_pos * p->weapon_pos; - gun_pos = 80 - (opos + fmulscale16(npos - opos, smoothratio)); + gun_pos = 80 - (opos + MulScaleF(npos - opos, smoothratio, 16)); 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 83fbdb73f..fe9694fd0 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 + fmulscale16((p->weapon_sway - p->oweapon_sway), smoothratio); - TiltStatus = !SyncInput() ? p->TiltStatus : p->oTiltStatus + fmulscale16((p->TiltStatus - p->oTiltStatus), smoothratio); + 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); if (shadedsector[p->cursectnum] == 1) shade = 16; @@ -141,7 +141,7 @@ void displayweapon_r(int snum, double smoothratio) int opos = p->oweapon_pos * p->oweapon_pos; int npos = p->weapon_pos * p->weapon_pos; - gun_pos = 80 - (opos + fmulscale16(npos - opos, smoothratio)); + gun_pos = 80 - (opos + MulScaleF(npos - opos, smoothratio, 16)); weapon_xoffset = (160)-90; weapon_xoffset -= bcosf(weapon_sway * 0.5) * (1. / 1536.); @@ -150,7 +150,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 + fmulscale16(p->hard_landing - p->ohard_landing, smoothratio)) * 8.; + gun_pos -= (p->ohard_landing + MulScaleF(p->hard_landing - p->ohard_landing, smoothratio, 16)) * 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 d5a4f2e34..a214cef06 100644 --- a/source/games/duke/src/render.cpp +++ b/source/games/duke/src/render.cpp @@ -261,7 +261,7 @@ void renderMirror(int cposx, int cposy, int cposz, binangle cang, fixedhoriz cho static inline binangle getcamspriteang(DDukeActor* newOwner, double const smoothratio) { - return buildfang(newOwner->tempang + fmulscale16(((newOwner->s.ang - newOwner->tempang + 1024) & 2047) - 1024, smoothratio)); + return buildfang(newOwner->tempang + MulScaleF(((newOwner->s.ang - newOwner->tempang + 1024) & 2047) - 1024, smoothratio, 16)); } //--------------------------------------------------------------------------- @@ -517,7 +517,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 + fmulscale16(((s->ang + 1024 - ud.cameraactor->tempang) & 2047) - 1024, smoothratio)); + cang = buildfang(ud.cameraactor->tempang + MulScaleF(((s->ang + 1024 - ud.cameraactor->tempang) & 2047) - 1024, smoothratio, 16)); auto bh = buildhoriz(s->yvel); se40code(s->x, s->y, s->z, cang, bh, smoothratio); @@ -542,15 +542,15 @@ void displayrooms(int snum, double smoothratio) if ((snum == myconnectindex) && (numplayers > 1)) { - cposx = omyx + xs_CRoundToInt(fmulscale16(myx - omyx, smoothratio)); - cposy = omyy + xs_CRoundToInt(fmulscale16(myy - omyy, smoothratio)); - cposz = omyz + xs_CRoundToInt(fmulscale16(myz - omyz, smoothratio)); + 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)); if (SyncInput()) { fixed_t ohorz = (omyhoriz + omyhorizoff).asq16(); fixed_t horz = (myhoriz + myhorizoff).asq16(); - choriz = q16horiz(ohorz + xs_CRoundToInt(fmulscale16(horz - ohorz, smoothratio))); - cang = bamang(xs_CRoundToUInt(omyang.asbam() + fmulscale16((myang - omyang).asbam(), smoothratio))); + choriz = q16horiz(ohorz + xs_CRoundToInt(MulScaleF(horz - ohorz, smoothratio, 16))); + cang = bamang(xs_CRoundToUInt(omyang.asbam() + MulScaleF((myang - omyang).asbam(), smoothratio, 16))); } else { @@ -561,9 +561,9 @@ void displayrooms(int snum, double smoothratio) } else { - cposx = p->oposx + xs_CRoundToInt(fmulscale16(p->posx - p->oposx, smoothratio)); - cposy = p->oposy + xs_CRoundToInt(fmulscale16(p->posy - p->oposy, smoothratio)); - cposz = p->oposz + xs_CRoundToInt(fmulscale16(p->posz - p->oposz, smoothratio)); + 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)); if (SyncInput()) { // Original code for when the values are passed through the sync struct @@ -592,7 +592,7 @@ void displayrooms(int snum, double smoothratio) } else if (p->over_shoulder_on == 0) { - if (cl_viewbob) cposz += p->opyoff + xs_CRoundToInt(fmulscale16(p->pyoff - p->opyoff, smoothratio)); + if (cl_viewbob) cposz += p->opyoff + xs_CRoundToInt(MulScaleF(p->pyoff - p->opyoff, smoothratio, 16)); } else { diff --git a/source/sw/src/draw.cpp b/source/sw/src/draw.cpp index 644a8136c..648b0bc70 100644 --- a/source/sw/src/draw.cpp +++ b/source/sw/src/draw.cpp @@ -1641,9 +1641,9 @@ drawscreen(PLAYERp pp, double smoothratio) else camerapp = pp; - tx = camerapp->oposx + xs_CRoundToInt(fmulscale16(camerapp->posx - camerapp->oposx, smoothratio)); - ty = camerapp->oposy + xs_CRoundToInt(fmulscale16(camerapp->posy - camerapp->oposy, smoothratio)); - tz = camerapp->oposz + xs_CRoundToInt(fmulscale16(camerapp->posz - camerapp->oposz, smoothratio)); + 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)); // 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. @@ -1734,7 +1734,7 @@ drawscreen(PLAYERp pp, double smoothratio) if (cl_viewbob) { tz += bob_amt; - tz += pp->obob_z + xs_CRoundToInt(fmulscale16(pp->bob_z - pp->obob_z, smoothratio)); + tz += pp->obob_z + xs_CRoundToInt(MulScaleF(pp->bob_z - pp->obob_z, smoothratio, 16)); } // recoil only when not in camera diff --git a/source/sw/src/jweapon.cpp b/source/sw/src/jweapon.cpp index 2aabc7abf..ec77a3fb9 100644 --- a/source/sw/src/jweapon.cpp +++ b/source/sw/src/jweapon.cpp @@ -2500,7 +2500,7 @@ InitShell(int16_t SpriteNum, int16_t ShellNum) if (u->PlayerP) { - wp->z += xs_CRoundToInt(-fmulscale16(u->PlayerP->horizon.horiz.asq16(), HORIZ_MULT / 3.)); + wp->z += xs_CRoundToInt(-MulScaleF(u->PlayerP->horizon.horiz.asq16(), HORIZ_MULT / 3., 16)); } switch (wu->ID) diff --git a/source/sw/src/panel.cpp b/source/sw/src/panel.cpp index 2d32cec4a..e94ba627b 100644 --- a/source/sw/src/panel.cpp +++ b/source/sw/src/panel.cpp @@ -6937,8 +6937,8 @@ pDisplaySprites(PLAYERp pp, double smoothratio) ang = psp->rotate_ang; shade = 0; flags = 0; - x = (psp->ox + fmulscale16(psp->x - psp->ox, smoothratio)) - look_anghalf; - y = (psp->oy + fmulscale16(psp->y - psp->oy, smoothratio)) + looking_arc; + x = (psp->ox + MulScaleF(psp->x - psp->ox, smoothratio, 16)) - look_anghalf; + y = (psp->oy + MulScaleF(psp->y - psp->oy, smoothratio, 16)) + looking_arc; // initilize pal here - jack with it below pal = psp->pal; diff --git a/source/sw/src/player.cpp b/source/sw/src/player.cpp index b119ab20f..50b83594f 100644 --- a/source/sw/src/player.cpp +++ b/source/sw/src/player.cpp @@ -1529,7 +1529,7 @@ DoPlayerTurnBoat(PLAYERp pp, float avel) if (sop->drive_angspeed) { float drive_oavel = pp->drive_avel; - pp->drive_avel = (fmulscale16(avel, sop->drive_angspeed) + (drive_oavel * (sop->drive_angslide - 1))) / sop->drive_angslide; + pp->drive_avel = (MulScaleF(avel, sop->drive_angspeed) + (drive_oavel * (sop->drive_angslide - 1)), 16) / sop->drive_angslide; avel = pp->drive_avel; } @@ -1554,7 +1554,7 @@ DoPlayerTurnVehicle(PLAYERp pp, float avel, int z, int floor_dist) if (sop->drive_angspeed) { float drive_oavel = pp->drive_avel; - pp->drive_avel = (fmulscale16(avel, sop->drive_angspeed) + (drive_oavel * (sop->drive_angslide - 1))) / sop->drive_angslide; + pp->drive_avel = (MulScaleF(avel, sop->drive_angspeed, 16) + (drive_oavel * (sop->drive_angslide - 1))) / sop->drive_angslide; avel = pp->drive_avel; } @@ -1583,7 +1583,7 @@ DoPlayerTurnVehicleRect(PLAYERp pp, int *x, int *y, int *ox, int *oy) if (sop->drive_angspeed) { float drive_oavel = pp->drive_avel; - pp->drive_avel = (fmulscale16(pp->input.avel, sop->drive_angspeed) + (drive_oavel * (sop->drive_angslide - 1))) / sop->drive_angslide; + pp->drive_avel = (MulScaleF(pp->input.avel, sop->drive_angspeed, 16) + (drive_oavel * (sop->drive_angslide - 1))) / sop->drive_angslide; avel = pp->drive_avel; } @@ -1613,7 +1613,7 @@ DoPlayerTurnTurret(PLAYERp pp, float avel) if (sop->drive_angspeed) { float drive_oavel = pp->drive_avel; - pp->drive_avel = (fmulscale16(avel, sop->drive_angspeed) + (drive_oavel * (sop->drive_angslide - 1))) / sop->drive_angslide; + pp->drive_avel = (MulScaleF(avel, sop->drive_angspeed, 16) + (drive_oavel * (sop->drive_angslide - 1))) / sop->drive_angslide; avel = pp->drive_avel; } diff --git a/source/sw/src/weapon.cpp b/source/sw/src/weapon.cpp index cd99e0c93..13232dbfb 100644 --- a/source/sw/src/weapon.cpp +++ b/source/sw/src/weapon.cpp @@ -17485,7 +17485,7 @@ InitTracerUzi(PLAYERp pp) return 0; } - wp->zvel = xs_CRoundToInt(-fmulscale16(pp->horizon.horiz.asq16(), wp->xvel / 8.)); + wp->zvel = xs_CRoundToInt(-MulScaleF(pp->horizon.horiz.asq16(), wp->xvel / 8., 16)); pp->SpriteP->clipdist = oclipdist; @@ -17544,7 +17544,7 @@ InitTracerTurret(short SpriteNum, short Operator, fixed_t q16horiz) SET(wp->cstat, CSTAT_SPRITE_YCENTER); SET(wp->cstat, CSTAT_SPRITE_INVISIBLE); - wp->zvel = xs_CRoundToInt(-fmulscale16(q16horiz, wp->xvel / 8.)); + wp->zvel = xs_CRoundToInt(-MulScaleF(q16horiz, wp->xvel / 8., 16)); WeaponAutoAim(sp, w, 32, false); @@ -18195,7 +18195,7 @@ InitTankShell(short SpriteNum, PLAYERp pp) SET(wp->cstat, CSTAT_SPRITE_YCENTER); SET(wp->cstat, CSTAT_SPRITE_INVISIBLE); - wp->zvel = xs_CRoundToInt(-fmulscale16(pp->horizon.horiz.asq16(), wp->xvel / 8.)); + wp->zvel = xs_CRoundToInt(-MulScaleF(pp->horizon.horiz.asq16(), wp->xvel / 8., 16)); WeaponAutoAim(sp, w, 64, false); // a bit of randomness @@ -18355,7 +18355,7 @@ InitTurretRocket(short SpriteNum, PLAYERp pp) SET(wu->Flags2, SPR2_SO_MISSILE); SET(wp->cstat, CSTAT_SPRITE_YCENTER); - wp->zvel = xs_CRoundToInt(-fmulscale16(pp->horizon.horiz.asq16(), wp->xvel / 8.)); + wp->zvel = xs_CRoundToInt(-MulScaleF(pp->horizon.horiz.asq16(), wp->xvel / 8., 16)); WeaponAutoAim(sp, w, 64, false); // a bit of randomness @@ -18402,7 +18402,7 @@ InitTurretFireball(short SpriteNum, PLAYERp pp) SET(wu->Flags2, SPR2_SO_MISSILE); SET(wp->cstat, CSTAT_SPRITE_YCENTER); - wp->zvel = xs_CRoundToInt(-fmulscale16(pp->horizon.horiz.asq16(), wp->xvel / 8.)); + wp->zvel = xs_CRoundToInt(-MulScaleF(pp->horizon.horiz.asq16(), wp->xvel / 8., 16)); WeaponAutoAim(sp, w, 64, false); // a bit of randomness