diff --git a/source/blood/src/misc.h b/source/blood/src/misc.h index fb5e0eb7e..10c5c4297 100644 --- a/source/blood/src/misc.h +++ b/source/blood/src/misc.h @@ -89,16 +89,6 @@ inline int Cos(int ang) return costable[ang & 2047]; } -inline double Sinf(double ang) -{ - return (1 << 30) * sin(BANG2RAD * ang); -} - -inline double Cosf(double ang) -{ - return (1 << 30) * sin(BANG2RAD * (ang + 512.)); -} - inline int SinScale16(int ang) { return FixedToInt(costable[(ang - 512) & 2047]); diff --git a/source/blood/src/prediction.cpp b/source/blood/src/prediction.cpp index db67e09ce..7a86e3c8d 100644 --- a/source/blood/src/prediction.cpp +++ b/source/blood/src/prediction.cpp @@ -232,9 +232,9 @@ static void fakeProcessInput(PLAYER *pPlayer, InputPacket *pInput) predict.at20 = clamp(predict.at20+pInput->horz, IntToFixed(-60), IntToFixed(60)); if (predict.at20 > 0) - predict.at24 = FloatToFixed(fmulscale30(120., Sinf(FixedToFloat(predict.at20) * 8.))); + predict.at24 = FloatToFixed(fmulscale30(120., bsinf(FixedToFloat(predict.at20) * 8., 16))); else if (predict.at20 < 0) - predict.at24 = FloatToFixed(fmulscale30(180., Sinf(FixedToFloat(predict.at20) * 8.))); + predict.at24 = FloatToFixed(fmulscale30(180., bsinf(FixedToFloat(predict.at20) * 8., 16))); else predict.at24 = 0; #endif diff --git a/source/blood/src/sfx.cpp b/source/blood/src/sfx.cpp index 4f80b700e..824b331db 100644 --- a/source/blood/src/sfx.cpp +++ b/source/blood/src/sfx.cpp @@ -127,7 +127,7 @@ void GameInterface::UpdateSounds() if (gMe->pSprite) { - listener.angle = -(float)gMe->pSprite->ang * pi::pi() / 1024; // Build uses a period of 2048. + listener.angle = -gMe->pSprite->ang * BAngRadian; // Build uses a period of 2048. listener.velocity.Zero(); listener.position = GetSoundPos(&gMe->pSprite->pos); listener.valid = true; diff --git a/source/blood/src/view.cpp b/source/blood/src/view.cpp index a6b72f2aa..536b58f90 100644 --- a/source/blood/src/view.cpp +++ b/source/blood/src/view.cpp @@ -631,7 +631,7 @@ void viewDrawScreen(bool sceneonly) int viewingRange = viewingrange; videoSetCorrectedAspect(); - int v1 = xs_CRoundToInt(double(viewingrange) * tan(r_fov * (PI / 360.))); + int v1 = xs_CRoundToInt(double(viewingrange) * tan(r_fov * (pi::pi() / 360.))); renderSetAspect(v1, yxaspect); diff --git a/source/build/include/build.h b/source/build/include/build.h index a8ee18ac1..21e81ae5c 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -47,11 +47,6 @@ enum rendmode_t { REND_POLYMER }; -#define PI 3.14159265358979323846 -#define fPI 3.14159265358979323846f - -#define BANG2RAD (PI * (1./1024.)) - enum { MAXSECTORS = 4096, @@ -717,14 +712,6 @@ int32_t wallvisible(int32_t const x, int32_t const y, int16_t const wallnum); void renderSetRollAngle(float rolla); #endif -// -// Calculates and returns a sintable[] value of the equivilent index (and supports fractional indexes also) -// -inline double calcSinTableValue(double index) -{ - return 16384. * sin(BANG2RAD * index); -} - void PrecacheHardwareTextures(int nTile); void Polymost_Startup(); diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 3b670cf7d..1cedd9fcb 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -412,19 +412,19 @@ static int32_t engineLoadTables(void) reciptable[i] = divscale30(2048, i+2048); for (i=0; i<=512; i++) - sintable[i] = (int16_t)(16384.f * sinf((float)i * BANG2RAD) + 0.0001f); + sintable[i] = bsinf(i); for (i=513; i<1024; i++) sintable[i] = sintable[1024-i]; for (i=1024; i<2048; i++) sintable[i] = -sintable[i-1024]; for (i=0; i<640; i++) - radarang[i] = (int16_t)(atanf(((float)(640-i)-0.5f) * (1.f/160.f)) * (-64.f * (1.f/BANG2RAD)) + 0.0001f); + radarang[i] = atan((639.5 - i) / 160.) * (-64. / BAngRadian); for (i=0; i<640; i++) radarang[1279-i] = -radarang[i]; for (i=0; i<5120; i++) - qradarang[i] = FloatToFixed(atanf(((float)(5120-i)-0.5f) * (1.f/1280.f)) * (-64.f * (1.f/BANG2RAD))); + qradarang[i] = FloatToFixed(atan((5119.5 - i) / 1280.) * (-64. / BAngRadian)); for (i=0; i<5120; i++) qradarang[10239-i] = -qradarang[i]; @@ -1000,10 +1000,8 @@ void set_globalang(fixed_t const ang) qglobalang = ang & 0x7FFFFFF; float const f_ang = FixedToFloat(ang); - float const f_ang_radians = f_ang * M_PI * (1.f/1024.f); - - float const fcosang = cosf(f_ang_radians) * 16384.f; - float const fsinang = sinf(f_ang_radians) * 16384.f; + float const fcosang = bcosf(f_ang); + float const fsinang = bsinf(f_ang); #ifdef USE_OPENGL fcosglobalang = fcosang; @@ -3195,7 +3193,7 @@ void alignflorslope(int16_t dasect, int32_t x, int32_t y, int32_t z) #ifdef USE_OPENGL void renderSetRollAngle(float rolla) { - gtang = rolla * (fPI * (1.f/1024.f)); + gtang = rolla * BAngRadian; } #endif diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index 10a501392..a7b504269 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -2458,7 +2458,7 @@ void polymost_drawrooms() { // calculates the extend of the zenith glitch float verticalfovtan = (fviewingrange * (windowxy2.y-windowxy1.y) * 5.f) / ((float)yxaspect * (windowxy2.x-windowxy1.x) * 4.f); - float verticalfov = atanf(verticalfovtan) * (2.f / fPI); + float verticalfov = atanf(verticalfovtan) * (2.f / pi::pi()); static constexpr float const maxhorizangle = 0.6361136f; // horiz of 199 in degrees float zenglitch = verticalfov + maxhorizangle - 0.95f; // less than 1 because the zenith glitch extends a bit if (zenglitch > 0.f) @@ -2850,7 +2850,7 @@ void polymost_prepareMirror(int32_t dax, int32_t day, int32_t daz, fixed_t daang { // calculates the extend of the zenith glitch float verticalfovtan = (fviewingrange * (windowxy2.y-windowxy1.y) * 5.f) / ((float)yxaspect * (windowxy2.x-windowxy1.x) * 4.f); - float verticalfov = atanf(verticalfovtan) * (2.f / fPI); + float verticalfov = atanf(verticalfovtan) * (2.f / pi::pi()); static constexpr float const maxhorizangle = 0.6361136f; // horiz of 199 in degrees float zenglitch = verticalfov + maxhorizangle - 0.95f; // less than 1 because the zenith glitch extends a bit if (zenglitch > 0.f) diff --git a/source/exhumed/src/sound.cpp b/source/exhumed/src/sound.cpp index 84ef80cdd..728748aaa 100644 --- a/source/exhumed/src/sound.cpp +++ b/source/exhumed/src/sound.cpp @@ -456,7 +456,7 @@ void EXSoundEngine::CalcPosVel(int type, const void* source, const float pt[3], else if (type == SOURCE_Swirly) { int which = *(int*)source; - float phase = (leveltime << (6 + which)) * (M_PI / 1024); + float phase = (leveltime << (6 + which)) * BAngRadian; pos->X = fcampos.X + 256 * cos(phase); pos->Z = fcampos.Z + 256 * sin(phase); } @@ -519,7 +519,7 @@ void GameInterface::UpdateSounds() } auto fv = GetSoundPos(&pos); SoundListener listener; - listener.angle = -(float)ang * pi::pi() / 1024; // Build uses a period of 2048. + listener.angle = -ang * BAngRadian; // Build uses a period of 2048. listener.velocity.Zero(); listener.position = GetSoundPos(&pos); listener.underwater = false; diff --git a/source/exhumed/src/view.cpp b/source/exhumed/src/view.cpp index aae528635..c92ab7acb 100644 --- a/source/exhumed/src/view.cpp +++ b/source/exhumed/src/view.cpp @@ -375,7 +375,7 @@ void DrawView(double smoothRatio, bool sceneonly) static uint8_t sectorCeilingPal[MAXSECTORS]; static uint8_t wallPal[MAXWALLS]; int const viewingRange = viewingrange; - int const vr = xs_CRoundToInt(65536.f * tanf(r_fov * (fPI / 360.f))); + int const vr = xs_CRoundToInt(65536.f * tanf(r_fov * (pi::pi() / 360.f))); videoSetCorrectedAspect(); diff --git a/source/games/duke/src/sounds.cpp b/source/games/duke/src/sounds.cpp index 858cd0a65..dc3f2df53 100644 --- a/source/games/duke/src/sounds.cpp +++ b/source/games/duke/src/sounds.cpp @@ -413,7 +413,7 @@ void GameInterface::UpdateSounds(void) if (c != nullptr) { - listener.angle = -(float)ca * pi::pi() / 1024; // Build uses a period of 2048. + listener.angle = -ca * BAngRadian; // Build uses a period of 2048. listener.velocity.Zero(); listener.position = GetSoundPos(c); listener.underwater = false; diff --git a/source/sw/src/draw.cpp b/source/sw/src/draw.cpp index 4b18fc0a9..598ba3ff1 100644 --- a/source/sw/src/draw.cpp +++ b/source/sw/src/draw.cpp @@ -1755,7 +1755,7 @@ drawscreen(PLAYERp pp, double smoothratio) videoSetCorrectedAspect(); - renderSetAspect(xs_CRoundToInt(double(viewingrange)* tan(r_fov* (PI / 360.))), yxaspect); + renderSetAspect(xs_CRoundToInt(double(viewingrange)* tan(r_fov * (pi::pi() / 360.))), yxaspect); OverlapDraw = true; DrawOverlapRoom(tx, ty, tz, tang.asq16(), thoriz.asq16(), tsectnum); OverlapDraw = false; diff --git a/source/sw/src/sounds.cpp b/source/sw/src/sounds.cpp index ab9eb8b2b..85afbfdc3 100644 --- a/source/sw/src/sounds.cpp +++ b/source/sw/src/sounds.cpp @@ -594,7 +594,7 @@ void GameInterface::UpdateSounds(void) PLAYERp pp = Player + screenpeek; SoundListener listener; - listener.angle = -(pp->angle.ang.asbam() / (double)BAMUNIT) * pi::pi() / 1024; // Build uses a period of 2048. + listener.angle = -pp->angle.ang.asbuild() * BAngRadian; // Build uses a period of 2048. listener.velocity.Zero(); listener.position = GetSoundPos((vec3_t*)&pp->posx); listener.underwater = false;