From b9c2af130aa791ebfb9744c9056df5a5352eea93 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Mon, 4 Jan 2021 22:59:00 +1100 Subject: [PATCH] - Replace `divscale()` calls with `DivScale()` from common. --- source/blood/src/actor.cpp | 6 +++--- source/blood/src/aibeast.cpp | 2 +- source/blood/src/aicaleb.cpp | 2 +- source/blood/src/aicerber.cpp | 8 ++++---- source/blood/src/aicult.cpp | 2 +- source/blood/src/aigarg.cpp | 16 ++++++++-------- source/blood/src/aighost.cpp | 16 ++++++++-------- source/blood/src/aigilbst.cpp | 2 +- source/blood/src/aitchern.cpp | 8 ++++---- source/blood/src/aiunicult.cpp | 8 ++++---- source/blood/src/player.cpp | 2 +- source/blood/src/triggers.cpp | 4 ++-- source/blood/src/weapon.cpp | 6 +++--- source/build/include/pragmas.h | 18 ------------------ 14 files changed, 41 insertions(+), 59 deletions(-) diff --git a/source/blood/src/actor.cpp b/source/blood/src/actor.cpp index b4a68a46a..cebd6ffca 100644 --- a/source/blood/src/actor.cpp +++ b/source/blood/src/actor.cpp @@ -6615,7 +6615,7 @@ void actFireVector(spritetype *pShooter, int a2, int a3, int a4, int a5, int a6, int t = thingInfo[pSprite->type-kThingBase].mass; if (t > 0 && pVectorData->impulse) { - int t2 = divscale(pVectorData->impulse, t, 8); + int t2 = DivScale(pVectorData->impulse, t, 8); xvel[nSprite] += MulScale(a4, t2, 16); yvel[nSprite] += MulScale(a5, t2, 16); zvel[nSprite] += MulScale(a6, t2, 16); @@ -6645,7 +6645,7 @@ void actFireVector(spritetype *pShooter, int a2, int a3, int a4, int a5, int a6, if (t > 0 && pVectorData->impulse) { - int t2 = divscale(pVectorData->impulse, t, 8); + int t2 = DivScale(pVectorData->impulse, t, 8); xvel[nSprite] += MulScale(a4, t2, 16); yvel[nSprite] += MulScale(a5, t2, 16); zvel[nSprite] += MulScale(a6, t2, 16); @@ -6702,7 +6702,7 @@ void actFireVector(spritetype *pShooter, int a2, int a3, int a4, int a5, int a6, if (gPhysSpritesCount > 0 && pVectorData->impulse) { int nIndex = debrisGetIndex(pSprite->index); if (nIndex != -1 && (xsprite[pSprite->extra].physAttr & kPhysDebrisVector)) { - int impulse = divscale(pVectorData->impulse, ClipLow(gSpriteMass[pSprite->extra].mass, 10), 6); + int impulse = DivScale(pVectorData->impulse, ClipLow(gSpriteMass[pSprite->extra].mass, 10), 6); xvel[nSprite] += MulScale(a4, impulse, 16); yvel[nSprite] += MulScale(a5, impulse, 16); zvel[nSprite] += MulScale(a6, impulse, 16); diff --git a/source/blood/src/aibeast.cpp b/source/blood/src/aibeast.cpp index ad0584f45..009e9bbe4 100644 --- a/source/blood/src/aibeast.cpp +++ b/source/blood/src/aibeast.cpp @@ -283,7 +283,7 @@ static void beastThinkChase(DBloodActor* actor) if (nDist < pDudeInfo->seeDist && klabs(nDeltaAngle) <= pDudeInfo->periphery) { aiSetTarget(pXSprite, pXSprite->target); - actor->dudeSlope = divscale(pTarget->z-pSprite->z, nDist, 10); + actor->dudeSlope = DivScale(pTarget->z-pSprite->z, nDist, 10); if (nDist < 0x1400 && nDist > 0xa00 && klabs(nDeltaAngle) < 85 && (pTarget->flags&2) && IsPlayerSprite(pTarget) && Chance(0x8000)) { diff --git a/source/blood/src/aicaleb.cpp b/source/blood/src/aicaleb.cpp index 90379be8b..0e8976d44 100644 --- a/source/blood/src/aicaleb.cpp +++ b/source/blood/src/aicaleb.cpp @@ -186,7 +186,7 @@ static void calebThinkChase(DBloodActor* actor) if (nDist < pDudeInfo->seeDist && klabs(nDeltaAngle) <= pDudeInfo->periphery) { aiSetTarget(pXSprite, pXSprite->target); - actor->dudeSlope = divscale(pTarget->z-pSprite->z, nDist, 10); + actor->dudeSlope = DivScale(pTarget->z-pSprite->z, nDist, 10); if (nDist < 0x599 && klabs(nDeltaAngle) < 28) { XSECTOR *pXSector; diff --git a/source/blood/src/aicerber.cpp b/source/blood/src/aicerber.cpp index 94f897e93..33ffa437b 100644 --- a/source/blood/src/aicerber.cpp +++ b/source/blood/src/aicerber.cpp @@ -116,7 +116,7 @@ void cerberusBurnSeqCallback(int, DBloodActor* actor) continue; if (tt1.at10) { - int t = divscale(nDist, tt1.at10, 12); + int t = DivScale(nDist, tt1.at10, 12); x2 += (xvel[nSprite2]*t)>>12; y2 += (yvel[nSprite2]*t)>>12; z2 += (zvel[nSprite2]*t)>>8; @@ -145,7 +145,7 @@ void cerberusBurnSeqCallback(int, DBloodActor* actor) nClosest = nDist2; aim.dx = CosScale16(nAngle); aim.dy = SinScale16(nAngle); - aim.dz = divscale(tz, nDist, 10); + aim.dz = DivScale(tz, nDist, 10); } else aim.dz = tz; @@ -201,7 +201,7 @@ void cerberusBurnSeqCallback2(int, DBloodActor* actor) continue; if (tt1.at10) { - int t = divscale(nDist, tt1.at10, 12); + int t = DivScale(nDist, tt1.at10, 12); x2 += (xvel[nSprite2]*t)>>12; y2 += (yvel[nSprite2]*t)>>12; z2 += (zvel[nSprite2]*t)>>8; @@ -232,7 +232,7 @@ void cerberusBurnSeqCallback2(int, DBloodActor* actor) nClosest = nDist2; aim.dx = CosScale16(nAngle); aim.dy = SinScale16(nAngle); - aim.dz = divscale(tz, nDist, 10); + aim.dz = DivScale(tz, nDist, 10); } else aim.dz = tz; diff --git a/source/blood/src/aicult.cpp b/source/blood/src/aicult.cpp index 512513241..a27af13bd 100644 --- a/source/blood/src/aicult.cpp +++ b/source/blood/src/aicult.cpp @@ -302,7 +302,7 @@ static void cultThinkChase(DBloodActor* actor) if (nDist < pDudeInfo->seeDist && klabs(nDeltaAngle) <= pDudeInfo->periphery) { aiSetTarget(pXSprite, pXSprite->target); - actor->dudeSlope = divscale(pTarget->z-pSprite->z, nDist, 10); + actor->dudeSlope = DivScale(pTarget->z-pSprite->z, nDist, 10); switch (pSprite->type) { case kDudeCultistTommy: if (nDist < 0x1e00 && nDist > 0xe00 && klabs(nDeltaAngle) < 85 && !TargetNearExplosion(pTarget) diff --git a/source/blood/src/aigarg.cpp b/source/blood/src/aigarg.cpp index 805ad18cf..ee70a1fc6 100644 --- a/source/blood/src/aigarg.cpp +++ b/source/blood/src/aigarg.cpp @@ -140,7 +140,7 @@ void BlastSSeqCallback(int, DBloodActor* actor) continue; if (tt.at10) { - int t = divscale(nDist, tt.at10, 12); + int t = DivScale(nDist, tt.at10, 12); x2 += (xvel[nSprite2]*t)>>12; y2 += (yvel[nSprite2]*t)>>12; z2 += (zvel[nSprite2]*t)>>8; @@ -169,20 +169,20 @@ void BlastSSeqCallback(int, DBloodActor* actor) nClosest = nDist2; aim.dx = CosScale16(nAngle); aim.dy = SinScale16(nAngle); - aim.dz = divscale(tz, nDist, 10); + aim.dz = DivScale(tz, nDist, 10); if (tz > -0x333) - aim.dz = divscale(tz, nDist, 10); + aim.dz = DivScale(tz, nDist, 10); else if (tz < -0x333 && tz > -0xb33) - aim.dz = divscale(tz, nDist, 10)+9460; + aim.dz = DivScale(tz, nDist, 10)+9460; else if (tz < -0xb33 && tz > -0x3000) - aim.dz = divscale(tz, nDist, 10)+9460; + aim.dz = DivScale(tz, nDist, 10)+9460; else if (tz < -0x3000) - aim.dz = divscale(tz, nDist, 10)-7500; + aim.dz = DivScale(tz, nDist, 10)-7500; else - aim.dz = divscale(tz, nDist, 10); + aim.dz = DivScale(tz, nDist, 10); } else - aim.dz = divscale(tz, nDist, 10); + aim.dz = DivScale(tz, nDist, 10); } } } diff --git a/source/blood/src/aighost.cpp b/source/blood/src/aighost.cpp index 8c0ed90b1..3d07fb78b 100644 --- a/source/blood/src/aighost.cpp +++ b/source/blood/src/aighost.cpp @@ -123,7 +123,7 @@ void ghostBlastSeqCallback(int, DBloodActor* actor) continue; if (tt.at10) { - int t = divscale(nDist, tt.at10, 12); + int t = DivScale(nDist, tt.at10, 12); x2 += (xvel[nSprite2]*t)>>12; y2 += (yvel[nSprite2]*t)>>12; z2 += (zvel[nSprite2]*t)>>8; @@ -152,20 +152,20 @@ void ghostBlastSeqCallback(int, DBloodActor* actor) nClosest = nDist2; aim.dx = CosScale16(nAngle); aim.dy = SinScale16(nAngle); - aim.dz = divscale(tz, nDist, 10); + aim.dz = DivScale(tz, nDist, 10); if (tz > -0x333) - aim.dz = divscale(tz, nDist, 10); + aim.dz = DivScale(tz, nDist, 10); else if (tz < -0x333 && tz > -0xb33) - aim.dz = divscale(tz, nDist, 10)+9460; + aim.dz = DivScale(tz, nDist, 10)+9460; else if (tz < -0xb33 && tz > -0x3000) - aim.dz = divscale(tz, nDist, 10)+9460; + aim.dz = DivScale(tz, nDist, 10)+9460; else if (tz < -0x3000) - aim.dz = divscale(tz, nDist, 10)-7500; + aim.dz = DivScale(tz, nDist, 10)-7500; else - aim.dz = divscale(tz, nDist, 10); + aim.dz = DivScale(tz, nDist, 10); } else - aim.dz = divscale(tz, nDist, 10); + aim.dz = DivScale(tz, nDist, 10); } } } diff --git a/source/blood/src/aigilbst.cpp b/source/blood/src/aigilbst.cpp index 7f3365682..06f6c2dbe 100644 --- a/source/blood/src/aigilbst.cpp +++ b/source/blood/src/aigilbst.cpp @@ -174,7 +174,7 @@ static void gillThinkChase(DBloodActor* actor) if (nDist < pDudeInfo->seeDist && klabs(nDeltaAngle) <= pDudeInfo->periphery) { aiSetTarget(pXSprite, pXSprite->target); - actor->dudeSlope = divscale(pTarget->z-pSprite->z, nDist, 10); + actor->dudeSlope = DivScale(pTarget->z-pSprite->z, nDist, 10); if (nDist < 921 && klabs(nDeltaAngle) < 28) { XSECTOR *pXSector; diff --git a/source/blood/src/aitchern.cpp b/source/blood/src/aitchern.cpp index bcbb0c5b3..788fa7ec5 100644 --- a/source/blood/src/aitchern.cpp +++ b/source/blood/src/aitchern.cpp @@ -98,7 +98,7 @@ void sub_71BD4(int, DBloodActor* actor) continue; if (tt.at10) { - int t = divscale(nDist, tt.at10, 12); + int t = DivScale(nDist, tt.at10, 12); x2 += (xvel[nSprite2]*t)>>12; y2 += (yvel[nSprite2]*t)>>12; z2 += (zvel[nSprite2]*t)>>8; @@ -127,7 +127,7 @@ void sub_71BD4(int, DBloodActor* actor) nClosest = nDist2; aim.dx = CosScale16(nAngle); aim.dy = SinScale16(nAngle); - aim.dz = divscale(tz, nDist, 10); + aim.dz = DivScale(tz, nDist, 10); } else aim.dz = tz; @@ -177,7 +177,7 @@ void sub_720AC(int, DBloodActor* actor) continue; if (tt.at10) { - int t = divscale(nDist, tt.at10, 12); + int t = DivScale(nDist, tt.at10, 12); x2 += (xvel[nSprite2]*t)>>12; y2 += (yvel[nSprite2]*t)>>12; z2 += (zvel[nSprite2]*t)>>8; @@ -206,7 +206,7 @@ void sub_720AC(int, DBloodActor* actor) nClosest = nDist2; aim.dx = CosScale16(nAngle); aim.dy = SinScale16(nAngle); - aim.dz = divscale(tz, nDist, 10); + aim.dz = DivScale(tz, nDist, 10); } else aim.dz = tz; diff --git a/source/blood/src/aiunicult.cpp b/source/blood/src/aiunicult.cpp index de9148e86..58377f995 100644 --- a/source/blood/src/aiunicult.cpp +++ b/source/blood/src/aiunicult.cpp @@ -308,7 +308,7 @@ static void ThrowThing(DBloodActor* actor, bool impact) } spritetype* pThing = NULL; - if ((pThing = actFireThing(pSprite, 0, 0, (dz / 128) - zThrow, curWeapon, divscale(dist / 540, 120, 23))) == NULL) return; + if ((pThing = actFireThing(pSprite, 0, 0, (dz / 128) - zThrow, curWeapon, DivScale(dist / 540, 120, 23))) == NULL) return; else if (pThinkInfo->picnum < 0 && pThing->type != kModernThingThrowableRock) pThing->picnum = 0; pThing->owner = pSprite->index; @@ -494,7 +494,7 @@ static void unicultThinkChase(DBloodActor* actor) if ((gFrameClock & 64) == 0 && Chance(0x3000) && !spriteIsUnderwater(pSprite, false)) playGenDudeSound(pSprite, kGenDudeSndChasing); - actor->dudeSlope = divscale(pTarget->z - pSprite->z, dist, 10); + actor->dudeSlope = DivScale(pTarget->z - pSprite->z, dist, 10); short curWeapon = gGenDudeExtra[pSprite->index].curWeapon; short weaponType = gGenDudeExtra[pSprite->index].weaponType; spritetype* pLeech = leechIsDropped(pSprite); const VECTORDATA* meleeVector = &gVectorData[22]; @@ -1563,7 +1563,7 @@ void dudeLeechOperate(spritetype* pSprite, XSPRITE* pXSprite, EVENT event) int nDist = approxDist(x - pSprite->x, y - pSprite->y); if (nDist != 0 && cansee(pSprite->x, pSprite->y, top, pSprite->sectnum, x, y, z, pTarget->sectnum)) { - int t = divscale(nDist, 0x1aaaaa, 12); + int t = DivScale(nDist, 0x1aaaaa, 12); x += (xvel[nTarget] * t) >> 12; y += (yvel[nTarget] * t) >> 12; int angBak = pSprite->ang; @@ -1571,7 +1571,7 @@ void dudeLeechOperate(spritetype* pSprite, XSPRITE* pXSprite, EVENT event) int dx = CosScale16(pSprite->ang); int dy = SinScale16(pSprite->ang); int tz = pTarget->z - (pTarget->yrepeat * pDudeInfo->aimHeight) * 4; - int dz = divscale(tz - top - 256, nDist, 10); + int dz = DivScale(tz - top - 256, nDist, 10); int nMissileType = kMissileLifeLeechAltNormal + (pXSprite->data3 ? 1 : 0); int t2; diff --git a/source/blood/src/player.cpp b/source/blood/src/player.cpp index 25ff32369..52fceb4e8 100644 --- a/source/blood/src/player.cpp +++ b/source/blood/src/player.cpp @@ -1238,7 +1238,7 @@ int ActionScan(PLAYER *pPlayer, int *a2, int *a3) int nMass = getDudeInfo(pSprite->type)->mass; if (nMass) { - int t2 = divscale(0xccccc, nMass, 8); + int t2 = DivScale(0xccccc, nMass, 8); xvel[*a2] += MulScale(x, t2, 16); yvel[*a2] += MulScale(y, t2, 16); zvel[*a2] += MulScale(z, t2, 16); diff --git a/source/blood/src/triggers.cpp b/source/blood/src/triggers.cpp index 882b29fba..4bbaf9c7f 100644 --- a/source/blood/src/triggers.cpp +++ b/source/blood/src/triggers.cpp @@ -259,7 +259,7 @@ void LifeLeechOperate(spritetype *pSprite, XSPRITE *pXSprite, EVENT event) int nDist = approxDist(x - pSprite->x, y - pSprite->y); if (nDist != 0 && cansee(pSprite->x, pSprite->y, top, pSprite->sectnum, x, y, z, pTarget->sectnum)) { - int t = divscale(nDist, 0x1aaaaa, 12); + int t = DivScale(nDist, 0x1aaaaa, 12); x += (xvel[nTarget]*t)>>12; y += (yvel[nTarget]*t)>>12; int angBak = pSprite->ang; @@ -267,7 +267,7 @@ void LifeLeechOperate(spritetype *pSprite, XSPRITE *pXSprite, EVENT event) int dx = CosScale16(pSprite->ang); int dy = SinScale16(pSprite->ang); int tz = pTarget->z - (pTarget->yrepeat * pDudeInfo->aimHeight) * 4; - int dz = divscale(tz - top - 256, nDist, 10); + int dz = DivScale(tz - top - 256, nDist, 10); int nMissileType = kMissileLifeLeechAltNormal + (pXSprite->data3 ? 1 : 0); int t2; if (!pXSprite->data3) diff --git a/source/blood/src/weapon.cpp b/source/blood/src/weapon.cpp index 27109b58a..9faab60c4 100644 --- a/source/blood/src/weapon.cpp +++ b/source/blood/src/weapon.cpp @@ -374,7 +374,7 @@ void UpdateAimVector(PLAYER * pPlayer) continue; if (pWeaponTrack->seeker) { - int t = divscale(nDist,pWeaponTrack->seeker, 12); + int t = DivScale(nDist,pWeaponTrack->seeker, 12); x2 += (xvel[nSprite]*t)>>12; y2 += (yvel[nSprite]*t)>>12; z2 += (zvel[nSprite]*t)>>8; @@ -407,7 +407,7 @@ void UpdateAimVector(PLAYER * pPlayer) nClosest = nDist2; aim.dx = CosScale16(angle); aim.dy = SinScale16(angle); - aim.dz = divscale(dzCenter, nDist, 10); + aim.dz = DivScale(dzCenter, nDist, 10); nTarget = nSprite; } } @@ -456,7 +456,7 @@ void UpdateAimVector(PLAYER * pPlayer) nClosest = nDist2; aim.dx = CosScale16(angle); aim.dy = SinScale16(angle); - aim.dz = divscale(dz, nDist, 10); + aim.dz = DivScale(dz, nDist, 10); nTarget = nSprite; } } diff --git a/source/build/include/pragmas.h b/source/build/include/pragmas.h index 23d711731..0b2173455 100644 --- a/source/build/include/pragmas.h +++ b/source/build/include/pragmas.h @@ -12,19 +12,6 @@ extern int32_t reciptable[2048]; -// break the C version of divscale out from the others -// because asm version overflows in drawmapview() - -#define qw(x) ((int64_t)(x)) // quadword cast -#define dw(x) ((int32_t)(x)) // doubleword cast -#define wo(x) ((int16_t)(x)) // word cast -#define by(x) ((uint8_t)(x)) // byte cast - -#define DIVTABLESIZE 16384 - -static inline int32_t divscale(int32_t eax, int32_t ebx, int32_t ecx) { return (int64_t(eax) << ecx) / ebx; } -static inline double fdivscale(double eax, double ebx, int32_t ecx) { return (eax * (double)(qw(1) << ecx)) / ebx; } - static inline int32_t scale(int32_t eax, int32_t edx, int32_t ecx) { return int64_t(eax) * edx / ecx; @@ -45,9 +32,4 @@ static inline int32_t krecipasm(int32_t i) return ((reciptable[(i >> 12) & 2047] >> (((i - 0x3f800000) >> 23) & 31)) ^ (i >> 31)); } -#undef qw -#undef dw -#undef wo -#undef by - #endif // pragmas_h_