From 27e12d8a9627166baaade8980c3d511866e7ea2c Mon Sep 17 00:00:00 2001 From: Pawel Kolodziejski Date: Wed, 23 Sep 2020 23:20:23 +0200 Subject: [PATCH] ALL: Eliminate LOCAL_PI macro --- audio/decoders/wma.cpp | 2 +- common/mdct.cpp | 2 +- common/scummsys.h | 5 ----- engines/grim/gfx_base.cpp | 2 +- engines/grim/gfx_opengl.cpp | 2 +- engines/grim/gfx_opengl_shaders.cpp | 2 +- engines/grim/gfx_tinygl.cpp | 2 +- engines/grim/lua/lmathlib.cpp | 16 +++++++--------- engines/grim/lua_v1.cpp | 2 +- engines/grim/set.cpp | 6 +++--- engines/icb/non_ad_module.cpp | 2 +- engines/icb/set_pc.cpp | 2 +- engines/myst3/movie.cpp | 4 ++-- engines/myst3/script.cpp | 4 ++-- engines/stark/resources/location.cpp | 4 ++-- engines/stark/scene.cpp | 2 +- engines/stark/visual/explodingimage.cpp | 4 ++-- .../base/gfx/opengl/base_render_opengl3d.cpp | 2 +- graphics/tinygl/light.cpp | 2 +- graphics/tinygl/matrix.cpp | 2 +- graphics/tinygl/zblit.cpp | 6 +++--- graphics/tinygl/zgl.h | 5 +---- 22 files changed, 35 insertions(+), 45 deletions(-) diff --git a/audio/decoders/wma.cpp b/audio/decoders/wma.cpp index 23b72df98f4..032934addf0 100644 --- a/audio/decoders/wma.cpp +++ b/audio/decoders/wma.cpp @@ -514,7 +514,7 @@ WMACodec::HuffmanDecoder *WMACodec::initCoefHuffman(uint16 *&runTable, float *&l } void WMACodec::initLSPToCurve() { - float wdel = M_PI / _frameLen; + float wdel = (float)M_PI / _frameLen; for (int i = 0; i < _frameLen; i++) _lspCosTable[i] = 2.0f * cosf(wdel * i); diff --git a/common/mdct.cpp b/common/mdct.cpp index 0cf3e05d741..78ec193263a 100644 --- a/common/mdct.cpp +++ b/common/mdct.cpp @@ -50,7 +50,7 @@ MDCT::MDCT(int bits, bool inverse, double scale) : _bits(bits), _fft(0) { scale = sqrt(ABS(scale)); for (int i = 0; i < size4; i++) { - const double alpha = 2 * M_PI * (i + theta) / _size; + const double alpha = 2 * (float)M_PI * (i + theta) / _size; _tCos[i] = -cos(alpha) * scale; _tSin[i] = -sin(alpha) * scale; diff --git a/common/scummsys.h b/common/scummsys.h index 8c560d297e3..b09ff1f99b6 100644 --- a/common/scummsys.h +++ b/common/scummsys.h @@ -404,11 +404,6 @@ #else #define STRINGBUFLEN 1024 #endif - -// ResidualVM specific: -#ifndef LOCAL_PI -#define LOCAL_PI 3.14159265358979323846 -#endif #endif #ifndef MAXPATHLEN diff --git a/engines/grim/gfx_base.cpp b/engines/grim/gfx_base.cpp index f035bd0a925..14bd0ce6fec 100644 --- a/engines/grim/gfx_base.cpp +++ b/engines/grim/gfx_base.cpp @@ -142,7 +142,7 @@ Math::Matrix4 GfxBase::makeLookMatrix(const Math::Vector3d& pos, const Math::Vec } Math::Matrix4 GfxBase::makeProjMatrix(float fov, float nclip, float fclip) { - float right = nclip * tan(fov / 2 * (LOCAL_PI / 180)); + float right = nclip * tan(fov / 2 * ((float)M_PI / 180)); float left = -right; float top = right * 0.75; float bottom = -right * 0.75; diff --git a/engines/grim/gfx_opengl.cpp b/engines/grim/gfx_opengl.cpp index b9768f0c82f..b1eb68084cf 100644 --- a/engines/grim/gfx_opengl.cpp +++ b/engines/grim/gfx_opengl.cpp @@ -231,7 +231,7 @@ void GfxOpenGL::setupCameraFrustum(float fov, float nclip, float fclip) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); - float right = nclip * tan(fov / 2 * (LOCAL_PI / 180)); + float right = nclip * tan(fov / 2 * ((float)M_PI / 180)); glFrustum(-right, right, -right * 0.75, right * 0.75, nclip, fclip); glMatrixMode(GL_MODELVIEW); diff --git a/engines/grim/gfx_opengl_shaders.cpp b/engines/grim/gfx_opengl_shaders.cpp index 0b7d4b345ae..642b194d56a 100644 --- a/engines/grim/gfx_opengl_shaders.cpp +++ b/engines/grim/gfx_opengl_shaders.cpp @@ -441,7 +441,7 @@ void GfxOpenGLS::setupCameraFrustum(float fov, float nclip, float fclip) { _fov = fov; _nclip = nclip; _fclip = fclip; - float right = nclip * tan(fov / 2 * (LOCAL_PI / 180)); + float right = nclip * tan(fov / 2 * ((float)M_PI / 180)); float top = right * 0.75; _projMatrix = makeFrustumMatrix(-right, right, -top, top, nclip, fclip); diff --git a/engines/grim/gfx_tinygl.cpp b/engines/grim/gfx_tinygl.cpp index 25702806659..9d281beb341 100644 --- a/engines/grim/gfx_tinygl.cpp +++ b/engines/grim/gfx_tinygl.cpp @@ -117,7 +117,7 @@ void GfxTinyGL::setupCameraFrustum(float fov, float nclip, float fclip) { tglMatrixMode(TGL_PROJECTION); tglLoadIdentity(); - float right = nclip * tan(fov / 2 * (LOCAL_PI / 180)); + float right = nclip * tan(fov / 2 * ((float)M_PI / 180)); tglFrustum(-right, right, -right * 0.75, right * 0.75, nclip, fclip); tglMatrixMode(TGL_MODELVIEW); diff --git a/engines/grim/lua/lmathlib.cpp b/engines/grim/lua/lmathlib.cpp index d750310a179..1060a7951ad 100644 --- a/engines/grim/lua/lmathlib.cpp +++ b/engines/grim/lua/lmathlib.cpp @@ -6,18 +6,16 @@ #define FORBIDDEN_SYMBOL_EXCEPTION_rand #define FORBIDDEN_SYMBOL_EXCEPTION_srand +#include "common/scummsys.h" + #include "engines/grim/lua/lauxlib.h" #include "engines/grim/lua/lua.h" #include "engines/grim/lua/lualib.h" namespace Grim { -#ifndef LOCAL_PI -#define LOCAL_PI (3.14159265358979323846) -#endif - -#define FROMRAD(a) ((a) * (180.0 / LOCAL_PI)) -#define TORAD(a) ((a) * (LOCAL_PI / 180.0)) +#define FROMRAD(a) ((a) * (180.0 / (float)M_PI)) +#define TORAD(a) ((a) * ((float)M_PI / 180.0)) static void math_abs() { float d = luaL_check_number(1); @@ -71,11 +69,11 @@ static void math_pow() { } static void math_deg() { - lua_pushnumber(luaL_check_number(1) * (180.0/LOCAL_PI)); + lua_pushnumber(luaL_check_number(1) * (180.0 / (float)M_PI)); } static void math_rad() { - lua_pushnumber(luaL_check_number(1) * (LOCAL_PI / 180.0)); + lua_pushnumber(luaL_check_number(1) * ((float)M_PI / 180.0)); } static void math_min() { @@ -148,7 +146,7 @@ void lua_mathlibopen() { lua_pushcfunction(math_pow); lua_pushnumber(0); // to get its tag lua_settagmethod(lua_tag(lua_pop()), "pow"); - lua_pushnumber((float)LOCAL_PI); + lua_pushnumber((float)M_PI); lua_setglobal("PI"); } diff --git a/engines/grim/lua_v1.cpp b/engines/grim/lua_v1.cpp index de35ea3d486..8af2ca64d8a 100644 --- a/engines/grim/lua_v1.cpp +++ b/engines/grim/lua_v1.cpp @@ -277,7 +277,7 @@ void Lua_V1::GetAngleBetweenVectors() { vec2.normalize(); float dot = vec1.dotProduct(vec2); - float angle = 90.0f - (180.0f * asin(dot)) / LOCAL_PI; + float angle = 90.0f - (180.0f * asin(dot)) / (float)M_PI; if (angle < 0) angle = -angle; lua_pushnumber(angle); diff --git a/engines/grim/set.cpp b/engines/grim/set.cpp index 474a686662b..7dac10c6908 100644 --- a/engines/grim/set.cpp +++ b/engines/grim/set.cpp @@ -541,12 +541,12 @@ void Set::Setup::setRoll(Math::Angle roll) { void Light::setUmbra(float angle) { _umbraangle = angle; - _cosumbraangle = cosf(angle * M_PI / 180.0f); + _cosumbraangle = cosf(angle * (float)M_PI / 180.0f); } void Light::setPenumbra(float angle) { _penumbraangle = angle; - _cospenumbraangle = cosf(angle * M_PI / 180.0f); + _cospenumbraangle = cosf(angle * (float)M_PI / 180.0f); } void Light::setIntensity(float intensity) { @@ -1053,7 +1053,7 @@ void Set::calculateSoundPosition(const Math::Vector3d &pos, int minVol, int maxV Math::Vector3d up(0, 0, 1); Math::Vector3d right; cameraVector.normalize(); - float roll = -_currSetup->_roll * LOCAL_PI / 180.f; + float roll = -_currSetup->_roll * (float)M_PI / 180.f; float cosr = cos(roll); // Rotate the up vector by roll. up = up * cosr + Math::Vector3d::crossProduct(cameraVector, up) * sin(roll) + diff --git a/engines/icb/non_ad_module.cpp b/engines/icb/non_ad_module.cpp index 260a76a845b..52af20dd99e 100644 --- a/engines/icb/non_ad_module.cpp +++ b/engines/icb/non_ad_module.cpp @@ -63,7 +63,7 @@ void WorldToFilm(const PXvector_PC &worldpos, const PCcamera &camera, bool8 &is_ PXreal AngleOfVector(PXreal x, PXreal y) { if (fabs(x) > 0.0001f) { /*smallest value safe for atan2*/ - return (float)atan2(y, x) / M_PI / 2; + return (float)atan2(y, x) / (float)M_PI / 2; } else { // atan2's y/x would be infinite, so treat as special case if (y > 0.0f) diff --git a/engines/icb/set_pc.cpp b/engines/icb/set_pc.cpp index ff2816a45d5..24a292abdec 100644 --- a/engines/icb/set_pc.cpp +++ b/engines/icb/set_pc.cpp @@ -1816,7 +1816,7 @@ void _set::HackMakeCamera() { float fpan; int scrnPan; if (ctheta != 0) { - fpan = (float)atan((float)stheta / (float)ctheta) / (2.0f * M_PI); + fpan = (float)atan((float)stheta / (float)ctheta) / (2.0f * (float)M_PI); scrnPan = (int)(fpan * ONE); // second & third quadrant (90-270 degrees) : pan += 180 (pan is -ve(90-180), (180-270)+ve) if (ctheta < 0) diff --git a/engines/myst3/movie.cpp b/engines/myst3/movie.cpp index 255cd14574b..719c80cdfd3 100644 --- a/engines/myst3/movie.cpp +++ b/engines/myst3/movie.cpp @@ -479,8 +479,8 @@ ProjectorMovie::ProjectorMovie(Myst3Engine *vm, uint16 id, Graphics::Surface *ba _enabled = true; for (uint i = 0; i < kBlurIterations; i++) { - _blurTableX[i] = (uint8)(sin(2 * LOCAL_PI * i / (float)kBlurIterations) * 256.0); - _blurTableY[i] = (uint8)(cos(2 * LOCAL_PI * i / (float)kBlurIterations) * 256.0); + _blurTableX[i] = (uint8)(sin(2 * (float)M_PI * i / (float)kBlurIterations) * 256.0); + _blurTableY[i] = (uint8)(cos(2 * (float)M_PI * i / (float)kBlurIterations) * 256.0); } } diff --git a/engines/myst3/script.cpp b/engines/myst3/script.cpp index 60ac333ee8f..52307de3260 100644 --- a/engines/myst3/script.cpp +++ b/engines/myst3/script.cpp @@ -922,7 +922,7 @@ void Script::polarToRectSimple(Context &c, const Opcode &cmd) { debugC(kDebugScript, "Opcode %d: Polar to rect transformation for angle in var %d", cmd.op, cmd.args[5]); int32 angleDeg = _vm->_state->getVar(cmd.args[5]); - float angleRad = 2 * LOCAL_PI / cmd.args[6] * angleDeg; + float angleRad = 2 * (float)M_PI / cmd.args[6] * angleDeg; float angleSin = sin(angleRad); float angleCos = cos(angleRad); @@ -946,7 +946,7 @@ void Script::polarToRect(Context &c, const Opcode &cmd) { debugC(kDebugScript, "Opcode %d: Complex polar to rect transformation for angle in var %d", cmd.op, cmd.args[8]); int32 angleDeg = _vm->_state->getVar(cmd.args[8]); - float angleRad = 2 * LOCAL_PI / cmd.args[9] * angleDeg; + float angleRad = 2 * (float)M_PI / cmd.args[9] * angleDeg; float angleSin = sin(angleRad); float angleCos = cos(angleRad); diff --git a/engines/stark/resources/location.cpp b/engines/stark/resources/location.cpp index b9fe2af0a89..1c4ae40cdd7 100644 --- a/engines/stark/resources/location.cpp +++ b/engines/stark/resources/location.cpp @@ -114,7 +114,7 @@ void Location::onGameLoop() { _floatPosition -= 1.0; } - float floatOffset = sinf(_floatPosition * 2.0f * M_PI) * _floatAmplitude; + float floatOffset = sinf(_floatPosition * 2.0f * (float)M_PI) * _floatAmplitude; StarkScene->setFloatOffset(floatOffset); } @@ -124,7 +124,7 @@ void Location::onGameLoop() { _swayPosition -= 1.0; } - float sway = sinf((_swayOffset + _swayPosition) * 2.0f * M_PI) * _swayAmplitude; + float sway = sinf((_swayOffset + _swayPosition) * 2.0f * (float)M_PI) * _swayAmplitude; StarkScene->setSwayAngle(_swayAngle * sway); } diff --git a/engines/stark/scene.cpp b/engines/stark/scene.cpp index 22c2b640c1b..c8b11888016 100644 --- a/engines/stark/scene.cpp +++ b/engines/stark/scene.cpp @@ -88,7 +88,7 @@ void Scene::scrollCamera(const Common::Rect &viewport) { void Scene::computeClippingRect(float *xmin, float *xmax, float *ymin, float *ymax) { float aspectRatio = _viewSize.width() / (float) _viewSize.height(); - float xmaxValue = _nearClipPlane * tan(_fov * M_PI / 360.0); + float xmaxValue = _nearClipPlane * tan(_fov * (float)M_PI / 360.0); float ymaxValue = xmaxValue / aspectRatio; float xminValue = xmaxValue - 2 * xmaxValue * (_viewport.width() / (float) _viewSize.width()); diff --git a/engines/stark/visual/explodingimage.cpp b/engines/stark/visual/explodingimage.cpp index 7958c586431..777cb773dce 100644 --- a/engines/stark/visual/explodingimage.cpp +++ b/engines/stark/visual/explodingimage.cpp @@ -112,8 +112,8 @@ void VisualExplodingImage::ExplosionUnit::setPosition(int x, int y) { void VisualExplodingImage::ExplosionUnit::setExplosionSettings(const Common::Point ¢er, const Common::Point &litude, float scale) { _center = Math::Vector2d(center.x, center.y); - _speed.setX(cos(StarkRandomSource->getRandomNumber(M_PI * 100)) * (float)amplitude.x); - _speed.setY(sin(StarkRandomSource->getRandomNumber(M_PI * 100)) * (float)amplitude.y); + _speed.setX(cos(StarkRandomSource->getRandomNumber((float)M_PI * 100)) * (float)amplitude.x); + _speed.setY(sin(StarkRandomSource->getRandomNumber((float)M_PI * 100)) * (float)amplitude.y); // WTF, ensuring all fragments go in the same direction? float magnitude = _position.getDistanceTo(_speed); diff --git a/engines/wintermute/base/gfx/opengl/base_render_opengl3d.cpp b/engines/wintermute/base/gfx/opengl/base_render_opengl3d.cpp index b1b540302ef..a2cf15c1aba 100644 --- a/engines/wintermute/base/gfx/opengl/base_render_opengl3d.cpp +++ b/engines/wintermute/base/gfx/opengl/base_render_opengl3d.cpp @@ -128,7 +128,7 @@ void BaseRenderOpenGL3D::setLightParameters(int index, const Math::Vector3d &pos glLightf(GL_LIGHT0 + index, GL_SPOT_EXPONENT, 0.0f); // wme sets the phi angle to 1.0 (in radians) // so either 180/pi or (180/pi)/2 should give the same result - glLightf(GL_LIGHT0 + index, GL_SPOT_CUTOFF, (180.0f / M_PI)); + glLightf(GL_LIGHT0 + index, GL_SPOT_CUTOFF, (180.0f / (float)M_PI)); } else { glLightf(GL_LIGHT0 + index, GL_SPOT_CUTOFF, 180.0f); } diff --git a/graphics/tinygl/light.cpp b/graphics/tinygl/light.cpp index effc609c425..2fc098cdf3c 100644 --- a/graphics/tinygl/light.cpp +++ b/graphics/tinygl/light.cpp @@ -131,7 +131,7 @@ void glopLight(GLContext *c, GLParam *p) { assert(a == 180 || (a >= 0 && a <= 90)); l->spot_cutoff = a; if (a != 180) - l->cos_spot_cutoff = (float)(cos(a * LOCAL_PI / 180.0)); + l->cos_spot_cutoff = (float)(cos(a * (float)M_PI / 180.0)); } break; case TGL_CONSTANT_ATTENUATION: diff --git a/graphics/tinygl/matrix.cpp b/graphics/tinygl/matrix.cpp index d0c551e6d18..6ba5ae0edd1 100644 --- a/graphics/tinygl/matrix.cpp +++ b/graphics/tinygl/matrix.cpp @@ -129,7 +129,7 @@ void glopRotate(GLContext *c, GLParam *p) { float angle; int dir_code; - angle = (float)(p[1].f * LOCAL_PI / 180.0); + angle = (float)(p[1].f * (float)M_PI / 180.0); u[0] = p[2].f; u[1] = p[3].f; u[2] = p[4].f; diff --git a/graphics/tinygl/zblit.cpp b/graphics/tinygl/zblit.cpp index 3761ce52594..6b373848b3d 100644 --- a/graphics/tinygl/zblit.cpp +++ b/graphics/tinygl/zblit.cpp @@ -552,8 +552,8 @@ FORCEINLINE void BlitImage::tglBlitRotoScale(int dstX, int dstY, int width, int clampHeight = destinationRectangle.height(); uint32 invAngle = 360 - (rotation % 360); - float invCos = cos(invAngle * M_PI / 180.0f); - float invSin = sin(invAngle * M_PI / 180.0f); + float invCos = cos(invAngle * (float)M_PI / 180.0f); + float invSin = sin(invAngle * (float)M_PI / 180.0f); int icosx = (int)(invCos * (65536.0f * srcWidth / width)); int isinx = (int)(invSin * (65536.0f * srcWidth / width)); @@ -736,7 +736,7 @@ void tglBlitResetScissorRect(void) { } // end of namespace Internal Common::Point transformPoint(float x, float y, int rotation) { - float rotateRad = rotation * M_PI / 180.0f; + float rotateRad = rotation * (float)M_PI / 180.0f; Common::Point newPoint; newPoint.x = x * cos(rotateRad) - y * sin(rotateRad); newPoint.y = x * sin(rotateRad) + y * cos(rotateRad); diff --git a/graphics/tinygl/zgl.h b/graphics/tinygl/zgl.h index 166df594458..b19b14d5bfa 100644 --- a/graphics/tinygl/zgl.h +++ b/graphics/tinygl/zgl.h @@ -33,6 +33,7 @@ #include "common/textconsole.h" #include "common/array.h" #include "common/list.h" +#include "common/scummsys.h" #include "graphics/tinygl/gl.h" #include "graphics/tinygl/zbuffer.h" @@ -448,10 +449,6 @@ void glClose(); #define dprintf #endif -#ifndef LOCAL_PI -#define LOCAL_PI (3.14159265358979323846) -#endif - // glopXXX functions #define ADD_OP(a,b,c) void glop ## a (GLContext *, GLParam *);