From 8acc4101be4cdc1cfee94bf2b4353410e9e32acf Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 2 Aug 2020 22:03:22 +0200 Subject: [PATCH] - simplified calcSinTableValue and inlined it. There's no need for all this magic voodoo - the sin function already returns the proper values all by itself. --- source/build/include/build.h | 9 ++++++++- source/build/src/engine.cpp | 9 --------- source/games/duke/src/hudweapon_d.cpp | 6 +++--- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/source/build/include/build.h b/source/build/include/build.h index 88f6dc6bb..4e9d7abde 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -938,7 +938,14 @@ int32_t videoSetRenderMode(int32_t renderer); void renderSetRollAngle(float rolla); #endif -double calcSinTableValue(double index); +// +// 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); +} + // pal: pass -1 to invalidate all palettes for the tile, or >=0 for a particular palette // how: pass -1 to invalidate all instances of the tile in texture memory, or a bitfield diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 3ae659ae4..bc73e5f27 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -4323,12 +4323,3 @@ void renderSetRollAngle(float rolla) } #endif -// -// Calculates and returns a sintable[] value of the equivilent index (and supports fractional indexes also) -// -double calcSinTableValue(double index) -{ - double value = fabs(16384. * sin(BANG2RAD * (index - (fmod(index, 512) * 2)))); - return (index >= 1024 ? -value : value); -} - diff --git a/source/games/duke/src/hudweapon_d.cpp b/source/games/duke/src/hudweapon_d.cpp index 5db8c63e1..f99677c4f 100644 --- a/source/games/duke/src/hudweapon_d.cpp +++ b/source/games/duke/src/hudweapon_d.cpp @@ -305,11 +305,11 @@ void displayweapon_d(int snum, double smoothratio) gun_pos = 80 - (opos + fmulscale16(npos - opos, smoothratio)); weapon_xoffset = (160)-90; - weapon_xoffset -= calcSinTableValue(fmod((weapon_sway / 2.) + 512, 2048)) / (1024. + 512.); + weapon_xoffset -= calcSinTableValue((weapon_sway / 2.) + 512) / (1024. + 512.); weapon_xoffset -= 58 + p->weapon_ang; if( sprite[p->i].xrepeat < 32 ) - gun_pos -= fabs(calcSinTableValue(fmod(weapon_sway * 4., 2048)) / 512.); - else gun_pos -= fabs(calcSinTableValue(fmod(weapon_sway / 2., 2048)) / 1024.); + gun_pos -= fabs(calcSinTableValue(weapon_sway * 4.) / 512.); + else gun_pos -= fabs(calcSinTableValue(weapon_sway / 2.) / 1024.); gun_pos -= (p->hard_landing<<3);