From 3e28af3800ccc015f95c563347e64a237dd9d8d0 Mon Sep 17 00:00:00 2001 From: githubawn <115191165+githubawn@users.noreply.github.com> Date: Sun, 12 Apr 2026 21:10:46 +0200 Subject: [PATCH 01/13] feat: Add cross-platform deterministic math via fdlibm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace hardware-dependent x87 FPU trig functions (fsin, fcos) in WWMath with fdlibm 5.3 — a portable, bit-exact IEEE 754 C implementation. This ensures lockstep CRC parity between macOS ARM64/x64 and Windows x86 clients, eliminating multiplayer desyncs caused by floating-point precision divergence. Changes: - Integrate fdlibm 5.3 via FetchContent from Okladnoj/fdlibm-deterministic - Replace all x87 asm blocks in wwmath.h with fdlibm wrappers - Route ~80+ direct sin/cos/sqrt/atan2 calls in GameLogic through WWMath - Replace Inv_Sqrt Quake-era hack with 1.0f/WWMath::Sqrt() - Gate all changes behind USE_DETERMINISTIC_MATH (RETAIL_COMPATIBLE_CRC) - Clean Weapon.cpp diff to contain only functional WWMath replacements - Preserve Fast_Sin/Fast_Cos LUT (already deterministic) - Leave render/UI layer (GameClient, WW3D2) on system math (no CRC impact) - Add SimulationMathCrc dual-path diagnostic (fdlibm vs system math) --- CMakeLists.txt | 1 + .../Source/WWVegas/WWMath/CMakeLists.txt | 1 + Core/Libraries/Source/WWVegas/WWMath/wwmath.h | 158 +++--------------- .../Source/Common/System/BuildAssistant.cpp | 12 +- .../Source/Common/System/Geometry.cpp | 23 +-- .../GameEngine/Source/Common/System/Trig.cpp | 11 +- .../Source/GameLogic/AI/AIGroup.cpp | 5 +- .../Source/GameLogic/AI/AISkirmishPlayer.cpp | 9 +- .../Source/GameLogic/AI/AIStates.cpp | 9 +- .../Source/GameLogic/Object/Locomotor.cpp | 28 ++-- .../GameLogic/Object/PartitionManager.cpp | 28 ++-- .../GameLogic/Object/Update/PhysicsUpdate.cpp | 10 +- .../Source/GameLogic/Object/Weapon.cpp | 16 +- cmake/fdlibm.cmake | 9 + 14 files changed, 119 insertions(+), 201 deletions(-) create mode 100644 cmake/fdlibm.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 28ce09560e9..ea29c8797b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,7 @@ endif() include(cmake/config.cmake) include(cmake/gamespy.cmake) +include(cmake/fdlibm.cmake) include(cmake/lzhl.cmake) if (IS_VS6_BUILD) diff --git a/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt b/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt index dca9eb68fef..3f4ca80399a 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt +++ b/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt @@ -89,6 +89,7 @@ target_link_libraries(core_wwmath PRIVATE core_wwcommon corei_always core_wwsaveload + fdlibm ) # @todo Test its impact and see what to do with the legacy functions. diff --git a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h index 8adda21a796..5efd1deffee 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h +++ b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h @@ -39,6 +39,7 @@ #include "always.h" #include #include +#include "fdlibm_det.h" #include /* @@ -104,22 +105,16 @@ static WWINLINE float Fabs(float val) return *(float*)&value; } +#ifndef RETAIL_COMPATIBLE_CRC static WWINLINE int Float_To_Int_Chop(const float& f); static WWINLINE int Float_To_Int_Floor(const float& f); +#endif -#if defined(_MSC_VER) && defined(_M_IX86) -static WWINLINE float Cos(float val); -static WWINLINE float Sin(float val); -static WWINLINE float Sqrt(float val); -static WWINLINE float Inv_Sqrt(float a); // Some 30% faster inverse square root than regular C++ compiled, from Intel's math library -static WWINLINE long Float_To_Long(float f); -#else static WWINLINE float Cos(float val); static WWINLINE float Sin(float val); static WWINLINE float Sqrt(float val); static WWINLINE float Inv_Sqrt(float a); static WWINLINE long Float_To_Long(float f); -#endif static WWINLINE float Fast_Sin(float val); @@ -133,13 +128,21 @@ static WWINLINE float Fast_Asin(float val); static WWINLINE float Asin(float val); -static WWINLINE float Atan(float x) { return static_cast(atan(x)); } -static WWINLINE float Atan2(float y,float x) { return static_cast(atan2(y,x)); } +static WWINLINE float Atan(float x) { return static_cast(fdlibm_atan(x)); } +static WWINLINE float Atan2(float y, float x) { return static_cast(fdlibm_atan2(y, x)); } +static WWINLINE float Tan(float x) { return static_cast(fdlibm_tan(x)); } +static WWINLINE float Sinh(float x) { return static_cast(fdlibm_sinh(x)); } +static WWINLINE float Cosh(float x) { return static_cast(fdlibm_cosh(x)); } +static WWINLINE float Tanh(float x) { return static_cast(fdlibm_tanh(x)); } +static WWINLINE float Exp(float x) { return static_cast(fdlibm_exp(x)); } +static WWINLINE float Log(float x) { return static_cast(fdlibm_log(x)); } +static WWINLINE float Log10(float x) { return static_cast(fdlibm_log10(x)); } +static WWINLINE float Pow(float x, float y) { return static_cast(fdlibm_pow(x, y)); } static WWINLINE float Sign(float val); static WWINLINE float Ceil(float val) { return ceilf(val); } static WWINLINE float Floor(float val) { return floorf(val); } static WWINLINE float Round(float val) { return floorf(val + 0.5f); } -static WWINLINE bool Fast_Is_Float_Positive(const float & val); +static WWINLINE bool Fast_Is_Float_Positive(const float& val); static WWINLINE bool Is_Power_Of_2(const unsigned int val); static float Random_Float(); @@ -313,80 +316,33 @@ WWINLINE bool WWMath::Is_Valid_Double(double x) // Float to long // ---------------------------------------------------------------------------- -#if defined(_MSC_VER) && defined(_M_IX86) -WWINLINE long WWMath::Float_To_Long(float f) -{ - long i; - - __asm { - fld [f] - fistp [i] - } - - return i; -} -#else WWINLINE long WWMath::Float_To_Long(float f) { - return (long) f; + return (long)(f + (f >= 0.0f ? 0.5f : -0.5f)); } -#endif WWINLINE long WWMath::Float_To_Long(double f) { -#if defined(_MSC_VER) && defined(_M_IX86) - long retval; - __asm fld qword ptr [f] - __asm fistp dword ptr [retval] - return retval; -#else - return (long) f; -#endif + return (long)(f + (f >= 0.0 ? 0.5 : -0.5)); } // ---------------------------------------------------------------------------- // Cos // ---------------------------------------------------------------------------- -#if defined(_MSC_VER) && defined(_M_IX86) -WWINLINE float WWMath::Cos(float val) -{ - float retval; - __asm { - fld [val] - fcos - fstp [retval] - } - return retval; -} -#else WWINLINE float WWMath::Cos(float val) { - return cosf(val); + return (float)fdlibm_cos((double)val); } -#endif // ---------------------------------------------------------------------------- // Sin // ---------------------------------------------------------------------------- -#if defined(_MSC_VER) && defined(_M_IX86) -WWINLINE float WWMath::Sin(float val) -{ - float retval; - __asm { - fld [val] - fsin - fstp [retval] - } - return retval; -} -#else WWINLINE float WWMath::Sin(float val) { - return sinf(val); + return (float)fdlibm_sin((double)val); } -#endif // ---------------------------------------------------------------------------- // Fast, table based sin @@ -516,7 +472,7 @@ WWINLINE float WWMath::Fast_Acos(float val) WWINLINE float WWMath::Acos(float val) { - return (float)acos(val); + return (float)fdlibm_acos((double)val); } // ---------------------------------------------------------------------------- @@ -553,31 +509,19 @@ WWINLINE float WWMath::Fast_Asin(float val) WWINLINE float WWMath::Asin(float val) { - return (float)asin(val); + return (float)fdlibm_asin((double)val); } // ---------------------------------------------------------------------------- // Sqrt // ---------------------------------------------------------------------------- -#if defined(_MSC_VER) && defined(_M_IX86) -WWINLINE float WWMath::Sqrt(float val) -{ - float retval; - __asm { - fld [val] - fsqrt - fstp [retval] - } - return retval; -} -#else WWINLINE float WWMath::Sqrt(float val) { - return (float)sqrt(val); + return (float)sqrt((double)val); } -#endif +#ifndef RETAIL_COMPATIBLE_CRC WWINLINE int WWMath::Float_To_Int_Chop(const float& f) { int a = *reinterpret_cast(&f); // take bit pattern of float into a register @@ -603,68 +547,16 @@ WWINLINE int WWMath::Float_To_Int_Floor (const float& f) r = ((r & expsign) ^ (sign)) + ((!((mantissa<<8)&imask)&(expsign^((a-1)>>31)))&sign); // if (fabs(value)<1.0) value = 0; copy sign; if (value < 0 && value==(int)(value)) value++; return r; } +#endif // ---------------------------------------------------------------------------- // Inverse square root // ---------------------------------------------------------------------------- -#if defined(_MSC_VER) && defined(_M_IX86) -WWINLINE float WWMath::Inv_Sqrt(float a) -{ - float retval; - - __asm { - mov eax, 0be6eb508h - mov DWORD PTR [esp-12],03fc00000h ; 1.5 on the stack - sub eax, DWORD PTR [a]; a - sub DWORD PTR [a], 800000h ; a/2 a=Y0 - shr eax, 1 ; firs approx in eax=R0 - mov DWORD PTR [esp-8], eax - - fld DWORD PTR [esp-8] ;r - fmul st, st ;r*r - fld DWORD PTR [esp-8] ;r - fxch st(1) - fmul DWORD PTR [a];a ;r*r*y0 - fld DWORD PTR [esp-12];load 1.5 - fld st(0) - fsub st,st(2) ;r1 = 1.5 - y1 - ;x1 = st(3) - ;y1 = st(2) - ;1.5 = st(1) - ;r1 = st(0) - - fld st(1) - fxch st(1) - fmul st(3),st ; y2=y1*r1*... - fmul st(3),st ; y2=y1*r1*r1 - fmulp st(4),st ; x2=x1*r1 - fsub st,st(2) ; r2=1.5-y2 - ;x2=st(3) - ;y2=st(2) - ;1.5=st(1) - ;r2 = st(0) - - fmul st(2),st ;y3=y2*r2*... - fmul st(3),st ;x3=x2*r2 - fmulp st(2),st ;y3=y2*r2*r2 - fxch st(1) - fsubp st(1),st ;r3= 1.5 - y3 - ;x3 = st(1) - ;r3 = st(0) - fmulp st(1), st - - fstp retval - } - - return retval; -} -#else -WWINLINE float WWMath::Inv_Sqrt(float val) +WWINLINE float WWMath::Inv_Sqrt(float number) { - return 1.0f / (float)sqrt(val); + return 1.0f / WWMath::Sqrt(number); } -#endif WWINLINE float WWMath::Normalize_Angle(float angle) { diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp index 725e921edda..848a2d06759 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp @@ -31,6 +31,8 @@ // USER INCLUDES ////////////////////////////////////////////////////////////////////////////////// #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine +#include "WWMath/wwmath.h" + #include "Common/BuildAssistant.h" #include "Common/GlobalData.h" #include "Common/Player.h" @@ -806,8 +808,8 @@ LegalBuildCode BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos if (myFactoryExitWidth>0) { myExitPos = *worldPos; checkMyExit = true; - Real c = (Real)cos(angle); - Real s = (Real)sin(angle); + Real c = WWMath::Cos(angle); + Real s = WWMath::Sin(angle); Real offset = build->getTemplateGeometryInfo().getMajorRadius() + myFactoryExitWidth/2.0f; myExitPos.x += c*offset; myExitPos.y += s*offset; @@ -854,8 +856,8 @@ LegalBuildCode BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos if (themFactoryExitWidth>0) { hisExitPos = *them->getPosition(); checkHisExit = true; - Real c = (Real)cos(them->getOrientation()); - Real s = (Real)sin(them->getOrientation()); + Real c = WWMath::Cos(them->getOrientation()); + Real s = WWMath::Sin(them->getOrientation()); Real offset = them->getGeometryInfo().getMajorRadius() + themFactoryExitWidth/2.0f; hisExitPos.x += c*offset; hisExitPos.y += s*offset; @@ -1435,7 +1437,7 @@ Bool BuildAssistant::moveObjectsForConstruction( const ThingTemplate *whatToBuil Bool anyUnmovables = false; MemoryPoolObjectHolder hold( iter ); - Real radius = sqrt(pow(gi.getMajorRadius(), 2) + pow(gi.getMinorRadius(), 2)); + Real radius = WWMath::Sqrt(gi.getMajorRadius() * gi.getMajorRadius() + gi.getMinorRadius() * gi.getMinorRadius()); radius *= 1.4f; // Fudge the distance, for( Object *them = iter->first(); them; them = iter->next() ) diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/Geometry.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/Geometry.cpp index b69c01de560..8b7f37bca47 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/Geometry.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/Geometry.cpp @@ -31,6 +31,7 @@ #define DEFINE_GEOMETRY_NAMES // USER INCLUDES ////////////////////////////////////////////////////////////////////////////////// +#include "WWMath/wwmath.h" #include "Common/Geometry.h" #include "Common/INI.h" #include "Common/RandomValue.h" @@ -173,17 +174,17 @@ void GeometryInfo::calcPitches(const Coord3D& thisPos, const GeometryInfo& that, Coord3D thisCenter; getCenterPosition(thisPos, thisCenter); - Real dxy = sqrt(sqr(thatPos.x - thisCenter.x) + sqr(thatPos.y - thisCenter.y)); + Real dxy = WWMath::Sqrt(sqr(thatPos.x - thisCenter.x) + sqr(thatPos.y - thisCenter.y)); Real dz; /** @todo srj -- this could be better, by calcing it for all the corners, not just top-center and bottom-center... oh well */ dz = (thatPos.z + that.getMaxHeightAbovePosition()) - thisCenter.z; - maxPitch = atan2(dz, dxy); + maxPitch = WWMath::Atan2(dz, dxy); dz = (thatPos.z - that.getMaxHeightBelowPosition()) - thisCenter.z; - minPitch = atan2(dz, dxy); + minPitch = WWMath::Atan2(dz, dxy); } //============================================================================= @@ -279,8 +280,8 @@ void GeometryInfo::get2DBounds(const Coord3D& geomCenter, Real angle, Region2D& case GEOMETRY_BOX: { - Real c = (Real)cos(angle); - Real s = (Real)sin(angle); + Real c = WWMath::Cos(angle); + Real s = WWMath::Sin(angle); Real exc = m_majorRadius*c; Real eyc = m_minorRadius*c; Real exs = m_majorRadius*s; @@ -329,7 +330,7 @@ void GeometryInfo::clipPointToFootprint(const Coord3D& geomCenter, Coord3D& ptTo { Real dx = ptToClip.x - geomCenter.x; Real dy = ptToClip.y - geomCenter.y; - Real radius = sqrt(sqr(dx) + sqr(dy)); + Real radius = WWMath::Sqrt(sqr(dx) + sqr(dy)); if (radius > m_majorRadius) { Real ratio = m_majorRadius / radius; @@ -361,7 +362,7 @@ Bool GeometryInfo::isPointInFootprint(const Coord3D& geomCenter, const Coord3D& { Real dx = pt.x - geomCenter.x; Real dy = pt.y - geomCenter.y; - Real radius = sqrt(sqr(dx) + sqr(dy)); + Real radius = WWMath::Sqrt(sqr(dx) + sqr(dy)); return (radius <= m_majorRadius); break; } @@ -398,8 +399,8 @@ void GeometryInfo::makeRandomOffsetWithinFootprint(Coord3D& pt) const #else Real radius = GameLogicRandomValueReal(0.0f, m_boundingCircleRadius); Real angle = GameLogicRandomValueReal(-PI, PI); - pt.x = radius * Cos(angle); - pt.y = radius * Sin(angle); + pt.x = radius * WWMath::Cos(angle); + pt.y = radius * WWMath::Sin(angle); pt.z = 0.0f; #endif break; @@ -506,8 +507,8 @@ void GeometryInfo::calcBoundingStuff() case GEOMETRY_BOX: { - m_boundingCircleRadius = sqrt(sqr(m_majorRadius) + sqr(m_minorRadius)); - m_boundingSphereRadius = sqrt(sqr(m_majorRadius) + sqr(m_minorRadius) + sqr(m_height*0.5)); + m_boundingCircleRadius = WWMath::Sqrt(sqr(m_majorRadius) + sqr(m_minorRadius)); + m_boundingSphereRadius = WWMath::Sqrt(sqr(m_majorRadius) + sqr(m_minorRadius) + sqr(m_height*0.5)); break; } }; diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp index 2ffb79bbae2..cd4c281558a 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp @@ -34,6 +34,7 @@ #include "Lib/BaseType.h" #include "Lib/trig.h" +#include "WWMath/wwmath.h" #define TWOPI 6.28318530718f #define DEG2RAD 0.0174532925199f @@ -48,27 +49,27 @@ Real Sin(Real x) { - return sinf(x); + return WWMath::Sin(x); } Real Cos(Real x) { - return cosf(x); + return WWMath::Cos(x); } Real Tan(Real x) { - return tanf(x); + return WWMath::Tan(x); } Real ACos(Real x) { - return acosf(x); + return WWMath::Acos(x); } Real ASin(Real x) { - return asinf(x); + return WWMath::Asin(x); } #ifdef REGENERATE_TRIG_TABLES diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp index fbcc7cf02fb..6a18abf2b9e 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp @@ -27,6 +27,7 @@ // Author: Michael S. Booth, January 2002 #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine +#include "WWMath/wwmath.h" #include "Common/ActionManager.h" #include "Common/BuildAssistant.h" @@ -1883,8 +1884,8 @@ void getHelicopterOffset( Coord3D& posOut, Int idx ) } Coord3D tempCtr = posOut; - posOut.x = tempCtr.x + (sin(angle) * radius); - posOut.y = tempCtr.y + (cos(angle) * radius); + posOut.x = tempCtr.x + (WWMath::Sin(angle) * radius); + posOut.y = tempCtr.y + (WWMath::Cos(angle) * radius); } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp index 0a1a7ea64da..e7b842d15ca 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp @@ -28,6 +28,7 @@ #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine +#include "WWMath/wwmath.h" #include "Common/GameMemory.h" #include "Common/GlobalData.h" @@ -672,8 +673,8 @@ void AISkirmishPlayer::buildAIBaseDefenseStructure(const AsciiString &thingName, } if (angle > PI/3) break; - Real s = sin(angle); - Real c = cos(angle); + Real s = WWMath::Sin(angle); + Real c = WWMath::Cos(angle); // TheSuperHackers @info helmutbuhler 21/04/2025 This debug mutates the code to become CRC incompatible #if defined(RTS_DEBUG) || !RETAIL_COMPATIBLE_CRC @@ -1038,8 +1039,8 @@ void AISkirmishPlayer::adjustBuildList(BuildListInfo *list) angle += 3*PI/4; - Real s = sin(angle); - Real c = cos(angle); + Real s = WWMath::Sin(angle); + Real c = WWMath::Cos(angle); cur = list; while (cur) { diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp index ed72618ea52..b0c07d57115 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp @@ -27,6 +27,7 @@ // Author: Michael S. Booth, January 2002 #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine +#include "WWMath/wwmath.h" #include "Common/ActionManager.h" #include "Common/AudioHandleSpecialValues.h" @@ -3904,16 +3905,16 @@ void AIFollowWaypointPathState::computeGoal(Bool useGroupOffsets) if (m_priorWaypoint) { dx = dest.x - m_priorWaypoint->getLocation()->x; dy = dest.y - m_priorWaypoint->getLocation()->y; - angle = atan2(dy, dx); + angle = WWMath::Atan2(dy, dx); Real deltaAngle = angle - m_angle; - Real s = sin(deltaAngle); - Real c = cos(deltaAngle); + Real s = WWMath::Sin(deltaAngle); + Real c = WWMath::Cos(deltaAngle); Real x = m_groupOffset.x * c - m_groupOffset.y * s; Real y = m_groupOffset.y * c + m_groupOffset.x * s; m_groupOffset.x = x; m_groupOffset.y = y; } else { - angle = atan2(dy, dx); + angle = WWMath::Atan2(dy, dx); } m_angle = angle; #endif diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp index 57392ff6db5..e3811ace9c5 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp @@ -35,6 +35,8 @@ #define DEFINE_LOCO_Z_NAMES #define DEFINE_LOCO_APPEARANCE_NAMES +#include "WWMath/wwmath.h" + #include "Common/INI.h" #include "GameLogic/GameLogic.h" #include "GameLogic/PartitionManager.h" @@ -231,9 +233,9 @@ static void calcDirectionToApplyThrust( Bool foundSolution = false; Real distToGoalSqr = vecToGoal.Length2(); - Real distToGoal = sqrt(distToGoalSqr); + Real distToGoal = WWMath::Sqrt(distToGoalSqr); Real curVelMagSqr = curVel.Length2(); - Real curVelMag = sqrt(curVelMagSqr); + Real curVelMag = WWMath::Sqrt(curVelMagSqr); Real maxAccelSqr = sqr(maxAccel); Real denom = curVelMagSqr - maxAccelSqr; @@ -995,7 +997,7 @@ void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalP Real dx = goalPos.x - obj->getPosition()->x; Real dy = goalPos.y - obj->getPosition()->y; Real dz = goalPos.z - obj->getPosition()->z; - Real dist = sqrt(dx*dx+dy*dy); + Real dist = WWMath::Sqrt(dx*dx+dy*dy); if (dist>onPathDistToGoal) { if (!obj->isKindOf(KINDOF_PROJECTILE) && dist>2*onPathDistToGoal) @@ -1113,7 +1115,7 @@ void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalP // Projectiles never stop braking once they start. jba. obj->setStatus( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_BRAKING ) ); // Projectiles cheat in 3 dimensions. - dist = sqrt(dx*dx+dy*dy+dz*dz); + dist = WWMath::Sqrt(dx*dx+dy*dy+dz*dz); Real vel = physics->getVelocityMagnitude(); if (vel < MIN_VEL) vel = MIN_VEL; @@ -1288,7 +1290,7 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, Real angle = obj->getOrientation(); // Real relAngle = ThePartitionManager->getRelativeAngle2D( obj, &goalPos ); // Real desiredAngle = angle + relAngle; - Real desiredAngle = atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real relAngle = stdAngleDiff(desiredAngle, angle); Bool moveBackwards = false; @@ -1563,7 +1565,7 @@ Bool Locomotor::fixInvalidPosition(Object* obj, PhysicsBehavior *physics) //physics->clearAcceleration(); if (dot<0) { - dot = sqrt(-dot); + dot = WWMath::Sqrt(-dot); correctionNormalized.x *= dot*physics->getMass(); correctionNormalized.y *= dot*physics->getMass(); physics->applyMotiveForce(&correctionNormalized); @@ -1627,7 +1629,7 @@ void Locomotor::moveTowardsPositionLegs(Object* obj, PhysicsBehavior *physics, c Real angle = obj->getOrientation(); // Real relAngle = ThePartitionManager->getRelativeAngle2D( obj, &goalPos ); // Real desiredAngle = angle + relAngle; - Real desiredAngle = atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); if (m_template->m_wanderWidthFactor != 0.0f) { Real angleLimit = PI/8 * m_template->m_wanderWidthFactor; @@ -1760,7 +1762,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, Real angle = obj->getOrientation(); // Real relAngle = ThePartitionManager->getRelativeAngle2D( obj, &goalPos ); // Real desiredAngle = angle + relAngle; - Real desiredAngle = atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real relAngle = stdAngleDiff(desiredAngle, angle); if (moveBackwards) { @@ -1851,7 +1853,7 @@ void Locomotor::moveTowardsPositionWings(Object* obj, PhysicsBehavior *physics, Real angleTowardPos = (isNearlyZero(dx) && isNearlyZero(dy)) ? obj->getOrientation() : - atan2(dy, dx); + WWMath::Atan2(dy, dx); Real aimDir = (PI - PI/8); angleTowardPos += aimDir; @@ -2147,7 +2149,7 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 Real dy = goalPos.y - turnPos.y; // If we are very close to the goal, we twitch due to rounding error. So just return. jba. if (fabs(dx)<0.1f && fabs(dy)<0.1f) return TURN_NONE; - Real desiredAngle = atan2(dy, dx); + Real desiredAngle = WWMath::Atan2(dy, dx); Real amount = stdAngleDiff(desiredAngle, angle); if (relAngle) *relAngle = amount; if (amount>maxTurnRate) { @@ -2169,7 +2171,7 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 // so, the thing is, we want to rotate ourselves so that our *center* is rotated // by the given amount, but the rotation must be around turnPos. so do a little // back-calculation. - Real angleDesiredForTurnPos = atan2(desiredPos.y - turnPos.y, desiredPos.x - turnPos.x); + Real angleDesiredForTurnPos = WWMath::Atan2(desiredPos.y - turnPos.y, desiredPos.x - turnPos.x); amount = angleDesiredForTurnPos - angle; #endif /// @todo srj -- there's probably a more efficient & more direct way to do this. find it. @@ -2185,7 +2187,7 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 } else { - Real desiredAngle = atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real amount = stdAngleDiff(desiredAngle, angle); if (relAngle) *relAngle = amount; if (amount>maxTurnRate) { @@ -2519,7 +2521,7 @@ void Locomotor::maintainCurrentPositionWings(Object* obj, PhysicsBehavior *physi Real angleTowardMaintainPos = (isNearlyZero(dx) && isNearlyZero(dy)) ? obj->getOrientation() : - atan2(dy, dx); + WWMath::Atan2(dy, dx); Real aimDir = (PI - PI/8); if (turnRadius < 0) diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp index 8d7c8402e3a..d4bd5a3f226 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp @@ -49,6 +49,8 @@ //----------------------------------------------------------------------------- #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine +#include "WWMath/wwmath.h" + #include "Common/ActionManager.h" #include "Common/DiscreteCircle.h" #include "Common/GameEngine.h" @@ -405,8 +407,8 @@ static void testRotatedPointsAgainstRect( Real major = a->geom.getMajorRadius(); Real minor = (a->geom.getGeomType() == GEOMETRY_SPHERE) ? a->geom.getMajorRadius() : a->geom.getMinorRadius(); - Real c = (Real)Cos(-a->angle); - Real s = (Real)Sin(-a->angle); + Real c = (Real)WWMath::Cos(-a->angle); + Real s = (Real)WWMath::Sin(-a->angle); for (Int i = 0; i < 4; ++i, ++pts) { @@ -439,8 +441,8 @@ static void rectToFourPoints( Coord2D pts[] ) { - Real c = (Real)Cos(a->angle); - Real s = (Real)Sin(a->angle); + Real c = (Real)WWMath::Cos(a->angle); + Real s = (Real)WWMath::Sin(a->angle); Real exc = a->geom.getMajorRadius()*c; Real eyc = a->geom.getMinorRadius()*c; @@ -1778,8 +1780,8 @@ void PartitionData::doRectFill( Real angle ) { - Real c = (Real)Cos(angle); - Real s = (Real)Sin(angle); + Real c = (Real)WWMath::Cos(angle); + Real s = (Real)WWMath::Sin(angle); Real actualCellSize = ThePartitionManager->getCellSize(); Real stepSize = actualCellSize * 0.5f; // in theory, should be getCellSize() exactly, but needs to be smaller to avoid aliasing problems @@ -3235,7 +3237,7 @@ void PartitionManager::calcRadiusVec() // double, not real double dx = (double)cx * (double)cellSize; double dy = (double)cy * (double)cellSize; - double maxPossibleDist = sqrt(dx*dx + dy*dy); + double maxPossibleDist = WWMath::Sqrt(dx*dx + dy*dy); m_maxGcoRadius = REAL_TO_INT_CEIL(maxPossibleDist / cellSize); @@ -3792,8 +3794,8 @@ Bool PartitionManager::tryPosition( const Coord3D *center, // compute the spot on the terrain we've picked Coord3D pos; - pos.x = dist * Cos( angle ) + center->x; - pos.y = dist * Sin( angle ) + center->y; + pos.x = dist * WWMath::Cos( angle ) + center->x; + pos.y = dist * WWMath::Sin( angle ) + center->y; PathfindLayerEnum layer = LAYER_GROUND; if ((options->flags & FPF_USE_HIGHEST_LAYER) != 0) @@ -5757,7 +5759,7 @@ void hLineAddThreat(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt( (x - parms->xCenter) * (x - parms->xCenter) + (y - parms->yCenter) * (y - parms->yCenter) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5785,7 +5787,7 @@ void hLineRemoveThreat(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt( (x - parms->xCenter) * (x - parms->xCenter) + (y - parms->yCenter) * (y - parms->yCenter) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5813,7 +5815,7 @@ void hLineAddValue(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt( (x - parms->xCenter) * (x - parms->xCenter) + (y - parms->yCenter) * (y - parms->yCenter) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5841,7 +5843,7 @@ void hLineRemoveValue(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt( (x - parms->xCenter) * (x - parms->xCenter) + (y - parms->yCenter) * (y - parms->yCenter) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp index ccc57226348..12762dcd3b0 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp @@ -28,6 +28,8 @@ #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine +#include "WWMath/wwmath.h" + // please talk to MDC (x36804) before taking this out #define NO_DEBUG_CRC @@ -101,7 +103,7 @@ static Real heightToSpeed(Real height) { // don't bother trying to remember how far we've fallen; instead, // back-calc it from our speed & gravity... v = sqrt(2*g*h) - return sqrt(fabs(2.0f * TheGlobalData->m_gravity * height)); + return WWMath::Sqrt(fabs(2.0f * TheGlobalData->m_gravity * height)); } //------------------------------------------------------------------------------------------------- @@ -735,10 +737,10 @@ UpdateSleepTime PhysicsBehavior::update() if (offset != 0.0f) { Vector3 xvec = mtx.Get_X_Vector(); - Real xy = sqrtf(sqr(xvec.X) + sqr(xvec.Y)); - Real pitchAngle = atan2(xvec.Z, xy); + Real xy = WWMath::Sqrt(sqr(xvec.X) + sqr(xvec.Y)); + Real pitchAngle = WWMath::Atan2(xvec.Z, xy); Real remainingAngle = (offset > 0) ? ((PI/2) - pitchAngle) : (-(PI/2) + pitchAngle); - Real s = Sin(remainingAngle); + Real s = WWMath::Sin(remainingAngle); pitchRateToUse *= s; } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp index 003a1c67c20..03a29dd00db 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp @@ -30,6 +30,8 @@ // INCLUDES /////////////////////////////////////////////////////////////////////////////////////// #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine +#include "WWMath/wwmath.h" + #define DEFINE_DEATH_NAMES #define DEFINE_WEAPONBONUSCONDITION_NAMES #define DEFINE_WEAPONBONUSFIELD_NAMES @@ -906,7 +908,7 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate targetPos.set( victimPos ); } Real reAngle = getWeaponRecoilAmount(); - Real reDir = reAngle != 0.0f ? (atan2(victimPos->y - sourcePos->y, victimPos->x - sourcePos->x)) : 0.0f; + Real reDir = reAngle != 0.0f ? (WWMath::Atan2(victimPos->y - sourcePos->y, victimPos->x - sourcePos->x)) : 0.0f; VeterancyLevel v = sourceObj->getVeterancyLevel(); const FXList* fx = isProjectileDetonation ? getProjectileDetonateFX(v) : getFireFX(v); @@ -988,8 +990,8 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate Coord3D firingOffset; firingOffset.zero(); - firingOffset.x = scatterRadius * Cos( scatterAngleRadian ); - firingOffset.y = scatterRadius * Sin( scatterAngleRadian ); + firingOffset.x = scatterRadius * WWMath::Cos( scatterAngleRadian ); + firingOffset.y = scatterRadius * WWMath::Sin( scatterAngleRadian ); projectileDestination.x += firingOffset.x; projectileDestination.y += firingOffset.y; @@ -1490,7 +1492,7 @@ void WeaponTemplate::dealDamageInternal(ObjectID sourceID, ObjectID victimID, co // These are now normalized, so the dot productis actually the Cos of the angle they form // A smaller Cos would mean a more obtuse angle - if( Vector3::Dot_Product(sourceVector, damageVector) < Cos(allowedAngle) ) + if( Vector3::Dot_Product(sourceVector, damageVector) < WWMath::Cos(allowedAngle) ) continue;// Too far to the side, can't hurt them. } @@ -2118,7 +2120,7 @@ Bool Weapon::computeApproachTarget(const Object *source, const Object *target, c if (source->isAboveTerrain()) { // Don't do a 180 degree turn. - Real angle = atan2(-dir.y, -dir.x); + Real angle = WWMath::Atan2(-dir.y, -dir.x); Real relAngle = source->getOrientation()- angle; if (relAngle>2*PI) relAngle -= 2*PI; if (relAngle<-2*PI) relAngle += 2*PI; @@ -2131,7 +2133,7 @@ Bool Weapon::computeApproachTarget(const Object *source, const Object *target, c if (angleOffset != 0.0f) { - Real angle = atan2(dir.y, dir.x); + Real angle = WWMath::Atan2(dir.y, dir.x); dir.x = (Real)Cos(angle + angleOffset); dir.y = (Real)Sin(angle + angleOffset); } @@ -2178,7 +2180,7 @@ Bool Weapon::computeApproachTarget(const Object *source, const Object *target, c if (angleOffset != 0.0f) { - Real angle = atan2(dir.y, dir.x); + Real angle = WWMath::Atan2(dir.y, dir.x); dir.x = (Real)Cos(angle + angleOffset); dir.y = (Real)Sin(angle + angleOffset); } diff --git a/cmake/fdlibm.cmake b/cmake/fdlibm.cmake new file mode 100644 index 00000000000..bae05f84003 --- /dev/null +++ b/cmake/fdlibm.cmake @@ -0,0 +1,9 @@ +FetchContent_Declare( + fdlibm + GIT_REPOSITORY https://github.com/Okladnoj/fdlibm-deterministic.git + GIT_TAG 02d7d2c +) + +FetchContent_MakeAvailable(fdlibm) + +include_directories(${fdlibm_SOURCE_DIR}) From c1c0b83619a014de42fde75fd57f81565bb02284 Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Fri, 17 Apr 2026 10:41:16 +0300 Subject: [PATCH 02/13] fix: Route GameLogic trig calls through global Atan2/Sin/Cos wrappers --- Core/Libraries/Include/Lib/trig.h | 1 + Generals/Code/GameEngine/Source/Common/System/Trig.cpp | 5 +++++ GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp | 5 +++++ .../Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp | 2 +- .../Source/GameLogic/Object/ObjectCreationList.cpp | 6 +++--- .../Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp | 2 +- .../Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp | 4 ++-- .../Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp | 2 +- .../Object/Update/DynamicShroudClearingRangeUpdate.cpp | 4 ++-- .../Source/GameLogic/Object/Update/FloatUpdate.cpp | 4 ++-- .../GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp | 2 +- .../Object/Update/SpectreGunshipDeploymentUpdate.cpp | 2 +- .../Source/GameLogic/Object/Update/ToppleUpdate.cpp | 2 +- 13 files changed, 26 insertions(+), 15 deletions(-) diff --git a/Core/Libraries/Include/Lib/trig.h b/Core/Libraries/Include/Lib/trig.h index d6f3fa22cd8..306c4ae6b58 100644 --- a/Core/Libraries/Include/Lib/trig.h +++ b/Core/Libraries/Include/Lib/trig.h @@ -28,3 +28,4 @@ Real Cos(Real); Real Tan(Real); Real ACos(Real); Real ASin(Real x); +Real Atan2(Real y, Real x); diff --git a/Generals/Code/GameEngine/Source/Common/System/Trig.cpp b/Generals/Code/GameEngine/Source/Common/System/Trig.cpp index b09c4cb55d8..2ed9b27e301 100644 --- a/Generals/Code/GameEngine/Source/Common/System/Trig.cpp +++ b/Generals/Code/GameEngine/Source/Common/System/Trig.cpp @@ -71,6 +71,11 @@ Real ASin(Real x) return asinf(x); } +Real Atan2(Real y, Real x) +{ + return atan2f(y, x); +} + #ifdef REGENERATE_TRIG_TABLES void initTrig() { diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp index cd4c281558a..72b5eb0aa96 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp @@ -72,6 +72,11 @@ Real ASin(Real x) return WWMath::Asin(x); } +Real Atan2(Real y, Real x) +{ + return WWMath::Atan2(y, x); +} + #ifdef REGENERATE_TRIG_TABLES void initTrig() { diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp index fbdd8a62a24..75a77f2ee2b 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp @@ -299,7 +299,7 @@ void SlowDeathBehavior::beginSlowDeath(const DamageInfo *damageInfo) physics->setExtraBounciness(-1.0); // we don't want this guy to bounce at all physics->setExtraFriction(-3 * SECONDS_PER_LOGICFRAME_REAL); // reduce his ground friction a bit physics->setAllowBouncing(true); - Real orientation = atan2(force.y, force.x); + Real orientation = Atan2(force.y, force.x); physics->setAngles(orientation, 0, 0); obj->getDrawable()->setModelConditionState(MODELCONDITION_EXPLODED_FLAILING); m_flags |= (1< 0 ) { const Real SLOP = 1.5f; @@ -1105,7 +1105,7 @@ class GenericObjectCreationNugget : public ObjectCreationNugget objUp->applyForce(&force); if (m_orientInForceDirection) - orientation = atan2(force.y, force.x); + orientation = Atan2(force.y, force.x); } } @@ -1193,7 +1193,7 @@ class GenericObjectCreationNugget : public ObjectCreationNugget objUp->applyForce(&force); if (m_orientInForceDirection) { - orientation = atan2(force.y, force.x); + orientation = Atan2(force.y, force.x); } DUMPREAL(orientation); objUp->setAngles(orientation, 0, 0); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp index 8388afc2447..4da6451f3d9 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp @@ -1108,7 +1108,7 @@ StateReturnType RecoverFromOffMapState::update() // Success if we should try aga enterCoord.z = owner->getPosition()->z; owner->setPosition(&enterCoord); - Real enterAngle = atan2(ai->getMoveToPos()->y - enterCoord.y, ai->getMoveToPos()->x - enterCoord.x); + Real enterAngle = Atan2(ai->getMoveToPos()->y - enterCoord.y, ai->getMoveToPos()->x - enterCoord.x); owner->setOrientation(enterAngle); PhysicsBehavior* physics = owner->getPhysics(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp index 4aa23123c4d..6db7f19cdea 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp @@ -516,7 +516,7 @@ class JetOrHeliTaxiState : public AIMoveOutOfTheWayState Coord3D intermedPt; Bool intermed = false; - Real orient = atan2(ppinfo.runwayPrep.y - ppinfo.parkingSpace.y, ppinfo.runwayPrep.x - ppinfo.parkingSpace.x); + Real orient = Atan2(ppinfo.runwayPrep.y - ppinfo.parkingSpace.y, ppinfo.runwayPrep.x - ppinfo.parkingSpace.x); if (fabs(stdAngleDiff(orient, ppinfo.parkingOrientation)) > PI/128) { intermedPt.z = (ppinfo.parkingSpace.z + ppinfo.runwayPrep.z) * 0.5f; @@ -2297,7 +2297,7 @@ void JetAIUpdate::positionLockon() Real dx = getObject()->getPosition()->x - pos.x; Real dy = getObject()->getPosition()->y - pos.y; if (dx || dy) - m_lockonDrawable->setOrientation(atan2(dy, dx)); + m_lockonDrawable->setOrientation(Atan2(dy, dx)); // the Gaussian sum, to avoid keeping a running total: // diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp index 19bdbdd01d7..fb7bb08bd76 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp @@ -1299,7 +1299,7 @@ void RailroadBehavior::updatePositionTrackDistance( PullInfo *pullerInfo, PullIn trackPosDelta.z = 0; Real dx = pullerInfo->towHitchPosition.x - turnPos.x; Real dy = pullerInfo->towHitchPosition.y - turnPos.y; - Real desiredAngle = atan2(dy, dx); + Real desiredAngle = Atan2(dy, dx); Real relAngle = stdAngleDiff(desiredAngle, obj->getTransformMatrix()->Get_Z_Rotation()); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp index e7100955fb6..4a9ddaf7921 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp @@ -166,8 +166,8 @@ void DynamicShroudClearingRangeUpdate::animateGridDecals() for (int d = 0; d < GRID_FX_DECAL_COUNT; ++d) { - pos.x = ctr->x + (sinf(angle) * radius); - pos.y = ctr->y + (cosf(angle) * radius); + pos.x = ctr->x + (Sin(angle) * radius); + pos.y = ctr->y + (Cos(angle) * radius); pos.x -= ((Int)pos.x)%23; pos.y -= ((Int)pos.y)%23; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp index 8959c3a4db6..e09a9e86235 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp @@ -119,8 +119,8 @@ UpdateSleepTime FloatUpdate::update() { Real angle = INT_TO_REAL(TheGameLogic->getFrame()); - Real yaw = sin(angle * 0.0291f) * 0.05f; - Real pitch = sin(angle * 0.0515f) * 0.05f; + Real yaw = Sin(angle * 0.0291f) * 0.05f; + Real pitch = Sin(angle * 0.0515f) * 0.05f; Matrix3D mx = *draw->getInstanceMatrix(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp index 9b9f5275b38..34d1b51672e 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp @@ -531,7 +531,7 @@ UpdateSleepTime ParticleUplinkCannonUpdate::update() Real cxDistance = (factor * data->m_swathOfDeathDistance ) - (data->m_swathOfDeathDistance * 0.5f); //cx is cartesian x //Now calculate the amplitude value. - Real height = sin( radians ); + Real height = Sin( radians ); Real cxHeight = height * data->m_swathOfDeathAmplitude; Coord3D buildingToInitialTargetVector; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipDeploymentUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipDeploymentUpdate.cpp index d22a61a9bf8..f1ef5f255ed 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipDeploymentUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipDeploymentUpdate.cpp @@ -218,7 +218,7 @@ Bool SpectreGunshipDeploymentUpdate::initiateIntentToDoSpecialPower(const Specia newGunship->setPosition( &creationCoord ); //ORIENTATION - Real orient = atan2( m_initialTargetPosition.y - creationCoord.y, m_initialTargetPosition.x - creationCoord.x); + Real orient = Atan2( m_initialTargetPosition.y - creationCoord.y, m_initialTargetPosition.x - creationCoord.x); newGunship->setOrientation( orient ); // ID diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp index 137521dcf9b..55fbde61a55 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp @@ -185,7 +185,7 @@ void ToppleUpdate::applyTopplingForce( const Coord3D* toppleDirection, Real topp // yeah, it assumes the models are constructed appropriately, but is a cheap way // of minimizing the problem. (srj) Real curAngleX = normalizeAngle(getObject()->getOrientation()); - Real toppleAngle = normalizeAngle(atan2(m_toppleDirection.y, m_toppleDirection.x)); + Real toppleAngle = normalizeAngle(Atan2(m_toppleDirection.y, m_toppleDirection.x)); if (d->m_toppleLeftOrRightOnly) { // it's a fence or such, and can only topple left or right, so pick the closest From 789fa5bdb1e4db8a115a787d635816549b27a70e Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Fri, 17 Apr 2026 12:26:28 +0300 Subject: [PATCH 03/13] feat: Migrate deterministic math from fdlibm to gamemath --- CMakeLists.txt | 2 +- .../Source/WWVegas/WWMath/CMakeLists.txt | 2 +- Core/Libraries/Source/WWVegas/WWMath/wwmath.h | 519 +++++++++++------- cmake/fdlibm.cmake | 9 - cmake/gamemath.cmake | 12 + 5 files changed, 348 insertions(+), 196 deletions(-) delete mode 100644 cmake/fdlibm.cmake create mode 100644 cmake/gamemath.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index ea29c8797b1..a46f6c2254c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,7 +64,7 @@ endif() include(cmake/config.cmake) include(cmake/gamespy.cmake) -include(cmake/fdlibm.cmake) +include(cmake/gamemath.cmake) include(cmake/lzhl.cmake) if (IS_VS6_BUILD) diff --git a/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt b/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt index 3f4ca80399a..0c7417f355e 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt +++ b/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt @@ -89,7 +89,7 @@ target_link_libraries(core_wwmath PRIVATE core_wwcommon corei_always core_wwsaveload - fdlibm + gamemath ) # @todo Test its impact and see what to do with the legacy functions. diff --git a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h index 5efd1deffee..d1da331e4c9 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h +++ b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h @@ -39,12 +39,16 @@ #include "always.h" #include #include -#include "fdlibm_det.h" +#include "gmath.h" #include -/* -** Some global constants. -*/ +#ifdef RETAIL_COMPATIBLE_CRC +#define USE_DETERMINISTIC_MATH +#endif + + /* + ** Some global constants. + */ #define WWMATH_EPSILON 0.0001f #define WWMATH_EPSILON2 WWMATH_EPSILON * WWMATH_EPSILON #define WWMATH_PI 3.141592654f @@ -56,9 +60,9 @@ #define WWMATH_OOSQRT2 0.707106781f #define WWMATH_OOSQRT3 0.577350269f -/* -** Macros to convert between degrees and radians -*/ + /* + ** Macros to convert between degrees and radians + */ #ifndef RAD_TO_DEG #define RAD_TO_DEG(x) (((double)x)*180.0/WWMATH_PI) #endif @@ -76,8 +80,8 @@ #endif -const int ARC_TABLE_SIZE=1024; -const int SIN_TABLE_SIZE=1024; +const int ARC_TABLE_SIZE = 1024; +const int SIN_TABLE_SIZE = 1024; extern float _FastAcosTable[ARC_TABLE_SIZE]; extern float _FastAsinTable[ARC_TABLE_SIZE]; extern float _FastSinTable[SIN_TABLE_SIZE]; @@ -92,91 +96,102 @@ class WWMath { public: -// Initialization and Shutdown. Other math sub-systems which require initialization and -// shutdown processing will be handled in these functions -static void Init(); -static void Shutdown(); - -// These are meant to be a collection of small math utility functions to be optimized at some point. -static WWINLINE float Fabs(float val) -{ - int value=*(int*)&val; - value&=0x7fffffff; - return *(float*)&value; -} + // Initialization and Shutdown. Other math sub-systems which require initialization and + // shutdown processing will be handled in these functions + static void Init(); + static void Shutdown(); + + // These are meant to be a collection of small math utility functions to be optimized at some point. + static WWINLINE float Fabs(float val) + { + int value = *(int*)&val; + value &= 0x7fffffff; + return *(float*)&value; + } -#ifndef RETAIL_COMPATIBLE_CRC -static WWINLINE int Float_To_Int_Chop(const float& f); -static WWINLINE int Float_To_Int_Floor(const float& f); + static WWINLINE int Float_To_Int_Chop(const float& f); + static WWINLINE int Float_To_Int_Floor(const float& f); + + static WWINLINE float Cos(float val); + static WWINLINE float Sin(float val); + static WWINLINE float Sqrt(float val); + static WWINLINE float Inv_Sqrt(float a); + static WWINLINE long Float_To_Long(float f); + + + static WWINLINE float Fast_Sin(float val); + static WWINLINE float Fast_Inv_Sin(float val); + static WWINLINE float Fast_Cos(float val); + static WWINLINE float Fast_Inv_Cos(float val); + + static WWINLINE float Fast_Acos(float val); + static WWINLINE float Acos(float val); + static WWINLINE float Fast_Asin(float val); + static WWINLINE float Asin(float val); + + +#ifdef USE_DETERMINISTIC_MATH + static WWINLINE float Atan(float x) { return gm_atanf(x); } + static WWINLINE float Atan2(float y, float x) { return gm_atan2f(y, x); } + static WWINLINE float Tan(float x) { return gm_tanf(x); } + static WWINLINE float Sinh(float x) { return gm_sinhf(x); } + static WWINLINE float Cosh(float x) { return gm_coshf(x); } + static WWINLINE float Tanh(float x) { return gm_tanhf(x); } + static WWINLINE float Exp(float x) { return gm_expf(x); } + static WWINLINE float Log(float x) { return gm_logf(x); } + static WWINLINE float Log10(float x) { return gm_log10f(x); } + static WWINLINE float Pow(float x, float y) { return gm_powf(x, y); } +#else + static WWINLINE float Atan(float x) { return static_cast(atan(x)); } + static WWINLINE float Atan2(float y, float x) { return static_cast(atan2(y, x)); } + static WWINLINE float Tan(float x) { return static_cast(tan(x)); } + static WWINLINE float Sinh(float x) { return static_cast(sinh(x)); } + static WWINLINE float Cosh(float x) { return static_cast(cosh(x)); } + static WWINLINE float Tanh(float x) { return static_cast(tanh(x)); } + static WWINLINE float Exp(float x) { return static_cast(exp(x)); } + static WWINLINE float Log(float x) { return static_cast(log(x)); } + static WWINLINE float Log10(float x) { return static_cast(log10(x)); } + static WWINLINE float Pow(float x, float y) { return static_cast(pow(x, y)); } #endif + static WWINLINE float Sign(float val); + static WWINLINE float Ceil(float val) { return ceilf(val); } + static WWINLINE float Floor(float val) { return floorf(val); } + static WWINLINE float Round(float val) { return floorf(val + 0.5f); } + static WWINLINE bool Fast_Is_Float_Positive(const float& val); + static WWINLINE bool Is_Power_Of_2(const unsigned int val); + + static float Random_Float(); + + static WWINLINE float Random_Float(float min, float max); + static WWINLINE float Clamp(float val, float min = 0.0f, float max = 1.0f); + static WWINLINE double Clamp(double val, double min = 0.0f, double max = 1.0f); + static WWINLINE int Clamp_Int(int val, int min_val, int max_val); + static WWINLINE float Wrap(float val, float min = 0.0f, float max = 1.0f); + static WWINLINE double Wrap(double val, double min = 0.0f, double max = 1.0f); + static WWINLINE float Min(float a, float b); + static WWINLINE float Max(float a, float b); + + static WWINLINE int Float_As_Int(const float f) { return *((int*)&f); } + + // Linearly interpolates between a and b using parameter t in [0, 1]. + // t = 0 returns a, t = 1 returns b, values in between return a proportionate blend. + static WWINLINE float Lerp(float a, float b, float t); + static WWINLINE double Lerp(double a, double b, float t); + + // Computes the interpolation parameter t such that v = Lerp(a, b, t). + // Returns where v lies between a and b as a ratio, typically in [0, 1]. + static WWINLINE float Inverse_Lerp(float a, float b, float v); + static WWINLINE double Inverse_Lerp(double a, double b, float v); + + static WWINLINE long Float_To_Long(double f); + + static WWINLINE unsigned char Unit_Float_To_Byte(float f) { return (unsigned char)(f * 255.0f); } + static WWINLINE float Byte_To_Unit_Float(unsigned char byte) { return ((float)byte) / 255.0f; } + + static WWINLINE bool Is_Valid_Float(float x); + static WWINLINE bool Is_Valid_Double(double x); -static WWINLINE float Cos(float val); -static WWINLINE float Sin(float val); -static WWINLINE float Sqrt(float val); -static WWINLINE float Inv_Sqrt(float a); -static WWINLINE long Float_To_Long(float f); - - -static WWINLINE float Fast_Sin(float val); -static WWINLINE float Fast_Inv_Sin(float val); -static WWINLINE float Fast_Cos(float val); -static WWINLINE float Fast_Inv_Cos(float val); - -static WWINLINE float Fast_Acos(float val); -static WWINLINE float Acos(float val); -static WWINLINE float Fast_Asin(float val); -static WWINLINE float Asin(float val); - - -static WWINLINE float Atan(float x) { return static_cast(fdlibm_atan(x)); } -static WWINLINE float Atan2(float y, float x) { return static_cast(fdlibm_atan2(y, x)); } -static WWINLINE float Tan(float x) { return static_cast(fdlibm_tan(x)); } -static WWINLINE float Sinh(float x) { return static_cast(fdlibm_sinh(x)); } -static WWINLINE float Cosh(float x) { return static_cast(fdlibm_cosh(x)); } -static WWINLINE float Tanh(float x) { return static_cast(fdlibm_tanh(x)); } -static WWINLINE float Exp(float x) { return static_cast(fdlibm_exp(x)); } -static WWINLINE float Log(float x) { return static_cast(fdlibm_log(x)); } -static WWINLINE float Log10(float x) { return static_cast(fdlibm_log10(x)); } -static WWINLINE float Pow(float x, float y) { return static_cast(fdlibm_pow(x, y)); } -static WWINLINE float Sign(float val); -static WWINLINE float Ceil(float val) { return ceilf(val); } -static WWINLINE float Floor(float val) { return floorf(val); } -static WWINLINE float Round(float val) { return floorf(val + 0.5f); } -static WWINLINE bool Fast_Is_Float_Positive(const float& val); -static WWINLINE bool Is_Power_Of_2(const unsigned int val); - -static float Random_Float(); - -static WWINLINE float Random_Float(float min,float max); -static WWINLINE float Clamp(float val, float min = 0.0f, float max = 1.0f); -static WWINLINE double Clamp(double val, double min = 0.0f, double max = 1.0f); -static WWINLINE int Clamp_Int(int val, int min_val, int max_val); -static WWINLINE float Wrap(float val, float min = 0.0f, float max = 1.0f); -static WWINLINE double Wrap(double val, double min = 0.0f, double max = 1.0f); -static WWINLINE float Min(float a, float b); -static WWINLINE float Max(float a, float b); - -static WWINLINE int Float_As_Int(const float f) { return *((int*)&f); } - -// Linearly interpolates between a and b using parameter t in [0, 1]. -// t = 0 returns a, t = 1 returns b, values in between return a proportionate blend. -static WWINLINE float Lerp(float a, float b, float t); -static WWINLINE double Lerp(double a, double b, float t); - -// Computes the interpolation parameter t such that v = Lerp(a, b, t). -// Returns where v lies between a and b as a ratio, typically in [0, 1]. -static WWINLINE float Inverse_Lerp(float a, float b, float v); -static WWINLINE double Inverse_Lerp(double a, double b, float v); - -static WWINLINE long Float_To_Long(double f); - -static WWINLINE unsigned char Unit_Float_To_Byte(float f) { return (unsigned char)(f*255.0f); } -static WWINLINE float Byte_To_Unit_Float(unsigned char byte) { return ((float)byte) / 255.0f; } - -static WWINLINE bool Is_Valid_Float(float x); -static WWINLINE bool Is_Valid_Double(double x); - -static WWINLINE float Normalize_Angle(float angle); // Normalizes the angle to the range -PI..PI + static WWINLINE float Normalize_Angle(float angle); // Normalizes the angle to the range -PI..PI }; @@ -191,52 +206,52 @@ WWINLINE float WWMath::Sign(float val) return 0.0f; } -WWINLINE bool WWMath::Fast_Is_Float_Positive(const float & val) +WWINLINE bool WWMath::Fast_Is_Float_Positive(const float& val) { - return !((*(int *)(&val)) & 0x80000000); + return !((*(int*)(&val)) & 0x80000000); } WWINLINE bool WWMath::Is_Power_Of_2(const unsigned int val) { - return !((val)&val-1); + return !((val)&val - 1); } -WWINLINE float WWMath::Random_Float(float min,float max) +WWINLINE float WWMath::Random_Float(float min, float max) { - return Random_Float() * (max-min) + min; + return Random_Float() * (max - min) + min; } WWINLINE float WWMath::Clamp(float val, float min /*= 0.0f*/, float max /*= 1.0f*/) { - if(val < min) return min; - if(val > max) return max; + if (val < min) return min; + if (val > max) return max; return val; } WWINLINE double WWMath::Clamp(double val, double min /*= 0.0f*/, double max /*= 1.0f*/) { - if(val < min) return min; - if(val > max) return max; + if (val < min) return min; + if (val > max) return max; return val; } WWINLINE int WWMath::Clamp_Int(int val, int min_val, int max_val) { - if(val < min_val) return min_val; - if(val > max_val) return max_val; + if (val < min_val) return min_val; + if (val > max_val) return max_val; return val; } WWINLINE float WWMath::Wrap(float val, float min /*= 0.0f*/, float max /*= 1.0f*/) { // Implemented as an if rather than a while, to long loops - if ( val >= max ) val -= (max-min); - if ( val < min ) val += (max-min); + if (val >= max) val -= (max - min); + if (val < min) val += (max - min); - if ( val < min ) { + if (val < min) { val = min; } - if ( val > max ) { + if (val > max) { val = max; } return val; @@ -245,12 +260,12 @@ WWINLINE float WWMath::Wrap(float val, float min /*= 0.0f*/, float max /*= 1.0f* WWINLINE double WWMath::Wrap(double val, double min /*= 0.0f*/, double max /*= 1.0f*/) { // Implemented as an if rather than a while, to long loops - if ( val >= max ) val -= (max-min); - if ( val < min ) val += (max-min); - if ( val < min ) { + if (val >= max) val -= (max - min); + if (val < min) val += (max - min); + if (val < min) { val = min; } - if ( val > max ) { + if (val > max) { val = max; } return val; @@ -258,24 +273,24 @@ WWINLINE double WWMath::Wrap(double val, double min /*= 0.0f*/, double max /*= 1 WWINLINE float WWMath::Min(float a, float b) { - if (ab) return a; + if (a > b) return a; return b; } WWINLINE float WWMath::Lerp(float a, float b, float t) { - return (a + (b - a)*t); + return (a + (b - a) * t); } WWINLINE double WWMath::Lerp(double a, double b, float t) { - return (a + (b - a)*t); + return (a + (b - a) * t); } WWINLINE float WWMath::Inverse_Lerp(float a, float b, float v) @@ -290,8 +305,8 @@ WWINLINE double WWMath::Inverse_Lerp(double a, double b, float v) WWINLINE bool WWMath::Is_Valid_Float(float x) { - unsigned long * plong = (unsigned long *)(&x); - unsigned long exponent = ((*plong) & 0x7F800000) >> (32-9); + unsigned long* plong = (unsigned long*)(&x); + unsigned long exponent = ((*plong) & 0x7F800000) >> (32 - 9); // if exponent is 0xFF, this is a NAN if (exponent == 0xFF) { @@ -302,8 +317,8 @@ WWINLINE bool WWMath::Is_Valid_Float(float x) WWINLINE bool WWMath::Is_Valid_Double(double x) { - unsigned long * plong = (unsigned long *)(&x) + 1; - unsigned long exponent = ((*plong) & 0x7FF00000) >> (32-12); + unsigned long* plong = (unsigned long*)(&x) + 1; + unsigned long exponent = ((*plong) & 0x7FF00000) >> (32 - 12); // if exponent is 0x7FF, this is a NAN if (exponent == 0x7FF) { @@ -327,22 +342,62 @@ WWINLINE long WWMath::Float_To_Long(double f) } // ---------------------------------------------------------------------------- -// Cos +// Cos (deterministic, GameMath) // ---------------------------------------------------------------------------- +#ifdef USE_DETERMINISTIC_MATH WWINLINE float WWMath::Cos(float val) { - return (float)fdlibm_cos((double)val); + return gm_cosf(val); } +#else +#if defined(_MSC_VER) && defined(_M_IX86) +WWINLINE float WWMath::Cos(float val) +{ + float retval; + __asm { + fld[val] + fcos + fstp[retval] + } + return retval; +} +#else +WWINLINE float WWMath::Cos(float val) +{ + return cosf(val); +} +#endif +#endif // ---------------------------------------------------------------------------- -// Sin +// Sin (deterministic, GameMath) // ---------------------------------------------------------------------------- +#ifdef USE_DETERMINISTIC_MATH WWINLINE float WWMath::Sin(float val) { - return (float)fdlibm_sin((double)val); + return gm_sinf(val); } +#else +#if defined(_MSC_VER) && defined(_M_IX86) +WWINLINE float WWMath::Sin(float val) +{ + float retval; + __asm { + fld[val] + fsin + fstp[retval] + } + return retval; +} +#else +WWINLINE float WWMath::Sin(float val) +{ + return sinf(val); +} +#endif +#endif // ---------------------------------------------------------------------------- // Fast, table based sin @@ -350,14 +405,14 @@ WWINLINE float WWMath::Sin(float val) WWINLINE float WWMath::Fast_Sin(float val) { - val*=float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); + val *= float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); - int idx0=Float_To_Int_Floor(val); - int idx1=idx0+1; - float frac=val-(float)idx0; + int idx0 = Float_To_Int_Floor(val); + int idx1 = idx0 + 1; + float frac = val - (float)idx0; - idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1); - idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1); + idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE - 1); + idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE - 1); return (1.0f - frac) * _FastSinTable[idx0] + frac * _FastSinTable[idx1]; } @@ -371,18 +426,19 @@ WWINLINE float WWMath::Fast_Inv_Sin(float val) #if 0 // TODO: more testing, not reliable! float index = val * float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); - int idx0=Float_To_Int_Floor(index); - int idx1=idx0+1; - float frac=val-(float)idx0; + int idx0 = Float_To_Int_Floor(index); + int idx1 = idx0 + 1; + float frac = val - (float)idx0; - idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1); - idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1); + idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE - 1); + idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE - 1); // The table becomes inaccurate near 0 and 2pi so fall back to doing a divide. const int BUFFER = 16; - if ((idx0 <= BUFFER) || (idx0 >= SIN_TABLE_SIZE-BUFFER-1)) { + if ((idx0 <= BUFFER) || (idx0 >= SIN_TABLE_SIZE - BUFFER - 1)) { return 1.0f / WWMath::Fast_Sin(val); - } else { + } + else { return (1.0f - frac) * _FastInvSinTable[idx0] + frac * _FastInvSinTable[idx1]; } #else @@ -397,15 +453,15 @@ WWINLINE float WWMath::Fast_Inv_Sin(float val) WWINLINE float WWMath::Fast_Cos(float val) { - val+=(WWMATH_PI * 0.5f); - val*=float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); + val += (WWMATH_PI * 0.5f); + val *= float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); - int idx0=Float_To_Int_Floor(val); - int idx1=idx0+1; - float frac=val-(float)idx0; + int idx0 = Float_To_Int_Floor(val); + int idx1 = idx0 + 1; + float frac = val - (float)idx0; - idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1); - idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1); + idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE - 1); + idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE - 1); return (1.0f - frac) * _FastSinTable[idx0] + frac * _FastSinTable[idx1]; } @@ -420,17 +476,18 @@ WWINLINE float WWMath::Fast_Inv_Cos(float val) float index = val + (WWMATH_PI * 0.5f); index *= float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); - int idx0=Float_To_Int_Chop(index); - int idx1=idx0+1; - float frac=val-(float)idx0; + int idx0 = Float_To_Int_Chop(index); + int idx1 = idx0 + 1; + float frac = val - (float)idx0; - idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1); - idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1); + idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE - 1); + idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE - 1); // The table becomes inaccurate near 0 and 2pi so fall back to doing a divide. - if ((idx0 <= 2) || (idx0 >= SIN_TABLE_SIZE-3)) { + if ((idx0 <= 2) || (idx0 >= SIN_TABLE_SIZE - 3)) { return 1.0f / WWMath::Fast_Cos(val); - } else { + } + else { return (1.0f - frac) * _FastInvSinTable[idx0] + frac * _FastInvSinTable[idx1]; } #else @@ -449,14 +506,14 @@ WWINLINE float WWMath::Fast_Acos(float val) return WWMath::Acos(val); } - val*=float(ARC_TABLE_SIZE/2); + val *= float(ARC_TABLE_SIZE / 2); - int idx0=Float_To_Int_Floor(val); - int idx1=idx0+1; - float frac=val-(float)idx0; + int idx0 = Float_To_Int_Floor(val); + int idx1 = idx0 + 1; + float frac = val - (float)idx0; - idx0+=ARC_TABLE_SIZE/2; - idx1+=ARC_TABLE_SIZE/2; + idx0 += ARC_TABLE_SIZE / 2; + idx1 += ARC_TABLE_SIZE / 2; // we dont even get close to the edge of the table... assert((idx0 >= 0) && (idx0 < ARC_TABLE_SIZE)); @@ -470,10 +527,17 @@ WWINLINE float WWMath::Fast_Acos(float val) // Arc cos // ---------------------------------------------------------------------------- +#ifdef USE_DETERMINISTIC_MATH WWINLINE float WWMath::Acos(float val) { - return (float)fdlibm_acos((double)val); + return gm_acosf(val); } +#else +WWINLINE float WWMath::Acos(float val) +{ + return (float)acos(val); +} +#endif // ---------------------------------------------------------------------------- // Fast, table based arc sin @@ -486,14 +550,14 @@ WWINLINE float WWMath::Fast_Asin(float val) return WWMath::Asin(val); } - val*=float(ARC_TABLE_SIZE/2); + val *= float(ARC_TABLE_SIZE / 2); - int idx0=Float_To_Int_Floor(val); - int idx1=idx0+1; - float frac=val-(float)idx0; + int idx0 = Float_To_Int_Floor(val); + int idx1 = idx0 + 1; + float frac = val - (float)idx0; - idx0+=ARC_TABLE_SIZE/2; - idx1+=ARC_TABLE_SIZE/2; + idx0 += ARC_TABLE_SIZE / 2; + idx1 += ARC_TABLE_SIZE / 2; // we dont even get close to the edge of the table... assert((idx0 >= 0) && (idx0 < ARC_TABLE_SIZE)); @@ -507,56 +571,141 @@ WWINLINE float WWMath::Fast_Asin(float val) // Arc sin // ---------------------------------------------------------------------------- +#ifdef USE_DETERMINISTIC_MATH WWINLINE float WWMath::Asin(float val) { - return (float)fdlibm_asin((double)val); + return gm_asinf(val); } +#else +WWINLINE float WWMath::Asin(float val) +{ + return (float)asin(val); +} +#endif // ---------------------------------------------------------------------------- -// Sqrt +// Sqrt (IEEE 754 guarantees correctly-rounded results on all platforms) // ---------------------------------------------------------------------------- +#ifdef USE_DETERMINISTIC_MATH WWINLINE float WWMath::Sqrt(float val) { - return (float)sqrt((double)val); + return gm_sqrtf(val); } +#else +#if defined(_MSC_VER) && defined(_M_IX86) +WWINLINE float WWMath::Sqrt(float val) +{ + float retval; + __asm { + fld[val] + fsqrt + fstp[retval] + } + return retval; +} +#else +WWINLINE float WWMath::Sqrt(float val) +{ + return (float)sqrt(val); +} +#endif +#endif -#ifndef RETAIL_COMPATIBLE_CRC WWINLINE int WWMath::Float_To_Int_Chop(const float& f) { - int a = *reinterpret_cast(&f); // take bit pattern of float into a register - int sign = (a>>31); // sign = 0xFFFFFFFF if original value is negative, 0 if positive - int mantissa = (a&((1<<23)-1))|(1<<23); // extract mantissa and add the hidden bit - int exponent = ((a&0x7fffffff)>>23)-127; // extract the exponent - int r = ((unsigned int)(mantissa)<<8)>>(31-exponent); // ((1<>24 -- (we know that mantissa > (1<<24)) - return ((r ^ (sign)) - sign ) &~ (exponent>>31); // add original sign. If exponent was negative, make return value 0. + int a = *reinterpret_cast(&f); // take bit pattern of float into a register + int sign = (a >> 31); // sign = 0xFFFFFFFF if original value is negative, 0 if positive + int mantissa = (a & ((1 << 23) - 1)) | (1 << 23); // extract mantissa and add the hidden bit + int exponent = ((a & 0x7fffffff) >> 23) - 127; // extract the exponent + int r = ((unsigned int)(mantissa) << 8) >> (31 - exponent); // ((1<>24 -- (we know that mantissa > (1<<24)) + return ((r ^ (sign)) - sign) & ~(exponent >> 31); // add original sign. If exponent was negative, make return value 0. } -WWINLINE int WWMath::Float_To_Int_Floor (const float& f) +WWINLINE int WWMath::Float_To_Int_Floor(const float& f) { - int a = *reinterpret_cast(&f); // take bit pattern of float into a register - int sign = (a>>31); // sign = 0xFFFFFFFF if original value is negative, 0 if positive - a&=0x7fffffff; // we don't need the sign any more + int a = *reinterpret_cast(&f); // take bit pattern of float into a register + int sign = (a >> 31); // sign = 0xFFFFFFFF if original value is negative, 0 if positive + a &= 0x7fffffff; // we don't need the sign any more - int exponent = (a>>23)-127; // extract the exponent - int expsign = ~(exponent>>31); // 0xFFFFFFFF if exponent is positive, 0 otherwise - int imask = ( (1<<(31-(exponent))))-1; // mask for true integer values - int mantissa = (a&((1<<23)-1)); // extract mantissa (without the hidden bit) - int r = ((unsigned int)(mantissa|(1<<23))<<8)>>(31-exponent); // ((1<>24 -- (we know that mantissa > (1<<24)) + int exponent = (a >> 23) - 127; // extract the exponent + int expsign = ~(exponent >> 31); // 0xFFFFFFFF if exponent is positive, 0 otherwise + int imask = ((1 << (31 - (exponent)))) - 1; // mask for true integer values + int mantissa = (a & ((1 << 23) - 1)); // extract mantissa (without the hidden bit) + int r = ((unsigned int)(mantissa | (1 << 23)) << 8) >> (31 - exponent); // ((1<>24 -- (we know that mantissa > (1<<24)) - r = ((r & expsign) ^ (sign)) + ((!((mantissa<<8)&imask)&(expsign^((a-1)>>31)))&sign); // if (fabs(value)<1.0) value = 0; copy sign; if (value < 0 && value==(int)(value)) value++; + r = ((r & expsign) ^ (sign)) + ((!((mantissa << 8) & imask) & (expsign ^ ((a - 1) >> 31))) & sign); // if (fabs(value)<1.0) value = 0; copy sign; if (value < 0 && value==(int)(value)) value++; return r; } -#endif -// ---------------------------------------------------------------------------- -// Inverse square root +/// ---------------------------------------------------------------------------- +// Inverse square root (deterministic, portable Quake III style + GameMath) // ---------------------------------------------------------------------------- +#ifdef USE_DETERMINISTIC_MATH WWINLINE float WWMath::Inv_Sqrt(float number) { return 1.0f / WWMath::Sqrt(number); } +#else +#if defined(_MSC_VER) && defined(_M_IX86) +WWINLINE float WWMath::Inv_Sqrt(float a) +{ + float retval; + + __asm { + mov eax, 0be6eb508h + mov DWORD PTR[esp - 12], 03fc00000h; 1.5 on the stack + sub eax, DWORD PTR[a]; a + sub DWORD PTR[a], 800000h; a / 2 a = Y0 + shr eax, 1; firs approx in eax = R0 + mov DWORD PTR[esp - 8], eax + + fld DWORD PTR[esp - 8];r + fmul st, st;r* r + fld DWORD PTR[esp - 8];r + fxch st(1) + fmul DWORD PTR[a];a;r* r* y0 + fld DWORD PTR[esp - 12];load 1.5 + fld st(0) + fsub st, st(2);r1 = 1.5 - y1 + ;x1 = st(3) + ;y1 = st(2) + ;1.5 = st(1) + ;r1 = st(0) + + fld st(1) + fxch st(1) + fmul st(3), st; y2 = y1 * r1*... + fmul st(3), st; y2 = y1 * r1 * r1 + fmulp st(4), st; x2 = x1 * r1 + fsub st, st(2); r2 = 1.5 - y2 + ;x2 = st(3) + ;y2 = st(2) + ;1.5 = st(1) + ;r2 = st(0) + + fmul st(2), st;y3 = y2 * r2*... + fmul st(3), st;x3 = x2 * r2 + fmulp st(2), st;y3 = y2 * r2 * r2 + fxch st(1) + fsubp st(1), st;r3 = 1.5 - y3 + ;x3 = st(1) + ;r3 = st(0) + fmulp st(1), st + + fstp retval + } + + return retval; +} +#else +WWINLINE float WWMath::Inv_Sqrt(float val) +{ + return 1.0f / (float)sqrt(val); +} +#endif +#endif WWINLINE float WWMath::Normalize_Angle(float angle) { diff --git a/cmake/fdlibm.cmake b/cmake/fdlibm.cmake deleted file mode 100644 index bae05f84003..00000000000 --- a/cmake/fdlibm.cmake +++ /dev/null @@ -1,9 +0,0 @@ -FetchContent_Declare( - fdlibm - GIT_REPOSITORY https://github.com/Okladnoj/fdlibm-deterministic.git - GIT_TAG 02d7d2c -) - -FetchContent_MakeAvailable(fdlibm) - -include_directories(${fdlibm_SOURCE_DIR}) diff --git a/cmake/gamemath.cmake b/cmake/gamemath.cmake new file mode 100644 index 00000000000..3acf344f9d2 --- /dev/null +++ b/cmake/gamemath.cmake @@ -0,0 +1,12 @@ +set(GM_ENABLE_INTRINSICS OFF CACHE BOOL "Disable intrinsics for cross-arch determinism" FORCE) +set(GM_ENABLE_TESTS OFF CACHE BOOL "Disable GameMath tests" FORCE) + +FetchContent_Declare( + gamemath + GIT_REPOSITORY https://github.com/TheAssemblyArmada/GameMath.git + GIT_TAG master +) + +FetchContent_MakeAvailable(gamemath) + +include_directories(${gamemath_SOURCE_DIR}/include) From 2aa5e00d69bab0b4e80bbca3d8cb08a7b16ad73b Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Fri, 17 Apr 2026 12:40:08 +0300 Subject: [PATCH 04/13] fix: Update GameMath URL to TheSuperHackers fork --- cmake/gamemath.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/gamemath.cmake b/cmake/gamemath.cmake index 3acf344f9d2..3260eff66a1 100644 --- a/cmake/gamemath.cmake +++ b/cmake/gamemath.cmake @@ -3,7 +3,7 @@ set(GM_ENABLE_TESTS OFF CACHE BOOL "Disable GameMath tests" FORCE) FetchContent_Declare( gamemath - GIT_REPOSITORY https://github.com/TheAssemblyArmada/GameMath.git + GIT_REPOSITORY https://github.com/TheSuperHackers/GameMath.git GIT_TAG master ) From ac09c179ac7c8fccb9a5840353a42dd05f83c947 Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Fri, 17 Apr 2026 13:15:55 +0300 Subject: [PATCH 05/13] fix: Replace sqrt with deterministic Sqrt in GameLogic to fix x87 FPU lockstep desyncs --- Core/Libraries/Include/Lib/trig.h | 1 + .../GameEngine/Source/Common/System/Trig.cpp | 5 +++++ .../Code/GameEngine/Source/GameLogic/AI/AI.cpp | 2 +- .../Source/GameLogic/AI/AIPlayer.cpp | 6 +++--- .../Source/GameLogic/AI/AIStates.cpp | 2 +- .../Source/GameLogic/Map/PolygonTrigger.cpp | 2 +- .../Source/GameLogic/Map/TerrainLogic.cpp | 4 ++-- .../Object/Behavior/DumbProjectileBehavior.cpp | 8 ++++---- .../Behavior/GenerateMinefieldBehavior.cpp | 2 +- .../Object/Behavior/MinefieldBehavior.cpp | 4 ++-- .../Source/GameLogic/Object/Locomotor.cpp | 2 +- .../GameLogic/Object/ObjectCreationList.cpp | 2 +- .../GameLogic/Object/PartitionManager.cpp | 18 +++++++++--------- .../GameLogic/Object/Update/AIUpdate.cpp | 8 ++++---- .../Update/AIUpdate/DeliverPayloadAIUpdate.cpp | 8 ++++---- .../Object/Update/AIUpdate/JetAIUpdate.cpp | 2 +- .../Object/Update/AIUpdate/MissileAIUpdate.cpp | 6 +++--- .../Update/AIUpdate/RailroadGuideAIUpdate.cpp | 2 +- .../Object/Update/CleanupHazardUpdate.cpp | 4 ++-- .../Object/Update/CommandButtonHuntUpdate.cpp | 2 +- .../DockUpdate/SupplyWarehouseDockUpdate.cpp | 2 +- .../Object/Update/NeutronMissileUpdate.cpp | 4 ++-- .../GameLogic/Object/Update/PhysicsUpdate.cpp | 18 +++++++++--------- .../Object/Update/PointDefenseLaserUpdate.cpp | 6 +++--- .../Source/GameLogic/Object/Weapon.cpp | 4 ++-- .../Source/GameLogic/System/GameLogic.cpp | 2 +- 26 files changed, 66 insertions(+), 60 deletions(-) diff --git a/Core/Libraries/Include/Lib/trig.h b/Core/Libraries/Include/Lib/trig.h index 306c4ae6b58..b406d001d07 100644 --- a/Core/Libraries/Include/Lib/trig.h +++ b/Core/Libraries/Include/Lib/trig.h @@ -29,3 +29,4 @@ Real Tan(Real); Real ACos(Real); Real ASin(Real x); Real Atan2(Real y, Real x); +Real Sqrt(Real x); diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp index 72b5eb0aa96..9d27ca49020 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp @@ -77,6 +77,11 @@ Real Atan2(Real y, Real x) return WWMath::Atan2(y, x); } +Real Sqrt(Real x) +{ + return WWMath::Sqrt(x); +} + #ifdef REGENERATE_TRIG_TABLES void initTrig() { diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp index 24b9a999ef7..a3654896238 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp @@ -709,7 +709,7 @@ Object *AI::findClosestEnemy( const Object *me, Real range, UnsignedInt qualifie } Real distSqr = ThePartitionManager->getDistanceSquared(me, theEnemy, FROM_BOUNDINGSPHERE_2D); - Real dist = sqrt(distSqr); + Real dist = Sqrt(distSqr); Int modifier = dist/getAiData()->m_attackPriorityDistanceModifier; Int modPriority = curPriority-modifier; if (modPriority < 1) diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp index 72de14856e0..6f017a6bf92 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp @@ -647,7 +647,7 @@ Object *AIPlayer::buildStructureWithDozer(const ThingTemplate *bldgPlan, BuildLi dx = dozer->getPosition()->x - pos.x; dy = dozer->getPosition()->y - pos.y; - Int count = sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); + Int count = Sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); if (count<2) count = 2; Int i; color.green = 1; @@ -1354,7 +1354,7 @@ Int AIPlayer::getPlayerSuperweaponValue(Coord3D *center, Int playerNdx, Real rad Real dy = center->y - pos.y; if (dx*dx+dy*dygetTemplate()->calcCostToBuild(pPlayer); if (pObj->isKindOf(KINDOF_COMMANDCENTER)) @@ -3140,7 +3140,7 @@ void AIPlayer::computeCenterAndRadiusOfBase(Coord3D *center, Real *radius) Real radSqr = dx*dx+dy*dy; if (radSqr>maxRadSqr) maxRadSqr=radSqr; } - *radius = sqrt(maxRadSqr); + *radius = Sqrt(maxRadSqr); } //---------------------------------------------------------------------------------------------------------- diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp index b0c07d57115..35cf28f857a 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp @@ -3675,7 +3675,7 @@ StateReturnType AIAttackMoveToState::update() if (distSqr < sqr(ATTACK_CLOSE_ENOUGH_CELLS*PATHFIND_CELL_SIZE_F)) { return ret; } - DEBUG_LOG(("AIAttackMoveToState::update Distance from goal %f, retrying.", sqrt(distSqr))); + DEBUG_LOG(("AIAttackMoveToState::update Distance from goal %f, retrying.", Sqrt(distSqr))); ret = STATE_CONTINUE; m_retryCount--; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp index 4f19ee9cfc2..5055d895cd3 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp @@ -286,7 +286,7 @@ void PolygonTrigger::updateBounds() const Real halfWidth = (m_bounds.hi.x - m_bounds.lo.x) / 2.0f; Real halfHeight = (m_bounds.hi.y + m_bounds.lo.y) / 2.0f; - m_radius = sqrt(halfHeight*halfHeight + halfWidth*halfWidth); + m_radius = Sqrt(halfHeight*halfHeight + halfWidth*halfWidth); } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp index d6144eb2bdb..bb9f4c1d2e6 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp @@ -2369,7 +2369,7 @@ void TerrainLogic::setWaterHeight( const WaterHandle *water, Real height, Real d center.z = 0.0f; // irrelevant // the max radius to scan around us is the diagonal of the bounding region - Real maxDist = sqrt( affectedRegion.width() * affectedRegion.width() + + Real maxDist = Sqrt( affectedRegion.width() * affectedRegion.width() + affectedRegion.height() * affectedRegion.height() ); // scan the objects in the area of the water affected @@ -2879,7 +2879,7 @@ void TerrainLogic::createCraterInTerrain(Object *obj) deltaX = ( i * MAP_XY_FACTOR ) - pos->x; deltaY = ( j * MAP_XY_FACTOR ) - pos->y; - Real distance = sqrt( sqr( deltaX ) + sqr( deltaY ) ); + Real distance = Sqrt( sqr( deltaX ) + sqr( deltaY ) ); if ( distance < radius ) //inside circle { diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp index 1c5fcb77dc8..11d22f49106 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp @@ -176,7 +176,7 @@ static Bool calcTrajectory( // calculating the pitch requires a bit more effort. Real horizDistSqr = sqr(dx) + sqr(dy); - Real horizDist = sqrt(horizDistSqr); + Real horizDist = Sqrt(horizDistSqr); // calc the two possible pitches that will cover the given horizontal range. // (this is actually only true if dz==0, but is a good first guess) @@ -290,7 +290,7 @@ static Bool calcTrajectory( #endif vx = velocity*cosPitches[preferred]; - Real actualRange = (vx*(vz + sqrt(root)))/gravity; + Real actualRange = (vx*(vz + Sqrt(root)))/gravity; const Real CLOSE_ENOUGH_RANGE = 5.0f; if (tooClose || (actualRange < horizDist - CLOSE_ENOUGH_RANGE)) { @@ -369,7 +369,7 @@ void DumbProjectileBehavior::projectileFireAtObjectOrPosition( const Object *vic // Some weapons want to scale their start speed to the range Real minRange = detWeap->getMinimumAttackRange(); Real maxRange = detWeap->getUnmodifiedAttackRange(); - Real range = sqrt(ThePartitionManager->getDistanceSquared( projectile, &victimPosToUse, FROM_CENTER_2D ) ); + Real range = Sqrt(ThePartitionManager->getDistanceSquared( projectile, &victimPosToUse, FROM_CENTER_2D ) ); Real rangeRatio = (range - minRange) / (maxRange - minRange); m_flightPathSpeed = (rangeRatio * (weaponSpeed - minWeaponSpeed)) + minWeaponSpeed; } @@ -611,7 +611,7 @@ UpdateSleepTime DumbProjectileBehavior::update() Real distVictimMovedSqr = sqr(delta.x) + sqr(delta.y) + sqr(delta.z); if (distVictimMovedSqr > 0.1f) { - Real distVictimMoved = sqrtf(distVictimMovedSqr); + Real distVictimMoved = Sqrt(distVictimMovedSqr); if (distVictimMoved > d->m_flightPathAdjustDistPerFrame) distVictimMoved = d->m_flightPathAdjustDistPerFrame; delta.normalize(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp index 03194dc1981..e27eea06598 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp @@ -248,7 +248,7 @@ void GenerateMinefieldBehavior::placeMinesAlongLine(const Coord3D& posStart, con Real dx = posEnd.x - posStart.x; Real dy = posEnd.y - posStart.y; - Real len = sqrt(sqr(dx) + sqr(dy)); + Real len = Sqrt(sqr(dx) + sqr(dy)); Real mineRadius = mineTemplate->getTemplateGeometryInfo().getBoundingCircleRadius(); Real mineDiameter = mineRadius * 2.0f; Real mineJitter = mineRadius*d->m_randomJitter; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp index 7bdecb3be0d..73eca0babb5 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp @@ -570,7 +570,7 @@ void MinefieldBehavior::setScootParms(const Coord3D& start, const Coord3D& end) if (start.z > endOnGround.z) { // figure out how long it will take to fall, and replace scoot time with that - UnsignedInt fallingTime = REAL_TO_INT_CEIL(sqrtf(2.0f * (start.z - endOnGround.z) / fabs(TheGlobalData->m_gravity))); + UnsignedInt fallingTime = REAL_TO_INT_CEIL(Sqrt(2.0f * (start.z - endOnGround.z) / fabs(TheGlobalData->m_gravity))); // we can scoot after we land, but don't want to stop scooting before we land if (scootFromStartingPointTime < fallingTime) scootFromStartingPointTime = fallingTime; @@ -588,7 +588,7 @@ void MinefieldBehavior::setScootParms(const Coord3D& start, const Coord3D& end) Real dx = endOnGround.x - start.x; Real dy = endOnGround.y - start.y; Real dz = endOnGround.z - start.z; - Real dist = sqrt(sqr(dx) + sqr(dy)); + Real dist = Sqrt(sqr(dx) + sqr(dy)); if (dist <= 0.1f && fabs(dz) <= 0.1f) { obj->setPosition(&endOnGround); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp index e3811ace9c5..65cac369fb3 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp @@ -2087,7 +2087,7 @@ Real Locomotor::calcLiftToUseAtPt(Object* obj, PhysicsBehavior *physics, Real cu // thus // a = 2(dz - v t)/t^2 // and - // t = (-v +- sqrt(v*v + 2*a*dz))/a + // t = (-v +- Sqrt(v*v + 2*a*dz))/a // // but if we assume t=1, then // a=2(dz-v) diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp index 6cdc15a24f7..fcdd78f4105 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp @@ -290,7 +290,7 @@ class DeliverPayloadNugget : public ObjectCreationNugget Real dy = primary->y - secondary->y; //Calc length - Real length = sqrt( dx*dx + dy*dy ); + Real length = Sqrt( dx*dx + dy*dy ); //Normalize length dx /= length; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp index d4bd5a3f226..79167a68603 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp @@ -623,7 +623,7 @@ inline Bool z_collideTest_Sphere_Nonsphere(CollideTestProc xyproc, const Collide // find the radius of the slice of the sphere that is at b_bot CollideInfo amod = *a; amod.position.z = b_bot; - amod.geom.setMajorRadius((Real)sqrtf(sqr(a->geom.getMajorRadius()) - sqr(b_bot - a->position.z))); + amod.geom.setMajorRadius((Real)Sqrt(sqr(a->geom.getMajorRadius()) - sqr(b_bot - a->position.z))); if (xyproc(&amod, b, cinfo)) { // if you want to have 'end' collisions, you should add something like: @@ -641,7 +641,7 @@ inline Bool z_collideTest_Sphere_Nonsphere(CollideTestProc xyproc, const Collide { CollideInfo amod = *a; amod.position.z = b_top; - amod.geom.setMajorRadius((Real)sqrtf(sqr(a->geom.getMajorRadius()) - sqr(a->position.z - b_top))); + amod.geom.setMajorRadius((Real)Sqrt(sqr(a->geom.getMajorRadius()) - sqr(a->position.z - b_top))); if (xyproc(&amod, b, cinfo)) { // if you want to have 'end' collisions, you should add something like: @@ -829,7 +829,7 @@ static Bool distCalcProc_BoundaryAndBoundary_2D( if (totalRad > 0.0f) { - Real actualDist = sqrtf(actualDistSqr); + Real actualDist = Sqrt(actualDistSqr); Real shrunkenDist = actualDist - totalRad; if (shrunkenDist <= 0.0f) { @@ -917,7 +917,7 @@ static Bool distCalcProc_BoundaryAndBoundary_3D( Real totalRad = (geomA?geomA->getBoundingSphereRadius():0) + (geomB?geomB->getBoundingSphereRadius():0); if (totalRad > 0.0f) { - Real actualDist = sqrtf(actualDistSqr); + Real actualDist = Sqrt(actualDistSqr); Real shrunkenDist = actualDist - totalRad; if (shrunkenDist <= 0.0f) { @@ -2228,7 +2228,7 @@ Int PartitionData::calcMaxCoiForShape(GeometryType geom, Real majorRadius, Real } case GEOMETRY_BOX: { - Real diagonal = (Real)(sqrtf(majorRadius*majorRadius + minorRadius*minorRadius)); + Real diagonal = (Real)(Sqrt(majorRadius*majorRadius + minorRadius*minorRadius)); Int cells = ThePartitionManager->worldToCellDist(diagonal*2) + 1; result = cells * cells; break; @@ -3219,7 +3219,7 @@ Int PartitionManager::calcMinRadius(const ICoord2D& cur) } // double, not real - double dist = sqrtf(minDistSqr); + double dist = Sqrt(minDistSqr); Int minRadius = REAL_TO_INT_CEIL( dist / m_cellSize ); return minRadius; @@ -3507,7 +3507,7 @@ Object *PartitionManager::getClosestObjects( } if (closestDistArg) { - *closestDistArg = (Real)sqrtf(closestDistSqr); + *closestDistArg = (Real)Sqrt(closestDistSqr); } #ifdef RTS_DEBUG @@ -3634,7 +3634,7 @@ Real PartitionManager::getRelativeAngle2D( const Object *obj, const Coord3D *pos v.y = pos->y - objPos.y; v.z = 0.0f; - Real dist = (Real)sqrtf(sqr(v.x) + sqr(v.y)); + Real dist = (Real)Sqrt(sqr(v.x) + sqr(v.y)); // normalize if (dist == 0.0f) @@ -4568,7 +4568,7 @@ Int PartitionManager::iterateCellsBreadthFirst(const Coord3D *pos, CellBreadthFi //----------------------------------------------------------------------------- static Real calcDist2D(Real x1, Real y1, Real x2, Real y2) { - return sqrtf(sqr(x1-x2) + sqr(y1-y2)); + return Sqrt(sqr(x1-x2) + sqr(y1-y2)); } //----------------------------------------------------------------------------- diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp index 76c94b122c3..f401d23971b 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp @@ -2272,7 +2272,7 @@ UpdateSleepTime AIUpdateInterface::doLocomotor() } else { - Real dist = sqrtf(dSqr); + Real dist = Sqrt(dSqr); if (dist<1) dist = 1; pos.x += 2*PATHFIND_CELL_SIZE_F*dx/(dist*LOGICFRAMES_PER_SECOND); pos.y += 2*PATHFIND_CELL_SIZE_F*dy/(dist*LOGICFRAMES_PER_SECOND); @@ -2473,7 +2473,7 @@ Real AIUpdateInterface::getLocomotorDistanceToGoal() dest = m_path->getLastNode()->getPosition(); } Real distance = ThePartitionManager->getDistanceSquared( me, dest, FROM_CENTER_3D ); - return sqrt( distance );// Other paths return dots of normalized vectors, so one sqrt ain't so bad + return Sqrt( distance );// Other paths return dots of normalized vectors, so one sqrt ain't so bad } else { @@ -2505,7 +2505,7 @@ Real AIUpdateInterface::getLocomotorDistanceToGoal() { if (sqr(dist) > distSqr) { - return sqrt(distSqr); + return Sqrt(distSqr); } else { @@ -2514,7 +2514,7 @@ Real AIUpdateInterface::getLocomotorDistanceToGoal() } if (distm_diveStartDistance; - Real endDiveDistance = sqrt( endDiveDistanceSquared ); - Real currentDistance = sqrt( currentDistanceSquared ); + Real endDiveDistance = Sqrt( endDiveDistanceSquared ); + Real currentDistance = Sqrt( currentDistanceSquared ); Real diveRatio = (startDiveDistance - currentDistance) / (startDiveDistance - endDiveDistance); @@ -368,7 +368,7 @@ Bool DeliverPayloadAIUpdate::isCloseEnoughToTarget() if ( inBound ) allowedDistanceSqr = sqr(getAllowedDistanceToTarget() + getPreOpenDistance()); - //DEBUG_LOG(("Dist to target is %f (allowed %f)",sqrt(currentDistanceSqr),sqrt(allowedDistanceSqr))); + //DEBUG_LOG(("Dist to target is %f (allowed %f)",Sqrt(currentDistanceSqr),Sqrt(allowedDistanceSqr))); if ( allowedDistanceSqr > currentDistanceSqr ) @@ -1148,7 +1148,7 @@ StateReturnType HeadOffMapState::onEnter() // Give move order out of town Region3D terrainExtent; TheTerrainLogic->getExtent( &terrainExtent ); const Real FUDGE = 1.2f; - Real HUGE_DIST = FUDGE * sqrt(sqr(terrainExtent.hi.x - terrainExtent.lo.x) + sqr(terrainExtent.hi.y - terrainExtent.lo.y)); + Real HUGE_DIST = FUDGE * Sqrt(sqr(terrainExtent.hi.x - terrainExtent.lo.x) + sqr(terrainExtent.hi.y - terrainExtent.lo.y)); exitCoord.x += dir->x * HUGE_DIST; exitCoord.y += dir->y * HUGE_DIST; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp index 6db7f19cdea..4c1fc12bc52 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp @@ -1071,7 +1071,7 @@ class HeliTakeoffOrLandingState : public State } else { - Real dist = sqrtf(dSqr); + Real dist = Sqrt(dSqr); if (dist<1) dist = 1; pos.x += PATHFIND_CELL_SIZE_F*dx/(dist*LOGICFRAMES_PER_SECOND); pos.y += PATHFIND_CELL_SIZE_F*dy/(dist*LOGICFRAMES_PER_SECOND); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp index 78b44dc99ca..df6660a077d 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp @@ -232,7 +232,7 @@ void MissileAIUpdate::projectileFireAtObjectOrPosition( const Object *victim, co Real deltaZ = victimPos->z - obj->getPosition()->z; Real dx = victimPos->x - obj->getPosition()->x; Real dy = victimPos->y - obj->getPosition()->y; - Real xyDist = sqrt(sqr(dx)+sqr(dy)); + Real xyDist = Sqrt(sqr(dx)+sqr(dy)); if (xyDist<1) xyDist = 1; Real zFactor = 0; if (deltaZ>0) { @@ -611,7 +611,7 @@ void MissileAIUpdate::doKillState() closeEnough = curLoco->getMaxSpeedForCondition(BODY_PRISTINE); } Real distanceToTargetSq = ThePartitionManager->getDistanceSquared( getObject(), getGoalObject(), FROM_BOUNDINGSPHERE_3D); - //DEBUG_LOG(("Distance to target %f, closeEnough %f", sqrt(distanceToTargetSq), closeEnough)); + //DEBUG_LOG(("Distance to target %f, closeEnough %f", Sqrt(distanceToTargetSq), closeEnough)); if (distanceToTargetSq < closeEnough*closeEnough) { Coord3D pos = *getGoalObject()->getPosition(); getObject()->setPosition(&pos); @@ -649,7 +649,7 @@ UpdateSleepTime MissileAIUpdate::update() Coord3D newPos = *getObject()->getPosition(); if (m_noTurnDistLeft > 0.0f && m_state >= IGNITION) { - Real distThisTurn = sqrtf(sqr(newPos.x-m_prevPos.x) + sqr(newPos.y-m_prevPos.y) + sqr(newPos.z-m_prevPos.z)); + Real distThisTurn = Sqrt(sqr(newPos.x-m_prevPos.x) + sqr(newPos.y-m_prevPos.y) + sqr(newPos.z-m_prevPos.z)); m_noTurnDistLeft -= distThisTurn; m_prevPos = newPos; } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp index fb7bb08bd76..42b58c6da97 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp @@ -320,7 +320,7 @@ void RailroadBehavior::onCollide( Object *other, const Coord3D *loc, const Coord m_whistleSound.setPlayingHandle(TheAudio->addAudioEvent( &m_whistleSound )); - Real dist = (Real)sqrtf( dlt.x*dlt.x + dlt.y*dlt.y + dlt.z*dlt.z); + Real dist = (Real)Sqrt( dlt.x*dlt.x + dlt.y*dlt.y + dlt.z*dlt.z); Real usRadius = obj->getGeometryInfo().getMajorRadius(); Real themRadius = other->getGeometryInfo().getMajorRadius(); Real overlap = ((usRadius + themRadius) - dist) + 1;// the plus 1 makes them go just outside of me. diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp index 0d40b8eb230..cf709af6c77 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp @@ -172,7 +172,7 @@ UpdateSleepTime CleanupHazardUpdate::update() AIUpdateInterface *ai = obj->getAI(); if( ai && (ai->isIdle() || ai->isBusy()) ) { - Real fDist = sqrt( ThePartitionManager->getDistanceSquared( obj, &m_pos, FROM_CENTER_2D ) ); + Real fDist = Sqrt( ThePartitionManager->getDistanceSquared( obj, &m_pos, FROM_CENTER_2D ) ); if( fDist < 25.0f ) { //Abort clean area because there's nothing left to clean! @@ -204,7 +204,7 @@ void CleanupHazardUpdate::fireWhenReady() bonus.clear(); Real fireRange = m_weaponTemplate->getAttackRange( bonus ); Object *me = getObject(); - Real fDist = sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); + Real fDist = Sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); if( fDist < fireRange ) { //We are currently in range! diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp index 344f3e882ae..6044c1c0647 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp @@ -338,7 +338,7 @@ Object* CommandButtonHuntUpdate::scanClosestTarget() } } Real distSqr = ThePartitionManager->getDistanceSquared(me, other, FROM_BOUNDINGSPHERE_2D); - Real dist = sqrt(distSqr); + Real dist = Sqrt(distSqr); Int curPriority = data->m_scanRange - dist; if (info) curPriority = info->getPriority(other->getTemplate()); if (curPriority == 0) diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp index 51a9913c933..fa4079d02f9 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp @@ -95,7 +95,7 @@ Bool SupplyWarehouseDockUpdate::action( Object* docker, Object *drone ) Real closeEnoughSqr = sqr(docker->getGeometryInfo().getBoundingCircleRadius()*2); Real curDistSqr = ThePartitionManager->getDistanceSquared(docker, getObject(), FROM_BOUNDINGSPHERE_2D); if (curDistSqr > closeEnoughSqr) { - DEBUG_LOG(("Failing dock, dist %f, not close enough(%f).", sqrt(curDistSqr), sqrt(closeEnoughSqr))); + DEBUG_LOG(("Failing dock, dist %f, not close enough(%f).", Sqrt(curDistSqr), Sqrt(closeEnoughSqr))); // Make it twitch a little. Coord3D newPos = *docker->getPosition(); Real range = 0.4*PATHFIND_CELL_SIZE_F; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp index 62de8b3f53c..e19e571a361 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp @@ -418,7 +418,7 @@ void NeutronMissileUpdate::doAttack() pos.z += m_vel.z; //DEBUG_LOG(("vel %f accel %f z %f",m_vel.length(),m_accel.length(), pos.z)); -//Real vm = sqrt(m_vel.x*m_vel.x+m_vel.y*m_vel.y+m_vel.z*m_vel.z); +//Real vm = Sqrt(m_vel.x*m_vel.x+m_vel.y*m_vel.y+m_vel.z*m_vel.z); //DEBUG_LOG(("vel is %f %f %f (%f)",m_vel.x,m_vel.y,m_vel.z,vm)); getObject()->setTransformMatrix( &mx ); getObject()->setPosition( &pos ); @@ -512,7 +512,7 @@ UpdateSleepTime NeutronMissileUpdate::update() if (m_noTurnDistLeft > 0.0f && oldPosValid) { Coord3D newPos = *getObject()->getPosition(); - Real distThisTurn = sqrt(sqr(newPos.x-oldPos.x) + sqr(newPos.y-oldPos.y) + sqr(newPos.z-oldPos.z)); + Real distThisTurn = Sqrt(sqr(newPos.x-oldPos.x) + sqr(newPos.y-oldPos.y) + sqr(newPos.z-oldPos.z)); //DEBUG_LOG(("noTurnDist goes from %f to %f",m_noTurnDistLeft,m_noTurnDistLeft-distThisTurn)); m_noTurnDistLeft -= distThisTurn; } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp index 12762dcd3b0..e5f7fbde981 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp @@ -102,7 +102,7 @@ static Real angleBetweenVectors(const Coord3D& inCurDir, const Coord3D& inGoalDi static Real heightToSpeed(Real height) { // don't bother trying to remember how far we've fallen; instead, - // back-calc it from our speed & gravity... v = sqrt(2*g*h) + // back-calc it from our speed & gravity... v = Sqrt(2*g*h) return WWMath::Sqrt(fabs(2.0f * TheGlobalData->m_gravity * height)); } @@ -144,7 +144,7 @@ PhysicsBehaviorModuleData::PhysicsBehaviorModuleData() static void parseHeightToSpeed( INI* ini, void * /*instance*/, void *store, const void* /*userData*/ ) { // don't bother trying to remember how far we've fallen; instead, - // back-calc it from our speed & gravity... v = sqrt(2*g*h) + // back-calc it from our speed & gravity... v = Sqrt(2*g*h) Real height = INI::scanReal(ini->getNextToken()); *(Real *)store = heightToSpeed(height); } @@ -850,7 +850,7 @@ UpdateSleepTime PhysicsBehavior::update() // // don't bother trying to remember how far we've fallen; instead, - // we back-calc it from our speed & gravity... v = sqrt(2*g*h). + // we back-calc it from our speed & gravity... v = Sqrt(2*g*h). // (note that m_minFallSpeedForDamage is always POSITIVE.) // // also note: since projectiles are immune to falling damage, don't @@ -944,7 +944,7 @@ Real PhysicsBehavior::getVelocityMagnitude() const { if (m_velMag == INVALID_VEL_MAG) { - m_velMag = (Real)sqrtf( sqr(m_vel.x) + sqr(m_vel.y) + sqr(m_vel.z) ); + m_velMag = (Real)Sqrt( sqr(m_vel.x) + sqr(m_vel.y) + sqr(m_vel.z) ); } return m_velMag; } @@ -964,9 +964,9 @@ Real PhysicsBehavior::getForwardSpeed2D() const Real dot = vx + vy; Real speedSquared = vx*vx + vy*vy; -// DEBUG_ASSERTCRASH( speedSquared != 0, ("zero speedSquared will overflow sqrtf()!") );// lorenzen... sanity check +// DEBUG_ASSERTCRASH( speedSquared != 0, ("zero speedSquared will overflow Sqrt()!") );// lorenzen... sanity check - Real speed = (Real)sqrtf( speedSquared ); + Real speed = (Real)Sqrt( speedSquared ); if (dot >= 0.0f) return speed; @@ -989,7 +989,7 @@ Real PhysicsBehavior::getForwardSpeed3D() const Real dot = vx + vy + vz; - Real speed = (Real)sqrtf( vx*vx + vy*vy + vz*vz ); + Real speed = (Real)Sqrt( vx*vx + vy*vy + vz*vz ); if (dot >= 0.0f) return speed; @@ -1036,7 +1036,7 @@ void PhysicsBehavior::scrubVelocity2D( Real desiredVelocity ) } else { - Real curVelocity = sqrtf(m_vel.x*m_vel.x + m_vel.y*m_vel.y); + Real curVelocity = Sqrt(m_vel.x*m_vel.x + m_vel.y*m_vel.y); if (desiredVelocity > curVelocity) { return; @@ -1321,7 +1321,7 @@ void PhysicsBehavior::onCollide( Object *other, const Coord3D *loc, const Coord3 m_lastCollidee = other->getID(); - Real dist = sqrtf(distSqr); + Real dist = Sqrt(distSqr); Real overlap = usRadius + themRadius - dist; // if objects are coincident, dist is zero, so force would be infinite -- clearly diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp index 643aa40a5b4..20ec42299bc 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp @@ -167,7 +167,7 @@ void PointDefenseLaserUpdate::fireWhenReady() bonus.clear(); Real fireRange = data->m_weaponTemplate->getAttackRange( bonus ); Object *me = getObject(); - Real fDist = sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); + Real fDist = Sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); if( fDist < fireRange ) { //We are currently in range! @@ -290,7 +290,7 @@ Object* PointDefenseLaserUpdate::scanClosestTarget() continue; } - Real fDist = sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); + Real fDist = Sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); if( fDist <= fireRange ) { @@ -317,7 +317,7 @@ Object* PointDefenseLaserUpdate::scanClosestTarget() pos.add( other->getPosition() ); //Recalculate the distance. - fDist = sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); + fDist = Sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); } } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp index 03a29dd00db..445f9981438 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp @@ -860,7 +860,7 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate Real attackRangeSqr = sqr(getAttackRange(bonus)); if (distSqr > attackRangeSqr) { - //DEBUG_ASSERTCRASH(distSqr < 5*5 || distSqr < attackRangeSqr*1.2f, ("*** victim is out of range (%f vs %f) of this weapon -- why did we attempt to fire?",sqrtf(distSqr),sqrtf(attackRangeSqr))); + //DEBUG_ASSERTCRASH(distSqr < 5*5 || distSqr < attackRangeSqr*1.2f, ("*** victim is out of range (%f vs %f) of this weapon -- why did we attempt to fire?",Sqrt(distSqr),Sqrt(attackRangeSqr))); //-extraLogging #if defined(RTS_DEBUG) @@ -882,7 +882,7 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate if (distSqr < minAttackRangeSqr-0.5f && !isProjectileDetonation) #endif { - DEBUG_ASSERTCRASH(distSqr > minAttackRangeSqr*0.8f, ("*** victim is closer than min attack range (%f vs %f) of this weapon -- why did we attempt to fire?",sqrtf(distSqr),sqrtf(minAttackRangeSqr))); + DEBUG_ASSERTCRASH(distSqr > minAttackRangeSqr*0.8f, ("*** victim is closer than min attack range (%f vs %f) of this weapon -- why did we attempt to fire?",Sqrt(distSqr),Sqrt(minAttackRangeSqr))); //-extraLogging #if defined(RTS_DEBUG) diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp index b4e678aa1d6..c565e91b7e9 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp @@ -845,7 +845,7 @@ static void populateRandomStartPosition( GameInfo *game ) { Coord3D p1 = c1->second; Coord3D p2 = c2->second; - startSpotDistance[i][j] = sqrt( sqr(p1.x-p2.x) + sqr(p1.y-p2.y) ); + startSpotDistance[i][j] = Sqrt( sqr(p1.x-p2.x) + sqr(p1.y-p2.y) ); } } else From 96b8b432aca63cf69c9154f44115976a9e2843b4 Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Fri, 17 Apr 2026 14:33:14 +0300 Subject: [PATCH 06/13] fix: Route base Generals trig functions and Sqrt through WWMath --- .../GameEngine/Source/Common/System/Trig.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Generals/Code/GameEngine/Source/Common/System/Trig.cpp b/Generals/Code/GameEngine/Source/Common/System/Trig.cpp index 2ed9b27e301..3ea14f64e7c 100644 --- a/Generals/Code/GameEngine/Source/Common/System/Trig.cpp +++ b/Generals/Code/GameEngine/Source/Common/System/Trig.cpp @@ -34,6 +34,7 @@ #include "Lib/BaseType.h" #include "Lib/trig.h" +#include "WWMath/wwmath.h" #define TWOPI 6.28318530718f #define DEG2RAD 0.0174532925199f @@ -48,32 +49,37 @@ Real Sin(Real x) { - return sinf(x); + return WWMath::Sin(x); } Real Cos(Real x) { - return cosf(x); + return WWMath::Cos(x); } Real Tan(Real x) { - return tanf(x); + return WWMath::Tan(x); } Real ACos(Real x) { - return acosf(x); + return WWMath::Acos(x); } Real ASin(Real x) { - return asinf(x); + return WWMath::Asin(x); } Real Atan2(Real y, Real x) { - return atan2f(y, x); + return WWMath::Atan2(y, x); +} + +Real Sqrt(Real x) +{ + return WWMath::Sqrt(x); } #ifdef REGENERATE_TRIG_TABLES From 9bf56a660e97b31682d1c46c7dd8225da79133c8 Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Fri, 17 Apr 2026 15:18:51 +0300 Subject: [PATCH 07/13] fix: Replace remaining FPU trig and sqrt functions with deterministic WWMath wrappers in GameLogic --- .../Source/Common/System/BuildAssistant.cpp | 10 +++---- .../Source/Common/System/Geometry.cpp | 18 ++++++------ .../GameEngine/Source/GameLogic/AI/AI.cpp | 2 +- .../Source/GameLogic/AI/AIGroup.cpp | 4 +-- .../Source/GameLogic/AI/AIPlayer.cpp | 6 ++-- .../Source/GameLogic/AI/AISkirmishPlayer.cpp | 8 +++--- .../Source/GameLogic/AI/AIStates.cpp | 10 +++---- .../Source/GameLogic/Map/PolygonTrigger.cpp | 2 +- .../Source/GameLogic/Map/TerrainLogic.cpp | 4 +-- .../Behavior/DumbProjectileBehavior.cpp | 12 ++++---- .../Behavior/GenerateMinefieldBehavior.cpp | 2 +- .../Object/Behavior/MinefieldBehavior.cpp | 4 +-- .../Object/Behavior/SlowDeathBehavior.cpp | 2 +- .../Source/GameLogic/Object/Locomotor.cpp | 28 +++++++++---------- .../GameLogic/Object/ObjectCreationList.cpp | 8 +++--- .../GameLogic/Object/PartitionManager.cpp | 28 +++++++++---------- .../GameLogic/Object/Update/AIUpdate.cpp | 8 +++--- .../Update/AIUpdate/ChinookAIUpdate.cpp | 2 +- .../AIUpdate/DeliverPayloadAIUpdate.cpp | 10 +++---- .../Object/Update/AIUpdate/JetAIUpdate.cpp | 6 ++-- .../Update/AIUpdate/MissileAIUpdate.cpp | 6 ++-- .../Update/AIUpdate/RailroadGuideAIUpdate.cpp | 4 +-- .../Object/Update/CleanupHazardUpdate.cpp | 4 +-- .../Object/Update/CommandButtonHuntUpdate.cpp | 2 +- .../DockUpdate/SupplyWarehouseDockUpdate.cpp | 2 +- .../DynamicShroudClearingRangeUpdate.cpp | 4 +-- .../GameLogic/Object/Update/FloatUpdate.cpp | 4 +-- .../Object/Update/NeutronMissileUpdate.cpp | 4 +-- .../Update/ParticleUplinkCannonUpdate.cpp | 6 ++-- .../GameLogic/Object/Update/PhysicsUpdate.cpp | 24 ++++++++-------- .../Object/Update/PointDefenseLaserUpdate.cpp | 6 ++-- .../GameLogic/Object/Update/ToppleUpdate.cpp | 2 +- .../Source/GameLogic/Object/Weapon.cpp | 12 ++++---- .../Source/GameLogic/System/GameLogic.cpp | 2 +- .../Source/GameLogic/Map/TerrainLogic.cpp | 2 +- .../Behavior/DumbProjectileBehavior.cpp | 4 +-- .../Update/ParticleUplinkCannonUpdate.cpp | 4 +-- 37 files changed, 133 insertions(+), 133 deletions(-) diff --git a/Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp b/Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp index ccb32fa1bf6..96b103e14ba 100644 --- a/Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp +++ b/Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp @@ -752,8 +752,8 @@ Bool BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos, if (myFactoryExitWidth>0) { myExitPos = *worldPos; checkMyExit = true; - Real c = (Real)cos(angle); - Real s = (Real)sin(angle); + Real c = (Real)Cos(angle); + Real s = (Real)Sin(angle); Real offset = build->getTemplateGeometryInfo().getMajorRadius() + myFactoryExitWidth/2.0f; myExitPos.x += c*offset; myExitPos.y += s*offset; @@ -787,8 +787,8 @@ Bool BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos, if (themFactoryExitWidth>0) { hisExitPos = *them->getPosition(); checkHisExit = true; - Real c = (Real)cos(them->getOrientation()); - Real s = (Real)sin(them->getOrientation()); + Real c = (Real)Cos(them->getOrientation()); + Real s = (Real)Sin(them->getOrientation()); Real offset = them->getGeometryInfo().getMajorRadius() + themFactoryExitWidth/2.0f; hisExitPos.x += c*offset; hisExitPos.y += s*offset; @@ -1405,7 +1405,7 @@ Bool BuildAssistant::moveObjectsForConstruction( const ThingTemplate *whatToBuil Bool anyUnmovables = false; MemoryPoolObjectHolder hold( iter ); - Real radius = sqrt(pow(gi.getMajorRadius(), 2) + pow(gi.getMinorRadius(), 2)); + Real radius = Sqrt(pow(gi.getMajorRadius(), 2) + pow(gi.getMinorRadius(), 2)); radius *= 1.4f; // Fudge the distance, for( Object *them = iter->first(); them; them = iter->next() ) diff --git a/Generals/Code/GameEngine/Source/Common/System/Geometry.cpp b/Generals/Code/GameEngine/Source/Common/System/Geometry.cpp index f33da731b42..6bce5b2c9ac 100644 --- a/Generals/Code/GameEngine/Source/Common/System/Geometry.cpp +++ b/Generals/Code/GameEngine/Source/Common/System/Geometry.cpp @@ -173,17 +173,17 @@ void GeometryInfo::calcPitches(const Coord3D& thisPos, const GeometryInfo& that, Coord3D thisCenter; getCenterPosition(thisPos, thisCenter); - Real dxy = sqrt(sqr(thatPos.x - thisCenter.x) + sqr(thatPos.y - thisCenter.y)); + Real dxy = Sqrt(sqr(thatPos.x - thisCenter.x) + sqr(thatPos.y - thisCenter.y)); Real dz; /** @todo srj -- this could be better, by calcing it for all the corners, not just top-center and bottom-center... oh well */ dz = (thatPos.z + that.getMaxHeightAbovePosition()) - thisCenter.z; - maxPitch = atan2(dz, dxy); + maxPitch = Atan2(dz, dxy); dz = (thatPos.z - that.getMaxHeightBelowPosition()) - thisCenter.z; - minPitch = atan2(dz, dxy); + minPitch = Atan2(dz, dxy); } //============================================================================= @@ -279,8 +279,8 @@ void GeometryInfo::get2DBounds(const Coord3D& geomCenter, Real angle, Region2D& case GEOMETRY_BOX: { - Real c = (Real)cos(angle); - Real s = (Real)sin(angle); + Real c = (Real)Cos(angle); + Real s = (Real)Sin(angle); Real exc = m_majorRadius*c; Real eyc = m_minorRadius*c; Real exs = m_majorRadius*s; @@ -329,7 +329,7 @@ void GeometryInfo::clipPointToFootprint(const Coord3D& geomCenter, Coord3D& ptTo { Real dx = ptToClip.x - geomCenter.x; Real dy = ptToClip.y - geomCenter.y; - Real radius = sqrt(sqr(dx) + sqr(dy)); + Real radius = Sqrt(sqr(dx) + sqr(dy)); if (radius > m_majorRadius) { Real ratio = m_majorRadius / radius; @@ -361,7 +361,7 @@ Bool GeometryInfo::isPointInFootprint(const Coord3D& geomCenter, const Coord3D& { Real dx = pt.x - geomCenter.x; Real dy = pt.y - geomCenter.y; - Real radius = sqrt(sqr(dx) + sqr(dy)); + Real radius = Sqrt(sqr(dx) + sqr(dy)); return (radius <= m_majorRadius); break; } @@ -506,8 +506,8 @@ void GeometryInfo::calcBoundingStuff() case GEOMETRY_BOX: { - m_boundingCircleRadius = sqrt(sqr(m_majorRadius) + sqr(m_minorRadius)); - m_boundingSphereRadius = sqrt(sqr(m_majorRadius) + sqr(m_minorRadius) + sqr(m_height*0.5)); + m_boundingCircleRadius = Sqrt(sqr(m_majorRadius) + sqr(m_minorRadius)); + m_boundingSphereRadius = Sqrt(sqr(m_majorRadius) + sqr(m_minorRadius) + sqr(m_height*0.5)); break; } }; diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AI.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AI.cpp index e3c879cf3a1..3386101856b 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AI.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AI.cpp @@ -706,7 +706,7 @@ Object *AI::findClosestEnemy( const Object *me, Real range, UnsignedInt qualifie } Real distSqr = ThePartitionManager->getDistanceSquared(me, theEnemy, FROM_BOUNDINGSPHERE_2D); - Real dist = sqrt(distSqr); + Real dist = Sqrt(distSqr); Int modifier = dist/getAiData()->m_attackPriorityDistanceModifier; Int modPriority = curPriority-modifier; if (modPriority < 1) diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp index 39f78bc9a4a..0c1b12c6008 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp @@ -1839,8 +1839,8 @@ void getHelicopterOffset( Coord3D& posOut, Int idx ) } Coord3D tempCtr = posOut; - posOut.x = tempCtr.x + (sin(angle) * radius); - posOut.y = tempCtr.y + (cos(angle) * radius); + posOut.x = tempCtr.x + (Sin(angle) * radius); + posOut.y = tempCtr.y + (Cos(angle) * radius); } diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp index b96483a33b5..e82bed17ed9 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp @@ -640,7 +640,7 @@ Object *AIPlayer::buildStructureWithDozer(const ThingTemplate *bldgPlan, BuildLi dx = dozer->getPosition()->x - pos.x; dy = dozer->getPosition()->y - pos.y; - Int count = sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); + Int count = Sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); if (count<2) count = 2; Int i; color.green = 1; @@ -1245,7 +1245,7 @@ Int AIPlayer::getPlayerSuperweaponValue(Coord3D *center, Int playerNdx, Real rad Real dx = center->x - pos.x; Real dy = center->y - pos.y; if (dx*dx+dy*dygetTemplate()->calcCostToBuild(pPlayer); if (pObj->isKindOf(KINDOF_COMMANDCENTER)) { @@ -2807,7 +2807,7 @@ void AIPlayer::computeCenterAndRadiusOfBase(Coord3D *center, Real *radius) Real radSqr = dx*dx+dy*dy; if (radSqr>maxRadSqr) maxRadSqr=radSqr; } - *radius = sqrt(maxRadSqr); + *radius = Sqrt(maxRadSqr); } //---------------------------------------------------------------------------------------------------------- diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp index afb876af064..a46fc9dc6e1 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp @@ -663,8 +663,8 @@ void AISkirmishPlayer::buildAIBaseDefenseStructure(const AsciiString &thingName, } if (angle > PI/3) break; - Real s = sin(angle); - Real c = cos(angle); + Real s = Sin(angle); + Real c = Cos(angle); // TheSuperHackers @info helmutbuhler 21/04/2025 This debug mutates the code to become CRC incompatible #if defined(RTS_DEBUG) || !RETAIL_COMPATIBLE_CRC @@ -1029,8 +1029,8 @@ void AISkirmishPlayer::adjustBuildList(BuildListInfo *list) angle += 3*PI/4; - Real s = sin(angle); - Real c = cos(angle); + Real s = Sin(angle); + Real c = Cos(angle); cur = list; while (cur) { diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp index 3ac19981a52..7e1db2210d4 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp @@ -3572,7 +3572,7 @@ StateReturnType AIAttackMoveToState::update() if (distSqr < sqr(ATTACK_CLOSE_ENOUGH_CELLS*PATHFIND_CELL_SIZE_F)) { return ret; } - DEBUG_LOG(("AIAttackMoveToState::update Distance from goal %f, retrying.", sqrt(distSqr))); + DEBUG_LOG(("AIAttackMoveToState::update Distance from goal %f, retrying.", Sqrt(distSqr))); ret = STATE_CONTINUE; m_retryCount--; @@ -3802,16 +3802,16 @@ void AIFollowWaypointPathState::computeGoal(Bool useGroupOffsets) if (m_priorWaypoint) { dx = dest.x - m_priorWaypoint->getLocation()->x; dy = dest.y - m_priorWaypoint->getLocation()->y; - angle = atan2(dy, dx); + angle = Atan2(dy, dx); Real deltaAngle = angle - m_angle; - Real s = sin(deltaAngle); - Real c = cos(deltaAngle); + Real s = Sin(deltaAngle); + Real c = Cos(deltaAngle); Real x = m_groupOffset.x * c - m_groupOffset.y * s; Real y = m_groupOffset.y * c + m_groupOffset.x * s; m_groupOffset.x = x; m_groupOffset.y = y; } else { - angle = atan2(dy, dx); + angle = Atan2(dy, dx); } m_angle = angle; #endif diff --git a/Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp b/Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp index 6cea7c6227a..9c6e2b3dacb 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp @@ -270,7 +270,7 @@ void PolygonTrigger::updateBounds() const Real halfWidth = (m_bounds.hi.x - m_bounds.lo.x) / 2.0f; Real halfHeight = (m_bounds.hi.y + m_bounds.lo.y) / 2.0f; - m_radius = sqrt(halfHeight*halfHeight + halfWidth*halfWidth); + m_radius = Sqrt(halfHeight*halfHeight + halfWidth*halfWidth); } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp b/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp index aa5e8887434..fd356ea6929 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp @@ -1468,7 +1468,7 @@ void makeAlignToNormalMatrix( Real angle, const Coord3D& pos, const Coord3D& nor /* It is extremely important that the resulting matrix is such that the xvector points in the angle we specified; specifically, - that atan2(xvec.y, xvec.x) == angle. So we must construct + that Atan2(xvec.y, xvec.x) == angle. So we must construct the matrix carefully to ensure this! */ x.x = Cos( angle ); @@ -2369,7 +2369,7 @@ void TerrainLogic::setWaterHeight( const WaterHandle *water, Real height, Real d center.z = 0.0f; // irrelavant // the max radius to scan around us is the diagonal of the bounding region - Real maxDist = sqrt( affectedRegion.width() * affectedRegion.width() + + Real maxDist = Sqrt( affectedRegion.width() * affectedRegion.width() + affectedRegion.height() * affectedRegion.height() ); // scan the objects in the area of the water affected diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp index 9684b87cdcd..19cdc291ca9 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp @@ -169,11 +169,11 @@ static Bool calcTrajectory( Real dz = end.z - start.z; // calculating the angle is trivial. - angle = atan2(dy, dx); + angle = Atan2(dy, dx); // calculating the pitch requires a bit more effort. Real horizDistSqr = sqr(dx) + sqr(dy); - Real horizDist = sqrt(horizDistSqr); + Real horizDist = Sqrt(horizDistSqr); // calc the two possible pitches that will cover the given horizontal range. // (this is actually only true if dz==0, but is a good first guess) @@ -182,7 +182,7 @@ static Bool calcTrajectory( // let's start by aiming directly for it. we know this isn't right (unless gravity // is zero, which it's not) but is a good starting point... - Real theta = atan2(dz, horizDist); + Real theta = Atan2(dz, horizDist); // if the angle isn't pretty shallow, we can get a better initial guess by using // the code below... const Real SHALLOW_ANGLE = 0.5f * PI / 180.0f; @@ -287,7 +287,7 @@ static Bool calcTrajectory( #endif vx = velocity*cosPitches[preferred]; - Real actualRange = (vx*(vz + sqrt(root)))/gravity; + Real actualRange = (vx*(vz + Sqrt(root)))/gravity; const Real CLOSE_ENOUGH_RANGE = 5.0f; if (tooClose || (actualRange < horizDist - CLOSE_ENOUGH_RANGE)) { @@ -366,7 +366,7 @@ void DumbProjectileBehavior::projectileFireAtObjectOrPosition( const Object *vic // Some weapons want to scale their start speed to the range Real minRange = detWeap->getMinimumAttackRange(); Real maxRange = detWeap->getUnmodifiedAttackRange(); - Real range = sqrt(ThePartitionManager->getDistanceSquared( projectile, &victimPosToUse, FROM_CENTER_2D ) ); + Real range = Sqrt(ThePartitionManager->getDistanceSquared( projectile, &victimPosToUse, FROM_CENTER_2D ) ); Real rangeRatio = (range - minRange) / (maxRange - minRange); m_flightPathSpeed = (rangeRatio * (weaponSpeed - minWeaponSpeed)) + minWeaponSpeed; } @@ -596,7 +596,7 @@ UpdateSleepTime DumbProjectileBehavior::update() Real distVictimMovedSqr = sqr(delta.x) + sqr(delta.y) + sqr(delta.z); if (distVictimMovedSqr > 0.1f) { - Real distVictimMoved = sqrtf(distVictimMovedSqr); + Real distVictimMoved = Sqrt(distVictimMovedSqr); if (distVictimMoved > d->m_flightPathAdjustDistPerFrame) distVictimMoved = d->m_flightPathAdjustDistPerFrame; delta.normalize(); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp index b37cf0f2ab3..ab6dbb4d1ad 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp @@ -232,7 +232,7 @@ void GenerateMinefieldBehavior::placeMinesAlongLine(const Coord3D& posStart, con Real dx = posEnd.x - posStart.x; Real dy = posEnd.y - posStart.y; - Real len = sqrt(sqr(dx) + sqr(dy)); + Real len = Sqrt(sqr(dx) + sqr(dy)); Real mineRadius = mineTemplate->getTemplateGeometryInfo().getBoundingCircleRadius(); Real mineDiameter = mineRadius * 2.0f; Real mineJitter = mineRadius*d->m_randomJitter; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp index 5a4b2727060..62cf3c37a48 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp @@ -562,7 +562,7 @@ void MinefieldBehavior::setScootParms(const Coord3D& start, const Coord3D& end) if (start.z > endOnGround.z) { // figure out how long it will take to fall, and replace scoot time with that - UnsignedInt fallingTime = REAL_TO_INT_CEIL(sqrtf(2.0f * (start.z - endOnGround.z) / fabs(TheGlobalData->m_gravity))); + UnsignedInt fallingTime = REAL_TO_INT_CEIL(Sqrt(2.0f * (start.z - endOnGround.z) / fabs(TheGlobalData->m_gravity))); // we can scoot after we land, but don't want to stop scooting before we land if (scootFromStartingPointTime < fallingTime) scootFromStartingPointTime = fallingTime; @@ -580,7 +580,7 @@ void MinefieldBehavior::setScootParms(const Coord3D& start, const Coord3D& end) Real dx = endOnGround.x - start.x; Real dy = endOnGround.y - start.y; Real dz = endOnGround.z - start.z; - Real dist = sqrt(sqr(dx) + sqr(dy)); + Real dist = Sqrt(sqr(dx) + sqr(dy)); if (dist <= 0.1f && fabs(dz) <= 0.1f) { obj->setPosition(&endOnGround); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp index 5f52385005c..8a655c1c7a4 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp @@ -299,7 +299,7 @@ void SlowDeathBehavior::beginSlowDeath(const DamageInfo *damageInfo) physics->setExtraBounciness(-1.0); // we don't want this guy to bounce at all physics->setExtraFriction(-3 * SECONDS_PER_LOGICFRAME_REAL); // reduce his ground friction a bit physics->setAllowBouncing(true); - Real orientation = atan2(force.y, force.x); + Real orientation = Atan2(force.y, force.x); physics->setAngles(orientation, 0, 0); obj->getDrawable()->setModelConditionState(MODELCONDITION_EXPLODED_FLAILING); m_flags |= (1<getPosition()->x; Real dy = goalPos.y - obj->getPosition()->y; Real dz = goalPos.z - obj->getPosition()->z; - Real dist = sqrt(dx*dx+dy*dy); + Real dist = Sqrt(dx*dx+dy*dy); if (dist>onPathDistToGoal) { if (!obj->isKindOf(KINDOF_PROJECTILE) && dist>2*onPathDistToGoal) @@ -1083,7 +1083,7 @@ void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalP // Projectiles never stop braking once they start. jba. obj->setStatus( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_BRAKING ) ); // Projectiles cheat in 3 dimensions. - dist = sqrt(dx*dx+dy*dy+dz*dz); + dist = Sqrt(dx*dx+dy*dy+dz*dz); Real vel = physics->getVelocityMagnitude(); if (vel < MIN_VEL) vel = MIN_VEL; @@ -1258,7 +1258,7 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, Real angle = obj->getOrientation(); // Real relAngle = ThePartitionManager->getRelativeAngle2D( obj, &goalPos ); // Real desiredAngle = angle + relAngle; - Real desiredAngle = atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real relAngle = stdAngleDiff(desiredAngle, angle); Bool moveBackwards = false; @@ -1533,7 +1533,7 @@ Bool Locomotor::fixInvalidPosition(Object* obj, PhysicsBehavior *physics) //physics->clearAcceleration(); if (dot<0) { - dot = sqrt(-dot); + dot = Sqrt(-dot); correctionNormalized.x *= dot*physics->getMass(); correctionNormalized.y *= dot*physics->getMass(); physics->applyMotiveForce(&correctionNormalized); @@ -1597,7 +1597,7 @@ void Locomotor::moveTowardsPositionLegs(Object* obj, PhysicsBehavior *physics, c Real angle = obj->getOrientation(); // Real relAngle = ThePartitionManager->getRelativeAngle2D( obj, &goalPos ); // Real desiredAngle = angle + relAngle; - Real desiredAngle = atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); if (m_template->m_wanderWidthFactor != 0.0f) { Real angleLimit = PI/8 * m_template->m_wanderWidthFactor; @@ -1730,7 +1730,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, Real angle = obj->getOrientation(); // Real relAngle = ThePartitionManager->getRelativeAngle2D( obj, &goalPos ); // Real desiredAngle = angle + relAngle; - Real desiredAngle = atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real relAngle = stdAngleDiff(desiredAngle, angle); if (moveBackwards) { @@ -1821,7 +1821,7 @@ void Locomotor::moveTowardsPositionWings(Object* obj, PhysicsBehavior *physics, Real angleTowardPos = (isNearlyZero(dx) && isNearlyZero(dy)) ? obj->getOrientation() : - atan2(dy, dx); + Atan2(dy, dx); Real aimDir = (PI - PI/8); angleTowardPos += aimDir; @@ -2055,7 +2055,7 @@ Real Locomotor::calcLiftToUseAtPt(Object* obj, PhysicsBehavior *physics, Real cu // thus // a = 2(dz - v t)/t^2 // and - // t = (-v +- sqrt(v*v + 2*a*dz))/a + // t = (-v +- Sqrt(v*v + 2*a*dz))/a // // but if we assume t=1, then // a=2(dz-v) @@ -2117,7 +2117,7 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 Real dy = goalPos.y - turnPos.y; // If we are very close to the goal, we twitch due to rounding error. So just return. jba. if (fabs(dx)<0.1f && fabs(dy)<0.1f) return TURN_NONE; - Real desiredAngle = atan2(dy, dx); + Real desiredAngle = Atan2(dy, dx); Real amount = stdAngleDiff(desiredAngle, angle); if (relAngle) *relAngle = amount; if (amount>maxTurnRate) { @@ -2139,7 +2139,7 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 // so, the thing is, we want to rotate ourselves so that our *center* is rotated // by the given amount, but the rotation must be around turnPos. so do a little // back-calculation. - Real angleDesiredForTurnPos = atan2(desiredPos.y - turnPos.y, desiredPos.x - turnPos.x); + Real angleDesiredForTurnPos = Atan2(desiredPos.y - turnPos.y, desiredPos.x - turnPos.x); amount = angleDesiredForTurnPos - angle; #endif /// @todo srj -- there's probably a more efficient & more direct way to do this. find it. @@ -2155,7 +2155,7 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 } else { - Real desiredAngle = atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real amount = stdAngleDiff(desiredAngle, angle); if (relAngle) *relAngle = amount; if (amount>maxTurnRate) { @@ -2488,7 +2488,7 @@ void Locomotor::maintainCurrentPositionWings(Object* obj, PhysicsBehavior *physi Real angleTowardMaintainPos = (isNearlyZero(dx) && isNearlyZero(dy)) ? obj->getOrientation() : - atan2(dy, dx); + Atan2(dy, dx); Real aimDir = (PI - PI/8); if (turnRadius < 0) diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp index c3508284362..927cada1c7f 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp @@ -281,7 +281,7 @@ class DeliverPayloadNugget : public ObjectCreationNugget Real dy = primary->y - secondary->y; //Calc length - Real length = sqrt( dx*dx + dy*dy ); + Real length = Sqrt( dx*dx + dy*dy ); //Normalize length dx /= length; @@ -348,7 +348,7 @@ class DeliverPayloadNugget : public ObjectCreationNugget } - Real orient = atan2( moveToPos.y - startPos.y, moveToPos.x - startPos.x); + Real orient = Atan2( moveToPos.y - startPos.y, moveToPos.x - startPos.x); if( m_data.m_distToTarget > 0 ) { const Real SLOP = 1.5f; @@ -1067,7 +1067,7 @@ class GenericObjectCreationNugget : public ObjectCreationNugget objUp->applyForce(&force); if (m_orientInForceDirection) - orientation = atan2(force.y, force.x); + orientation = Atan2(force.y, force.x); } } @@ -1155,7 +1155,7 @@ class GenericObjectCreationNugget : public ObjectCreationNugget objUp->applyForce(&force); if (m_orientInForceDirection) { - orientation = atan2(force.y, force.x); + orientation = Atan2(force.y, force.x); } DUMPREAL(orientation); objUp->setAngles(orientation, 0, 0); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp index 2bb86292763..41e1e91b446 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp @@ -617,7 +617,7 @@ inline Bool z_collideTest_Sphere_Nonsphere(CollideTestProc xyproc, const Collide // find the radius of the slice of the sphere that is at b_bot CollideInfo amod = *a; amod.position.z = b_bot; - amod.geom.setMajorRadius((Real)sqrtf(sqr(a->geom.getMajorRadius()) - sqr(b_bot - a->position.z))); + amod.geom.setMajorRadius((Real)Sqrt(sqr(a->geom.getMajorRadius()) - sqr(b_bot - a->position.z))); if (xyproc(&amod, b, cinfo)) { // if you want to have 'end' collisions, you should add something like: @@ -635,7 +635,7 @@ inline Bool z_collideTest_Sphere_Nonsphere(CollideTestProc xyproc, const Collide { CollideInfo amod = *a; amod.position.z = b_top; - amod.geom.setMajorRadius((Real)sqrtf(sqr(a->geom.getMajorRadius()) - sqr(a->position.z - b_top))); + amod.geom.setMajorRadius((Real)Sqrt(sqr(a->geom.getMajorRadius()) - sqr(a->position.z - b_top))); if (xyproc(&amod, b, cinfo)) { // if you want to have 'end' collisions, you should add something like: @@ -823,7 +823,7 @@ static Bool distCalcProc_BoundaryAndBoundary_2D( if (totalRad > 0.0f) { - Real actualDist = sqrtf(actualDistSqr); + Real actualDist = Sqrt(actualDistSqr); Real shrunkenDist = actualDist - totalRad; if (shrunkenDist <= 0.0f) { @@ -911,7 +911,7 @@ static Bool distCalcProc_BoundaryAndBoundary_3D( Real totalRad = (geomA?geomA->getBoundingSphereRadius():0) + (geomB?geomB->getBoundingSphereRadius():0); if (totalRad > 0.0f) { - Real actualDist = sqrtf(actualDistSqr); + Real actualDist = Sqrt(actualDistSqr); Real shrunkenDist = actualDist - totalRad; if (shrunkenDist <= 0.0f) { @@ -2219,7 +2219,7 @@ Int PartitionData::calcMaxCoiForShape(GeometryType geom, Real majorRadius, Real } case GEOMETRY_BOX: { - Real diagonal = (Real)(sqrtf(majorRadius*majorRadius + minorRadius*minorRadius)); + Real diagonal = (Real)(Sqrt(majorRadius*majorRadius + minorRadius*minorRadius)); Int cells = ThePartitionManager->worldToCellDist(diagonal*2) + 1; result = cells * cells; break; @@ -3210,7 +3210,7 @@ Int PartitionManager::calcMinRadius(const ICoord2D& cur) } // double, not real - double dist = sqrtf(minDistSqr); + double dist = Sqrt(minDistSqr); Int minRadius = REAL_TO_INT_CEIL( dist / m_cellSize ); return minRadius; @@ -3228,7 +3228,7 @@ void PartitionManager::calcRadiusVec() // double, not real double dx = (double)cx * (double)cellSize; double dy = (double)cy * (double)cellSize; - double maxPossibleDist = sqrt(dx*dx + dy*dy); + double maxPossibleDist = Sqrt(dx*dx + dy*dy); m_maxGcoRadius = REAL_TO_INT_CEIL(maxPossibleDist / cellSize); @@ -3498,7 +3498,7 @@ Object *PartitionManager::getClosestObjects( } if (closestDistArg) { - *closestDistArg = (Real)sqrtf(closestDistSqr); + *closestDistArg = (Real)Sqrt(closestDistSqr); } #ifdef RTS_DEBUG @@ -3625,7 +3625,7 @@ Real PartitionManager::getRelativeAngle2D( const Object *obj, const Coord3D *pos v.y = pos->y - objPos.y; v.z = 0.0f; - Real dist = (Real)sqrtf(sqr(v.x) + sqr(v.y)); + Real dist = (Real)Sqrt(sqr(v.x) + sqr(v.y)); // normalize if (dist == 0.0f) @@ -4556,7 +4556,7 @@ Int PartitionManager::iterateCellsBreadthFirst(const Coord3D *pos, CellBreadthFi //----------------------------------------------------------------------------- static Real calcDist2D(Real x1, Real y1, Real x2, Real y2) { - return sqrtf(sqr(x1-x2) + sqr(y1-y2)); + return Sqrt(sqr(x1-x2) + sqr(y1-y2)); } //----------------------------------------------------------------------------- @@ -5715,7 +5715,7 @@ void hLineAddThreat(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); + distance = Sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5743,7 +5743,7 @@ void hLineRemoveThreat(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); + distance = Sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5771,7 +5771,7 @@ void hLineAddValue(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); + distance = Sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5799,7 +5799,7 @@ void hLineRemoveValue(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); + distance = Sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp index dd3b07d378d..20e1036e125 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp @@ -2230,7 +2230,7 @@ UpdateSleepTime AIUpdateInterface::doLocomotor() } else { - Real dist = sqrtf(dSqr); + Real dist = Sqrt(dSqr); if (dist<1) dist = 1; pos.x += 2*PATHFIND_CELL_SIZE_F*dx/(dist*LOGICFRAMES_PER_SECOND); pos.y += 2*PATHFIND_CELL_SIZE_F*dy/(dist*LOGICFRAMES_PER_SECOND); @@ -2424,7 +2424,7 @@ Real AIUpdateInterface::getLocomotorDistanceToGoal() dest = m_path->getLastNode()->getPosition(); } Real distance = ThePartitionManager->getDistanceSquared( me, dest, FROM_CENTER_3D ); - return sqrt( distance );// Other paths return dots of normalized vectors, so one sqrt ain't so bad + return Sqrt( distance );// Other paths return dots of normalized vectors, so one sqrt ain't so bad } else { @@ -2456,7 +2456,7 @@ Real AIUpdateInterface::getLocomotorDistanceToGoal() { if (sqr(dist) > distSqr) { - return sqrt(distSqr); + return Sqrt(distSqr); } else { @@ -2465,7 +2465,7 @@ Real AIUpdateInterface::getLocomotorDistanceToGoal() } if (distgetExtent( &terrainExtent ); const Real FUDGE = 1.2f; - Real HUGE_DIST = FUDGE * sqrt(sqr(terrainExtent.hi.x - terrainExtent.lo.x) + sqr(terrainExtent.hi.y - terrainExtent.lo.y)); + Real HUGE_DIST = FUDGE * Sqrt(sqr(terrainExtent.hi.x - terrainExtent.lo.x) + sqr(terrainExtent.hi.y - terrainExtent.lo.y)); exitCoord.x += dir->x * HUGE_DIST; exitCoord.y += dir->y * HUGE_DIST; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp index a6f15066955..ce0e0c0860d 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp @@ -201,8 +201,8 @@ UpdateSleepTime DeliverPayloadAIUpdate::update() { //Calc strafe ratio Real startDiveDistance = getData()->m_diveStartDistance; - Real endDiveDistance = sqrt( endDiveDistanceSquared ); - Real currentDistance = sqrt( currentDistanceSquared ); + Real endDiveDistance = Sqrt( endDiveDistanceSquared ); + Real currentDistance = Sqrt( currentDistanceSquared ); Real diveRatio = (startDiveDistance - currentDistance) / (startDiveDistance - endDiveDistance); @@ -367,7 +367,7 @@ Bool DeliverPayloadAIUpdate::isCloseEnoughToTarget() if ( inBound ) allowedDistanceSqr = sqr(getAllowedDistanceToTarget() + getPreOpenDistance()); - //DEBUG_LOG(("Dist to target is %f (allowed %f)",sqrt(currentDistanceSqr),sqrt(allowedDistanceSqr))); + //DEBUG_LOG(("Dist to target is %f (allowed %f)",Sqrt(currentDistanceSqr),Sqrt(allowedDistanceSqr))); if ( allowedDistanceSqr > currentDistanceSqr ) @@ -1081,7 +1081,7 @@ StateReturnType RecoverFromOffMapState::update() // Success if we should try aga enterCoord.z = owner->getPosition()->z; owner->setPosition(&enterCoord); - Real enterAngle = atan2(ai->getMoveToPos()->y - enterCoord.y, ai->getMoveToPos()->x - enterCoord.x); + Real enterAngle = Atan2(ai->getMoveToPos()->y - enterCoord.y, ai->getMoveToPos()->x - enterCoord.x); owner->setOrientation(enterAngle); PhysicsBehavior* physics = owner->getPhysics(); @@ -1121,7 +1121,7 @@ StateReturnType HeadOffMapState::onEnter() // Give move order out of town Region3D terrainExtent; TheTerrainLogic->getExtent( &terrainExtent ); const Real FUDGE = 1.2f; - Real HUGE_DIST = FUDGE * sqrt(sqr(terrainExtent.hi.x - terrainExtent.lo.x) + sqr(terrainExtent.hi.y - terrainExtent.lo.y)); + Real HUGE_DIST = FUDGE * Sqrt(sqr(terrainExtent.hi.x - terrainExtent.lo.x) + sqr(terrainExtent.hi.y - terrainExtent.lo.y)); exitCoord.x += dir->x * HUGE_DIST; exitCoord.y += dir->y * HUGE_DIST; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp index 6693caf829d..14e55dc6c70 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp @@ -457,7 +457,7 @@ class JetOrHeliTaxiState : public AIMoveOutOfTheWayState Coord3D intermedPt; Bool intermed = false; - Real orient = atan2(ppinfo.runwayPrep.y - ppinfo.parkingSpace.y, ppinfo.runwayPrep.x - ppinfo.parkingSpace.x); + Real orient = Atan2(ppinfo.runwayPrep.y - ppinfo.parkingSpace.y, ppinfo.runwayPrep.x - ppinfo.parkingSpace.x); if (fabs(stdAngleDiff(orient, ppinfo.parkingOrientation)) > PI/128) { intermedPt.z = (ppinfo.parkingSpace.z + ppinfo.runwayPrep.z) * 0.5f; @@ -884,7 +884,7 @@ class HeliTakeoffOrLandingState : public State } else { - Real dist = sqrtf(dSqr); + Real dist = Sqrt(dSqr); if (dist<1) dist = 1; pos.x += PATHFIND_CELL_SIZE_F*dx/(dist*LOGICFRAMES_PER_SECOND); pos.y += PATHFIND_CELL_SIZE_F*dy/(dist*LOGICFRAMES_PER_SECOND); @@ -2070,7 +2070,7 @@ void JetAIUpdate::positionLockon() Real dx = getObject()->getPosition()->x - pos.x; Real dy = getObject()->getPosition()->y - pos.y; if (dx || dy) - m_lockonDrawable->setOrientation(atan2(dy, dx)); + m_lockonDrawable->setOrientation(Atan2(dy, dx)); // the Gaussian sum, to avoid keeping a running total: // diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp index 688a0918a5a..2a873797bd9 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp @@ -223,7 +223,7 @@ void MissileAIUpdate::projectileFireAtObjectOrPosition( const Object *victim, co Real deltaZ = victimPos->z - obj->getPosition()->z; Real dx = victimPos->x - obj->getPosition()->x; Real dy = victimPos->y - obj->getPosition()->y; - Real xyDist = sqrt(sqr(dx)+sqr(dy)); + Real xyDist = Sqrt(sqr(dx)+sqr(dy)); if (xyDist<1) xyDist = 1; Real zFactor = 0; if (deltaZ>0) { @@ -581,7 +581,7 @@ void MissileAIUpdate::doKillState() closeEnough = curLoco->getMaxSpeedForCondition(BODY_PRISTINE); } Real distanceToTargetSq = ThePartitionManager->getDistanceSquared( getObject(), getGoalObject(), FROM_CENTER_3D); - //DEBUG_LOG(("Distance to target %f, closeEnough %f", sqrt(distanceToTargetSq), closeEnough)); + //DEBUG_LOG(("Distance to target %f, closeEnough %f", Sqrt(distanceToTargetSq), closeEnough)); if (distanceToTargetSq < closeEnough*closeEnough) { Coord3D pos = *getGoalObject()->getPosition(); getObject()->setPosition(&pos); @@ -619,7 +619,7 @@ UpdateSleepTime MissileAIUpdate::update() Coord3D newPos = *getObject()->getPosition(); if (m_noTurnDistLeft > 0.0f && m_state >= IGNITION) { - Real distThisTurn = sqrtf(sqr(newPos.x-m_prevPos.x) + sqr(newPos.y-m_prevPos.y) + sqr(newPos.z-m_prevPos.z)); + Real distThisTurn = Sqrt(sqr(newPos.x-m_prevPos.x) + sqr(newPos.y-m_prevPos.y) + sqr(newPos.z-m_prevPos.z)); m_noTurnDistLeft -= distThisTurn; m_prevPos = newPos; } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp index 283d7926a9d..a3e6eb6986d 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp @@ -315,7 +315,7 @@ void RailroadBehavior::onCollide( Object *other, const Coord3D *loc, const Coord m_whistleSound.setPlayingHandle(TheAudio->addAudioEvent( &m_whistleSound )); - Real dist = (Real)sqrtf( dlt.x*dlt.x + dlt.y*dlt.y + dlt.z*dlt.z); + Real dist = (Real)Sqrt( dlt.x*dlt.x + dlt.y*dlt.y + dlt.z*dlt.z); Real usRadius = obj->getGeometryInfo().getMajorRadius(); Real themRadius = other->getGeometryInfo().getMajorRadius(); Real overlap = ((usRadius + themRadius) - dist) + 1;// the plus 1 makes them go just outside of me. @@ -1259,7 +1259,7 @@ void RailroadBehavior::updatePositionTrackDistance( PullInfo *pullerInfo, PullIn trackPosDelta.z = 0; Real dx = pullerInfo->towHitchPosition.x - turnPos.x; Real dy = pullerInfo->towHitchPosition.y - turnPos.y; - Real desiredAngle = atan2(dy, dx); + Real desiredAngle = Atan2(dy, dx); Real relAngle = stdAngleDiff(desiredAngle, obj->getTransformMatrix()->Get_Z_Rotation()); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp index 8a23910d7d3..4a98b25ab61 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp @@ -172,7 +172,7 @@ UpdateSleepTime CleanupHazardUpdate::update() AIUpdateInterface *ai = obj->getAI(); if( ai && (ai->isIdle() || ai->isBusy()) ) { - Real fDist = sqrt( ThePartitionManager->getDistanceSquared( obj, &m_pos, FROM_CENTER_2D ) ); + Real fDist = Sqrt( ThePartitionManager->getDistanceSquared( obj, &m_pos, FROM_CENTER_2D ) ); if( fDist < 25.0f ) { //Abort clean area because there's nothing left to clean! @@ -204,7 +204,7 @@ void CleanupHazardUpdate::fireWhenReady() bonus.clear(); Real fireRange = m_weaponTemplate->getAttackRange( bonus ); Object *me = getObject(); - Real fDist = sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); + Real fDist = Sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); if( fDist < fireRange ) { //We are currently in range! diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp index e7df932630c..90bdcea296b 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp @@ -290,7 +290,7 @@ Object* CommandButtonHuntUpdate::scanClosestTarget() } } Real distSqr = ThePartitionManager->getDistanceSquared(me, other, FROM_BOUNDINGSPHERE_2D); - Real dist = sqrt(distSqr); + Real dist = Sqrt(distSqr); Int curPriority = data->m_scanRange - dist; if (info) curPriority = info->getPriority(other->getTemplate()); if (curPriority == 0) diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp index 62ac01c158a..6de7f898d74 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp @@ -95,7 +95,7 @@ Bool SupplyWarehouseDockUpdate::action( Object* docker, Object *drone ) Real closeEnoughSqr = sqr(docker->getGeometryInfo().getBoundingCircleRadius()*2); Real curDistSqr = ThePartitionManager->getDistanceSquared(docker, getObject(), FROM_BOUNDINGSPHERE_2D); if (curDistSqr > closeEnoughSqr) { - DEBUG_LOG(("Failing dock, dist %f, not close enough(%f).", sqrt(curDistSqr), sqrt(closeEnoughSqr))); + DEBUG_LOG(("Failing dock, dist %f, not close enough(%f).", Sqrt(curDistSqr), Sqrt(closeEnoughSqr))); // Make it twitch a little. Coord3D newPos = *docker->getPosition(); Real range = 0.4*PATHFIND_CELL_SIZE_F; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp index 5ad5b511a23..66550acad5d 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp @@ -166,8 +166,8 @@ void DynamicShroudClearingRangeUpdate::animateGridDecals() for (int d = 0; d < GRID_FX_DECAL_COUNT; ++d) { - pos.x = ctr->x + (sinf(angle) * radius); - pos.y = ctr->y + (cosf(angle) * radius); + pos.x = ctr->x + (Sin(angle) * radius); + pos.y = ctr->y + (Cos(angle) * radius); pos.x -= ((Int)pos.x)%23; pos.y -= ((Int)pos.y)%23; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp index 29f256c4801..e1c48f1c00d 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp @@ -119,8 +119,8 @@ UpdateSleepTime FloatUpdate::update() { Real angle = INT_TO_REAL(TheGameLogic->getFrame()); - Real yaw = sin(angle * 0.0291f) * 0.05f; - Real pitch = sin(angle * 0.0515f) * 0.05f; + Real yaw = Sin(angle * 0.0291f) * 0.05f; + Real pitch = Sin(angle * 0.0515f) * 0.05f; Matrix3D mx = *draw->getInstanceMatrix(); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp index 9bf55521dde..e9e107ccbf8 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp @@ -418,7 +418,7 @@ void NeutronMissileUpdate::doAttack() pos.z += m_vel.z; //DEBUG_LOG(("vel %f accel %f z %f",m_vel.length(),m_accel.length(), pos.z)); -//Real vm = sqrt(m_vel.x*m_vel.x+m_vel.y*m_vel.y+m_vel.z*m_vel.z); +//Real vm = Sqrt(m_vel.x*m_vel.x+m_vel.y*m_vel.y+m_vel.z*m_vel.z); //DEBUG_LOG(("vel is %f %f %f (%f)",m_vel.x,m_vel.y,m_vel.z,vm)); getObject()->setTransformMatrix( &mx ); getObject()->setPosition( &pos ); @@ -512,7 +512,7 @@ UpdateSleepTime NeutronMissileUpdate::update() if (m_noTurnDistLeft > 0.0f && oldPosValid) { Coord3D newPos = *getObject()->getPosition(); - Real distThisTurn = sqrt(sqr(newPos.x-oldPos.x) + sqr(newPos.y-oldPos.y) + sqr(newPos.z-oldPos.z)); + Real distThisTurn = Sqrt(sqr(newPos.x-oldPos.x) + sqr(newPos.y-oldPos.y) + sqr(newPos.z-oldPos.z)); //DEBUG_LOG(("noTurnDist goes from %f to %f",m_noTurnDistLeft,m_noTurnDistLeft-distThisTurn)); m_noTurnDistLeft -= distThisTurn; } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp index 980a9c525af..2efe5d60715 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp @@ -474,12 +474,12 @@ UpdateSleepTime ParticleUplinkCannonUpdate::update() //First determine the factor of time completed (ranges between 0.0 and 1.0) Real factor = (Real)(now - orbitalBirthFrame) / (Real)(orbitalDeathFrame - orbitalBirthFrame); - //We're generating a swath that travels the points between sin( -1PI ) and sin( 1PI ) + //We're generating a swath that travels the points between Sin( -1PI ) and Sin( 1PI ) Real radians = (factor * TWO_PI) - PI; Real cxDistance = (factor * data->m_swathOfDeathDistance ) - (data->m_swathOfDeathDistance * 0.5f); //cx is cartesian x //Now calculate the amplitude value. - Real height = sin( radians ); + Real height = Sin( radians ); Real cxHeight = height * data->m_swathOfDeathAmplitude; Coord3D buildingToInitialTargetVector; @@ -501,7 +501,7 @@ UpdateSleepTime ParticleUplinkCannonUpdate::update() cartesianTargetVector.Normalize(); Real dotProduct = Vector2::Dot_Product( buildingToTargetVector, cartesianTargetVector ); - dotProduct = __min( 0.99999f, __max( -0.99999f, dotProduct ) ); //Account for numerical errors. Also, acos(-1.00000) is coming out QNAN on the superweapon general map. Heh. + dotProduct = __min( 0.99999f, __max( -0.99999f, dotProduct ) ); //Account for numerical errors. Also, ACos(-1.00000) is coming out QNAN on the superweapon general map. Heh. Real angle = (Real)ACos( dotProduct ); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp index a56790b941f..93bd1984ce5 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp @@ -92,8 +92,8 @@ static Real angleBetweenVectors(const Coord3D& inCurDir, const Coord3D& inGoalDi static Real heightToSpeed(Real height) { // don't bother trying to remember how far we've fallen; instead, - // back-calc it from our speed & gravity... v = sqrt(2*g*h) - return sqrt(fabs(2.0f * TheGlobalData->m_gravity * height)); + // back-calc it from our speed & gravity... v = Sqrt(2*g*h) + return Sqrt(fabs(2.0f * TheGlobalData->m_gravity * height)); } //------------------------------------------------------------------------------------------------- @@ -129,7 +129,7 @@ PhysicsBehaviorModuleData::PhysicsBehaviorModuleData() static void parseHeightToSpeed( INI* ini, void * /*instance*/, void *store, const void* /*userData*/ ) { // don't bother trying to remember how far we've fallen; instead, - // back-calc it from our speed & gravity... v = sqrt(2*g*h) + // back-calc it from our speed & gravity... v = Sqrt(2*g*h) Real height = INI::scanReal(ini->getNextToken()); *(Real *)store = heightToSpeed(height); } @@ -636,8 +636,8 @@ UpdateSleepTime PhysicsBehavior::update() if (offset != 0.0f) { Vector3 xvec = mtx.Get_X_Vector(); - Real xy = sqrtf(sqr(xvec.X) + sqr(xvec.Y)); - Real pitchAngle = atan2(xvec.Z, xy); + Real xy = Sqrt(sqr(xvec.X) + sqr(xvec.Y)); + Real pitchAngle = Atan2(xvec.Z, xy); Real remainingAngle = (offset > 0) ? ((PI/2) - pitchAngle) : (-(PI/2) + pitchAngle); Real s = Sin(remainingAngle); pitchRateToUse *= s; @@ -723,7 +723,7 @@ UpdateSleepTime PhysicsBehavior::update() // // don't bother trying to remember how far we've fallen; instead, - // we back-calc it from our speed & gravity... v = sqrt(2*g*h). + // we back-calc it from our speed & gravity... v = Sqrt(2*g*h). // (note that m_minFallSpeedForDamage is always POSITIVE.) // // also note: since projectiles are immune to falling damage, don't @@ -817,7 +817,7 @@ Real PhysicsBehavior::getVelocityMagnitude() const { if (m_velMag == INVALID_VEL_MAG) { - m_velMag = (Real)sqrtf( sqr(m_vel.x) + sqr(m_vel.y) + sqr(m_vel.z) ); + m_velMag = (Real)Sqrt( sqr(m_vel.x) + sqr(m_vel.y) + sqr(m_vel.z) ); } return m_velMag; } @@ -837,9 +837,9 @@ Real PhysicsBehavior::getForwardSpeed2D() const Real dot = vx + vy; Real speedSquared = vx*vx + vy*vy; -// DEBUG_ASSERTCRASH( speedSquared != 0, ("zero speedSquared will overflow sqrtf()!") );// lorenzen... sanity check +// DEBUG_ASSERTCRASH( speedSquared != 0, ("zero speedSquared will overflow Sqrt()!") );// lorenzen... sanity check - Real speed = (Real)sqrtf( speedSquared ); + Real speed = (Real)Sqrt( speedSquared ); if (dot >= 0.0f) return speed; @@ -862,7 +862,7 @@ Real PhysicsBehavior::getForwardSpeed3D() const Real dot = vx + vy + vz; - Real speed = (Real)sqrtf( vx*vx + vy*vy + vz*vz ); + Real speed = (Real)Sqrt( vx*vx + vy*vy + vz*vz ); if (dot >= 0.0f) return speed; @@ -909,7 +909,7 @@ void PhysicsBehavior::scrubVelocity2D( Real desiredVelocity ) } else { - Real curVelocity = sqrtf(m_vel.x*m_vel.x + m_vel.y*m_vel.y); + Real curVelocity = Sqrt(m_vel.x*m_vel.x + m_vel.y*m_vel.y); if (desiredVelocity > curVelocity) { return; @@ -1194,7 +1194,7 @@ void PhysicsBehavior::onCollide( Object *other, const Coord3D *loc, const Coord3 m_lastCollidee = other->getID(); - Real dist = sqrtf(distSqr); + Real dist = Sqrt(distSqr); Real overlap = usRadius + themRadius - dist; // if objects are coincident, dist is zero, so force would be infinite -- clearly diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp index 1e9302a3327..1c265805c7a 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp @@ -167,7 +167,7 @@ void PointDefenseLaserUpdate::fireWhenReady() bonus.clear(); Real fireRange = data->m_weaponTemplate->getAttackRange( bonus ); Object *me = getObject(); - Real fDist = sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); + Real fDist = Sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); if( fDist < fireRange ) { //We are currently in range! @@ -285,7 +285,7 @@ Object* PointDefenseLaserUpdate::scanClosestTarget() continue; } - Real fDist = sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); + Real fDist = Sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); if( fDist <= fireRange ) { @@ -312,7 +312,7 @@ Object* PointDefenseLaserUpdate::scanClosestTarget() pos.add( other->getPosition() ); //Recalculate the distance. - fDist = sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); + fDist = Sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); } } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp index bd725493a58..537d35974a2 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp @@ -185,7 +185,7 @@ void ToppleUpdate::applyTopplingForce( const Coord3D* toppleDirection, Real topp // yeah, it assumes the models are constructed appropriately, but is a cheap way // of minimizing the problem. (srj) Real curAngleX = normalizeAngle(getObject()->getOrientation()); - Real toppleAngle = normalizeAngle(atan2(m_toppleDirection.y, m_toppleDirection.x)); + Real toppleAngle = normalizeAngle(Atan2(m_toppleDirection.y, m_toppleDirection.x)); if (d->m_toppleLeftOrRightOnly) { // it's a fence or such, and can only topple left or right, so pick the closest diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp index 86f54c1081b..e8778106ea2 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp @@ -826,7 +826,7 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate Real attackRangeSqr = sqr(getAttackRange(bonus)); if (distSqr > attackRangeSqr) { - //DEBUG_ASSERTCRASH(distSqr < 5*5 || distSqr < attackRangeSqr*1.2f, ("*** victim is out of range (%f vs %f) of this weapon -- why did we attempt to fire?",sqrtf(distSqr),sqrtf(attackRangeSqr))); + //DEBUG_ASSERTCRASH(distSqr < 5*5 || distSqr < attackRangeSqr*1.2f, ("*** victim is out of range (%f vs %f) of this weapon -- why did we attempt to fire?",Sqrt(distSqr),Sqrt(attackRangeSqr))); //-extraLogging #if defined(RTS_DEBUG) @@ -848,7 +848,7 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate if (distSqr < minAttackRangeSqr-0.5f && !isProjectileDetonation) #endif { - DEBUG_ASSERTCRASH(distSqr > minAttackRangeSqr*0.8f, ("*** victim is closer than min attack range (%f vs %f) of this weapon -- why did we attempt to fire?",sqrtf(distSqr),sqrtf(minAttackRangeSqr))); + DEBUG_ASSERTCRASH(distSqr > minAttackRangeSqr*0.8f, ("*** victim is closer than min attack range (%f vs %f) of this weapon -- why did we attempt to fire?",Sqrt(distSqr),Sqrt(minAttackRangeSqr))); //-extraLogging #if defined(RTS_DEBUG) @@ -874,7 +874,7 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate targetPos.set( victimPos ); } Real reAngle = getWeaponRecoilAmount(); - Real reDir = reAngle != 0.0f ? (atan2(victimPos->y - sourcePos->y, victimPos->x - sourcePos->x)) : 0.0f; + Real reDir = reAngle != 0.0f ? (Atan2(victimPos->y - sourcePos->y, victimPos->x - sourcePos->x)) : 0.0f; VeterancyLevel v = sourceObj->getVeterancyLevel(); const FXList* fx = isProjectileDetonation ? getProjectileDetonateFX(v) : getFireFX(v); @@ -1921,7 +1921,7 @@ Bool Weapon::computeApproachTarget(const Object *source, const Object *target, c if (source->isAboveTerrain()) { // Don't do a 180 degree turn. - Real angle = atan2(-dir.y, -dir.x); + Real angle = Atan2(-dir.y, -dir.x); Real relAngle = source->getOrientation()- angle; if (relAngle>2*PI) relAngle -= 2*PI; if (relAngle<-2*PI) relAngle += 2*PI; @@ -1934,7 +1934,7 @@ Bool Weapon::computeApproachTarget(const Object *source, const Object *target, c if (angleOffset != 0.0f) { - Real angle = atan2(dir.y, dir.x); + Real angle = Atan2(dir.y, dir.x); dir.x = (Real)Cos(angle + angleOffset); dir.y = (Real)Sin(angle + angleOffset); } @@ -1981,7 +1981,7 @@ Bool Weapon::computeApproachTarget(const Object *source, const Object *target, c if (angleOffset != 0.0f) { - Real angle = atan2(dir.y, dir.x); + Real angle = Atan2(dir.y, dir.x); dir.x = (Real)Cos(angle + angleOffset); dir.y = (Real)Sin(angle + angleOffset); } diff --git a/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp index 780bdfff8a2..c3e81cdee1f 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp @@ -805,7 +805,7 @@ static void populateRandomStartPosition( GameInfo *game ) { Coord3D p1 = c1->second; Coord3D p2 = c2->second; - startSpotDistance[i][j] = sqrt( sqr(p1.x-p2.x) + sqr(p1.y-p2.y) ); + startSpotDistance[i][j] = Sqrt( sqr(p1.x-p2.x) + sqr(p1.y-p2.y) ); } } else diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp index bb9f4c1d2e6..a63b4539eb5 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp @@ -1468,7 +1468,7 @@ void makeAlignToNormalMatrix( Real angle, const Coord3D& pos, const Coord3D& nor /* It is extremely important that the resulting matrix is such that the xvector points in the angle we specified; specifically, - that atan2(xvec.y, xvec.x) == angle. So we must construct + that Atan2(xvec.y, xvec.x) == angle. So we must construct the matrix carefully to ensure this! */ x.x = Cos( angle ); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp index 11d22f49106..ae9c4537fad 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp @@ -172,7 +172,7 @@ static Bool calcTrajectory( Real dz = end.z - start.z; // calculating the angle is trivial. - angle = atan2(dy, dx); + angle = Atan2(dy, dx); // calculating the pitch requires a bit more effort. Real horizDistSqr = sqr(dx) + sqr(dy); @@ -185,7 +185,7 @@ static Bool calcTrajectory( // let's start by aiming directly for it. we know this isn't right (unless gravity // is zero, which it's not) but is a good starting point... - Real theta = atan2(dz, horizDist); + Real theta = Atan2(dz, horizDist); // if the angle isn't pretty shallow, we can get a better initial guess by using // the code below... const Real SHALLOW_ANGLE = 0.5f * PI / 180.0f; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp index 34d1b51672e..5f21db0f175 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp @@ -526,7 +526,7 @@ UpdateSleepTime ParticleUplinkCannonUpdate::update() //First determine the factor of time completed (ranges between 0.0 and 1.0) Real factor = (Real)(now - orbitalBirthFrame) / (Real)(orbitalDeathFrame - orbitalBirthFrame); - //We're generating a swath that travels the points between sin( -1PI ) and sin( 1PI ) + //We're generating a swath that travels the points between Sin( -1PI ) and Sin( 1PI ) Real radians = (factor * TWO_PI) - PI; Real cxDistance = (factor * data->m_swathOfDeathDistance ) - (data->m_swathOfDeathDistance * 0.5f); //cx is cartesian x @@ -553,7 +553,7 @@ UpdateSleepTime ParticleUplinkCannonUpdate::update() cartesianTargetVector.Normalize(); Real dotProduct = Vector2::Dot_Product( buildingToTargetVector, cartesianTargetVector ); - dotProduct = __min( 0.99999f, __max( -0.99999f, dotProduct ) ); //Account for numerical errors. Also, acos(-1.00000) is coming out QNAN on the superweapon general map. Heh. + dotProduct = __min( 0.99999f, __max( -0.99999f, dotProduct ) ); //Account for numerical errors. Also, ACos(-1.00000) is coming out QNAN on the superweapon general map. Heh. Real angle = (Real)ACos( dotProduct ); if( buildingToTargetVector.Y >= 0 ) From 585ecc359ccf83acfb78c2bc7378064207bf0eed Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Sat, 18 Apr 2026 04:16:21 +0300 Subject: [PATCH 08/13] refactor(math): Migrate legacy floating point math to deterministic WWMath wrappers Replaces non-deterministic trigonometric and generic floating point math function calls with deterministic counterparts from the WWMath library across the core codebase. This ensures mathematical parity to prevent frame desyncs during multiplayer lockstep execution, and includes build-fixes for missing WWMath namespaces and header removals. --- Core/CMakeLists.txt | 2 +- .../Source/GameClient/RadiusDecal.cpp | 2 +- .../Source/GameClient/System/ParticleSys.cpp | 6 +- .../Source/GameLogic/AI/AIPathfind.cpp | 12 +- .../W3DDevice/Common/System/W3DRadar.cpp | 24 +-- .../GameClient/Drawable/Draw/W3DRopeDraw.cpp | 6 +- .../W3DDevice/GameClient/W3DTreeBuffer.cpp | 6 +- Core/Libraries/Include/Lib/BaseType.h | 6 +- Core/Libraries/Include/Lib/trig.h | 32 ---- .../Source/WWVegas/WW3D2/CMakeLists.txt | 2 +- .../Libraries/Source/WWVegas/WW3D2/ww3dtrig.h | 52 ------ Generals/Code/GameEngine/CMakeLists.txt | 2 +- .../Source/Common/System/BuildAssistant.cpp | 10 +- .../Source/Common/System/Geometry.cpp | 22 +-- .../GameEngine/Source/Common/System/Trig.cpp | 156 ------------------ .../GameEngine/Source/Common/Thing/Thing.cpp | 10 +- .../GameEngine/Source/GameClient/Drawable.cpp | 12 +- .../Drawable/Update/SwayClientUpdate.cpp | 2 +- .../GameEngine/Source/GameLogic/AI/AI.cpp | 2 +- .../Source/GameLogic/AI/AIGroup.cpp | 4 +- .../Source/GameLogic/AI/AIPlayer.cpp | 6 +- .../Source/GameLogic/AI/AISkirmishPlayer.cpp | 8 +- .../Source/GameLogic/AI/AIStates.cpp | 14 +- .../Source/GameLogic/AI/TurretAI.cpp | 2 +- .../Source/GameLogic/Map/PolygonTrigger.cpp | 2 +- .../Source/GameLogic/Map/TerrainLogic.cpp | 16 +- .../Behavior/DumbProjectileBehavior.cpp | 24 +-- .../Behavior/GenerateMinefieldBehavior.cpp | 6 +- .../Object/Behavior/MinefieldBehavior.cpp | 4 +- .../Object/Behavior/ParkingPlaceBehavior.cpp | 4 +- .../Object/Behavior/SlowDeathBehavior.cpp | 2 +- .../Object/Contain/GarrisonContain.cpp | 8 +- .../GameLogic/Object/Contain/OpenContain.cpp | 4 +- .../Object/Contain/TunnelContain.cpp | 4 +- .../Source/GameLogic/Object/Locomotor.cpp | 54 +++--- .../GameLogic/Object/ObjectCreationList.cpp | 24 +-- .../GameLogic/Object/PartitionManager.cpp | 46 +++--- .../GameLogic/Object/Update/AIUpdate.cpp | 8 +- .../Update/AIUpdate/ChinookAIUpdate.cpp | 2 +- .../AIUpdate/DeliverPayloadAIUpdate.cpp | 10 +- .../Object/Update/AIUpdate/JetAIUpdate.cpp | 18 +- .../Update/AIUpdate/MissileAIUpdate.cpp | 6 +- .../Update/AIUpdate/RailroadGuideAIUpdate.cpp | 8 +- .../Object/Update/CleanupHazardUpdate.cpp | 4 +- .../Object/Update/CommandButtonHuntUpdate.cpp | 2 +- .../DockUpdate/SupplyWarehouseDockUpdate.cpp | 2 +- .../DynamicShroudClearingRangeUpdate.cpp | 4 +- .../GameLogic/Object/Update/FloatUpdate.cpp | 4 +- .../Update/HelicopterSlowDeathUpdate.cpp | 4 +- .../Object/Update/MobMemberSlavedUpdate.cpp | 4 +- .../Object/Update/NeutronMissileUpdate.cpp | 6 +- .../Update/ParticleUplinkCannonUpdate.cpp | 8 +- .../GameLogic/Object/Update/PhysicsUpdate.cpp | 28 ++-- .../Object/Update/PointDefenseLaserUpdate.cpp | 6 +- .../GameLogic/Object/Update/SlavedUpdate.cpp | 20 +-- .../GameLogic/Object/Update/StealthUpdate.cpp | 2 +- .../Object/Update/StructureToppleUpdate.cpp | 32 ++-- .../GameLogic/Object/Update/ToppleUpdate.cpp | 6 +- .../Object/Update/WaveGuideUpdate.cpp | 4 +- .../Source/GameLogic/Object/Weapon.cpp | 24 +-- .../GameLogic/ScriptEngine/ScriptEngine.cpp | 8 +- .../Source/GameLogic/System/GameLogic.cpp | 2 +- .../W3DDevice/GameClient/W3DParticleSys.cpp | 4 +- GeneralsMD/Code/GameEngine/CMakeLists.txt | 2 +- .../GameEngine/Source/Common/System/Trig.cpp | 156 ------------------ .../GameEngine/Source/Common/Thing/Thing.cpp | 10 +- .../GameEngine/Source/GameClient/Drawable.cpp | 20 +-- .../Drawable/Update/SwayClientUpdate.cpp | 2 +- .../GameEngine/Source/GameLogic/AI/AI.cpp | 2 +- .../Source/GameLogic/AI/AIPlayer.cpp | 6 +- .../Source/GameLogic/AI/AIStates.cpp | 6 +- .../Source/GameLogic/AI/TurretAI.cpp | 2 +- .../Source/GameLogic/Map/PolygonTrigger.cpp | 2 +- .../Source/GameLogic/Map/TerrainLogic.cpp | 18 +- .../Behavior/DumbProjectileBehavior.cpp | 24 +-- .../Object/Behavior/FlightDeckBehavior.cpp | 4 +- .../Behavior/GenerateMinefieldBehavior.cpp | 6 +- .../Object/Behavior/MinefieldBehavior.cpp | 4 +- .../Object/Behavior/ParkingPlaceBehavior.cpp | 4 +- .../Object/Behavior/SlowDeathBehavior.cpp | 2 +- .../Object/Contain/GarrisonContain.cpp | 8 +- .../GameLogic/Object/Contain/OpenContain.cpp | 4 +- .../Object/Contain/TunnelContain.cpp | 4 +- .../Source/GameLogic/Object/Locomotor.cpp | 28 ++-- .../GameLogic/Object/ObjectCreationList.cpp | 24 +-- .../GameLogic/Object/PartitionManager.cpp | 20 +-- .../GameLogic/Object/Update/AIUpdate.cpp | 8 +- .../AIUpdate/DeliverPayloadAIUpdate.cpp | 10 +- .../Object/Update/AIUpdate/JetAIUpdate.cpp | 18 +- .../Update/AIUpdate/MissileAIUpdate.cpp | 6 +- .../Update/AIUpdate/RailroadGuideAIUpdate.cpp | 8 +- .../Object/Update/CleanupHazardUpdate.cpp | 4 +- .../Object/Update/CommandButtonHuntUpdate.cpp | 2 +- .../DockUpdate/SupplyWarehouseDockUpdate.cpp | 2 +- .../DynamicShroudClearingRangeUpdate.cpp | 4 +- .../GameLogic/Object/Update/FloatUpdate.cpp | 4 +- .../Update/HelicopterSlowDeathUpdate.cpp | 4 +- .../Object/Update/MobMemberSlavedUpdate.cpp | 4 +- .../Object/Update/NeutronMissileUpdate.cpp | 6 +- .../Update/ParticleUplinkCannonUpdate.cpp | 8 +- .../GameLogic/Object/Update/PhysicsUpdate.cpp | 20 +-- .../Object/Update/PointDefenseLaserUpdate.cpp | 6 +- .../GameLogic/Object/Update/SlavedUpdate.cpp | 20 +-- .../Update/SpectreGunshipDeploymentUpdate.cpp | 2 +- .../GameLogic/Object/Update/StealthUpdate.cpp | 2 +- .../Object/Update/StructureToppleUpdate.cpp | 32 ++-- .../GameLogic/Object/Update/ToppleUpdate.cpp | 6 +- .../Object/Update/WaveGuideUpdate.cpp | 4 +- .../Source/GameLogic/Object/Weapon.cpp | 12 +- .../GameLogic/ScriptEngine/ScriptEngine.cpp | 8 +- .../Source/GameLogic/System/GameLogic.cpp | 2 +- .../W3DDevice/GameClient/W3DParticleSys.cpp | 4 +- 112 files changed, 496 insertions(+), 892 deletions(-) delete mode 100644 Core/Libraries/Include/Lib/trig.h delete mode 100644 Core/Libraries/Source/WWVegas/WW3D2/ww3dtrig.h delete mode 100644 Generals/Code/GameEngine/Source/Common/System/Trig.cpp delete mode 100644 GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp diff --git a/Core/CMakeLists.txt b/Core/CMakeLists.txt index 7c1269d1db9..1bb054f5f09 100644 --- a/Core/CMakeLists.txt +++ b/Core/CMakeLists.txt @@ -16,7 +16,7 @@ target_include_directories(corei_main INTERFACE "Main") target_sources(corei_libraries_include PRIVATE Libraries/Include/Lib/BaseType.h Libraries/Include/Lib/BaseTypeCore.h - Libraries/Include/Lib/trig.h + Libraries/Include/rts/debug.h Libraries/Include/rts/profile.h ) diff --git a/Core/GameEngine/Source/GameClient/RadiusDecal.cpp b/Core/GameEngine/Source/GameClient/RadiusDecal.cpp index c7863220aaf..8c5afd3d30a 100644 --- a/Core/GameEngine/Source/GameClient/RadiusDecal.cpp +++ b/Core/GameEngine/Source/GameClient/RadiusDecal.cpp @@ -194,7 +194,7 @@ void RadiusDecal::update() { UnsignedInt now = TheGameLogic->getFrame(); Real theta = (2*PI) * (Real)(now % m_template->m_opacityThrobTime) / (Real)m_template->m_opacityThrobTime; - Real percent = 0.5f * (Sin(theta) + 1.0f); + Real percent = 0.5f * (WWMath::Sin(theta) + 1.0f); Int opac; if( TheGameLogic->getDrawIconUI() ) { diff --git a/Core/GameEngine/Source/GameClient/System/ParticleSys.cpp b/Core/GameEngine/Source/GameClient/System/ParticleSys.cpp index 474fe5b5b2c..e69b8fd4c4b 100644 --- a/Core/GameEngine/Source/GameClient/System/ParticleSys.cpp +++ b/Core/GameEngine/Source/GameClient/System/ParticleSys.cpp @@ -584,8 +584,8 @@ void Particle::doWindMotion() (noForceDistance - fullForceDistance))); // integrate the wind motion into the position - m_pos.x += (Cos( windAngle ) * windForceStrength); - m_pos.y += (Sin( windAngle ) * windForceStrength); + m_pos.x += (WWMath::Cos( windAngle ) * windForceStrength); + m_pos.y += (WWMath::Sin( windAngle ) * windForceStrength); } @@ -3518,7 +3518,7 @@ static Real angleBetween(const Coord2D *vecA, const Coord2D *vecB) return 0.0f; } - Real theta = ACos( cosTheta ); + Real theta = WWMath::Acos( cosTheta ); if (vecB->x > 0) { return theta; diff --git a/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp b/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp index bb7a6c4fe24..8938f0bf66d 100644 --- a/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp +++ b/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp @@ -3956,8 +3956,8 @@ Bool PathfindLayer::isPointOnWall(ObjectID *wallPieces, Int numPieces, const Coo Real major = obj->getGeometryInfo().getMajorRadius(); Real minor = (obj->getGeometryInfo().getGeomType() == GEOMETRY_SPHERE) ? obj->getGeometryInfo().getMajorRadius() : obj->getGeometryInfo().getMinorRadius(); - Real c = (Real)Cos(-obj->getOrientation()); - Real s = (Real)Sin(-obj->getOrientation()); + Real c = (Real)WWMath::Cos(-obj->getOrientation()); + Real s = (Real)WWMath::Sin(-obj->getOrientation()); // convert to a delta relative to rect ctr Real ptx = pt->x - obj->getPosition()->x; @@ -4224,8 +4224,8 @@ void Pathfinder::classifyFence( Object *obj, Bool insert ) Real halfsizeY = PATHFIND_CELL_SIZE_F/10.0f; Real fenceOffset = obj->getTemplate()->getFenceXOffset(); - Real c = (Real)Cos(angle); - Real s = (Real)Sin(angle); + Real c = (Real)WWMath::Cos(angle); + Real s = (Real)WWMath::Sin(angle); const Real STEP_SIZE = PATHFIND_CELL_SIZE_F * 0.5f; // in theory, should be PATHFIND_CELL_SIZE_F exactly, but needs to be smaller to avoid aliasing problems Real ydx = s * STEP_SIZE; @@ -4432,8 +4432,8 @@ void Pathfinder::internal_classifyObjectFootprint( Object *obj, Bool insert ) Real halfsizeX = obj->getGeometryInfo().getMajorRadius(); Real halfsizeY = obj->getGeometryInfo().getMinorRadius(); - Real c = (Real)Cos(angle); - Real s = (Real)Sin(angle); + Real c = (Real)WWMath::Cos(angle); + Real s = (Real)WWMath::Sin(angle); const Real STEP_SIZE = PATHFIND_CELL_SIZE_F * 0.5f; // in theory, should be PATHFIND_CELL_SIZE_F exactly, but needs to be smaller to avoid aliasing problems Real ydx = s * STEP_SIZE; diff --git a/Core/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp b/Core/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp index 53a5299f152..aa2240cc405 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp @@ -403,16 +403,16 @@ void W3DRadar::drawSingleBeaconEvent( Int pixelX, Int pixelY, Int width, Int hei // create a triangle around the event angle = 0.0f - addAngle; - tri[ 0 ].x = REAL_TO_INT( (DOUBLE_TO_REAL( Cos( angle ) ) * eventSize) + event->radarLoc.x ); - tri[ 0 ].y = REAL_TO_INT( (DOUBLE_TO_REAL( Sin( angle ) ) * eventSize) + event->radarLoc.y ); + tri[ 0 ].x = REAL_TO_INT( (DOUBLE_TO_REAL( WWMath::Cos( angle ) ) * eventSize) + event->radarLoc.x ); + tri[ 0 ].y = REAL_TO_INT( (DOUBLE_TO_REAL( WWMath::Sin( angle ) ) * eventSize) + event->radarLoc.y ); angle = 2.0f * PI / 3.0f - addAngle; - tri[ 1 ].x = REAL_TO_INT( (DOUBLE_TO_REAL( Cos( angle ) ) * eventSize) + event->radarLoc.x ); - tri[ 1 ].y = REAL_TO_INT( (DOUBLE_TO_REAL( Sin( angle ) ) * eventSize) + event->radarLoc.y ); + tri[ 1 ].x = REAL_TO_INT( (DOUBLE_TO_REAL( WWMath::Cos( angle ) ) * eventSize) + event->radarLoc.x ); + tri[ 1 ].y = REAL_TO_INT( (DOUBLE_TO_REAL( WWMath::Sin( angle ) ) * eventSize) + event->radarLoc.y ); angle = -2.0f * PI / 3.0f - addAngle; - tri[ 2 ].x = REAL_TO_INT( (DOUBLE_TO_REAL( Cos( angle ) ) * eventSize) + event->radarLoc.x ); - tri[ 2 ].y = REAL_TO_INT( (DOUBLE_TO_REAL( Sin( angle ) ) * eventSize) + event->radarLoc.y ); + tri[ 2 ].x = REAL_TO_INT( (DOUBLE_TO_REAL( WWMath::Cos( angle ) ) * eventSize) + event->radarLoc.x ); + tri[ 2 ].y = REAL_TO_INT( (DOUBLE_TO_REAL( WWMath::Sin( angle ) ) * eventSize) + event->radarLoc.y ); // translate radar coords to screen coords radarToPixel( &tri[ 0 ], &tri[ 0 ], pixelX, pixelY, width, height ); @@ -502,16 +502,16 @@ void W3DRadar::drawSingleGenericEvent( Int pixelX, Int pixelY, Int width, Int he // create a triangle around the event angle = 0.0f - addAngle; - tri[ 0 ].x = REAL_TO_INT( (DOUBLE_TO_REAL( Cos( angle ) ) * eventSize) + event->radarLoc.x ); - tri[ 0 ].y = REAL_TO_INT( (DOUBLE_TO_REAL( Sin( angle ) ) * eventSize) + event->radarLoc.y ); + tri[ 0 ].x = REAL_TO_INT( (DOUBLE_TO_REAL( WWMath::Cos( angle ) ) * eventSize) + event->radarLoc.x ); + tri[ 0 ].y = REAL_TO_INT( (DOUBLE_TO_REAL( WWMath::Sin( angle ) ) * eventSize) + event->radarLoc.y ); angle = 2.0f * PI / 3.0f - addAngle; - tri[ 1 ].x = REAL_TO_INT( (DOUBLE_TO_REAL( Cos( angle ) ) * eventSize) + event->radarLoc.x ); - tri[ 1 ].y = REAL_TO_INT( (DOUBLE_TO_REAL( Sin( angle ) ) * eventSize) + event->radarLoc.y ); + tri[ 1 ].x = REAL_TO_INT( (DOUBLE_TO_REAL( WWMath::Cos( angle ) ) * eventSize) + event->radarLoc.x ); + tri[ 1 ].y = REAL_TO_INT( (DOUBLE_TO_REAL( WWMath::Sin( angle ) ) * eventSize) + event->radarLoc.y ); angle = -2.0f * PI / 3.0f - addAngle; - tri[ 2 ].x = REAL_TO_INT( (DOUBLE_TO_REAL( Cos( angle ) ) * eventSize) + event->radarLoc.x ); - tri[ 2 ].y = REAL_TO_INT( (DOUBLE_TO_REAL( Sin( angle ) ) * eventSize) + event->radarLoc.y ); + tri[ 2 ].x = REAL_TO_INT( (DOUBLE_TO_REAL( WWMath::Cos( angle ) ) * eventSize) + event->radarLoc.x ); + tri[ 2 ].y = REAL_TO_INT( (DOUBLE_TO_REAL( WWMath::Sin( angle ) ) * eventSize) + event->radarLoc.y ); // translate radar coords to screen coords radarToPixel( &tri[ 0 ], &tri[ 0 ], pixelX, pixelY, width, height ); diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DRopeDraw.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DRopeDraw.cpp index 11221d6a0b5..83d03677252 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DRopeDraw.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DRopeDraw.cpp @@ -84,8 +84,8 @@ void W3DRopeDraw::buildSegments() SegInfo info; Real axis = GameClientRandomValueReal(0, 2*PI); - info.wobbleAxisX = Cos(axis); - info.wobbleAxisY = Sin(axis); + info.wobbleAxisX = WWMath::Cos(axis); + info.wobbleAxisY = WWMath::Sin(axis); info.line = NEW Line3DClass( Vector3(pos.x,pos.y,pos.z), Vector3(pos.x,pos.y,pos.z+eachLen), m_width * 0.5f, // width @@ -186,7 +186,7 @@ void W3DRopeDraw::doDrawModule(const Matrix3D* transformMtx) if (!m_segments.empty()) { - Real deflection = Sin(m_curWobblePhase) * m_wobbleAmp; + Real deflection = WWMath::Sin(m_curWobblePhase) * m_wobbleAmp; const Coord3D* pos = getDrawable()->getPosition(); Vector3 start(pos->x, pos->y, pos->z + m_curZOffset); Real eachLen = m_curLen / m_segments.size(); diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp index aa86abc5f2a..a59b50fab53 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp @@ -351,10 +351,10 @@ void W3DTreeBuffer::updateSway(const BreezeInfo& info) { Int i; for (i=0; i 1.0) c = 1.0; - Real value = (Real)ACos( (Real)c ); + Real value = (Real)WWMath::ACos( (Real)c ); // Determine sign by checking Z component of dir cross vector // Note this is assumes 2D, and is identical to dotting the perpendicular of v with dir @@ -295,7 +295,7 @@ inline Real Coord2D::toAngle() const else if (c > 1.0f) c = 1.0f; - return y < 0.0f ? -ACos(c) : ACos(c); + return y < 0.0f ? -WWMath::ACos(c) : WWMath::ACos(c); #endif } diff --git a/Core/Libraries/Include/Lib/trig.h b/Core/Libraries/Include/Lib/trig.h deleted file mode 100644 index b406d001d07..00000000000 --- a/Core/Libraries/Include/Lib/trig.h +++ /dev/null @@ -1,32 +0,0 @@ -/* -** Command & Conquer Generals Zero Hour(tm) -** Copyright 2025 Electronic Arts Inc. -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -*/ - -// Trig.h -// fast trig functions -// Author: Sondra Iverson, March 1998 -// Converted to Generals by Matthew D. Campbell, February 2002 - -#pragma once - -Real Sin(Real); -Real Cos(Real); -Real Tan(Real); -Real ACos(Real); -Real ASin(Real x); -Real Atan2(Real y, Real x); -Real Sqrt(Real x); diff --git a/Core/Libraries/Source/WWVegas/WW3D2/CMakeLists.txt b/Core/Libraries/Source/WWVegas/WW3D2/CMakeLists.txt index cb9067a383a..fc5c946dc14 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/CMakeLists.txt +++ b/Core/Libraries/Source/WWVegas/WW3D2/CMakeLists.txt @@ -230,7 +230,7 @@ set(WW3D2_SRC ww3dformat.cpp ww3dformat.h ww3dids.h - ww3dtrig.h + ) add_library(corei_ww3d2 INTERFACE) diff --git a/Core/Libraries/Source/WWVegas/WW3D2/ww3dtrig.h b/Core/Libraries/Source/WWVegas/WW3D2/ww3dtrig.h deleted file mode 100644 index 2720d320ca2..00000000000 --- a/Core/Libraries/Source/WWVegas/WW3D2/ww3dtrig.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -** Command & Conquer Generals Zero Hour(tm) -** Copyright 2025 Electronic Arts Inc. -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -*/ - -/*********************************************************************************************** - *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S *** - *********************************************************************************************** - * * - * Project Name : WW3D * - * * - * $Archive:: /Commando/Code/ww3d2/ww3dtrig.h $* - * * - * $Author:: Greg_h $* - * * - * $Modtime:: 1/08/01 10:04a $* - * * - * $Revision:: 1 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#pragma once - -/* -** The WW3D Library will check for debugging triggers using the following ID's -** Your application may install a trigger handler into the WWDebug library and then -** watch for these ID's coming through. Then if you wish to "trigger" one, then -** assign a key or something to the trigger and when your trigger handler is called, -** check if the key is down. The trigger can be enabled in any way you want but -** in practice, most things will probably be tied to keys. -*/ -enum -{ - WW3D_TRIGGER_RENDER_STATS = 0x100, // display render stats in the debug window - WW3D_TRIGGER_SURFACE_CACHE_STATS = 0x101, // display surface cache info in the debug window - WW3D_TRIGGER_PROCESS_STATS = 0x102 // render stats for last frame only -}; diff --git a/Generals/Code/GameEngine/CMakeLists.txt b/Generals/Code/GameEngine/CMakeLists.txt index 73b6cc223bf..034cd391c76 100644 --- a/Generals/Code/GameEngine/CMakeLists.txt +++ b/Generals/Code/GameEngine/CMakeLists.txt @@ -618,7 +618,7 @@ set(GAMEENGINE_SRC Source/Common/System/StackDump.cpp # Source/Common/System/StreamingArchiveFile.cpp # Source/Common/System/SubsystemInterface.cpp - Source/Common/System/Trig.cpp + # Source/Common/System/UnicodeString.cpp Source/Common/System/Upgrade.cpp # Source/Common/System/Xfer.cpp diff --git a/Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp b/Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp index 96b103e14ba..3c7a4436d19 100644 --- a/Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp +++ b/Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp @@ -752,8 +752,8 @@ Bool BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos, if (myFactoryExitWidth>0) { myExitPos = *worldPos; checkMyExit = true; - Real c = (Real)Cos(angle); - Real s = (Real)Sin(angle); + Real c = (Real)WWMath::Cos(angle); + Real s = (Real)WWMath::Sin(angle); Real offset = build->getTemplateGeometryInfo().getMajorRadius() + myFactoryExitWidth/2.0f; myExitPos.x += c*offset; myExitPos.y += s*offset; @@ -787,8 +787,8 @@ Bool BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos, if (themFactoryExitWidth>0) { hisExitPos = *them->getPosition(); checkHisExit = true; - Real c = (Real)Cos(them->getOrientation()); - Real s = (Real)Sin(them->getOrientation()); + Real c = (Real)WWMath::Cos(them->getOrientation()); + Real s = (Real)WWMath::Sin(them->getOrientation()); Real offset = them->getGeometryInfo().getMajorRadius() + themFactoryExitWidth/2.0f; hisExitPos.x += c*offset; hisExitPos.y += s*offset; @@ -1405,7 +1405,7 @@ Bool BuildAssistant::moveObjectsForConstruction( const ThingTemplate *whatToBuil Bool anyUnmovables = false; MemoryPoolObjectHolder hold( iter ); - Real radius = Sqrt(pow(gi.getMajorRadius(), 2) + pow(gi.getMinorRadius(), 2)); + Real radius = WWMath::Sqrt(pow(gi.getMajorRadius(), 2) + pow(gi.getMinorRadius(), 2)); radius *= 1.4f; // Fudge the distance, for( Object *them = iter->first(); them; them = iter->next() ) diff --git a/Generals/Code/GameEngine/Source/Common/System/Geometry.cpp b/Generals/Code/GameEngine/Source/Common/System/Geometry.cpp index 6bce5b2c9ac..5f9697b9644 100644 --- a/Generals/Code/GameEngine/Source/Common/System/Geometry.cpp +++ b/Generals/Code/GameEngine/Source/Common/System/Geometry.cpp @@ -173,17 +173,17 @@ void GeometryInfo::calcPitches(const Coord3D& thisPos, const GeometryInfo& that, Coord3D thisCenter; getCenterPosition(thisPos, thisCenter); - Real dxy = Sqrt(sqr(thatPos.x - thisCenter.x) + sqr(thatPos.y - thisCenter.y)); + Real dxy = WWMath::Sqrt(sqr(thatPos.x - thisCenter.x) + sqr(thatPos.y - thisCenter.y)); Real dz; /** @todo srj -- this could be better, by calcing it for all the corners, not just top-center and bottom-center... oh well */ dz = (thatPos.z + that.getMaxHeightAbovePosition()) - thisCenter.z; - maxPitch = Atan2(dz, dxy); + maxPitch = WWMath::Atan2(dz, dxy); dz = (thatPos.z - that.getMaxHeightBelowPosition()) - thisCenter.z; - minPitch = Atan2(dz, dxy); + minPitch = WWMath::Atan2(dz, dxy); } //============================================================================= @@ -279,8 +279,8 @@ void GeometryInfo::get2DBounds(const Coord3D& geomCenter, Real angle, Region2D& case GEOMETRY_BOX: { - Real c = (Real)Cos(angle); - Real s = (Real)Sin(angle); + Real c = (Real)WWMath::Cos(angle); + Real s = (Real)WWMath::Sin(angle); Real exc = m_majorRadius*c; Real eyc = m_minorRadius*c; Real exs = m_majorRadius*s; @@ -329,7 +329,7 @@ void GeometryInfo::clipPointToFootprint(const Coord3D& geomCenter, Coord3D& ptTo { Real dx = ptToClip.x - geomCenter.x; Real dy = ptToClip.y - geomCenter.y; - Real radius = Sqrt(sqr(dx) + sqr(dy)); + Real radius = WWMath::Sqrt(sqr(dx) + sqr(dy)); if (radius > m_majorRadius) { Real ratio = m_majorRadius / radius; @@ -361,7 +361,7 @@ Bool GeometryInfo::isPointInFootprint(const Coord3D& geomCenter, const Coord3D& { Real dx = pt.x - geomCenter.x; Real dy = pt.y - geomCenter.y; - Real radius = Sqrt(sqr(dx) + sqr(dy)); + Real radius = WWMath::Sqrt(sqr(dx) + sqr(dy)); return (radius <= m_majorRadius); break; } @@ -398,8 +398,8 @@ void GeometryInfo::makeRandomOffsetWithinFootprint(Coord3D& pt) const #else Real radius = GameLogicRandomValueReal(0.0f, m_boundingCircleRadius); Real angle = GameLogicRandomValueReal(-PI, PI); - pt.x = radius * Cos(angle); - pt.y = radius * Sin(angle); + pt.x = radius * WWMath::Cos(angle); + pt.y = radius * WWMath::Sin(angle); pt.z = 0.0f; #endif break; @@ -506,8 +506,8 @@ void GeometryInfo::calcBoundingStuff() case GEOMETRY_BOX: { - m_boundingCircleRadius = Sqrt(sqr(m_majorRadius) + sqr(m_minorRadius)); - m_boundingSphereRadius = Sqrt(sqr(m_majorRadius) + sqr(m_minorRadius) + sqr(m_height*0.5)); + m_boundingCircleRadius = WWMath::Sqrt(sqr(m_majorRadius) + sqr(m_minorRadius)); + m_boundingSphereRadius = WWMath::Sqrt(sqr(m_majorRadius) + sqr(m_minorRadius) + sqr(m_height*0.5)); break; } }; diff --git a/Generals/Code/GameEngine/Source/Common/System/Trig.cpp b/Generals/Code/GameEngine/Source/Common/System/Trig.cpp deleted file mode 100644 index 3ea14f64e7c..00000000000 --- a/Generals/Code/GameEngine/Source/Common/System/Trig.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/* -** Command & Conquer Generals(tm) -** Copyright 2025 Electronic Arts Inc. -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -*/ - -//////////////////////////////////////////////////////////////////////////////// -// // -// (c) 2001-2003 Electronic Arts Inc. // -// // -//////////////////////////////////////////////////////////////////////////////// - -// Trig.cpp -// fast trig functions -// Author: Michael S. Booth, March 1994 -// Converted to Generals by Matthew D. Campbell, February 2002 - -#include "PreRTS.h" - -#include -#include - -#include "Lib/BaseType.h" -#include "Lib/trig.h" -#include "WWMath/wwmath.h" - -#define TWOPI 6.28318530718f -#define DEG2RAD 0.0174532925199f -#define TRIG_RES 4096 - -// the following are for fixed point ints with 12 fractional bits -#define INT_ONE 4096 -#define INT_TWOPI 25736 -#define INT_THREEPIOVERTWO 19302 -#define INT_PI 12868 -#define INT_HALFPI 6434 - -Real Sin(Real x) -{ - return WWMath::Sin(x); -} - -Real Cos(Real x) -{ - return WWMath::Cos(x); -} - -Real Tan(Real x) -{ - return WWMath::Tan(x); -} - -Real ACos(Real x) -{ - return WWMath::Acos(x); -} - -Real ASin(Real x) -{ - return WWMath::Asin(x); -} - -Real Atan2(Real y, Real x) -{ - return WWMath::Atan2(y, x); -} - -Real Sqrt(Real x) -{ - return WWMath::Sqrt(x); -} - -#ifdef REGENERATE_TRIG_TABLES -void initTrig() -{ - static Byte inited = FALSE; - Real angle, r; - int i; - - if (inited) - return; - - inited = TRUE; - - static int columns = 8; - int column = 0; - FILE *fp = fopen("trig.txt", "w"); - fprintf(fp, "static Int sinLookup[TRIG_RES] = {\n"); - for( i=0; igetGeometryInfo().getMajorRadius(); Real width = obj->getGeometryInfo().getMinorRadius(); - Real pitchHeight = length*Sin(m_locoInfo->m_pitch + m_locoInfo->m_accelerationPitch - groundPitch); - Real rollHeight = width*Sin(m_locoInfo->m_roll + m_locoInfo->m_accelerationRoll - groundRoll); + Real pitchHeight = length*WWMath::Sin(m_locoInfo->m_pitch + m_locoInfo->m_accelerationPitch - groundPitch); + Real rollHeight = width*WWMath::Sin(m_locoInfo->m_roll + m_locoInfo->m_accelerationRoll - groundRoll); info.m_totalZ = fabs(pitchHeight)/4 + fabs(rollHeight)/4; return; // maintain the same orientation while we fly through the air. } @@ -1899,8 +1899,8 @@ void Drawable::calcPhysicsXformWheels( const Locomotor *locomotor, PhysicsXformI // Calculate suspension info. Real length = obj->getGeometryInfo().getMajorRadius(); Real width = obj->getGeometryInfo().getMinorRadius(); - Real pitchHeight = length*Sin(info.m_totalPitch-groundPitch); - Real rollHeight = width*Sin(info.m_totalRoll-groundRoll); + Real pitchHeight = length*WWMath::Sin(info.m_totalPitch-groundPitch); + Real rollHeight = width*WWMath::Sin(info.m_totalRoll-groundRoll); if (DO_WHEELS) { // calculate each wheel position @@ -3705,8 +3705,8 @@ Bool Drawable::handleWeaponFireFX(WeaponSlotType wslot, Int specificBarrelToUse, recoilAngle += PI; if (m_locoInfo) { - m_locoInfo->m_accelerationPitchRate += recoilAmount * Cos(recoilAngle); - m_locoInfo->m_accelerationRollRate += recoilAmount * Sin(recoilAngle); + m_locoInfo->m_accelerationPitchRate += recoilAmount * WWMath::Cos(recoilAngle); + m_locoInfo->m_accelerationRollRate += recoilAmount * WWMath::Sin(recoilAngle); } } diff --git a/Generals/Code/GameEngine/Source/GameClient/Drawable/Update/SwayClientUpdate.cpp b/Generals/Code/GameEngine/Source/GameClient/Drawable/Update/SwayClientUpdate.cpp index 11b449b635c..da4e4122b76 100644 --- a/Generals/Code/GameEngine/Source/GameClient/Drawable/Update/SwayClientUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameClient/Drawable/Update/SwayClientUpdate.cpp @@ -121,7 +121,7 @@ void SwayClientUpdate::clientUpdate() m_curValue += m_curDelta * timeScale; if (m_curValue > 2*PI) m_curValue -= 2*PI; - Real cosine = Cos(m_curValue); + Real cosine = WWMath::Cos(m_curValue); Real targetAngle = cosine * m_curAngleLimit + m_leanAngle; Real deltaAngle = targetAngle - m_curAngle; diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AI.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AI.cpp index 3386101856b..172cdd49083 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AI.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AI.cpp @@ -706,7 +706,7 @@ Object *AI::findClosestEnemy( const Object *me, Real range, UnsignedInt qualifie } Real distSqr = ThePartitionManager->getDistanceSquared(me, theEnemy, FROM_BOUNDINGSPHERE_2D); - Real dist = Sqrt(distSqr); + Real dist = WWMath::Sqrt(distSqr); Int modifier = dist/getAiData()->m_attackPriorityDistanceModifier; Int modPriority = curPriority-modifier; if (modPriority < 1) diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp index 0c1b12c6008..a11919ad4f6 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp @@ -1839,8 +1839,8 @@ void getHelicopterOffset( Coord3D& posOut, Int idx ) } Coord3D tempCtr = posOut; - posOut.x = tempCtr.x + (Sin(angle) * radius); - posOut.y = tempCtr.y + (Cos(angle) * radius); + posOut.x = tempCtr.x + (WWMath::Sin(angle) * radius); + posOut.y = tempCtr.y + (WWMath::Cos(angle) * radius); } diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp index e82bed17ed9..fa0a8f9c308 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp @@ -640,7 +640,7 @@ Object *AIPlayer::buildStructureWithDozer(const ThingTemplate *bldgPlan, BuildLi dx = dozer->getPosition()->x - pos.x; dy = dozer->getPosition()->y - pos.y; - Int count = Sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); + Int count = WWMath::Sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); if (count<2) count = 2; Int i; color.green = 1; @@ -1245,7 +1245,7 @@ Int AIPlayer::getPlayerSuperweaponValue(Coord3D *center, Int playerNdx, Real rad Real dx = center->x - pos.x; Real dy = center->y - pos.y; if (dx*dx+dy*dygetTemplate()->calcCostToBuild(pPlayer); if (pObj->isKindOf(KINDOF_COMMANDCENTER)) { @@ -2807,7 +2807,7 @@ void AIPlayer::computeCenterAndRadiusOfBase(Coord3D *center, Real *radius) Real radSqr = dx*dx+dy*dy; if (radSqr>maxRadSqr) maxRadSqr=radSqr; } - *radius = Sqrt(maxRadSqr); + *radius = WWMath::Sqrt(maxRadSqr); } //---------------------------------------------------------------------------------------------------------- diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp index a46fc9dc6e1..382237663b9 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp @@ -663,8 +663,8 @@ void AISkirmishPlayer::buildAIBaseDefenseStructure(const AsciiString &thingName, } if (angle > PI/3) break; - Real s = Sin(angle); - Real c = Cos(angle); + Real s = WWMath::Sin(angle); + Real c = WWMath::Cos(angle); // TheSuperHackers @info helmutbuhler 21/04/2025 This debug mutates the code to become CRC incompatible #if defined(RTS_DEBUG) || !RETAIL_COMPATIBLE_CRC @@ -1029,8 +1029,8 @@ void AISkirmishPlayer::adjustBuildList(BuildListInfo *list) angle += 3*PI/4; - Real s = Sin(angle); - Real c = Cos(angle); + Real s = WWMath::Sin(angle); + Real c = WWMath::Cos(angle); cur = list; while (cur) { diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp index 7e1db2210d4..cdeb650612e 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp @@ -604,8 +604,8 @@ StateReturnType AIRappelState::update() bldg->getGeometryInfo().getBoundingCircleRadius()); Real angle = GameLogicRandomValueReal( PI, 2*PI );//Downish. Coord3D startPosition = *bldg->getPosition(); - startPosition.x += offset * Cos( angle ); - startPosition.y += offset * Sin( angle ); + startPosition.x += offset * WWMath::Cos( angle ); + startPosition.y += offset * WWMath::Sin( angle ); startPosition.z = TheTerrainLogic->getGroundHeight( startPosition.x, startPosition.y ); obj->setPosition( &startPosition ); @@ -3572,7 +3572,7 @@ StateReturnType AIAttackMoveToState::update() if (distSqr < sqr(ATTACK_CLOSE_ENOUGH_CELLS*PATHFIND_CELL_SIZE_F)) { return ret; } - DEBUG_LOG(("AIAttackMoveToState::update Distance from goal %f, retrying.", Sqrt(distSqr))); + DEBUG_LOG(("AIAttackMoveToState::update Distance from goal %f, retrying.", WWMath::Sqrt(distSqr))); ret = STATE_CONTINUE; m_retryCount--; @@ -3802,16 +3802,16 @@ void AIFollowWaypointPathState::computeGoal(Bool useGroupOffsets) if (m_priorWaypoint) { dx = dest.x - m_priorWaypoint->getLocation()->x; dy = dest.y - m_priorWaypoint->getLocation()->y; - angle = Atan2(dy, dx); + angle = WWMath::Atan2(dy, dx); Real deltaAngle = angle - m_angle; - Real s = Sin(deltaAngle); - Real c = Cos(deltaAngle); + Real s = WWMath::Sin(deltaAngle); + Real c = WWMath::Cos(deltaAngle); Real x = m_groupOffset.x * c - m_groupOffset.y * s; Real y = m_groupOffset.y * c + m_groupOffset.x * s; m_groupOffset.x = x; m_groupOffset.y = y; } else { - angle = Atan2(dy, dx); + angle = WWMath::Atan2(dy, dx); } m_angle = angle; #endif diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp index cbae6d63d4f..2e80ff7e55d 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp @@ -1100,7 +1100,7 @@ StateReturnType TurretAIAimTurretState::update() Real actualPitch; if( v.length() > 0 ) - actualPitch = ASin( v.z / v.length() ); + actualPitch = WWMath::Asin( v.z / v.length() ); else actualPitch = 0;// Don't point at NAN, just point at 0 if they are right on us diff --git a/Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp b/Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp index 9c6e2b3dacb..c17f6f8315a 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp @@ -270,7 +270,7 @@ void PolygonTrigger::updateBounds() const Real halfWidth = (m_bounds.hi.x - m_bounds.lo.x) / 2.0f; Real halfHeight = (m_bounds.hi.y + m_bounds.lo.y) / 2.0f; - m_radius = Sqrt(halfHeight*halfHeight + halfWidth*halfWidth); + m_radius = WWMath::Sqrt(halfHeight*halfHeight + halfWidth*halfWidth); } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp b/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp index fd356ea6929..49ef68a338c 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp @@ -339,8 +339,8 @@ Bridge::Bridge(Object *bridgeObj) Real halfsizeY = bridgeObj->getGeometryInfo().getMinorRadius(); m_bridgeInfo.bridgeWidth = 2*halfsizeY; - Real c = (Real)Cos(angle); - Real s = (Real)Sin(angle); + Real c = (Real)WWMath::Cos(angle); + Real s = (Real)WWMath::Sin(angle); m_bridgeInfo.fromLeft.set(pos->x-halfsizeX*c-halfsizeY*s, pos->y + halfsizeY*c - halfsizeX*s, pos->z); m_bridgeInfo.toLeft.set(pos->x+halfsizeX*c-halfsizeY*s, pos->y + halfsizeY*c + halfsizeX*s, pos->z); @@ -1468,11 +1468,11 @@ void makeAlignToNormalMatrix( Real angle, const Coord3D& pos, const Coord3D& nor /* It is extremely important that the resulting matrix is such that the xvector points in the angle we specified; specifically, - that Atan2(xvec.y, xvec.x) == angle. So we must construct + that WWMath::Atan2(xvec.y, xvec.x) == angle. So we must construct the matrix carefully to ensure this! */ - x.x = Cos( angle ); - x.y = Sin( angle ); + x.x = WWMath::Cos( angle ); + x.y = WWMath::Sin( angle ); x.z = 0.0f; //x.normalize(); -- redundant; is normalized by definition @@ -2369,7 +2369,7 @@ void TerrainLogic::setWaterHeight( const WaterHandle *water, Real height, Real d center.z = 0.0f; // irrelavant // the max radius to scan around us is the diagonal of the bounding region - Real maxDist = Sqrt( affectedRegion.width() * affectedRegion.width() + + Real maxDist = WWMath::Sqrt( affectedRegion.width() * affectedRegion.width() + affectedRegion.height() * affectedRegion.height() ); // scan the objects in the area of the water affected @@ -2652,8 +2652,8 @@ void TerrainLogic::flattenTerrain(Object *obj) Real halfsizeY = obj->getGeometryInfo().getMinorRadius(); - Real c = (Real)Cos(angle); - Real s = (Real)Sin(angle); + Real c = (Real)WWMath::Cos(angle); + Real s = (Real)WWMath::Sin(angle); Vector3 topLeft(pos->x-halfsizeX*c-halfsizeY*s, pos->y + halfsizeY*c - halfsizeX*s, 0); Vector3 topRight(pos->x+halfsizeX*c-halfsizeY*s, pos->y + halfsizeY*c + halfsizeX*s, 0); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp index 19cdc291ca9..ce216cc18ad 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp @@ -169,11 +169,11 @@ static Bool calcTrajectory( Real dz = end.z - start.z; // calculating the angle is trivial. - angle = Atan2(dy, dx); + angle = WWMath::Atan2(dy, dx); // calculating the pitch requires a bit more effort. Real horizDistSqr = sqr(dx) + sqr(dy); - Real horizDist = Sqrt(horizDistSqr); + Real horizDist = WWMath::Sqrt(horizDistSqr); // calc the two possible pitches that will cover the given horizontal range. // (this is actually only true if dz==0, but is a good first guess) @@ -182,7 +182,7 @@ static Bool calcTrajectory( // let's start by aiming directly for it. we know this isn't right (unless gravity // is zero, which it's not) but is a good starting point... - Real theta = Atan2(dz, horizDist); + Real theta = WWMath::Atan2(dz, horizDist); // if the angle isn't pretty shallow, we can get a better initial guess by using // the code below... const Real SHALLOW_ANGLE = 0.5f * PI / 180.0f; @@ -191,7 +191,7 @@ static Bool calcTrajectory( Real t = horizDist / velocity; Real vz = (dz/t + 0.5f*gravity*t); Real sineOfAngle = clamp(-1.0f, vz / velocity, 1.0f); - theta = ASin(sineOfAngle)*0.5f; + theta = WWMath::Asin(sineOfAngle)*0.5f; } /* @@ -203,7 +203,7 @@ static Bool calcTrajectory( { return false; } - Real theta = ASin(sineOfAngle)*0.5f; + Real theta = WWMath::Asin(sineOfAngle)*0.5f; */ Real pitches[2]; @@ -225,10 +225,10 @@ static Bool calcTrajectory( // calc the horiz-speed & time for each. // note that time can only be negative for 90getMinimumAttackRange(); Real maxRange = detWeap->getUnmodifiedAttackRange(); - Real range = Sqrt(ThePartitionManager->getDistanceSquared( projectile, &victimPosToUse, FROM_CENTER_2D ) ); + Real range = WWMath::Sqrt(ThePartitionManager->getDistanceSquared( projectile, &victimPosToUse, FROM_CENTER_2D ) ); Real rangeRatio = (range - minRange) / (maxRange - minRange); m_flightPathSpeed = (rangeRatio * (weaponSpeed - minWeaponSpeed)) + minWeaponSpeed; } @@ -596,7 +596,7 @@ UpdateSleepTime DumbProjectileBehavior::update() Real distVictimMovedSqr = sqr(delta.x) + sqr(delta.y) + sqr(delta.z); if (distVictimMovedSqr > 0.1f) { - Real distVictimMoved = Sqrt(distVictimMovedSqr); + Real distVictimMoved = WWMath::Sqrt(distVictimMovedSqr); if (distVictimMoved > d->m_flightPathAdjustDistPerFrame) distVictimMoved = d->m_flightPathAdjustDistPerFrame; delta.normalize(); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp index ab6dbb4d1ad..10dfeaaaa41 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp @@ -232,7 +232,7 @@ void GenerateMinefieldBehavior::placeMinesAlongLine(const Coord3D& posStart, con Real dx = posEnd.x - posStart.x; Real dy = posEnd.y - posStart.y; - Real len = Sqrt(sqr(dx) + sqr(dy)); + Real len = WWMath::Sqrt(sqr(dx) + sqr(dy)); Real mineRadius = mineTemplate->getTemplateGeometryInfo().getBoundingCircleRadius(); Real mineDiameter = mineRadius * 2.0f; Real mineJitter = mineRadius*d->m_randomJitter; @@ -304,8 +304,8 @@ void GenerateMinefieldBehavior::placeMinesAroundCircle(const Coord3D& pos, Real for (Real angle = 0; angle < angleLim; angle += angleInc) { Coord3D pt; - pt.x = pos.x + radius * Cos(angle); - pt.y = pos.y + radius * Sin(angle); + pt.x = pos.x + radius * WWMath::Cos(angle); + pt.y = pos.y + radius * WWMath::Sin(angle); pt.z = TheTerrainLogic->getGroundHeight( pt.x, pt.y ); offsetBySmallRandomAmount(pt, mineJitter); placeMineAt(pt, mineTemplate, team, obj); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp index 62cf3c37a48..c0f5ea9c665 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp @@ -562,7 +562,7 @@ void MinefieldBehavior::setScootParms(const Coord3D& start, const Coord3D& end) if (start.z > endOnGround.z) { // figure out how long it will take to fall, and replace scoot time with that - UnsignedInt fallingTime = REAL_TO_INT_CEIL(Sqrt(2.0f * (start.z - endOnGround.z) / fabs(TheGlobalData->m_gravity))); + UnsignedInt fallingTime = REAL_TO_INT_CEIL(WWMath::Sqrt(2.0f * (start.z - endOnGround.z) / fabs(TheGlobalData->m_gravity))); // we can scoot after we land, but don't want to stop scooting before we land if (scootFromStartingPointTime < fallingTime) scootFromStartingPointTime = fallingTime; @@ -580,7 +580,7 @@ void MinefieldBehavior::setScootParms(const Coord3D& start, const Coord3D& end) Real dx = endOnGround.x - start.x; Real dy = endOnGround.y - start.y; Real dz = endOnGround.z - start.z; - Real dist = Sqrt(sqr(dx) + sqr(dy)); + Real dist = WWMath::Sqrt(sqr(dx) + sqr(dy)); if (dist <= 0.1f && fabs(dz) <= 0.1f) { obj->setPosition(&endOnGround); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp index 4b472d1ce53..1728c8fc8fb 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp @@ -327,8 +327,8 @@ Bool ParkingPlaceBehavior::reserveSpace(ObjectID id, Real parkingOffset, Parking info->parkingSpace = d->m_parkInHangars ? ppi->m_hangarStart : ppi->m_location; if (parkingOffset != 0.0f) { - info->parkingSpace.x += parkingOffset * Cos(ppi->m_orientation); - info->parkingSpace.y += parkingOffset * Sin(ppi->m_orientation); + info->parkingSpace.x += parkingOffset * WWMath::Cos(ppi->m_orientation); + info->parkingSpace.y += parkingOffset * WWMath::Sin(ppi->m_orientation); } info->runwayPrep = ppi->m_prep; info->parkingOrientation = d->m_parkInHangars ? ppi->m_hangarStartOrient : ppi->m_orientation; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp index 8a655c1c7a4..5e8ea4cfcc1 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp @@ -299,7 +299,7 @@ void SlowDeathBehavior::beginSlowDeath(const DamageInfo *damageInfo) physics->setExtraBounciness(-1.0); // we don't want this guy to bounce at all physics->setExtraFriction(-3 * SECONDS_PER_LOGICFRAME_REAL); // reduce his ground friction a bit physics->setAllowBouncing(true); - Real orientation = Atan2(force.y, force.x); + Real orientation = WWMath::Atan2(force.y, force.x); physics->setAngles(orientation, 0, 0); obj->getDrawable()->setModelConditionState(MODELCONDITION_EXPLODED_FLAILING); m_flags |= (1<pathfinder()->validMovementTerrain( LAYER_GROUND, loco, &startPosition)) { // try front & back. Real offset = getObject()->getGeometryInfo().getMajorRadius(); - startPosition.x -= offset*Cos(exitAngle); - startPosition.y -= offset*Sin(exitAngle); + startPosition.x -= offset*WWMath::Cos(exitAngle); + startPosition.y -= offset*WWMath::Sin(exitAngle); if (!TheAI->pathfinder()->validMovementTerrain(LAYER_GROUND, loco, &startPosition)) { - startPosition.x += 2*offset*Cos(exitAngle); - startPosition.y += 2*offset*Sin(exitAngle); + startPosition.x += 2*offset*WWMath::Cos(exitAngle); + startPosition.y += 2*offset*WWMath::Sin(exitAngle); if (!TheAI->pathfinder()->validMovementTerrain(LAYER_GROUND, loco, &startPosition)) { startPosition = *getObject()->getPosition(); } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp index 92dc77b2889..e86af265be8 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp @@ -611,8 +611,8 @@ void OpenContain::scatterToNearbyPosition(Object* rider) Real dist = GameLogicRandomValueReal( minRadius, maxRadius ); Coord3D pos; - pos.x = dist * Cos( angle ) + containerPos->x; - pos.y = dist * Sin( angle ) + containerPos->y; + pos.x = dist * WWMath::Cos( angle ) + containerPos->x; + pos.y = dist * WWMath::Sin( angle ) + containerPos->y; pos.z = TheTerrainLogic->getLayerHeight( pos.x, pos.y, theContainer->getLayer() ); // set orientation diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cpp index bef8b3fc454..6cdafd0e857 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cpp @@ -295,8 +295,8 @@ void TunnelContain::scatterToNearbyPosition(Object* obj) Real dist = GameLogicRandomValueReal( minRadius, maxRadius ); Coord3D pos; - pos.x = dist * Cos( angle ) + containerPos->x; - pos.y = dist * Sin( angle ) + containerPos->y; + pos.x = dist * WWMath::Cos( angle ) + containerPos->x; + pos.y = dist * WWMath::Sin( angle ) + containerPos->y; pos.z = TheTerrainLogic->getGroundHeight( pos.x, pos.y ); // set orientation diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp index e1935632bd5..a0228b2d170 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp @@ -129,7 +129,7 @@ static Real tryToRotateVector3D( // dot of two unit vectors is cos of angle between them. Real cosine = Vector3::Dot_Product(curDir, goalDir); // bound it in case of numerical error - Real angleBetween = (Real)ACos(clamp(-1.0f, cosine, 1.0f)); + Real angleBetween = (Real)WWMath::Acos(clamp(-1.0f, cosine, 1.0f)); if (maxAngle < 0) { @@ -231,9 +231,9 @@ static void calcDirectionToApplyThrust( Bool foundSolution = false; Real distToGoalSqr = vecToGoal.Length2(); - Real distToGoal = Sqrt(distToGoalSqr); + Real distToGoal = WWMath::Sqrt(distToGoalSqr); Real curVelMagSqr = curVel.Length2(); - Real curVelMag = Sqrt(curVelMagSqr); + Real curVelMag = WWMath::Sqrt(curVelMagSqr); Real maxAccelSqr = sqr(maxAccel); Real denom = curVelMagSqr - maxAccelSqr; @@ -869,8 +869,8 @@ void Locomotor::locoUpdate_moveTowardsAngle(Object* obj, Real goalAngle) { // can't stay in one place; move in the desired direction at min speed. Coord3D desiredPos = *obj->getPosition(); - desiredPos.x += Cos(goalAngle) * minSpeed * 2; - desiredPos.y += Sin(goalAngle) * minSpeed * 2; + desiredPos.x += WWMath::Cos(goalAngle) * minSpeed * 2; + desiredPos.y += WWMath::Sin(goalAngle) * minSpeed * 2; // pass a huge num for "dist to goal", so that we don't think we're nearing // our destination and thus slow down... const Real onPathDistToGoal = 99999.0f; @@ -884,8 +884,8 @@ void Locomotor::locoUpdate_moveTowardsAngle(Object* obj, Real goalAngle) { DEBUG_ASSERTCRASH(m_template->m_appearance != LOCO_THRUST, ("THRUST should always have minspeeds!")); Coord3D desiredPos = *obj->getPosition(); - desiredPos.x += Cos(goalAngle) * 1000.0f; - desiredPos.y += Sin(goalAngle) * 1000.0f; + desiredPos.x += WWMath::Cos(goalAngle) * 1000.0f; + desiredPos.y += WWMath::Sin(goalAngle) * 1000.0f; PhysicsTurningType rotating = rotateTowardsPosition(obj, desiredPos); physics->setTurning(rotating); handleBehaviorZ(obj, physics, *obj->getPosition()); @@ -971,7 +971,7 @@ void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalP Real dx = goalPos.x - obj->getPosition()->x; Real dy = goalPos.y - obj->getPosition()->y; Real dz = goalPos.z - obj->getPosition()->z; - Real dist = Sqrt(dx*dx+dy*dy); + Real dist = WWMath::Sqrt(dx*dx+dy*dy); if (dist>onPathDistToGoal) { if (!obj->isKindOf(KINDOF_PROJECTILE) && dist>2*onPathDistToGoal) @@ -1083,7 +1083,7 @@ void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalP // Projectiles never stop braking once they start. jba. obj->setStatus( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_BRAKING ) ); // Projectiles cheat in 3 dimensions. - dist = Sqrt(dx*dx+dy*dy+dz*dz); + dist = WWMath::Sqrt(dx*dx+dy*dy+dz*dz); Real vel = physics->getVelocityMagnitude(); if (vel < MIN_VEL) vel = MIN_VEL; @@ -1258,7 +1258,7 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, Real angle = obj->getOrientation(); // Real relAngle = ThePartitionManager->getRelativeAngle2D( obj, &goalPos ); // Real desiredAngle = angle + relAngle; - Real desiredAngle = Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real relAngle = stdAngleDiff(desiredAngle, angle); Bool moveBackwards = false; @@ -1341,8 +1341,8 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, targetAngle += turnAmount; } Coord3D offset; - offset.x = Cos(targetAngle)*distance; - offset.y = Sin(targetAngle)*distance; + offset.x = WWMath::Cos(targetAngle)*distance; + offset.y = WWMath::Sin(targetAngle)*distance; offset.z = 0; const Coord3D* pos = obj->getPosition(); @@ -1533,7 +1533,7 @@ Bool Locomotor::fixInvalidPosition(Object* obj, PhysicsBehavior *physics) //physics->clearAcceleration(); if (dot<0) { - dot = Sqrt(-dot); + dot = WWMath::Sqrt(-dot); correctionNormalized.x *= dot*physics->getMass(); correctionNormalized.y *= dot*physics->getMass(); physics->applyMotiveForce(&correctionNormalized); @@ -1597,7 +1597,7 @@ void Locomotor::moveTowardsPositionLegs(Object* obj, PhysicsBehavior *physics, c Real angle = obj->getOrientation(); // Real relAngle = ThePartitionManager->getRelativeAngle2D( obj, &goalPos ); // Real desiredAngle = angle + relAngle; - Real desiredAngle = Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); if (m_template->m_wanderWidthFactor != 0.0f) { Real angleLimit = PI/8 * m_template->m_wanderWidthFactor; @@ -1730,7 +1730,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, Real angle = obj->getOrientation(); // Real relAngle = ThePartitionManager->getRelativeAngle2D( obj, &goalPos ); // Real desiredAngle = angle + relAngle; - Real desiredAngle = Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real relAngle = stdAngleDiff(desiredAngle, angle); if (moveBackwards) { @@ -1821,7 +1821,7 @@ void Locomotor::moveTowardsPositionWings(Object* obj, PhysicsBehavior *physics, Real angleTowardPos = (isNearlyZero(dx) && isNearlyZero(dy)) ? obj->getOrientation() : - Atan2(dy, dx); + WWMath::Atan2(dy, dx); Real aimDir = (PI - PI/8); angleTowardPos += aimDir; @@ -1831,8 +1831,8 @@ void Locomotor::moveTowardsPositionWings(Object* obj, PhysicsBehavior *physics, // project a spot "radius" dist away from it, in that dir Coord3D desiredPos = goalPos; - desiredPos.x += Cos(angleTowardPos) * turnRadius; - desiredPos.y += Sin(angleTowardPos) * turnRadius; + desiredPos.x += WWMath::Cos(angleTowardPos) * turnRadius; + desiredPos.y += WWMath::Sin(angleTowardPos) * turnRadius; moveTowardsPositionOther(obj, physics, desiredPos, 0, desiredSpeed); return; } @@ -2055,7 +2055,7 @@ Real Locomotor::calcLiftToUseAtPt(Object* obj, PhysicsBehavior *physics, Real cu // thus // a = 2(dz - v t)/t^2 // and - // t = (-v +- Sqrt(v*v + 2*a*dz))/a + // t = (-v +- WWMath::Sqrt(v*v + 2*a*dz))/a // // but if we assume t=1, then // a=2(dz-v) @@ -2117,7 +2117,7 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 Real dy = goalPos.y - turnPos.y; // If we are very close to the goal, we twitch due to rounding error. So just return. jba. if (fabs(dx)<0.1f && fabs(dy)<0.1f) return TURN_NONE; - Real desiredAngle = Atan2(dy, dx); + Real desiredAngle = WWMath::Atan2(dy, dx); Real amount = stdAngleDiff(desiredAngle, angle); if (relAngle) *relAngle = amount; if (amount>maxTurnRate) { @@ -2132,14 +2132,14 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 #if 0 Coord3D desiredPos = *obj->getPosition(); // well, desired Dir, anyway - desiredPos.x += Cos(angle + amount) * radius; - desiredPos.y += Sin(angle + amount) * radius; + desiredPos.x += WWMath::Cos(angle + amount) * radius; + desiredPos.y += WWMath::Sin(angle + amount) * radius; // so, the thing is, we want to rotate ourselves so that our *center* is rotated // by the given amount, but the rotation must be around turnPos. so do a little // back-calculation. - Real angleDesiredForTurnPos = Atan2(desiredPos.y - turnPos.y, desiredPos.x - turnPos.x); + Real angleDesiredForTurnPos = WWMath::Atan2(desiredPos.y - turnPos.y, desiredPos.x - turnPos.x); amount = angleDesiredForTurnPos - angle; #endif /// @todo srj -- there's probably a more efficient & more direct way to do this. find it. @@ -2155,7 +2155,7 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 } else { - Real desiredAngle = Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real amount = stdAngleDiff(desiredAngle, angle); if (relAngle) *relAngle = amount; if (amount>maxTurnRate) { @@ -2488,7 +2488,7 @@ void Locomotor::maintainCurrentPositionWings(Object* obj, PhysicsBehavior *physi Real angleTowardMaintainPos = (isNearlyZero(dx) && isNearlyZero(dy)) ? obj->getOrientation() : - Atan2(dy, dx); + WWMath::Atan2(dy, dx); Real aimDir = (PI - PI/8); if (turnRadius < 0) @@ -2500,8 +2500,8 @@ void Locomotor::maintainCurrentPositionWings(Object* obj, PhysicsBehavior *physi // project a spot "radius" dist away from it, in that dir Coord3D desiredPos = m_maintainPos; - desiredPos.x += Cos(angleTowardMaintainPos) * turnRadius; - desiredPos.y += Sin(angleTowardMaintainPos) * turnRadius; + desiredPos.x += WWMath::Cos(angleTowardMaintainPos) * turnRadius; + desiredPos.y += WWMath::Sin(angleTowardMaintainPos) * turnRadius; moveTowardsPositionWings(obj, physics, desiredPos, 0, m_template->m_minSpeed); } } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp index 927cada1c7f..5c0390849ca 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp @@ -281,7 +281,7 @@ class DeliverPayloadNugget : public ObjectCreationNugget Real dy = primary->y - secondary->y; //Calc length - Real length = Sqrt( dx*dx + dy*dy ); + Real length = WWMath::Sqrt( dx*dx + dy*dy ); //Normalize length dx /= length; @@ -289,14 +289,14 @@ class DeliverPayloadNugget : public ObjectCreationNugget //Rotate 90 degrees CCW. Real radians = 90.0f * PI / 180.0f; - Real s = Sin( radians ); - Real c = Cos( radians ); + Real s = WWMath::Sin( radians ); + Real c = WWMath::Cos( radians ); CCWx = dx * c + dy * -s + dx; CCWy = dx * s + dy * c + dy; //Rotate 90 degrees CW - s = Sin( -radians ); - c = Cos( -radians ); + s = WWMath::Sin( -radians ); + c = WWMath::Cos( -radians ); CWx = dx * c + dy * -s + dx; CWy = dx * s + dy * c + dy; } @@ -343,17 +343,17 @@ class DeliverPayloadNugget : public ObjectCreationNugget { Real randomRadius = GameLogicRandomValueReal(0, m_errorRadius ); Real randomAngle = GameLogicRandomValueReal(0, PI*2 ); - targetPos.x += randomRadius * Cos( randomAngle ); - targetPos.y += randomRadius * Sin( randomAngle ); + targetPos.x += randomRadius * WWMath::Cos( randomAngle ); + targetPos.y += randomRadius * WWMath::Sin( randomAngle ); } - Real orient = Atan2( moveToPos.y - startPos.y, moveToPos.x - startPos.x); + Real orient = WWMath::Atan2( moveToPos.y - startPos.y, moveToPos.x - startPos.x); if( m_data.m_distToTarget > 0 ) { const Real SLOP = 1.5f; - startPos.x -= Cos(orient) * m_data.m_distToTarget * SLOP; - startPos.y -= Sin(orient) * m_data.m_distToTarget * SLOP; + startPos.x -= WWMath::Cos(orient) * m_data.m_distToTarget * SLOP; + startPos.y -= WWMath::Sin(orient) * m_data.m_distToTarget * SLOP; } Object *transport; @@ -1067,7 +1067,7 @@ class GenericObjectCreationNugget : public ObjectCreationNugget objUp->applyForce(&force); if (m_orientInForceDirection) - orientation = Atan2(force.y, force.x); + orientation = WWMath::Atan2(force.y, force.x); } } @@ -1155,7 +1155,7 @@ class GenericObjectCreationNugget : public ObjectCreationNugget objUp->applyForce(&force); if (m_orientInForceDirection) { - orientation = Atan2(force.y, force.x); + orientation = WWMath::Atan2(force.y, force.x); } DUMPREAL(orientation); objUp->setAngles(orientation, 0, 0); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp index 41e1e91b446..a76bde40fd8 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp @@ -401,8 +401,8 @@ static void testRotatedPointsAgainstRect( Real major = a->geom.getMajorRadius(); Real minor = (a->geom.getGeomType() == GEOMETRY_SPHERE) ? a->geom.getMajorRadius() : a->geom.getMinorRadius(); - Real c = (Real)Cos(-a->angle); - Real s = (Real)Sin(-a->angle); + Real c = (Real)WWMath::Cos(-a->angle); + Real s = (Real)WWMath::Sin(-a->angle); for (Int i = 0; i < 4; ++i, ++pts) { @@ -435,8 +435,8 @@ static void rectToFourPoints( Coord2D pts[] ) { - Real c = (Real)Cos(a->angle); - Real s = (Real)Sin(a->angle); + Real c = (Real)WWMath::Cos(a->angle); + Real s = (Real)WWMath::Sin(a->angle); Real exc = a->geom.getMajorRadius()*c; Real eyc = a->geom.getMinorRadius()*c; @@ -617,7 +617,7 @@ inline Bool z_collideTest_Sphere_Nonsphere(CollideTestProc xyproc, const Collide // find the radius of the slice of the sphere that is at b_bot CollideInfo amod = *a; amod.position.z = b_bot; - amod.geom.setMajorRadius((Real)Sqrt(sqr(a->geom.getMajorRadius()) - sqr(b_bot - a->position.z))); + amod.geom.setMajorRadius((Real)WWMath::Sqrt(sqr(a->geom.getMajorRadius()) - sqr(b_bot - a->position.z))); if (xyproc(&amod, b, cinfo)) { // if you want to have 'end' collisions, you should add something like: @@ -635,7 +635,7 @@ inline Bool z_collideTest_Sphere_Nonsphere(CollideTestProc xyproc, const Collide { CollideInfo amod = *a; amod.position.z = b_top; - amod.geom.setMajorRadius((Real)Sqrt(sqr(a->geom.getMajorRadius()) - sqr(a->position.z - b_top))); + amod.geom.setMajorRadius((Real)WWMath::Sqrt(sqr(a->geom.getMajorRadius()) - sqr(a->position.z - b_top))); if (xyproc(&amod, b, cinfo)) { // if you want to have 'end' collisions, you should add something like: @@ -823,7 +823,7 @@ static Bool distCalcProc_BoundaryAndBoundary_2D( if (totalRad > 0.0f) { - Real actualDist = Sqrt(actualDistSqr); + Real actualDist = WWMath::Sqrt(actualDistSqr); Real shrunkenDist = actualDist - totalRad; if (shrunkenDist <= 0.0f) { @@ -911,7 +911,7 @@ static Bool distCalcProc_BoundaryAndBoundary_3D( Real totalRad = (geomA?geomA->getBoundingSphereRadius():0) + (geomB?geomB->getBoundingSphereRadius():0); if (totalRad > 0.0f) { - Real actualDist = Sqrt(actualDistSqr); + Real actualDist = WWMath::Sqrt(actualDistSqr); Real shrunkenDist = actualDist - totalRad; if (shrunkenDist <= 0.0f) { @@ -1774,8 +1774,8 @@ void PartitionData::doRectFill( Real angle ) { - Real c = (Real)Cos(angle); - Real s = (Real)Sin(angle); + Real c = (Real)WWMath::Cos(angle); + Real s = (Real)WWMath::Sin(angle); Real actualCellSize = ThePartitionManager->getCellSize(); Real stepSize = actualCellSize * 0.5f; // in theory, should be getCellSize() exactly, but needs to be smaller to avoid aliasing problems @@ -2219,7 +2219,7 @@ Int PartitionData::calcMaxCoiForShape(GeometryType geom, Real majorRadius, Real } case GEOMETRY_BOX: { - Real diagonal = (Real)(Sqrt(majorRadius*majorRadius + minorRadius*minorRadius)); + Real diagonal = (Real)(WWMath::Sqrt(majorRadius*majorRadius + minorRadius*minorRadius)); Int cells = ThePartitionManager->worldToCellDist(diagonal*2) + 1; result = cells * cells; break; @@ -3210,7 +3210,7 @@ Int PartitionManager::calcMinRadius(const ICoord2D& cur) } // double, not real - double dist = Sqrt(minDistSqr); + double dist = WWMath::Sqrt(minDistSqr); Int minRadius = REAL_TO_INT_CEIL( dist / m_cellSize ); return minRadius; @@ -3228,7 +3228,7 @@ void PartitionManager::calcRadiusVec() // double, not real double dx = (double)cx * (double)cellSize; double dy = (double)cy * (double)cellSize; - double maxPossibleDist = Sqrt(dx*dx + dy*dy); + double maxPossibleDist = WWMath::Sqrt(dx*dx + dy*dy); m_maxGcoRadius = REAL_TO_INT_CEIL(maxPossibleDist / cellSize); @@ -3498,7 +3498,7 @@ Object *PartitionManager::getClosestObjects( } if (closestDistArg) { - *closestDistArg = (Real)Sqrt(closestDistSqr); + *closestDistArg = (Real)WWMath::Sqrt(closestDistSqr); } #ifdef RTS_DEBUG @@ -3625,7 +3625,7 @@ Real PartitionManager::getRelativeAngle2D( const Object *obj, const Coord3D *pos v.y = pos->y - objPos.y; v.z = 0.0f; - Real dist = (Real)Sqrt(sqr(v.x) + sqr(v.y)); + Real dist = (Real)WWMath::Sqrt(sqr(v.x) + sqr(v.y)); // normalize if (dist == 0.0f) @@ -3648,7 +3648,7 @@ Real PartitionManager::getRelativeAngle2D( const Object *obj, const Coord3D *pos else if (c > 1.0) c = 1.0; - Real value = (Real)ACos( c ); + Real value = (Real)WWMath::Acos( c ); // Determine sign by checking Z component of dir cross v // Note this is assumes 2D, and is identical to dotting the perpendicular of v with dir @@ -3785,8 +3785,8 @@ Bool PartitionManager::tryPosition( const Coord3D *center, // compute the spot on the terrain we've picked Coord3D pos; - pos.x = dist * Cos( angle ) + center->x; - pos.y = dist * Sin( angle ) + center->y; + pos.x = dist * WWMath::Cos( angle ) + center->x; + pos.y = dist * WWMath::Sin( angle ) + center->y; PathfindLayerEnum layer = LAYER_GROUND; if ((options->flags & FPF_USE_HIGHEST_LAYER) != 0) @@ -4556,7 +4556,7 @@ Int PartitionManager::iterateCellsBreadthFirst(const Coord3D *pos, CellBreadthFi //----------------------------------------------------------------------------- static Real calcDist2D(Real x1, Real y1, Real x2, Real y2) { - return Sqrt(sqr(x1-x2) + sqr(y1-y2)); + return WWMath::Sqrt(sqr(x1-x2) + sqr(y1-y2)); } //----------------------------------------------------------------------------- @@ -5715,7 +5715,7 @@ void hLineAddThreat(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = Sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5743,7 +5743,7 @@ void hLineRemoveThreat(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = Sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5771,7 +5771,7 @@ void hLineAddValue(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = Sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5799,7 +5799,7 @@ void hLineRemoveValue(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = Sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp index 20e1036e125..400517d8b91 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp @@ -2230,7 +2230,7 @@ UpdateSleepTime AIUpdateInterface::doLocomotor() } else { - Real dist = Sqrt(dSqr); + Real dist = WWMath::Sqrt(dSqr); if (dist<1) dist = 1; pos.x += 2*PATHFIND_CELL_SIZE_F*dx/(dist*LOGICFRAMES_PER_SECOND); pos.y += 2*PATHFIND_CELL_SIZE_F*dy/(dist*LOGICFRAMES_PER_SECOND); @@ -2424,7 +2424,7 @@ Real AIUpdateInterface::getLocomotorDistanceToGoal() dest = m_path->getLastNode()->getPosition(); } Real distance = ThePartitionManager->getDistanceSquared( me, dest, FROM_CENTER_3D ); - return Sqrt( distance );// Other paths return dots of normalized vectors, so one sqrt ain't so bad + return WWMath::Sqrt( distance );// Other paths return dots of normalized vectors, so one sqrt ain't so bad } else { @@ -2456,7 +2456,7 @@ Real AIUpdateInterface::getLocomotorDistanceToGoal() { if (sqr(dist) > distSqr) { - return Sqrt(distSqr); + return WWMath::Sqrt(distSqr); } else { @@ -2465,7 +2465,7 @@ Real AIUpdateInterface::getLocomotorDistanceToGoal() } if (distgetExtent( &terrainExtent ); const Real FUDGE = 1.2f; - Real HUGE_DIST = FUDGE * Sqrt(sqr(terrainExtent.hi.x - terrainExtent.lo.x) + sqr(terrainExtent.hi.y - terrainExtent.lo.y)); + Real HUGE_DIST = FUDGE * WWMath::Sqrt(sqr(terrainExtent.hi.x - terrainExtent.lo.x) + sqr(terrainExtent.hi.y - terrainExtent.lo.y)); exitCoord.x += dir->x * HUGE_DIST; exitCoord.y += dir->y * HUGE_DIST; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp index ce0e0c0860d..c42730f3201 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp @@ -201,8 +201,8 @@ UpdateSleepTime DeliverPayloadAIUpdate::update() { //Calc strafe ratio Real startDiveDistance = getData()->m_diveStartDistance; - Real endDiveDistance = Sqrt( endDiveDistanceSquared ); - Real currentDistance = Sqrt( currentDistanceSquared ); + Real endDiveDistance = WWMath::Sqrt( endDiveDistanceSquared ); + Real currentDistance = WWMath::Sqrt( currentDistanceSquared ); Real diveRatio = (startDiveDistance - currentDistance) / (startDiveDistance - endDiveDistance); @@ -367,7 +367,7 @@ Bool DeliverPayloadAIUpdate::isCloseEnoughToTarget() if ( inBound ) allowedDistanceSqr = sqr(getAllowedDistanceToTarget() + getPreOpenDistance()); - //DEBUG_LOG(("Dist to target is %f (allowed %f)",Sqrt(currentDistanceSqr),Sqrt(allowedDistanceSqr))); + //DEBUG_LOG(("Dist to target is %f (allowed %f)",WWMath::Sqrt(currentDistanceSqr),WWMath::Sqrt(allowedDistanceSqr))); if ( allowedDistanceSqr > currentDistanceSqr ) @@ -1081,7 +1081,7 @@ StateReturnType RecoverFromOffMapState::update() // Success if we should try aga enterCoord.z = owner->getPosition()->z; owner->setPosition(&enterCoord); - Real enterAngle = Atan2(ai->getMoveToPos()->y - enterCoord.y, ai->getMoveToPos()->x - enterCoord.x); + Real enterAngle = WWMath::Atan2(ai->getMoveToPos()->y - enterCoord.y, ai->getMoveToPos()->x - enterCoord.x); owner->setOrientation(enterAngle); PhysicsBehavior* physics = owner->getPhysics(); @@ -1121,7 +1121,7 @@ StateReturnType HeadOffMapState::onEnter() // Give move order out of town Region3D terrainExtent; TheTerrainLogic->getExtent( &terrainExtent ); const Real FUDGE = 1.2f; - Real HUGE_DIST = FUDGE * Sqrt(sqr(terrainExtent.hi.x - terrainExtent.lo.x) + sqr(terrainExtent.hi.y - terrainExtent.lo.y)); + Real HUGE_DIST = FUDGE * WWMath::Sqrt(sqr(terrainExtent.hi.x - terrainExtent.lo.x) + sqr(terrainExtent.hi.y - terrainExtent.lo.y)); exitCoord.x += dir->x * HUGE_DIST; exitCoord.y += dir->y * HUGE_DIST; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp index 14e55dc6c70..3167b261d19 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp @@ -398,10 +398,10 @@ static Bool intersectInfiniteLine2D Real& ix, Real& iy ) { - Real bx = ax + Cos(ao); - Real by = ay + Sin(ao); - Real dx = cx + Cos(co); - Real dy = cy + Sin(co); + Real bx = ax + WWMath::Cos(ao); + Real by = ay + WWMath::Sin(ao); + Real dx = cx + WWMath::Cos(co); + Real dy = cy + WWMath::Sin(co); Real denom = ((bx - ax) * (dy - cy) - (by - ay) * (dx - cx)); if (denom == 0.0f) @@ -457,7 +457,7 @@ class JetOrHeliTaxiState : public AIMoveOutOfTheWayState Coord3D intermedPt; Bool intermed = false; - Real orient = Atan2(ppinfo.runwayPrep.y - ppinfo.parkingSpace.y, ppinfo.runwayPrep.x - ppinfo.parkingSpace.x); + Real orient = WWMath::Atan2(ppinfo.runwayPrep.y - ppinfo.parkingSpace.y, ppinfo.runwayPrep.x - ppinfo.parkingSpace.x); if (fabs(stdAngleDiff(orient, ppinfo.parkingOrientation)) > PI/128) { intermedPt.z = (ppinfo.parkingSpace.z + ppinfo.runwayPrep.z) * 0.5f; @@ -884,7 +884,7 @@ class HeliTakeoffOrLandingState : public State } else { - Real dist = Sqrt(dSqr); + Real dist = WWMath::Sqrt(dSqr); if (dist<1) dist = 1; pos.x += PATHFIND_CELL_SIZE_F*dx/(dist*LOGICFRAMES_PER_SECOND); pos.y += PATHFIND_CELL_SIZE_F*dy/(dist*LOGICFRAMES_PER_SECOND); @@ -2062,15 +2062,15 @@ void JetAIUpdate::positionLockon() Real dist = finalDist + (d->m_lockonInitialDist - finalDist) * frac; Real angle = d->m_lockonAngleSpin * frac; - pos.x += Cos(angle) * dist; - pos.y += Sin(angle) * dist; + pos.x += WWMath::Cos(angle) * dist; + pos.y += WWMath::Sin(angle) * dist; // pos.z is untouched m_lockonDrawable->setPosition(&pos); Real dx = getObject()->getPosition()->x - pos.x; Real dy = getObject()->getPosition()->y - pos.y; if (dx || dy) - m_lockonDrawable->setOrientation(Atan2(dy, dx)); + m_lockonDrawable->setOrientation(WWMath::Atan2(dy, dx)); // the Gaussian sum, to avoid keeping a running total: // diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp index 2a873797bd9..4686ed58bda 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp @@ -223,7 +223,7 @@ void MissileAIUpdate::projectileFireAtObjectOrPosition( const Object *victim, co Real deltaZ = victimPos->z - obj->getPosition()->z; Real dx = victimPos->x - obj->getPosition()->x; Real dy = victimPos->y - obj->getPosition()->y; - Real xyDist = Sqrt(sqr(dx)+sqr(dy)); + Real xyDist = WWMath::Sqrt(sqr(dx)+sqr(dy)); if (xyDist<1) xyDist = 1; Real zFactor = 0; if (deltaZ>0) { @@ -581,7 +581,7 @@ void MissileAIUpdate::doKillState() closeEnough = curLoco->getMaxSpeedForCondition(BODY_PRISTINE); } Real distanceToTargetSq = ThePartitionManager->getDistanceSquared( getObject(), getGoalObject(), FROM_CENTER_3D); - //DEBUG_LOG(("Distance to target %f, closeEnough %f", Sqrt(distanceToTargetSq), closeEnough)); + //DEBUG_LOG(("Distance to target %f, closeEnough %f", WWMath::Sqrt(distanceToTargetSq), closeEnough)); if (distanceToTargetSq < closeEnough*closeEnough) { Coord3D pos = *getGoalObject()->getPosition(); getObject()->setPosition(&pos); @@ -619,7 +619,7 @@ UpdateSleepTime MissileAIUpdate::update() Coord3D newPos = *getObject()->getPosition(); if (m_noTurnDistLeft > 0.0f && m_state >= IGNITION) { - Real distThisTurn = Sqrt(sqr(newPos.x-m_prevPos.x) + sqr(newPos.y-m_prevPos.y) + sqr(newPos.z-m_prevPos.z)); + Real distThisTurn = WWMath::Sqrt(sqr(newPos.x-m_prevPos.x) + sqr(newPos.y-m_prevPos.y) + sqr(newPos.z-m_prevPos.z)); m_noTurnDistLeft -= distThisTurn; m_prevPos = newPos; } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp index a3e6eb6986d..7f1017e4f71 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp @@ -315,7 +315,7 @@ void RailroadBehavior::onCollide( Object *other, const Coord3D *loc, const Coord m_whistleSound.setPlayingHandle(TheAudio->addAudioEvent( &m_whistleSound )); - Real dist = (Real)Sqrt( dlt.x*dlt.x + dlt.y*dlt.y + dlt.z*dlt.z); + Real dist = (Real)WWMath::Sqrt( dlt.x*dlt.x + dlt.y*dlt.y + dlt.z*dlt.z); Real usRadius = obj->getGeometryInfo().getMajorRadius(); Real themRadius = other->getGeometryInfo().getMajorRadius(); Real overlap = ((usRadius + themRadius) - dist) + 1;// the plus 1 makes them go just outside of me. @@ -1184,8 +1184,8 @@ void alignToTerrain( Real angle, const Coord3D& pos, const Coord3D& normal, Matr z = normal; - x.x = Cos( angle ); - x.y = Sin( angle ); + x.x = WWMath::Cos( angle ); + x.y = WWMath::Sin( angle ); x.z = 0.0f; if (z.z != 0.0f) { @@ -1259,7 +1259,7 @@ void RailroadBehavior::updatePositionTrackDistance( PullInfo *pullerInfo, PullIn trackPosDelta.z = 0; Real dx = pullerInfo->towHitchPosition.x - turnPos.x; Real dy = pullerInfo->towHitchPosition.y - turnPos.y; - Real desiredAngle = Atan2(dy, dx); + Real desiredAngle = WWMath::Atan2(dy, dx); Real relAngle = stdAngleDiff(desiredAngle, obj->getTransformMatrix()->Get_Z_Rotation()); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp index 4a98b25ab61..57cc8f8211a 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp @@ -172,7 +172,7 @@ UpdateSleepTime CleanupHazardUpdate::update() AIUpdateInterface *ai = obj->getAI(); if( ai && (ai->isIdle() || ai->isBusy()) ) { - Real fDist = Sqrt( ThePartitionManager->getDistanceSquared( obj, &m_pos, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( obj, &m_pos, FROM_CENTER_2D ) ); if( fDist < 25.0f ) { //Abort clean area because there's nothing left to clean! @@ -204,7 +204,7 @@ void CleanupHazardUpdate::fireWhenReady() bonus.clear(); Real fireRange = m_weaponTemplate->getAttackRange( bonus ); Object *me = getObject(); - Real fDist = Sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); if( fDist < fireRange ) { //We are currently in range! diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp index 90bdcea296b..936da747afe 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp @@ -290,7 +290,7 @@ Object* CommandButtonHuntUpdate::scanClosestTarget() } } Real distSqr = ThePartitionManager->getDistanceSquared(me, other, FROM_BOUNDINGSPHERE_2D); - Real dist = Sqrt(distSqr); + Real dist = WWMath::Sqrt(distSqr); Int curPriority = data->m_scanRange - dist; if (info) curPriority = info->getPriority(other->getTemplate()); if (curPriority == 0) diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp index 6de7f898d74..1f2b5f080c1 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp @@ -95,7 +95,7 @@ Bool SupplyWarehouseDockUpdate::action( Object* docker, Object *drone ) Real closeEnoughSqr = sqr(docker->getGeometryInfo().getBoundingCircleRadius()*2); Real curDistSqr = ThePartitionManager->getDistanceSquared(docker, getObject(), FROM_BOUNDINGSPHERE_2D); if (curDistSqr > closeEnoughSqr) { - DEBUG_LOG(("Failing dock, dist %f, not close enough(%f).", Sqrt(curDistSqr), Sqrt(closeEnoughSqr))); + DEBUG_LOG(("Failing dock, dist %f, not close enough(%f).", WWMath::Sqrt(curDistSqr), WWMath::Sqrt(closeEnoughSqr))); // Make it twitch a little. Coord3D newPos = *docker->getPosition(); Real range = 0.4*PATHFIND_CELL_SIZE_F; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp index 66550acad5d..de00790d071 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp @@ -166,8 +166,8 @@ void DynamicShroudClearingRangeUpdate::animateGridDecals() for (int d = 0; d < GRID_FX_DECAL_COUNT; ++d) { - pos.x = ctr->x + (Sin(angle) * radius); - pos.y = ctr->y + (Cos(angle) * radius); + pos.x = ctr->x + (WWMath::Sin(angle) * radius); + pos.y = ctr->y + (WWMath::Cos(angle) * radius); pos.x -= ((Int)pos.x)%23; pos.y -= ((Int)pos.y)%23; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp index e1c48f1c00d..40d350662bd 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp @@ -119,8 +119,8 @@ UpdateSleepTime FloatUpdate::update() { Real angle = INT_TO_REAL(TheGameLogic->getFrame()); - Real yaw = Sin(angle * 0.0291f) * 0.05f; - Real pitch = Sin(angle * 0.0515f) * 0.05f; + Real yaw = WWMath::Sin(angle * 0.0291f) * 0.05f; + Real pitch = WWMath::Sin(angle * 0.0515f) * 0.05f; Matrix3D mx = *draw->getInstanceMatrix(); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp index b8c2be438f5..ff3fe318c54 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp @@ -359,8 +359,8 @@ UpdateSleepTime HelicopterSlowDeathBehavior::update() // is *NOT* the angle the object is facing // Coord3D force; - force.x = DOUBLE_TO_REAL( Cos( m_forwardAngle ) ) * m_forwardSpeed; - force.y = DOUBLE_TO_REAL( Sin( m_forwardAngle ) ) * m_forwardSpeed; + force.x = DOUBLE_TO_REAL( WWMath::Cos( m_forwardAngle ) ) * m_forwardSpeed; + force.y = DOUBLE_TO_REAL( WWMath::Sin( m_forwardAngle ) ) * m_forwardSpeed; force.z = 0.0f; physics->applyMotiveForce( &force ); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/MobMemberSlavedUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/MobMemberSlavedUpdate.cpp index c92f144f5b9..f9993a26350 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/MobMemberSlavedUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/MobMemberSlavedUpdate.cpp @@ -358,8 +358,8 @@ void MobMemberSlavedUpdate::doCatchUpLogic( Coord3D *pos ) Real randomDirection = GameLogicRandomValue( 0, 2*PI ); Real randomRadius = GameLogicRandomValue( 0, data->m_noNeedToCatchUpRadius ); nuPos.set(pos); - nuPos.x += randomRadius * Cos( randomDirection ); - nuPos.y += randomRadius * Sin( randomDirection ); + nuPos.x += randomRadius * WWMath::Cos( randomDirection ); + nuPos.y += randomRadius * WWMath::Sin( randomDirection ); nuPos.z = TheTerrainLogic->getGroundHeight( nuPos.x, nuPos.y ); AIUpdateInterface *ai = getObject()->getAIUpdateInterface(); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp index e9e107ccbf8..0489077e0a7 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp @@ -294,7 +294,7 @@ static Real calcTransform(const Object* obj, const Coord3D *pos, Real maxTurnRat else if (c > 1.0) c = 1.0; - Real angle = (Real)ACos( c ); + Real angle = (Real)WWMath::Acos( c ); Vector3 newDir; if (fabs(angle) < maxTurnRate) @@ -418,7 +418,7 @@ void NeutronMissileUpdate::doAttack() pos.z += m_vel.z; //DEBUG_LOG(("vel %f accel %f z %f",m_vel.length(),m_accel.length(), pos.z)); -//Real vm = Sqrt(m_vel.x*m_vel.x+m_vel.y*m_vel.y+m_vel.z*m_vel.z); +//Real vm = WWMath::Sqrt(m_vel.x*m_vel.x+m_vel.y*m_vel.y+m_vel.z*m_vel.z); //DEBUG_LOG(("vel is %f %f %f (%f)",m_vel.x,m_vel.y,m_vel.z,vm)); getObject()->setTransformMatrix( &mx ); getObject()->setPosition( &pos ); @@ -512,7 +512,7 @@ UpdateSleepTime NeutronMissileUpdate::update() if (m_noTurnDistLeft > 0.0f && oldPosValid) { Coord3D newPos = *getObject()->getPosition(); - Real distThisTurn = Sqrt(sqr(newPos.x-oldPos.x) + sqr(newPos.y-oldPos.y) + sqr(newPos.z-oldPos.z)); + Real distThisTurn = WWMath::Sqrt(sqr(newPos.x-oldPos.x) + sqr(newPos.y-oldPos.y) + sqr(newPos.z-oldPos.z)); //DEBUG_LOG(("noTurnDist goes from %f to %f",m_noTurnDistLeft,m_noTurnDistLeft-distThisTurn)); m_noTurnDistLeft -= distThisTurn; } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp index 2efe5d60715..3b032a6431a 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp @@ -474,12 +474,12 @@ UpdateSleepTime ParticleUplinkCannonUpdate::update() //First determine the factor of time completed (ranges between 0.0 and 1.0) Real factor = (Real)(now - orbitalBirthFrame) / (Real)(orbitalDeathFrame - orbitalBirthFrame); - //We're generating a swath that travels the points between Sin( -1PI ) and Sin( 1PI ) + //We're generating a swath that travels the points between WWMath::Sin( -1PI ) and WWMath::Sin( 1PI ) Real radians = (factor * TWO_PI) - PI; Real cxDistance = (factor * data->m_swathOfDeathDistance ) - (data->m_swathOfDeathDistance * 0.5f); //cx is cartesian x //Now calculate the amplitude value. - Real height = Sin( radians ); + Real height = WWMath::Sin( radians ); Real cxHeight = height * data->m_swathOfDeathAmplitude; Coord3D buildingToInitialTargetVector; @@ -501,9 +501,9 @@ UpdateSleepTime ParticleUplinkCannonUpdate::update() cartesianTargetVector.Normalize(); Real dotProduct = Vector2::Dot_Product( buildingToTargetVector, cartesianTargetVector ); - dotProduct = __min( 0.99999f, __max( -0.99999f, dotProduct ) ); //Account for numerical errors. Also, ACos(-1.00000) is coming out QNAN on the superweapon general map. Heh. + dotProduct = __min( 0.99999f, __max( -0.99999f, dotProduct ) ); //Account for numerical errors. Also, WWMath::Acos(-1.00000) is coming out QNAN on the superweapon general map. Heh. - Real angle = (Real)ACos( dotProduct ); + Real angle = (Real)WWMath::Acos( dotProduct ); if( buildingToTargetVector.Y >= 0 ) { diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp index 93bd1984ce5..c99ed355c60 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp @@ -83,7 +83,7 @@ static Real angleBetweenVectors(const Coord3D& inCurDir, const Coord3D& inGoalDi Real cosine = Vector3::Dot_Product(curDir, goalDir); // bound it in case of numerical error - Real angleBetween = (Real)ACos(clamp(-1.0f, cosine, 1.0f)); + Real angleBetween = (Real)WWMath::Acos(clamp(-1.0f, cosine, 1.0f)); return angleBetween; } @@ -92,8 +92,8 @@ static Real angleBetweenVectors(const Coord3D& inCurDir, const Coord3D& inGoalDi static Real heightToSpeed(Real height) { // don't bother trying to remember how far we've fallen; instead, - // back-calc it from our speed & gravity... v = Sqrt(2*g*h) - return Sqrt(fabs(2.0f * TheGlobalData->m_gravity * height)); + // back-calc it from our speed & gravity... v = WWMath::Sqrt(2*g*h) + return WWMath::Sqrt(fabs(2.0f * TheGlobalData->m_gravity * height)); } //------------------------------------------------------------------------------------------------- @@ -129,7 +129,7 @@ PhysicsBehaviorModuleData::PhysicsBehaviorModuleData() static void parseHeightToSpeed( INI* ini, void * /*instance*/, void *store, const void* /*userData*/ ) { // don't bother trying to remember how far we've fallen; instead, - // back-calc it from our speed & gravity... v = Sqrt(2*g*h) + // back-calc it from our speed & gravity... v = WWMath::Sqrt(2*g*h) Real height = INI::scanReal(ini->getNextToken()); *(Real *)store = heightToSpeed(height); } @@ -636,10 +636,10 @@ UpdateSleepTime PhysicsBehavior::update() if (offset != 0.0f) { Vector3 xvec = mtx.Get_X_Vector(); - Real xy = Sqrt(sqr(xvec.X) + sqr(xvec.Y)); - Real pitchAngle = Atan2(xvec.Z, xy); + Real xy = WWMath::Sqrt(sqr(xvec.X) + sqr(xvec.Y)); + Real pitchAngle = WWMath::Atan2(xvec.Z, xy); Real remainingAngle = (offset > 0) ? ((PI/2) - pitchAngle) : (-(PI/2) + pitchAngle); - Real s = Sin(remainingAngle); + Real s = WWMath::Sin(remainingAngle); pitchRateToUse *= s; } @@ -723,7 +723,7 @@ UpdateSleepTime PhysicsBehavior::update() // // don't bother trying to remember how far we've fallen; instead, - // we back-calc it from our speed & gravity... v = Sqrt(2*g*h). + // we back-calc it from our speed & gravity... v = WWMath::Sqrt(2*g*h). // (note that m_minFallSpeedForDamage is always POSITIVE.) // // also note: since projectiles are immune to falling damage, don't @@ -817,7 +817,7 @@ Real PhysicsBehavior::getVelocityMagnitude() const { if (m_velMag == INVALID_VEL_MAG) { - m_velMag = (Real)Sqrt( sqr(m_vel.x) + sqr(m_vel.y) + sqr(m_vel.z) ); + m_velMag = (Real)WWMath::Sqrt( sqr(m_vel.x) + sqr(m_vel.y) + sqr(m_vel.z) ); } return m_velMag; } @@ -837,9 +837,9 @@ Real PhysicsBehavior::getForwardSpeed2D() const Real dot = vx + vy; Real speedSquared = vx*vx + vy*vy; -// DEBUG_ASSERTCRASH( speedSquared != 0, ("zero speedSquared will overflow Sqrt()!") );// lorenzen... sanity check +// DEBUG_ASSERTCRASH( speedSquared != 0, ("zero speedSquared will overflow WWMath::Sqrt()!") );// lorenzen... sanity check - Real speed = (Real)Sqrt( speedSquared ); + Real speed = (Real)WWMath::Sqrt( speedSquared ); if (dot >= 0.0f) return speed; @@ -862,7 +862,7 @@ Real PhysicsBehavior::getForwardSpeed3D() const Real dot = vx + vy + vz; - Real speed = (Real)Sqrt( vx*vx + vy*vy + vz*vz ); + Real speed = (Real)WWMath::Sqrt( vx*vx + vy*vy + vz*vz ); if (dot >= 0.0f) return speed; @@ -909,7 +909,7 @@ void PhysicsBehavior::scrubVelocity2D( Real desiredVelocity ) } else { - Real curVelocity = Sqrt(m_vel.x*m_vel.x + m_vel.y*m_vel.y); + Real curVelocity = WWMath::Sqrt(m_vel.x*m_vel.x + m_vel.y*m_vel.y); if (desiredVelocity > curVelocity) { return; @@ -1194,7 +1194,7 @@ void PhysicsBehavior::onCollide( Object *other, const Coord3D *loc, const Coord3 m_lastCollidee = other->getID(); - Real dist = Sqrt(distSqr); + Real dist = WWMath::Sqrt(distSqr); Real overlap = usRadius + themRadius - dist; // if objects are coincident, dist is zero, so force would be infinite -- clearly diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp index 1c265805c7a..c774dd264cc 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp @@ -167,7 +167,7 @@ void PointDefenseLaserUpdate::fireWhenReady() bonus.clear(); Real fireRange = data->m_weaponTemplate->getAttackRange( bonus ); Object *me = getObject(); - Real fDist = Sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); if( fDist < fireRange ) { //We are currently in range! @@ -285,7 +285,7 @@ Object* PointDefenseLaserUpdate::scanClosestTarget() continue; } - Real fDist = Sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); if( fDist <= fireRange ) { @@ -312,7 +312,7 @@ Object* PointDefenseLaserUpdate::scanClosestTarget() pos.add( other->getPosition() ); //Recalculate the distance. - fDist = Sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); + fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); } } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp index 6ffef8dc861..a0c6d3d8a1e 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp @@ -314,8 +314,8 @@ void SlavedUpdate::doAttackLogic( const Object *target ) //Allow me to wander away from the pinnedPosition. Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.zero(); - m_guardPointOffset.x += data->m_attackWanderRange * Cos( randomDirection ); - m_guardPointOffset.y += data->m_attackWanderRange * Sin( randomDirection ); + m_guardPointOffset.x += data->m_attackWanderRange * WWMath::Cos( randomDirection ); + m_guardPointOffset.y += data->m_attackWanderRange * WWMath::Sin( randomDirection ); //Offset our pinned position by our random offset. attackPosition.x += m_guardPointOffset.x; @@ -377,8 +377,8 @@ void SlavedUpdate::doScoutLogic( const Coord3D *mastersDestination ) //Allow me to wander away from the pinnedPosition. Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.zero(); - m_guardPointOffset.x += data->m_scoutWanderRange * Cos( randomDirection ); - m_guardPointOffset.y += data->m_scoutWanderRange * Sin( randomDirection ); + m_guardPointOffset.x += data->m_scoutWanderRange * WWMath::Cos( randomDirection ); + m_guardPointOffset.y += data->m_scoutWanderRange * WWMath::Sin( randomDirection ); //Offset our pinned position by our random offset. scoutPosition.x += m_guardPointOffset.x; @@ -407,8 +407,8 @@ void SlavedUpdate::doGuardLogic( Coord3D *pinnedPosition ) // recalc where we want to be if we wander around Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.zero(); - m_guardPointOffset.x += data->m_guardMaxRange * Cos( randomDirection ); - m_guardPointOffset.y += data->m_guardMaxRange * Sin( randomDirection ); + m_guardPointOffset.x += data->m_guardMaxRange * WWMath::Cos( randomDirection ); + m_guardPointOffset.y += data->m_guardMaxRange * WWMath::Sin( randomDirection ); pinnedPosition->x += m_guardPointOffset.x; pinnedPosition->y += m_guardPointOffset.y; @@ -674,8 +674,8 @@ void SlavedUpdate::moveToNewRepairSpot() //Allow me to wander away from the pinnedPosition. Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.set( master->getPosition() ); - m_guardPointOffset.x += data->m_repairRange * Cos( randomDirection ); - m_guardPointOffset.y += data->m_repairRange * Sin( randomDirection ); + m_guardPointOffset.x += data->m_repairRange * WWMath::Cos( randomDirection ); + m_guardPointOffset.y += data->m_repairRange * WWMath::Sin( randomDirection ); m_guardPointOffset.z = TheTerrainLogic->getGroundHeight( m_guardPointOffset.x, m_guardPointOffset.y ); Real altitude = GameLogicRandomValueReal( data->m_repairMinAltitude, data->m_repairMaxAltitude ); m_guardPointOffset.z += altitude; @@ -708,8 +708,8 @@ void SlavedUpdate::startSlavedEffects( const Object *slaver ) // Decide where our pinned stray point is Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.zero(); - m_guardPointOffset.x += data->m_guardMaxRange * Cos( randomDirection ); - m_guardPointOffset.y += data->m_guardMaxRange * Sin( randomDirection ); + m_guardPointOffset.x += data->m_guardMaxRange * WWMath::Cos( randomDirection ); + m_guardPointOffset.y += data->m_guardMaxRange * WWMath::Sin( randomDirection ); // mark selves as not selectable getObject()->setStatus( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_UNSELECTABLE ) ); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp index ca2af15e7dc..ecbfc554e72 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp @@ -425,7 +425,7 @@ UpdateSleepTime StealthUpdate::update() } else { - draw->setEffectiveOpacity( 0.5f + ( Sin( m_pulsePhase ) * 0.5f ) ); + draw->setEffectiveOpacity( 0.5f + ( WWMath::Sin( m_pulsePhase ) * 0.5f ) ); // between one half and full opacity m_pulsePhase += m_pulsePhaseRate; } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StructureToppleUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StructureToppleUpdate.cpp index 4a1235e6c3c..c41d57b4fbd 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StructureToppleUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StructureToppleUpdate.cpp @@ -158,15 +158,15 @@ void StructureToppleUpdate::beginStructureTopple(const DamageInfo *damageInfo) toppleAngle = m_toppleDirection.toAngle(); toppleAngle += GameLogicRandomValueReal(-PI/8, PI/8); } - m_toppleDirection.x = Cos(toppleAngle); - m_toppleDirection.y = Sin(toppleAngle); + m_toppleDirection.x = WWMath::Cos(toppleAngle); + m_toppleDirection.y = WWMath::Sin(toppleAngle); TheScriptEngine->adjustToppleDirection(getObject(), &m_toppleDirection); Real averageRadius = (building->getGeometryInfo().getMajorRadius() + building->getGeometryInfo().getMinorRadius()) / 2; Real explosionRadius = averageRadius * 0.90; - m_delayBurstLocation.x = building->getPosition()->x + explosionRadius * Cos(toppleAngle); - m_delayBurstLocation.y = building->getPosition()->y + explosionRadius * Sin(toppleAngle); + m_delayBurstLocation.x = building->getPosition()->x + explosionRadius * WWMath::Cos(toppleAngle); + m_delayBurstLocation.y = building->getPosition()->y + explosionRadius * WWMath::Sin(toppleAngle); m_delayBurstLocation.z = TheTerrainLogic->getGroundHeight(m_delayBurstLocation.x, m_delayBurstLocation.y); doToppleStartFX(building, damageInfo); @@ -231,7 +231,7 @@ UpdateSleepTime StructureToppleUpdate::update() // The building is in the process of falling over. if (m_toppleState == TOPPLESTATE_TOPPLING) { UnsignedInt now = TheGameLogic->getFrame(); - Real toppleAcceleration = TOPPLE_ACCELERATION_FACTOR * (Sin(m_accumulatedAngle) * (1.0 - m_structuralIntegrity)); + Real toppleAcceleration = TOPPLE_ACCELERATION_FACTOR * (WWMath::Sin(m_accumulatedAngle) * (1.0 - m_structuralIntegrity)); // DEBUG_LOG(("toppleAcceleration = %f", toppleAcceleration)); m_toppleVelocity += toppleAcceleration; // DEBUG_LOG(("m_toppleVelocity = %f", m_toppleVelocity)); @@ -368,8 +368,8 @@ void StructureToppleUpdate::applyCrushingDamage(Real theta) // Do this because the amount of ground that is affected will be different if the building falls // in different orientations. Real angle = orientationAngle - toppleAngle; - Real minorComponent = building->getGeometryInfo().getMinorRadius() * Cos(angle); - Real majorComponent = building->getGeometryInfo().getMajorRadius() * Sin(angle); + Real minorComponent = building->getGeometryInfo().getMinorRadius() * WWMath::Cos(angle); + Real majorComponent = building->getGeometryInfo().getMajorRadius() * WWMath::Sin(angle); Coord3D temp3D; temp3D.x = majorComponent; @@ -385,7 +385,7 @@ void StructureToppleUpdate::applyCrushingDamage(Real theta) } // The furthest away from the base of the building to explode on. - Real maxDistance = m_buildingHeight * (1.0 - Sin(theta)); + Real maxDistance = m_buildingHeight * (1.0 - WWMath::Sin(theta)); /* * Fire explosions at regular intervals across the area that the building is currently @@ -396,14 +396,14 @@ void StructureToppleUpdate::applyCrushingDamage(Real theta) // Coord3D target; Real j = m_lastCrushedLocation; for (; j < maxDistance; j += WEAPON_SPACING_PERPENDICULAR) { - jcos = j * Cos(toppleAngle); - jsin = j * Sin(toppleAngle); + jcos = j * WWMath::Cos(toppleAngle); + jsin = j * WWMath::Sin(toppleAngle); doDamageLine(building, wt, jcos, jsin, facingWidth, toppleAngle); } - jcos = maxDistance * Cos(toppleAngle); - jsin = maxDistance * Sin(toppleAngle); + jcos = maxDistance * WWMath::Cos(toppleAngle); + jsin = maxDistance * WWMath::Sin(toppleAngle); doDamageLine(building, wt, jcos, jsin, facingWidth, toppleAngle); m_lastCrushedLocation = j; @@ -424,8 +424,8 @@ void StructureToppleUpdate::doDamageLine(Object *building, const WeaponTemplate* for (Real i = -facingWidth; i < facingWidth; i += WEAPON_SPACING_PARALLEL) { - target.x = building->getPosition()->x + jcos + (i * Sin(toppleAngle)); - target.y = building->getPosition()->y + jsin + (i * Cos(toppleAngle)); + target.x = building->getPosition()->x + jcos + (i * WWMath::Sin(toppleAngle)); + target.y = building->getPosition()->y + jsin + (i * WWMath::Cos(toppleAngle)); target.z = TheTerrainLogic->getGroundHeight(target.x, target.y); TheWeaponStore->createAndFireTempWeapon(wt, building, &target); @@ -436,8 +436,8 @@ void StructureToppleUpdate::doDamageLine(Object *building, const WeaponTemplate* } // Make sure there are weapons fired and FX done on the edge of the building. - target.x = building->getPosition()->x + jcos + (facingWidth * Sin(toppleAngle)); - target.y = building->getPosition()->y + jsin + (facingWidth * Cos(toppleAngle)); + target.x = building->getPosition()->x + jcos + (facingWidth * WWMath::Sin(toppleAngle)); + target.y = building->getPosition()->y + jsin + (facingWidth * WWMath::Cos(toppleAngle)); target.z = TheTerrainLogic->getGroundHeight(target.x, target.y); TheWeaponStore->createAndFireTempWeapon(wt, building, &target); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp index 537d35974a2..3a6e483c428 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp @@ -185,13 +185,13 @@ void ToppleUpdate::applyTopplingForce( const Coord3D* toppleDirection, Real topp // yeah, it assumes the models are constructed appropriately, but is a cheap way // of minimizing the problem. (srj) Real curAngleX = normalizeAngle(getObject()->getOrientation()); - Real toppleAngle = normalizeAngle(Atan2(m_toppleDirection.y, m_toppleDirection.x)); + Real toppleAngle = normalizeAngle(WWMath::Atan2(m_toppleDirection.y, m_toppleDirection.x)); if (d->m_toppleLeftOrRightOnly) { // it's a fence or such, and can only topple left or right, so pick the closest toppleAngle = angleClosestTo(curAngleX + PI/2, curAngleX - PI/2, toppleAngle); - m_toppleDirection.x = Cos(toppleAngle); - m_toppleDirection.y = Sin(toppleAngle); + m_toppleDirection.x = WWMath::Cos(toppleAngle); + m_toppleDirection.y = WWMath::Sin(toppleAngle); // go ahead and remove it from the pathfinder now, rather than waiting for the topple to // finish.... since we might be in a slightly different position when toppled, which can diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/WaveGuideUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/WaveGuideUpdate.cpp index 9ee80c51bee..7cd29e289c9 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/WaveGuideUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/WaveGuideUpdate.cpp @@ -718,8 +718,8 @@ void WaveGuideUpdate::doDamage() // angle is rotated, because we computed from 'from' and 'to' points of // the bridge going *across* the valley, not pointing *down* it // - u.x = Cos( angle + modData->m_bridgeParticleAngleFudge ); - u.y = Sin( angle + modData->m_bridgeParticleAngleFudge ); + u.x = WWMath::Cos( angle + modData->m_bridgeParticleAngleFudge ); + u.y = WWMath::Sin( angle + modData->m_bridgeParticleAngleFudge ); u.z = 0.0f; y.crossProduct( &z, &u, &y ); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp index e8778106ea2..7cf3a8a56ba 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp @@ -826,7 +826,7 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate Real attackRangeSqr = sqr(getAttackRange(bonus)); if (distSqr > attackRangeSqr) { - //DEBUG_ASSERTCRASH(distSqr < 5*5 || distSqr < attackRangeSqr*1.2f, ("*** victim is out of range (%f vs %f) of this weapon -- why did we attempt to fire?",Sqrt(distSqr),Sqrt(attackRangeSqr))); + //DEBUG_ASSERTCRASH(distSqr < 5*5 || distSqr < attackRangeSqr*1.2f, ("*** victim is out of range (%f vs %f) of this weapon -- why did we attempt to fire?",WWMath::Sqrt(distSqr),WWMath::Sqrt(attackRangeSqr))); //-extraLogging #if defined(RTS_DEBUG) @@ -848,7 +848,7 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate if (distSqr < minAttackRangeSqr-0.5f && !isProjectileDetonation) #endif { - DEBUG_ASSERTCRASH(distSqr > minAttackRangeSqr*0.8f, ("*** victim is closer than min attack range (%f vs %f) of this weapon -- why did we attempt to fire?",Sqrt(distSqr),Sqrt(minAttackRangeSqr))); + DEBUG_ASSERTCRASH(distSqr > minAttackRangeSqr*0.8f, ("*** victim is closer than min attack range (%f vs %f) of this weapon -- why did we attempt to fire?",WWMath::Sqrt(distSqr),WWMath::Sqrt(minAttackRangeSqr))); //-extraLogging #if defined(RTS_DEBUG) @@ -874,7 +874,7 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate targetPos.set( victimPos ); } Real reAngle = getWeaponRecoilAmount(); - Real reDir = reAngle != 0.0f ? (Atan2(victimPos->y - sourcePos->y, victimPos->x - sourcePos->x)) : 0.0f; + Real reDir = reAngle != 0.0f ? (WWMath::Atan2(victimPos->y - sourcePos->y, victimPos->x - sourcePos->x)) : 0.0f; VeterancyLevel v = sourceObj->getVeterancyLevel(); const FXList* fx = isProjectileDetonation ? getProjectileDetonateFX(v) : getFireFX(v); @@ -1052,8 +1052,8 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate Coord3D firingOffset; firingOffset.zero(); - firingOffset.x = scatterRadius * Cos( scatterAngleRadian ); - firingOffset.y = scatterRadius * Sin( scatterAngleRadian ); + firingOffset.x = scatterRadius * WWMath::Cos( scatterAngleRadian ); + firingOffset.y = scatterRadius * WWMath::Sin( scatterAngleRadian ); projectileDestination.x += firingOffset.x; projectileDestination.y += firingOffset.y; @@ -1921,7 +1921,7 @@ Bool Weapon::computeApproachTarget(const Object *source, const Object *target, c if (source->isAboveTerrain()) { // Don't do a 180 degree turn. - Real angle = Atan2(-dir.y, -dir.x); + Real angle = WWMath::Atan2(-dir.y, -dir.x); Real relAngle = source->getOrientation()- angle; if (relAngle>2*PI) relAngle -= 2*PI; if (relAngle<-2*PI) relAngle += 2*PI; @@ -1934,9 +1934,9 @@ Bool Weapon::computeApproachTarget(const Object *source, const Object *target, c if (angleOffset != 0.0f) { - Real angle = Atan2(dir.y, dir.x); - dir.x = (Real)Cos(angle + angleOffset); - dir.y = (Real)Sin(angle + angleOffset); + Real angle = WWMath::Atan2(dir.y, dir.x); + dir.x = (Real)WWMath::Cos(angle + angleOffset); + dir.y = (Real)WWMath::Sin(angle + angleOffset); } // select a spot along the line between us, halfway between the min & max range. @@ -1981,9 +1981,9 @@ Bool Weapon::computeApproachTarget(const Object *source, const Object *target, c if (angleOffset != 0.0f) { - Real angle = Atan2(dir.y, dir.x); - dir.x = (Real)Cos(angle + angleOffset); - dir.y = (Real)Sin(angle + angleOffset); + Real angle = WWMath::Atan2(dir.y, dir.x); + dir.x = (Real)WWMath::Cos(angle + angleOffset); + dir.y = (Real)WWMath::Sin(angle + angleOffset); } // select a spot along the line between us, in range of our weapon diff --git a/Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp b/Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp index 7775245e531..c7991dc7827 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp @@ -4584,8 +4584,8 @@ void ScriptEngine::reset() } m_breezeInfo.m_direction = PI/3; - m_breezeInfo.m_directionVec.x = Sin(m_breezeInfo.m_direction); - m_breezeInfo.m_directionVec.y = Cos(m_breezeInfo.m_direction); + m_breezeInfo.m_directionVec.x = WWMath::Sin(m_breezeInfo.m_direction); + m_breezeInfo.m_directionVec.y = WWMath::Cos(m_breezeInfo.m_direction); m_breezeInfo.m_intensity = 0.07f*PI/4; m_breezeInfo.m_lean = 0.07f*PI/4; m_breezeInfo.m_breezePeriod = LOGICFRAMES_PER_SECOND * 5; @@ -5707,8 +5707,8 @@ void ScriptEngine::setSway( ScriptAction *pAction ) DEBUG_ASSERTCRASH(pAction->getNumParameters() >= 5, ("Not enough parameters.")); ++m_breezeInfo.m_breezeVersion; m_breezeInfo.m_direction = pAction->getParameter(0)->getReal(); - m_breezeInfo.m_directionVec.x = Sin(m_breezeInfo.m_direction); - m_breezeInfo.m_directionVec.y = Cos(m_breezeInfo.m_direction); + m_breezeInfo.m_directionVec.x = WWMath::Sin(m_breezeInfo.m_direction); + m_breezeInfo.m_directionVec.y = WWMath::Cos(m_breezeInfo.m_direction); m_breezeInfo.m_intensity = pAction->getParameter(1)->getReal(); m_breezeInfo.m_lean = pAction->getParameter(2)->getReal(); m_breezeInfo.m_breezePeriod = pAction->getParameter(3)->getInt(); diff --git a/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp index c3e81cdee1f..8cb922c2862 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp @@ -805,7 +805,7 @@ static void populateRandomStartPosition( GameInfo *game ) { Coord3D p1 = c1->second; Coord3D p2 = c2->second; - startSpotDistance[i][j] = Sqrt( sqr(p1.x-p2.x) + sqr(p1.y-p2.y) ); + startSpotDistance[i][j] = WWMath::Sqrt( sqr(p1.x-p2.x) + sqr(p1.y-p2.y) ); } } else diff --git a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp index adb44f0d3b3..b2096866ce6 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp @@ -313,8 +313,8 @@ void W3DParticleSystemManager::doParticles(RenderInfoClass &rinfo) Coord3D worldStart, worldEnd; ICoord2D pixelStart, pixelEnd; sys->getPosition( &worldStart ); - worldEnd.x = Cos( sys->getWindAngle() ) * 50.0f + worldStart.x; - worldEnd.y = Sin( sys->getWindAngle() ) * 50.0f + worldStart.y; + worldEnd.x = WWMath::Cos( sys->getWindAngle() ) * 50.0f + worldStart.x; + worldEnd.y = WWMath::Sin( sys->getWindAngle() ) * 50.0f + worldStart.y; worldEnd.z = worldStart.z; TheTacticalView->worldToScreen( &worldStart, &pixelStart ); TheTacticalView->worldToScreen( &worldEnd, &pixelEnd ); diff --git a/GeneralsMD/Code/GameEngine/CMakeLists.txt b/GeneralsMD/Code/GameEngine/CMakeLists.txt index 3b6d674c2b4..6d939511d5d 100644 --- a/GeneralsMD/Code/GameEngine/CMakeLists.txt +++ b/GeneralsMD/Code/GameEngine/CMakeLists.txt @@ -659,7 +659,7 @@ set(GAMEENGINE_SRC Source/Common/System/StackDump.cpp # Source/Common/System/StreamingArchiveFile.cpp # Source/Common/System/SubsystemInterface.cpp - Source/Common/System/Trig.cpp + # Source/Common/System/UnicodeString.cpp Source/Common/System/Upgrade.cpp # Source/Common/System/Xfer.cpp diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp deleted file mode 100644 index 9d27ca49020..00000000000 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/* -** Command & Conquer Generals Zero Hour(tm) -** Copyright 2025 Electronic Arts Inc. -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -*/ - -//////////////////////////////////////////////////////////////////////////////// -// // -// (c) 2001-2003 Electronic Arts Inc. // -// // -//////////////////////////////////////////////////////////////////////////////// - -// Trig.cpp -// fast trig functions -// Author: Michael S. Booth, March 1994 -// Converted to Generals by Matthew D. Campbell, February 2002 - -#include "PreRTS.h" - -#include -#include - -#include "Lib/BaseType.h" -#include "Lib/trig.h" -#include "WWMath/wwmath.h" - -#define TWOPI 6.28318530718f -#define DEG2RAD 0.0174532925199f -#define TRIG_RES 4096 - -// the following are for fixed point ints with 12 fractional bits -#define INT_ONE 4096 -#define INT_TWOPI 25736 -#define INT_THREEPIOVERTWO 19302 -#define INT_PI 12868 -#define INT_HALFPI 6434 - -Real Sin(Real x) -{ - return WWMath::Sin(x); -} - -Real Cos(Real x) -{ - return WWMath::Cos(x); -} - -Real Tan(Real x) -{ - return WWMath::Tan(x); -} - -Real ACos(Real x) -{ - return WWMath::Acos(x); -} - -Real ASin(Real x) -{ - return WWMath::Asin(x); -} - -Real Atan2(Real y, Real x) -{ - return WWMath::Atan2(y, x); -} - -Real Sqrt(Real x) -{ - return WWMath::Sqrt(x); -} - -#ifdef REGENERATE_TRIG_TABLES -void initTrig() -{ - static Byte inited = FALSE; - Real angle, r; - int i; - - if (inited) - return; - - inited = TRUE; - - static int columns = 8; - int column = 0; - FILE *fp = fopen("trig.txt", "w"); - fprintf(fp, "static Int sinLookup[TRIG_RES] = {\n"); - for( i=0; igetGeometryInfo().getMajorRadius(); Real width = obj->getGeometryInfo().getMinorRadius(); - Real pitchHeight = length*Sin(m_locoInfo->m_pitch + m_locoInfo->m_accelerationPitch - groundPitch); - Real rollHeight = width*Sin(m_locoInfo->m_roll + m_locoInfo->m_accelerationRoll - groundRoll); + Real pitchHeight = length*WWMath::Sin(m_locoInfo->m_pitch + m_locoInfo->m_accelerationPitch - groundPitch); + Real rollHeight = width*WWMath::Sin(m_locoInfo->m_roll + m_locoInfo->m_accelerationRoll - groundRoll); info.m_totalZ = fabs(pitchHeight)/4 + fabs(rollHeight)/4; return; // maintain the same orientation while we fly through the air. } @@ -2056,8 +2056,8 @@ void Drawable::calcPhysicsXformWheels( const Locomotor *locomotor, PhysicsXformI // Calculate suspension info. Real length = obj->getGeometryInfo().getMajorRadius(); Real width = obj->getGeometryInfo().getMinorRadius(); - Real pitchHeight = length*Sin(info.m_totalPitch-groundPitch); - Real rollHeight = width*Sin(info.m_totalRoll-groundRoll); + Real pitchHeight = length*WWMath::Sin(info.m_totalPitch-groundPitch); + Real rollHeight = width*WWMath::Sin(info.m_totalRoll-groundRoll); if (DO_WHEELS) { // calculate each wheel position @@ -2257,8 +2257,8 @@ void Drawable::calcPhysicsXformMotorcycle( const Locomotor *locomotor, PhysicsXf // Calculate suspension info. Real length = obj->getGeometryInfo().getMajorRadius(); //Real width = obj->getGeometryInfo().getMinorRadius(); - Real pitchHeight = length*Sin(m_locoInfo->m_pitch + m_locoInfo->m_accelerationPitch - groundPitch); - //Real rollHeight = width*Sin(m_locoInfo->m_roll + m_locoInfo->m_accelerationRoll - groundRoll); + Real pitchHeight = length*WWMath::Sin(m_locoInfo->m_pitch + m_locoInfo->m_accelerationPitch - groundPitch); + //Real rollHeight = width*WWMath::Sin(m_locoInfo->m_roll + m_locoInfo->m_accelerationRoll - groundRoll); info.m_totalZ = fabs(pitchHeight)/4;// + fabs(rollHeight)/4; //return; // maintain the same orientation while we fly through the air. } @@ -2363,8 +2363,8 @@ void Drawable::calcPhysicsXformMotorcycle( const Locomotor *locomotor, PhysicsXf // Calculate suspension info. Real length = obj->getGeometryInfo().getMajorRadius(); Real width = obj->getGeometryInfo().getMinorRadius(); - Real pitchHeight = length*Sin(info.m_totalPitch-groundPitch); - Real rollHeight = width*Sin(info.m_totalRoll-groundRoll); + Real pitchHeight = length*WWMath::Sin(info.m_totalPitch-groundPitch); + Real rollHeight = width*WWMath::Sin(info.m_totalRoll-groundRoll); if (DO_WHEELS) { // calculate each wheel position @@ -4195,8 +4195,8 @@ Bool Drawable::handleWeaponFireFX(WeaponSlotType wslot, Int specificBarrelToUse, recoilAngle += PI; if (m_locoInfo) { - m_locoInfo->m_accelerationPitchRate += recoilAmount * Cos(recoilAngle); - m_locoInfo->m_accelerationRollRate += recoilAmount * Sin(recoilAngle); + m_locoInfo->m_accelerationPitchRate += recoilAmount * WWMath::Cos(recoilAngle); + m_locoInfo->m_accelerationRollRate += recoilAmount * WWMath::Sin(recoilAngle); } } diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable/Update/SwayClientUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable/Update/SwayClientUpdate.cpp index 874b6f74548..fafafc4e380 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable/Update/SwayClientUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable/Update/SwayClientUpdate.cpp @@ -121,7 +121,7 @@ void SwayClientUpdate::clientUpdate() m_curValue += m_curDelta * timeScale; if (m_curValue > 2*PI) m_curValue -= 2*PI; - Real cosine = Cos(m_curValue); + Real cosine = WWMath::Cos(m_curValue); Real targetAngle = cosine * m_curAngleLimit + m_leanAngle; Real deltaAngle = targetAngle - m_curAngle; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp index a3654896238..e5a9dd3188b 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp @@ -709,7 +709,7 @@ Object *AI::findClosestEnemy( const Object *me, Real range, UnsignedInt qualifie } Real distSqr = ThePartitionManager->getDistanceSquared(me, theEnemy, FROM_BOUNDINGSPHERE_2D); - Real dist = Sqrt(distSqr); + Real dist = WWMath::Sqrt(distSqr); Int modifier = dist/getAiData()->m_attackPriorityDistanceModifier; Int modPriority = curPriority-modifier; if (modPriority < 1) diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp index 6f017a6bf92..b77f5360b90 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp @@ -647,7 +647,7 @@ Object *AIPlayer::buildStructureWithDozer(const ThingTemplate *bldgPlan, BuildLi dx = dozer->getPosition()->x - pos.x; dy = dozer->getPosition()->y - pos.y; - Int count = Sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); + Int count = WWMath::Sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); if (count<2) count = 2; Int i; color.green = 1; @@ -1354,7 +1354,7 @@ Int AIPlayer::getPlayerSuperweaponValue(Coord3D *center, Int playerNdx, Real rad Real dy = center->y - pos.y; if (dx*dx+dy*dygetTemplate()->calcCostToBuild(pPlayer); if (pObj->isKindOf(KINDOF_COMMANDCENTER)) @@ -3140,7 +3140,7 @@ void AIPlayer::computeCenterAndRadiusOfBase(Coord3D *center, Real *radius) Real radSqr = dx*dx+dy*dy; if (radSqr>maxRadSqr) maxRadSqr=radSqr; } - *radius = Sqrt(maxRadSqr); + *radius = WWMath::Sqrt(maxRadSqr); } //---------------------------------------------------------------------------------------------------------- diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp index 35cf28f857a..0cef68c75d6 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp @@ -608,8 +608,8 @@ StateReturnType AIRappelState::update() bldg->getGeometryInfo().getBoundingCircleRadius()); Real angle = GameLogicRandomValueReal( PI, 2*PI );//Downish. Coord3D startPosition = *bldg->getPosition(); - startPosition.x += offset * Cos( angle ); - startPosition.y += offset * Sin( angle ); + startPosition.x += offset * WWMath::Cos( angle ); + startPosition.y += offset * WWMath::Sin( angle ); startPosition.z = TheTerrainLogic->getGroundHeight( startPosition.x, startPosition.y ); obj->setPosition( &startPosition ); @@ -3675,7 +3675,7 @@ StateReturnType AIAttackMoveToState::update() if (distSqr < sqr(ATTACK_CLOSE_ENOUGH_CELLS*PATHFIND_CELL_SIZE_F)) { return ret; } - DEBUG_LOG(("AIAttackMoveToState::update Distance from goal %f, retrying.", Sqrt(distSqr))); + DEBUG_LOG(("AIAttackMoveToState::update Distance from goal %f, retrying.", WWMath::Sqrt(distSqr))); ret = STATE_CONTINUE; m_retryCount--; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp index 55f4421c41e..b242365eb77 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp @@ -1117,7 +1117,7 @@ StateReturnType TurretAIAimTurretState::update() Real actualPitch; if( v.length() > 0 ) - actualPitch = ASin( v.z / v.length() ); + actualPitch = WWMath::Asin( v.z / v.length() ); else actualPitch = 0;// Don't point at NAN, just point at 0 if they are right on us diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp index 5055d895cd3..69791c9fd76 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp @@ -286,7 +286,7 @@ void PolygonTrigger::updateBounds() const Real halfWidth = (m_bounds.hi.x - m_bounds.lo.x) / 2.0f; Real halfHeight = (m_bounds.hi.y + m_bounds.lo.y) / 2.0f; - m_radius = Sqrt(halfHeight*halfHeight + halfWidth*halfWidth); + m_radius = WWMath::Sqrt(halfHeight*halfHeight + halfWidth*halfWidth); } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp index a63b4539eb5..95fa848361a 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp @@ -339,8 +339,8 @@ Bridge::Bridge(Object *bridgeObj) Real halfsizeY = bridgeObj->getGeometryInfo().getMinorRadius(); m_bridgeInfo.bridgeWidth = 2*halfsizeY; - Real c = (Real)Cos(angle); - Real s = (Real)Sin(angle); + Real c = (Real)WWMath::Cos(angle); + Real s = (Real)WWMath::Sin(angle); m_bridgeInfo.fromLeft.set(pos->x-halfsizeX*c-halfsizeY*s, pos->y + halfsizeY*c - halfsizeX*s, pos->z); m_bridgeInfo.toLeft.set(pos->x+halfsizeX*c-halfsizeY*s, pos->y + halfsizeY*c + halfsizeX*s, pos->z); @@ -1468,11 +1468,11 @@ void makeAlignToNormalMatrix( Real angle, const Coord3D& pos, const Coord3D& nor /* It is extremely important that the resulting matrix is such that the xvector points in the angle we specified; specifically, - that Atan2(xvec.y, xvec.x) == angle. So we must construct + that WWMath::Atan2(xvec.y, xvec.x) == angle. So we must construct the matrix carefully to ensure this! */ - x.x = Cos( angle ); - x.y = Sin( angle ); + x.x = WWMath::Cos( angle ); + x.y = WWMath::Sin( angle ); x.z = 0.0f; //x.normalize(); -- redundant; is normalized by definition @@ -2369,7 +2369,7 @@ void TerrainLogic::setWaterHeight( const WaterHandle *water, Real height, Real d center.z = 0.0f; // irrelevant // the max radius to scan around us is the diagonal of the bounding region - Real maxDist = Sqrt( affectedRegion.width() * affectedRegion.width() + + Real maxDist = WWMath::Sqrt( affectedRegion.width() * affectedRegion.width() + affectedRegion.height() * affectedRegion.height() ); // scan the objects in the area of the water affected @@ -2652,8 +2652,8 @@ void TerrainLogic::flattenTerrain(Object *obj) Real halfsizeY = obj->getGeometryInfo().getMinorRadius(); - Real c = (Real)Cos(angle); - Real s = (Real)Sin(angle); + Real c = (Real)WWMath::Cos(angle); + Real s = (Real)WWMath::Sin(angle); Vector3 topLeft(pos->x-halfsizeX*c-halfsizeY*s, pos->y + halfsizeY*c - halfsizeX*s, 0); Vector3 topRight(pos->x+halfsizeX*c-halfsizeY*s, pos->y + halfsizeY*c + halfsizeX*s, 0); @@ -2879,7 +2879,7 @@ void TerrainLogic::createCraterInTerrain(Object *obj) deltaX = ( i * MAP_XY_FACTOR ) - pos->x; deltaY = ( j * MAP_XY_FACTOR ) - pos->y; - Real distance = Sqrt( sqr( deltaX ) + sqr( deltaY ) ); + Real distance = WWMath::Sqrt( sqr( deltaX ) + sqr( deltaY ) ); if ( distance < radius ) //inside circle { diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp index ae9c4537fad..ba6d246a9a1 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp @@ -172,11 +172,11 @@ static Bool calcTrajectory( Real dz = end.z - start.z; // calculating the angle is trivial. - angle = Atan2(dy, dx); + angle = WWMath::Atan2(dy, dx); // calculating the pitch requires a bit more effort. Real horizDistSqr = sqr(dx) + sqr(dy); - Real horizDist = Sqrt(horizDistSqr); + Real horizDist = WWMath::Sqrt(horizDistSqr); // calc the two possible pitches that will cover the given horizontal range. // (this is actually only true if dz==0, but is a good first guess) @@ -185,7 +185,7 @@ static Bool calcTrajectory( // let's start by aiming directly for it. we know this isn't right (unless gravity // is zero, which it's not) but is a good starting point... - Real theta = Atan2(dz, horizDist); + Real theta = WWMath::Atan2(dz, horizDist); // if the angle isn't pretty shallow, we can get a better initial guess by using // the code below... const Real SHALLOW_ANGLE = 0.5f * PI / 180.0f; @@ -194,7 +194,7 @@ static Bool calcTrajectory( Real t = horizDist / velocity; Real vz = (dz/t + 0.5f*gravity*t); Real sineOfAngle = clamp(-1.0f, vz / velocity, 1.0f); - theta = ASin(sineOfAngle)*0.5f; + theta = WWMath::Asin(sineOfAngle)*0.5f; } /* @@ -206,7 +206,7 @@ static Bool calcTrajectory( { return false; } - Real theta = ASin(sineOfAngle)*0.5f; + Real theta = WWMath::Asin(sineOfAngle)*0.5f; */ Real pitches[2]; @@ -228,10 +228,10 @@ static Bool calcTrajectory( // calc the horiz-speed & time for each. // note that time can only be negative for 90getMinimumAttackRange(); Real maxRange = detWeap->getUnmodifiedAttackRange(); - Real range = Sqrt(ThePartitionManager->getDistanceSquared( projectile, &victimPosToUse, FROM_CENTER_2D ) ); + Real range = WWMath::Sqrt(ThePartitionManager->getDistanceSquared( projectile, &victimPosToUse, FROM_CENTER_2D ) ); Real rangeRatio = (range - minRange) / (maxRange - minRange); m_flightPathSpeed = (rangeRatio * (weaponSpeed - minWeaponSpeed)) + minWeaponSpeed; } @@ -611,7 +611,7 @@ UpdateSleepTime DumbProjectileBehavior::update() Real distVictimMovedSqr = sqr(delta.x) + sqr(delta.y) + sqr(delta.z); if (distVictimMovedSqr > 0.1f) { - Real distVictimMoved = Sqrt(distVictimMovedSqr); + Real distVictimMoved = WWMath::Sqrt(distVictimMovedSqr); if (distVictimMoved > d->m_flightPathAdjustDistPerFrame) distVictimMoved = d->m_flightPathAdjustDistPerFrame; delta.normalize(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/FlightDeckBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/FlightDeckBehavior.cpp index 07714caafff..7ccaaa8c0dc 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/FlightDeckBehavior.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/FlightDeckBehavior.cpp @@ -494,8 +494,8 @@ Bool FlightDeckBehavior::reserveSpace(ObjectID id, Real parkingOffset, ParkingPl calcPPInfo( id, info ); if (parkingOffset != 0.0f) { - info->parkingSpace.x += parkingOffset * Cos(ppi->m_orientation); - info->parkingSpace.y += parkingOffset * Sin(ppi->m_orientation); + info->parkingSpace.x += parkingOffset * WWMath::Cos(ppi->m_orientation); + info->parkingSpace.y += parkingOffset * WWMath::Sin(ppi->m_orientation); } } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp index e27eea06598..c315d227f5c 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp @@ -248,7 +248,7 @@ void GenerateMinefieldBehavior::placeMinesAlongLine(const Coord3D& posStart, con Real dx = posEnd.x - posStart.x; Real dy = posEnd.y - posStart.y; - Real len = Sqrt(sqr(dx) + sqr(dy)); + Real len = WWMath::Sqrt(sqr(dx) + sqr(dy)); Real mineRadius = mineTemplate->getTemplateGeometryInfo().getBoundingCircleRadius(); Real mineDiameter = mineRadius * 2.0f; Real mineJitter = mineRadius*d->m_randomJitter; @@ -320,8 +320,8 @@ void GenerateMinefieldBehavior::placeMinesAroundCircle(const Coord3D& pos, Real for (Real angle = 0; angle < angleLim; angle += angleInc) { Coord3D pt; - pt.x = pos.x + radius * Cos(angle); - pt.y = pos.y + radius * Sin(angle); + pt.x = pos.x + radius * WWMath::Cos(angle); + pt.y = pos.y + radius * WWMath::Sin(angle); pt.z = TheTerrainLogic->getGroundHeight( pt.x, pt.y ); offsetBySmallRandomAmount(pt, mineJitter); placeMineAt(pt, mineTemplate, team, obj); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp index 73eca0babb5..7ffc6e7d3bc 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp @@ -570,7 +570,7 @@ void MinefieldBehavior::setScootParms(const Coord3D& start, const Coord3D& end) if (start.z > endOnGround.z) { // figure out how long it will take to fall, and replace scoot time with that - UnsignedInt fallingTime = REAL_TO_INT_CEIL(Sqrt(2.0f * (start.z - endOnGround.z) / fabs(TheGlobalData->m_gravity))); + UnsignedInt fallingTime = REAL_TO_INT_CEIL(WWMath::Sqrt(2.0f * (start.z - endOnGround.z) / fabs(TheGlobalData->m_gravity))); // we can scoot after we land, but don't want to stop scooting before we land if (scootFromStartingPointTime < fallingTime) scootFromStartingPointTime = fallingTime; @@ -588,7 +588,7 @@ void MinefieldBehavior::setScootParms(const Coord3D& start, const Coord3D& end) Real dx = endOnGround.x - start.x; Real dy = endOnGround.y - start.y; Real dz = endOnGround.z - start.z; - Real dist = Sqrt(sqr(dx) + sqr(dy)); + Real dist = WWMath::Sqrt(sqr(dx) + sqr(dy)); if (dist <= 0.1f && fabs(dz) <= 0.1f) { obj->setPosition(&endOnGround); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp index 64338846eef..13c7bcb134a 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp @@ -354,8 +354,8 @@ Bool ParkingPlaceBehavior::reserveSpace(ObjectID id, Real parkingOffset, Parking calcPPInfo( id, info ); if (parkingOffset != 0.0f) { - info->parkingSpace.x += parkingOffset * Cos(ppi->m_orientation); - info->parkingSpace.y += parkingOffset * Sin(ppi->m_orientation); + info->parkingSpace.x += parkingOffset * WWMath::Cos(ppi->m_orientation); + info->parkingSpace.y += parkingOffset * WWMath::Sin(ppi->m_orientation); } } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp index 75a77f2ee2b..3d14c15ef67 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp @@ -299,7 +299,7 @@ void SlowDeathBehavior::beginSlowDeath(const DamageInfo *damageInfo) physics->setExtraBounciness(-1.0); // we don't want this guy to bounce at all physics->setExtraFriction(-3 * SECONDS_PER_LOGICFRAME_REAL); // reduce his ground friction a bit physics->setAllowBouncing(true); - Real orientation = Atan2(force.y, force.x); + Real orientation = WWMath::Atan2(force.y, force.x); physics->setAngles(orientation, 0, 0); obj->getDrawable()->setModelConditionState(MODELCONDITION_EXPLODED_FLAILING); m_flags |= (1<pathfinder()->validMovementTerrain( LAYER_GROUND, loco, &startPosition)) { // try front & back. Real offset = getObject()->getGeometryInfo().getMajorRadius(); - startPosition.x -= offset*Cos(exitAngle); - startPosition.y -= offset*Sin(exitAngle); + startPosition.x -= offset*WWMath::Cos(exitAngle); + startPosition.y -= offset*WWMath::Sin(exitAngle); if (!TheAI->pathfinder()->validMovementTerrain(LAYER_GROUND, loco, &startPosition)) { - startPosition.x += 2*offset*Cos(exitAngle); - startPosition.y += 2*offset*Sin(exitAngle); + startPosition.x += 2*offset*WWMath::Cos(exitAngle); + startPosition.y += 2*offset*WWMath::Sin(exitAngle); if (!TheAI->pathfinder()->validMovementTerrain(LAYER_GROUND, loco, &startPosition)) { startPosition = *getObject()->getPosition(); } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp index 0da2deb1da7..718a5526a67 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp @@ -737,8 +737,8 @@ void OpenContain::scatterToNearbyPosition(Object* rider) Real dist = GameLogicRandomValueReal( minRadius, maxRadius ); Coord3D pos; - pos.x = dist * Cos( angle ) + containerPos->x; - pos.y = dist * Sin( angle ) + containerPos->y; + pos.x = dist * WWMath::Cos( angle ) + containerPos->x; + pos.y = dist * WWMath::Sin( angle ) + containerPos->y; pos.z = TheTerrainLogic->getLayerHeight( pos.x, pos.y, theContainer->getLayer() ); // set orientation diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cpp index c15eefa1712..cfd93aec88c 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cpp @@ -372,8 +372,8 @@ void TunnelContain::scatterToNearbyPosition(Object* obj) Real dist = GameLogicRandomValueReal( minRadius, maxRadius ); Coord3D pos; - pos.x = dist * Cos( angle ) + containerPos->x; - pos.y = dist * Sin( angle ) + containerPos->y; + pos.x = dist * WWMath::Cos( angle ) + containerPos->x; + pos.y = dist * WWMath::Sin( angle ) + containerPos->y; pos.z = TheTerrainLogic->getGroundHeight( pos.x, pos.y ); // set orientation diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp index 65cac369fb3..cf0f2463471 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp @@ -131,7 +131,7 @@ static Real tryToRotateVector3D( // dot of two unit vectors is cos of angle between them. Real cosine = Vector3::Dot_Product(curDir, goalDir); // bound it in case of numerical error - Real angleBetween = (Real)ACos(clamp(-1.0f, cosine, 1.0f)); + Real angleBetween = (Real)WWMath::Acos(clamp(-1.0f, cosine, 1.0f)); if (maxAngle < 0) { @@ -889,8 +889,8 @@ void Locomotor::locoUpdate_moveTowardsAngle(Object* obj, Real goalAngle) { // can't stay in one place; move in the desired direction at min speed. Coord3D desiredPos = *obj->getPosition(); - desiredPos.x += Cos(goalAngle) * minSpeed * 2; - desiredPos.y += Sin(goalAngle) * minSpeed * 2; + desiredPos.x += WWMath::Cos(goalAngle) * minSpeed * 2; + desiredPos.y += WWMath::Sin(goalAngle) * minSpeed * 2; // pass a huge num for "dist to goal", so that we don't think we're nearing // our destination and thus slow down... const Real onPathDistToGoal = 99999.0f; @@ -904,8 +904,8 @@ void Locomotor::locoUpdate_moveTowardsAngle(Object* obj, Real goalAngle) { DEBUG_ASSERTCRASH(m_template->m_appearance != LOCO_THRUST, ("THRUST should always have minspeeds!")); Coord3D desiredPos = *obj->getPosition(); - desiredPos.x += Cos(goalAngle) * 1000.0f; - desiredPos.y += Sin(goalAngle) * 1000.0f; + desiredPos.x += WWMath::Cos(goalAngle) * 1000.0f; + desiredPos.y += WWMath::Sin(goalAngle) * 1000.0f; PhysicsTurningType rotating = rotateTowardsPosition(obj, desiredPos); physics->setTurning(rotating); handleBehaviorZ(obj, physics, *obj->getPosition()); @@ -1373,8 +1373,8 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, targetAngle += turnAmount; } Coord3D offset; - offset.x = Cos(targetAngle)*distance; - offset.y = Sin(targetAngle)*distance; + offset.x = WWMath::Cos(targetAngle)*distance; + offset.y = WWMath::Sin(targetAngle)*distance; offset.z = 0; const Coord3D* pos = obj->getPosition(); @@ -1863,8 +1863,8 @@ void Locomotor::moveTowardsPositionWings(Object* obj, PhysicsBehavior *physics, // project a spot "radius" dist away from it, in that dir Coord3D desiredPos = goalPos; - desiredPos.x += Cos(angleTowardPos) * turnRadius; - desiredPos.y += Sin(angleTowardPos) * turnRadius; + desiredPos.x += WWMath::Cos(angleTowardPos) * turnRadius; + desiredPos.y += WWMath::Sin(angleTowardPos) * turnRadius; moveTowardsPositionOther(obj, physics, desiredPos, 0, desiredSpeed); return; } @@ -2087,7 +2087,7 @@ Real Locomotor::calcLiftToUseAtPt(Object* obj, PhysicsBehavior *physics, Real cu // thus // a = 2(dz - v t)/t^2 // and - // t = (-v +- Sqrt(v*v + 2*a*dz))/a + // t = (-v +- WWMath::Sqrt(v*v + 2*a*dz))/a // // but if we assume t=1, then // a=2(dz-v) @@ -2164,8 +2164,8 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 #if 0 Coord3D desiredPos = *obj->getPosition(); // well, desired Dir, anyway - desiredPos.x += Cos(angle + amount) * radius; - desiredPos.y += Sin(angle + amount) * radius; + desiredPos.x += WWMath::Cos(angle + amount) * radius; + desiredPos.y += WWMath::Sin(angle + amount) * radius; // so, the thing is, we want to rotate ourselves so that our *center* is rotated @@ -2533,8 +2533,8 @@ void Locomotor::maintainCurrentPositionWings(Object* obj, PhysicsBehavior *physi // project a spot "radius" dist away from it, in that dir Coord3D desiredPos = m_maintainPos; - desiredPos.x += Cos(angleTowardMaintainPos) * turnRadius; - desiredPos.y += Sin(angleTowardMaintainPos) * turnRadius; + desiredPos.x += WWMath::Cos(angleTowardMaintainPos) * turnRadius; + desiredPos.y += WWMath::Sin(angleTowardMaintainPos) * turnRadius; moveTowardsPositionWings(obj, physics, desiredPos, 0, m_template->m_minSpeed); } } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp index fcdd78f4105..fb794325cb1 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp @@ -290,7 +290,7 @@ class DeliverPayloadNugget : public ObjectCreationNugget Real dy = primary->y - secondary->y; //Calc length - Real length = Sqrt( dx*dx + dy*dy ); + Real length = WWMath::Sqrt( dx*dx + dy*dy ); //Normalize length dx /= length; @@ -298,14 +298,14 @@ class DeliverPayloadNugget : public ObjectCreationNugget //Rotate 90 degrees CCW. Real radians = 90.0f * PI / 180.0f; - Real s = Sin( radians ); - Real c = Cos( radians ); + Real s = WWMath::Sin( radians ); + Real c = WWMath::Cos( radians ); CCWx = dx * c + dy * -s + dx; CCWy = dx * s + dy * c + dy; //Rotate 90 degrees CW - s = Sin( -radians ); - c = Cos( -radians ); + s = WWMath::Sin( -radians ); + c = WWMath::Cos( -radians ); CWx = dx * c + dy * -s + dx; CWy = dx * s + dy * c + dy; } @@ -352,17 +352,17 @@ class DeliverPayloadNugget : public ObjectCreationNugget { Real randomRadius = GameLogicRandomValueReal(0, m_errorRadius ); Real randomAngle = GameLogicRandomValueReal(0, PI*2 ); - targetPos.x += randomRadius * Cos( randomAngle ); - targetPos.y += randomRadius * Sin( randomAngle ); + targetPos.x += randomRadius * WWMath::Cos( randomAngle ); + targetPos.y += randomRadius * WWMath::Sin( randomAngle ); } - Real orient = Atan2( moveToPos.y - startPos.y, moveToPos.x - startPos.x); + Real orient = WWMath::Atan2( moveToPos.y - startPos.y, moveToPos.x - startPos.x); if( m_data.m_distToTarget > 0 ) { const Real SLOP = 1.5f; - startPos.x -= Cos(orient) * m_data.m_distToTarget * SLOP; - startPos.y -= Sin(orient) * m_data.m_distToTarget * SLOP; + startPos.x -= WWMath::Cos(orient) * m_data.m_distToTarget * SLOP; + startPos.y -= WWMath::Sin(orient) * m_data.m_distToTarget * SLOP; } Object *transport; @@ -1105,7 +1105,7 @@ class GenericObjectCreationNugget : public ObjectCreationNugget objUp->applyForce(&force); if (m_orientInForceDirection) - orientation = Atan2(force.y, force.x); + orientation = WWMath::Atan2(force.y, force.x); } } @@ -1193,7 +1193,7 @@ class GenericObjectCreationNugget : public ObjectCreationNugget objUp->applyForce(&force); if (m_orientInForceDirection) { - orientation = Atan2(force.y, force.x); + orientation = WWMath::Atan2(force.y, force.x); } DUMPREAL(orientation); objUp->setAngles(orientation, 0, 0); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp index 79167a68603..075f7999381 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp @@ -623,7 +623,7 @@ inline Bool z_collideTest_Sphere_Nonsphere(CollideTestProc xyproc, const Collide // find the radius of the slice of the sphere that is at b_bot CollideInfo amod = *a; amod.position.z = b_bot; - amod.geom.setMajorRadius((Real)Sqrt(sqr(a->geom.getMajorRadius()) - sqr(b_bot - a->position.z))); + amod.geom.setMajorRadius((Real)WWMath::Sqrt(sqr(a->geom.getMajorRadius()) - sqr(b_bot - a->position.z))); if (xyproc(&amod, b, cinfo)) { // if you want to have 'end' collisions, you should add something like: @@ -641,7 +641,7 @@ inline Bool z_collideTest_Sphere_Nonsphere(CollideTestProc xyproc, const Collide { CollideInfo amod = *a; amod.position.z = b_top; - amod.geom.setMajorRadius((Real)Sqrt(sqr(a->geom.getMajorRadius()) - sqr(a->position.z - b_top))); + amod.geom.setMajorRadius((Real)WWMath::Sqrt(sqr(a->geom.getMajorRadius()) - sqr(a->position.z - b_top))); if (xyproc(&amod, b, cinfo)) { // if you want to have 'end' collisions, you should add something like: @@ -829,7 +829,7 @@ static Bool distCalcProc_BoundaryAndBoundary_2D( if (totalRad > 0.0f) { - Real actualDist = Sqrt(actualDistSqr); + Real actualDist = WWMath::Sqrt(actualDistSqr); Real shrunkenDist = actualDist - totalRad; if (shrunkenDist <= 0.0f) { @@ -917,7 +917,7 @@ static Bool distCalcProc_BoundaryAndBoundary_3D( Real totalRad = (geomA?geomA->getBoundingSphereRadius():0) + (geomB?geomB->getBoundingSphereRadius():0); if (totalRad > 0.0f) { - Real actualDist = Sqrt(actualDistSqr); + Real actualDist = WWMath::Sqrt(actualDistSqr); Real shrunkenDist = actualDist - totalRad; if (shrunkenDist <= 0.0f) { @@ -2228,7 +2228,7 @@ Int PartitionData::calcMaxCoiForShape(GeometryType geom, Real majorRadius, Real } case GEOMETRY_BOX: { - Real diagonal = (Real)(Sqrt(majorRadius*majorRadius + minorRadius*minorRadius)); + Real diagonal = (Real)(WWMath::Sqrt(majorRadius*majorRadius + minorRadius*minorRadius)); Int cells = ThePartitionManager->worldToCellDist(diagonal*2) + 1; result = cells * cells; break; @@ -3219,7 +3219,7 @@ Int PartitionManager::calcMinRadius(const ICoord2D& cur) } // double, not real - double dist = Sqrt(minDistSqr); + double dist = WWMath::Sqrt(minDistSqr); Int minRadius = REAL_TO_INT_CEIL( dist / m_cellSize ); return minRadius; @@ -3507,7 +3507,7 @@ Object *PartitionManager::getClosestObjects( } if (closestDistArg) { - *closestDistArg = (Real)Sqrt(closestDistSqr); + *closestDistArg = (Real)WWMath::Sqrt(closestDistSqr); } #ifdef RTS_DEBUG @@ -3634,7 +3634,7 @@ Real PartitionManager::getRelativeAngle2D( const Object *obj, const Coord3D *pos v.y = pos->y - objPos.y; v.z = 0.0f; - Real dist = (Real)Sqrt(sqr(v.x) + sqr(v.y)); + Real dist = (Real)WWMath::Sqrt(sqr(v.x) + sqr(v.y)); // normalize if (dist == 0.0f) @@ -3657,7 +3657,7 @@ Real PartitionManager::getRelativeAngle2D( const Object *obj, const Coord3D *pos else if (c > 1.0) c = 1.0; - Real value = (Real)ACos( c ); + Real value = (Real)WWMath::Acos( c ); // Determine sign by checking Z component of dir cross v // Note this is assumes 2D, and is identical to dotting the perpendicular of v with dir @@ -4568,7 +4568,7 @@ Int PartitionManager::iterateCellsBreadthFirst(const Coord3D *pos, CellBreadthFi //----------------------------------------------------------------------------- static Real calcDist2D(Real x1, Real y1, Real x2, Real y2) { - return Sqrt(sqr(x1-x2) + sqr(y1-y2)); + return WWMath::Sqrt(sqr(x1-x2) + sqr(y1-y2)); } //----------------------------------------------------------------------------- diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp index f401d23971b..dc8b6b513fc 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp @@ -2272,7 +2272,7 @@ UpdateSleepTime AIUpdateInterface::doLocomotor() } else { - Real dist = Sqrt(dSqr); + Real dist = WWMath::Sqrt(dSqr); if (dist<1) dist = 1; pos.x += 2*PATHFIND_CELL_SIZE_F*dx/(dist*LOGICFRAMES_PER_SECOND); pos.y += 2*PATHFIND_CELL_SIZE_F*dy/(dist*LOGICFRAMES_PER_SECOND); @@ -2473,7 +2473,7 @@ Real AIUpdateInterface::getLocomotorDistanceToGoal() dest = m_path->getLastNode()->getPosition(); } Real distance = ThePartitionManager->getDistanceSquared( me, dest, FROM_CENTER_3D ); - return Sqrt( distance );// Other paths return dots of normalized vectors, so one sqrt ain't so bad + return WWMath::Sqrt( distance );// Other paths return dots of normalized vectors, so one sqrt ain't so bad } else { @@ -2505,7 +2505,7 @@ Real AIUpdateInterface::getLocomotorDistanceToGoal() { if (sqr(dist) > distSqr) { - return Sqrt(distSqr); + return WWMath::Sqrt(distSqr); } else { @@ -2514,7 +2514,7 @@ Real AIUpdateInterface::getLocomotorDistanceToGoal() } if (distm_diveStartDistance; - Real endDiveDistance = Sqrt( endDiveDistanceSquared ); - Real currentDistance = Sqrt( currentDistanceSquared ); + Real endDiveDistance = WWMath::Sqrt( endDiveDistanceSquared ); + Real currentDistance = WWMath::Sqrt( currentDistanceSquared ); Real diveRatio = (startDiveDistance - currentDistance) / (startDiveDistance - endDiveDistance); @@ -368,7 +368,7 @@ Bool DeliverPayloadAIUpdate::isCloseEnoughToTarget() if ( inBound ) allowedDistanceSqr = sqr(getAllowedDistanceToTarget() + getPreOpenDistance()); - //DEBUG_LOG(("Dist to target is %f (allowed %f)",Sqrt(currentDistanceSqr),Sqrt(allowedDistanceSqr))); + //DEBUG_LOG(("Dist to target is %f (allowed %f)",WWMath::Sqrt(currentDistanceSqr),WWMath::Sqrt(allowedDistanceSqr))); if ( allowedDistanceSqr > currentDistanceSqr ) @@ -1108,7 +1108,7 @@ StateReturnType RecoverFromOffMapState::update() // Success if we should try aga enterCoord.z = owner->getPosition()->z; owner->setPosition(&enterCoord); - Real enterAngle = Atan2(ai->getMoveToPos()->y - enterCoord.y, ai->getMoveToPos()->x - enterCoord.x); + Real enterAngle = WWMath::Atan2(ai->getMoveToPos()->y - enterCoord.y, ai->getMoveToPos()->x - enterCoord.x); owner->setOrientation(enterAngle); PhysicsBehavior* physics = owner->getPhysics(); @@ -1148,7 +1148,7 @@ StateReturnType HeadOffMapState::onEnter() // Give move order out of town Region3D terrainExtent; TheTerrainLogic->getExtent( &terrainExtent ); const Real FUDGE = 1.2f; - Real HUGE_DIST = FUDGE * Sqrt(sqr(terrainExtent.hi.x - terrainExtent.lo.x) + sqr(terrainExtent.hi.y - terrainExtent.lo.y)); + Real HUGE_DIST = FUDGE * WWMath::Sqrt(sqr(terrainExtent.hi.x - terrainExtent.lo.x) + sqr(terrainExtent.hi.y - terrainExtent.lo.y)); exitCoord.x += dir->x * HUGE_DIST; exitCoord.y += dir->y * HUGE_DIST; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp index 4c1fc12bc52..6e03d06e08a 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp @@ -447,10 +447,10 @@ static Bool intersectInfiniteLine2D Real& ix, Real& iy ) { - Real bx = ax + Cos(ao); - Real by = ay + Sin(ao); - Real dx = cx + Cos(co); - Real dy = cy + Sin(co); + Real bx = ax + WWMath::Cos(ao); + Real by = ay + WWMath::Sin(ao); + Real dx = cx + WWMath::Cos(co); + Real dy = cy + WWMath::Sin(co); Real denom = ((bx - ax) * (dy - cy) - (by - ay) * (dx - cx)); if (denom == 0.0f) @@ -516,7 +516,7 @@ class JetOrHeliTaxiState : public AIMoveOutOfTheWayState Coord3D intermedPt; Bool intermed = false; - Real orient = Atan2(ppinfo.runwayPrep.y - ppinfo.parkingSpace.y, ppinfo.runwayPrep.x - ppinfo.parkingSpace.x); + Real orient = WWMath::Atan2(ppinfo.runwayPrep.y - ppinfo.parkingSpace.y, ppinfo.runwayPrep.x - ppinfo.parkingSpace.x); if (fabs(stdAngleDiff(orient, ppinfo.parkingOrientation)) > PI/128) { intermedPt.z = (ppinfo.parkingSpace.z + ppinfo.runwayPrep.z) * 0.5f; @@ -1071,7 +1071,7 @@ class HeliTakeoffOrLandingState : public State } else { - Real dist = Sqrt(dSqr); + Real dist = WWMath::Sqrt(dSqr); if (dist<1) dist = 1; pos.x += PATHFIND_CELL_SIZE_F*dx/(dist*LOGICFRAMES_PER_SECOND); pos.y += PATHFIND_CELL_SIZE_F*dy/(dist*LOGICFRAMES_PER_SECOND); @@ -2289,15 +2289,15 @@ void JetAIUpdate::positionLockon() Real dist = finalDist + (d->m_lockonInitialDist - finalDist) * frac; Real angle = d->m_lockonAngleSpin * frac; - pos.x += Cos(angle) * dist; - pos.y += Sin(angle) * dist; + pos.x += WWMath::Cos(angle) * dist; + pos.y += WWMath::Sin(angle) * dist; // pos.z is untouched m_lockonDrawable->setPosition(&pos); Real dx = getObject()->getPosition()->x - pos.x; Real dy = getObject()->getPosition()->y - pos.y; if (dx || dy) - m_lockonDrawable->setOrientation(Atan2(dy, dx)); + m_lockonDrawable->setOrientation(WWMath::Atan2(dy, dx)); // the Gaussian sum, to avoid keeping a running total: // diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp index df6660a077d..8e678b33ea1 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp @@ -232,7 +232,7 @@ void MissileAIUpdate::projectileFireAtObjectOrPosition( const Object *victim, co Real deltaZ = victimPos->z - obj->getPosition()->z; Real dx = victimPos->x - obj->getPosition()->x; Real dy = victimPos->y - obj->getPosition()->y; - Real xyDist = Sqrt(sqr(dx)+sqr(dy)); + Real xyDist = WWMath::Sqrt(sqr(dx)+sqr(dy)); if (xyDist<1) xyDist = 1; Real zFactor = 0; if (deltaZ>0) { @@ -611,7 +611,7 @@ void MissileAIUpdate::doKillState() closeEnough = curLoco->getMaxSpeedForCondition(BODY_PRISTINE); } Real distanceToTargetSq = ThePartitionManager->getDistanceSquared( getObject(), getGoalObject(), FROM_BOUNDINGSPHERE_3D); - //DEBUG_LOG(("Distance to target %f, closeEnough %f", Sqrt(distanceToTargetSq), closeEnough)); + //DEBUG_LOG(("Distance to target %f, closeEnough %f", WWMath::Sqrt(distanceToTargetSq), closeEnough)); if (distanceToTargetSq < closeEnough*closeEnough) { Coord3D pos = *getGoalObject()->getPosition(); getObject()->setPosition(&pos); @@ -649,7 +649,7 @@ UpdateSleepTime MissileAIUpdate::update() Coord3D newPos = *getObject()->getPosition(); if (m_noTurnDistLeft > 0.0f && m_state >= IGNITION) { - Real distThisTurn = Sqrt(sqr(newPos.x-m_prevPos.x) + sqr(newPos.y-m_prevPos.y) + sqr(newPos.z-m_prevPos.z)); + Real distThisTurn = WWMath::Sqrt(sqr(newPos.x-m_prevPos.x) + sqr(newPos.y-m_prevPos.y) + sqr(newPos.z-m_prevPos.z)); m_noTurnDistLeft -= distThisTurn; m_prevPos = newPos; } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp index 42b58c6da97..b8fbf64a258 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp @@ -320,7 +320,7 @@ void RailroadBehavior::onCollide( Object *other, const Coord3D *loc, const Coord m_whistleSound.setPlayingHandle(TheAudio->addAudioEvent( &m_whistleSound )); - Real dist = (Real)Sqrt( dlt.x*dlt.x + dlt.y*dlt.y + dlt.z*dlt.z); + Real dist = (Real)WWMath::Sqrt( dlt.x*dlt.x + dlt.y*dlt.y + dlt.z*dlt.z); Real usRadius = obj->getGeometryInfo().getMajorRadius(); Real themRadius = other->getGeometryInfo().getMajorRadius(); Real overlap = ((usRadius + themRadius) - dist) + 1;// the plus 1 makes them go just outside of me. @@ -1224,8 +1224,8 @@ void alignToTerrain( Real angle, const Coord3D& pos, const Coord3D& normal, Matr z = normal; - x.x = Cos( angle ); - x.y = Sin( angle ); + x.x = WWMath::Cos( angle ); + x.y = WWMath::Sin( angle ); x.z = 0.0f; if (z.z != 0.0f) { @@ -1299,7 +1299,7 @@ void RailroadBehavior::updatePositionTrackDistance( PullInfo *pullerInfo, PullIn trackPosDelta.z = 0; Real dx = pullerInfo->towHitchPosition.x - turnPos.x; Real dy = pullerInfo->towHitchPosition.y - turnPos.y; - Real desiredAngle = Atan2(dy, dx); + Real desiredAngle = WWMath::Atan2(dy, dx); Real relAngle = stdAngleDiff(desiredAngle, obj->getTransformMatrix()->Get_Z_Rotation()); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp index cf709af6c77..2a14009633a 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp @@ -172,7 +172,7 @@ UpdateSleepTime CleanupHazardUpdate::update() AIUpdateInterface *ai = obj->getAI(); if( ai && (ai->isIdle() || ai->isBusy()) ) { - Real fDist = Sqrt( ThePartitionManager->getDistanceSquared( obj, &m_pos, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( obj, &m_pos, FROM_CENTER_2D ) ); if( fDist < 25.0f ) { //Abort clean area because there's nothing left to clean! @@ -204,7 +204,7 @@ void CleanupHazardUpdate::fireWhenReady() bonus.clear(); Real fireRange = m_weaponTemplate->getAttackRange( bonus ); Object *me = getObject(); - Real fDist = Sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); if( fDist < fireRange ) { //We are currently in range! diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp index 6044c1c0647..8eac2411461 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp @@ -338,7 +338,7 @@ Object* CommandButtonHuntUpdate::scanClosestTarget() } } Real distSqr = ThePartitionManager->getDistanceSquared(me, other, FROM_BOUNDINGSPHERE_2D); - Real dist = Sqrt(distSqr); + Real dist = WWMath::Sqrt(distSqr); Int curPriority = data->m_scanRange - dist; if (info) curPriority = info->getPriority(other->getTemplate()); if (curPriority == 0) diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp index fa4079d02f9..272d2895255 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp @@ -95,7 +95,7 @@ Bool SupplyWarehouseDockUpdate::action( Object* docker, Object *drone ) Real closeEnoughSqr = sqr(docker->getGeometryInfo().getBoundingCircleRadius()*2); Real curDistSqr = ThePartitionManager->getDistanceSquared(docker, getObject(), FROM_BOUNDINGSPHERE_2D); if (curDistSqr > closeEnoughSqr) { - DEBUG_LOG(("Failing dock, dist %f, not close enough(%f).", Sqrt(curDistSqr), Sqrt(closeEnoughSqr))); + DEBUG_LOG(("Failing dock, dist %f, not close enough(%f).", WWMath::Sqrt(curDistSqr), WWMath::Sqrt(closeEnoughSqr))); // Make it twitch a little. Coord3D newPos = *docker->getPosition(); Real range = 0.4*PATHFIND_CELL_SIZE_F; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp index 4a9ddaf7921..2e1e69f7ae1 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp @@ -166,8 +166,8 @@ void DynamicShroudClearingRangeUpdate::animateGridDecals() for (int d = 0; d < GRID_FX_DECAL_COUNT; ++d) { - pos.x = ctr->x + (Sin(angle) * radius); - pos.y = ctr->y + (Cos(angle) * radius); + pos.x = ctr->x + (WWMath::Sin(angle) * radius); + pos.y = ctr->y + (WWMath::Cos(angle) * radius); pos.x -= ((Int)pos.x)%23; pos.y -= ((Int)pos.y)%23; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp index e09a9e86235..0fd8ed5c2c3 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp @@ -119,8 +119,8 @@ UpdateSleepTime FloatUpdate::update() { Real angle = INT_TO_REAL(TheGameLogic->getFrame()); - Real yaw = Sin(angle * 0.0291f) * 0.05f; - Real pitch = Sin(angle * 0.0515f) * 0.05f; + Real yaw = WWMath::Sin(angle * 0.0291f) * 0.05f; + Real pitch = WWMath::Sin(angle * 0.0515f) * 0.05f; Matrix3D mx = *draw->getInstanceMatrix(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp index e3a86fb24b4..9084db01141 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp @@ -359,8 +359,8 @@ UpdateSleepTime HelicopterSlowDeathBehavior::update() // is *NOT* the angle the object is facing // Coord3D force; - force.x = DOUBLE_TO_REAL( Cos( m_forwardAngle ) ) * m_forwardSpeed; - force.y = DOUBLE_TO_REAL( Sin( m_forwardAngle ) ) * m_forwardSpeed; + force.x = DOUBLE_TO_REAL( WWMath::Cos( m_forwardAngle ) ) * m_forwardSpeed; + force.y = DOUBLE_TO_REAL( WWMath::Sin( m_forwardAngle ) ) * m_forwardSpeed; force.z = 0.0f; physics->applyMotiveForce( &force ); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/MobMemberSlavedUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/MobMemberSlavedUpdate.cpp index c864b5e413f..02c741f8544 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/MobMemberSlavedUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/MobMemberSlavedUpdate.cpp @@ -358,8 +358,8 @@ void MobMemberSlavedUpdate::doCatchUpLogic( Coord3D *pos ) Real randomDirection = GameLogicRandomValue( 0, 2*PI ); Real randomRadius = GameLogicRandomValue( 0, data->m_noNeedToCatchUpRadius ); nuPos.set(pos); - nuPos.x += randomRadius * Cos( randomDirection ); - nuPos.y += randomRadius * Sin( randomDirection ); + nuPos.x += randomRadius * WWMath::Cos( randomDirection ); + nuPos.y += randomRadius * WWMath::Sin( randomDirection ); nuPos.z = TheTerrainLogic->getGroundHeight( nuPos.x, nuPos.y ); AIUpdateInterface *ai = getObject()->getAIUpdateInterface(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp index e19e571a361..54f75a9f838 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp @@ -294,7 +294,7 @@ static Real calcTransform(const Object* obj, const Coord3D *pos, Real maxTurnRat else if (c > 1.0) c = 1.0; - Real angle = (Real)ACos( c ); + Real angle = (Real)WWMath::Acos( c ); Vector3 newDir; if (fabs(angle) < maxTurnRate) @@ -418,7 +418,7 @@ void NeutronMissileUpdate::doAttack() pos.z += m_vel.z; //DEBUG_LOG(("vel %f accel %f z %f",m_vel.length(),m_accel.length(), pos.z)); -//Real vm = Sqrt(m_vel.x*m_vel.x+m_vel.y*m_vel.y+m_vel.z*m_vel.z); +//Real vm = WWMath::Sqrt(m_vel.x*m_vel.x+m_vel.y*m_vel.y+m_vel.z*m_vel.z); //DEBUG_LOG(("vel is %f %f %f (%f)",m_vel.x,m_vel.y,m_vel.z,vm)); getObject()->setTransformMatrix( &mx ); getObject()->setPosition( &pos ); @@ -512,7 +512,7 @@ UpdateSleepTime NeutronMissileUpdate::update() if (m_noTurnDistLeft > 0.0f && oldPosValid) { Coord3D newPos = *getObject()->getPosition(); - Real distThisTurn = Sqrt(sqr(newPos.x-oldPos.x) + sqr(newPos.y-oldPos.y) + sqr(newPos.z-oldPos.z)); + Real distThisTurn = WWMath::Sqrt(sqr(newPos.x-oldPos.x) + sqr(newPos.y-oldPos.y) + sqr(newPos.z-oldPos.z)); //DEBUG_LOG(("noTurnDist goes from %f to %f",m_noTurnDistLeft,m_noTurnDistLeft-distThisTurn)); m_noTurnDistLeft -= distThisTurn; } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp index 5f21db0f175..8e7f043494a 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp @@ -526,12 +526,12 @@ UpdateSleepTime ParticleUplinkCannonUpdate::update() //First determine the factor of time completed (ranges between 0.0 and 1.0) Real factor = (Real)(now - orbitalBirthFrame) / (Real)(orbitalDeathFrame - orbitalBirthFrame); - //We're generating a swath that travels the points between Sin( -1PI ) and Sin( 1PI ) + //We're generating a swath that travels the points between WWMath::Sin( -1PI ) and WWMath::Sin( 1PI ) Real radians = (factor * TWO_PI) - PI; Real cxDistance = (factor * data->m_swathOfDeathDistance ) - (data->m_swathOfDeathDistance * 0.5f); //cx is cartesian x //Now calculate the amplitude value. - Real height = Sin( radians ); + Real height = WWMath::Sin( radians ); Real cxHeight = height * data->m_swathOfDeathAmplitude; Coord3D buildingToInitialTargetVector; @@ -553,8 +553,8 @@ UpdateSleepTime ParticleUplinkCannonUpdate::update() cartesianTargetVector.Normalize(); Real dotProduct = Vector2::Dot_Product( buildingToTargetVector, cartesianTargetVector ); - dotProduct = __min( 0.99999f, __max( -0.99999f, dotProduct ) ); //Account for numerical errors. Also, ACos(-1.00000) is coming out QNAN on the superweapon general map. Heh. - Real angle = (Real)ACos( dotProduct ); + dotProduct = __min( 0.99999f, __max( -0.99999f, dotProduct ) ); //Account for numerical errors. Also, WWMath::Acos(-1.00000) is coming out QNAN on the superweapon general map. Heh. + Real angle = (Real)WWMath::Acos( dotProduct ); if( buildingToTargetVector.Y >= 0 ) { diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp index e5f7fbde981..f223ff1b776 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp @@ -93,7 +93,7 @@ static Real angleBetweenVectors(const Coord3D& inCurDir, const Coord3D& inGoalDi Real cosine = Vector3::Dot_Product(curDir, goalDir); // bound it in case of numerical error - Real angleBetween = (Real)ACos(clamp(-1.0f, cosine, 1.0f)); + Real angleBetween = (Real)WWMath::Acos(clamp(-1.0f, cosine, 1.0f)); return angleBetween; } @@ -102,7 +102,7 @@ static Real angleBetweenVectors(const Coord3D& inCurDir, const Coord3D& inGoalDi static Real heightToSpeed(Real height) { // don't bother trying to remember how far we've fallen; instead, - // back-calc it from our speed & gravity... v = Sqrt(2*g*h) + // back-calc it from our speed & gravity... v = WWMath::Sqrt(2*g*h) return WWMath::Sqrt(fabs(2.0f * TheGlobalData->m_gravity * height)); } @@ -144,7 +144,7 @@ PhysicsBehaviorModuleData::PhysicsBehaviorModuleData() static void parseHeightToSpeed( INI* ini, void * /*instance*/, void *store, const void* /*userData*/ ) { // don't bother trying to remember how far we've fallen; instead, - // back-calc it from our speed & gravity... v = Sqrt(2*g*h) + // back-calc it from our speed & gravity... v = WWMath::Sqrt(2*g*h) Real height = INI::scanReal(ini->getNextToken()); *(Real *)store = heightToSpeed(height); } @@ -850,7 +850,7 @@ UpdateSleepTime PhysicsBehavior::update() // // don't bother trying to remember how far we've fallen; instead, - // we back-calc it from our speed & gravity... v = Sqrt(2*g*h). + // we back-calc it from our speed & gravity... v = WWMath::Sqrt(2*g*h). // (note that m_minFallSpeedForDamage is always POSITIVE.) // // also note: since projectiles are immune to falling damage, don't @@ -944,7 +944,7 @@ Real PhysicsBehavior::getVelocityMagnitude() const { if (m_velMag == INVALID_VEL_MAG) { - m_velMag = (Real)Sqrt( sqr(m_vel.x) + sqr(m_vel.y) + sqr(m_vel.z) ); + m_velMag = (Real)WWMath::Sqrt( sqr(m_vel.x) + sqr(m_vel.y) + sqr(m_vel.z) ); } return m_velMag; } @@ -964,9 +964,9 @@ Real PhysicsBehavior::getForwardSpeed2D() const Real dot = vx + vy; Real speedSquared = vx*vx + vy*vy; -// DEBUG_ASSERTCRASH( speedSquared != 0, ("zero speedSquared will overflow Sqrt()!") );// lorenzen... sanity check +// DEBUG_ASSERTCRASH( speedSquared != 0, ("zero speedSquared will overflow WWMath::Sqrt()!") );// lorenzen... sanity check - Real speed = (Real)Sqrt( speedSquared ); + Real speed = (Real)WWMath::Sqrt( speedSquared ); if (dot >= 0.0f) return speed; @@ -989,7 +989,7 @@ Real PhysicsBehavior::getForwardSpeed3D() const Real dot = vx + vy + vz; - Real speed = (Real)Sqrt( vx*vx + vy*vy + vz*vz ); + Real speed = (Real)WWMath::Sqrt( vx*vx + vy*vy + vz*vz ); if (dot >= 0.0f) return speed; @@ -1036,7 +1036,7 @@ void PhysicsBehavior::scrubVelocity2D( Real desiredVelocity ) } else { - Real curVelocity = Sqrt(m_vel.x*m_vel.x + m_vel.y*m_vel.y); + Real curVelocity = WWMath::Sqrt(m_vel.x*m_vel.x + m_vel.y*m_vel.y); if (desiredVelocity > curVelocity) { return; @@ -1321,7 +1321,7 @@ void PhysicsBehavior::onCollide( Object *other, const Coord3D *loc, const Coord3 m_lastCollidee = other->getID(); - Real dist = Sqrt(distSqr); + Real dist = WWMath::Sqrt(distSqr); Real overlap = usRadius + themRadius - dist; // if objects are coincident, dist is zero, so force would be infinite -- clearly diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp index 20ec42299bc..86fd7667c6e 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp @@ -167,7 +167,7 @@ void PointDefenseLaserUpdate::fireWhenReady() bonus.clear(); Real fireRange = data->m_weaponTemplate->getAttackRange( bonus ); Object *me = getObject(); - Real fDist = Sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); if( fDist < fireRange ) { //We are currently in range! @@ -290,7 +290,7 @@ Object* PointDefenseLaserUpdate::scanClosestTarget() continue; } - Real fDist = Sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); if( fDist <= fireRange ) { @@ -317,7 +317,7 @@ Object* PointDefenseLaserUpdate::scanClosestTarget() pos.add( other->getPosition() ); //Recalculate the distance. - fDist = Sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); + fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); } } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp index 27303efcc5b..36c88c456d1 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp @@ -319,8 +319,8 @@ void SlavedUpdate::doAttackLogic( const Object *target ) //Allow me to wander away from the pinnedPosition. Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.zero(); - m_guardPointOffset.x += data->m_attackWanderRange * Cos( randomDirection ); - m_guardPointOffset.y += data->m_attackWanderRange * Sin( randomDirection ); + m_guardPointOffset.x += data->m_attackWanderRange * WWMath::Cos( randomDirection ); + m_guardPointOffset.y += data->m_attackWanderRange * WWMath::Sin( randomDirection ); //Offset our pinned position by our random offset. attackPosition.x += m_guardPointOffset.x; @@ -382,8 +382,8 @@ void SlavedUpdate::doScoutLogic( const Coord3D *mastersDestination ) //Allow me to wander away from the pinnedPosition. Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.zero(); - m_guardPointOffset.x += data->m_scoutWanderRange * Cos( randomDirection ); - m_guardPointOffset.y += data->m_scoutWanderRange * Sin( randomDirection ); + m_guardPointOffset.x += data->m_scoutWanderRange * WWMath::Cos( randomDirection ); + m_guardPointOffset.y += data->m_scoutWanderRange * WWMath::Sin( randomDirection ); //Offset our pinned position by our random offset. scoutPosition.x += m_guardPointOffset.x; @@ -412,8 +412,8 @@ void SlavedUpdate::doGuardLogic( Coord3D *pinnedPosition ) // recalc where we want to be if we wander around Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.zero(); - m_guardPointOffset.x += data->m_guardMaxRange * Cos( randomDirection ); - m_guardPointOffset.y += data->m_guardMaxRange * Sin( randomDirection ); + m_guardPointOffset.x += data->m_guardMaxRange * WWMath::Cos( randomDirection ); + m_guardPointOffset.y += data->m_guardMaxRange * WWMath::Sin( randomDirection ); pinnedPosition->x += m_guardPointOffset.x; pinnedPosition->y += m_guardPointOffset.y; @@ -679,8 +679,8 @@ void SlavedUpdate::moveToNewRepairSpot() //Allow me to wander away from the pinnedPosition. Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.set( master->getPosition() ); - m_guardPointOffset.x += data->m_repairRange * Cos( randomDirection ); - m_guardPointOffset.y += data->m_repairRange * Sin( randomDirection ); + m_guardPointOffset.x += data->m_repairRange * WWMath::Cos( randomDirection ); + m_guardPointOffset.y += data->m_repairRange * WWMath::Sin( randomDirection ); m_guardPointOffset.z = TheTerrainLogic->getGroundHeight( m_guardPointOffset.x, m_guardPointOffset.y ); Real altitude = GameLogicRandomValueReal( data->m_repairMinAltitude, data->m_repairMaxAltitude ); m_guardPointOffset.z += altitude; @@ -713,8 +713,8 @@ void SlavedUpdate::startSlavedEffects( const Object *slaver ) // Decide where our pinned stray point is Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.zero(); - m_guardPointOffset.x += data->m_guardMaxRange * Cos( randomDirection ); - m_guardPointOffset.y += data->m_guardMaxRange * Sin( randomDirection ); + m_guardPointOffset.x += data->m_guardMaxRange * WWMath::Cos( randomDirection ); + m_guardPointOffset.y += data->m_guardMaxRange * WWMath::Sin( randomDirection ); // mark selves as not selectable getObject()->setStatus( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_UNSELECTABLE ) ); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipDeploymentUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipDeploymentUpdate.cpp index f1ef5f255ed..e1cadfceef6 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipDeploymentUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipDeploymentUpdate.cpp @@ -218,7 +218,7 @@ Bool SpectreGunshipDeploymentUpdate::initiateIntentToDoSpecialPower(const Specia newGunship->setPosition( &creationCoord ); //ORIENTATION - Real orient = Atan2( m_initialTargetPosition.y - creationCoord.y, m_initialTargetPosition.x - creationCoord.x); + Real orient = WWMath::Atan2( m_initialTargetPosition.y - creationCoord.y, m_initialTargetPosition.x - creationCoord.x); newGunship->setOrientation( orient ); // ID diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp index 4a2f3625093..aced9091a9b 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp @@ -684,7 +684,7 @@ UpdateSleepTime StealthUpdate::update() } else { - draw->setEffectiveOpacity( 0.5f + ( Sin( m_pulsePhase ) * 0.5f ) ); + draw->setEffectiveOpacity( 0.5f + ( WWMath::Sin( m_pulsePhase ) * 0.5f ) ); // between one half and full opacity m_pulsePhase += m_pulsePhaseRate; } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StructureToppleUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StructureToppleUpdate.cpp index 600a6f0ccf4..e652c23e51b 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StructureToppleUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StructureToppleUpdate.cpp @@ -158,15 +158,15 @@ void StructureToppleUpdate::beginStructureTopple(const DamageInfo *damageInfo) toppleAngle = m_toppleDirection.toAngle(); toppleAngle += GameLogicRandomValueReal(-PI/8, PI/8); } - m_toppleDirection.x = Cos(toppleAngle); - m_toppleDirection.y = Sin(toppleAngle); + m_toppleDirection.x = WWMath::Cos(toppleAngle); + m_toppleDirection.y = WWMath::Sin(toppleAngle); TheScriptEngine->adjustToppleDirection(getObject(), &m_toppleDirection); Real averageRadius = (building->getGeometryInfo().getMajorRadius() + building->getGeometryInfo().getMinorRadius()) / 2; Real explosionRadius = averageRadius * 0.90; - m_delayBurstLocation.x = building->getPosition()->x + explosionRadius * Cos(toppleAngle); - m_delayBurstLocation.y = building->getPosition()->y + explosionRadius * Sin(toppleAngle); + m_delayBurstLocation.x = building->getPosition()->x + explosionRadius * WWMath::Cos(toppleAngle); + m_delayBurstLocation.y = building->getPosition()->y + explosionRadius * WWMath::Sin(toppleAngle); m_delayBurstLocation.z = TheTerrainLogic->getGroundHeight(m_delayBurstLocation.x, m_delayBurstLocation.y); doToppleStartFX(building, damageInfo); @@ -231,7 +231,7 @@ UpdateSleepTime StructureToppleUpdate::update() // The building is in the process of falling over. if (m_toppleState == TOPPLESTATE_TOPPLING) { UnsignedInt now = TheGameLogic->getFrame(); - Real toppleAcceleration = TOPPLE_ACCELERATION_FACTOR * (Sin(m_accumulatedAngle) * (1.0 - m_structuralIntegrity)); + Real toppleAcceleration = TOPPLE_ACCELERATION_FACTOR * (WWMath::Sin(m_accumulatedAngle) * (1.0 - m_structuralIntegrity)); // DEBUG_LOG(("toppleAcceleration = %f", toppleAcceleration)); m_toppleVelocity += toppleAcceleration; // DEBUG_LOG(("m_toppleVelocity = %f", m_toppleVelocity)); @@ -368,8 +368,8 @@ void StructureToppleUpdate::applyCrushingDamage(Real theta) // Do this because the amount of ground that is affected will be different if the building falls // in different orientations. Real angle = orientationAngle - toppleAngle; - Real minorComponent = building->getGeometryInfo().getMinorRadius() * Cos(angle); - Real majorComponent = building->getGeometryInfo().getMajorRadius() * Sin(angle); + Real minorComponent = building->getGeometryInfo().getMinorRadius() * WWMath::Cos(angle); + Real majorComponent = building->getGeometryInfo().getMajorRadius() * WWMath::Sin(angle); Coord3D temp3D; temp3D.x = majorComponent; @@ -385,7 +385,7 @@ void StructureToppleUpdate::applyCrushingDamage(Real theta) } // The furthest away from the base of the building to explode on. - Real maxDistance = m_buildingHeight * (1.0 - Sin(theta)); + Real maxDistance = m_buildingHeight * (1.0 - WWMath::Sin(theta)); /* * Fire explosions at regular intervals across the area that the building is currently @@ -396,14 +396,14 @@ void StructureToppleUpdate::applyCrushingDamage(Real theta) // Coord3D target; Real j = m_lastCrushedLocation; for (; j < maxDistance; j += WEAPON_SPACING_PERPENDICULAR) { - jcos = j * Cos(toppleAngle); - jsin = j * Sin(toppleAngle); + jcos = j * WWMath::Cos(toppleAngle); + jsin = j * WWMath::Sin(toppleAngle); doDamageLine(building, wt, jcos, jsin, facingWidth, toppleAngle); } - jcos = maxDistance * Cos(toppleAngle); - jsin = maxDistance * Sin(toppleAngle); + jcos = maxDistance * WWMath::Cos(toppleAngle); + jsin = maxDistance * WWMath::Sin(toppleAngle); doDamageLine(building, wt, jcos, jsin, facingWidth, toppleAngle); m_lastCrushedLocation = j; @@ -424,8 +424,8 @@ void StructureToppleUpdate::doDamageLine(Object *building, const WeaponTemplate* for (Real i = -facingWidth; i < facingWidth; i += WEAPON_SPACING_PARALLEL) { - target.x = building->getPosition()->x + jcos + (i * Sin(toppleAngle)); - target.y = building->getPosition()->y + jsin + (i * Cos(toppleAngle)); + target.x = building->getPosition()->x + jcos + (i * WWMath::Sin(toppleAngle)); + target.y = building->getPosition()->y + jsin + (i * WWMath::Cos(toppleAngle)); target.z = TheTerrainLogic->getGroundHeight(target.x, target.y); TheWeaponStore->createAndFireTempWeapon(wt, building, &target); @@ -436,8 +436,8 @@ void StructureToppleUpdate::doDamageLine(Object *building, const WeaponTemplate* } // Make sure there are weapons fired and FX done on the edge of the building. - target.x = building->getPosition()->x + jcos + (facingWidth * Sin(toppleAngle)); - target.y = building->getPosition()->y + jsin + (facingWidth * Cos(toppleAngle)); + target.x = building->getPosition()->x + jcos + (facingWidth * WWMath::Sin(toppleAngle)); + target.y = building->getPosition()->y + jsin + (facingWidth * WWMath::Cos(toppleAngle)); target.z = TheTerrainLogic->getGroundHeight(target.x, target.y); TheWeaponStore->createAndFireTempWeapon(wt, building, &target); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp index 55fbde61a55..5f3e03b8379 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp @@ -185,13 +185,13 @@ void ToppleUpdate::applyTopplingForce( const Coord3D* toppleDirection, Real topp // yeah, it assumes the models are constructed appropriately, but is a cheap way // of minimizing the problem. (srj) Real curAngleX = normalizeAngle(getObject()->getOrientation()); - Real toppleAngle = normalizeAngle(Atan2(m_toppleDirection.y, m_toppleDirection.x)); + Real toppleAngle = normalizeAngle(WWMath::Atan2(m_toppleDirection.y, m_toppleDirection.x)); if (d->m_toppleLeftOrRightOnly) { // it's a fence or such, and can only topple left or right, so pick the closest toppleAngle = angleClosestTo(curAngleX + PI/2, curAngleX - PI/2, toppleAngle); - m_toppleDirection.x = Cos(toppleAngle); - m_toppleDirection.y = Sin(toppleAngle); + m_toppleDirection.x = WWMath::Cos(toppleAngle); + m_toppleDirection.y = WWMath::Sin(toppleAngle); // go ahead and remove it from the pathfinder now, rather than waiting for the topple to // finish.... since we might be in a slightly different position when toppled, which can diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/WaveGuideUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/WaveGuideUpdate.cpp index 9350b0914cb..8f45ef4c975 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/WaveGuideUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/WaveGuideUpdate.cpp @@ -718,8 +718,8 @@ void WaveGuideUpdate::doDamage() // angle is rotated, because we computed from 'from' and 'to' points of // the bridge going *across* the valley, not pointing *down* it // - u.x = Cos( angle + modData->m_bridgeParticleAngleFudge ); - u.y = Sin( angle + modData->m_bridgeParticleAngleFudge ); + u.x = WWMath::Cos( angle + modData->m_bridgeParticleAngleFudge ); + u.y = WWMath::Sin( angle + modData->m_bridgeParticleAngleFudge ); u.z = 0.0f; y.crossProduct( &z, &u, &y ); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp index 445f9981438..147b24bfbf8 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp @@ -860,7 +860,7 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate Real attackRangeSqr = sqr(getAttackRange(bonus)); if (distSqr > attackRangeSqr) { - //DEBUG_ASSERTCRASH(distSqr < 5*5 || distSqr < attackRangeSqr*1.2f, ("*** victim is out of range (%f vs %f) of this weapon -- why did we attempt to fire?",Sqrt(distSqr),Sqrt(attackRangeSqr))); + //DEBUG_ASSERTCRASH(distSqr < 5*5 || distSqr < attackRangeSqr*1.2f, ("*** victim is out of range (%f vs %f) of this weapon -- why did we attempt to fire?",WWMath::Sqrt(distSqr),WWMath::Sqrt(attackRangeSqr))); //-extraLogging #if defined(RTS_DEBUG) @@ -882,7 +882,7 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate if (distSqr < minAttackRangeSqr-0.5f && !isProjectileDetonation) #endif { - DEBUG_ASSERTCRASH(distSqr > minAttackRangeSqr*0.8f, ("*** victim is closer than min attack range (%f vs %f) of this weapon -- why did we attempt to fire?",Sqrt(distSqr),Sqrt(minAttackRangeSqr))); + DEBUG_ASSERTCRASH(distSqr > minAttackRangeSqr*0.8f, ("*** victim is closer than min attack range (%f vs %f) of this weapon -- why did we attempt to fire?",WWMath::Sqrt(distSqr),WWMath::Sqrt(minAttackRangeSqr))); //-extraLogging #if defined(RTS_DEBUG) @@ -2134,8 +2134,8 @@ Bool Weapon::computeApproachTarget(const Object *source, const Object *target, c if (angleOffset != 0.0f) { Real angle = WWMath::Atan2(dir.y, dir.x); - dir.x = (Real)Cos(angle + angleOffset); - dir.y = (Real)Sin(angle + angleOffset); + dir.x = (Real)WWMath::Cos(angle + angleOffset); + dir.y = (Real)WWMath::Sin(angle + angleOffset); } // select a spot along the line between us, halfway between the min & max range. @@ -2181,8 +2181,8 @@ Bool Weapon::computeApproachTarget(const Object *source, const Object *target, c if (angleOffset != 0.0f) { Real angle = WWMath::Atan2(dir.y, dir.x); - dir.x = (Real)Cos(angle + angleOffset); - dir.y = (Real)Sin(angle + angleOffset); + dir.x = (Real)WWMath::Cos(angle + angleOffset); + dir.y = (Real)WWMath::Sin(angle + angleOffset); } // select a spot along the line between us, in range of our weapon diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp index 7c9c612245c..d6665912808 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp @@ -5299,8 +5299,8 @@ void ScriptEngine::reset() } m_breezeInfo.m_direction = PI/3; - m_breezeInfo.m_directionVec.x = Sin(m_breezeInfo.m_direction); - m_breezeInfo.m_directionVec.y = Cos(m_breezeInfo.m_direction); + m_breezeInfo.m_directionVec.x = WWMath::Sin(m_breezeInfo.m_direction); + m_breezeInfo.m_directionVec.y = WWMath::Cos(m_breezeInfo.m_direction); m_breezeInfo.m_intensity = 0.07f*PI/4; m_breezeInfo.m_lean = 0.07f*PI/4; m_breezeInfo.m_breezePeriod = LOGICFRAMES_PER_SECOND * 5; @@ -6408,8 +6408,8 @@ void ScriptEngine::setSway( ScriptAction *pAction ) DEBUG_ASSERTCRASH(pAction->getNumParameters() >= 5, ("Not enough parameters.")); ++m_breezeInfo.m_breezeVersion; m_breezeInfo.m_direction = pAction->getParameter(0)->getReal(); - m_breezeInfo.m_directionVec.x = Sin(m_breezeInfo.m_direction); - m_breezeInfo.m_directionVec.y = Cos(m_breezeInfo.m_direction); + m_breezeInfo.m_directionVec.x = WWMath::Sin(m_breezeInfo.m_direction); + m_breezeInfo.m_directionVec.y = WWMath::Cos(m_breezeInfo.m_direction); m_breezeInfo.m_intensity = pAction->getParameter(1)->getReal(); m_breezeInfo.m_lean = pAction->getParameter(2)->getReal(); m_breezeInfo.m_breezePeriod = pAction->getParameter(3)->getInt(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp index c565e91b7e9..790f8ed6ef1 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp @@ -845,7 +845,7 @@ static void populateRandomStartPosition( GameInfo *game ) { Coord3D p1 = c1->second; Coord3D p2 = c2->second; - startSpotDistance[i][j] = Sqrt( sqr(p1.x-p2.x) + sqr(p1.y-p2.y) ); + startSpotDistance[i][j] = WWMath::Sqrt( sqr(p1.x-p2.x) + sqr(p1.y-p2.y) ); } } else diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp index b1b792b3ac9..975999d99ea 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp @@ -348,8 +348,8 @@ void W3DParticleSystemManager::doParticles(RenderInfoClass &rinfo) Coord3D worldStart, worldEnd; ICoord2D pixelStart, pixelEnd; sys->getPosition( &worldStart ); - worldEnd.x = Cos( sys->getWindAngle() ) * 50.0f + worldStart.x; - worldEnd.y = Sin( sys->getWindAngle() ) * 50.0f + worldStart.y; + worldEnd.x = WWMath::Cos( sys->getWindAngle() ) * 50.0f + worldStart.x; + worldEnd.y = WWMath::Sin( sys->getWindAngle() ) * 50.0f + worldStart.y; worldEnd.z = worldStart.z; TheTacticalView->worldToScreen( &worldStart, &pixelStart ); TheTacticalView->worldToScreen( &worldEnd, &pixelEnd ); From b71bc5981e0ebb1b10e4ea318e9e5f9504f2cc46 Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Sat, 18 Apr 2026 21:44:41 +0300 Subject: [PATCH 09/13] fix(build): Exclude GameMath from VC6 and fix ACos typo in BaseType.h - Guard gamemath.cmake and link with NOT IS_VS6_BUILD (VC6 lacks long long, stdint.h) - Guard gmath.h include in wwmath.h with _MSC_VER >= 1300 check - Fix ACos -> Acos case mismatch in BaseType.h (3 call sites) --- CMakeLists.txt | 4 +++- Core/Libraries/Include/Lib/BaseType.h | 4 ++-- Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt | 5 ++++- Core/Libraries/Source/WWVegas/WWMath/wwmath.h | 5 ++++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a46f6c2254c..0e0c5afaeb2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,7 +64,9 @@ endif() include(cmake/config.cmake) include(cmake/gamespy.cmake) -include(cmake/gamemath.cmake) +if (NOT IS_VS6_BUILD) + include(cmake/gamemath.cmake) +endif() include(cmake/lzhl.cmake) if (IS_VS6_BUILD) diff --git a/Core/Libraries/Include/Lib/BaseType.h b/Core/Libraries/Include/Lib/BaseType.h index 64d30dd71ed..3bc04015f36 100644 --- a/Core/Libraries/Include/Lib/BaseType.h +++ b/Core/Libraries/Include/Lib/BaseType.h @@ -270,7 +270,7 @@ inline Real Coord2D::toAngle() const else if (c > 1.0) c = 1.0; - Real value = (Real)WWMath::ACos( (Real)c ); + Real value = (Real)WWMath::Acos( (Real)c ); // Determine sign by checking Z component of dir cross vector // Note this is assumes 2D, and is identical to dotting the perpendicular of v with dir @@ -295,7 +295,7 @@ inline Real Coord2D::toAngle() const else if (c > 1.0f) c = 1.0f; - return y < 0.0f ? -WWMath::ACos(c) : WWMath::ACos(c); + return y < 0.0f ? -WWMath::Acos(c) : WWMath::Acos(c); #endif } diff --git a/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt b/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt index 0c7417f355e..1b57718d6f0 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt +++ b/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt @@ -89,8 +89,11 @@ target_link_libraries(core_wwmath PRIVATE core_wwcommon corei_always core_wwsaveload - gamemath ) +if (NOT IS_VS6_BUILD) + target_link_libraries(core_wwmath PRIVATE gamemath) +endif() + # @todo Test its impact and see what to do with the legacy functions. #add_compile_definitions(core_wwmath PUBLIC ALLOW_TEMPORARIES) # Enables legacy math with "temporaries" diff --git a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h index d1da331e4c9..68b1ad91064 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h +++ b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h @@ -39,11 +39,14 @@ #include "always.h" #include #include -#include "gmath.h" #include +// TheSuperHackers @fix VC6 does not support long long or required by GameMath (gmath.h). +#if !(defined(_MSC_VER) && _MSC_VER < 1300) +#include "gmath.h" #ifdef RETAIL_COMPATIBLE_CRC #define USE_DETERMINISTIC_MATH +#endif #endif /* From 144464150f473def81300742fb8e1ae4c2391c3d Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Sun, 19 Apr 2026 00:07:53 +0300 Subject: [PATCH 10/13] fix(build): Cast NUM_TAB_PANES to Int in min/max to resolve template ambiguity --- .../GUIEdit/Source/Dialog Procedures/TabControlProperties.cpp | 4 ++-- .../GUIEdit/Source/Dialog Procedures/TabControlProperties.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Generals/Code/Tools/GUIEdit/Source/Dialog Procedures/TabControlProperties.cpp b/Generals/Code/Tools/GUIEdit/Source/Dialog Procedures/TabControlProperties.cpp index 10790580990..a47b6ddaabe 100644 --- a/Generals/Code/Tools/GUIEdit/Source/Dialog Procedures/TabControlProperties.cpp +++ b/Generals/Code/Tools/GUIEdit/Source/Dialog Procedures/TabControlProperties.cpp @@ -334,8 +334,8 @@ static LRESULT CALLBACK tabControlPropertiesCallback( HWND hWndDialog, tabData->tabEdge = TP_BOTTOM_SIDE; //safeties - tabData->tabCount = max( tabData->tabCount, 1 ); - tabData->tabCount = min( tabData->tabCount, NUM_TAB_PANES ); + tabData->tabCount = max( tabData->tabCount, (Int)1 ); + tabData->tabCount = min( tabData->tabCount, (Int)NUM_TAB_PANES ); GadgetTabControlComputeTabRegion( tabControl ); GadgetTabControlResizeSubPanes( tabControl ); diff --git a/GeneralsMD/Code/Tools/GUIEdit/Source/Dialog Procedures/TabControlProperties.cpp b/GeneralsMD/Code/Tools/GUIEdit/Source/Dialog Procedures/TabControlProperties.cpp index 97fe8fd9887..e7ffae8d5fe 100644 --- a/GeneralsMD/Code/Tools/GUIEdit/Source/Dialog Procedures/TabControlProperties.cpp +++ b/GeneralsMD/Code/Tools/GUIEdit/Source/Dialog Procedures/TabControlProperties.cpp @@ -334,8 +334,8 @@ static LRESULT CALLBACK tabControlPropertiesCallback( HWND hWndDialog, tabData->tabEdge = TP_BOTTOM_SIDE; //safeties - tabData->tabCount = max( tabData->tabCount, 1 ); - tabData->tabCount = min( tabData->tabCount, NUM_TAB_PANES ); + tabData->tabCount = max( tabData->tabCount, (Int)1 ); + tabData->tabCount = min( tabData->tabCount, (Int)NUM_TAB_PANES ); GadgetTabControlComputeTabRegion( tabControl ); GadgetTabControlResizeSubPanes( tabControl ); From 5e3d59926bb25698770379e10e528980e782b4da Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Sun, 19 Apr 2026 01:26:17 +0300 Subject: [PATCH 11/13] fix(build): Decouple WWMath from WWVegas to fix isolated tools CI Extracted wwmath.h from tight coupling with the 3D engine's always.h macro definitions to establish WWMath as an independent Level 1 base library interface. Exposes Libraries/Source/WWVegas/WWMath and gamemath directly to corei_libraries_include targets, ensuring low-level utilities like Babylon and versionUpdate can compile BaseType.h without transitive rendering dependencies. --- Core/CMakeLists.txt | 5 +- Core/GameEngine/Include/GameClient/View.h | 2 +- .../Common/Diagnostic/SimulationMathCrc.cpp | 2 +- Core/Libraries/Include/Lib/BaseType.h | 2 +- .../Source/WWVegas/WWMath/CMakeLists.txt | 2 +- .../Source/WWVegas/WWMath/wwmath.cpp | 1 + Core/Libraries/Source/WWVegas/WWMath/wwmath.h | 414 +++++++++--------- .../W3DDevice/GameClient/W3DDisplay.cpp | 2 +- .../Source/Common/System/BuildAssistant.cpp | 2 +- .../Source/Common/System/Geometry.cpp | 2 +- .../Source/GameLogic/AI/AIGroup.cpp | 2 +- .../Source/GameLogic/AI/AISkirmishPlayer.cpp | 2 +- .../Source/GameLogic/AI/AIStates.cpp | 2 +- .../Source/GameLogic/Object/Locomotor.cpp | 2 +- .../GameLogic/Object/PartitionManager.cpp | 2 +- .../GameLogic/Object/Update/PhysicsUpdate.cpp | 2 +- .../Source/GameLogic/Object/Weapon.cpp | 2 +- .../W3DDevice/GameClient/W3DDisplay.cpp | 2 +- cmake/gamemath.cmake | 3 +- 19 files changed, 240 insertions(+), 213 deletions(-) diff --git a/Core/CMakeLists.txt b/Core/CMakeLists.txt index 1bb054f5f09..5926f8fb084 100644 --- a/Core/CMakeLists.txt +++ b/Core/CMakeLists.txt @@ -8,7 +8,10 @@ add_library(corei_always INTERFACE) add_library(corei_always_no_pch INTERFACE) # Use this for Shared Libs with MFC AFX target_include_directories(corei_gameengine_include INTERFACE "GameEngine/Include") -target_include_directories(corei_libraries_include INTERFACE "Libraries/Include") +target_include_directories(corei_libraries_include INTERFACE "Libraries/Include" "Libraries/Source/WWVegas/WWMath") +if (NOT IS_VS6_BUILD) + target_link_libraries(corei_libraries_include INTERFACE gamemath) +endif() target_include_directories(corei_libraries_source_wwvegas INTERFACE "Libraries/Source/WWVegas") target_include_directories(corei_libraries_source_wwvegas_wwlib INTERFACE "Libraries/Source/WWVegas/WWLib") target_include_directories(corei_main INTERFACE "Main") diff --git a/Core/GameEngine/Include/GameClient/View.h b/Core/GameEngine/Include/GameClient/View.h index 7180b907f25..09f357b9d46 100644 --- a/Core/GameEngine/Include/GameClient/View.h +++ b/Core/GameEngine/Include/GameClient/View.h @@ -34,7 +34,7 @@ #include "Common/Snapshot.h" #include "Lib/BaseType.h" #include "WW3D2/coltype.h" ///< we don't generally do this, but we need the W3D collision types -#include "WWMath/wwmath.h" +#include "wwmath.h" #define DEFAULT_VIEW_WIDTH 640 #define DEFAULT_VIEW_HEIGHT 480 diff --git a/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp b/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp index 1b062f44e34..8f1e62917a3 100644 --- a/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp +++ b/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp @@ -21,7 +21,7 @@ #include "Common/Diagnostic/SimulationMathCrc.h" #include "Common/XferCRC.h" #include "WWMath/matrix3d.h" -#include "WWMath/wwmath.h" +#include "wwmath.h" #include "GameLogic/FPUControl.h" #include diff --git a/Core/Libraries/Include/Lib/BaseType.h b/Core/Libraries/Include/Lib/BaseType.h index 2638e29e383..3bc04015f36 100644 --- a/Core/Libraries/Include/Lib/BaseType.h +++ b/Core/Libraries/Include/Lib/BaseType.h @@ -30,7 +30,7 @@ #pragma once #include "Lib/BaseTypeCore.h" -#include "WWMath/wwmath.h" +#include "wwmath.h" //----------------------------------------------------------------------------- typedef wchar_t WideChar; ///< multi-byte character representations diff --git a/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt b/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt index 1b57718d6f0..f388a7ea0e4 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt +++ b/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt @@ -92,7 +92,7 @@ target_link_libraries(core_wwmath PRIVATE ) if (NOT IS_VS6_BUILD) - target_link_libraries(core_wwmath PRIVATE gamemath) + target_link_libraries(core_wwmath PUBLIC gamemath) endif() # @todo Test its impact and see what to do with the legacy functions. diff --git a/Core/Libraries/Source/WWVegas/WWMath/wwmath.cpp b/Core/Libraries/Source/WWVegas/WWMath/wwmath.cpp index ab5c0f91276..9bbf8a076b8 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/wwmath.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/wwmath.cpp @@ -35,6 +35,7 @@ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ +#include "always.h" #include "wwmath.h" #include "wwhack.h" #include "lookuptable.h" diff --git a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h index 68b1ad91064..109632f504c 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h +++ b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h @@ -36,7 +36,12 @@ #pragma once -#include "always.h" +#if defined(_MSC_VER) +#define WWINLINE __forceinline +#else +#define WWINLINE inline +#endif + #include #include #include @@ -49,9 +54,9 @@ #endif #endif - /* - ** Some global constants. - */ +/* +** Some global constants. +*/ #define WWMATH_EPSILON 0.0001f #define WWMATH_EPSILON2 WWMATH_EPSILON * WWMATH_EPSILON #define WWMATH_PI 3.141592654f @@ -63,9 +68,9 @@ #define WWMATH_OOSQRT2 0.707106781f #define WWMATH_OOSQRT3 0.577350269f - /* - ** Macros to convert between degrees and radians - */ +/* +** Macros to convert between degrees and radians +*/ #ifndef RAD_TO_DEG #define RAD_TO_DEG(x) (((double)x)*180.0/WWMATH_PI) #endif @@ -83,8 +88,8 @@ #endif -const int ARC_TABLE_SIZE = 1024; -const int SIN_TABLE_SIZE = 1024; +const int ARC_TABLE_SIZE=1024; +const int SIN_TABLE_SIZE=1024; extern float _FastAcosTable[ARC_TABLE_SIZE]; extern float _FastAsinTable[ARC_TABLE_SIZE]; extern float _FastSinTable[SIN_TABLE_SIZE]; @@ -99,38 +104,46 @@ class WWMath { public: - // Initialization and Shutdown. Other math sub-systems which require initialization and - // shutdown processing will be handled in these functions - static void Init(); - static void Shutdown(); - - // These are meant to be a collection of small math utility functions to be optimized at some point. - static WWINLINE float Fabs(float val) - { - int value = *(int*)&val; - value &= 0x7fffffff; - return *(float*)&value; - } +// Initialization and Shutdown. Other math sub-systems which require initialization and +// shutdown processing will be handled in these functions +static void Init(); +static void Shutdown(); - static WWINLINE int Float_To_Int_Chop(const float& f); - static WWINLINE int Float_To_Int_Floor(const float& f); +// These are meant to be a collection of small math utility functions to be optimized at some point. +static WWINLINE float Fabs(float val) +{ + int value=*(int*)&val; + value&=0x7fffffff; + return *(float*)&value; +} - static WWINLINE float Cos(float val); - static WWINLINE float Sin(float val); - static WWINLINE float Sqrt(float val); - static WWINLINE float Inv_Sqrt(float a); - static WWINLINE long Float_To_Long(float f); +static WWINLINE int Float_To_Int_Chop(const float& f); +static WWINLINE int Float_To_Int_Floor(const float& f); + +#if defined(_MSC_VER) && defined(_M_IX86) +static WWINLINE float Cos(float val); +static WWINLINE float Sin(float val); +static WWINLINE float Sqrt(float val); +static WWINLINE float Inv_Sqrt(float a); // Some 30% faster inverse square root than regular C++ compiled, from Intel's math library +static WWINLINE long Float_To_Long(float f); +#else +static WWINLINE float Cos(float val); +static WWINLINE float Sin(float val); +static WWINLINE float Sqrt(float val); +static WWINLINE float Inv_Sqrt(float a); +static WWINLINE long Float_To_Long(float f); +#endif - static WWINLINE float Fast_Sin(float val); - static WWINLINE float Fast_Inv_Sin(float val); - static WWINLINE float Fast_Cos(float val); - static WWINLINE float Fast_Inv_Cos(float val); +static WWINLINE float Fast_Sin(float val); +static WWINLINE float Fast_Inv_Sin(float val); +static WWINLINE float Fast_Cos(float val); +static WWINLINE float Fast_Inv_Cos(float val); - static WWINLINE float Fast_Acos(float val); - static WWINLINE float Acos(float val); - static WWINLINE float Fast_Asin(float val); - static WWINLINE float Asin(float val); +static WWINLINE float Fast_Acos(float val); +static WWINLINE float Acos(float val); +static WWINLINE float Fast_Asin(float val); +static WWINLINE float Asin(float val); #ifdef USE_DETERMINISTIC_MATH @@ -146,55 +159,47 @@ class WWMath static WWINLINE float Pow(float x, float y) { return gm_powf(x, y); } #else static WWINLINE float Atan(float x) { return static_cast(atan(x)); } - static WWINLINE float Atan2(float y, float x) { return static_cast(atan2(y, x)); } - static WWINLINE float Tan(float x) { return static_cast(tan(x)); } - static WWINLINE float Sinh(float x) { return static_cast(sinh(x)); } - static WWINLINE float Cosh(float x) { return static_cast(cosh(x)); } - static WWINLINE float Tanh(float x) { return static_cast(tanh(x)); } - static WWINLINE float Exp(float x) { return static_cast(exp(x)); } - static WWINLINE float Log(float x) { return static_cast(log(x)); } - static WWINLINE float Log10(float x) { return static_cast(log10(x)); } - static WWINLINE float Pow(float x, float y) { return static_cast(pow(x, y)); } + static WWINLINE float Atan2(float y,float x) { return static_cast(atan2(y,x)); } #endif - static WWINLINE float Sign(float val); - static WWINLINE float Ceil(float val) { return ceilf(val); } - static WWINLINE float Floor(float val) { return floorf(val); } - static WWINLINE float Round(float val) { return floorf(val + 0.5f); } - static WWINLINE bool Fast_Is_Float_Positive(const float& val); - static WWINLINE bool Is_Power_Of_2(const unsigned int val); +static WWINLINE float Sign(float val); +static WWINLINE float Ceil(float val) { return ceilf(val); } +static WWINLINE float Floor(float val) { return floorf(val); } +static WWINLINE float Round(float val) { return floorf(val + 0.5f); } +static WWINLINE bool Fast_Is_Float_Positive(const float & val); +static WWINLINE bool Is_Power_Of_2(const unsigned int val); - static float Random_Float(); +static float Random_Float(); - static WWINLINE float Random_Float(float min, float max); - static WWINLINE float Clamp(float val, float min = 0.0f, float max = 1.0f); - static WWINLINE double Clamp(double val, double min = 0.0f, double max = 1.0f); - static WWINLINE int Clamp_Int(int val, int min_val, int max_val); - static WWINLINE float Wrap(float val, float min = 0.0f, float max = 1.0f); - static WWINLINE double Wrap(double val, double min = 0.0f, double max = 1.0f); - static WWINLINE float Min(float a, float b); - static WWINLINE float Max(float a, float b); +static WWINLINE float Random_Float(float min,float max); +static WWINLINE float Clamp(float val, float min = 0.0f, float max = 1.0f); +static WWINLINE double Clamp(double val, double min = 0.0f, double max = 1.0f); +static WWINLINE int Clamp_Int(int val, int min_val, int max_val); +static WWINLINE float Wrap(float val, float min = 0.0f, float max = 1.0f); +static WWINLINE double Wrap(double val, double min = 0.0f, double max = 1.0f); +static WWINLINE float Min(float a, float b); +static WWINLINE float Max(float a, float b); - static WWINLINE int Float_As_Int(const float f) { return *((int*)&f); } +static WWINLINE int Float_As_Int(const float f) { return *((int*)&f); } - // Linearly interpolates between a and b using parameter t in [0, 1]. - // t = 0 returns a, t = 1 returns b, values in between return a proportionate blend. - static WWINLINE float Lerp(float a, float b, float t); - static WWINLINE double Lerp(double a, double b, float t); +// Linearly interpolates between a and b using parameter t in [0, 1]. +// t = 0 returns a, t = 1 returns b, values in between return a proportionate blend. +static WWINLINE float Lerp(float a, float b, float t); +static WWINLINE double Lerp(double a, double b, float t); - // Computes the interpolation parameter t such that v = Lerp(a, b, t). - // Returns where v lies between a and b as a ratio, typically in [0, 1]. - static WWINLINE float Inverse_Lerp(float a, float b, float v); - static WWINLINE double Inverse_Lerp(double a, double b, float v); +// Computes the interpolation parameter t such that v = Lerp(a, b, t). +// Returns where v lies between a and b as a ratio, typically in [0, 1]. +static WWINLINE float Inverse_Lerp(float a, float b, float v); +static WWINLINE double Inverse_Lerp(double a, double b, float v); - static WWINLINE long Float_To_Long(double f); +static WWINLINE long Float_To_Long(double f); - static WWINLINE unsigned char Unit_Float_To_Byte(float f) { return (unsigned char)(f * 255.0f); } - static WWINLINE float Byte_To_Unit_Float(unsigned char byte) { return ((float)byte) / 255.0f; } +static WWINLINE unsigned char Unit_Float_To_Byte(float f) { return (unsigned char)(f*255.0f); } +static WWINLINE float Byte_To_Unit_Float(unsigned char byte) { return ((float)byte) / 255.0f; } - static WWINLINE bool Is_Valid_Float(float x); - static WWINLINE bool Is_Valid_Double(double x); +static WWINLINE bool Is_Valid_Float(float x); +static WWINLINE bool Is_Valid_Double(double x); - static WWINLINE float Normalize_Angle(float angle); // Normalizes the angle to the range -PI..PI +static WWINLINE float Normalize_Angle(float angle); // Normalizes the angle to the range -PI..PI }; @@ -209,52 +214,52 @@ WWINLINE float WWMath::Sign(float val) return 0.0f; } -WWINLINE bool WWMath::Fast_Is_Float_Positive(const float& val) +WWINLINE bool WWMath::Fast_Is_Float_Positive(const float & val) { - return !((*(int*)(&val)) & 0x80000000); + return !((*(int *)(&val)) & 0x80000000); } WWINLINE bool WWMath::Is_Power_Of_2(const unsigned int val) { - return !((val)&val - 1); + return !((val)&val-1); } -WWINLINE float WWMath::Random_Float(float min, float max) +WWINLINE float WWMath::Random_Float(float min,float max) { - return Random_Float() * (max - min) + min; + return Random_Float() * (max-min) + min; } WWINLINE float WWMath::Clamp(float val, float min /*= 0.0f*/, float max /*= 1.0f*/) { - if (val < min) return min; - if (val > max) return max; + if(val < min) return min; + if(val > max) return max; return val; } WWINLINE double WWMath::Clamp(double val, double min /*= 0.0f*/, double max /*= 1.0f*/) { - if (val < min) return min; - if (val > max) return max; + if(val < min) return min; + if(val > max) return max; return val; } WWINLINE int WWMath::Clamp_Int(int val, int min_val, int max_val) { - if (val < min_val) return min_val; - if (val > max_val) return max_val; + if(val < min_val) return min_val; + if(val > max_val) return max_val; return val; } WWINLINE float WWMath::Wrap(float val, float min /*= 0.0f*/, float max /*= 1.0f*/) { // Implemented as an if rather than a while, to long loops - if (val >= max) val -= (max - min); - if (val < min) val += (max - min); + if ( val >= max ) val -= (max-min); + if ( val < min ) val += (max-min); - if (val < min) { + if ( val < min ) { val = min; } - if (val > max) { + if ( val > max ) { val = max; } return val; @@ -263,12 +268,12 @@ WWINLINE float WWMath::Wrap(float val, float min /*= 0.0f*/, float max /*= 1.0f* WWINLINE double WWMath::Wrap(double val, double min /*= 0.0f*/, double max /*= 1.0f*/) { // Implemented as an if rather than a while, to long loops - if (val >= max) val -= (max - min); - if (val < min) val += (max - min); - if (val < min) { + if ( val >= max ) val -= (max-min); + if ( val < min ) val += (max-min); + if ( val < min ) { val = min; } - if (val > max) { + if ( val > max ) { val = max; } return val; @@ -276,24 +281,24 @@ WWINLINE double WWMath::Wrap(double val, double min /*= 0.0f*/, double max /*= 1 WWINLINE float WWMath::Min(float a, float b) { - if (a < b) return a; + if (a b) return a; + if (a>b) return a; return b; } WWINLINE float WWMath::Lerp(float a, float b, float t) { - return (a + (b - a) * t); + return (a + (b - a)*t); } WWINLINE double WWMath::Lerp(double a, double b, float t) { - return (a + (b - a) * t); + return (a + (b - a)*t); } WWINLINE float WWMath::Inverse_Lerp(float a, float b, float v) @@ -308,8 +313,8 @@ WWINLINE double WWMath::Inverse_Lerp(double a, double b, float v) WWINLINE bool WWMath::Is_Valid_Float(float x) { - unsigned long* plong = (unsigned long*)(&x); - unsigned long exponent = ((*plong) & 0x7F800000) >> (32 - 9); + unsigned long * plong = (unsigned long *)(&x); + unsigned long exponent = ((*plong) & 0x7F800000) >> (32-9); // if exponent is 0xFF, this is a NAN if (exponent == 0xFF) { @@ -320,8 +325,8 @@ WWINLINE bool WWMath::Is_Valid_Float(float x) WWINLINE bool WWMath::Is_Valid_Double(double x) { - unsigned long* plong = (unsigned long*)(&x) + 1; - unsigned long exponent = ((*plong) & 0x7FF00000) >> (32 - 12); + unsigned long * plong = (unsigned long *)(&x) + 1; + unsigned long exponent = ((*plong) & 0x7FF00000) >> (32-12); // if exponent is 0x7FF, this is a NAN if (exponent == 0x7FF) { @@ -334,18 +339,39 @@ WWINLINE bool WWMath::Is_Valid_Double(double x) // Float to long // ---------------------------------------------------------------------------- +#if defined(_MSC_VER) && defined(_M_IX86) +WWINLINE long WWMath::Float_To_Long(float f) +{ + long i; + + __asm { + fld [f] + fistp [i] + } + + return i; +} +#else WWINLINE long WWMath::Float_To_Long(float f) { - return (long)(f + (f >= 0.0f ? 0.5f : -0.5f)); + return (long) f; } +#endif WWINLINE long WWMath::Float_To_Long(double f) { - return (long)(f + (f >= 0.0 ? 0.5 : -0.5)); +#if defined(_MSC_VER) && defined(_M_IX86) + long retval; + __asm fld qword ptr [f] + __asm fistp dword ptr [retval] + return retval; +#else + return (long) f; +#endif } // ---------------------------------------------------------------------------- -// Cos (deterministic, GameMath) +// Cos // ---------------------------------------------------------------------------- #ifdef USE_DETERMINISTIC_MATH @@ -359,9 +385,9 @@ WWINLINE float WWMath::Cos(float val) { float retval; __asm { - fld[val] + fld [val] fcos - fstp[retval] + fstp [retval] } return retval; } @@ -374,7 +400,7 @@ WWINLINE float WWMath::Cos(float val) #endif // ---------------------------------------------------------------------------- -// Sin (deterministic, GameMath) +// Sin // ---------------------------------------------------------------------------- #ifdef USE_DETERMINISTIC_MATH @@ -388,9 +414,9 @@ WWINLINE float WWMath::Sin(float val) { float retval; __asm { - fld[val] + fld [val] fsin - fstp[retval] + fstp [retval] } return retval; } @@ -408,14 +434,14 @@ WWINLINE float WWMath::Sin(float val) WWINLINE float WWMath::Fast_Sin(float val) { - val *= float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); + val*=float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); - int idx0 = Float_To_Int_Floor(val); - int idx1 = idx0 + 1; - float frac = val - (float)idx0; + int idx0=Float_To_Int_Floor(val); + int idx1=idx0+1; + float frac=val-(float)idx0; - idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE - 1); - idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE - 1); + idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1); + idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1); return (1.0f - frac) * _FastSinTable[idx0] + frac * _FastSinTable[idx1]; } @@ -429,19 +455,18 @@ WWINLINE float WWMath::Fast_Inv_Sin(float val) #if 0 // TODO: more testing, not reliable! float index = val * float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); - int idx0 = Float_To_Int_Floor(index); - int idx1 = idx0 + 1; - float frac = val - (float)idx0; + int idx0=Float_To_Int_Floor(index); + int idx1=idx0+1; + float frac=val-(float)idx0; - idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE - 1); - idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE - 1); + idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1); + idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1); // The table becomes inaccurate near 0 and 2pi so fall back to doing a divide. const int BUFFER = 16; - if ((idx0 <= BUFFER) || (idx0 >= SIN_TABLE_SIZE - BUFFER - 1)) { + if ((idx0 <= BUFFER) || (idx0 >= SIN_TABLE_SIZE-BUFFER-1)) { return 1.0f / WWMath::Fast_Sin(val); - } - else { + } else { return (1.0f - frac) * _FastInvSinTable[idx0] + frac * _FastInvSinTable[idx1]; } #else @@ -456,15 +481,15 @@ WWINLINE float WWMath::Fast_Inv_Sin(float val) WWINLINE float WWMath::Fast_Cos(float val) { - val += (WWMATH_PI * 0.5f); - val *= float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); + val+=(WWMATH_PI * 0.5f); + val*=float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); - int idx0 = Float_To_Int_Floor(val); - int idx1 = idx0 + 1; - float frac = val - (float)idx0; + int idx0=Float_To_Int_Floor(val); + int idx1=idx0+1; + float frac=val-(float)idx0; - idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE - 1); - idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE - 1); + idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1); + idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1); return (1.0f - frac) * _FastSinTable[idx0] + frac * _FastSinTable[idx1]; } @@ -479,18 +504,17 @@ WWINLINE float WWMath::Fast_Inv_Cos(float val) float index = val + (WWMATH_PI * 0.5f); index *= float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); - int idx0 = Float_To_Int_Chop(index); - int idx1 = idx0 + 1; - float frac = val - (float)idx0; + int idx0=Float_To_Int_Chop(index); + int idx1=idx0+1; + float frac=val-(float)idx0; - idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE - 1); - idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE - 1); + idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1); + idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1); // The table becomes inaccurate near 0 and 2pi so fall back to doing a divide. - if ((idx0 <= 2) || (idx0 >= SIN_TABLE_SIZE - 3)) { + if ((idx0 <= 2) || (idx0 >= SIN_TABLE_SIZE-3)) { return 1.0f / WWMath::Fast_Cos(val); - } - else { + } else { return (1.0f - frac) * _FastInvSinTable[idx0] + frac * _FastInvSinTable[idx1]; } #else @@ -509,14 +533,14 @@ WWINLINE float WWMath::Fast_Acos(float val) return WWMath::Acos(val); } - val *= float(ARC_TABLE_SIZE / 2); + val*=float(ARC_TABLE_SIZE/2); - int idx0 = Float_To_Int_Floor(val); - int idx1 = idx0 + 1; - float frac = val - (float)idx0; + int idx0=Float_To_Int_Floor(val); + int idx1=idx0+1; + float frac=val-(float)idx0; - idx0 += ARC_TABLE_SIZE / 2; - idx1 += ARC_TABLE_SIZE / 2; + idx0+=ARC_TABLE_SIZE/2; + idx1+=ARC_TABLE_SIZE/2; // we dont even get close to the edge of the table... assert((idx0 >= 0) && (idx0 < ARC_TABLE_SIZE)); @@ -553,14 +577,14 @@ WWINLINE float WWMath::Fast_Asin(float val) return WWMath::Asin(val); } - val *= float(ARC_TABLE_SIZE / 2); + val*=float(ARC_TABLE_SIZE/2); - int idx0 = Float_To_Int_Floor(val); - int idx1 = idx0 + 1; - float frac = val - (float)idx0; + int idx0=Float_To_Int_Floor(val); + int idx1=idx0+1; + float frac=val-(float)idx0; - idx0 += ARC_TABLE_SIZE / 2; - idx1 += ARC_TABLE_SIZE / 2; + idx0+=ARC_TABLE_SIZE/2; + idx1+=ARC_TABLE_SIZE/2; // we dont even get close to the edge of the table... assert((idx0 >= 0) && (idx0 < ARC_TABLE_SIZE)); @@ -587,7 +611,7 @@ WWINLINE float WWMath::Asin(float val) #endif // ---------------------------------------------------------------------------- -// Sqrt (IEEE 754 guarantees correctly-rounded results on all platforms) +// Sqrt // ---------------------------------------------------------------------------- #ifdef USE_DETERMINISTIC_MATH @@ -601,9 +625,9 @@ WWINLINE float WWMath::Sqrt(float val) { float retval; __asm { - fld[val] + fld [val] fsqrt - fstp[retval] + fstp [retval] } return retval; } @@ -617,32 +641,32 @@ WWINLINE float WWMath::Sqrt(float val) WWINLINE int WWMath::Float_To_Int_Chop(const float& f) { - int a = *reinterpret_cast(&f); // take bit pattern of float into a register - int sign = (a >> 31); // sign = 0xFFFFFFFF if original value is negative, 0 if positive - int mantissa = (a & ((1 << 23) - 1)) | (1 << 23); // extract mantissa and add the hidden bit - int exponent = ((a & 0x7fffffff) >> 23) - 127; // extract the exponent - int r = ((unsigned int)(mantissa) << 8) >> (31 - exponent); // ((1<>24 -- (we know that mantissa > (1<<24)) - return ((r ^ (sign)) - sign) & ~(exponent >> 31); // add original sign. If exponent was negative, make return value 0. + int a = *reinterpret_cast(&f); // take bit pattern of float into a register + int sign = (a>>31); // sign = 0xFFFFFFFF if original value is negative, 0 if positive + int mantissa = (a&((1<<23)-1))|(1<<23); // extract mantissa and add the hidden bit + int exponent = ((a&0x7fffffff)>>23)-127; // extract the exponent + int r = ((unsigned int)(mantissa)<<8)>>(31-exponent); // ((1<>24 -- (we know that mantissa > (1<<24)) + return ((r ^ (sign)) - sign ) &~ (exponent>>31); // add original sign. If exponent was negative, make return value 0. } -WWINLINE int WWMath::Float_To_Int_Floor(const float& f) +WWINLINE int WWMath::Float_To_Int_Floor (const float& f) { - int a = *reinterpret_cast(&f); // take bit pattern of float into a register - int sign = (a >> 31); // sign = 0xFFFFFFFF if original value is negative, 0 if positive - a &= 0x7fffffff; // we don't need the sign any more + int a = *reinterpret_cast(&f); // take bit pattern of float into a register + int sign = (a>>31); // sign = 0xFFFFFFFF if original value is negative, 0 if positive + a&=0x7fffffff; // we don't need the sign any more - int exponent = (a >> 23) - 127; // extract the exponent - int expsign = ~(exponent >> 31); // 0xFFFFFFFF if exponent is positive, 0 otherwise - int imask = ((1 << (31 - (exponent)))) - 1; // mask for true integer values - int mantissa = (a & ((1 << 23) - 1)); // extract mantissa (without the hidden bit) - int r = ((unsigned int)(mantissa | (1 << 23)) << 8) >> (31 - exponent); // ((1<>24 -- (we know that mantissa > (1<<24)) + int exponent = (a>>23)-127; // extract the exponent + int expsign = ~(exponent>>31); // 0xFFFFFFFF if exponent is positive, 0 otherwise + int imask = ( (1<<(31-(exponent))))-1; // mask for true integer values + int mantissa = (a&((1<<23)-1)); // extract mantissa (without the hidden bit) + int r = ((unsigned int)(mantissa|(1<<23))<<8)>>(31-exponent); // ((1<>24 -- (we know that mantissa > (1<<24)) - r = ((r & expsign) ^ (sign)) + ((!((mantissa << 8) & imask) & (expsign ^ ((a - 1) >> 31))) & sign); // if (fabs(value)<1.0) value = 0; copy sign; if (value < 0 && value==(int)(value)) value++; + r = ((r & expsign) ^ (sign)) + ((!((mantissa<<8)&imask)&(expsign^((a-1)>>31)))&sign); // if (fabs(value)<1.0) value = 0; copy sign; if (value < 0 && value==(int)(value)) value++; return r; } -/// ---------------------------------------------------------------------------- -// Inverse square root (deterministic, portable Quake III style + GameMath) +// ---------------------------------------------------------------------------- +// Inverse square root // ---------------------------------------------------------------------------- #ifdef USE_DETERMINISTIC_MATH @@ -658,20 +682,20 @@ WWINLINE float WWMath::Inv_Sqrt(float a) __asm { mov eax, 0be6eb508h - mov DWORD PTR[esp - 12], 03fc00000h; 1.5 on the stack - sub eax, DWORD PTR[a]; a - sub DWORD PTR[a], 800000h; a / 2 a = Y0 - shr eax, 1; firs approx in eax = R0 - mov DWORD PTR[esp - 8], eax - - fld DWORD PTR[esp - 8];r - fmul st, st;r* r - fld DWORD PTR[esp - 8];r + mov DWORD PTR [esp-12],03fc00000h ; 1.5 on the stack + sub eax, DWORD PTR [a]; a + sub DWORD PTR [a], 800000h ; a/2 a=Y0 + shr eax, 1 ; firs approx in eax=R0 + mov DWORD PTR [esp-8], eax + + fld DWORD PTR [esp-8] ;r + fmul st, st ;r*r + fld DWORD PTR [esp-8] ;r fxch st(1) - fmul DWORD PTR[a];a;r* r* y0 - fld DWORD PTR[esp - 12];load 1.5 + fmul DWORD PTR [a];a ;r*r*y0 + fld DWORD PTR [esp-12];load 1.5 fld st(0) - fsub st, st(2);r1 = 1.5 - y1 + fsub st,st(2) ;r1 = 1.5 - y1 ;x1 = st(3) ;y1 = st(2) ;1.5 = st(1) @@ -679,20 +703,20 @@ WWINLINE float WWMath::Inv_Sqrt(float a) fld st(1) fxch st(1) - fmul st(3), st; y2 = y1 * r1*... - fmul st(3), st; y2 = y1 * r1 * r1 - fmulp st(4), st; x2 = x1 * r1 - fsub st, st(2); r2 = 1.5 - y2 - ;x2 = st(3) - ;y2 = st(2) - ;1.5 = st(1) + fmul st(3),st ; y2=y1*r1*... + fmul st(3),st ; y2=y1*r1*r1 + fmulp st(4),st ; x2=x1*r1 + fsub st,st(2) ; r2=1.5-y2 + ;x2=st(3) + ;y2=st(2) + ;1.5=st(1) ;r2 = st(0) - fmul st(2), st;y3 = y2 * r2*... - fmul st(3), st;x3 = x2 * r2 - fmulp st(2), st;y3 = y2 * r2 * r2 + fmul st(2),st ;y3=y2*r2*... + fmul st(3),st ;x3=x2*r2 + fmulp st(2),st ;y3=y2*r2*r2 fxch st(1) - fsubp st(1), st;r3 = 1.5 - y3 + fsubp st(1),st ;r3= 1.5 - y3 ;x3 = st(1) ;r3 = st(0) fmulp st(1), st diff --git a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp index 97770f6ab10..75eef81659d 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp @@ -80,7 +80,7 @@ static void drawFramerateBar(); #include "W3DDevice/GameClient/W3DDebugDisplay.h" #include "W3DDevice/GameClient/W3DProjectedShadow.h" #include "W3DDevice/GameClient/W3DShroud.h" -#include "WWMath/wwmath.h" +#include "wwmath.h" #include "WWLib/registry.h" #include "WW3D2/ww3d.h" #include "WW3D2/predlod.h" diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp index 848a2d06759..de84802f788 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp @@ -31,7 +31,7 @@ // USER INCLUDES ////////////////////////////////////////////////////////////////////////////////// #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine -#include "WWMath/wwmath.h" +#include "wwmath.h" #include "Common/BuildAssistant.h" #include "Common/GlobalData.h" diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/Geometry.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/Geometry.cpp index 8b7f37bca47..d9e1a4a430c 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/Geometry.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/Geometry.cpp @@ -31,7 +31,7 @@ #define DEFINE_GEOMETRY_NAMES // USER INCLUDES ////////////////////////////////////////////////////////////////////////////////// -#include "WWMath/wwmath.h" +#include "wwmath.h" #include "Common/Geometry.h" #include "Common/INI.h" #include "Common/RandomValue.h" diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp index 6a18abf2b9e..bdcb0023bfe 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp @@ -27,7 +27,7 @@ // Author: Michael S. Booth, January 2002 #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine -#include "WWMath/wwmath.h" +#include "wwmath.h" #include "Common/ActionManager.h" #include "Common/BuildAssistant.h" diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp index e7b842d15ca..c3727c08ad6 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp @@ -28,7 +28,7 @@ #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine -#include "WWMath/wwmath.h" +#include "wwmath.h" #include "Common/GameMemory.h" #include "Common/GlobalData.h" diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp index 0cef68c75d6..337d0663abd 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp @@ -27,7 +27,7 @@ // Author: Michael S. Booth, January 2002 #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine -#include "WWMath/wwmath.h" +#include "wwmath.h" #include "Common/ActionManager.h" #include "Common/AudioHandleSpecialValues.h" diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp index cf0f2463471..1a04eaf0c13 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp @@ -35,7 +35,7 @@ #define DEFINE_LOCO_Z_NAMES #define DEFINE_LOCO_APPEARANCE_NAMES -#include "WWMath/wwmath.h" +#include "wwmath.h" #include "Common/INI.h" #include "GameLogic/GameLogic.h" diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp index 075f7999381..7807bf696e0 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp @@ -49,7 +49,7 @@ //----------------------------------------------------------------------------- #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine -#include "WWMath/wwmath.h" +#include "wwmath.h" #include "Common/ActionManager.h" #include "Common/DiscreteCircle.h" diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp index f223ff1b776..694330dbe77 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp @@ -28,7 +28,7 @@ #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine -#include "WWMath/wwmath.h" +#include "wwmath.h" // please talk to MDC (x36804) before taking this out #define NO_DEBUG_CRC diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp index 5965ca3681c..39b34b10557 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp @@ -30,7 +30,7 @@ // INCLUDES /////////////////////////////////////////////////////////////////////////////////////// #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine -#include "WWMath/wwmath.h" +#include "wwmath.h" #define DEFINE_DEATH_NAMES #define DEFINE_WEAPONBONUSCONDITION_NAMES diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp index 6a17841b0fa..c31f0a62488 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp @@ -81,7 +81,7 @@ static void drawFramerateBar(); #include "W3DDevice/GameClient/W3DDebugDisplay.h" #include "W3DDevice/GameClient/W3DProjectedShadow.h" #include "W3DDevice/GameClient/W3DShroud.h" -#include "WWMath/wwmath.h" +#include "wwmath.h" #include "WWLib/registry.h" #include "WW3D2/ww3d.h" #include "WW3D2/predlod.h" diff --git a/cmake/gamemath.cmake b/cmake/gamemath.cmake index 3260eff66a1..1761f842698 100644 --- a/cmake/gamemath.cmake +++ b/cmake/gamemath.cmake @@ -4,9 +4,8 @@ set(GM_ENABLE_TESTS OFF CACHE BOOL "Disable GameMath tests" FORCE) FetchContent_Declare( gamemath GIT_REPOSITORY https://github.com/TheSuperHackers/GameMath.git - GIT_TAG master + GIT_TAG 59f7ccd494f7e7c916a784ac26ef266f9f09d78d ) FetchContent_MakeAvailable(gamemath) -include_directories(${gamemath_SOURCE_DIR}/include) From d28bcb23df5bf5df17fe0a073a435b7e4a7bfc1a Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Tue, 28 Apr 2026 01:47:35 +0300 Subject: [PATCH 12/13] feat: Add WWMath::CosTrig/SinTrig wrappers for backward-compatible Trig.cpp replacement SinTrig/CosTrig use cosf/sinf (matching original Trig.cpp CRT behavior) without USE_DETERMINISTIC_MATH, and gm_cosf/gm_sinf with it enabled. This preserves CRC compatibility with retail replays in non-deterministic builds while providing cross-platform determinism when USE_DETERMINISTIC_MATH is active. --- Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp | 12 ++++++------ Core/Libraries/Source/WWVegas/WWMath/wwmath.h | 10 ++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp b/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp index 19febd1f0ed..8ae1b7faa31 100644 --- a/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp +++ b/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp @@ -3955,8 +3955,8 @@ Bool PathfindLayer::isPointOnWall(ObjectID *wallPieces, Int numPieces, const Coo Real major = obj->getGeometryInfo().getMajorRadius(); Real minor = (obj->getGeometryInfo().getGeomType() == GEOMETRY_SPHERE) ? obj->getGeometryInfo().getMajorRadius() : obj->getGeometryInfo().getMinorRadius(); - Real c = (Real)WWMath::Cos(-obj->getOrientation()); - Real s = (Real)WWMath::Sin(-obj->getOrientation()); + Real c = (Real)WWMath::CosTrig(-obj->getOrientation()); + Real s = (Real)WWMath::SinTrig(-obj->getOrientation()); // convert to a delta relative to rect ctr Real ptx = pt->x - obj->getPosition()->x; @@ -4223,8 +4223,8 @@ void Pathfinder::classifyFence( Object *obj, Bool insert ) Real halfsizeY = PATHFIND_CELL_SIZE_F/10.0f; Real fenceOffset = obj->getTemplate()->getFenceXOffset(); - Real c = (Real)WWMath::Cos(angle); - Real s = (Real)WWMath::Sin(angle); + Real c = (Real)WWMath::CosTrig(angle); + Real s = (Real)WWMath::SinTrig(angle); const Real STEP_SIZE = PATHFIND_CELL_SIZE_F * 0.5f; // in theory, should be PATHFIND_CELL_SIZE_F exactly, but needs to be smaller to avoid aliasing problems Real ydx = s * STEP_SIZE; @@ -4431,8 +4431,8 @@ void Pathfinder::internal_classifyObjectFootprint( Object *obj, Bool insert ) Real halfsizeX = obj->getGeometryInfo().getMajorRadius(); Real halfsizeY = obj->getGeometryInfo().getMinorRadius(); - Real c = (Real)WWMath::Cos(angle); - Real s = (Real)WWMath::Sin(angle); + Real c = (Real)WWMath::CosTrig(angle); + Real s = (Real)WWMath::SinTrig(angle); const Real STEP_SIZE = PATHFIND_CELL_SIZE_F * 0.5f; // in theory, should be PATHFIND_CELL_SIZE_F exactly, but needs to be smaller to avoid aliasing problems Real ydx = s * STEP_SIZE; diff --git a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h index 109632f504c..0aa46915a30 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h +++ b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h @@ -157,9 +157,19 @@ static WWINLINE float Asin(float val); static WWINLINE float Log(float x) { return gm_logf(x); } static WWINLINE float Log10(float x) { return gm_log10f(x); } static WWINLINE float Pow(float x, float y) { return gm_powf(x, y); } + static WWINLINE float SinTrig(float x) { return gm_sinf(x); } + static WWINLINE float CosTrig(float x) { return gm_cosf(x); } + static WWINLINE float TanTrig(float x) { return gm_tanf(x); } + static WWINLINE float ACosTrig(float x) { return gm_acosf(x); } + static WWINLINE float ASinTrig(float x) { return gm_asinf(x); } #else static WWINLINE float Atan(float x) { return static_cast(atan(x)); } static WWINLINE float Atan2(float y,float x) { return static_cast(atan2(y,x)); } + static WWINLINE float SinTrig(float x) { return sinf(x); } + static WWINLINE float CosTrig(float x) { return cosf(x); } + static WWINLINE float TanTrig(float x) { return tanf(x); } + static WWINLINE float ACosTrig(float x) { return acosf(x); } + static WWINLINE float ASinTrig(float x) { return asinf(x); } #endif static WWINLINE float Sign(float val); static WWINLINE float Ceil(float val) { return ceilf(val); } From 9daa569e774ae2a23e42659aeab183dab22d1c51 Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Tue, 28 Apr 2026 01:59:43 +0300 Subject: [PATCH 13/13] feat: Replace WWMath::Cos/Sin with CosTrig/SinTrig in game logic (Generals + GeneralsMD) All game logic files that originally used global Cos()/Sin() from Trig.cpp now use WWMath::CosTrig()/SinTrig() which preserves cosf()/sinf() behavior without USE_DETERMINISTIC_MATH, and routes through gm_cosf()/gm_sinf() when deterministic math is enabled. --- .../Source/Common/System/BuildAssistant.cpp | 8 ++--- .../Source/Common/System/Geometry.cpp | 8 ++--- .../GameEngine/Source/Common/Thing/Thing.cpp | 8 ++--- .../Source/GameLogic/AI/AIGroup.cpp | 4 +-- .../Source/GameLogic/AI/AISkirmishPlayer.cpp | 8 ++--- .../Source/GameLogic/AI/AIStates.cpp | 8 ++--- .../Source/GameLogic/Map/TerrainLogic.cpp | 12 +++---- .../Behavior/DumbProjectileBehavior.cpp | 8 ++--- .../Behavior/GenerateMinefieldBehavior.cpp | 4 +-- .../Object/Behavior/ParkingPlaceBehavior.cpp | 4 +-- .../Object/Contain/GarrisonContain.cpp | 8 ++--- .../GameLogic/Object/Contain/OpenContain.cpp | 4 +-- .../Object/Contain/TunnelContain.cpp | 4 +-- .../Source/GameLogic/Object/Locomotor.cpp | 24 +++++++------- .../GameLogic/Object/ObjectCreationList.cpp | 16 +++++----- .../GameLogic/Object/PartitionManager.cpp | 16 +++++----- .../Object/Update/AIUpdate/JetAIUpdate.cpp | 12 +++---- .../Update/AIUpdate/RailroadGuideAIUpdate.cpp | 4 +-- .../DynamicShroudClearingRangeUpdate.cpp | 4 +-- .../GameLogic/Object/Update/FloatUpdate.cpp | 4 +-- .../Update/HelicopterSlowDeathUpdate.cpp | 4 +-- .../Object/Update/MobMemberSlavedUpdate.cpp | 4 +-- .../Update/ParticleUplinkCannonUpdate.cpp | 4 +-- .../GameLogic/Object/Update/PhysicsUpdate.cpp | 2 +- .../GameLogic/Object/Update/SlavedUpdate.cpp | 20 ++++++------ .../GameLogic/Object/Update/StealthUpdate.cpp | 2 +- .../Object/Update/StructureToppleUpdate.cpp | 32 +++++++++---------- .../GameLogic/Object/Update/ToppleUpdate.cpp | 4 +-- .../Object/Update/WaveGuideUpdate.cpp | 4 +-- .../Source/GameLogic/Object/Weapon.cpp | 12 +++---- .../GameLogic/ScriptEngine/ScriptEngine.cpp | 8 ++--- .../Source/Common/System/BuildAssistant.cpp | 8 ++--- .../Source/Common/System/Geometry.cpp | 8 ++--- .../GameEngine/Source/Common/Thing/Thing.cpp | 8 ++--- .../Source/GameLogic/AI/AIGroup.cpp | 4 +-- .../Source/GameLogic/AI/AISkirmishPlayer.cpp | 8 ++--- .../Source/GameLogic/AI/AIStates.cpp | 8 ++--- .../Source/GameLogic/Map/TerrainLogic.cpp | 12 +++---- .../Behavior/DumbProjectileBehavior.cpp | 8 ++--- .../Object/Behavior/FlightDeckBehavior.cpp | 4 +-- .../Behavior/GenerateMinefieldBehavior.cpp | 4 +-- .../Object/Behavior/ParkingPlaceBehavior.cpp | 4 +-- .../Object/Contain/GarrisonContain.cpp | 8 ++--- .../GameLogic/Object/Contain/OpenContain.cpp | 4 +-- .../Object/Contain/TunnelContain.cpp | 4 +-- .../Source/GameLogic/Object/Locomotor.cpp | 24 +++++++------- .../GameLogic/Object/ObjectCreationList.cpp | 16 +++++----- .../GameLogic/Object/PartitionManager.cpp | 16 +++++----- .../Object/Update/AIUpdate/JetAIUpdate.cpp | 12 +++---- .../Update/AIUpdate/RailroadGuideAIUpdate.cpp | 4 +-- .../DynamicShroudClearingRangeUpdate.cpp | 4 +-- .../GameLogic/Object/Update/FloatUpdate.cpp | 4 +-- .../Update/HelicopterSlowDeathUpdate.cpp | 4 +-- .../Object/Update/MobMemberSlavedUpdate.cpp | 4 +-- .../Update/ParticleUplinkCannonUpdate.cpp | 4 +-- .../GameLogic/Object/Update/PhysicsUpdate.cpp | 2 +- .../GameLogic/Object/Update/SlavedUpdate.cpp | 20 ++++++------ .../GameLogic/Object/Update/StealthUpdate.cpp | 2 +- .../Object/Update/StructureToppleUpdate.cpp | 32 +++++++++---------- .../GameLogic/Object/Update/ToppleUpdate.cpp | 4 +-- .../Object/Update/WaveGuideUpdate.cpp | 4 +-- .../Source/GameLogic/Object/Weapon.cpp | 14 ++++---- .../GameLogic/ScriptEngine/ScriptEngine.cpp | 8 ++--- 63 files changed, 267 insertions(+), 267 deletions(-) diff --git a/Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp b/Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp index 3c7a4436d19..b49a06389a2 100644 --- a/Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp +++ b/Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp @@ -752,8 +752,8 @@ Bool BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos, if (myFactoryExitWidth>0) { myExitPos = *worldPos; checkMyExit = true; - Real c = (Real)WWMath::Cos(angle); - Real s = (Real)WWMath::Sin(angle); + Real c = (Real)WWMath::CosTrig(angle); + Real s = (Real)WWMath::SinTrig(angle); Real offset = build->getTemplateGeometryInfo().getMajorRadius() + myFactoryExitWidth/2.0f; myExitPos.x += c*offset; myExitPos.y += s*offset; @@ -787,8 +787,8 @@ Bool BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos, if (themFactoryExitWidth>0) { hisExitPos = *them->getPosition(); checkHisExit = true; - Real c = (Real)WWMath::Cos(them->getOrientation()); - Real s = (Real)WWMath::Sin(them->getOrientation()); + Real c = (Real)WWMath::CosTrig(them->getOrientation()); + Real s = (Real)WWMath::SinTrig(them->getOrientation()); Real offset = them->getGeometryInfo().getMajorRadius() + themFactoryExitWidth/2.0f; hisExitPos.x += c*offset; hisExitPos.y += s*offset; diff --git a/Generals/Code/GameEngine/Source/Common/System/Geometry.cpp b/Generals/Code/GameEngine/Source/Common/System/Geometry.cpp index 5f9697b9644..b658d5a4b04 100644 --- a/Generals/Code/GameEngine/Source/Common/System/Geometry.cpp +++ b/Generals/Code/GameEngine/Source/Common/System/Geometry.cpp @@ -279,8 +279,8 @@ void GeometryInfo::get2DBounds(const Coord3D& geomCenter, Real angle, Region2D& case GEOMETRY_BOX: { - Real c = (Real)WWMath::Cos(angle); - Real s = (Real)WWMath::Sin(angle); + Real c = (Real)WWMath::CosTrig(angle); + Real s = (Real)WWMath::SinTrig(angle); Real exc = m_majorRadius*c; Real eyc = m_minorRadius*c; Real exs = m_majorRadius*s; @@ -398,8 +398,8 @@ void GeometryInfo::makeRandomOffsetWithinFootprint(Coord3D& pt) const #else Real radius = GameLogicRandomValueReal(0.0f, m_boundingCircleRadius); Real angle = GameLogicRandomValueReal(-PI, PI); - pt.x = radius * WWMath::Cos(angle); - pt.y = radius * WWMath::Sin(angle); + pt.x = radius * WWMath::CosTrig(angle); + pt.y = radius * WWMath::SinTrig(angle); pt.z = 0.0f; #endif break; diff --git a/Generals/Code/GameEngine/Source/Common/Thing/Thing.cpp b/Generals/Code/GameEngine/Source/Common/Thing/Thing.cpp index 769936d9824..dfa87e781e4 100644 --- a/Generals/Code/GameEngine/Source/Common/Thing/Thing.cpp +++ b/Generals/Code/GameEngine/Source/Common/Thing/Thing.cpp @@ -109,8 +109,8 @@ const Coord3D* Thing::getUnitDirectionVector2D() const if (!(m_cacheFlags & VALID_DIRVECTOR)) { Real angle = getOrientation(); - m_cachedDirVector.x = WWMath::Cos( angle ); - m_cachedDirVector.y = WWMath::Sin( angle ); + m_cachedDirVector.x = WWMath::CosTrig( angle ); + m_cachedDirVector.y = WWMath::SinTrig( angle ); m_cachedDirVector.z = 0; m_cacheFlags |= VALID_DIRVECTOR; } @@ -229,8 +229,8 @@ void Thing::setOrientation( Real angle ) z.y = 0.0f; z.z = 1.0f; - u.x = WWMath::Cos(angle); - u.y = WWMath::Sin(angle); + u.x = WWMath::CosTrig(angle); + u.y = WWMath::SinTrig(angle); u.z = 0.0f; y.crossProduct( &z, &u, &y ); diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp index a11919ad4f6..e401be036d1 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp @@ -1839,8 +1839,8 @@ void getHelicopterOffset( Coord3D& posOut, Int idx ) } Coord3D tempCtr = posOut; - posOut.x = tempCtr.x + (WWMath::Sin(angle) * radius); - posOut.y = tempCtr.y + (WWMath::Cos(angle) * radius); + posOut.x = tempCtr.x + (WWMath::SinTrig(angle) * radius); + posOut.y = tempCtr.y + (WWMath::CosTrig(angle) * radius); } diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp index 382237663b9..3e08d7b7f9d 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp @@ -663,8 +663,8 @@ void AISkirmishPlayer::buildAIBaseDefenseStructure(const AsciiString &thingName, } if (angle > PI/3) break; - Real s = WWMath::Sin(angle); - Real c = WWMath::Cos(angle); + Real s = WWMath::SinTrig(angle); + Real c = WWMath::CosTrig(angle); // TheSuperHackers @info helmutbuhler 21/04/2025 This debug mutates the code to become CRC incompatible #if defined(RTS_DEBUG) || !RETAIL_COMPATIBLE_CRC @@ -1029,8 +1029,8 @@ void AISkirmishPlayer::adjustBuildList(BuildListInfo *list) angle += 3*PI/4; - Real s = WWMath::Sin(angle); - Real c = WWMath::Cos(angle); + Real s = WWMath::SinTrig(angle); + Real c = WWMath::CosTrig(angle); cur = list; while (cur) { diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp index cdeb650612e..51f498ff8e6 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp @@ -604,8 +604,8 @@ StateReturnType AIRappelState::update() bldg->getGeometryInfo().getBoundingCircleRadius()); Real angle = GameLogicRandomValueReal( PI, 2*PI );//Downish. Coord3D startPosition = *bldg->getPosition(); - startPosition.x += offset * WWMath::Cos( angle ); - startPosition.y += offset * WWMath::Sin( angle ); + startPosition.x += offset * WWMath::CosTrig( angle ); + startPosition.y += offset * WWMath::SinTrig( angle ); startPosition.z = TheTerrainLogic->getGroundHeight( startPosition.x, startPosition.y ); obj->setPosition( &startPosition ); @@ -3804,8 +3804,8 @@ void AIFollowWaypointPathState::computeGoal(Bool useGroupOffsets) dy = dest.y - m_priorWaypoint->getLocation()->y; angle = WWMath::Atan2(dy, dx); Real deltaAngle = angle - m_angle; - Real s = WWMath::Sin(deltaAngle); - Real c = WWMath::Cos(deltaAngle); + Real s = WWMath::SinTrig(deltaAngle); + Real c = WWMath::CosTrig(deltaAngle); Real x = m_groupOffset.x * c - m_groupOffset.y * s; Real y = m_groupOffset.y * c + m_groupOffset.x * s; m_groupOffset.x = x; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp b/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp index 49ef68a338c..6885b0c6450 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp @@ -339,8 +339,8 @@ Bridge::Bridge(Object *bridgeObj) Real halfsizeY = bridgeObj->getGeometryInfo().getMinorRadius(); m_bridgeInfo.bridgeWidth = 2*halfsizeY; - Real c = (Real)WWMath::Cos(angle); - Real s = (Real)WWMath::Sin(angle); + Real c = (Real)WWMath::CosTrig(angle); + Real s = (Real)WWMath::SinTrig(angle); m_bridgeInfo.fromLeft.set(pos->x-halfsizeX*c-halfsizeY*s, pos->y + halfsizeY*c - halfsizeX*s, pos->z); m_bridgeInfo.toLeft.set(pos->x+halfsizeX*c-halfsizeY*s, pos->y + halfsizeY*c + halfsizeX*s, pos->z); @@ -1471,8 +1471,8 @@ void makeAlignToNormalMatrix( Real angle, const Coord3D& pos, const Coord3D& nor that WWMath::Atan2(xvec.y, xvec.x) == angle. So we must construct the matrix carefully to ensure this! */ - x.x = WWMath::Cos( angle ); - x.y = WWMath::Sin( angle ); + x.x = WWMath::CosTrig( angle ); + x.y = WWMath::SinTrig( angle ); x.z = 0.0f; //x.normalize(); -- redundant; is normalized by definition @@ -2652,8 +2652,8 @@ void TerrainLogic::flattenTerrain(Object *obj) Real halfsizeY = obj->getGeometryInfo().getMinorRadius(); - Real c = (Real)WWMath::Cos(angle); - Real s = (Real)WWMath::Sin(angle); + Real c = (Real)WWMath::CosTrig(angle); + Real s = (Real)WWMath::SinTrig(angle); Vector3 topLeft(pos->x-halfsizeX*c-halfsizeY*s, pos->y + halfsizeY*c - halfsizeX*s, 0); Vector3 topRight(pos->x+halfsizeX*c-halfsizeY*s, pos->y + halfsizeY*c + halfsizeX*s, 0); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp index 9803e847fe9..cbfd9263c97 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp @@ -225,10 +225,10 @@ static Bool calcTrajectory( // calc the horiz-speed & time for each. // note that time can only be negative for 90getGroundHeight( pt.x, pt.y ); offsetBySmallRandomAmount(pt, mineJitter); placeMineAt(pt, mineTemplate, team, obj); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp index 1728c8fc8fb..2549a869ae4 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp @@ -327,8 +327,8 @@ Bool ParkingPlaceBehavior::reserveSpace(ObjectID id, Real parkingOffset, Parking info->parkingSpace = d->m_parkInHangars ? ppi->m_hangarStart : ppi->m_location; if (parkingOffset != 0.0f) { - info->parkingSpace.x += parkingOffset * WWMath::Cos(ppi->m_orientation); - info->parkingSpace.y += parkingOffset * WWMath::Sin(ppi->m_orientation); + info->parkingSpace.x += parkingOffset * WWMath::CosTrig(ppi->m_orientation); + info->parkingSpace.y += parkingOffset * WWMath::SinTrig(ppi->m_orientation); } info->runwayPrep = ppi->m_prep; info->parkingOrientation = d->m_parkInHangars ? ppi->m_hangarStartOrient : ppi->m_orientation; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Contain/GarrisonContain.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Contain/GarrisonContain.cpp index 8314f6a1a3c..96acfd2a5ac 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Contain/GarrisonContain.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Contain/GarrisonContain.cpp @@ -1263,11 +1263,11 @@ void GarrisonContain::exitObjectViaDoor( Object *exitObj, ExitDoorType exitDoor if (loco && !TheAI->pathfinder()->validMovementTerrain( LAYER_GROUND, loco, &startPosition)) { // try front & back. Real offset = getObject()->getGeometryInfo().getMajorRadius(); - startPosition.x -= offset*WWMath::Cos(exitAngle); - startPosition.y -= offset*WWMath::Sin(exitAngle); + startPosition.x -= offset*WWMath::CosTrig(exitAngle); + startPosition.y -= offset*WWMath::SinTrig(exitAngle); if (!TheAI->pathfinder()->validMovementTerrain(LAYER_GROUND, loco, &startPosition)) { - startPosition.x += 2*offset*WWMath::Cos(exitAngle); - startPosition.y += 2*offset*WWMath::Sin(exitAngle); + startPosition.x += 2*offset*WWMath::CosTrig(exitAngle); + startPosition.y += 2*offset*WWMath::SinTrig(exitAngle); if (!TheAI->pathfinder()->validMovementTerrain(LAYER_GROUND, loco, &startPosition)) { startPosition = *getObject()->getPosition(); } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp index e86af265be8..339b841126c 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp @@ -611,8 +611,8 @@ void OpenContain::scatterToNearbyPosition(Object* rider) Real dist = GameLogicRandomValueReal( minRadius, maxRadius ); Coord3D pos; - pos.x = dist * WWMath::Cos( angle ) + containerPos->x; - pos.y = dist * WWMath::Sin( angle ) + containerPos->y; + pos.x = dist * WWMath::CosTrig( angle ) + containerPos->x; + pos.y = dist * WWMath::SinTrig( angle ) + containerPos->y; pos.z = TheTerrainLogic->getLayerHeight( pos.x, pos.y, theContainer->getLayer() ); // set orientation diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cpp index 6cdafd0e857..c827b321ac1 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cpp @@ -295,8 +295,8 @@ void TunnelContain::scatterToNearbyPosition(Object* obj) Real dist = GameLogicRandomValueReal( minRadius, maxRadius ); Coord3D pos; - pos.x = dist * WWMath::Cos( angle ) + containerPos->x; - pos.y = dist * WWMath::Sin( angle ) + containerPos->y; + pos.x = dist * WWMath::CosTrig( angle ) + containerPos->x; + pos.y = dist * WWMath::SinTrig( angle ) + containerPos->y; pos.z = TheTerrainLogic->getGroundHeight( pos.x, pos.y ); // set orientation diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp index a0228b2d170..697eabd8c7d 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp @@ -869,8 +869,8 @@ void Locomotor::locoUpdate_moveTowardsAngle(Object* obj, Real goalAngle) { // can't stay in one place; move in the desired direction at min speed. Coord3D desiredPos = *obj->getPosition(); - desiredPos.x += WWMath::Cos(goalAngle) * minSpeed * 2; - desiredPos.y += WWMath::Sin(goalAngle) * minSpeed * 2; + desiredPos.x += WWMath::CosTrig(goalAngle) * minSpeed * 2; + desiredPos.y += WWMath::SinTrig(goalAngle) * minSpeed * 2; // pass a huge num for "dist to goal", so that we don't think we're nearing // our destination and thus slow down... const Real onPathDistToGoal = 99999.0f; @@ -884,8 +884,8 @@ void Locomotor::locoUpdate_moveTowardsAngle(Object* obj, Real goalAngle) { DEBUG_ASSERTCRASH(m_template->m_appearance != LOCO_THRUST, ("THRUST should always have minspeeds!")); Coord3D desiredPos = *obj->getPosition(); - desiredPos.x += WWMath::Cos(goalAngle) * 1000.0f; - desiredPos.y += WWMath::Sin(goalAngle) * 1000.0f; + desiredPos.x += WWMath::CosTrig(goalAngle) * 1000.0f; + desiredPos.y += WWMath::SinTrig(goalAngle) * 1000.0f; PhysicsTurningType rotating = rotateTowardsPosition(obj, desiredPos); physics->setTurning(rotating); handleBehaviorZ(obj, physics, *obj->getPosition()); @@ -1341,8 +1341,8 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, targetAngle += turnAmount; } Coord3D offset; - offset.x = WWMath::Cos(targetAngle)*distance; - offset.y = WWMath::Sin(targetAngle)*distance; + offset.x = WWMath::CosTrig(targetAngle)*distance; + offset.y = WWMath::SinTrig(targetAngle)*distance; offset.z = 0; const Coord3D* pos = obj->getPosition(); @@ -1831,8 +1831,8 @@ void Locomotor::moveTowardsPositionWings(Object* obj, PhysicsBehavior *physics, // project a spot "radius" dist away from it, in that dir Coord3D desiredPos = goalPos; - desiredPos.x += WWMath::Cos(angleTowardPos) * turnRadius; - desiredPos.y += WWMath::Sin(angleTowardPos) * turnRadius; + desiredPos.x += WWMath::CosTrig(angleTowardPos) * turnRadius; + desiredPos.y += WWMath::SinTrig(angleTowardPos) * turnRadius; moveTowardsPositionOther(obj, physics, desiredPos, 0, desiredSpeed); return; } @@ -2132,8 +2132,8 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 #if 0 Coord3D desiredPos = *obj->getPosition(); // well, desired Dir, anyway - desiredPos.x += WWMath::Cos(angle + amount) * radius; - desiredPos.y += WWMath::Sin(angle + amount) * radius; + desiredPos.x += WWMath::CosTrig(angle + amount) * radius; + desiredPos.y += WWMath::SinTrig(angle + amount) * radius; // so, the thing is, we want to rotate ourselves so that our *center* is rotated @@ -2500,8 +2500,8 @@ void Locomotor::maintainCurrentPositionWings(Object* obj, PhysicsBehavior *physi // project a spot "radius" dist away from it, in that dir Coord3D desiredPos = m_maintainPos; - desiredPos.x += WWMath::Cos(angleTowardMaintainPos) * turnRadius; - desiredPos.y += WWMath::Sin(angleTowardMaintainPos) * turnRadius; + desiredPos.x += WWMath::CosTrig(angleTowardMaintainPos) * turnRadius; + desiredPos.y += WWMath::SinTrig(angleTowardMaintainPos) * turnRadius; moveTowardsPositionWings(obj, physics, desiredPos, 0, m_template->m_minSpeed); } } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp index 9e3c4f522f4..d493afe4066 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp @@ -289,14 +289,14 @@ class DeliverPayloadNugget : public ObjectCreationNugget //Rotate 90 degrees CCW. Real radians = 90.0f * PI / 180.0f; - Real s = WWMath::Sin( radians ); - Real c = WWMath::Cos( radians ); + Real s = WWMath::SinTrig( radians ); + Real c = WWMath::CosTrig( radians ); CCWx = dx * c + dy * -s + dx; CCWy = dx * s + dy * c + dy; //Rotate 90 degrees CW - s = WWMath::Sin( -radians ); - c = WWMath::Cos( -radians ); + s = WWMath::SinTrig( -radians ); + c = WWMath::CosTrig( -radians ); CWx = dx * c + dy * -s + dx; CWy = dx * s + dy * c + dy; } @@ -343,8 +343,8 @@ class DeliverPayloadNugget : public ObjectCreationNugget { Real randomRadius = GameLogicRandomValueReal(0, m_errorRadius ); Real randomAngle = GameLogicRandomValueReal(0, PI*2 ); - targetPos.x += randomRadius * WWMath::Cos( randomAngle ); - targetPos.y += randomRadius * WWMath::Sin( randomAngle ); + targetPos.x += randomRadius * WWMath::CosTrig( randomAngle ); + targetPos.y += randomRadius * WWMath::SinTrig( randomAngle ); } @@ -352,8 +352,8 @@ class DeliverPayloadNugget : public ObjectCreationNugget if( m_data.m_distToTarget > 0 ) { const Real SLOP = 1.5f; - startPos.x -= WWMath::Cos(orient) * m_data.m_distToTarget * SLOP; - startPos.y -= WWMath::Sin(orient) * m_data.m_distToTarget * SLOP; + startPos.x -= WWMath::CosTrig(orient) * m_data.m_distToTarget * SLOP; + startPos.y -= WWMath::SinTrig(orient) * m_data.m_distToTarget * SLOP; } Object *transport; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp index a76bde40fd8..74d9f414aac 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp @@ -401,8 +401,8 @@ static void testRotatedPointsAgainstRect( Real major = a->geom.getMajorRadius(); Real minor = (a->geom.getGeomType() == GEOMETRY_SPHERE) ? a->geom.getMajorRadius() : a->geom.getMinorRadius(); - Real c = (Real)WWMath::Cos(-a->angle); - Real s = (Real)WWMath::Sin(-a->angle); + Real c = (Real)WWMath::CosTrig(-a->angle); + Real s = (Real)WWMath::SinTrig(-a->angle); for (Int i = 0; i < 4; ++i, ++pts) { @@ -435,8 +435,8 @@ static void rectToFourPoints( Coord2D pts[] ) { - Real c = (Real)WWMath::Cos(a->angle); - Real s = (Real)WWMath::Sin(a->angle); + Real c = (Real)WWMath::CosTrig(a->angle); + Real s = (Real)WWMath::SinTrig(a->angle); Real exc = a->geom.getMajorRadius()*c; Real eyc = a->geom.getMinorRadius()*c; @@ -1774,8 +1774,8 @@ void PartitionData::doRectFill( Real angle ) { - Real c = (Real)WWMath::Cos(angle); - Real s = (Real)WWMath::Sin(angle); + Real c = (Real)WWMath::CosTrig(angle); + Real s = (Real)WWMath::SinTrig(angle); Real actualCellSize = ThePartitionManager->getCellSize(); Real stepSize = actualCellSize * 0.5f; // in theory, should be getCellSize() exactly, but needs to be smaller to avoid aliasing problems @@ -3785,8 +3785,8 @@ Bool PartitionManager::tryPosition( const Coord3D *center, // compute the spot on the terrain we've picked Coord3D pos; - pos.x = dist * WWMath::Cos( angle ) + center->x; - pos.y = dist * WWMath::Sin( angle ) + center->y; + pos.x = dist * WWMath::CosTrig( angle ) + center->x; + pos.y = dist * WWMath::SinTrig( angle ) + center->y; PathfindLayerEnum layer = LAYER_GROUND; if ((options->flags & FPF_USE_HIGHEST_LAYER) != 0) diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp index 3167b261d19..4bb1a02e6d1 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp @@ -398,10 +398,10 @@ static Bool intersectInfiniteLine2D Real& ix, Real& iy ) { - Real bx = ax + WWMath::Cos(ao); - Real by = ay + WWMath::Sin(ao); - Real dx = cx + WWMath::Cos(co); - Real dy = cy + WWMath::Sin(co); + Real bx = ax + WWMath::CosTrig(ao); + Real by = ay + WWMath::SinTrig(ao); + Real dx = cx + WWMath::CosTrig(co); + Real dy = cy + WWMath::SinTrig(co); Real denom = ((bx - ax) * (dy - cy) - (by - ay) * (dx - cx)); if (denom == 0.0f) @@ -2062,8 +2062,8 @@ void JetAIUpdate::positionLockon() Real dist = finalDist + (d->m_lockonInitialDist - finalDist) * frac; Real angle = d->m_lockonAngleSpin * frac; - pos.x += WWMath::Cos(angle) * dist; - pos.y += WWMath::Sin(angle) * dist; + pos.x += WWMath::CosTrig(angle) * dist; + pos.y += WWMath::SinTrig(angle) * dist; // pos.z is untouched m_lockonDrawable->setPosition(&pos); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp index 7f1017e4f71..f957460fcc0 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp @@ -1184,8 +1184,8 @@ void alignToTerrain( Real angle, const Coord3D& pos, const Coord3D& normal, Matr z = normal; - x.x = WWMath::Cos( angle ); - x.y = WWMath::Sin( angle ); + x.x = WWMath::CosTrig( angle ); + x.y = WWMath::SinTrig( angle ); x.z = 0.0f; if (z.z != 0.0f) { diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp index de00790d071..43823442874 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp @@ -166,8 +166,8 @@ void DynamicShroudClearingRangeUpdate::animateGridDecals() for (int d = 0; d < GRID_FX_DECAL_COUNT; ++d) { - pos.x = ctr->x + (WWMath::Sin(angle) * radius); - pos.y = ctr->y + (WWMath::Cos(angle) * radius); + pos.x = ctr->x + (WWMath::SinTrig(angle) * radius); + pos.y = ctr->y + (WWMath::CosTrig(angle) * radius); pos.x -= ((Int)pos.x)%23; pos.y -= ((Int)pos.y)%23; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp index 40d350662bd..85362f8bc63 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp @@ -119,8 +119,8 @@ UpdateSleepTime FloatUpdate::update() { Real angle = INT_TO_REAL(TheGameLogic->getFrame()); - Real yaw = WWMath::Sin(angle * 0.0291f) * 0.05f; - Real pitch = WWMath::Sin(angle * 0.0515f) * 0.05f; + Real yaw = WWMath::SinTrig(angle * 0.0291f) * 0.05f; + Real pitch = WWMath::SinTrig(angle * 0.0515f) * 0.05f; Matrix3D mx = *draw->getInstanceMatrix(); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp index ff3fe318c54..c9caabae992 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp @@ -359,8 +359,8 @@ UpdateSleepTime HelicopterSlowDeathBehavior::update() // is *NOT* the angle the object is facing // Coord3D force; - force.x = DOUBLE_TO_REAL( WWMath::Cos( m_forwardAngle ) ) * m_forwardSpeed; - force.y = DOUBLE_TO_REAL( WWMath::Sin( m_forwardAngle ) ) * m_forwardSpeed; + force.x = DOUBLE_TO_REAL( WWMath::CosTrig( m_forwardAngle ) ) * m_forwardSpeed; + force.y = DOUBLE_TO_REAL( WWMath::SinTrig( m_forwardAngle ) ) * m_forwardSpeed; force.z = 0.0f; physics->applyMotiveForce( &force ); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/MobMemberSlavedUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/MobMemberSlavedUpdate.cpp index f9993a26350..28906a069e0 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/MobMemberSlavedUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/MobMemberSlavedUpdate.cpp @@ -358,8 +358,8 @@ void MobMemberSlavedUpdate::doCatchUpLogic( Coord3D *pos ) Real randomDirection = GameLogicRandomValue( 0, 2*PI ); Real randomRadius = GameLogicRandomValue( 0, data->m_noNeedToCatchUpRadius ); nuPos.set(pos); - nuPos.x += randomRadius * WWMath::Cos( randomDirection ); - nuPos.y += randomRadius * WWMath::Sin( randomDirection ); + nuPos.x += randomRadius * WWMath::CosTrig( randomDirection ); + nuPos.y += randomRadius * WWMath::SinTrig( randomDirection ); nuPos.z = TheTerrainLogic->getGroundHeight( nuPos.x, nuPos.y ); AIUpdateInterface *ai = getObject()->getAIUpdateInterface(); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp index 3b032a6431a..b0a1ba18fb4 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp @@ -474,12 +474,12 @@ UpdateSleepTime ParticleUplinkCannonUpdate::update() //First determine the factor of time completed (ranges between 0.0 and 1.0) Real factor = (Real)(now - orbitalBirthFrame) / (Real)(orbitalDeathFrame - orbitalBirthFrame); - //We're generating a swath that travels the points between WWMath::Sin( -1PI ) and WWMath::Sin( 1PI ) + //We're generating a swath that travels the points between WWMath::SinTrig( -1PI ) and WWMath::SinTrig( 1PI ) Real radians = (factor * TWO_PI) - PI; Real cxDistance = (factor * data->m_swathOfDeathDistance ) - (data->m_swathOfDeathDistance * 0.5f); //cx is cartesian x //Now calculate the amplitude value. - Real height = WWMath::Sin( radians ); + Real height = WWMath::SinTrig( radians ); Real cxHeight = height * data->m_swathOfDeathAmplitude; Coord3D buildingToInitialTargetVector; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp index c99ed355c60..40f656815ef 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp @@ -639,7 +639,7 @@ UpdateSleepTime PhysicsBehavior::update() Real xy = WWMath::Sqrt(sqr(xvec.X) + sqr(xvec.Y)); Real pitchAngle = WWMath::Atan2(xvec.Z, xy); Real remainingAngle = (offset > 0) ? ((PI/2) - pitchAngle) : (-(PI/2) + pitchAngle); - Real s = WWMath::Sin(remainingAngle); + Real s = WWMath::SinTrig(remainingAngle); pitchRateToUse *= s; } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp index a0c6d3d8a1e..7d3427c2a48 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp @@ -314,8 +314,8 @@ void SlavedUpdate::doAttackLogic( const Object *target ) //Allow me to wander away from the pinnedPosition. Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.zero(); - m_guardPointOffset.x += data->m_attackWanderRange * WWMath::Cos( randomDirection ); - m_guardPointOffset.y += data->m_attackWanderRange * WWMath::Sin( randomDirection ); + m_guardPointOffset.x += data->m_attackWanderRange * WWMath::CosTrig( randomDirection ); + m_guardPointOffset.y += data->m_attackWanderRange * WWMath::SinTrig( randomDirection ); //Offset our pinned position by our random offset. attackPosition.x += m_guardPointOffset.x; @@ -377,8 +377,8 @@ void SlavedUpdate::doScoutLogic( const Coord3D *mastersDestination ) //Allow me to wander away from the pinnedPosition. Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.zero(); - m_guardPointOffset.x += data->m_scoutWanderRange * WWMath::Cos( randomDirection ); - m_guardPointOffset.y += data->m_scoutWanderRange * WWMath::Sin( randomDirection ); + m_guardPointOffset.x += data->m_scoutWanderRange * WWMath::CosTrig( randomDirection ); + m_guardPointOffset.y += data->m_scoutWanderRange * WWMath::SinTrig( randomDirection ); //Offset our pinned position by our random offset. scoutPosition.x += m_guardPointOffset.x; @@ -407,8 +407,8 @@ void SlavedUpdate::doGuardLogic( Coord3D *pinnedPosition ) // recalc where we want to be if we wander around Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.zero(); - m_guardPointOffset.x += data->m_guardMaxRange * WWMath::Cos( randomDirection ); - m_guardPointOffset.y += data->m_guardMaxRange * WWMath::Sin( randomDirection ); + m_guardPointOffset.x += data->m_guardMaxRange * WWMath::CosTrig( randomDirection ); + m_guardPointOffset.y += data->m_guardMaxRange * WWMath::SinTrig( randomDirection ); pinnedPosition->x += m_guardPointOffset.x; pinnedPosition->y += m_guardPointOffset.y; @@ -674,8 +674,8 @@ void SlavedUpdate::moveToNewRepairSpot() //Allow me to wander away from the pinnedPosition. Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.set( master->getPosition() ); - m_guardPointOffset.x += data->m_repairRange * WWMath::Cos( randomDirection ); - m_guardPointOffset.y += data->m_repairRange * WWMath::Sin( randomDirection ); + m_guardPointOffset.x += data->m_repairRange * WWMath::CosTrig( randomDirection ); + m_guardPointOffset.y += data->m_repairRange * WWMath::SinTrig( randomDirection ); m_guardPointOffset.z = TheTerrainLogic->getGroundHeight( m_guardPointOffset.x, m_guardPointOffset.y ); Real altitude = GameLogicRandomValueReal( data->m_repairMinAltitude, data->m_repairMaxAltitude ); m_guardPointOffset.z += altitude; @@ -708,8 +708,8 @@ void SlavedUpdate::startSlavedEffects( const Object *slaver ) // Decide where our pinned stray point is Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.zero(); - m_guardPointOffset.x += data->m_guardMaxRange * WWMath::Cos( randomDirection ); - m_guardPointOffset.y += data->m_guardMaxRange * WWMath::Sin( randomDirection ); + m_guardPointOffset.x += data->m_guardMaxRange * WWMath::CosTrig( randomDirection ); + m_guardPointOffset.y += data->m_guardMaxRange * WWMath::SinTrig( randomDirection ); // mark selves as not selectable getObject()->setStatus( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_UNSELECTABLE ) ); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp index ecbfc554e72..861b443b9be 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp @@ -425,7 +425,7 @@ UpdateSleepTime StealthUpdate::update() } else { - draw->setEffectiveOpacity( 0.5f + ( WWMath::Sin( m_pulsePhase ) * 0.5f ) ); + draw->setEffectiveOpacity( 0.5f + ( WWMath::SinTrig( m_pulsePhase ) * 0.5f ) ); // between one half and full opacity m_pulsePhase += m_pulsePhaseRate; } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StructureToppleUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StructureToppleUpdate.cpp index 9e09290c515..6d4dd6fca96 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StructureToppleUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StructureToppleUpdate.cpp @@ -158,15 +158,15 @@ void StructureToppleUpdate::beginStructureTopple(const DamageInfo *damageInfo) toppleAngle = m_toppleDirection.toAngle(); toppleAngle += GameLogicRandomValueReal(-PI/8, PI/8); } - m_toppleDirection.x = WWMath::Cos(toppleAngle); - m_toppleDirection.y = WWMath::Sin(toppleAngle); + m_toppleDirection.x = WWMath::CosTrig(toppleAngle); + m_toppleDirection.y = WWMath::SinTrig(toppleAngle); TheScriptEngine->adjustToppleDirection(getObject(), &m_toppleDirection); Real averageRadius = (building->getGeometryInfo().getMajorRadius() + building->getGeometryInfo().getMinorRadius()) / 2; Real explosionRadius = averageRadius * 0.90; - m_delayBurstLocation.x = building->getPosition()->x + explosionRadius * WWMath::Cos(toppleAngle); - m_delayBurstLocation.y = building->getPosition()->y + explosionRadius * WWMath::Sin(toppleAngle); + m_delayBurstLocation.x = building->getPosition()->x + explosionRadius * WWMath::CosTrig(toppleAngle); + m_delayBurstLocation.y = building->getPosition()->y + explosionRadius * WWMath::SinTrig(toppleAngle); m_delayBurstLocation.z = TheTerrainLogic->getGroundHeight(m_delayBurstLocation.x, m_delayBurstLocation.y); doToppleStartFX(building, damageInfo); @@ -231,7 +231,7 @@ UpdateSleepTime StructureToppleUpdate::update() // The building is in the process of falling over. if (m_toppleState == TOPPLESTATE_TOPPLING) { UnsignedInt now = TheGameLogic->getFrame(); - Real toppleAcceleration = TOPPLE_ACCELERATION_FACTOR * (WWMath::Sin(m_accumulatedAngle) * (1.0 - m_structuralIntegrity)); + Real toppleAcceleration = TOPPLE_ACCELERATION_FACTOR * (WWMath::SinTrig(m_accumulatedAngle) * (1.0 - m_structuralIntegrity)); // DEBUG_LOG(("toppleAcceleration = %f", toppleAcceleration)); m_toppleVelocity += toppleAcceleration; // DEBUG_LOG(("m_toppleVelocity = %f", m_toppleVelocity)); @@ -368,8 +368,8 @@ void StructureToppleUpdate::applyCrushingDamage(Real theta) // Do this because the amount of ground that is affected will be different if the building falls // in different orientations. Real angle = orientationAngle - toppleAngle; - Real minorComponent = building->getGeometryInfo().getMinorRadius() * WWMath::Cos(angle); - Real majorComponent = building->getGeometryInfo().getMajorRadius() * WWMath::Sin(angle); + Real minorComponent = building->getGeometryInfo().getMinorRadius() * WWMath::CosTrig(angle); + Real majorComponent = building->getGeometryInfo().getMajorRadius() * WWMath::SinTrig(angle); Coord3D temp3D; temp3D.x = majorComponent; @@ -385,7 +385,7 @@ void StructureToppleUpdate::applyCrushingDamage(Real theta) } // The furthest away from the base of the building to explode on. - Real maxDistance = m_buildingHeight * (1.0 - WWMath::Sin(theta)); + Real maxDistance = m_buildingHeight * (1.0 - WWMath::SinTrig(theta)); /* * Fire explosions at regular intervals across the area that the building is currently @@ -396,14 +396,14 @@ void StructureToppleUpdate::applyCrushingDamage(Real theta) // Coord3D target; Real j = m_lastCrushedLocation; for (; j < maxDistance; j += WEAPON_SPACING_PERPENDICULAR) { - jcos = j * WWMath::Cos(toppleAngle); - jsin = j * WWMath::Sin(toppleAngle); + jcos = j * WWMath::CosTrig(toppleAngle); + jsin = j * WWMath::SinTrig(toppleAngle); doDamageLine(building, wt, jcos, jsin, facingWidth, toppleAngle); } - jcos = maxDistance * WWMath::Cos(toppleAngle); - jsin = maxDistance * WWMath::Sin(toppleAngle); + jcos = maxDistance * WWMath::CosTrig(toppleAngle); + jsin = maxDistance * WWMath::SinTrig(toppleAngle); doDamageLine(building, wt, jcos, jsin, facingWidth, toppleAngle); m_lastCrushedLocation = j; @@ -424,8 +424,8 @@ void StructureToppleUpdate::doDamageLine(Object *building, const WeaponTemplate* for (Real i = -facingWidth; i < facingWidth; i += WEAPON_SPACING_PARALLEL) { - target.x = building->getPosition()->x + jcos + (i * WWMath::Sin(toppleAngle)); - target.y = building->getPosition()->y + jsin + (i * WWMath::Cos(toppleAngle)); + target.x = building->getPosition()->x + jcos + (i * WWMath::SinTrig(toppleAngle)); + target.y = building->getPosition()->y + jsin + (i * WWMath::CosTrig(toppleAngle)); target.z = TheTerrainLogic->getGroundHeight(target.x, target.y); TheWeaponStore->createAndFireTempWeapon(wt, building, &target); @@ -436,8 +436,8 @@ void StructureToppleUpdate::doDamageLine(Object *building, const WeaponTemplate* } // Make sure there are weapons fired and FX done on the edge of the building. - target.x = building->getPosition()->x + jcos + (facingWidth * WWMath::Sin(toppleAngle)); - target.y = building->getPosition()->y + jsin + (facingWidth * WWMath::Cos(toppleAngle)); + target.x = building->getPosition()->x + jcos + (facingWidth * WWMath::SinTrig(toppleAngle)); + target.y = building->getPosition()->y + jsin + (facingWidth * WWMath::CosTrig(toppleAngle)); target.z = TheTerrainLogic->getGroundHeight(target.x, target.y); TheWeaponStore->createAndFireTempWeapon(wt, building, &target); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp index 3a6e483c428..860ae339cec 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp @@ -190,8 +190,8 @@ void ToppleUpdate::applyTopplingForce( const Coord3D* toppleDirection, Real topp { // it's a fence or such, and can only topple left or right, so pick the closest toppleAngle = angleClosestTo(curAngleX + PI/2, curAngleX - PI/2, toppleAngle); - m_toppleDirection.x = WWMath::Cos(toppleAngle); - m_toppleDirection.y = WWMath::Sin(toppleAngle); + m_toppleDirection.x = WWMath::CosTrig(toppleAngle); + m_toppleDirection.y = WWMath::SinTrig(toppleAngle); // go ahead and remove it from the pathfinder now, rather than waiting for the topple to // finish.... since we might be in a slightly different position when toppled, which can diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/WaveGuideUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/WaveGuideUpdate.cpp index 7cd29e289c9..2ae049b6bc6 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/WaveGuideUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/WaveGuideUpdate.cpp @@ -718,8 +718,8 @@ void WaveGuideUpdate::doDamage() // angle is rotated, because we computed from 'from' and 'to' points of // the bridge going *across* the valley, not pointing *down* it // - u.x = WWMath::Cos( angle + modData->m_bridgeParticleAngleFudge ); - u.y = WWMath::Sin( angle + modData->m_bridgeParticleAngleFudge ); + u.x = WWMath::CosTrig( angle + modData->m_bridgeParticleAngleFudge ); + u.y = WWMath::SinTrig( angle + modData->m_bridgeParticleAngleFudge ); u.z = 0.0f; y.crossProduct( &z, &u, &y ); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp index a6a1efd88da..404069b1fce 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp @@ -1051,8 +1051,8 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate Coord3D firingOffset; firingOffset.zero(); - firingOffset.x = scatterRadius * WWMath::Cos( scatterAngleRadian ); - firingOffset.y = scatterRadius * WWMath::Sin( scatterAngleRadian ); + firingOffset.x = scatterRadius * WWMath::CosTrig( scatterAngleRadian ); + firingOffset.y = scatterRadius * WWMath::SinTrig( scatterAngleRadian ); projectileDestination.x += firingOffset.x; projectileDestination.y += firingOffset.y; @@ -1934,8 +1934,8 @@ Bool Weapon::computeApproachTarget(const Object *source, const Object *target, c if (angleOffset != 0.0f) { Real angle = WWMath::Atan2(dir.y, dir.x); - dir.x = (Real)WWMath::Cos(angle + angleOffset); - dir.y = (Real)WWMath::Sin(angle + angleOffset); + dir.x = (Real)WWMath::CosTrig(angle + angleOffset); + dir.y = (Real)WWMath::SinTrig(angle + angleOffset); } // select a spot along the line between us, halfway between the min & max range. @@ -1981,8 +1981,8 @@ Bool Weapon::computeApproachTarget(const Object *source, const Object *target, c if (angleOffset != 0.0f) { Real angle = WWMath::Atan2(dir.y, dir.x); - dir.x = (Real)WWMath::Cos(angle + angleOffset); - dir.y = (Real)WWMath::Sin(angle + angleOffset); + dir.x = (Real)WWMath::CosTrig(angle + angleOffset); + dir.y = (Real)WWMath::SinTrig(angle + angleOffset); } // select a spot along the line between us, in range of our weapon diff --git a/Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp b/Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp index c7991dc7827..cc9783611da 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp @@ -4584,8 +4584,8 @@ void ScriptEngine::reset() } m_breezeInfo.m_direction = PI/3; - m_breezeInfo.m_directionVec.x = WWMath::Sin(m_breezeInfo.m_direction); - m_breezeInfo.m_directionVec.y = WWMath::Cos(m_breezeInfo.m_direction); + m_breezeInfo.m_directionVec.x = WWMath::SinTrig(m_breezeInfo.m_direction); + m_breezeInfo.m_directionVec.y = WWMath::CosTrig(m_breezeInfo.m_direction); m_breezeInfo.m_intensity = 0.07f*PI/4; m_breezeInfo.m_lean = 0.07f*PI/4; m_breezeInfo.m_breezePeriod = LOGICFRAMES_PER_SECOND * 5; @@ -5707,8 +5707,8 @@ void ScriptEngine::setSway( ScriptAction *pAction ) DEBUG_ASSERTCRASH(pAction->getNumParameters() >= 5, ("Not enough parameters.")); ++m_breezeInfo.m_breezeVersion; m_breezeInfo.m_direction = pAction->getParameter(0)->getReal(); - m_breezeInfo.m_directionVec.x = WWMath::Sin(m_breezeInfo.m_direction); - m_breezeInfo.m_directionVec.y = WWMath::Cos(m_breezeInfo.m_direction); + m_breezeInfo.m_directionVec.x = WWMath::SinTrig(m_breezeInfo.m_direction); + m_breezeInfo.m_directionVec.y = WWMath::CosTrig(m_breezeInfo.m_direction); m_breezeInfo.m_intensity = pAction->getParameter(1)->getReal(); m_breezeInfo.m_lean = pAction->getParameter(2)->getReal(); m_breezeInfo.m_breezePeriod = pAction->getParameter(3)->getInt(); diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp index de84802f788..bede536e6f5 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp @@ -808,8 +808,8 @@ LegalBuildCode BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos if (myFactoryExitWidth>0) { myExitPos = *worldPos; checkMyExit = true; - Real c = WWMath::Cos(angle); - Real s = WWMath::Sin(angle); + Real c = WWMath::CosTrig(angle); + Real s = WWMath::SinTrig(angle); Real offset = build->getTemplateGeometryInfo().getMajorRadius() + myFactoryExitWidth/2.0f; myExitPos.x += c*offset; myExitPos.y += s*offset; @@ -856,8 +856,8 @@ LegalBuildCode BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos if (themFactoryExitWidth>0) { hisExitPos = *them->getPosition(); checkHisExit = true; - Real c = WWMath::Cos(them->getOrientation()); - Real s = WWMath::Sin(them->getOrientation()); + Real c = WWMath::CosTrig(them->getOrientation()); + Real s = WWMath::SinTrig(them->getOrientation()); Real offset = them->getGeometryInfo().getMajorRadius() + themFactoryExitWidth/2.0f; hisExitPos.x += c*offset; hisExitPos.y += s*offset; diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/Geometry.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/Geometry.cpp index d9e1a4a430c..11c844e6209 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/Geometry.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/Geometry.cpp @@ -280,8 +280,8 @@ void GeometryInfo::get2DBounds(const Coord3D& geomCenter, Real angle, Region2D& case GEOMETRY_BOX: { - Real c = WWMath::Cos(angle); - Real s = WWMath::Sin(angle); + Real c = WWMath::CosTrig(angle); + Real s = WWMath::SinTrig(angle); Real exc = m_majorRadius*c; Real eyc = m_minorRadius*c; Real exs = m_majorRadius*s; @@ -399,8 +399,8 @@ void GeometryInfo::makeRandomOffsetWithinFootprint(Coord3D& pt) const #else Real radius = GameLogicRandomValueReal(0.0f, m_boundingCircleRadius); Real angle = GameLogicRandomValueReal(-PI, PI); - pt.x = radius * WWMath::Cos(angle); - pt.y = radius * WWMath::Sin(angle); + pt.x = radius * WWMath::CosTrig(angle); + pt.y = radius * WWMath::SinTrig(angle); pt.z = 0.0f; #endif break; diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Thing/Thing.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Thing/Thing.cpp index db0544ce041..50ec76e752f 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/Thing/Thing.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/Thing/Thing.cpp @@ -109,8 +109,8 @@ const Coord3D* Thing::getUnitDirectionVector2D() const if (!(m_cacheFlags & VALID_DIRVECTOR)) { Real angle = getOrientation(); - m_cachedDirVector.x = WWMath::Cos( angle ); - m_cachedDirVector.y = WWMath::Sin( angle ); + m_cachedDirVector.x = WWMath::CosTrig( angle ); + m_cachedDirVector.y = WWMath::SinTrig( angle ); m_cachedDirVector.z = 0; m_cacheFlags |= VALID_DIRVECTOR; } @@ -229,8 +229,8 @@ void Thing::setOrientation( Real angle ) z.y = 0.0f; z.z = 1.0f; - u.x = WWMath::Cos(angle); - u.y = WWMath::Sin(angle); + u.x = WWMath::CosTrig(angle); + u.y = WWMath::SinTrig(angle); u.z = 0.0f; y.crossProduct( &z, &u, &y ); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp index bdcb0023bfe..fac9a55a86a 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp @@ -1884,8 +1884,8 @@ void getHelicopterOffset( Coord3D& posOut, Int idx ) } Coord3D tempCtr = posOut; - posOut.x = tempCtr.x + (WWMath::Sin(angle) * radius); - posOut.y = tempCtr.y + (WWMath::Cos(angle) * radius); + posOut.x = tempCtr.x + (WWMath::SinTrig(angle) * radius); + posOut.y = tempCtr.y + (WWMath::CosTrig(angle) * radius); } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp index c3727c08ad6..10b9b113fb7 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp @@ -673,8 +673,8 @@ void AISkirmishPlayer::buildAIBaseDefenseStructure(const AsciiString &thingName, } if (angle > PI/3) break; - Real s = WWMath::Sin(angle); - Real c = WWMath::Cos(angle); + Real s = WWMath::SinTrig(angle); + Real c = WWMath::CosTrig(angle); // TheSuperHackers @info helmutbuhler 21/04/2025 This debug mutates the code to become CRC incompatible #if defined(RTS_DEBUG) || !RETAIL_COMPATIBLE_CRC @@ -1039,8 +1039,8 @@ void AISkirmishPlayer::adjustBuildList(BuildListInfo *list) angle += 3*PI/4; - Real s = WWMath::Sin(angle); - Real c = WWMath::Cos(angle); + Real s = WWMath::SinTrig(angle); + Real c = WWMath::CosTrig(angle); cur = list; while (cur) { diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp index 337d0663abd..ca567913d1d 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp @@ -608,8 +608,8 @@ StateReturnType AIRappelState::update() bldg->getGeometryInfo().getBoundingCircleRadius()); Real angle = GameLogicRandomValueReal( PI, 2*PI );//Downish. Coord3D startPosition = *bldg->getPosition(); - startPosition.x += offset * WWMath::Cos( angle ); - startPosition.y += offset * WWMath::Sin( angle ); + startPosition.x += offset * WWMath::CosTrig( angle ); + startPosition.y += offset * WWMath::SinTrig( angle ); startPosition.z = TheTerrainLogic->getGroundHeight( startPosition.x, startPosition.y ); obj->setPosition( &startPosition ); @@ -3907,8 +3907,8 @@ void AIFollowWaypointPathState::computeGoal(Bool useGroupOffsets) dy = dest.y - m_priorWaypoint->getLocation()->y; angle = WWMath::Atan2(dy, dx); Real deltaAngle = angle - m_angle; - Real s = WWMath::Sin(deltaAngle); - Real c = WWMath::Cos(deltaAngle); + Real s = WWMath::SinTrig(deltaAngle); + Real c = WWMath::CosTrig(deltaAngle); Real x = m_groupOffset.x * c - m_groupOffset.y * s; Real y = m_groupOffset.y * c + m_groupOffset.x * s; m_groupOffset.x = x; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp index 95fa848361a..2cb9302f411 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp @@ -339,8 +339,8 @@ Bridge::Bridge(Object *bridgeObj) Real halfsizeY = bridgeObj->getGeometryInfo().getMinorRadius(); m_bridgeInfo.bridgeWidth = 2*halfsizeY; - Real c = (Real)WWMath::Cos(angle); - Real s = (Real)WWMath::Sin(angle); + Real c = (Real)WWMath::CosTrig(angle); + Real s = (Real)WWMath::SinTrig(angle); m_bridgeInfo.fromLeft.set(pos->x-halfsizeX*c-halfsizeY*s, pos->y + halfsizeY*c - halfsizeX*s, pos->z); m_bridgeInfo.toLeft.set(pos->x+halfsizeX*c-halfsizeY*s, pos->y + halfsizeY*c + halfsizeX*s, pos->z); @@ -1471,8 +1471,8 @@ void makeAlignToNormalMatrix( Real angle, const Coord3D& pos, const Coord3D& nor that WWMath::Atan2(xvec.y, xvec.x) == angle. So we must construct the matrix carefully to ensure this! */ - x.x = WWMath::Cos( angle ); - x.y = WWMath::Sin( angle ); + x.x = WWMath::CosTrig( angle ); + x.y = WWMath::SinTrig( angle ); x.z = 0.0f; //x.normalize(); -- redundant; is normalized by definition @@ -2652,8 +2652,8 @@ void TerrainLogic::flattenTerrain(Object *obj) Real halfsizeY = obj->getGeometryInfo().getMinorRadius(); - Real c = (Real)WWMath::Cos(angle); - Real s = (Real)WWMath::Sin(angle); + Real c = (Real)WWMath::CosTrig(angle); + Real s = (Real)WWMath::SinTrig(angle); Vector3 topLeft(pos->x-halfsizeX*c-halfsizeY*s, pos->y + halfsizeY*c - halfsizeX*s, 0); Vector3 topRight(pos->x+halfsizeX*c-halfsizeY*s, pos->y + halfsizeY*c + halfsizeX*s, 0); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp index 8e7b77e08c4..f4682aef1f0 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp @@ -228,10 +228,10 @@ static Bool calcTrajectory( // calc the horiz-speed & time for each. // note that time can only be negative for 90parkingSpace.x += parkingOffset * WWMath::Cos(ppi->m_orientation); - info->parkingSpace.y += parkingOffset * WWMath::Sin(ppi->m_orientation); + info->parkingSpace.x += parkingOffset * WWMath::CosTrig(ppi->m_orientation); + info->parkingSpace.y += parkingOffset * WWMath::SinTrig(ppi->m_orientation); } } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp index c315d227f5c..cde2478cf06 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp @@ -320,8 +320,8 @@ void GenerateMinefieldBehavior::placeMinesAroundCircle(const Coord3D& pos, Real for (Real angle = 0; angle < angleLim; angle += angleInc) { Coord3D pt; - pt.x = pos.x + radius * WWMath::Cos(angle); - pt.y = pos.y + radius * WWMath::Sin(angle); + pt.x = pos.x + radius * WWMath::CosTrig(angle); + pt.y = pos.y + radius * WWMath::SinTrig(angle); pt.z = TheTerrainLogic->getGroundHeight( pt.x, pt.y ); offsetBySmallRandomAmount(pt, mineJitter); placeMineAt(pt, mineTemplate, team, obj); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp index 13c7bcb134a..2d74564acd5 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp @@ -354,8 +354,8 @@ Bool ParkingPlaceBehavior::reserveSpace(ObjectID id, Real parkingOffset, Parking calcPPInfo( id, info ); if (parkingOffset != 0.0f) { - info->parkingSpace.x += parkingOffset * WWMath::Cos(ppi->m_orientation); - info->parkingSpace.y += parkingOffset * WWMath::Sin(ppi->m_orientation); + info->parkingSpace.x += parkingOffset * WWMath::CosTrig(ppi->m_orientation); + info->parkingSpace.y += parkingOffset * WWMath::SinTrig(ppi->m_orientation); } } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/GarrisonContain.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/GarrisonContain.cpp index d4be8aff3c9..97059cb4d16 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/GarrisonContain.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/GarrisonContain.cpp @@ -1516,11 +1516,11 @@ void GarrisonContain::exitObjectViaDoor( Object *exitObj, ExitDoorType exitDoor if (loco && !TheAI->pathfinder()->validMovementTerrain( LAYER_GROUND, loco, &startPosition)) { // try front & back. Real offset = getObject()->getGeometryInfo().getMajorRadius(); - startPosition.x -= offset*WWMath::Cos(exitAngle); - startPosition.y -= offset*WWMath::Sin(exitAngle); + startPosition.x -= offset*WWMath::CosTrig(exitAngle); + startPosition.y -= offset*WWMath::SinTrig(exitAngle); if (!TheAI->pathfinder()->validMovementTerrain(LAYER_GROUND, loco, &startPosition)) { - startPosition.x += 2*offset*WWMath::Cos(exitAngle); - startPosition.y += 2*offset*WWMath::Sin(exitAngle); + startPosition.x += 2*offset*WWMath::CosTrig(exitAngle); + startPosition.y += 2*offset*WWMath::SinTrig(exitAngle); if (!TheAI->pathfinder()->validMovementTerrain(LAYER_GROUND, loco, &startPosition)) { startPosition = *getObject()->getPosition(); } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp index 718a5526a67..9935e137d7d 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp @@ -737,8 +737,8 @@ void OpenContain::scatterToNearbyPosition(Object* rider) Real dist = GameLogicRandomValueReal( minRadius, maxRadius ); Coord3D pos; - pos.x = dist * WWMath::Cos( angle ) + containerPos->x; - pos.y = dist * WWMath::Sin( angle ) + containerPos->y; + pos.x = dist * WWMath::CosTrig( angle ) + containerPos->x; + pos.y = dist * WWMath::SinTrig( angle ) + containerPos->y; pos.z = TheTerrainLogic->getLayerHeight( pos.x, pos.y, theContainer->getLayer() ); // set orientation diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cpp index cfd93aec88c..1770947121a 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cpp @@ -372,8 +372,8 @@ void TunnelContain::scatterToNearbyPosition(Object* obj) Real dist = GameLogicRandomValueReal( minRadius, maxRadius ); Coord3D pos; - pos.x = dist * WWMath::Cos( angle ) + containerPos->x; - pos.y = dist * WWMath::Sin( angle ) + containerPos->y; + pos.x = dist * WWMath::CosTrig( angle ) + containerPos->x; + pos.y = dist * WWMath::SinTrig( angle ) + containerPos->y; pos.z = TheTerrainLogic->getGroundHeight( pos.x, pos.y ); // set orientation diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp index 1a04eaf0c13..6832834ceed 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp @@ -889,8 +889,8 @@ void Locomotor::locoUpdate_moveTowardsAngle(Object* obj, Real goalAngle) { // can't stay in one place; move in the desired direction at min speed. Coord3D desiredPos = *obj->getPosition(); - desiredPos.x += WWMath::Cos(goalAngle) * minSpeed * 2; - desiredPos.y += WWMath::Sin(goalAngle) * minSpeed * 2; + desiredPos.x += WWMath::CosTrig(goalAngle) * minSpeed * 2; + desiredPos.y += WWMath::SinTrig(goalAngle) * minSpeed * 2; // pass a huge num for "dist to goal", so that we don't think we're nearing // our destination and thus slow down... const Real onPathDistToGoal = 99999.0f; @@ -904,8 +904,8 @@ void Locomotor::locoUpdate_moveTowardsAngle(Object* obj, Real goalAngle) { DEBUG_ASSERTCRASH(m_template->m_appearance != LOCO_THRUST, ("THRUST should always have minspeeds!")); Coord3D desiredPos = *obj->getPosition(); - desiredPos.x += WWMath::Cos(goalAngle) * 1000.0f; - desiredPos.y += WWMath::Sin(goalAngle) * 1000.0f; + desiredPos.x += WWMath::CosTrig(goalAngle) * 1000.0f; + desiredPos.y += WWMath::SinTrig(goalAngle) * 1000.0f; PhysicsTurningType rotating = rotateTowardsPosition(obj, desiredPos); physics->setTurning(rotating); handleBehaviorZ(obj, physics, *obj->getPosition()); @@ -1373,8 +1373,8 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, targetAngle += turnAmount; } Coord3D offset; - offset.x = WWMath::Cos(targetAngle)*distance; - offset.y = WWMath::Sin(targetAngle)*distance; + offset.x = WWMath::CosTrig(targetAngle)*distance; + offset.y = WWMath::SinTrig(targetAngle)*distance; offset.z = 0; const Coord3D* pos = obj->getPosition(); @@ -1863,8 +1863,8 @@ void Locomotor::moveTowardsPositionWings(Object* obj, PhysicsBehavior *physics, // project a spot "radius" dist away from it, in that dir Coord3D desiredPos = goalPos; - desiredPos.x += WWMath::Cos(angleTowardPos) * turnRadius; - desiredPos.y += WWMath::Sin(angleTowardPos) * turnRadius; + desiredPos.x += WWMath::CosTrig(angleTowardPos) * turnRadius; + desiredPos.y += WWMath::SinTrig(angleTowardPos) * turnRadius; moveTowardsPositionOther(obj, physics, desiredPos, 0, desiredSpeed); return; } @@ -2164,8 +2164,8 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 #if 0 Coord3D desiredPos = *obj->getPosition(); // well, desired Dir, anyway - desiredPos.x += WWMath::Cos(angle + amount) * radius; - desiredPos.y += WWMath::Sin(angle + amount) * radius; + desiredPos.x += WWMath::CosTrig(angle + amount) * radius; + desiredPos.y += WWMath::SinTrig(angle + amount) * radius; // so, the thing is, we want to rotate ourselves so that our *center* is rotated @@ -2533,8 +2533,8 @@ void Locomotor::maintainCurrentPositionWings(Object* obj, PhysicsBehavior *physi // project a spot "radius" dist away from it, in that dir Coord3D desiredPos = m_maintainPos; - desiredPos.x += WWMath::Cos(angleTowardMaintainPos) * turnRadius; - desiredPos.y += WWMath::Sin(angleTowardMaintainPos) * turnRadius; + desiredPos.x += WWMath::CosTrig(angleTowardMaintainPos) * turnRadius; + desiredPos.y += WWMath::SinTrig(angleTowardMaintainPos) * turnRadius; moveTowardsPositionWings(obj, physics, desiredPos, 0, m_template->m_minSpeed); } } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp index 86baa2d1156..a6af6ae20f1 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp @@ -298,14 +298,14 @@ class DeliverPayloadNugget : public ObjectCreationNugget //Rotate 90 degrees CCW. Real radians = 90.0f * PI / 180.0f; - Real s = WWMath::Sin( radians ); - Real c = WWMath::Cos( radians ); + Real s = WWMath::SinTrig( radians ); + Real c = WWMath::CosTrig( radians ); CCWx = dx * c + dy * -s + dx; CCWy = dx * s + dy * c + dy; //Rotate 90 degrees CW - s = WWMath::Sin( -radians ); - c = WWMath::Cos( -radians ); + s = WWMath::SinTrig( -radians ); + c = WWMath::CosTrig( -radians ); CWx = dx * c + dy * -s + dx; CWy = dx * s + dy * c + dy; } @@ -352,8 +352,8 @@ class DeliverPayloadNugget : public ObjectCreationNugget { Real randomRadius = GameLogicRandomValueReal(0, m_errorRadius ); Real randomAngle = GameLogicRandomValueReal(0, PI*2 ); - targetPos.x += randomRadius * WWMath::Cos( randomAngle ); - targetPos.y += randomRadius * WWMath::Sin( randomAngle ); + targetPos.x += randomRadius * WWMath::CosTrig( randomAngle ); + targetPos.y += randomRadius * WWMath::SinTrig( randomAngle ); } @@ -361,8 +361,8 @@ class DeliverPayloadNugget : public ObjectCreationNugget if( m_data.m_distToTarget > 0 ) { const Real SLOP = 1.5f; - startPos.x -= WWMath::Cos(orient) * m_data.m_distToTarget * SLOP; - startPos.y -= WWMath::Sin(orient) * m_data.m_distToTarget * SLOP; + startPos.x -= WWMath::CosTrig(orient) * m_data.m_distToTarget * SLOP; + startPos.y -= WWMath::SinTrig(orient) * m_data.m_distToTarget * SLOP; } Object *transport; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp index 7807bf696e0..7be52d19a44 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp @@ -407,8 +407,8 @@ static void testRotatedPointsAgainstRect( Real major = a->geom.getMajorRadius(); Real minor = (a->geom.getGeomType() == GEOMETRY_SPHERE) ? a->geom.getMajorRadius() : a->geom.getMinorRadius(); - Real c = (Real)WWMath::Cos(-a->angle); - Real s = (Real)WWMath::Sin(-a->angle); + Real c = (Real)WWMath::CosTrig(-a->angle); + Real s = (Real)WWMath::SinTrig(-a->angle); for (Int i = 0; i < 4; ++i, ++pts) { @@ -441,8 +441,8 @@ static void rectToFourPoints( Coord2D pts[] ) { - Real c = (Real)WWMath::Cos(a->angle); - Real s = (Real)WWMath::Sin(a->angle); + Real c = (Real)WWMath::CosTrig(a->angle); + Real s = (Real)WWMath::SinTrig(a->angle); Real exc = a->geom.getMajorRadius()*c; Real eyc = a->geom.getMinorRadius()*c; @@ -1780,8 +1780,8 @@ void PartitionData::doRectFill( Real angle ) { - Real c = (Real)WWMath::Cos(angle); - Real s = (Real)WWMath::Sin(angle); + Real c = (Real)WWMath::CosTrig(angle); + Real s = (Real)WWMath::SinTrig(angle); Real actualCellSize = ThePartitionManager->getCellSize(); Real stepSize = actualCellSize * 0.5f; // in theory, should be getCellSize() exactly, but needs to be smaller to avoid aliasing problems @@ -3794,8 +3794,8 @@ Bool PartitionManager::tryPosition( const Coord3D *center, // compute the spot on the terrain we've picked Coord3D pos; - pos.x = dist * WWMath::Cos( angle ) + center->x; - pos.y = dist * WWMath::Sin( angle ) + center->y; + pos.x = dist * WWMath::CosTrig( angle ) + center->x; + pos.y = dist * WWMath::SinTrig( angle ) + center->y; PathfindLayerEnum layer = LAYER_GROUND; if ((options->flags & FPF_USE_HIGHEST_LAYER) != 0) diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp index 6e03d06e08a..54fab10ec06 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp @@ -447,10 +447,10 @@ static Bool intersectInfiniteLine2D Real& ix, Real& iy ) { - Real bx = ax + WWMath::Cos(ao); - Real by = ay + WWMath::Sin(ao); - Real dx = cx + WWMath::Cos(co); - Real dy = cy + WWMath::Sin(co); + Real bx = ax + WWMath::CosTrig(ao); + Real by = ay + WWMath::SinTrig(ao); + Real dx = cx + WWMath::CosTrig(co); + Real dy = cy + WWMath::SinTrig(co); Real denom = ((bx - ax) * (dy - cy) - (by - ay) * (dx - cx)); if (denom == 0.0f) @@ -2289,8 +2289,8 @@ void JetAIUpdate::positionLockon() Real dist = finalDist + (d->m_lockonInitialDist - finalDist) * frac; Real angle = d->m_lockonAngleSpin * frac; - pos.x += WWMath::Cos(angle) * dist; - pos.y += WWMath::Sin(angle) * dist; + pos.x += WWMath::CosTrig(angle) * dist; + pos.y += WWMath::SinTrig(angle) * dist; // pos.z is untouched m_lockonDrawable->setPosition(&pos); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp index b8fbf64a258..84b88e6ede7 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp @@ -1224,8 +1224,8 @@ void alignToTerrain( Real angle, const Coord3D& pos, const Coord3D& normal, Matr z = normal; - x.x = WWMath::Cos( angle ); - x.y = WWMath::Sin( angle ); + x.x = WWMath::CosTrig( angle ); + x.y = WWMath::SinTrig( angle ); x.z = 0.0f; if (z.z != 0.0f) { diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp index 2e1e69f7ae1..f361c955638 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp @@ -166,8 +166,8 @@ void DynamicShroudClearingRangeUpdate::animateGridDecals() for (int d = 0; d < GRID_FX_DECAL_COUNT; ++d) { - pos.x = ctr->x + (WWMath::Sin(angle) * radius); - pos.y = ctr->y + (WWMath::Cos(angle) * radius); + pos.x = ctr->x + (WWMath::SinTrig(angle) * radius); + pos.y = ctr->y + (WWMath::CosTrig(angle) * radius); pos.x -= ((Int)pos.x)%23; pos.y -= ((Int)pos.y)%23; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp index 0fd8ed5c2c3..9151d70ed42 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp @@ -119,8 +119,8 @@ UpdateSleepTime FloatUpdate::update() { Real angle = INT_TO_REAL(TheGameLogic->getFrame()); - Real yaw = WWMath::Sin(angle * 0.0291f) * 0.05f; - Real pitch = WWMath::Sin(angle * 0.0515f) * 0.05f; + Real yaw = WWMath::SinTrig(angle * 0.0291f) * 0.05f; + Real pitch = WWMath::SinTrig(angle * 0.0515f) * 0.05f; Matrix3D mx = *draw->getInstanceMatrix(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp index 9084db01141..07cb00b98f7 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp @@ -359,8 +359,8 @@ UpdateSleepTime HelicopterSlowDeathBehavior::update() // is *NOT* the angle the object is facing // Coord3D force; - force.x = DOUBLE_TO_REAL( WWMath::Cos( m_forwardAngle ) ) * m_forwardSpeed; - force.y = DOUBLE_TO_REAL( WWMath::Sin( m_forwardAngle ) ) * m_forwardSpeed; + force.x = DOUBLE_TO_REAL( WWMath::CosTrig( m_forwardAngle ) ) * m_forwardSpeed; + force.y = DOUBLE_TO_REAL( WWMath::SinTrig( m_forwardAngle ) ) * m_forwardSpeed; force.z = 0.0f; physics->applyMotiveForce( &force ); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/MobMemberSlavedUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/MobMemberSlavedUpdate.cpp index 02c741f8544..95137d7f71b 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/MobMemberSlavedUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/MobMemberSlavedUpdate.cpp @@ -358,8 +358,8 @@ void MobMemberSlavedUpdate::doCatchUpLogic( Coord3D *pos ) Real randomDirection = GameLogicRandomValue( 0, 2*PI ); Real randomRadius = GameLogicRandomValue( 0, data->m_noNeedToCatchUpRadius ); nuPos.set(pos); - nuPos.x += randomRadius * WWMath::Cos( randomDirection ); - nuPos.y += randomRadius * WWMath::Sin( randomDirection ); + nuPos.x += randomRadius * WWMath::CosTrig( randomDirection ); + nuPos.y += randomRadius * WWMath::SinTrig( randomDirection ); nuPos.z = TheTerrainLogic->getGroundHeight( nuPos.x, nuPos.y ); AIUpdateInterface *ai = getObject()->getAIUpdateInterface(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp index 8e7f043494a..0b2819bd03a 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp @@ -526,12 +526,12 @@ UpdateSleepTime ParticleUplinkCannonUpdate::update() //First determine the factor of time completed (ranges between 0.0 and 1.0) Real factor = (Real)(now - orbitalBirthFrame) / (Real)(orbitalDeathFrame - orbitalBirthFrame); - //We're generating a swath that travels the points between WWMath::Sin( -1PI ) and WWMath::Sin( 1PI ) + //We're generating a swath that travels the points between WWMath::SinTrig( -1PI ) and WWMath::SinTrig( 1PI ) Real radians = (factor * TWO_PI) - PI; Real cxDistance = (factor * data->m_swathOfDeathDistance ) - (data->m_swathOfDeathDistance * 0.5f); //cx is cartesian x //Now calculate the amplitude value. - Real height = WWMath::Sin( radians ); + Real height = WWMath::SinTrig( radians ); Real cxHeight = height * data->m_swathOfDeathAmplitude; Coord3D buildingToInitialTargetVector; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp index 694330dbe77..3f1bffa2176 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp @@ -740,7 +740,7 @@ UpdateSleepTime PhysicsBehavior::update() Real xy = WWMath::Sqrt(sqr(xvec.X) + sqr(xvec.Y)); Real pitchAngle = WWMath::Atan2(xvec.Z, xy); Real remainingAngle = (offset > 0) ? ((PI/2) - pitchAngle) : (-(PI/2) + pitchAngle); - Real s = WWMath::Sin(remainingAngle); + Real s = WWMath::SinTrig(remainingAngle); pitchRateToUse *= s; } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp index 36c88c456d1..4c1abc6992c 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp @@ -319,8 +319,8 @@ void SlavedUpdate::doAttackLogic( const Object *target ) //Allow me to wander away from the pinnedPosition. Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.zero(); - m_guardPointOffset.x += data->m_attackWanderRange * WWMath::Cos( randomDirection ); - m_guardPointOffset.y += data->m_attackWanderRange * WWMath::Sin( randomDirection ); + m_guardPointOffset.x += data->m_attackWanderRange * WWMath::CosTrig( randomDirection ); + m_guardPointOffset.y += data->m_attackWanderRange * WWMath::SinTrig( randomDirection ); //Offset our pinned position by our random offset. attackPosition.x += m_guardPointOffset.x; @@ -382,8 +382,8 @@ void SlavedUpdate::doScoutLogic( const Coord3D *mastersDestination ) //Allow me to wander away from the pinnedPosition. Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.zero(); - m_guardPointOffset.x += data->m_scoutWanderRange * WWMath::Cos( randomDirection ); - m_guardPointOffset.y += data->m_scoutWanderRange * WWMath::Sin( randomDirection ); + m_guardPointOffset.x += data->m_scoutWanderRange * WWMath::CosTrig( randomDirection ); + m_guardPointOffset.y += data->m_scoutWanderRange * WWMath::SinTrig( randomDirection ); //Offset our pinned position by our random offset. scoutPosition.x += m_guardPointOffset.x; @@ -412,8 +412,8 @@ void SlavedUpdate::doGuardLogic( Coord3D *pinnedPosition ) // recalc where we want to be if we wander around Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.zero(); - m_guardPointOffset.x += data->m_guardMaxRange * WWMath::Cos( randomDirection ); - m_guardPointOffset.y += data->m_guardMaxRange * WWMath::Sin( randomDirection ); + m_guardPointOffset.x += data->m_guardMaxRange * WWMath::CosTrig( randomDirection ); + m_guardPointOffset.y += data->m_guardMaxRange * WWMath::SinTrig( randomDirection ); pinnedPosition->x += m_guardPointOffset.x; pinnedPosition->y += m_guardPointOffset.y; @@ -679,8 +679,8 @@ void SlavedUpdate::moveToNewRepairSpot() //Allow me to wander away from the pinnedPosition. Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.set( master->getPosition() ); - m_guardPointOffset.x += data->m_repairRange * WWMath::Cos( randomDirection ); - m_guardPointOffset.y += data->m_repairRange * WWMath::Sin( randomDirection ); + m_guardPointOffset.x += data->m_repairRange * WWMath::CosTrig( randomDirection ); + m_guardPointOffset.y += data->m_repairRange * WWMath::SinTrig( randomDirection ); m_guardPointOffset.z = TheTerrainLogic->getGroundHeight( m_guardPointOffset.x, m_guardPointOffset.y ); Real altitude = GameLogicRandomValueReal( data->m_repairMinAltitude, data->m_repairMaxAltitude ); m_guardPointOffset.z += altitude; @@ -713,8 +713,8 @@ void SlavedUpdate::startSlavedEffects( const Object *slaver ) // Decide where our pinned stray point is Real randomDirection = GameLogicRandomValue( 0, 2*PI ); m_guardPointOffset.zero(); - m_guardPointOffset.x += data->m_guardMaxRange * WWMath::Cos( randomDirection ); - m_guardPointOffset.y += data->m_guardMaxRange * WWMath::Sin( randomDirection ); + m_guardPointOffset.x += data->m_guardMaxRange * WWMath::CosTrig( randomDirection ); + m_guardPointOffset.y += data->m_guardMaxRange * WWMath::SinTrig( randomDirection ); // mark selves as not selectable getObject()->setStatus( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_UNSELECTABLE ) ); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp index aced9091a9b..5fafdd8e308 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp @@ -684,7 +684,7 @@ UpdateSleepTime StealthUpdate::update() } else { - draw->setEffectiveOpacity( 0.5f + ( WWMath::Sin( m_pulsePhase ) * 0.5f ) ); + draw->setEffectiveOpacity( 0.5f + ( WWMath::SinTrig( m_pulsePhase ) * 0.5f ) ); // between one half and full opacity m_pulsePhase += m_pulsePhaseRate; } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StructureToppleUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StructureToppleUpdate.cpp index 9d923dabc85..3c8b244130a 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StructureToppleUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StructureToppleUpdate.cpp @@ -158,15 +158,15 @@ void StructureToppleUpdate::beginStructureTopple(const DamageInfo *damageInfo) toppleAngle = m_toppleDirection.toAngle(); toppleAngle += GameLogicRandomValueReal(-PI/8, PI/8); } - m_toppleDirection.x = WWMath::Cos(toppleAngle); - m_toppleDirection.y = WWMath::Sin(toppleAngle); + m_toppleDirection.x = WWMath::CosTrig(toppleAngle); + m_toppleDirection.y = WWMath::SinTrig(toppleAngle); TheScriptEngine->adjustToppleDirection(getObject(), &m_toppleDirection); Real averageRadius = (building->getGeometryInfo().getMajorRadius() + building->getGeometryInfo().getMinorRadius()) / 2; Real explosionRadius = averageRadius * 0.90; - m_delayBurstLocation.x = building->getPosition()->x + explosionRadius * WWMath::Cos(toppleAngle); - m_delayBurstLocation.y = building->getPosition()->y + explosionRadius * WWMath::Sin(toppleAngle); + m_delayBurstLocation.x = building->getPosition()->x + explosionRadius * WWMath::CosTrig(toppleAngle); + m_delayBurstLocation.y = building->getPosition()->y + explosionRadius * WWMath::SinTrig(toppleAngle); m_delayBurstLocation.z = TheTerrainLogic->getGroundHeight(m_delayBurstLocation.x, m_delayBurstLocation.y); doToppleStartFX(building, damageInfo); @@ -231,7 +231,7 @@ UpdateSleepTime StructureToppleUpdate::update() // The building is in the process of falling over. if (m_toppleState == TOPPLESTATE_TOPPLING) { UnsignedInt now = TheGameLogic->getFrame(); - Real toppleAcceleration = TOPPLE_ACCELERATION_FACTOR * (WWMath::Sin(m_accumulatedAngle) * (1.0 - m_structuralIntegrity)); + Real toppleAcceleration = TOPPLE_ACCELERATION_FACTOR * (WWMath::SinTrig(m_accumulatedAngle) * (1.0 - m_structuralIntegrity)); // DEBUG_LOG(("toppleAcceleration = %f", toppleAcceleration)); m_toppleVelocity += toppleAcceleration; // DEBUG_LOG(("m_toppleVelocity = %f", m_toppleVelocity)); @@ -368,8 +368,8 @@ void StructureToppleUpdate::applyCrushingDamage(Real theta) // Do this because the amount of ground that is affected will be different if the building falls // in different orientations. Real angle = orientationAngle - toppleAngle; - Real minorComponent = building->getGeometryInfo().getMinorRadius() * WWMath::Cos(angle); - Real majorComponent = building->getGeometryInfo().getMajorRadius() * WWMath::Sin(angle); + Real minorComponent = building->getGeometryInfo().getMinorRadius() * WWMath::CosTrig(angle); + Real majorComponent = building->getGeometryInfo().getMajorRadius() * WWMath::SinTrig(angle); Coord3D temp3D; temp3D.x = majorComponent; @@ -385,7 +385,7 @@ void StructureToppleUpdate::applyCrushingDamage(Real theta) } // The furthest away from the base of the building to explode on. - Real maxDistance = m_buildingHeight * (1.0 - WWMath::Sin(theta)); + Real maxDistance = m_buildingHeight * (1.0 - WWMath::SinTrig(theta)); /* * Fire explosions at regular intervals across the area that the building is currently @@ -396,14 +396,14 @@ void StructureToppleUpdate::applyCrushingDamage(Real theta) // Coord3D target; Real j = m_lastCrushedLocation; for (; j < maxDistance; j += WEAPON_SPACING_PERPENDICULAR) { - jcos = j * WWMath::Cos(toppleAngle); - jsin = j * WWMath::Sin(toppleAngle); + jcos = j * WWMath::CosTrig(toppleAngle); + jsin = j * WWMath::SinTrig(toppleAngle); doDamageLine(building, wt, jcos, jsin, facingWidth, toppleAngle); } - jcos = maxDistance * WWMath::Cos(toppleAngle); - jsin = maxDistance * WWMath::Sin(toppleAngle); + jcos = maxDistance * WWMath::CosTrig(toppleAngle); + jsin = maxDistance * WWMath::SinTrig(toppleAngle); doDamageLine(building, wt, jcos, jsin, facingWidth, toppleAngle); m_lastCrushedLocation = j; @@ -424,8 +424,8 @@ void StructureToppleUpdate::doDamageLine(Object *building, const WeaponTemplate* for (Real i = -facingWidth; i < facingWidth; i += WEAPON_SPACING_PARALLEL) { - target.x = building->getPosition()->x + jcos + (i * WWMath::Sin(toppleAngle)); - target.y = building->getPosition()->y + jsin + (i * WWMath::Cos(toppleAngle)); + target.x = building->getPosition()->x + jcos + (i * WWMath::SinTrig(toppleAngle)); + target.y = building->getPosition()->y + jsin + (i * WWMath::CosTrig(toppleAngle)); target.z = TheTerrainLogic->getGroundHeight(target.x, target.y); TheWeaponStore->createAndFireTempWeapon(wt, building, &target); @@ -436,8 +436,8 @@ void StructureToppleUpdate::doDamageLine(Object *building, const WeaponTemplate* } // Make sure there are weapons fired and FX done on the edge of the building. - target.x = building->getPosition()->x + jcos + (facingWidth * WWMath::Sin(toppleAngle)); - target.y = building->getPosition()->y + jsin + (facingWidth * WWMath::Cos(toppleAngle)); + target.x = building->getPosition()->x + jcos + (facingWidth * WWMath::SinTrig(toppleAngle)); + target.y = building->getPosition()->y + jsin + (facingWidth * WWMath::CosTrig(toppleAngle)); target.z = TheTerrainLogic->getGroundHeight(target.x, target.y); TheWeaponStore->createAndFireTempWeapon(wt, building, &target); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp index 5f3e03b8379..df2e7c00512 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp @@ -190,8 +190,8 @@ void ToppleUpdate::applyTopplingForce( const Coord3D* toppleDirection, Real topp { // it's a fence or such, and can only topple left or right, so pick the closest toppleAngle = angleClosestTo(curAngleX + PI/2, curAngleX - PI/2, toppleAngle); - m_toppleDirection.x = WWMath::Cos(toppleAngle); - m_toppleDirection.y = WWMath::Sin(toppleAngle); + m_toppleDirection.x = WWMath::CosTrig(toppleAngle); + m_toppleDirection.y = WWMath::SinTrig(toppleAngle); // go ahead and remove it from the pathfinder now, rather than waiting for the topple to // finish.... since we might be in a slightly different position when toppled, which can diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/WaveGuideUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/WaveGuideUpdate.cpp index 8f45ef4c975..44b9b5bc424 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/WaveGuideUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/WaveGuideUpdate.cpp @@ -718,8 +718,8 @@ void WaveGuideUpdate::doDamage() // angle is rotated, because we computed from 'from' and 'to' points of // the bridge going *across* the valley, not pointing *down* it // - u.x = WWMath::Cos( angle + modData->m_bridgeParticleAngleFudge ); - u.y = WWMath::Sin( angle + modData->m_bridgeParticleAngleFudge ); + u.x = WWMath::CosTrig( angle + modData->m_bridgeParticleAngleFudge ); + u.y = WWMath::SinTrig( angle + modData->m_bridgeParticleAngleFudge ); u.z = 0.0f; y.crossProduct( &z, &u, &y ); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp index 39b34b10557..287199851e1 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp @@ -989,8 +989,8 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate Coord3D firingOffset; firingOffset.zero(); - firingOffset.x = scatterRadius * WWMath::Cos( scatterAngleRadian ); - firingOffset.y = scatterRadius * WWMath::Sin( scatterAngleRadian ); + firingOffset.x = scatterRadius * WWMath::CosTrig( scatterAngleRadian ); + firingOffset.y = scatterRadius * WWMath::SinTrig( scatterAngleRadian ); projectileDestination.x += firingOffset.x; projectileDestination.y += firingOffset.y; @@ -1491,7 +1491,7 @@ void WeaponTemplate::dealDamageInternal(ObjectID sourceID, ObjectID victimID, co // These are now normalized, so the dot productis actually the Cos of the angle they form // A smaller Cos would mean a more obtuse angle - if( Vector3::Dot_Product(sourceVector, damageVector) < WWMath::Cos(allowedAngle) ) + if( Vector3::Dot_Product(sourceVector, damageVector) < WWMath::CosTrig(allowedAngle) ) continue;// Too far to the side, can't hurt them. } @@ -2133,8 +2133,8 @@ Bool Weapon::computeApproachTarget(const Object *source, const Object *target, c if (angleOffset != 0.0f) { Real angle = WWMath::Atan2(dir.y, dir.x); - dir.x = (Real)WWMath::Cos(angle + angleOffset); - dir.y = (Real)WWMath::Sin(angle + angleOffset); + dir.x = (Real)WWMath::CosTrig(angle + angleOffset); + dir.y = (Real)WWMath::SinTrig(angle + angleOffset); } // select a spot along the line between us, halfway between the min & max range. @@ -2180,8 +2180,8 @@ Bool Weapon::computeApproachTarget(const Object *source, const Object *target, c if (angleOffset != 0.0f) { Real angle = WWMath::Atan2(dir.y, dir.x); - dir.x = (Real)WWMath::Cos(angle + angleOffset); - dir.y = (Real)WWMath::Sin(angle + angleOffset); + dir.x = (Real)WWMath::CosTrig(angle + angleOffset); + dir.y = (Real)WWMath::SinTrig(angle + angleOffset); } // select a spot along the line between us, in range of our weapon diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp index d6665912808..073b744b769 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp @@ -5299,8 +5299,8 @@ void ScriptEngine::reset() } m_breezeInfo.m_direction = PI/3; - m_breezeInfo.m_directionVec.x = WWMath::Sin(m_breezeInfo.m_direction); - m_breezeInfo.m_directionVec.y = WWMath::Cos(m_breezeInfo.m_direction); + m_breezeInfo.m_directionVec.x = WWMath::SinTrig(m_breezeInfo.m_direction); + m_breezeInfo.m_directionVec.y = WWMath::CosTrig(m_breezeInfo.m_direction); m_breezeInfo.m_intensity = 0.07f*PI/4; m_breezeInfo.m_lean = 0.07f*PI/4; m_breezeInfo.m_breezePeriod = LOGICFRAMES_PER_SECOND * 5; @@ -6408,8 +6408,8 @@ void ScriptEngine::setSway( ScriptAction *pAction ) DEBUG_ASSERTCRASH(pAction->getNumParameters() >= 5, ("Not enough parameters.")); ++m_breezeInfo.m_breezeVersion; m_breezeInfo.m_direction = pAction->getParameter(0)->getReal(); - m_breezeInfo.m_directionVec.x = WWMath::Sin(m_breezeInfo.m_direction); - m_breezeInfo.m_directionVec.y = WWMath::Cos(m_breezeInfo.m_direction); + m_breezeInfo.m_directionVec.x = WWMath::SinTrig(m_breezeInfo.m_direction); + m_breezeInfo.m_directionVec.y = WWMath::CosTrig(m_breezeInfo.m_direction); m_breezeInfo.m_intensity = pAction->getParameter(1)->getReal(); m_breezeInfo.m_lean = pAction->getParameter(2)->getReal(); m_breezeInfo.m_breezePeriod = pAction->getParameter(3)->getInt();