From d7bd992a258cb55fb748b2559eda01620fcf1447 Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Tue, 28 Apr 2026 17:50:11 +0300 Subject: [PATCH 1/9] feat(math): Add cross-platform deterministic math via GameMath (fdlibm) Integrate GameMath library (fdlibm) for bit-perfect cross-platform floating-point reproducibility. When USE_DETERMINISTIC_MATH is active, all WWMath functions (Sin, Cos, Sqrt, Inv_Sqrt, Float_To_Long, Acos, Asin, Atan, Atan2) use fdlibm instead of x87 asm or system CRT. - Add GameMath via FetchContent with global include paths - Replace Trig.cpp with inline WWMath::*Trig wrappers - Add WWMath::*Origin wrappers for bare CRT calls in game logic - Prioritize USE_DETERMINISTIC_MATH over _MSC_VER/_M_IX86 guards - Verified: win32 replay CRC matches original x87 output --- CMakeLists.txt | 3 + .../Common/Diagnostic/SimulationMathCrc.cpp | 8 +- Core/GameEngine/Source/Common/INI/INI.cpp | 4 +- .../Source/GameLogic/AI/AIPathfind.cpp | 32 ++--- .../Source/WWVegas/WWMath/CMakeLists.txt | 6 + Core/Libraries/Source/WWVegas/WWMath/wwmath.h | 123 +++++++++++++++++- .../GameEngine/Source/Common/RTS/Player.cpp | 2 +- .../Source/Common/System/BuildAssistant.cpp | 2 +- .../Source/Common/System/Geometry.cpp | 14 +- .../GameEngine/Source/Common/System/Trig.cpp | 111 ++-------------- .../GameEngine/Source/GameLogic/AI/AI.cpp | 2 +- .../Source/GameLogic/AI/AIPlayer.cpp | 10 +- .../Source/GameLogic/AI/AIStates.cpp | 14 +- .../Source/GameLogic/AI/TurretAI.cpp | 8 +- .../Source/GameLogic/Map/PolygonTrigger.cpp | 2 +- .../Source/GameLogic/Map/TerrainLogic.cpp | 28 ++-- .../Behavior/DumbProjectileBehavior.cpp | 18 +-- .../Behavior/GenerateMinefieldBehavior.cpp | 2 +- .../Object/Behavior/MinefieldBehavior.cpp | 8 +- .../Object/Behavior/SlowDeathBehavior.cpp | 2 +- .../Object/Contain/ParachuteContain.cpp | 2 +- .../Source/GameLogic/Object/Locomotor.cpp | 86 ++++++------ .../Source/GameLogic/Object/Object.cpp | 8 +- .../GameLogic/Object/ObjectCreationList.cpp | 8 +- .../GameLogic/Object/PartitionManager.cpp | 38 +++--- .../GameLogic/Object/Update/AIUpdate.cpp | 14 +- .../Update/AIUpdate/ChinookAIUpdate.cpp | 8 +- .../AIUpdate/DeliverPayloadAIUpdate.cpp | 8 +- .../Object/Update/AIUpdate/JetAIUpdate.cpp | 10 +- .../Update/AIUpdate/MissileAIUpdate.cpp | 4 +- .../Update/AIUpdate/POWTruckAIUpdate.cpp | 2 +- .../Update/AIUpdate/RailroadGuideAIUpdate.cpp | 12 +- .../Object/Update/CleanupHazardUpdate.cpp | 4 +- .../Object/Update/CommandButtonHuntUpdate.cpp | 2 +- .../DockUpdate/SupplyWarehouseDockUpdate.cpp | 4 +- .../Object/Update/NeutronMissileUpdate.cpp | 6 +- .../GameLogic/Object/Update/PhysicsUpdate.cpp | 38 +++--- .../Object/Update/PointDefenseLaserUpdate.cpp | 6 +- .../GameLogic/Object/Update/StealthUpdate.cpp | 2 +- .../Object/Update/TensileFormationUpdate.cpp | 2 +- .../GameLogic/Object/Update/ToppleUpdate.cpp | 8 +- .../Source/GameLogic/Object/Weapon.cpp | 18 +-- .../Source/GameLogic/System/GameLogic.cpp | 2 +- .../GameEngine/Source/Common/RTS/Player.cpp | 2 +- .../Source/Common/System/BuildAssistant.cpp | 2 +- .../Source/Common/System/Geometry.cpp | 14 +- .../GameEngine/Source/Common/System/Trig.cpp | 109 ++-------------- .../GameEngine/Source/GameLogic/AI/AI.cpp | 2 +- .../Source/GameLogic/AI/AIPlayer.cpp | 10 +- .../Source/GameLogic/AI/AIStates.cpp | 14 +- .../Source/GameLogic/AI/TurretAI.cpp | 8 +- .../Source/GameLogic/Map/PolygonTrigger.cpp | 2 +- .../Source/GameLogic/Map/TerrainLogic.cpp | 30 ++--- .../Behavior/DumbProjectileBehavior.cpp | 18 +-- .../Behavior/GenerateMinefieldBehavior.cpp | 2 +- .../Object/Behavior/MinefieldBehavior.cpp | 8 +- .../Object/Behavior/SlowDeathBehavior.cpp | 2 +- .../Object/Contain/ParachuteContain.cpp | 2 +- .../Source/GameLogic/Object/Locomotor.cpp | 86 ++++++------ .../Source/GameLogic/Object/Object.cpp | 8 +- .../GameLogic/Object/ObjectCreationList.cpp | 8 +- .../GameLogic/Object/PartitionManager.cpp | 38 +++--- .../GameLogic/Object/Update/AIUpdate.cpp | 14 +- .../Update/AIUpdate/ChinookAIUpdate.cpp | 6 +- .../AIUpdate/DeliverPayloadAIUpdate.cpp | 8 +- .../Object/Update/AIUpdate/JetAIUpdate.cpp | 10 +- .../Update/AIUpdate/MissileAIUpdate.cpp | 4 +- .../Update/AIUpdate/POWTruckAIUpdate.cpp | 2 +- .../Update/AIUpdate/RailroadGuideAIUpdate.cpp | 12 +- .../Object/Update/CleanupHazardUpdate.cpp | 4 +- .../Object/Update/CommandButtonHuntUpdate.cpp | 2 +- .../DockUpdate/SupplyWarehouseDockUpdate.cpp | 4 +- .../Object/Update/NeutronMissileUpdate.cpp | 6 +- .../GameLogic/Object/Update/PhysicsUpdate.cpp | 44 +++---- .../Object/Update/PointDefenseLaserUpdate.cpp | 6 +- .../Update/SpectreGunshipDeploymentUpdate.cpp | 2 +- .../GameLogic/Object/Update/StealthUpdate.cpp | 2 +- .../Object/Update/TensileFormationUpdate.cpp | 2 +- .../GameLogic/Object/Update/ToppleUpdate.cpp | 8 +- .../Source/GameLogic/Object/Weapon.cpp | 24 ++-- .../Source/GameLogic/System/GameLogic.cpp | 2 +- cmake/gamemath.cmake | 14 ++ 82 files changed, 596 insertions(+), 636 deletions(-) create mode 100644 cmake/gamemath.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 28ce09560e9..0e0c5afaeb2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,9 @@ endif() include(cmake/config.cmake) include(cmake/gamespy.cmake) +if (NOT IS_VS6_BUILD) + include(cmake/gamemath.cmake) +endif() include(cmake/lzhl.cmake) if (IS_VS6_BUILD) diff --git a/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp b/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp index 1b062f44e34..5245d7c01a2 100644 --- a/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp +++ b/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp @@ -42,12 +42,12 @@ static void appendSimulationMathCrc(XferCRC &xfer) tanf(0.3f), asinf(0.967302263f), acosf(0.967302263f), - atanf(0.967302263f) * powf(1.1f, 2.0f), - atan2f(0.4f, 1.3f), + WWMath::AtanfOrigin(0.967302263f) * WWMath::PowfOrigin(1.1f, 2.0f), + WWMath::Atan2fOrigin(0.4f, 1.3f), sinhf(0.2f), coshf(0.4f) * tanhf(0.5f), - sqrtf(55788.84375f), - expf(0.1f) * log10f(2.3f), + WWMath::SqrtfOrigin(55788.84375f), + WWMath::ExpfOrigin(0.1f) * WWMath::Log10fOrigin(2.3f), logf(1.4f)); Matrix3D::Multiply(matrix, factorsMatrix, &matrix); diff --git a/Core/GameEngine/Source/Common/INI/INI.cpp b/Core/GameEngine/Source/Common/INI/INI.cpp index b3a26a5f4c1..901d49935a3 100644 --- a/Core/GameEngine/Source/Common/INI/INI.cpp +++ b/Core/GameEngine/Source/Common/INI/INI.cpp @@ -1789,7 +1789,7 @@ void INI::parseDurationReal( INI *ini, void * /*instance*/, void *store, const v void INI::parseDurationUnsignedInt( INI *ini, void * /*instance*/, void *store, const void* /*userData*/ ) { UnsignedInt val = scanUnsignedInt(ini->getNextToken()); - *(UnsignedInt *)store = (UnsignedInt)ceilf(ConvertDurationFromMsecsToFrames((Real)val)); + *(UnsignedInt *)store = (UnsignedInt)WWMath::CeilfOrigin(ConvertDurationFromMsecsToFrames((Real)val)); } // ------------------------------------------------------------------------------------------------ @@ -1797,7 +1797,7 @@ void INI::parseDurationUnsignedInt( INI *ini, void * /*instance*/, void *store, void INI::parseDurationUnsignedShort( INI *ini, void * /*instance*/, void *store, const void* /*userData*/ ) { UnsignedInt val = scanUnsignedInt(ini->getNextToken()); - *(UnsignedShort *)store = (UnsignedShort)ceilf(ConvertDurationFromMsecsToFrames((Real)val)); + *(UnsignedShort *)store = (UnsignedShort)WWMath::CeilfOrigin(ConvertDurationFromMsecsToFrames((Real)val)); } //------------------------------------------------------------------------------------------------- diff --git a/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp b/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp index 0d8003df21a..d73fa771825 100644 --- a/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp +++ b/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp @@ -727,9 +727,9 @@ inline Bool isReallyClose(const Coord3D& a, const Coord3D& b) { const Real CLOSE_ENOUGH = 0.1f; return - fabs(a.x-b.x) <= CLOSE_ENOUGH && - fabs(a.y-b.y) <= CLOSE_ENOUGH && - fabs(a.z-b.z) <= CLOSE_ENOUGH; + WWMath::FAbsOrigin(a.x-b.x) <= CLOSE_ENOUGH && + WWMath::FAbsOrigin(a.y-b.y) <= CLOSE_ENOUGH && + WWMath::FAbsOrigin(a.z-b.z) <= CLOSE_ENOUGH; } /** @@ -921,7 +921,7 @@ void Path::computePointOnPath( // compute distance of point from this path segment Real toDistSqr = sqr(toPos.x) + sqr(toPos.y); Real offsetDistSq = toDistSqr - sqr(alongPathDist); - Real offsetDist = (offsetDistSq <= 0.0) ? 0.0 : sqrt(offsetDistSq); + Real offsetDist = (offsetDistSq <= 0.0) ? 0.0 : WWMath::SqrtOrigin(offsetDistSq); // If we are basically on the path, return the next path node as the movement goal. // However, the farther off the path we get, the movement goal becomes closer to our @@ -1011,8 +1011,8 @@ void Path::computePointOnPath( out.posOnPath.x = closeNodePos->x + alongPathDist * segmentDirNorm.x; out.posOnPath.y = closeNodePos->y + alongPathDist * segmentDirNorm.y; out.posOnPath.z = closeNodePos->z; - Real dx = fabs(pos.x - out.posOnPath.x); - Real dy = fabs(pos.y - out.posOnPath.y); + Real dx = WWMath::FAbsOrigin(pos.x - out.posOnPath.x); + Real dy = WWMath::FAbsOrigin(pos.y - out.posOnPath.y); if (dx<1 && dy<1 && closeNode->getNextOptimized() && closeNode->getNextOptimized()->getNextOptimized()) { out.posOnPath = *closeNode->getNextOptimized()->getNextOptimized()->getPosition(); } @@ -2070,7 +2070,7 @@ UnsignedInt PathfindCell::costToGoal( PathfindCell *goal ) Int dy = m_info->m_pos.y - goal->getYIndex(); #define NO_REAL_DIST #ifdef REAL_DIST - Int cost = COST_ORTHOGONAL*sqrt(dx*dx + dy*dy); + Int cost = COST_ORTHOGONAL*WWMath::SqrtOrigin(dx*dx + dy*dy); #else if (dx<0) dx = -dx; if (dy<0) dy = -dy; @@ -2096,7 +2096,7 @@ UnsignedInt PathfindCell::costToHierGoal( PathfindCell *goal ) } Int dx = m_info->m_pos.x - goal->getXIndex(); Int dy = m_info->m_pos.y - goal->getYIndex(); - Int cost = REAL_TO_INT_FLOOR(COST_ORTHOGONAL*sqrt(dx*dx + dy*dy) + 0.5f); + Int cost = REAL_TO_INT_FLOOR(COST_ORTHOGONAL*WWMath::SqrtOrigin(dx*dx + dy*dy) + 0.5f); return cost; } @@ -3963,8 +3963,8 @@ Bool PathfindLayer::isPointOnWall(ObjectID *wallPieces, Int numPieces, const Coo Real pty = pt->y - obj->getPosition()->y; // inverse-rotate it to the right coord system - Real ptx_new = (Real)fabs(ptx*c - pty*s); - Real pty_new = (Real)fabs(ptx*s + pty*c); + Real ptx_new = (Real)WWMath::FAbsOrigin(ptx*c - pty*s); + Real pty_new = (Real)WWMath::FAbsOrigin(ptx*s + pty*c); if (ptx_new <= major && pty_new <= minor) { @@ -6415,7 +6415,7 @@ Int Pathfinder::examineNeighboringCells(PathfindCell *parentCell, PathfindCell * toPos.y = newCellCoord.y * PATHFIND_CELL_SIZE_F ; toPos.z = TheTerrainLogic->getGroundHeight(toPos.x , toPos.y); - if ( fabs(fromPos.z - toPos.z)getPinched()) { @@ -6440,7 +6440,7 @@ Int Pathfinder::examineNeighboringCells(PathfindCell *parentCell, PathfindCell * } else { dx = newCellCoord.x - goalCell->getXIndex(); dy = newCellCoord.y - goalCell->getYIndex(); - costRemaining = COST_ORTHOGONAL*sqrt(dx*dx + dy*dy); + costRemaining = COST_ORTHOGONAL*WWMath::SqrtOrigin(dx*dx + dy*dy); costRemaining -= attackDistance/2; if (costRemaining<0) costRemaining=0; @@ -6764,7 +6764,7 @@ Path *Pathfinder::internalFindPath( Object *obj, const LocomotorSet& locomotorSe dx = from->x - to->x; dy = from->y - to->y; - Int count = sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); + Int count = WWMath::SqrtOrigin(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); if (count<2) count = 2; Int i; color.green = 0; @@ -7455,7 +7455,7 @@ Path *Pathfinder::findGroundPath( const Coord3D *from, dx = from->x - to->x; dy = from->y - to->y; - Int count = sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); + Int count = WWMath::SqrtOrigin(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); if (count<2) count = 2; Int i; color.green = 0; @@ -8159,7 +8159,7 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu dx = from->x - to->x; dy = from->y - to->y; - Int count = sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); + Int count = WWMath::SqrtOrigin(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); if (count<2) count = 2; Int i; color.green = 0; @@ -11216,7 +11216,7 @@ Path *Pathfinder::findSafePath( const Object *obj, const LocomotorSet& locomotor farthestDistanceSqr = distSqr; if (cellCount > MAX_CELLS) { #ifdef INTENSE_DEBUG - DEBUG_LOG(("Took intermediate path, dist %f, goal dist %f", sqrt(farthestDistanceSqr), repulsorRadius)); + DEBUG_LOG(("Took intermediate path, dist %f, goal dist %f", WWMath::SqrtOrigin(farthestDistanceSqr), repulsorRadius)); #endif ok = true; // Already a big search, just take this one. } diff --git a/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt b/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt index dca9eb68fef..4669b675165 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt +++ b/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt @@ -91,5 +91,11 @@ target_link_libraries(core_wwmath PRIVATE core_wwsaveload ) +if (NOT IS_VS6_BUILD) + target_link_libraries(core_wwmath PUBLIC + 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 8adda21a796..1ea32b730f6 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h +++ b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h @@ -41,6 +41,15 @@ #include #include +// TheSuperHackers @fix VC6 does not support long long or required by GameMath (gmath.h). +// Use __has_include because wwmath.h is transitively included by targets that may not link gamemath. +#if !(defined(_MSC_VER) && _MSC_VER < 1300) +#if defined(__has_include) && __has_include("gmath.h") +#include "gmath.h" +#define USE_DETERMINISTIC_MATH +#endif +#endif + /* ** Some global constants. */ @@ -133,8 +142,75 @@ 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); } +#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)); } +#endif + +// Trig wrappers: replace global Sin/Cos/Tan/ACos/ASin from deleted Trig.cpp. +// Original Trig.cpp called CRT float functions (sinf, cosf, etc.). +#ifdef USE_DETERMINISTIC_MATH + 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 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 + +// Origin wrappers: replace bare CRT math calls in GameLogic. +// Each wrapper preserves the exact type (float vs double) of the vanilla CRT call. +#ifdef USE_DETERMINISTIC_MATH + static WWINLINE double SqrtOrigin(double x) { return (double)gm_sqrtf((float)x); } + static WWINLINE float SqrtfOrigin(float x) { return gm_sqrtf(x); } + static WWINLINE double Atan2Origin(double y, double x) { return (double)gm_atan2f((float)y, (float)x); } + static WWINLINE float Atan2fOrigin(float y, float x) { return gm_atan2f(y, x); } + static WWINLINE double AtanOrigin(double x) { return (double)gm_atanf((float)x); } + static WWINLINE float AtanfOrigin(float x) { return gm_atanf(x); } + static WWINLINE double ACosOrigin(double x) { return (double)gm_acosf((float)x); } + static WWINLINE float ACosfOrigin(float x) { return gm_acosf(x); } + static WWINLINE double ASinOrigin(double x) { return (double)gm_asinf((float)x); } + static WWINLINE float ASinfOrigin(float x) { return gm_asinf(x); } + static WWINLINE double TanOrigin(double x) { return (double)gm_tanf((float)x); } + static WWINLINE float TanfOrigin(float x) { return gm_tanf(x); } + static WWINLINE double FAbsOrigin(double x) { return (double)gm_fabsf((float)x); } + static WWINLINE float FAbsfOrigin(float x) { return gm_fabsf(x); } + static WWINLINE double PowOrigin(double x, double y) { return (double)gm_powf((float)x, (float)y); } + static WWINLINE float PowfOrigin(float x, float y) { return gm_powf(x, y); } + static WWINLINE double CeilOrigin(double x) { return (double)gm_ceilf((float)x); } + static WWINLINE float CeilfOrigin(float x) { return gm_ceilf(x); } + static WWINLINE float ExpfOrigin(float x) { return gm_expf(x); } + static WWINLINE float Log10fOrigin(float x) { return gm_log10f(x); } +#else + static WWINLINE double SqrtOrigin(double x) { return sqrt(x); } + static WWINLINE float SqrtfOrigin(float x) { return sqrtf(x); } + static WWINLINE double Atan2Origin(double y, double x) { return atan2(y, x); } + static WWINLINE float Atan2fOrigin(float y, float x) { return atan2f(y, x); } + static WWINLINE double AtanOrigin(double x) { return atan(x); } + static WWINLINE float AtanfOrigin(float x) { return atanf(x); } + static WWINLINE double ACosOrigin(double x) { return acos(x); } + static WWINLINE float ACosfOrigin(float x) { return acosf(x); } + static WWINLINE double ASinOrigin(double x) { return asin(x); } + static WWINLINE float ASinfOrigin(float x) { return asinf(x); } + static WWINLINE double TanOrigin(double x) { return tan(x); } + static WWINLINE float TanfOrigin(float x) { return tanf(x); } + static WWINLINE double FAbsOrigin(double x) { return fabs(x); } + static WWINLINE float FAbsfOrigin(float x) { return fabsf(x); } + static WWINLINE double PowOrigin(double x, double y) { return pow(x, y); } + static WWINLINE float PowfOrigin(float x, float y) { return powf(x, y); } + static WWINLINE double CeilOrigin(double x) { return ceil(x); } + static WWINLINE float CeilfOrigin(float x) { return ceilf(x); } + static WWINLINE float ExpfOrigin(float x) { return expf(x); } + static WWINLINE float Log10fOrigin(float x) { return log10f(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); } @@ -313,7 +389,12 @@ WWINLINE bool WWMath::Is_Valid_Double(double x) // Float to long // ---------------------------------------------------------------------------- -#if defined(_MSC_VER) && defined(_M_IX86) +#if defined(USE_DETERMINISTIC_MATH) +WWINLINE long WWMath::Float_To_Long(float f) +{ + return gm_lrintf(f); +} +#elif defined(_MSC_VER) && defined(_M_IX86) WWINLINE long WWMath::Float_To_Long(float f) { long i; @@ -334,7 +415,9 @@ WWINLINE long WWMath::Float_To_Long(float f) WWINLINE long WWMath::Float_To_Long(double f) { -#if defined(_MSC_VER) && defined(_M_IX86) +#if defined(USE_DETERMINISTIC_MATH) + return gm_lrint(f); +#elif defined(_MSC_VER) && defined(_M_IX86) long retval; __asm fld qword ptr [f] __asm fistp dword ptr [retval] @@ -348,7 +431,12 @@ WWINLINE long WWMath::Float_To_Long(double f) // Cos // ---------------------------------------------------------------------------- -#if defined(_MSC_VER) && defined(_M_IX86) +#if defined(USE_DETERMINISTIC_MATH) +WWINLINE float WWMath::Cos(float val) +{ + return gm_cosf(val); +} +#elif defined(_MSC_VER) && defined(_M_IX86) WWINLINE float WWMath::Cos(float val) { float retval; @@ -370,7 +458,12 @@ WWINLINE float WWMath::Cos(float val) // Sin // ---------------------------------------------------------------------------- -#if defined(_MSC_VER) && defined(_M_IX86) +#if defined(USE_DETERMINISTIC_MATH) +WWINLINE float WWMath::Sin(float val) +{ + return gm_sinf(val); +} +#elif defined(_MSC_VER) && defined(_M_IX86) WWINLINE float WWMath::Sin(float val) { float retval; @@ -516,7 +609,11 @@ WWINLINE float WWMath::Fast_Acos(float val) WWINLINE float WWMath::Acos(float val) { +#ifdef USE_DETERMINISTIC_MATH + return gm_acosf(val); +#else return (float)acos(val); +#endif } // ---------------------------------------------------------------------------- @@ -553,14 +650,23 @@ WWINLINE float WWMath::Fast_Asin(float val) WWINLINE float WWMath::Asin(float val) { +#ifdef USE_DETERMINISTIC_MATH + return gm_asinf(val); +#else return (float)asin(val); +#endif } // ---------------------------------------------------------------------------- // Sqrt // ---------------------------------------------------------------------------- -#if defined(_MSC_VER) && defined(_M_IX86) +#if defined(USE_DETERMINISTIC_MATH) +WWINLINE float WWMath::Sqrt(float val) +{ + return gm_sqrtf(val); +} +#elif defined(_MSC_VER) && defined(_M_IX86) WWINLINE float WWMath::Sqrt(float val) { float retval; @@ -608,7 +714,12 @@ WWINLINE int WWMath::Float_To_Int_Floor (const float& f) // Inverse square root // ---------------------------------------------------------------------------- -#if defined(_MSC_VER) && defined(_M_IX86) +#if defined(USE_DETERMINISTIC_MATH) +WWINLINE float WWMath::Inv_Sqrt(float val) +{ + return 1.0f / gm_sqrtf(val); +} +#elif defined(_MSC_VER) && defined(_M_IX86) WWINLINE float WWMath::Inv_Sqrt(float a) { float retval; diff --git a/Generals/Code/GameEngine/Source/Common/RTS/Player.cpp b/Generals/Code/GameEngine/Source/Common/RTS/Player.cpp index 24400891859..6250c452368 100644 --- a/Generals/Code/GameEngine/Source/Common/RTS/Player.cpp +++ b/Generals/Code/GameEngine/Source/Common/RTS/Player.cpp @@ -2327,7 +2327,7 @@ void Player::doBountyForKill(const Object* killer, const Object* victim) Int bounty = REAL_TO_INT_CEIL(costToBuild * m_cashBountyPercent); #else // TheSuperHackers @bugfix Stubbjax 20/02/2026 Subtract epsilon to ensure bounty is rounded up correctly. - Int bounty = ceil((costToBuild * m_cashBountyPercent) - WWMATH_EPSILON); + Int bounty = WWMath::CeilOrigin((costToBuild * m_cashBountyPercent) - WWMATH_EPSILON); #endif if( bounty ) diff --git a/Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp b/Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp index ccb32fa1bf6..561d5246ee5 100644 --- a/Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp +++ b/Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp @@ -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::SqrtOrigin(WWMath::PowOrigin(gi.getMajorRadius(), 2) + WWMath::PowOrigin(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..dbe3279be50 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::SqrtOrigin(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::Atan2Origin(dz, dxy); dz = (thatPos.z - that.getMaxHeightBelowPosition()) - thisCenter.z; - minPitch = atan2(dz, dxy); + minPitch = WWMath::Atan2Origin(dz, dxy); } //============================================================================= @@ -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::SqrtOrigin(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::SqrtOrigin(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 = WWMath::SqrtOrigin(sqr(m_majorRadius) + sqr(m_minorRadius)); + m_boundingSphereRadius = WWMath::SqrtOrigin(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 index b09c4cb55d8..ca07f65983c 100644 --- a/Generals/Code/GameEngine/Source/Common/System/Trig.cpp +++ b/Generals/Code/GameEngine/Source/Common/System/Trig.cpp @@ -1,5 +1,5 @@ /* -** Command & Conquer Generals(tm) +** Command & Conquer Generals Zero Hour(tm) ** Copyright 2025 Electronic Arts Inc. ** ** This program is free software: you can redistribute it and/or modify @@ -17,129 +17,42 @@ */ //////////////////////////////////////////////////////////////////////////////// -// // -// (c) 2001-2003 Electronic Arts Inc. // -// // +// // +// (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 +// TheSuperHackers @refactor Redirect legacy trig functions to deterministic WWMath wrappers. +// Original implementations called CRT float functions (sinf, cosf, acosf, asinf, tanf). #include "PreRTS.h" -#include -#include - #include "Lib/BaseType.h" #include "Lib/trig.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 +#include "WWMath/wwmath.h" Real Sin(Real x) { - return sinf(x); + return WWMath::SinTrig(x); } Real Cos(Real x) { - return cosf(x); + return WWMath::CosTrig(x); } Real Tan(Real x) { - return tanf(x); + return WWMath::TanTrig(x); } Real ACos(Real x) { - return acosf(x); + return WWMath::ACosTrig(x); } Real ASin(Real x) { - return asinf(x); + return WWMath::ASinTrig(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; igetDistanceSquared(me, theEnemy, FROM_BOUNDINGSPHERE_2D); - Real dist = sqrt(distSqr); + Real dist = WWMath::SqrtOrigin(distSqr); Int modifier = dist/getAiData()->m_attackPriorityDistanceModifier; Int modPriority = curPriority-modifier; if (modPriority < 1) diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp index bac316191b1..c2ef8bd3fda 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp @@ -482,7 +482,7 @@ Object *AIPlayer::buildStructureNow(const ThingTemplate *bldgPlan, BuildListInfo { Coord3D rallyPoint; Bool gotOffset = false; - if (fabs(info->getRallyOffset()->x) > 1.0f || fabs(info->getRallyOffset()->y)>1.0f) { + if (WWMath::FAbsOrigin(info->getRallyOffset()->x) > 1.0f || WWMath::FAbsOrigin(info->getRallyOffset()->y)>1.0f) { gotOffset; } if (!exitInterface->getNaturalRallyPoint(rallyPoint)) { @@ -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::SqrtOrigin(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); if (count<2) count = 2; Int i; color.green = 1; @@ -662,7 +662,7 @@ Object *AIPlayer::buildStructureWithDozer(const ThingTemplate *bldgPlan, BuildLi { Coord3D rallyPoint; Bool gotOffset = false; - if (fabs(info->getRallyOffset()->x) > 1.0f || fabs(info->getRallyOffset()->y)>1.0f) { + if (WWMath::FAbsOrigin(info->getRallyOffset()->x) > 1.0f || WWMath::FAbsOrigin(info->getRallyOffset()->y)>1.0f) { gotOffset; } if (!exitInterface->getNaturalRallyPoint(rallyPoint)) { @@ -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)) { @@ -2806,7 +2806,7 @@ void AIPlayer::computeCenterAndRadiusOfBase(Coord3D *center, Real *radius) Real radSqr = dx*dx+dy*dy; if (radSqr>maxRadSqr) maxRadSqr=radSqr; } - *radius = sqrt(maxRadSqr); + *radius = WWMath::SqrtOrigin(maxRadSqr); } //---------------------------------------------------------------------------------------------------------- diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp index 3ac19981a52..9ddc0c054f9 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp @@ -524,7 +524,7 @@ StateReturnType AIRappelState::onEnter() obj->setLayer(layerAtDest); AIUpdateInterface *ai = obj->getAI(); - Real MAX_RAPPEL_RATE = fabs(TheGlobalData->m_gravity) * LOGICFRAMES_PER_SECOND * 2.5f; + Real MAX_RAPPEL_RATE = WWMath::FAbsOrigin(TheGlobalData->m_gravity) * LOGICFRAMES_PER_SECOND * 2.5f; m_rappelRate = -min(ai->getDesiredSpeed(), MAX_RAPPEL_RATE); return STATE_CONTINUE; @@ -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::SqrtOrigin(distSqr))); ret = STATE_CONTINUE; m_retryCount--; @@ -3802,7 +3802,7 @@ 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::Atan2Origin(dy, dx); Real deltaAngle = angle - m_angle; Real s = sin(deltaAngle); Real c = cos(deltaAngle); @@ -3811,7 +3811,7 @@ void AIFollowWaypointPathState::computeGoal(Bool useGroupOffsets) m_groupOffset.x = x; m_groupOffset.y = y; } else { - angle = atan2(dy, dx); + angle = WWMath::Atan2Origin(dy, dx); } m_angle = angle; #endif @@ -4933,7 +4933,7 @@ StateReturnType AIAttackAimAtTargetState::update() //DEBUG_LOG(("AIM: desired %f, actual %f, delta %f, aimDelta %f, goalpos %f %f",rad2deg(obj->getOrientation() + relAngle),rad2deg(obj->getOrientation()),rad2deg(relAngle),rad2deg(aimDelta),victim->getPosition()->x,victim->getPosition()->y)); if (m_canTurnInPlace) { - if (fabs(relAngle) > aimDelta) + if (WWMath::FAbsOrigin(relAngle) > aimDelta) { Real desiredAngle = source->getOrientation() + relAngle; sourceAI->setLocomotorGoalOrientation(desiredAngle); @@ -4945,7 +4945,7 @@ StateReturnType AIAttackAimAtTargetState::update() sourceAI->setLocomotorGoalPositionExplicit(m_isAttackingObject ? *victim->getPosition() : *getMachineGoalPosition()); } - if (fabs(relAngle) < aimDelta /*&& !m_preAttackFrames*/ ) + if (WWMath::FAbsOrigin(relAngle) < aimDelta /*&& !m_preAttackFrames*/ ) { AIUpdateInterface* victimAI = victim ? victim->getAI() : nullptr; // add ourself as a targeter BEFORE calling isTemporarilyPreventingAimSuccess(). @@ -6983,7 +6983,7 @@ StateReturnType AIFaceState::update() Real relAngle = ThePartitionManager->getRelativeAngle2D( obj, pos ); const Real REL_THRESH = 0.035f; // about 2 degrees. (getRelativeAngle2D is current only accurate to about 1.25 degrees) - if( fabs( relAngle ) < REL_THRESH ) + if( WWMath::FAbsOrigin( relAngle ) < REL_THRESH ) { return STATE_SUCCESS; } diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp index 651e2c4f2f0..22085b0c6d8 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp @@ -386,7 +386,7 @@ Bool TurretAI::friend_turnTowardsAngle(Real desiredAngle, Real rateModifier, Rea Real angleDiff = normalizeAngle(desiredAngle - actualAngle); // Are we close enough to the desired angle to just snap there? - if (fabs(angleDiff) < turnRate) + if (WWMath::FAbsOrigin(angleDiff) < turnRate) { // we are centered actualAngle = desiredAngle; @@ -409,7 +409,7 @@ Bool TurretAI::friend_turnTowardsAngle(Real desiredAngle, Real rateModifier, Rea if( m_angle != origAngle ) getOwner()->reactToTurretChange( m_whichTurret, origAngle, m_pitch ); - Bool aligned = fabs(m_angle - desiredAngle) <= relThresh; + Bool aligned = WWMath::FAbsOrigin(m_angle - desiredAngle) <= relThresh; return aligned; } @@ -427,7 +427,7 @@ Bool TurretAI::friend_turnTowardsPitch(Real desiredPitch, Real rateModifier) Real pitchRate = getPitchRate() * rateModifier; Real pitchDiff = normalizeAngle(desiredPitch - actualPitch); - if (fabs(pitchDiff) < pitchRate) + if (WWMath::FAbsOrigin(pitchDiff) < pitchRate) { // we are centered actualPitch = desiredPitch; @@ -1070,7 +1070,7 @@ StateReturnType TurretAIAimTurretState::update() turret->friend_setPositiveSweep(!turret->friend_getPositiveSweep()); Real angleDiff = normalizeAngle(relAngle - turret->getTurretAngle()); - turnAlignedToNemesis = (fabs(angleDiff) < sweep); + turnAlignedToNemesis = (WWMath::FAbsOrigin(angleDiff) < sweep); } Bool pitchAlignedToNemesis = true; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp b/Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp index 6cea7c6227a..d1884a02e73 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::SqrtOrigin(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..0fbf0547113 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 WWMath::Atan2Origin(xvec.y, xvec.x) == angle. So we must construct the matrix carefully to ensure this! */ x.x = Cos( angle ); @@ -1489,7 +1489,7 @@ void makeAlignToNormalMatrix( Real angle, const Coord3D& pos, const Coord3D& nor x.normalize(); } - DEBUG_ASSERTCRASH(fabs(x.x*z.x + x.y*z.y + x.z*z.z)<0.0001,("dot is not zero (%f)",fabs(x.x*z.x + x.y*z.y + x.z*z.z))); + DEBUG_ASSERTCRASH(WWMath::FAbsOrigin(x.x*z.x + x.y*z.y + x.z*z.z)<0.0001,("dot is not zero (%f)",WWMath::FAbsOrigin(x.x*z.x + x.y*z.y + x.z*z.z))); // now computing the y vector is trivial. y.crossProduct( &z, &x, &y ); @@ -1685,12 +1685,12 @@ PathfindLayerEnum TerrainLogic::getLayerForDestination(const Coord3D *pos) { Bridge *pBridge = getFirstBridge(); PathfindLayerEnum bestLayer = LAYER_GROUND; - Real bestDistance = fabs(pos->z - getGroundHeight(pos->x, pos->y)); + Real bestDistance = WWMath::FAbsOrigin(pos->z - getGroundHeight(pos->x, pos->y)); if (bestDistance > TheAI->pathfinder()->getWallHeight()/2) { // check wall. if (TheAI->pathfinder()->isPointOnWall(pos)) { - Real delta = fabs(pos->z-TheAI->pathfinder()->getWallHeight()); + Real delta = WWMath::FAbsOrigin(pos->z-TheAI->pathfinder()->getWallHeight()); if (deltaisPointOnBridge(pos) ) { - Real delta = fabs(pos->z-pBridge->getBridgeHeight(pos, nullptr)); + Real delta = WWMath::FAbsOrigin(pos->z-pBridge->getBridgeHeight(pos, nullptr)); if (deltagetLayer(); bestDistance = delta; @@ -1724,7 +1724,7 @@ PathfindLayerEnum TerrainLogic::getHighestLayerForDestination(const Coord3D *pos if (TheAI->pathfinder()->isPointOnWall(pos)) { Real delta = pos->z - TheAI->pathfinder()->getWallHeight(); // must be ABOVE (or on) the wall for this call. (srj) - if (delta >= 0 && fabs(delta) < fabs(bestDistance)) { + if (delta >= 0 && WWMath::FAbsOrigin(delta) < WWMath::FAbsOrigin(bestDistance)) { bestLayer = (PathfindLayerEnum)LAYER_WALL; bestDistance = delta; } @@ -1739,7 +1739,7 @@ PathfindLayerEnum TerrainLogic::getHighestLayerForDestination(const Coord3D *pos if (pBridge->isPointOnBridge(pos) ) { Real delta = pos->z - pBridge->getBridgeHeight(pos, nullptr); // must be ABOVE (or on) the bridge for this call. (srj) - if (delta >= 0 && fabs(delta) < fabs(bestDistance)) { + if (delta >= 0 && WWMath::FAbsOrigin(delta) < WWMath::FAbsOrigin(bestDistance)) { bestLayer = pBridge->getLayer(); bestDistance = delta; } @@ -1788,7 +1788,7 @@ Bool TerrainLogic::objectInteractsWithBridgeLayer(Object *obj, Int layer, Bool c if (match) { Real bridgeHeight = pBridge->getBridgeHeight(obj->getPosition(), nullptr); - Real delta = fabs(obj->getPosition()->z-bridgeHeight); + Real delta = WWMath::FAbsOrigin(obj->getPosition()->z-bridgeHeight); if (delta>LAYER_Z_CLOSE_ENOUGH_F) { return false; } @@ -1837,7 +1837,7 @@ Bool TerrainLogic::objectInteractsWithBridgeEnd(Object *obj, Int layer) const if (match) { Real bridgeHeight = pBridge->getBridgeHeight(obj->getPosition(), nullptr); - Real delta = fabs(obj->getPosition()->z-bridgeHeight); + Real delta = WWMath::FAbsOrigin(obj->getPosition()->z-bridgeHeight); if (delta>LAYER_Z_CLOSE_ENOUGH_F) { return false; @@ -2055,10 +2055,10 @@ Coord3D TerrainLogic::findClosestEdgePoint ( const Coord3D *closestTo ) const getExtent( &mapExtent ); Real distances[4]; - distances[0] = fabs( closestTo->y - mapExtent.lo.y );//top - distances[1] = fabs( closestTo->x - mapExtent.hi.x );//right - distances[2] = fabs( closestTo->y - mapExtent.hi.y );//bottom - distances[3] = fabs( closestTo->x - mapExtent.lo.x );//left + distances[0] = WWMath::FAbsOrigin( closestTo->y - mapExtent.lo.y );//top + distances[1] = WWMath::FAbsOrigin( closestTo->x - mapExtent.hi.x );//right + distances[2] = WWMath::FAbsOrigin( closestTo->y - mapExtent.hi.y );//bottom + distances[3] = WWMath::FAbsOrigin( closestTo->x - mapExtent.lo.x );//left Real bestDistance = distances[0]; Int bestDistanceIndex = 0; for( Int lameIndex = 1; lameIndex < 4; lameIndex++ ) @@ -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::SqrtOrigin( 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 7c4bc633863..924d99db6ab 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp @@ -169,24 +169,24 @@ static Bool calcTrajectory( Real dz = end.z - start.z; // calculating the angle is trivial. - angle = atan2(dy, dx); + angle = WWMath::Atan2Origin(dy, dx); // calculating the pitch requires a bit more effort. Real horizDistSqr = sqr(dx) + sqr(dy); - Real horizDist = sqrt(horizDistSqr); + Real horizDist = WWMath::SqrtOrigin(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) - Real gravity = fabs(TheGlobalData->m_gravity); + Real gravity = WWMath::FAbsOrigin(TheGlobalData->m_gravity); Real gravityTwoDZ = gravity * 2.0f * dz; // 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::Atan2Origin(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; - if (fabs(theta) > SHALLOW_ANGLE) + if (WWMath::FAbsOrigin(theta) > SHALLOW_ANGLE) { Real t = horizDist / velocity; Real vz = (dz/t + 0.5f*gravity*t); @@ -287,7 +287,7 @@ static Bool calcTrajectory( #endif vx = velocity*cosPitches[preferred]; - Real actualRange = (vx*(vz + sqrt(root)))/gravity; + Real actualRange = (vx*(vz + WWMath::SqrtOrigin(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 = WWMath::SqrtOrigin(ThePartitionManager->getDistanceSquared( projectile, &victimPosToUse, FROM_CENTER_2D ) ); Real rangeRatio = (range - minRange) / (maxRange - minRange); m_flightPathSpeed = (rangeRatio * (weaponSpeed - minWeaponSpeed)) + minWeaponSpeed; } @@ -441,7 +441,7 @@ Bool DumbProjectileBehavior::calcFlightPath(Bool recalcNumSegments) if (recalcNumSegments) { Real flightDistance = flightCurve.getApproximateLength(); - m_flightPathSegments = ceil( flightDistance / m_flightPathSpeed ); + m_flightPathSegments = WWMath::CeilOrigin( flightDistance / m_flightPathSpeed ); } flightCurve.getSegmentPoints( m_flightPathSegments, &m_flightPath ); DEBUG_ASSERTCRASH(m_flightPathSegments == m_flightPath.size(), ("m_flightPathSegments mismatch")); @@ -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 = WWMath::SqrtfOrigin(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..b197c8f0f1a 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::SqrtOrigin(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..ec96df057be 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(WWMath::SqrtfOrigin(2.0f * (start.z - endOnGround.z) / WWMath::FAbsOrigin(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,8 +580,8 @@ 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)); - if (dist <= 0.1f && fabs(dz) <= 0.1f) + Real dist = WWMath::SqrtOrigin(sqr(dx) + sqr(dy)); + if (dist <= 0.1f && WWMath::FAbsOrigin(dz) <= 0.1f) { obj->setPosition(&endOnGround); m_scootFramesLeft = 0; @@ -590,7 +590,7 @@ void MinefieldBehavior::setScootParms(const Coord3D& start, const Coord3D& end) { Real t = (Real)scootFromStartingPointTime; Real scootFromStartingPointSpeed = dist / t; - Real accelMag = fabs(2.0f * (dist - scootFromStartingPointSpeed*t)/sqr(t)); + Real accelMag = WWMath::FAbsOrigin(2.0f * (dist - scootFromStartingPointSpeed*t)/sqr(t)); Real dxNorm = (dist <= 0.1f) ? 0.0f : (dx / dist); Real dyNorm = (dist <= 0.1f) ? 0.0f : (dy / dist); m_scootVel.x = dxNorm * scootFromStartingPointSpeed; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp index 20bdea05e43..b770e8e9506 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::Atan2Origin(force.y, force.x); physics->setAngles(orientation, 0, 0); obj->getDrawable()->setModelConditionState(MODELCONDITION_EXPLODED_FLAILING); m_flags |= (1<getPosition()->z) >= d->m_paraOpenDist) + if (WWMath::FAbsOrigin(m_startZ - parachute->getPosition()->z) >= d->m_paraOpenDist) { m_opened = true; parachute->clearAndSetModelConditionState(MODELCONDITION_FREEFALL, MODELCONDITION_PARACHUTING); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp index d751f77dc73..6a1a838249d 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp @@ -84,7 +84,7 @@ static Real calcSlowDownDist(Real curSpeed, Real desiredSpeed, Real maxBraking) if (delta <= 0) return 0.0f; - Real dist = (sqr(delta) / fabs(maxBraking)) * 0.5f; + Real dist = (sqr(delta) / WWMath::FAbsOrigin(maxBraking)) * 0.5f; // use a little fudge so that things can stop "on a dime" more easily... const Real FUDGE = 1.05f; @@ -95,14 +95,14 @@ static Real calcSlowDownDist(Real curSpeed, Real desiredSpeed, Real maxBraking) inline Bool isNearlyZero(Real a) { const Real TINY_EPSILON = 0.001f; - return fabs(a) < TINY_EPSILON; + return WWMath::FAbsOrigin(a) < TINY_EPSILON; } //----------------------------------------------------------------------------- inline Bool isNearly(Real a, Real val) { const Real TINY_EPSILON = 0.001f; - return fabs(a - val) < TINY_EPSILON; + return WWMath::FAbsOrigin(a - val) < TINY_EPSILON; } //----------------------------------------------------------------------------- @@ -141,7 +141,7 @@ static Real tryToRotateVector3D( } } - if (fabs(angleBetween) <= maxAngle) + if (WWMath::FAbsOrigin(angleBetween) <= maxAngle) { // close enough actualDir = goalDir; @@ -231,9 +231,9 @@ static void calcDirectionToApplyThrust( Bool foundSolution = false; Real distToGoalSqr = vecToGoal.Length2(); - Real distToGoal = sqrt(distToGoalSqr); + Real distToGoal = WWMath::SqrtOrigin(distToGoalSqr); Real curVelMagSqr = curVel.Length2(); - Real curVelMag = sqrt(curVelMagSqr); + Real curVelMag = WWMath::SqrtOrigin(curVelMagSqr); Real maxAccelSqr = sqr(maxAccel); Real denom = curVelMagSqr - maxAccelSqr; @@ -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::SqrtOrigin(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::SqrtOrigin(dx*dx+dy*dy+dz*dz); Real vel = physics->getVelocityMagnitude(); if (vel < MIN_VEL) vel = MIN_VEL; @@ -1107,7 +1107,7 @@ void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalP // Normalize. if (dist > 0.001f) { - Real vel = fabs(physics->getForwardSpeed2D()); + Real vel = WWMath::FAbsOrigin(physics->getForwardSpeed2D()); if (vel < MIN_VEL) vel = MIN_VEL; if (vel > dist) @@ -1152,7 +1152,7 @@ void Locomotor::moveTowardsPositionTreads(Object* obj, PhysicsBehavior *physics, // Modulate speed according to turning. The more we have to turn, the slower we go // const Real QUAETERPI = PI / 4.0f; - Real angleCoeff = (Real)fabs( relAngle ) / QUAETERPI; + Real angleCoeff = (Real)WWMath::FAbsOrigin( relAngle ) / QUAETERPI; if (angleCoeff > 1.0f) angleCoeff = 1.0; @@ -1223,7 +1223,7 @@ void Locomotor::moveTowardsPositionTreads(Object* obj, PhysicsBehavior *physics, see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (fabs(accelForce) > fabs(maxForceNeeded)) + if (WWMath::FAbsOrigin(accelForce) > WWMath::FAbsOrigin(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); @@ -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::Atan2Origin(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real relAngle = stdAngleDiff(desiredAngle, angle); Bool moveBackwards = false; @@ -1275,14 +1275,14 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, #if 1 if (actualSpeed==0.0f) { setFlag(MOVING_BACKWARDS, false); - if (m_template->m_canMoveBackward && fabs(relAngle) > PI/2) { + if (m_template->m_canMoveBackward && WWMath::FAbsOrigin(relAngle) > PI/2) { setFlag(MOVING_BACKWARDS, true ); setFlag(DOING_THREE_POINT_TURN, onPathDistToGoal>5*obj->getGeometryInfo().getMajorRadius()); } } if (getFlag(MOVING_BACKWARDS)) { - if (fabs(relAngle) < PI/2) { + if (WWMath::FAbsOrigin(relAngle) < PI/2) { moveBackwards = false; setFlag(MOVING_BACKWARDS, false); } else { @@ -1298,7 +1298,7 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, #endif const Real SMALL_TURN = PI / 20.0f; - if ((Real)fabs( relAngle ) > SMALL_TURN) + if ((Real)WWMath::FAbsOrigin( relAngle ) > SMALL_TURN) { if (desiredSpeed>turnSpeed) { @@ -1323,7 +1323,7 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, const Real FIFTEEN_DEGREES = PI / 12.0f; const Real PROJECT_FRAMES = LOGICFRAMES_PER_SECOND/2; // Project out 1/2 second. - if (fabs( relAngle ) > FIFTEEN_DEGREES) + if (WWMath::FAbsOrigin( relAngle ) > FIFTEEN_DEGREES) { // If we're turning more than 10 degrees, check & see if we're moving into "impassable territory" Real distance = PROJECT_FRAMES * (goalSpeed+actualSpeed)/2.0f; @@ -1462,7 +1462,7 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (fabs(accelForce) > fabs(maxForceNeeded)) + if (WWMath::FAbsOrigin(accelForce) > WWMath::FAbsOrigin(maxForceNeeded)) accelForce = maxForceNeeded; //DEBUG_LOG(("Braking %d, actualSpeed %f, goalSpeed %f, delta %f, accel %f", getFlag(IS_BRAKING), @@ -1533,7 +1533,7 @@ Bool Locomotor::fixInvalidPosition(Object* obj, PhysicsBehavior *physics) //physics->clearAcceleration(); if (dot<0) { - dot = sqrt(-dot); + dot = WWMath::SqrtOrigin(-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::Atan2Origin(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; @@ -1623,7 +1623,7 @@ void Locomotor::moveTowardsPositionLegs(Object* obj, PhysicsBehavior *physics, c // Modulate speed according to turning. The more we have to turn, the slower we go // const Real QUARTERPI = PI / 4.0f; - Real angleCoeff = (Real)fabs( relAngle ) / (QUARTERPI); + Real angleCoeff = (Real)WWMath::FAbsOrigin( relAngle ) / (QUARTERPI); if (angleCoeff > 1.0f) angleCoeff = 1.0; @@ -1653,7 +1653,7 @@ void Locomotor::moveTowardsPositionLegs(Object* obj, PhysicsBehavior *physics, c see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (fabs(accelForce) > fabs(maxForceNeeded)) + if (WWMath::FAbsOrigin(accelForce) > WWMath::FAbsOrigin(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); @@ -1695,7 +1695,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, if (dz*dz > sqr(PATHFIND_CELL_SIZE_F)) { setFlag(CLIMBING, true); } - if (fabs(dz)<1) { + if (WWMath::FAbsOrigin(dz)<1) { setFlag(CLIMBING, false); } @@ -1715,7 +1715,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, moveBackwards = true; } - Real groundSlope = fabs(delta.z - pos.z); + Real groundSlope = WWMath::FAbsOrigin(delta.z - pos.z); if (groundSlope<1.0f) groundSlope = 1.0f; if (groundSlope>1.0f) { @@ -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::Atan2Origin(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real relAngle = stdAngleDiff(desiredAngle, angle); if (moveBackwards) { @@ -1744,7 +1744,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, // Modulate speed according to turning. The more we have to turn, the slower we go // const Real QUARTERPI = PI / 4.0f; - Real angleCoeff = (Real)fabs( relAngle ) / (QUARTERPI); + Real angleCoeff = (Real)WWMath::FAbsOrigin( relAngle ) / (QUARTERPI); if (angleCoeff > 1.0f) angleCoeff = 1.0; @@ -1786,7 +1786,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (fabs(accelForce) > fabs(maxForceNeeded)) + if (WWMath::FAbsOrigin(accelForce) > WWMath::FAbsOrigin(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); @@ -1813,7 +1813,7 @@ void Locomotor::moveTowardsPositionWings(Object* obj, PhysicsBehavior *physics, Real dx = goalPos.x - pos->x; Real dy = goalPos.y - pos->y; Real dz = goalPos.z - pos->z; - if (fabs(dz) > m_circleThresh) + if (WWMath::FAbsOrigin(dz) > m_circleThresh) { // aim for the spot on the opposite side of the circle. @@ -1821,7 +1821,7 @@ void Locomotor::moveTowardsPositionWings(Object* obj, PhysicsBehavior *physics, Real angleTowardPos = (isNearlyZero(dx) && isNearlyZero(dy)) ? obj->getOrientation() : - atan2(dy, dx); + WWMath::Atan2Origin(dy, dx); Real aimDir = (PI - PI/8); angleTowardPos += aimDir; @@ -1910,7 +1910,7 @@ void Locomotor::moveTowardsPositionThrust(Object* obj, PhysicsBehavior *physics, // so we tend to "level out" at that height. we don't use this till // below, but go ahead and calc it now... Real MAX_VERTICAL_DAMP_RANGE = m_preferredHeight * 0.5; - delta = fabs(delta); + delta = WWMath::FAbsOrigin(delta); if (delta > MAX_VERTICAL_DAMP_RANGE) delta = MAX_VERTICAL_DAMP_RANGE; zDirDamping = 1.0f - (delta / MAX_VERTICAL_DAMP_RANGE); @@ -2027,7 +2027,7 @@ Real Locomotor::calcLiftToUseAtPt(Object* obj, PhysicsBehavior *physics, Real cu // see how far we need to slow to dead stop, given max braking Real desiredAccel; const Real TINY_ACCEL = 0.001f; - if (fabs(maxAccel) > TINY_ACCEL) + if (WWMath::FAbsOrigin(maxAccel) > TINY_ACCEL) { Real deltaZ = preferredHeight - curZ; // calc how far it will take for us to go from cur speed to zero speed, at max accel. @@ -2035,14 +2035,14 @@ Real Locomotor::calcLiftToUseAtPt(Object* obj, PhysicsBehavior *physics, Real cu // in theory, the above is the correct calculation, but in practice, // doesn't work in some situations (eg, opening of USA01 map). Why, I dunno. // But for now I have gone back to the old, looks-incorrect-to-me-but-works calc. (srj) - Real brakeDist = (sqr(curVelZ) / fabs(maxAccel)); - if (fabs(brakeDist) > fabs(deltaZ)) + Real brakeDist = (sqr(curVelZ) / WWMath::FAbsOrigin(maxAccel)); + if (WWMath::FAbsOrigin(brakeDist) > WWMath::FAbsOrigin(deltaZ)) { // if the dist-to-accel (or dist-to-brake) is further than the dist-to-go, // use the max accel. desiredAccel = maxAccel; } - else if (fabs(curVelZ) > m_template->m_speedLimitZ) + else if (WWMath::FAbsOrigin(curVelZ) > m_template->m_speedLimitZ) { // or, if we're going too fast, limit it here. desiredAccel = m_template->m_speedLimitZ - curVelZ; @@ -2116,8 +2116,8 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 Real dx =goalPos.x - turnPos.x; 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); + if (WWMath::FAbsOrigin(dx)<0.1f && WWMath::FAbsOrigin(dy)<0.1f) return TURN_NONE; + Real desiredAngle = WWMath::Atan2Origin(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 = WWMath::Atan2Origin(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::Atan2Origin(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real amount = stdAngleDiff(desiredAngle, angle); if (relAngle) *relAngle = amount; if (amount>maxTurnRate) { @@ -2333,8 +2333,8 @@ void Locomotor::moveTowardsPositionOther(Object* obj, PhysicsBehavior *physics, //fabs(goalPos.y - pos->y),fabs(goalPos.x - pos->x), //fabs(goalPos.y - pos->y)/goalSpeed,fabs(goalPos.x - pos->x)/goalSpeed)); if (getFlag(ULTRA_ACCURATE) && - fabs(goalPos.y - pos->y) <= goalSpeed * m_template->m_ultraAccurateSlideIntoPlaceFactor && - fabs(goalPos.x - pos->x) <= goalSpeed * m_template->m_ultraAccurateSlideIntoPlaceFactor) + WWMath::FAbsOrigin(goalPos.y - pos->y) <= goalSpeed * m_template->m_ultraAccurateSlideIntoPlaceFactor && + WWMath::FAbsOrigin(goalPos.x - pos->x) <= goalSpeed * m_template->m_ultraAccurateSlideIntoPlaceFactor) { // don't turn, just slide in the right direction physics->setTurning(TURN_NONE); @@ -2373,7 +2373,7 @@ void Locomotor::moveTowardsPositionOther(Object* obj, PhysicsBehavior *physics, see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (fabs(accelForce) > fabs(maxForceNeeded)) + if (WWMath::FAbsOrigin(accelForce) > WWMath::FAbsOrigin(maxForceNeeded)) accelForce = maxForceNeeded; Coord3D force; @@ -2488,7 +2488,7 @@ void Locomotor::maintainCurrentPositionWings(Object* obj, PhysicsBehavior *physi Real angleTowardMaintainPos = (isNearlyZero(dx) && isNearlyZero(dy)) ? obj->getOrientation() : - atan2(dy, dx); + WWMath::Atan2Origin(dy, dx); Real aimDir = (PI - PI/8); if (turnRadius < 0) @@ -2522,7 +2522,7 @@ void Locomotor::maintainCurrentPositionHover(Object* obj, PhysicsBehavior *physi // Real minSpeed = max( 1.0E-10f, m_template->m_minSpeed ); Real speedDelta = minSpeed - actualSpeed; - if (fabs(speedDelta) > minSpeed) + if (WWMath::FAbsOrigin(speedDelta) > minSpeed) { Real mass = physics->getMass(); Real acceleration = (speedDelta > 0.0f) ? maxAcceleration : -getBraking(); @@ -2533,7 +2533,7 @@ void Locomotor::maintainCurrentPositionHover(Object* obj, PhysicsBehavior *physi see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (fabs(accelForce) > fabs(maxForceNeeded)) + if (WWMath::FAbsOrigin(accelForce) > WWMath::FAbsOrigin(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp index edda6839d12..cc544a37e37 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp @@ -1594,13 +1594,13 @@ inline Bool isPosDifferent(const Coord3D* a, const Coord3D* b) // so we must put in some cleverness... const Real THRESH = 0.01f; - if (fabs(a->x - b->x) > THRESH) + if (WWMath::FAbsOrigin(a->x - b->x) > THRESH) return true; - if (fabs(a->y - b->y) > THRESH) + if (WWMath::FAbsOrigin(a->y - b->y) > THRESH) return true; - if (fabs(a->z - b->z) > THRESH) + if (WWMath::FAbsOrigin(a->z - b->z) > THRESH) return true; return false; @@ -1616,7 +1616,7 @@ inline Bool isAngleDifferent(Real a, Real b) const Real THRESH = 0.01f; // in radians, this is approx 1/2 degree. - if (fabs(a - b) > THRESH) + if (WWMath::FAbsOrigin(a - b) > THRESH) return true; return false; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp index f1ec13163f4..3c80a648899 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::SqrtOrigin( 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 = WWMath::Atan2Origin( 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 = WWMath::Atan2Origin(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::Atan2Origin(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..3130ecf8f09 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp @@ -411,13 +411,13 @@ static void testRotatedPointsAgainstRect( Real pty = pts->y - a->position.y; // inverse-rotate it to the right coord system - Real ptx_new = (Real)fabs(ptx*c - pty*s); - Real pty_new = (Real)fabs(ptx*s + pty*c); + Real ptx_new = (Real)WWMath::FAbsOrigin(ptx*c - pty*s); + Real pty_new = (Real)WWMath::FAbsOrigin(ptx*s + pty*c); #ifdef INTENSE_DEBUG Real mag_a = sqr(ptx)+sqr(pty); Real mag_b = sqr(ptx_new)+sqr(pty_new); - DEBUG_ASSERTCRASH(fabs(mag_a - mag_b) <= 1.0, ("hmm, unlikely")); + DEBUG_ASSERTCRASH(WWMath::FAbsOrigin(mag_a - mag_b) <= 1.0, ("hmm, unlikely")); #endif if (ptx_new <= major && pty_new <= minor) @@ -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)WWMath::SqrtfOrigin(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)WWMath::SqrtfOrigin(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 = WWMath::SqrtfOrigin(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 = WWMath::SqrtfOrigin(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)(WWMath::SqrtfOrigin(majorRadius*majorRadius + minorRadius*minorRadius)); Int cells = ThePartitionManager->worldToCellDist(diagonal*2) + 1; result = cells * cells; break; @@ -2636,7 +2636,7 @@ static void calcHeights(const Region3D& world, Real cellSize, Int x, Int y, Real Real xbase = world.lo.x + (x * cellSize); Real ybase = world.lo.y + (y * cellSize); const Real ROUGH_STEP_SIZE = 2; // roughly every 2 ft, please - Real numSteps = ceilf(cellSize / ROUGH_STEP_SIZE); + Real numSteps = WWMath::CeilfOrigin(cellSize / ROUGH_STEP_SIZE); Real step = cellSize / numSteps; loZ = HUGE_DIST; // huge positive hiZ = -HUGE_DIST; // huge negative @@ -3210,7 +3210,7 @@ Int PartitionManager::calcMinRadius(const ICoord2D& cur) } // double, not real - double dist = sqrtf(minDistSqr); + double dist = WWMath::SqrtfOrigin(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::SqrtOrigin(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)WWMath::SqrtfOrigin(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)WWMath::SqrtfOrigin(sqr(v.x) + sqr(v.y)); // normalize if (dist == 0.0f) @@ -3803,7 +3803,7 @@ Bool PartitionManager::tryPosition( const Coord3D *center, pos.z = TheTerrainLogic->getGroundHeight( pos.x, pos.y ); } - if (fabs(pos.z - center->z) > options->maxZDelta) + if (WWMath::FAbsOrigin(pos.z - center->z) > options->maxZDelta) return FALSE; // @@ -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 WWMath::SqrtfOrigin(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::SqrtOrigin( WWMath::PowOrigin(x - parms->xCenter, 2) + WWMath::PowOrigin(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::SqrtOrigin( WWMath::PowOrigin(x - parms->xCenter, 2) + WWMath::PowOrigin(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::SqrtOrigin( WWMath::PowOrigin(x - parms->xCenter, 2) + WWMath::PowOrigin(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::SqrtOrigin( WWMath::PowOrigin(x - parms->xCenter, 2) + WWMath::PowOrigin(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 f75f965f68f..95ee0a7e140 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp @@ -1282,8 +1282,8 @@ Bool AIUpdateInterface::blockedBy(Object *other) // If we are near our final goal, don't get stuck. if (goalCell.x>0 && goalCell.y>0) { - Real dx = fabs(goalPos.x-pos.x); - Real dy = fabs(goalPos.y-pos.y); + Real dx = WWMath::FAbsOrigin(goalPos.x-pos.x); + Real dy = WWMath::FAbsOrigin(goalPos.y-pos.y); if (dxgetRelativeAngle2D( getObject(), &info.posOnPath ); } - if (fabs(deltaAngle)>PI/30) + if (WWMath::FAbsOrigin(deltaAngle)>PI/30) { return TRUE; } @@ -2230,7 +2230,7 @@ UpdateSleepTime AIUpdateInterface::doLocomotor() } else { - Real dist = sqrtf(dSqr); + Real dist = WWMath::SqrtfOrigin(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::SqrtOrigin( 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::SqrtOrigin(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::SqrtOrigin(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; @@ -569,7 +569,7 @@ class ChinookCombatDropState : public State { if (it->ropeLen < it->ropeLenMax) { - it->ropeSpeed += fabs(TheGlobalData->m_gravity); + it->ropeSpeed += WWMath::FAbsOrigin(TheGlobalData->m_gravity); if (it->ropeSpeed > d->m_ropeDropSpeed) it->ropeSpeed = d->m_ropeDropSpeed; it->ropeLen += it->ropeSpeed; @@ -761,7 +761,7 @@ class ChinookMoveToBldgState : public AIMoveToState StateReturnType status = AIMoveToState::update(); const Real THRESH = 3.0f; - if (status != STATE_CONTINUE && fabs(obj->getPosition()->z - m_destZ) > THRESH) + if (status != STATE_CONTINUE && WWMath::FAbsOrigin(obj->getPosition()->z - m_destZ) > THRESH) status = STATE_CONTINUE; return status; @@ -840,7 +840,7 @@ ChinookAIUpdateModuleData::ChinookAIUpdateModuleData() m_minDropHeight = 30.0f; m_ropeFinalHeight = 0.0f; m_ropeDropSpeed = 1e10f; // um, fast. - m_rappelSpeed = fabs(TheGlobalData->m_gravity) * LOGICFRAMES_PER_SECOND * 0.5f; + m_rappelSpeed = WWMath::FAbsOrigin(TheGlobalData->m_gravity) * LOGICFRAMES_PER_SECOND * 0.5f; m_ropeWobbleLen = 10.0f; m_ropeWobbleAmp = 1.0f; m_ropeWobbleRate = 0.1f; 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..a5fbc85d8f6 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::SqrtOrigin( endDiveDistanceSquared ); + Real currentDistance = WWMath::SqrtOrigin( currentDistanceSquared ); Real diveRatio = (startDiveDistance - currentDistance) / (startDiveDistance - endDiveDistance); @@ -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::Atan2Origin(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::SqrtOrigin(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..74b10c53d19 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp @@ -457,8 +457,8 @@ class JetOrHeliTaxiState : public AIMoveOutOfTheWayState Coord3D intermedPt; Bool intermed = false; - Real orient = atan2(ppinfo.runwayPrep.y - ppinfo.parkingSpace.y, ppinfo.runwayPrep.x - ppinfo.parkingSpace.x); - if (fabs(stdAngleDiff(orient, ppinfo.parkingOrientation)) > PI/128) + Real orient = WWMath::Atan2Origin(ppinfo.runwayPrep.y - ppinfo.parkingSpace.y, ppinfo.runwayPrep.x - ppinfo.parkingSpace.x); + if (WWMath::FAbsOrigin(stdAngleDiff(orient, ppinfo.parkingOrientation)) > PI/128) { intermedPt.z = (ppinfo.parkingSpace.z + ppinfo.runwayPrep.z) * 0.5f; intermed = intersectInfiniteLine2D( @@ -884,7 +884,7 @@ class HeliTakeoffOrLandingState : public State } else { - Real dist = sqrtf(dSqr); + Real dist = WWMath::SqrtfOrigin(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); @@ -1012,7 +1012,7 @@ class JetOrHeliParkOrientState : public State return STATE_FAILURE; const Real THRESH = 0.001f; - if (fabs(stdAngleDiff(jet->getOrientation(), ppinfo.parkingOrientation)) <= THRESH) + if (WWMath::FAbsOrigin(stdAngleDiff(jet->getOrientation(), ppinfo.parkingOrientation)) <= THRESH) return STATE_SUCCESS; // magically position it correctly. @@ -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(WWMath::Atan2Origin(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..ec81067b278 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::SqrtOrigin(sqr(dx)+sqr(dy)); if (xyDist<1) xyDist = 1; Real zFactor = 0; if (deltaZ>0) { @@ -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 = WWMath::SqrtfOrigin(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/POWTruckAIUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/POWTruckAIUpdate.cpp index dc83acdf5db..ac85df56e69 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/POWTruckAIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/POWTruckAIUpdate.cpp @@ -480,7 +480,7 @@ void POWTruckAIUpdate::updateCollectingTarget() { // are we close enough to tell them to start moving to us - Real distSq = pow( us->getGeometryInfo().getBoundingSphereRadius() * 2.0f, 2 ); + Real distSq = WWMath::PowOrigin( us->getGeometryInfo().getBoundingSphereRadius() * 2.0f, 2 ); if( ThePartitionManager->getDistanceSquared( us, target, FROM_CENTER_2D ) <= distSq ) { 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..78ba5dc24af 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)WWMath::SqrtfOrigin( 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. @@ -472,8 +472,8 @@ void RailroadBehavior::playImpactSound(Object *victim, const Coord3D *impactPosi impact.setPosition(impactPosition); if ( theirPhys ) { - vel += fabs(theirPhys->getVelocity()->length()); - mass += fabs(theirPhys->getMass()); + vel += WWMath::FAbsOrigin(theirPhys->getVelocity()->length()); + mass += WWMath::FAbsOrigin(theirPhys->getMass()); vel /= 2; mass /= 2;//average of him and me @@ -675,7 +675,7 @@ UpdateSleepTime RailroadBehavior::update() if ( m_conductorState == APPLY_BRAKES ) { conductorPullInfo.speed *= modData->m_braking; - if (fabs(conductorPullInfo.speed) < 0.01f) + if (WWMath::FAbsOrigin(conductorPullInfo.speed) < 0.01f) { conductorPullInfo.speed = 0; ///////////////////////////////////////( &m_hissySteamSound ); @@ -1193,7 +1193,7 @@ void alignToTerrain( Real angle, const Coord3D& pos, const Coord3D& normal, Matr x.normalize(); } - DEBUG_ASSERTCRASH(fabs(x.x*z.x + x.y*z.y + x.z*z.z)<0.0001,("dot is not zero")); + DEBUG_ASSERTCRASH(WWMath::FAbsOrigin(x.x*z.x + x.y*z.y + x.z*z.z)<0.0001,("dot is not zero")); // now computing the y vector is trivial. y.crossProduct( &z, &x, &y ); @@ -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::Atan2Origin(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..6054662da83 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::SqrtOrigin( 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::SqrtOrigin( 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..538123add49 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::SqrtOrigin(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..0487e1be939 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::SqrtOrigin(curDistSqr), WWMath::SqrtOrigin(closeEnoughSqr))); // Make it twitch a little. Coord3D newPos = *docker->getPosition(); Real range = 0.4*PATHFIND_CELL_SIZE_F; @@ -170,7 +170,7 @@ void SupplyWarehouseDockUpdate::setDockCrippled( Bool setting ) void SupplyWarehouseDockUpdate::setCashValue( Int cashValue ) { // A script can tell us our set value, and we need to figure out the boxes needed to provide that. - m_boxesStored = ceil(cashValue / (float)TheGlobalData->m_baseValuePerSupplyBox); + m_boxesStored = WWMath::CeilOrigin(cashValue / (float)TheGlobalData->m_baseValuePerSupplyBox); Drawable *draw = getObject()->getDrawable(); if( draw ) { diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp index 9bf55521dde..305979e6408 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp @@ -297,7 +297,7 @@ static Real calcTransform(const Object* obj, const Coord3D *pos, Real maxTurnRat Real angle = (Real)ACos( c ); Vector3 newDir; - if (fabs(angle) < maxTurnRate) + if (WWMath::FAbsOrigin(angle) < maxTurnRate) { // close enough -- point exactly in the right dir newDir = otherDir; @@ -355,7 +355,7 @@ void NeutronMissileUpdate::doAttack() // // Modulate speed according to turning. The more we have to turn, the slower we go // - Real angleCoeff = (Real)fabs( relAngle ) / (PI / 2.0f); + Real angleCoeff = (Real)WWMath::FAbsOrigin( relAngle ) / (PI / 2.0f); if (angleCoeff > 1.0f) angleCoeff = 1.0; } @@ -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::SqrtOrigin(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/PhysicsUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp index a56790b941f..df7bd65c63a 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp @@ -93,7 +93,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::SqrtOrigin(WWMath::FAbsOrigin(2.0f * TheGlobalData->m_gravity * height)); } //------------------------------------------------------------------------------------------------- @@ -438,7 +438,7 @@ Bool PhysicsBehavior::handleBounce(Real oldZ, Real newZ, Real groundZ, Coord3D* Real vz = getVelocity()->z; if (oldZ > groundZ && vz < 0.0f) { - desiredAccelZ = fabs(vz) * stiffness; + desiredAccelZ = WWMath::FAbsOrigin(vz) * stiffness; } bounceForce->x = 0.0f; @@ -470,7 +470,7 @@ Bool PhysicsBehavior::handleBounce(Real oldZ, Real newZ, Real groundZ, Coord3D* inline Bool isVerySmall3D(const Coord3D& v) { const Real THRESH = 0.01f; - return (fabs(v.x) < THRESH && fabs(v.y) < THRESH && fabs(v.z) < THRESH); + return (WWMath::FAbsOrigin(v.x) < THRESH && WWMath::FAbsOrigin(v.y) < THRESH && WWMath::FAbsOrigin(v.z) < THRESH); } //------------------------------------------------------------------------------------------------- @@ -569,9 +569,9 @@ UpdateSleepTime PhysicsBehavior::update() // when vel gets tiny, just clamp to zero const Real THRESH = 0.001f; - if (fabsf(m_vel.x) < THRESH) m_vel.x = 0.0f; - if (fabsf(m_vel.y) < THRESH) m_vel.y = 0.0f; - if (fabsf(m_vel.z) < THRESH) m_vel.z = 0.0f; + if (WWMath::FAbsfOrigin(m_vel.x) < THRESH) m_vel.x = 0.0f; + if (WWMath::FAbsfOrigin(m_vel.y) < THRESH) m_vel.y = 0.0f; + if (WWMath::FAbsfOrigin(m_vel.z) < THRESH) m_vel.z = 0.0f; m_velMag = INVALID_VEL_MAG; @@ -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 = WWMath::SqrtfOrigin(sqr(xvec.X) + sqr(xvec.Y)); + Real pitchAngle = WWMath::Atan2Origin(xvec.Z, xy); Real remainingAngle = (offset > 0) ? ((PI/2) - pitchAngle) : (-(PI/2) + pitchAngle); Real s = Sin(remainingAngle); pitchRateToUse *= s; @@ -737,8 +737,8 @@ UpdateSleepTime PhysicsBehavior::update() // going down hills don't injure themselves (unless the hill is really steep) const Real MIN_ANGLE_TAN = 3.0f; // roughly 71 degrees const Real TINY_DELTA = 0.01f; - if ((fabs(m_vel.x) <= TINY_DELTA || fabs(activeVelZ / m_vel.x) >= MIN_ANGLE_TAN) && - (fabs(m_vel.y) <= TINY_DELTA || fabs(activeVelZ / m_vel.y) >= MIN_ANGLE_TAN)) + if ((WWMath::FAbsOrigin(m_vel.x) <= TINY_DELTA || WWMath::FAbsOrigin(activeVelZ / m_vel.x) >= MIN_ANGLE_TAN) && + (WWMath::FAbsOrigin(m_vel.y) <= TINY_DELTA || WWMath::FAbsOrigin(activeVelZ / m_vel.y) >= MIN_ANGLE_TAN)) { Real damageAmt = netSpeed * getMass() * d->m_fallHeightDamageFactor; @@ -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)WWMath::SqrtfOrigin( sqr(m_vel.x) + sqr(m_vel.y) + sqr(m_vel.z) ); } return m_velMag; } @@ -839,7 +839,7 @@ Real PhysicsBehavior::getForwardSpeed2D() const Real speedSquared = vx*vx + vy*vy; // DEBUG_ASSERTCRASH( speedSquared != 0, ("zero speedSquared will overflow sqrtf()!") );// lorenzen... sanity check - Real speed = (Real)sqrtf( speedSquared ); + Real speed = (Real)WWMath::SqrtfOrigin( 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)WWMath::SqrtfOrigin( vx*vx + vy*vy + vz*vz ); if (dot >= 0.0f) return speed; @@ -885,7 +885,7 @@ Bool PhysicsBehavior::wasPreviouslyOverlapped(Object *obj) const //------------------------------------------------------------------------------------------------- void PhysicsBehavior::scrubVelocityZ( Real desiredVelocity ) { - if (fabs(desiredVelocity) < 0.001f) + if (WWMath::FAbsOrigin(desiredVelocity) < 0.001f) { m_vel.z = 0; } @@ -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 = WWMath::SqrtfOrigin(m_vel.x*m_vel.x + m_vel.y*m_vel.y); if (desiredVelocity > curVelocity) { return; @@ -992,9 +992,9 @@ void PhysicsBehavior::doBounceSound(const Coord3D& prevPos) //Real vel = fabs(getVelocity()->z); // can't use velocity, because it's already been updated this frame, and will be zero... (srj) - Real vel = fabs(prevPos.z - getObject()->getPosition()->z); + Real vel = WWMath::FAbsOrigin(prevPos.z - getObject()->getPosition()->z); - Real mass = fabs(getMass()); + Real mass = WWMath::FAbsOrigin(getMass()); if (vel > NORMAL_VEL_Z) { vel = NORMAL_VEL_Z; } @@ -1194,7 +1194,7 @@ void PhysicsBehavior::onCollide( Object *other, const Coord3D *loc, const Coord3 m_lastCollidee = other->getID(); - Real dist = sqrtf(distSqr); + Real dist = WWMath::SqrtfOrigin(distSqr); Real overlap = usRadius + themRadius - dist; // if objects are coincident, dist is zero, so force would be infinite -- clearly @@ -1297,7 +1297,7 @@ static Bool perpsLogicallyEqual( Real perpOne, Real perpTwo ) { // Equality with a wiggle fudge. const Real PERP_RANGE = 0.15f; - return fabs( perpOne - perpTwo ) <= PERP_RANGE; + return WWMath::FAbsOrigin( perpOne - perpTwo ) <= PERP_RANGE; } //------------------------------------------------------------------------------------------------- diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp index 1e9302a3327..6bd4e5d9441 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::SqrtOrigin( 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::SqrtOrigin( 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::SqrtOrigin( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); } } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp index ca2af15e7dc..9d542899c41 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp @@ -411,7 +411,7 @@ UpdateSleepTime StealthUpdate::update() m_disguiseHalfpointReached = true; } //Opacity ranges from full to none at midpoint and full again at the end - Real opacity = fabs( 1.0f - (factor * 2.0f) ); + Real opacity = WWMath::FAbsOrigin( 1.0f - (factor * 2.0f) ); Real overrideOpacity = opacity < 1.0f ? 0.0f : 1.0f; draw->setEffectiveOpacity( opacity, overrideOpacity ); if( !m_disguiseTransitionFrames && !m_transitioningToDisguise ) diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/TensileFormationUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/TensileFormationUpdate.cpp index a0e9296ccdc..cf1657308fb 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/TensileFormationUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/TensileFormationUpdate.cpp @@ -348,7 +348,7 @@ UpdateSleepTime TensileFormationUpdate::update() else draw->clearModelConditionFlags(MAKE_MODELCONDITION_MASK(MODELCONDITION_MOVING)); - if ( fabs( pos->z - newPos.z ) > 0.2f && m_life < 100) + if ( WWMath::FAbsOrigin( pos->z - newPos.z ) > 0.2f && m_life < 100) draw->setModelConditionFlags(MAKE_MODELCONDITION_MASK(MODELCONDITION_FREEFALL)); else draw->clearModelConditionFlags(MAKE_MODELCONDITION_MASK(MODELCONDITION_FREEFALL)); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp index bd725493a58..f74ef2c8211 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp @@ -130,7 +130,7 @@ static Real angleClosestTo(Real a1, Real a2, Real desired) { a1 = normalizeAngle(a1); a2 = normalizeAngle(a2); - return (fabs(stdAngleDiff(desired, a1)) < fabs(stdAngleDiff(desired, a2))) ? a1 : a2; + return (WWMath::FAbsOrigin(stdAngleDiff(desired, a1)) < WWMath::FAbsOrigin(stdAngleDiff(desired, a2))) ? a1 : a2; } //------------------------------------------------------------------------------------------------- @@ -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(WWMath::Atan2Origin(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 @@ -298,7 +298,7 @@ UpdateSleepTime ToppleUpdate::update() m_angularVelocity *= -d->m_bounceVelocityPercent; if( BitIsSet( m_options, TOPPLE_OPTIONS_NO_BOUNCE ) == TRUE || - fabs(m_angularVelocity) < VELOCITY_BOUNCE_LIMIT ) + WWMath::FAbsOrigin(m_angularVelocity) < VELOCITY_BOUNCE_LIMIT ) { // too slow, just stop m_angularVelocity = 0; @@ -338,7 +338,7 @@ UpdateSleepTime ToppleUpdate::update() } } } - else if( fabs(m_angularVelocity) >= VELOCITY_BOUNCE_SOUND_LIMIT ) + else if( WWMath::FAbsOrigin(m_angularVelocity) >= VELOCITY_BOUNCE_SOUND_LIMIT ) { // fast enough bounce to warrant the bounce fx if( BitIsSet( m_options, TOPPLE_OPTIONS_NO_FX ) == FALSE ) diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp index 2fdd9fa4dbf..13aa3afd1e6 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp @@ -383,8 +383,8 @@ void WeaponTemplate::reset() // No matter what we have now, we want to convert it to frames from msec. // ShotDelay used to use parseDurationUnsignedInt, and we are expanding on that. - self->m_minDelayBetweenShots = ceilf(ConvertDurationFromMsecsToFrames((Real)self->m_minDelayBetweenShots)); - self->m_maxDelayBetweenShots = ceilf(ConvertDurationFromMsecsToFrames((Real)self->m_maxDelayBetweenShots)); + self->m_minDelayBetweenShots = WWMath::CeilfOrigin(ConvertDurationFromMsecsToFrames((Real)self->m_minDelayBetweenShots)); + self->m_maxDelayBetweenShots = WWMath::CeilfOrigin(ConvertDurationFromMsecsToFrames((Real)self->m_maxDelayBetweenShots)); } @@ -847,7 +847,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?",WWMath::SqrtfOrigin(distSqr),WWMath::SqrtfOrigin(minAttackRangeSqr))); //-extraLogging #if defined(RTS_DEBUG) @@ -873,7 +873,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::Atan2Origin(victimPos->y - sourcePos->y, victimPos->x - sourcePos->x)) : 0.0f; VeterancyLevel v = sourceObj->getVeterancyLevel(); const FXList* fx = isProjectileDetonation ? getProjectileDetonateFX(v) : getFireFX(v); @@ -1920,11 +1920,11 @@ 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::Atan2Origin(-dir.y, -dir.x); Real relAngle = source->getOrientation()- angle; if (relAngle>2*PI) relAngle -= 2*PI; if (relAngle<-2*PI) relAngle += 2*PI; - if (fabs(relAngle)getPosition(); const Real ACCEPTABLE_DZ = 10.0f; - if (fabs(dst->z - src->z) < ACCEPTABLE_DZ) + if (WWMath::FAbsOrigin(dst->z - src->z) < ACCEPTABLE_DZ) return true; // always good enough if dz is small, regardless of pitch Real minPitch, maxPitch; diff --git a/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp index 7092303fa64..c52d014f622 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp @@ -808,7 +808,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::SqrtOrigin( sqr(p1.x-p2.x) + sqr(p1.y-p2.y) ); } } else diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp index 69d44b5edc1..d47a41250fd 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp @@ -2433,7 +2433,7 @@ void Player::doBountyForKill(const Object* killer, const Object* victim) Int bounty = REAL_TO_INT_CEIL(costToBuild * m_cashBountyPercent); #else // TheSuperHackers @bugfix Stubbjax 20/02/2026 Subtract epsilon to ensure bounty is rounded up correctly. - Int bounty = ceil((costToBuild * m_cashBountyPercent) - WWMATH_EPSILON); + Int bounty = WWMath::CeilOrigin((costToBuild * m_cashBountyPercent) - WWMATH_EPSILON); #endif if( bounty ) diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp index 725e921edda..f3c8de32339 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp @@ -1435,7 +1435,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::SqrtOrigin(WWMath::PowOrigin(gi.getMajorRadius(), 2) + WWMath::PowOrigin(gi.getMinorRadius(), 2)); 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..9f2e61f71af 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/Geometry.cpp +++ b/GeneralsMD/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::SqrtOrigin(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::Atan2Origin(dz, dxy); dz = (thatPos.z - that.getMaxHeightBelowPosition()) - thisCenter.z; - minPitch = atan2(dz, dxy); + minPitch = WWMath::Atan2Origin(dz, dxy); } //============================================================================= @@ -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::SqrtOrigin(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::SqrtOrigin(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 = WWMath::SqrtOrigin(sqr(m_majorRadius) + sqr(m_minorRadius)); + m_boundingSphereRadius = WWMath::SqrtOrigin(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..ca07f65983c 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp @@ -17,129 +17,42 @@ */ //////////////////////////////////////////////////////////////////////////////// -// // -// (c) 2001-2003 Electronic Arts Inc. // -// // +// // +// (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 +// TheSuperHackers @refactor Redirect legacy trig functions to deterministic WWMath wrappers. +// Original implementations called CRT float functions (sinf, cosf, acosf, asinf, tanf). #include "PreRTS.h" -#include -#include - #include "Lib/BaseType.h" #include "Lib/trig.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 +#include "WWMath/wwmath.h" Real Sin(Real x) { - return sinf(x); + return WWMath::SinTrig(x); } Real Cos(Real x) { - return cosf(x); + return WWMath::CosTrig(x); } Real Tan(Real x) { - return tanf(x); + return WWMath::TanTrig(x); } Real ACos(Real x) { - return acosf(x); + return WWMath::ACosTrig(x); } Real ASin(Real x) { - return asinf(x); + return WWMath::ASinTrig(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; igetDistanceSquared(me, theEnemy, FROM_BOUNDINGSPHERE_2D); - Real dist = sqrt(distSqr); + Real dist = WWMath::SqrtOrigin(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 ad587dd12fe..93fb03b1e72 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp @@ -489,7 +489,7 @@ Object *AIPlayer::buildStructureNow(const ThingTemplate *bldgPlan, BuildListInfo { Coord3D rallyPoint; Bool gotOffset = false; - if (fabs(info->getRallyOffset()->x) > 1.0f || fabs(info->getRallyOffset()->y)>1.0f) { + if (WWMath::FAbsOrigin(info->getRallyOffset()->x) > 1.0f || WWMath::FAbsOrigin(info->getRallyOffset()->y)>1.0f) { gotOffset; } if (!exitInterface->getNaturalRallyPoint(rallyPoint)) { @@ -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::SqrtOrigin(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); if (count<2) count = 2; Int i; color.green = 1; @@ -669,7 +669,7 @@ Object *AIPlayer::buildStructureWithDozer(const ThingTemplate *bldgPlan, BuildLi { Coord3D rallyPoint; Bool gotOffset = false; - if (fabs(info->getRallyOffset()->x) > 1.0f || fabs(info->getRallyOffset()->y)>1.0f) { + if (WWMath::FAbsOrigin(info->getRallyOffset()->x) > 1.0f || WWMath::FAbsOrigin(info->getRallyOffset()->y)>1.0f) { gotOffset; } if (!exitInterface->getNaturalRallyPoint(rallyPoint)) { @@ -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)) @@ -3139,7 +3139,7 @@ void AIPlayer::computeCenterAndRadiusOfBase(Coord3D *center, Real *radius) Real radSqr = dx*dx+dy*dy; if (radSqr>maxRadSqr) maxRadSqr=radSqr; } - *radius = sqrt(maxRadSqr); + *radius = WWMath::SqrtOrigin(maxRadSqr); } //---------------------------------------------------------------------------------------------------------- diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp index ed72618ea52..46471922c06 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp @@ -527,7 +527,7 @@ StateReturnType AIRappelState::onEnter() obj->setLayer(layerAtDest); AIUpdateInterface *ai = obj->getAI(); - Real MAX_RAPPEL_RATE = fabs(TheGlobalData->m_gravity) * LOGICFRAMES_PER_SECOND * 2.5f; + Real MAX_RAPPEL_RATE = WWMath::FAbsOrigin(TheGlobalData->m_gravity) * LOGICFRAMES_PER_SECOND * 2.5f; m_rappelRate = -min(ai->getDesiredSpeed(), MAX_RAPPEL_RATE); return STATE_CONTINUE; @@ -3674,7 +3674,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::SqrtOrigin(distSqr))); ret = STATE_CONTINUE; m_retryCount--; @@ -3904,7 +3904,7 @@ 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::Atan2Origin(dy, dx); Real deltaAngle = angle - m_angle; Real s = sin(deltaAngle); Real c = cos(deltaAngle); @@ -3913,7 +3913,7 @@ void AIFollowWaypointPathState::computeGoal(Bool useGroupOffsets) m_groupOffset.x = x; m_groupOffset.y = y; } else { - angle = atan2(dy, dx); + angle = WWMath::Atan2Origin(dy, dx); } m_angle = angle; #endif @@ -5078,7 +5078,7 @@ StateReturnType AIAttackAimAtTargetState::update() //DEBUG_LOG(("AIM: desired %f, actual %f, delta %f, aimDelta %f, goalpos %f %f",rad2deg(obj->getOrientation() + relAngle),rad2deg(obj->getOrientation()),rad2deg(relAngle),rad2deg(aimDelta),victim->getPosition()->x,victim->getPosition()->y)); if (m_canTurnInPlace) { - if (fabs(relAngle) > aimDelta) + if (WWMath::FAbsOrigin(relAngle) > aimDelta) { Real desiredAngle = source->getOrientation() + relAngle; sourceAI->setLocomotorGoalOrientation(desiredAngle); @@ -5090,7 +5090,7 @@ StateReturnType AIAttackAimAtTargetState::update() sourceAI->setLocomotorGoalPositionExplicit(m_isAttackingObject ? *victim->getPosition() : *getMachineGoalPosition()); } - if (fabs(relAngle) < aimDelta /*&& !m_preAttackFrames*/ ) + if (WWMath::FAbsOrigin(relAngle) < aimDelta /*&& !m_preAttackFrames*/ ) { AIUpdateInterface* victimAI = victim ? victim->getAI() : nullptr; // add ourself as a targeter BEFORE calling isTemporarilyPreventingAimSuccess(). @@ -7484,7 +7484,7 @@ StateReturnType AIFaceState::update() Real relAngle = ThePartitionManager->getRelativeAngle2D( obj, pos ); const Real REL_THRESH = 0.035f; // about 2 degrees. (getRelativeAngle2D is current only accurate to about 1.25 degrees) - if( fabs( relAngle ) < REL_THRESH ) + if( WWMath::FAbsOrigin( relAngle ) < REL_THRESH ) { return STATE_SUCCESS; } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp index 78395baf998..09bf72c68bf 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp @@ -386,7 +386,7 @@ Bool TurretAI::friend_turnTowardsAngle(Real desiredAngle, Real rateModifier, Rea Real angleDiff = normalizeAngle(desiredAngle - actualAngle); // Are we close enough to the desired angle to just snap there? - if (fabs(angleDiff) < turnRate) + if (WWMath::FAbsOrigin(angleDiff) < turnRate) { // we are centered actualAngle = desiredAngle; @@ -409,7 +409,7 @@ Bool TurretAI::friend_turnTowardsAngle(Real desiredAngle, Real rateModifier, Rea if( m_angle != origAngle ) getOwner()->reactToTurretChange( m_whichTurret, origAngle, m_pitch ); - Bool aligned = fabs(m_angle - desiredAngle) <= relThresh; + Bool aligned = WWMath::FAbsOrigin(m_angle - desiredAngle) <= relThresh; return aligned; } @@ -427,7 +427,7 @@ Bool TurretAI::friend_turnTowardsPitch(Real desiredPitch, Real rateModifier) Real pitchRate = getPitchRate() * rateModifier; Real pitchDiff = normalizeAngle(desiredPitch - actualPitch); - if (fabs(pitchDiff) < pitchRate) + if (WWMath::FAbsOrigin(pitchDiff) < pitchRate) { // we are centered actualPitch = desiredPitch; @@ -1087,7 +1087,7 @@ StateReturnType TurretAIAimTurretState::update() turret->friend_setPositiveSweep(!turret->friend_getPositiveSweep()); Real angleDiff = normalizeAngle(relAngle - turret->getTurretAngle()); - turnAlignedToNemesis = (fabs(angleDiff) < sweep); + turnAlignedToNemesis = (WWMath::FAbsOrigin(angleDiff) < sweep); } Bool pitchAlignedToNemesis = true; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp index 4f19ee9cfc2..5a1c6f524ae 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::SqrtOrigin(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..bb894275466 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 WWMath::Atan2Origin(xvec.y, xvec.x) == angle. So we must construct the matrix carefully to ensure this! */ x.x = Cos( angle ); @@ -1489,7 +1489,7 @@ void makeAlignToNormalMatrix( Real angle, const Coord3D& pos, const Coord3D& nor x.normalize(); } - DEBUG_ASSERTCRASH(fabs(x.x*z.x + x.y*z.y + x.z*z.z)<0.0001,("dot is not zero (%f)",fabs(x.x*z.x + x.y*z.y + x.z*z.z))); + DEBUG_ASSERTCRASH(WWMath::FAbsOrigin(x.x*z.x + x.y*z.y + x.z*z.z)<0.0001,("dot is not zero (%f)",WWMath::FAbsOrigin(x.x*z.x + x.y*z.y + x.z*z.z))); // now computing the y vector is trivial. y.crossProduct( &z, &x, &y ); @@ -1685,12 +1685,12 @@ PathfindLayerEnum TerrainLogic::getLayerForDestination(const Coord3D *pos) { Bridge *pBridge = getFirstBridge(); PathfindLayerEnum bestLayer = LAYER_GROUND; - Real bestDistance = fabs(pos->z - getGroundHeight(pos->x, pos->y)); + Real bestDistance = WWMath::FAbsOrigin(pos->z - getGroundHeight(pos->x, pos->y)); if (bestDistance > TheAI->pathfinder()->getWallHeight()/2) { // check wall. if (TheAI->pathfinder()->isPointOnWall(pos)) { - Real delta = fabs(pos->z-TheAI->pathfinder()->getWallHeight()); + Real delta = WWMath::FAbsOrigin(pos->z-TheAI->pathfinder()->getWallHeight()); if (deltaisPointOnBridge(pos) ) { - Real delta = fabs(pos->z-pBridge->getBridgeHeight(pos, nullptr)); + Real delta = WWMath::FAbsOrigin(pos->z-pBridge->getBridgeHeight(pos, nullptr)); if (deltagetLayer(); bestDistance = delta; @@ -1724,7 +1724,7 @@ PathfindLayerEnum TerrainLogic::getHighestLayerForDestination(const Coord3D *pos if (TheAI->pathfinder()->isPointOnWall(pos)) { Real delta = pos->z - TheAI->pathfinder()->getWallHeight(); // must be ABOVE (or on) the wall for this call. (srj) - if (delta >= 0 && fabs(delta) < fabs(bestDistance)) { + if (delta >= 0 && WWMath::FAbsOrigin(delta) < WWMath::FAbsOrigin(bestDistance)) { bestLayer = (PathfindLayerEnum)LAYER_WALL; bestDistance = delta; } @@ -1739,7 +1739,7 @@ PathfindLayerEnum TerrainLogic::getHighestLayerForDestination(const Coord3D *pos if (pBridge->isPointOnBridge(pos) ) { Real delta = pos->z - pBridge->getBridgeHeight(pos, nullptr); // must be ABOVE (or on) the bridge for this call. (srj) - if (delta >= 0 && fabs(delta) < fabs(bestDistance)) { + if (delta >= 0 && WWMath::FAbsOrigin(delta) < WWMath::FAbsOrigin(bestDistance)) { bestLayer = pBridge->getLayer(); bestDistance = delta; } @@ -1788,7 +1788,7 @@ Bool TerrainLogic::objectInteractsWithBridgeLayer(Object *obj, Int layer, Bool c if (match) { Real bridgeHeight = pBridge->getBridgeHeight(obj->getPosition(), nullptr); - Real delta = fabs(obj->getPosition()->z-bridgeHeight); + Real delta = WWMath::FAbsOrigin(obj->getPosition()->z-bridgeHeight); if (delta>LAYER_Z_CLOSE_ENOUGH_F) { return false; } @@ -1837,7 +1837,7 @@ Bool TerrainLogic::objectInteractsWithBridgeEnd(Object *obj, Int layer) const if (match) { Real bridgeHeight = pBridge->getBridgeHeight(obj->getPosition(), nullptr); - Real delta = fabs(obj->getPosition()->z-bridgeHeight); + Real delta = WWMath::FAbsOrigin(obj->getPosition()->z-bridgeHeight); if (delta>LAYER_Z_CLOSE_ENOUGH_F) { return false; @@ -2055,10 +2055,10 @@ Coord3D TerrainLogic::findClosestEdgePoint ( const Coord3D *closestTo ) const getExtent( &mapExtent ); Real distances[4]; - distances[0] = fabs( closestTo->y - mapExtent.lo.y );//top - distances[1] = fabs( closestTo->x - mapExtent.hi.x );//right - distances[2] = fabs( closestTo->y - mapExtent.hi.y );//bottom - distances[3] = fabs( closestTo->x - mapExtent.lo.x );//left + distances[0] = WWMath::FAbsOrigin( closestTo->y - mapExtent.lo.y );//top + distances[1] = WWMath::FAbsOrigin( closestTo->x - mapExtent.hi.x );//right + distances[2] = WWMath::FAbsOrigin( closestTo->y - mapExtent.hi.y );//bottom + distances[3] = WWMath::FAbsOrigin( closestTo->x - mapExtent.lo.x );//left Real bestDistance = distances[0]; Int bestDistanceIndex = 0; for( Int lameIndex = 1; lameIndex < 4; lameIndex++ ) @@ -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::SqrtOrigin( 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 = WWMath::SqrtOrigin( 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 9b782240938..b17fcc0ac38 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp @@ -172,24 +172,24 @@ static Bool calcTrajectory( Real dz = end.z - start.z; // calculating the angle is trivial. - angle = atan2(dy, dx); + angle = WWMath::Atan2Origin(dy, dx); // calculating the pitch requires a bit more effort. Real horizDistSqr = sqr(dx) + sqr(dy); - Real horizDist = sqrt(horizDistSqr); + Real horizDist = WWMath::SqrtOrigin(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) - Real gravity = fabs(TheGlobalData->m_gravity); + Real gravity = WWMath::FAbsOrigin(TheGlobalData->m_gravity); Real gravityTwoDZ = gravity * 2.0f * dz; // 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::Atan2Origin(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; - if (fabs(theta) > SHALLOW_ANGLE) + if (WWMath::FAbsOrigin(theta) > SHALLOW_ANGLE) { Real t = horizDist / velocity; Real vz = (dz/t + 0.5f*gravity*t); @@ -290,7 +290,7 @@ static Bool calcTrajectory( #endif vx = velocity*cosPitches[preferred]; - Real actualRange = (vx*(vz + sqrt(root)))/gravity; + Real actualRange = (vx*(vz + WWMath::SqrtOrigin(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 = WWMath::SqrtOrigin(ThePartitionManager->getDistanceSquared( projectile, &victimPosToUse, FROM_CENTER_2D ) ); Real rangeRatio = (range - minRange) / (maxRange - minRange); m_flightPathSpeed = (rangeRatio * (weaponSpeed - minWeaponSpeed)) + minWeaponSpeed; } @@ -444,7 +444,7 @@ Bool DumbProjectileBehavior::calcFlightPath(Bool recalcNumSegments) if (recalcNumSegments) { Real flightDistance = flightCurve.getApproximateLength(); - m_flightPathSegments = ceil( flightDistance / m_flightPathSpeed ); + m_flightPathSegments = WWMath::CeilOrigin( flightDistance / m_flightPathSpeed ); } // TheSuperHackers @info The way flight paths are used requires at least two curve points. @@ -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 = WWMath::SqrtfOrigin(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..1f89505fc1f 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::SqrtOrigin(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..ec7c314fc70 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(WWMath::SqrtfOrigin(2.0f * (start.z - endOnGround.z) / WWMath::FAbsOrigin(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,8 +588,8 @@ 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)); - if (dist <= 0.1f && fabs(dz) <= 0.1f) + Real dist = WWMath::SqrtOrigin(sqr(dx) + sqr(dy)); + if (dist <= 0.1f && WWMath::FAbsOrigin(dz) <= 0.1f) { obj->setPosition(&endOnGround); m_scootFramesLeft = 0; @@ -598,7 +598,7 @@ void MinefieldBehavior::setScootParms(const Coord3D& start, const Coord3D& end) { Real t = (Real)scootFromStartingPointTime; Real scootFromStartingPointSpeed = dist / t; - Real accelMag = fabs(2.0f * (dist - scootFromStartingPointSpeed*t)/sqr(t)); + Real accelMag = WWMath::FAbsOrigin(2.0f * (dist - scootFromStartingPointSpeed*t)/sqr(t)); Real dxNorm = (dist <= 0.1f) ? 0.0f : (dx / dist); Real dyNorm = (dist <= 0.1f) ? 0.0f : (dy / dist); m_scootVel.x = dxNorm * scootFromStartingPointSpeed; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp index f2942322f9a..92dcfe36bbd 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::Atan2Origin(force.y, force.x); physics->setAngles(orientation, 0, 0); obj->getDrawable()->setModelConditionState(MODELCONDITION_EXPLODED_FLAILING); m_flags |= (1<getPosition()->z) >= d->m_paraOpenDist) + if (WWMath::FAbsOrigin(m_startZ - parachute->getPosition()->z) >= d->m_paraOpenDist) { m_opened = true; parachute->clearAndSetModelConditionState(MODELCONDITION_FREEFALL, MODELCONDITION_PARACHUTING); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp index 57392ff6db5..e942f2ed44d 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp @@ -84,7 +84,7 @@ static Real calcSlowDownDist(Real curSpeed, Real desiredSpeed, Real maxBraking) if (delta <= 0) return 0.0f; - Real dist = (sqr(delta) / fabs(maxBraking)) * 0.5f; + Real dist = (sqr(delta) / WWMath::FAbsOrigin(maxBraking)) * 0.5f; // use a little fudge so that things can stop "on a dime" more easily... const Real FUDGE = 1.05f; @@ -95,14 +95,14 @@ static Real calcSlowDownDist(Real curSpeed, Real desiredSpeed, Real maxBraking) inline Bool isNearlyZero(Real a) { const Real TINY_EPSILON = 0.001f; - return fabs(a) < TINY_EPSILON; + return WWMath::FAbsOrigin(a) < TINY_EPSILON; } //----------------------------------------------------------------------------- inline Bool isNearly(Real a, Real val) { const Real TINY_EPSILON = 0.001f; - return fabs(a - val) < TINY_EPSILON; + return WWMath::FAbsOrigin(a - val) < TINY_EPSILON; } //----------------------------------------------------------------------------- @@ -141,7 +141,7 @@ static Real tryToRotateVector3D( } } - if (fabs(angleBetween) <= maxAngle) + if (WWMath::FAbsOrigin(angleBetween) <= maxAngle) { // close enough actualDir = goalDir; @@ -231,9 +231,9 @@ static void calcDirectionToApplyThrust( Bool foundSolution = false; Real distToGoalSqr = vecToGoal.Length2(); - Real distToGoal = sqrt(distToGoalSqr); + Real distToGoal = WWMath::SqrtOrigin(distToGoalSqr); Real curVelMagSqr = curVel.Length2(); - Real curVelMag = sqrt(curVelMagSqr); + Real curVelMag = WWMath::SqrtOrigin(curVelMagSqr); Real maxAccelSqr = sqr(maxAccel); Real denom = curVelMagSqr - maxAccelSqr; @@ -995,7 +995,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::SqrtOrigin(dx*dx+dy*dy); if (dist>onPathDistToGoal) { if (!obj->isKindOf(KINDOF_PROJECTILE) && dist>2*onPathDistToGoal) @@ -1113,7 +1113,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::SqrtOrigin(dx*dx+dy*dy+dz*dz); Real vel = physics->getVelocityMagnitude(); if (vel < MIN_VEL) vel = MIN_VEL; @@ -1137,7 +1137,7 @@ void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalP // Normalize. if (dist > 0.001f) { - Real vel = fabs(physics->getForwardSpeed2D()); + Real vel = WWMath::FAbsOrigin(physics->getForwardSpeed2D()); if (vel < MIN_VEL) vel = MIN_VEL; if (vel > dist) @@ -1182,7 +1182,7 @@ void Locomotor::moveTowardsPositionTreads(Object* obj, PhysicsBehavior *physics, // Modulate speed according to turning. The more we have to turn, the slower we go // const Real QUAETERPI = PI / 4.0f; - Real angleCoeff = (Real)fabs( relAngle ) / QUAETERPI; + Real angleCoeff = (Real)WWMath::FAbsOrigin( relAngle ) / QUAETERPI; if (angleCoeff > 1.0f) angleCoeff = 1.0; @@ -1253,7 +1253,7 @@ void Locomotor::moveTowardsPositionTreads(Object* obj, PhysicsBehavior *physics, see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (fabs(accelForce) > fabs(maxForceNeeded)) + if (WWMath::FAbsOrigin(accelForce) > WWMath::FAbsOrigin(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); @@ -1288,7 +1288,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::Atan2Origin(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real relAngle = stdAngleDiff(desiredAngle, angle); Bool moveBackwards = false; @@ -1305,14 +1305,14 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, #if 1 if (actualSpeed==0.0f) { setFlag(MOVING_BACKWARDS, false); - if (m_template->m_canMoveBackward && fabs(relAngle) > PI/2) { + if (m_template->m_canMoveBackward && WWMath::FAbsOrigin(relAngle) > PI/2) { setFlag(MOVING_BACKWARDS, true ); setFlag(DOING_THREE_POINT_TURN, onPathDistToGoal>5*obj->getGeometryInfo().getMajorRadius()); } } if (getFlag(MOVING_BACKWARDS)) { - if (fabs(relAngle) < PI/2) { + if (WWMath::FAbsOrigin(relAngle) < PI/2) { moveBackwards = false; setFlag(MOVING_BACKWARDS, false); } else { @@ -1328,7 +1328,7 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, #endif const Real SMALL_TURN = PI / 20.0f; - if ((Real)fabs( relAngle ) > SMALL_TURN) + if ((Real)WWMath::FAbsOrigin( relAngle ) > SMALL_TURN) { if (desiredSpeed>turnSpeed) { @@ -1353,7 +1353,7 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, const Real FIFTEEN_DEGREES = PI / 12.0f; const Real PROJECT_FRAMES = LOGICFRAMES_PER_SECOND/2; // Project out 1/2 second. - if (fabs( relAngle ) > FIFTEEN_DEGREES) + if (WWMath::FAbsOrigin( relAngle ) > FIFTEEN_DEGREES) { // If we're turning more than 10 degrees, check & see if we're moving into "impassable territory" Real distance = PROJECT_FRAMES * (goalSpeed+actualSpeed)/2.0f; @@ -1492,7 +1492,7 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (fabs(accelForce) > fabs(maxForceNeeded)) + if (WWMath::FAbsOrigin(accelForce) > WWMath::FAbsOrigin(maxForceNeeded)) accelForce = maxForceNeeded; //DEBUG_LOG(("Braking %d, actualSpeed %f, goalSpeed %f, delta %f, accel %f", getFlag(IS_BRAKING), @@ -1563,7 +1563,7 @@ Bool Locomotor::fixInvalidPosition(Object* obj, PhysicsBehavior *physics) //physics->clearAcceleration(); if (dot<0) { - dot = sqrt(-dot); + dot = WWMath::SqrtOrigin(-dot); correctionNormalized.x *= dot*physics->getMass(); correctionNormalized.y *= dot*physics->getMass(); physics->applyMotiveForce(&correctionNormalized); @@ -1627,7 +1627,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::Atan2Origin(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; @@ -1653,7 +1653,7 @@ void Locomotor::moveTowardsPositionLegs(Object* obj, PhysicsBehavior *physics, c // Modulate speed according to turning. The more we have to turn, the slower we go // const Real QUARTERPI = PI / 4.0f; - Real angleCoeff = (Real)fabs( relAngle ) / (QUARTERPI); + Real angleCoeff = (Real)WWMath::FAbsOrigin( relAngle ) / (QUARTERPI); if (angleCoeff > 1.0f) angleCoeff = 1.0; @@ -1683,7 +1683,7 @@ void Locomotor::moveTowardsPositionLegs(Object* obj, PhysicsBehavior *physics, c see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (fabs(accelForce) > fabs(maxForceNeeded)) + if (WWMath::FAbsOrigin(accelForce) > WWMath::FAbsOrigin(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); @@ -1725,7 +1725,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, if (dz*dz > sqr(PATHFIND_CELL_SIZE_F)) { setFlag(CLIMBING, true); } - if (fabs(dz)<1) { + if (WWMath::FAbsOrigin(dz)<1) { setFlag(CLIMBING, false); } @@ -1745,7 +1745,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, moveBackwards = true; } - Real groundSlope = fabs(delta.z - pos.z); + Real groundSlope = WWMath::FAbsOrigin(delta.z - pos.z); if (groundSlope<1.0f) groundSlope = 1.0f; if (groundSlope>1.0f) { @@ -1760,7 +1760,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::Atan2Origin(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real relAngle = stdAngleDiff(desiredAngle, angle); if (moveBackwards) { @@ -1774,7 +1774,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, // Modulate speed according to turning. The more we have to turn, the slower we go // const Real QUARTERPI = PI / 4.0f; - Real angleCoeff = (Real)fabs( relAngle ) / (QUARTERPI); + Real angleCoeff = (Real)WWMath::FAbsOrigin( relAngle ) / (QUARTERPI); if (angleCoeff > 1.0f) angleCoeff = 1.0; @@ -1816,7 +1816,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (fabs(accelForce) > fabs(maxForceNeeded)) + if (WWMath::FAbsOrigin(accelForce) > WWMath::FAbsOrigin(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); @@ -1843,7 +1843,7 @@ void Locomotor::moveTowardsPositionWings(Object* obj, PhysicsBehavior *physics, Real dx = goalPos.x - pos->x; Real dy = goalPos.y - pos->y; Real dz = goalPos.z - pos->z; - if (fabs(dz) > m_circleThresh) + if (WWMath::FAbsOrigin(dz) > m_circleThresh) { // aim for the spot on the opposite side of the circle. @@ -1851,7 +1851,7 @@ void Locomotor::moveTowardsPositionWings(Object* obj, PhysicsBehavior *physics, Real angleTowardPos = (isNearlyZero(dx) && isNearlyZero(dy)) ? obj->getOrientation() : - atan2(dy, dx); + WWMath::Atan2Origin(dy, dx); Real aimDir = (PI - PI/8); angleTowardPos += aimDir; @@ -1940,7 +1940,7 @@ void Locomotor::moveTowardsPositionThrust(Object* obj, PhysicsBehavior *physics, // so we tend to "level out" at that height. we don't use this till // below, but go ahead and calc it now... Real MAX_VERTICAL_DAMP_RANGE = m_preferredHeight * 0.5; - delta = fabs(delta); + delta = WWMath::FAbsOrigin(delta); if (delta > MAX_VERTICAL_DAMP_RANGE) delta = MAX_VERTICAL_DAMP_RANGE; zDirDamping = 1.0f - (delta / MAX_VERTICAL_DAMP_RANGE); @@ -2057,7 +2057,7 @@ Real Locomotor::calcLiftToUseAtPt(Object* obj, PhysicsBehavior *physics, Real cu // see how far we need to slow to dead stop, given max braking Real desiredAccel; const Real TINY_ACCEL = 0.001f; - if (fabs(maxAccel) > TINY_ACCEL) + if (WWMath::FAbsOrigin(maxAccel) > TINY_ACCEL) { Real deltaZ = preferredHeight - curZ; // calc how far it will take for us to go from cur speed to zero speed, at max accel. @@ -2065,14 +2065,14 @@ Real Locomotor::calcLiftToUseAtPt(Object* obj, PhysicsBehavior *physics, Real cu // in theory, the above is the correct calculation, but in practice, // doesn't work in some situations (eg, opening of USA01 map). Why, I dunno. // But for now I have gone back to the old, looks-incorrect-to-me-but-works calc. (srj) - Real brakeDist = (sqr(curVelZ) / fabs(maxAccel)); - if (fabs(brakeDist) > fabs(deltaZ)) + Real brakeDist = (sqr(curVelZ) / WWMath::FAbsOrigin(maxAccel)); + if (WWMath::FAbsOrigin(brakeDist) > WWMath::FAbsOrigin(deltaZ)) { // if the dist-to-accel (or dist-to-brake) is further than the dist-to-go, // use the max accel. desiredAccel = maxAccel; } - else if (fabs(curVelZ) > m_template->m_speedLimitZ) + else if (WWMath::FAbsOrigin(curVelZ) > m_template->m_speedLimitZ) { // or, if we're going too fast, limit it here. desiredAccel = m_template->m_speedLimitZ - curVelZ; @@ -2146,8 +2146,8 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 Real dx =goalPos.x - turnPos.x; 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); + if (WWMath::FAbsOrigin(dx)<0.1f && WWMath::FAbsOrigin(dy)<0.1f) return TURN_NONE; + Real desiredAngle = WWMath::Atan2Origin(dy, dx); Real amount = stdAngleDiff(desiredAngle, angle); if (relAngle) *relAngle = amount; if (amount>maxTurnRate) { @@ -2169,7 +2169,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::Atan2Origin(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 +2185,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::Atan2Origin(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real amount = stdAngleDiff(desiredAngle, angle); if (relAngle) *relAngle = amount; if (amount>maxTurnRate) { @@ -2363,8 +2363,8 @@ void Locomotor::moveTowardsPositionOther(Object* obj, PhysicsBehavior *physics, //fabs(goalPos.y - pos->y),fabs(goalPos.x - pos->x), //fabs(goalPos.y - pos->y)/goalSpeed,fabs(goalPos.x - pos->x)/goalSpeed)); if (getFlag(ULTRA_ACCURATE) && - fabs(goalPos.y - pos->y) <= goalSpeed * m_template->m_ultraAccurateSlideIntoPlaceFactor && - fabs(goalPos.x - pos->x) <= goalSpeed * m_template->m_ultraAccurateSlideIntoPlaceFactor) + WWMath::FAbsOrigin(goalPos.y - pos->y) <= goalSpeed * m_template->m_ultraAccurateSlideIntoPlaceFactor && + WWMath::FAbsOrigin(goalPos.x - pos->x) <= goalSpeed * m_template->m_ultraAccurateSlideIntoPlaceFactor) { // don't turn, just slide in the right direction physics->setTurning(TURN_NONE); @@ -2403,7 +2403,7 @@ void Locomotor::moveTowardsPositionOther(Object* obj, PhysicsBehavior *physics, see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (fabs(accelForce) > fabs(maxForceNeeded)) + if (WWMath::FAbsOrigin(accelForce) > WWMath::FAbsOrigin(maxForceNeeded)) accelForce = maxForceNeeded; Coord3D force; @@ -2519,7 +2519,7 @@ void Locomotor::maintainCurrentPositionWings(Object* obj, PhysicsBehavior *physi Real angleTowardMaintainPos = (isNearlyZero(dx) && isNearlyZero(dy)) ? obj->getOrientation() : - atan2(dy, dx); + WWMath::Atan2Origin(dy, dx); Real aimDir = (PI - PI/8); if (turnRadius < 0) @@ -2553,7 +2553,7 @@ void Locomotor::maintainCurrentPositionHover(Object* obj, PhysicsBehavior *physi // Real minSpeed = max( 1.0E-10f, m_template->m_minSpeed ); Real speedDelta = minSpeed - actualSpeed; - if (fabs(speedDelta) > minSpeed) + if (WWMath::FAbsOrigin(speedDelta) > minSpeed) { Real mass = physics->getMass(); Real acceleration = (speedDelta > 0.0f) ? maxAcceleration : -getBraking(); @@ -2564,7 +2564,7 @@ void Locomotor::maintainCurrentPositionHover(Object* obj, PhysicsBehavior *physi see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (fabs(accelForce) > fabs(maxForceNeeded)) + if (WWMath::FAbsOrigin(accelForce) > WWMath::FAbsOrigin(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp index 0a03557b1b3..bb6d883cb27 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp @@ -1754,13 +1754,13 @@ inline Bool isPosDifferent(const Coord3D* a, const Coord3D* b) // so we must put in some cleverness... const Real THRESH = 0.01f; - if (fabs(a->x - b->x) > THRESH) + if (WWMath::FAbsOrigin(a->x - b->x) > THRESH) return true; - if (fabs(a->y - b->y) > THRESH) + if (WWMath::FAbsOrigin(a->y - b->y) > THRESH) return true; - if (fabs(a->z - b->z) > THRESH) + if (WWMath::FAbsOrigin(a->z - b->z) > THRESH) return true; return false; @@ -1776,7 +1776,7 @@ inline Bool isAngleDifferent(Real a, Real b) const Real THRESH = 0.01f; // in radians, this is approx 1/2 degree. - if (fabs(a - b) > THRESH) + if (WWMath::FAbsOrigin(a - b) > THRESH) return true; return false; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp index b23d6c603ae..89bb9f39023 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::SqrtOrigin( dx*dx + dy*dy ); //Normalize length dx /= length; @@ -357,7 +357,7 @@ class DeliverPayloadNugget : public ObjectCreationNugget } - Real orient = atan2( moveToPos.y - startPos.y, moveToPos.x - startPos.x); + Real orient = WWMath::Atan2Origin( moveToPos.y - startPos.y, moveToPos.x - startPos.x); if( m_data.m_distToTarget > 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 = WWMath::Atan2Origin(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::Atan2Origin(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 8d7c8402e3a..6f8bf73cb0c 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp @@ -415,13 +415,13 @@ static void testRotatedPointsAgainstRect( Real pty = pts->y - a->position.y; // inverse-rotate it to the right coord system - Real ptx_new = (Real)fabs(ptx*c - pty*s); - Real pty_new = (Real)fabs(ptx*s + pty*c); + Real ptx_new = (Real)WWMath::FAbsOrigin(ptx*c - pty*s); + Real pty_new = (Real)WWMath::FAbsOrigin(ptx*s + pty*c); #ifdef INTENSE_DEBUG Real mag_a = sqr(ptx)+sqr(pty); Real mag_b = sqr(ptx_new)+sqr(pty_new); - DEBUG_ASSERTCRASH(fabs(mag_a - mag_b) <= 1.0, ("hmm, unlikely")); + DEBUG_ASSERTCRASH(WWMath::FAbsOrigin(mag_a - mag_b) <= 1.0, ("hmm, unlikely")); #endif if (ptx_new <= major && pty_new <= minor) @@ -621,7 +621,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)WWMath::SqrtfOrigin(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: @@ -639,7 +639,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)WWMath::SqrtfOrigin(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: @@ -827,7 +827,7 @@ static Bool distCalcProc_BoundaryAndBoundary_2D( if (totalRad > 0.0f) { - Real actualDist = sqrtf(actualDistSqr); + Real actualDist = WWMath::SqrtfOrigin(actualDistSqr); Real shrunkenDist = actualDist - totalRad; if (shrunkenDist <= 0.0f) { @@ -915,7 +915,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 = WWMath::SqrtfOrigin(actualDistSqr); Real shrunkenDist = actualDist - totalRad; if (shrunkenDist <= 0.0f) { @@ -2226,7 +2226,7 @@ Int PartitionData::calcMaxCoiForShape(GeometryType geom, Real majorRadius, Real } case GEOMETRY_BOX: { - Real diagonal = (Real)(sqrtf(majorRadius*majorRadius + minorRadius*minorRadius)); + Real diagonal = (Real)(WWMath::SqrtfOrigin(majorRadius*majorRadius + minorRadius*minorRadius)); Int cells = ThePartitionManager->worldToCellDist(diagonal*2) + 1; result = cells * cells; break; @@ -2643,7 +2643,7 @@ static void calcHeights(const Region3D& world, Real cellSize, Int x, Int y, Real Real xbase = world.lo.x + (x * cellSize); Real ybase = world.lo.y + (y * cellSize); const Real ROUGH_STEP_SIZE = MAP_XY_FACTOR; // no point in stepping smaller than grid scale - Real numSteps = ceilf(cellSize / ROUGH_STEP_SIZE); + Real numSteps = WWMath::CeilfOrigin(cellSize / ROUGH_STEP_SIZE); Real step = cellSize / numSteps; loZ = HUGE_DIST; // huge positive hiZ = -HUGE_DIST; // huge negative @@ -3217,7 +3217,7 @@ Int PartitionManager::calcMinRadius(const ICoord2D& cur) } // double, not real - double dist = sqrtf(minDistSqr); + double dist = WWMath::SqrtfOrigin(minDistSqr); Int minRadius = REAL_TO_INT_CEIL( dist / m_cellSize ); return minRadius; @@ -3235,7 +3235,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::SqrtOrigin(dx*dx + dy*dy); m_maxGcoRadius = REAL_TO_INT_CEIL(maxPossibleDist / cellSize); @@ -3505,7 +3505,7 @@ Object *PartitionManager::getClosestObjects( } if (closestDistArg) { - *closestDistArg = (Real)sqrtf(closestDistSqr); + *closestDistArg = (Real)WWMath::SqrtfOrigin(closestDistSqr); } #ifdef RTS_DEBUG @@ -3632,7 +3632,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)WWMath::SqrtfOrigin(sqr(v.x) + sqr(v.y)); // normalize if (dist == 0.0f) @@ -3810,7 +3810,7 @@ Bool PartitionManager::tryPosition( const Coord3D *center, pos.z = TheTerrainLogic->getGroundHeight( pos.x, pos.y ); } - if (fabs(pos.z - center->z) > options->maxZDelta) + if (WWMath::FAbsOrigin(pos.z - center->z) > options->maxZDelta) return FALSE; // @@ -4566,7 +4566,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 WWMath::SqrtfOrigin(sqr(x1-x2) + sqr(y1-y2)); } //----------------------------------------------------------------------------- @@ -5757,7 +5757,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::SqrtOrigin( WWMath::PowOrigin(x - parms->xCenter, 2) + WWMath::PowOrigin(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5785,7 +5785,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::SqrtOrigin( WWMath::PowOrigin(x - parms->xCenter, 2) + WWMath::PowOrigin(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5813,7 +5813,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::SqrtOrigin( WWMath::PowOrigin(x - parms->xCenter, 2) + WWMath::PowOrigin(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5841,7 +5841,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::SqrtOrigin( WWMath::PowOrigin(x - parms->xCenter, 2) + WWMath::PowOrigin(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp index 5243446c6be..dc88acf91b3 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp @@ -1296,8 +1296,8 @@ Bool AIUpdateInterface::blockedBy(Object *other) // If we are near our final goal, don't get stuck. if (goalCell.x>0 && goalCell.y>0) { - Real dx = fabs(goalPos.x-pos.x); - Real dy = fabs(goalPos.y-pos.y); + Real dx = WWMath::FAbsOrigin(goalPos.x-pos.x); + Real dy = WWMath::FAbsOrigin(goalPos.y-pos.y); if (dxgetRelativeAngle2D( getObject(), &info.posOnPath ); } - if (fabs(deltaAngle)>PI/30) + if (WWMath::FAbsOrigin(deltaAngle)>PI/30) { return TRUE; } @@ -2272,7 +2272,7 @@ UpdateSleepTime AIUpdateInterface::doLocomotor() } else { - Real dist = sqrtf(dSqr); + Real dist = WWMath::SqrtfOrigin(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::SqrtOrigin( 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::SqrtOrigin(distSqr); } else { @@ -2514,7 +2514,7 @@ Real AIUpdateInterface::getLocomotorDistanceToGoal() } if (distropeLen < it->ropeLenMax) { - it->ropeSpeed += fabs(TheGlobalData->m_gravity); + it->ropeSpeed += WWMath::FAbsOrigin(TheGlobalData->m_gravity); if (it->ropeSpeed > d->m_ropeDropSpeed) it->ropeSpeed = d->m_ropeDropSpeed; it->ropeLen += it->ropeSpeed; @@ -762,7 +762,7 @@ class ChinookMoveToBldgState : public AIMoveToState StateReturnType status = AIMoveToState::update(); const Real THRESH = 3.0f; - if (status != STATE_CONTINUE && fabs(obj->getPosition()->z - m_destZ) > THRESH) + if (status != STATE_CONTINUE && WWMath::FAbsOrigin(obj->getPosition()->z - m_destZ) > THRESH) status = STATE_CONTINUE; return status; @@ -891,7 +891,7 @@ ChinookAIUpdateModuleData::ChinookAIUpdateModuleData() m_minDropHeight = 30.0f; m_ropeFinalHeight = 0.0f; m_ropeDropSpeed = 1e10f; // um, fast. - m_rappelSpeed = fabs(TheGlobalData->m_gravity) * LOGICFRAMES_PER_SECOND * 0.5f; + m_rappelSpeed = WWMath::FAbsOrigin(TheGlobalData->m_gravity) * LOGICFRAMES_PER_SECOND * 0.5f; m_ropeWobbleLen = 10.0f; m_ropeWobbleAmp = 1.0f; m_ropeWobbleRate = 0.1f; 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..3e6ead39fb1 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp @@ -202,8 +202,8 @@ UpdateSleepTime DeliverPayloadAIUpdate::update() { //Calc strafe ratio Real startDiveDistance = getData()->m_diveStartDistance; - Real endDiveDistance = sqrt( endDiveDistanceSquared ); - Real currentDistance = sqrt( currentDistanceSquared ); + Real endDiveDistance = WWMath::SqrtOrigin( endDiveDistanceSquared ); + Real currentDistance = WWMath::SqrtOrigin( currentDistanceSquared ); Real diveRatio = (startDiveDistance - currentDistance) / (startDiveDistance - endDiveDistance); @@ -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::Atan2Origin(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::SqrtOrigin(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 4aa23123c4d..8f970922928 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp @@ -516,8 +516,8 @@ class JetOrHeliTaxiState : public AIMoveOutOfTheWayState Coord3D intermedPt; Bool intermed = false; - Real orient = atan2(ppinfo.runwayPrep.y - ppinfo.parkingSpace.y, ppinfo.runwayPrep.x - ppinfo.parkingSpace.x); - if (fabs(stdAngleDiff(orient, ppinfo.parkingOrientation)) > PI/128) + Real orient = WWMath::Atan2Origin(ppinfo.runwayPrep.y - ppinfo.parkingSpace.y, ppinfo.runwayPrep.x - ppinfo.parkingSpace.x); + if (WWMath::FAbsOrigin(stdAngleDiff(orient, ppinfo.parkingOrientation)) > PI/128) { intermedPt.z = (ppinfo.parkingSpace.z + ppinfo.runwayPrep.z) * 0.5f; intermed = intersectInfiniteLine2D( @@ -1071,7 +1071,7 @@ class HeliTakeoffOrLandingState : public State } else { - Real dist = sqrtf(dSqr); + Real dist = WWMath::SqrtfOrigin(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); @@ -1199,7 +1199,7 @@ class JetOrHeliParkOrientState : public State return STATE_FAILURE; const Real THRESH = 0.001f; - if (fabs(stdAngleDiff(jet->getOrientation(), ppinfo.parkingOrientation)) <= THRESH) + if (WWMath::FAbsOrigin(stdAngleDiff(jet->getOrientation(), ppinfo.parkingOrientation)) <= THRESH) return STATE_SUCCESS; // magically position it correctly. @@ -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(WWMath::Atan2Origin(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 78b44dc99ca..08c342b7c03 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::SqrtOrigin(sqr(dx)+sqr(dy)); if (xyDist<1) xyDist = 1; Real zFactor = 0; if (deltaZ>0) { @@ -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 = WWMath::SqrtfOrigin(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/POWTruckAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/POWTruckAIUpdate.cpp index cfe716f8440..bcbab2e4600 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/POWTruckAIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/POWTruckAIUpdate.cpp @@ -480,7 +480,7 @@ void POWTruckAIUpdate::updateCollectingTarget() { // are we close enough to tell them to start moving to us - Real distSq = pow( us->getGeometryInfo().getBoundingSphereRadius() * 2.0f, 2 ); + Real distSq = WWMath::PowOrigin( us->getGeometryInfo().getBoundingSphereRadius() * 2.0f, 2 ); if( ThePartitionManager->getDistanceSquared( us, target, FROM_CENTER_2D ) <= distSq ) { 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..39847819b0c 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)WWMath::SqrtfOrigin( 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. @@ -467,8 +467,8 @@ void RailroadBehavior::playImpactSound(Object *victim, const Coord3D *impactPosi impact.setPosition(impactPosition); if ( theirPhys ) { - vel += fabs(theirPhys->getVelocity()->length()); - mass += fabs(theirPhys->getMass()); + vel += WWMath::FAbsOrigin(theirPhys->getVelocity()->length()); + mass += WWMath::FAbsOrigin(theirPhys->getMass()); vel /= 2; mass /= 2;//average of him and me @@ -700,7 +700,7 @@ UpdateSleepTime RailroadBehavior::update() if ( m_conductorState == APPLY_BRAKES ) { conductorPullInfo.speed *= modData->m_braking; - if (fabs(conductorPullInfo.speed) < 0.1f) + if (WWMath::FAbsOrigin(conductorPullInfo.speed) < 0.1f) { conductorPullInfo.speed = 0; ///////////////////////////////////////( &m_hissySteamSound ); @@ -1233,7 +1233,7 @@ void alignToTerrain( Real angle, const Coord3D& pos, const Coord3D& normal, Matr x.normalize(); } - DEBUG_ASSERTCRASH(fabs(x.x*z.x + x.y*z.y + x.z*z.z)<0.0001,("dot is not zero")); + DEBUG_ASSERTCRASH(WWMath::FAbsOrigin(x.x*z.x + x.y*z.y + x.z*z.z)<0.0001,("dot is not zero")); // now computing the y vector is trivial. y.crossProduct( &z, &x, &y ); @@ -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::Atan2Origin(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 0d40b8eb230..78fee0b7978 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::SqrtOrigin( 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::SqrtOrigin( 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..c769f4880d5 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::SqrtOrigin(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..a00ebef152f 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::SqrtOrigin(curDistSqr), WWMath::SqrtOrigin(closeEnoughSqr))); // Make it twitch a little. Coord3D newPos = *docker->getPosition(); Real range = 0.4*PATHFIND_CELL_SIZE_F; @@ -170,7 +170,7 @@ void SupplyWarehouseDockUpdate::setDockCrippled( Bool setting ) void SupplyWarehouseDockUpdate::setCashValue( Int cashValue ) { // A script can tell us our set value, and we need to figure out the boxes needed to provide that. - m_boxesStored = ceil(cashValue / (float)TheGlobalData->m_baseValuePerSupplyBox); + m_boxesStored = WWMath::CeilOrigin(cashValue / (float)TheGlobalData->m_baseValuePerSupplyBox); Drawable *draw = getObject()->getDrawable(); if( draw ) { diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp index 62de8b3f53c..73b623e1902 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp @@ -297,7 +297,7 @@ static Real calcTransform(const Object* obj, const Coord3D *pos, Real maxTurnRat Real angle = (Real)ACos( c ); Vector3 newDir; - if (fabs(angle) < maxTurnRate) + if (WWMath::FAbsOrigin(angle) < maxTurnRate) { // close enough -- point exactly in the right dir newDir = otherDir; @@ -355,7 +355,7 @@ void NeutronMissileUpdate::doAttack() // // Modulate speed according to turning. The more we have to turn, the slower we go // - Real angleCoeff = (Real)fabs( relAngle ) / (PI / 2.0f); + Real angleCoeff = (Real)WWMath::FAbsOrigin( relAngle ) / (PI / 2.0f); if (angleCoeff > 1.0f) angleCoeff = 1.0; } @@ -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::SqrtOrigin(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 ccc57226348..b4196f0ec1b 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp @@ -101,7 +101,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::SqrtOrigin(WWMath::FAbsOrigin(2.0f * TheGlobalData->m_gravity * height)); } //------------------------------------------------------------------------------------------------- @@ -511,7 +511,7 @@ Bool PhysicsBehavior::handleBounce(Real oldZ, Real newZ, Real groundZ, Coord3D* Real vz = getVelocity()->z; if (oldZ > groundZ && vz < 0.0f) { - desiredAccelZ = fabs(vz) * stiffness; + desiredAccelZ = WWMath::FAbsOrigin(vz) * stiffness; } bounceForce->x = 0.0f; @@ -553,7 +553,7 @@ Bool PhysicsBehavior::handleBounce(Real oldZ, Real newZ, Real groundZ, Coord3D* inline Bool isVerySmall3D(const Coord3D& v) { const Real THRESH = 0.01f; - return (fabs(v.x) < THRESH && fabs(v.y) < THRESH && fabs(v.z) < THRESH); + return (WWMath::FAbsOrigin(v.x) < THRESH && WWMath::FAbsOrigin(v.y) < THRESH && WWMath::FAbsOrigin(v.z) < THRESH); } //------------------------------------------------------------------------------------------------- @@ -653,9 +653,9 @@ UpdateSleepTime PhysicsBehavior::update() // when vel gets tiny, just clamp to zero const Real THRESH = 0.001f; - if (fabsf(m_vel.x) < THRESH) m_vel.x = 0.0f; - if (fabsf(m_vel.y) < THRESH) m_vel.y = 0.0f; - if (fabsf(m_vel.z) < THRESH) m_vel.z = 0.0f; + if (WWMath::FAbsfOrigin(m_vel.x) < THRESH) m_vel.x = 0.0f; + if (WWMath::FAbsfOrigin(m_vel.y) < THRESH) m_vel.y = 0.0f; + if (WWMath::FAbsfOrigin(m_vel.z) < THRESH) m_vel.z = 0.0f; m_velMag = INVALID_VEL_MAG; @@ -687,9 +687,9 @@ UpdateSleepTime PhysicsBehavior::update() // Check when to clear the stunned status if (getIsStunned()) { - if ( (fabs(m_vel.x) < STUN_RELIEF_EPSILON && - fabs(m_vel.y) < STUN_RELIEF_EPSILON && - fabs(m_vel.z) < STUN_RELIEF_EPSILON) + if ( (WWMath::FAbsOrigin(m_vel.x) < STUN_RELIEF_EPSILON && + WWMath::FAbsOrigin(m_vel.y) < STUN_RELIEF_EPSILON && + WWMath::FAbsOrigin(m_vel.z) < STUN_RELIEF_EPSILON) || obj->isSignificantlyAboveTerrain() == FALSE ) { @@ -735,8 +735,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 = WWMath::SqrtfOrigin(sqr(xvec.X) + sqr(xvec.Y)); + Real pitchAngle = WWMath::Atan2Origin(xvec.Z, xy); Real remainingAngle = (offset > 0) ? ((PI/2) - pitchAngle) : (-(PI/2) + pitchAngle); Real s = Sin(remainingAngle); pitchRateToUse *= s; @@ -862,8 +862,8 @@ UpdateSleepTime PhysicsBehavior::update() // going down hills don't injure themselves (unless the hill is really steep) const Real MIN_ANGLE_TAN = 3.0f; // roughly 71 degrees const Real TINY_DELTA = 0.01f; - if ((fabs(m_vel.x) <= TINY_DELTA || fabs(activeVelZ / m_vel.x) >= MIN_ANGLE_TAN) && - (fabs(m_vel.y) <= TINY_DELTA || fabs(activeVelZ / m_vel.y) >= MIN_ANGLE_TAN)) + if ((WWMath::FAbsOrigin(m_vel.x) <= TINY_DELTA || WWMath::FAbsOrigin(activeVelZ / m_vel.x) >= MIN_ANGLE_TAN) && + (WWMath::FAbsOrigin(m_vel.y) <= TINY_DELTA || WWMath::FAbsOrigin(activeVelZ / m_vel.y) >= MIN_ANGLE_TAN)) { Real damageAmt = netSpeed * getMass() * d->m_fallHeightDamageFactor; @@ -942,7 +942,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)WWMath::SqrtfOrigin( sqr(m_vel.x) + sqr(m_vel.y) + sqr(m_vel.z) ); } return m_velMag; } @@ -964,7 +964,7 @@ Real PhysicsBehavior::getForwardSpeed2D() const Real speedSquared = vx*vx + vy*vy; // DEBUG_ASSERTCRASH( speedSquared != 0, ("zero speedSquared will overflow sqrtf()!") );// lorenzen... sanity check - Real speed = (Real)sqrtf( speedSquared ); + Real speed = (Real)WWMath::SqrtfOrigin( speedSquared ); if (dot >= 0.0f) return speed; @@ -987,7 +987,7 @@ Real PhysicsBehavior::getForwardSpeed3D() const Real dot = vx + vy + vz; - Real speed = (Real)sqrtf( vx*vx + vy*vy + vz*vz ); + Real speed = (Real)WWMath::SqrtfOrigin( vx*vx + vy*vy + vz*vz ); if (dot >= 0.0f) return speed; @@ -1010,7 +1010,7 @@ Bool PhysicsBehavior::wasPreviouslyOverlapped(Object *obj) const //------------------------------------------------------------------------------------------------- void PhysicsBehavior::scrubVelocityZ( Real desiredVelocity ) { - if (fabs(desiredVelocity) < 0.001f) + if (WWMath::FAbsOrigin(desiredVelocity) < 0.001f) { m_vel.z = 0; } @@ -1034,7 +1034,7 @@ void PhysicsBehavior::scrubVelocity2D( Real desiredVelocity ) } else { - Real curVelocity = sqrtf(m_vel.x*m_vel.x + m_vel.y*m_vel.y); + Real curVelocity = WWMath::SqrtfOrigin(m_vel.x*m_vel.x + m_vel.y*m_vel.y); if (desiredVelocity > curVelocity) { return; @@ -1117,9 +1117,9 @@ void PhysicsBehavior::doBounceSound(const Coord3D& prevPos) //Real vel = fabs(getVelocity()->z); // can't use velocity, because it's already been updated this frame, and will be zero... (srj) - Real vel = fabs(prevPos.z - getObject()->getPosition()->z); + Real vel = WWMath::FAbsOrigin(prevPos.z - getObject()->getPosition()->z); - Real mass = fabs(getMass()); + Real mass = WWMath::FAbsOrigin(getMass()); if (vel > NORMAL_VEL_Z) { vel = NORMAL_VEL_Z; } @@ -1319,7 +1319,7 @@ void PhysicsBehavior::onCollide( Object *other, const Coord3D *loc, const Coord3 m_lastCollidee = other->getID(); - Real dist = sqrtf(distSqr); + Real dist = WWMath::SqrtfOrigin(distSqr); Real overlap = usRadius + themRadius - dist; // if objects are coincident, dist is zero, so force would be infinite -- clearly @@ -1422,7 +1422,7 @@ static Bool perpsLogicallyEqual( Real perpOne, Real perpTwo ) { // Equality with a wiggle fudge. const Real PERP_RANGE = 0.15f; - return fabs( perpOne - perpTwo ) <= PERP_RANGE; + return WWMath::FAbsOrigin( perpOne - perpTwo ) <= PERP_RANGE; } //------------------------------------------------------------------------------------------------- diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp index 643aa40a5b4..6772e21c55f 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::SqrtOrigin( 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::SqrtOrigin( 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::SqrtOrigin( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); } } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipDeploymentUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipDeploymentUpdate.cpp index d22a61a9bf8..1e550a40f6f 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::Atan2Origin( 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..795b3f7d333 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp @@ -670,7 +670,7 @@ UpdateSleepTime StealthUpdate::update() m_disguiseHalfpointReached = true; } //Opacity ranges from full to none at midpoint and full again at the end - Real opacity = fabs( 1.0f - (factor * 2.0f) ); + Real opacity = WWMath::FAbsOrigin( 1.0f - (factor * 2.0f) ); Real overrideOpacity = opacity < 1.0f ? 0.0f : 1.0f; draw->setEffectiveOpacity( opacity, overrideOpacity ); if( !m_disguiseTransitionFrames && !m_transitioningToDisguise ) diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/TensileFormationUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/TensileFormationUpdate.cpp index 66ef8bc1598..f80e99d1185 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/TensileFormationUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/TensileFormationUpdate.cpp @@ -348,7 +348,7 @@ UpdateSleepTime TensileFormationUpdate::update() else draw->clearModelConditionFlags(MAKE_MODELCONDITION_MASK(MODELCONDITION_MOVING)); - if ( fabs( pos->z - newPos.z ) > 0.2f && m_life < 100) + if ( WWMath::FAbsOrigin( pos->z - newPos.z ) > 0.2f && m_life < 100) draw->setModelConditionFlags(MAKE_MODELCONDITION_MASK(MODELCONDITION_FREEFALL)); else draw->clearModelConditionFlags(MAKE_MODELCONDITION_MASK(MODELCONDITION_FREEFALL)); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp index 137521dcf9b..93975b7d940 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp @@ -130,7 +130,7 @@ static Real angleClosestTo(Real a1, Real a2, Real desired) { a1 = normalizeAngle(a1); a2 = normalizeAngle(a2); - return (fabs(stdAngleDiff(desired, a1)) < fabs(stdAngleDiff(desired, a2))) ? a1 : a2; + return (WWMath::FAbsOrigin(stdAngleDiff(desired, a1)) < WWMath::FAbsOrigin(stdAngleDiff(desired, a2))) ? a1 : a2; } //------------------------------------------------------------------------------------------------- @@ -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(WWMath::Atan2Origin(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 @@ -298,7 +298,7 @@ UpdateSleepTime ToppleUpdate::update() m_angularVelocity *= -d->m_bounceVelocityPercent; if( BitIsSet( m_options, TOPPLE_OPTIONS_NO_BOUNCE ) == TRUE || - fabs(m_angularVelocity) < VELOCITY_BOUNCE_LIMIT ) + WWMath::FAbsOrigin(m_angularVelocity) < VELOCITY_BOUNCE_LIMIT ) { // too slow, just stop m_angularVelocity = 0; @@ -338,7 +338,7 @@ UpdateSleepTime ToppleUpdate::update() } } } - else if( fabs(m_angularVelocity) >= VELOCITY_BOUNCE_SOUND_LIMIT ) + else if( WWMath::FAbsOrigin(m_angularVelocity) >= VELOCITY_BOUNCE_SOUND_LIMIT ) { // fast enough bounce to warrant the bounce fx if( BitIsSet( m_options, TOPPLE_OPTIONS_NO_FX ) == FALSE ) diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp index da4ef34b952..880e630768a 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp @@ -397,8 +397,8 @@ void WeaponTemplate::reset() // No matter what we have now, we want to convert it to frames from msec. // ShotDelay used to use parseDurationUnsignedInt, and we are expanding on that. - self->m_minDelayBetweenShots = ceilf(ConvertDurationFromMsecsToFrames((Real)self->m_minDelayBetweenShots)); - self->m_maxDelayBetweenShots = ceilf(ConvertDurationFromMsecsToFrames((Real)self->m_maxDelayBetweenShots)); + self->m_minDelayBetweenShots = WWMath::CeilfOrigin(ConvertDurationFromMsecsToFrames((Real)self->m_minDelayBetweenShots)); + self->m_maxDelayBetweenShots = WWMath::CeilfOrigin(ConvertDurationFromMsecsToFrames((Real)self->m_maxDelayBetweenShots)); } @@ -879,7 +879,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?",WWMath::SqrtfOrigin(distSqr),WWMath::SqrtfOrigin(minAttackRangeSqr))); //-extraLogging #if defined(RTS_DEBUG) @@ -905,7 +905,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::Atan2Origin(victimPos->y - sourcePos->y, victimPos->x - sourcePos->x)) : 0.0f; VeterancyLevel v = sourceObj->getVeterancyLevel(); const FXList* fx = isProjectileDetonation ? getProjectileDetonateFX(v) : getFireFX(v); @@ -1502,9 +1502,9 @@ void WeaponTemplate::dealDamageInternal(ObjectID sourceID, ObjectID victimID, co Coord3D shockWaveVector = damageDirection; // Guard against zero vector. Make vector straight up if that is the case - if (fabs(shockWaveVector.x) < WWMATH_EPSILON && - fabs(shockWaveVector.y) < WWMATH_EPSILON && - fabs(shockWaveVector.z) < WWMATH_EPSILON) + if (WWMath::FAbsOrigin(shockWaveVector.x) < WWMATH_EPSILON && + WWMath::FAbsOrigin(shockWaveVector.y) < WWMATH_EPSILON && + WWMath::FAbsOrigin(shockWaveVector.z) < WWMATH_EPSILON) { shockWaveVector.z = 1.0f; } @@ -2117,11 +2117,11 @@ 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::Atan2Origin(-dir.y, -dir.x); Real relAngle = source->getOrientation()- angle; if (relAngle>2*PI) relAngle -= 2*PI; if (relAngle<-2*PI) relAngle += 2*PI; - if (fabs(relAngle)getPosition(); const Real ACCEPTABLE_DZ = 10.0f; - if (fabs(dst->z - src->z) < ACCEPTABLE_DZ) + if (WWMath::FAbsOrigin(dst->z - src->z) < ACCEPTABLE_DZ) return true; // always good enough if dz is small, regardless of pitch Real minPitch, maxPitch; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp index 4606cc849f1..da95d613d84 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp @@ -848,7 +848,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::SqrtOrigin( sqr(p1.x-p2.x) + sqr(p1.y-p2.y) ); } } else diff --git a/cmake/gamemath.cmake b/cmake/gamemath.cmake new file mode 100644 index 00000000000..7dd1e57983b --- /dev/null +++ b/cmake/gamemath.cmake @@ -0,0 +1,14 @@ +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/TheSuperHackers/GameMath.git + GIT_TAG 59f7ccd494f7e7c916a784ac26ef266f9f09d78d +) + +FetchContent_MakeAvailable(gamemath) + +# Ensure GameMath includes are available to ALL targets +# to prevent ODR violations and ensure USE_DETERMINISTIC_MATH activates consistently. +include_directories(${gamemath_SOURCE_DIR}/include) From 65fa3351c592f2275f42b08ba661acdcba1c8638 Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Fri, 1 May 2026 00:44:16 +0300 Subject: [PATCH 2/9] fix(math): Route BaseType.h sqrt() through deterministic Sqrt() wrapper Add global Sqrt(double) to trig.h/Trig.cpp, routing through WWMath::SqrtOrigin(). Replace 5 bare CRT sqrt() calls in BaseType.h (Coord2D::length, Coord2D::toAngle, ICoord2D::length, Coord3D::length, ICoord3D::length) with the new Sqrt() gateway. This closes the last known CRT math leak in CRC-critical code paths. Same pattern as existing Sin/Cos/ACos routing via Trig.cpp. --- Core/Libraries/Include/Lib/BaseType.h | 10 +++++----- Core/Libraries/Include/Lib/trig.h | 1 + Generals/Code/GameEngine/Source/Common/System/Trig.cpp | 5 +++++ .../Code/GameEngine/Source/Common/System/Trig.cpp | 5 +++++ 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Core/Libraries/Include/Lib/BaseType.h b/Core/Libraries/Include/Lib/BaseType.h index 16135504d6e..a88473a98b2 100644 --- a/Core/Libraries/Include/Lib/BaseType.h +++ b/Core/Libraries/Include/Lib/BaseType.h @@ -248,7 +248,7 @@ struct Coord2D return x == value && y == value; } - Real length() const { return (Real)sqrt( x*x + y*y ); } + Real length() const { return (Real)Sqrt( x*x + y*y ); } Real lengthSqr() const { return x*x + y*y; } void normalize() @@ -273,7 +273,7 @@ inline Real Coord2D::toAngle() const vector.x = x; vector.y = y; - Real dist = (Real)sqrt(vector.x * vector.x + vector.y * vector.y); + Real dist = (Real)Sqrt(vector.x * vector.x + vector.y * vector.y); // normalize if (dist == 0.0f) @@ -340,7 +340,7 @@ struct ICoord2D return x == value && y == value; } - Int length() const { return (Int)sqrt( (double)(x*x + y*y) ); } + Int length() const { return (Int)Sqrt( (double)(x*x + y*y) ); } }; struct Region2D @@ -388,7 +388,7 @@ struct Coord3D { Real x, y, z; - Real length() const { return (Real)sqrt( x*x + y*y + z*z ); } + Real length() const { return (Real)Sqrt( x*x + y*y + z*z ); } Real lengthSqr() const { return ( x*x + y*y + z*z ); } void normalize() @@ -476,7 +476,7 @@ struct ICoord3D { Int x, y, z; - Int length() const { return (Int)sqrt( (double)(x*x + y*y + z*z) ); } + Int length() const { return (Int)Sqrt( (double)(x*x + y*y + z*z) ); } void zero() { diff --git a/Core/Libraries/Include/Lib/trig.h b/Core/Libraries/Include/Lib/trig.h index d6f3fa22cd8..204608820d3 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); +double Sqrt(double x); diff --git a/Generals/Code/GameEngine/Source/Common/System/Trig.cpp b/Generals/Code/GameEngine/Source/Common/System/Trig.cpp index ca07f65983c..f3f1b47baef 100644 --- a/Generals/Code/GameEngine/Source/Common/System/Trig.cpp +++ b/Generals/Code/GameEngine/Source/Common/System/Trig.cpp @@ -56,3 +56,8 @@ Real ASin(Real x) { return WWMath::ASinTrig(x); } + +double Sqrt(double x) +{ + return WWMath::SqrtOrigin(x); +} diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp index ca07f65983c..f3f1b47baef 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp @@ -56,3 +56,8 @@ Real ASin(Real x) { return WWMath::ASinTrig(x); } + +double Sqrt(double x) +{ + return WWMath::SqrtOrigin(x); +} From 779f71416c0d92d80af40470c373343e4526e0d0 Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Fri, 1 May 2026 03:49:16 +0300 Subject: [PATCH 3/9] fix(math): Enforce USE_DETERMINISTIC_MATH and complete deterministic coverage --- .../Common/Diagnostic/SimulationMathCrc.cpp | 12 +++---- Core/Libraries/Source/WWVegas/WWMath/wwmath.h | 34 +++++++++++++------ .../GameEngine/Source/Common/System/Trig.cpp | 2 +- cmake/gamemath.cmake | 2 ++ 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp b/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp index 5245d7c01a2..3763d54e339 100644 --- a/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp +++ b/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp @@ -39,16 +39,16 @@ static void appendSimulationMathCrc(XferCRC &xfer) factorsMatrix.Set( WWMath::Sin(0.7f) * log10f(2.3f), WWMath::Cos(1.1f) * powf(1.1f, 2.0f), - tanf(0.3f), - asinf(0.967302263f), - acosf(0.967302263f), + WWMath::TanfOrigin(0.3f), + WWMath::ASinfOrigin(0.967302263f), + WWMath::ACosfOrigin(0.967302263f), WWMath::AtanfOrigin(0.967302263f) * WWMath::PowfOrigin(1.1f, 2.0f), WWMath::Atan2fOrigin(0.4f, 1.3f), - sinhf(0.2f), - coshf(0.4f) * tanhf(0.5f), + WWMath::SinhfOrigin(0.2f), + WWMath::CoshfOrigin(0.4f) * WWMath::TanhfOrigin(0.5f), WWMath::SqrtfOrigin(55788.84375f), WWMath::ExpfOrigin(0.1f) * WWMath::Log10fOrigin(2.3f), - logf(1.4f)); + WWMath::LogfOrigin(1.4f)); Matrix3D::Multiply(matrix, factorsMatrix, &matrix); matrix.Get_Inverse(matrix); diff --git a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h index 1ea32b730f6..b549afbb917 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h +++ b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h @@ -46,23 +46,26 @@ #if !(defined(_MSC_VER) && _MSC_VER < 1300) #if defined(__has_include) && __has_include("gmath.h") #include "gmath.h" -#define USE_DETERMINISTIC_MATH #endif #endif +#if !(defined(_MSC_VER) && _MSC_VER < 1300) +#define USE_DETERMINISTIC_MATH +#endif + /* ** Some global constants. */ -#define WWMATH_EPSILON 0.0001f -#define WWMATH_EPSILON2 WWMATH_EPSILON * WWMATH_EPSILON +#define WWMATH_EPSILON 0.0001f +#define WWMATH_EPSILON2 WWMATH_EPSILON * WWMATH_EPSILON #define WWMATH_PI 3.141592654f -#define WWMATH_TWO_PI 6.283185308f -#define WWMATH_FLOAT_MAX (FLT_MAX) -#define WWMATH_FLOAT_MIN (FLT_MIN) -#define WWMATH_SQRT2 1.414213562f -#define WWMATH_SQRT3 1.732050808f -#define WWMATH_OOSQRT2 0.707106781f -#define WWMATH_OOSQRT3 0.577350269f +#define WWMATH_TWO_PI 6.283185308f +#define WWMATH_FLOAT_MAX (FLT_MAX) +#define WWMATH_FLOAT_MIN (FLT_MIN) +#define WWMATH_SQRT2 1.414213562f +#define WWMATH_SQRT3 1.732050808f +#define WWMATH_OOSQRT2 0.707106781f +#define WWMATH_OOSQRT3 0.577350269f /* ** Macros to convert between degrees and radians @@ -168,6 +171,9 @@ static WWINLINE float Atan2(float y,float x) { return static_cast(atan2( // Origin wrappers: replace bare CRT math calls in GameLogic. // Each wrapper preserves the exact type (float vs double) of the vanilla CRT call. +// Note: double overloads narrow to float before calling GameMath (gm_*f). +// GameMath only provides float-precision functions. All call sites pass float-width +// values, so the narrowing is lossless in practice. #ifdef USE_DETERMINISTIC_MATH static WWINLINE double SqrtOrigin(double x) { return (double)gm_sqrtf((float)x); } static WWINLINE float SqrtfOrigin(float x) { return gm_sqrtf(x); } @@ -189,6 +195,10 @@ static WWINLINE float Atan2(float y,float x) { return static_cast(atan2( static WWINLINE float CeilfOrigin(float x) { return gm_ceilf(x); } static WWINLINE float ExpfOrigin(float x) { return gm_expf(x); } static WWINLINE float Log10fOrigin(float x) { return gm_log10f(x); } + static WWINLINE float LogfOrigin(float x) { return gm_logf(x); } + static WWINLINE float SinhfOrigin(float x) { return gm_sinhf(x); } + static WWINLINE float CoshfOrigin(float x) { return gm_coshf(x); } + static WWINLINE float TanhfOrigin(float x) { return gm_tanhf(x); } #else static WWINLINE double SqrtOrigin(double x) { return sqrt(x); } static WWINLINE float SqrtfOrigin(float x) { return sqrtf(x); } @@ -210,6 +220,10 @@ static WWINLINE float Atan2(float y,float x) { return static_cast(atan2( static WWINLINE float CeilfOrigin(float x) { return ceilf(x); } static WWINLINE float ExpfOrigin(float x) { return expf(x); } static WWINLINE float Log10fOrigin(float x) { return log10f(x); } + static WWINLINE float LogfOrigin(float x) { return logf(x); } + static WWINLINE float SinhfOrigin(float x) { return sinhf(x); } + static WWINLINE float CoshfOrigin(float x) { return coshf(x); } + static WWINLINE float TanhfOrigin(float x) { return tanhf(x); } #endif static WWINLINE float Sign(float val); static WWINLINE float Ceil(float val) { return ceilf(val); } diff --git a/Generals/Code/GameEngine/Source/Common/System/Trig.cpp b/Generals/Code/GameEngine/Source/Common/System/Trig.cpp index f3f1b47baef..603521e1c7c 100644 --- a/Generals/Code/GameEngine/Source/Common/System/Trig.cpp +++ b/Generals/Code/GameEngine/Source/Common/System/Trig.cpp @@ -1,5 +1,5 @@ /* -** Command & Conquer Generals Zero Hour(tm) +** Command & Conquer Generals(tm) ** Copyright 2025 Electronic Arts Inc. ** ** This program is free software: you can redistribute it and/or modify diff --git a/cmake/gamemath.cmake b/cmake/gamemath.cmake index 7dd1e57983b..55e31898d0b 100644 --- a/cmake/gamemath.cmake +++ b/cmake/gamemath.cmake @@ -1,3 +1,5 @@ +# FORCE is required to guarantee cross-platform bit-exact determinism. +# Intrinsics would use platform-specific SIMD, breaking CRC parity between architectures. 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) From a344ef2fb40171b7dd6e385e5a1855784035c606 Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Fri, 1 May 2026 13:38:05 +0300 Subject: [PATCH 4/9] fix(math): Restore original formatting and complete deterministic coverage - Restore original Trig.cpp code (author comments, defines, REGENERATE_TRIG_TABLES) - Keep only functional changes: sinf->WWMath::SinTrig redirects + Sqrt(double) - Restore original tab alignment in wwmath.h #define block - Route remaining CRT calls in SimulationMathCrc through WWMath (sinh/cosh/tanh/logf) - Add cmake comments explaining FORCE usage --- Core/Libraries/Source/WWVegas/WWMath/wwmath.h | 18 ++-- .../GameEngine/Source/Common/System/Trig.cpp | 100 +++++++++++++++++- .../GameEngine/Source/Common/System/Trig.cpp | 100 +++++++++++++++++- 3 files changed, 199 insertions(+), 19 deletions(-) diff --git a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h index b549afbb917..3526310a2b1 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h +++ b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h @@ -56,16 +56,16 @@ /* ** Some global constants. */ -#define WWMATH_EPSILON 0.0001f -#define WWMATH_EPSILON2 WWMATH_EPSILON * WWMATH_EPSILON +#define WWMATH_EPSILON 0.0001f +#define WWMATH_EPSILON2 WWMATH_EPSILON * WWMATH_EPSILON #define WWMATH_PI 3.141592654f -#define WWMATH_TWO_PI 6.283185308f -#define WWMATH_FLOAT_MAX (FLT_MAX) -#define WWMATH_FLOAT_MIN (FLT_MIN) -#define WWMATH_SQRT2 1.414213562f -#define WWMATH_SQRT3 1.732050808f -#define WWMATH_OOSQRT2 0.707106781f -#define WWMATH_OOSQRT3 0.577350269f +#define WWMATH_TWO_PI 6.283185308f +#define WWMATH_FLOAT_MAX (FLT_MAX) +#define WWMATH_FLOAT_MIN (FLT_MIN) +#define WWMATH_SQRT2 1.414213562f +#define WWMATH_SQRT3 1.732050808f +#define WWMATH_OOSQRT2 0.707106781f +#define WWMATH_OOSQRT3 0.577350269f /* ** Macros to convert between degrees and radians diff --git a/Generals/Code/GameEngine/Source/Common/System/Trig.cpp b/Generals/Code/GameEngine/Source/Common/System/Trig.cpp index 603521e1c7c..d7d9ab3db9c 100644 --- a/Generals/Code/GameEngine/Source/Common/System/Trig.cpp +++ b/Generals/Code/GameEngine/Source/Common/System/Trig.cpp @@ -17,21 +17,38 @@ */ //////////////////////////////////////////////////////////////////////////////// -// // -// (c) 2001-2003 Electronic Arts Inc. // -// // +// // +// (c) 2001-2003 Electronic Arts Inc. // +// // //////////////////////////////////////////////////////////////////////////////// // Trig.cpp -// TheSuperHackers @refactor Redirect legacy trig functions to deterministic WWMath wrappers. -// Original implementations called CRT float functions (sinf, cosf, acosf, asinf, tanf). +// 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 + +// TheSuperHackers @refactor Redirect trig functions to deterministic WWMath wrappers. + Real Sin(Real x) { return WWMath::SinTrig(x); @@ -61,3 +78,76 @@ double Sqrt(double x) { return WWMath::SqrtOrigin(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; i +#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 + +// TheSuperHackers @refactor Redirect trig functions to deterministic WWMath wrappers. + Real Sin(Real x) { return WWMath::SinTrig(x); @@ -61,3 +78,76 @@ double Sqrt(double x) { return WWMath::SqrtOrigin(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; i Date: Sun, 3 May 2026 17:32:19 +0300 Subject: [PATCH 5/9] test(math): Implement diagnostic benchmark for deterministic math parity - Add RUN_MATH_BENCHMARK_REPLAY400_FLAG to SimulationMathCrc.h - Implement 10000-iteration dual-path benchmark in SimulationMathCrc.cpp - Inject benchmark trigger into GameLogic::update at replay frame 400 - Benchmark measures CRT vs WWMath precision and performance --- .../Common/Diagnostic/SimulationMathCrc.h | 4 + .../Common/Diagnostic/SimulationMathCrc.cpp | 80 ++++++++++++++++++- .../Source/GameLogic/System/GameLogic.cpp | 17 ++++ 3 files changed, 97 insertions(+), 4 deletions(-) diff --git a/Core/GameEngine/Include/Common/Diagnostic/SimulationMathCrc.h b/Core/GameEngine/Include/Common/Diagnostic/SimulationMathCrc.h index 031bc2e3f88..81396b1a8a5 100644 --- a/Core/GameEngine/Include/Common/Diagnostic/SimulationMathCrc.h +++ b/Core/GameEngine/Include/Common/Diagnostic/SimulationMathCrc.h @@ -18,8 +18,12 @@ #pragma once +// Flags for diagnostic math benchmarks +// #define RUN_MATH_BENCHMARK_REPLAY400_FLAG + class SimulationMathCrc { public: static UnsignedInt calculate(); + static void runBenchmark(int iterations = 10000); }; diff --git a/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp b/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp index 3763d54e339..6fafe047bc4 100644 --- a/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp +++ b/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp @@ -25,8 +25,10 @@ #include "GameLogic/FPUControl.h" #include +#include +#include -static void appendSimulationMathCrc(XferCRC &xfer) +static void appendSimulationMathCrc_Deterministic(XferCRC &xfer) { Matrix3D matrix; Matrix3D factorsMatrix; @@ -37,8 +39,8 @@ static void appendSimulationMathCrc(XferCRC &xfer) 0.9f, 1.0f, 2.1f, 1.2f); factorsMatrix.Set( - WWMath::Sin(0.7f) * log10f(2.3f), - WWMath::Cos(1.1f) * powf(1.1f, 2.0f), + WWMath::Sin(0.7f) * WWMath::Log10fOrigin(2.3f), + WWMath::Cos(1.1f) * WWMath::PowfOrigin(1.1f, 2.0f), WWMath::TanfOrigin(0.3f), WWMath::ASinfOrigin(0.967302263f), WWMath::ACosfOrigin(0.967302263f), @@ -56,6 +58,36 @@ static void appendSimulationMathCrc(XferCRC &xfer) xfer.xferMatrix3D(&matrix); } +static void appendSimulationMathCrc_Native(XferCRC &xfer) +{ + Matrix3D matrix; + Matrix3D factorsMatrix; + + matrix.Set( + 4.1f, 1.2f, 0.3f, 0.4f, + 0.5f, 3.6f, 0.7f, 0.8f, + 0.9f, 1.0f, 2.1f, 1.2f); + + factorsMatrix.Set( + (float)(::sin(0.7) * ::log10(2.3)), + (float)(::cos(1.1) * ::pow(1.1, 2.0)), + (float)::tan(0.3), + (float)::asin(0.967302263), + (float)::acos(0.967302263), + (float)(::atan(0.967302263) * ::pow(1.1, 2.0)), + (float)::atan2(0.4, 1.3), + (float)::sinh(0.2), + (float)(::cosh(0.4) * ::tanh(0.5)), + (float)::sqrt(55788.84375), + (float)(::exp(0.1) * ::log10(2.3)), + (float)::log(1.4)); + + Matrix3D::Multiply(matrix, factorsMatrix, &matrix); + matrix.Get_Inverse(matrix); + + xfer.xferMatrix3D(&matrix); +} + UnsignedInt SimulationMathCrc::calculate() { XferCRC xfer; @@ -63,7 +95,7 @@ UnsignedInt SimulationMathCrc::calculate() setFPMode(); - appendSimulationMathCrc(xfer); + appendSimulationMathCrc_Deterministic(xfer); _fpreset(); @@ -71,3 +103,43 @@ UnsignedInt SimulationMathCrc::calculate() return xfer.getCRC(); } + +void SimulationMathCrc::runBenchmark(int iterations) +{ + clock_t startDet = clock(); + UnsignedInt crcDet = 0; + + setFPMode(); + for (int i = 0; i < iterations; ++i) + { + XferCRC xfer; + xfer.open("SimMathDet"); + appendSimulationMathCrc_Deterministic(xfer); + xfer.close(); + if (i == 0) crcDet = xfer.getCRC(); + } + _fpreset(); + clock_t endDet = clock(); + double timeDetMs = (double)(endDet - startDet) / CLOCKS_PER_SEC * 1000.0; + + clock_t startNat = clock(); + UnsignedInt crcNat = 0; + + setFPMode(); + for (int i = 0; i < iterations; ++i) + { + XferCRC xfer; + xfer.open("SimMathNat"); + appendSimulationMathCrc_Native(xfer); + xfer.close(); + if (i == 0) crcNat = xfer.getCRC(); + } + _fpreset(); + clock_t endNat = clock(); + double timeNatMs = (double)(endNat - startNat) / CLOCKS_PER_SEC * 1000.0; + + printf("\n================ MATH BENCHMARK (%d iters) ================\n", iterations); + printf("Deterministic (WWMath): CRC = %08X, Time = %.2f ms\n", crcDet, timeDetMs); + printf("Native (system math): CRC = %08X, Time = %.2f ms\n", crcNat, timeNatMs); + printf("===========================================================\n\n"); +} diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp index da95d613d84..230c921b674 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp @@ -33,6 +33,7 @@ #include "Common/AudioHandleSpecialValues.h" #include "Common/BuildAssistant.h" #include "Common/CRCDebug.h" +#include "Common/Diagnostic/SimulationMathCrc.h" #include "Common/FramePacer.h" #include "Common/GameAudio.h" #include "Common/GameEngine.h" @@ -3738,6 +3739,22 @@ void GameLogic::update() TheTerrainLogic->UPDATE(); } +#ifdef RUN_MATH_BENCHMARK_REPLAY400_FLAG + static int s_replayStartFrame = -1; + static bool s_benchmarkRun = false; + + if (!s_benchmarkRun && TheRecorder && TheRecorder->isPlaybackMode()) + { + if (s_replayStartFrame == -1) { + s_replayStartFrame = m_frame; + } + else if (m_frame == s_replayStartFrame + 400) { + SimulationMathCrc::runBenchmark(10000); + s_benchmarkRun = true; + } + } +#endif + // force CRC calculation, so we can keep a cache of the last N CRCs. We do this right where the recorder // would be getting the CRC anyway, so replays can get the CRCs from the exact instant in time as the original. Bool isMPGameOrReplay = (TheRecorder && TheRecorder->isMultiplayer() && getGameMode() != GAME_SHELL && getGameMode() != GAME_NONE); From ae08fa996dc3ee482b49bfb9da42aa2f6e6fe6f5 Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Sun, 3 May 2026 18:09:35 +0300 Subject: [PATCH 6/9] fix(math): Resolve VC6 loop scoping error C2374 in benchmark - Declare loop iterator outside of for loop in runBenchmark to support legacy MSVC scoping rules --- .../Source/Common/Diagnostic/SimulationMathCrc.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp b/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp index 6fafe047bc4..c7d4e05adcb 100644 --- a/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp +++ b/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp @@ -106,11 +106,12 @@ UnsignedInt SimulationMathCrc::calculate() void SimulationMathCrc::runBenchmark(int iterations) { + int i; clock_t startDet = clock(); UnsignedInt crcDet = 0; setFPMode(); - for (int i = 0; i < iterations; ++i) + for (i = 0; i < iterations; ++i) { XferCRC xfer; xfer.open("SimMathDet"); @@ -126,7 +127,7 @@ void SimulationMathCrc::runBenchmark(int iterations) UnsignedInt crcNat = 0; setFPMode(); - for (int i = 0; i < iterations; ++i) + for (i = 0; i < iterations; ++i) { XferCRC xfer; xfer.open("SimMathNat"); From afe36e5bed1cf6d40aa7854d3f742fab162d1ef9 Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Sun, 3 May 2026 21:43:54 +0300 Subject: [PATCH 7/9] TheSuperHackers @fix Disable FMA contraction for cross-platform deterministic math parity --- cmake/compilers.cmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmake/compilers.cmake b/cmake/compilers.cmake index c5c4d5118c2..afaf5df2387 100644 --- a/cmake/compilers.cmake +++ b/cmake/compilers.cmake @@ -51,6 +51,9 @@ if (NOT IS_VS6_BUILD) add_compile_options(/Zc:__cplusplus) else() add_compile_options(-Wsuggest-override) + # TheSuperHackers @fix Prevent FMA contraction (a*b+c -> fmadd) which skips intermediate + # rounding and breaks cross-platform deterministic math parity with MSVC (/fp:precise). + add_compile_options(-ffp-contract=off) endif() else() if(RTS_BUILD_OPTION_VC6_FULL_DEBUG) From d05cbba3c1d818057ce8588c7886323c4b320658 Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Tue, 5 May 2026 20:39:01 +0300 Subject: [PATCH 8/9] refactor(math): Address xezon review feedback on PR #2670 - Merge gmath.h include + USE_DETERMINISTIC_MATH into single __has_include block - Replace all #ifdef/#if defined() with #if USE_DETERMINISTIC_MATH - Remove TheSuperHackers @fix prefix from cmake comment - Expand ODR abbreviation in gamemath.cmake comment - Add blank lines after setFPMode() in benchmark - Fix iters abbreviation in printf - Simplify benchmark: remove replay dependency, auto-trigger at frame 400 - Rename WWMath wrappers to Function_Name convention (578 replacements, 79 files) --- .../Common/Diagnostic/SimulationMathCrc.h | 2 +- .../Common/Diagnostic/SimulationMathCrc.cpp | 28 ++-- Core/GameEngine/Source/Common/INI/INI.cpp | 4 +- .../Source/GameLogic/AI/AIPathfind.cpp | 32 ++-- Core/Libraries/Source/WWVegas/WWMath/wwmath.h | 147 +++++++++--------- .../GameEngine/Source/Common/RTS/Player.cpp | 2 +- .../Source/Common/System/BuildAssistant.cpp | 2 +- .../Source/Common/System/Geometry.cpp | 14 +- .../GameEngine/Source/Common/System/Trig.cpp | 12 +- .../GameEngine/Source/GameLogic/AI/AI.cpp | 2 +- .../Source/GameLogic/AI/AIPlayer.cpp | 10 +- .../Source/GameLogic/AI/AIStates.cpp | 14 +- .../Source/GameLogic/AI/TurretAI.cpp | 8 +- .../Source/GameLogic/Map/PolygonTrigger.cpp | 2 +- .../Source/GameLogic/Map/TerrainLogic.cpp | 28 ++-- .../Behavior/DumbProjectileBehavior.cpp | 18 +-- .../Behavior/GenerateMinefieldBehavior.cpp | 2 +- .../Object/Behavior/MinefieldBehavior.cpp | 8 +- .../Object/Behavior/SlowDeathBehavior.cpp | 2 +- .../Object/Contain/ParachuteContain.cpp | 2 +- .../Source/GameLogic/Object/Locomotor.cpp | 86 +++++----- .../Source/GameLogic/Object/Object.cpp | 8 +- .../GameLogic/Object/ObjectCreationList.cpp | 8 +- .../GameLogic/Object/PartitionManager.cpp | 38 ++--- .../GameLogic/Object/Update/AIUpdate.cpp | 14 +- .../Update/AIUpdate/ChinookAIUpdate.cpp | 8 +- .../AIUpdate/DeliverPayloadAIUpdate.cpp | 8 +- .../Object/Update/AIUpdate/JetAIUpdate.cpp | 10 +- .../Update/AIUpdate/MissileAIUpdate.cpp | 4 +- .../Update/AIUpdate/POWTruckAIUpdate.cpp | 2 +- .../Update/AIUpdate/RailroadGuideAIUpdate.cpp | 12 +- .../Object/Update/CleanupHazardUpdate.cpp | 4 +- .../Object/Update/CommandButtonHuntUpdate.cpp | 2 +- .../DockUpdate/SupplyWarehouseDockUpdate.cpp | 4 +- .../Object/Update/NeutronMissileUpdate.cpp | 6 +- .../GameLogic/Object/Update/PhysicsUpdate.cpp | 38 ++--- .../Object/Update/PointDefenseLaserUpdate.cpp | 6 +- .../GameLogic/Object/Update/StealthUpdate.cpp | 2 +- .../Object/Update/TensileFormationUpdate.cpp | 2 +- .../GameLogic/Object/Update/ToppleUpdate.cpp | 8 +- .../Source/GameLogic/Object/Weapon.cpp | 18 +-- .../Source/GameLogic/System/GameLogic.cpp | 2 +- .../GameEngine/Source/Common/RTS/Player.cpp | 2 +- .../Source/Common/System/BuildAssistant.cpp | 2 +- .../Source/Common/System/Geometry.cpp | 14 +- .../GameEngine/Source/Common/System/Trig.cpp | 12 +- .../GameEngine/Source/GameLogic/AI/AI.cpp | 2 +- .../Source/GameLogic/AI/AIPlayer.cpp | 10 +- .../Source/GameLogic/AI/AIStates.cpp | 14 +- .../Source/GameLogic/AI/TurretAI.cpp | 8 +- .../Source/GameLogic/Map/PolygonTrigger.cpp | 2 +- .../Source/GameLogic/Map/TerrainLogic.cpp | 30 ++-- .../Behavior/DumbProjectileBehavior.cpp | 18 +-- .../Behavior/GenerateMinefieldBehavior.cpp | 2 +- .../Object/Behavior/MinefieldBehavior.cpp | 8 +- .../Object/Behavior/SlowDeathBehavior.cpp | 2 +- .../Object/Contain/ParachuteContain.cpp | 2 +- .../Source/GameLogic/Object/Locomotor.cpp | 86 +++++----- .../Source/GameLogic/Object/Object.cpp | 8 +- .../GameLogic/Object/ObjectCreationList.cpp | 8 +- .../GameLogic/Object/PartitionManager.cpp | 38 ++--- .../GameLogic/Object/Update/AIUpdate.cpp | 14 +- .../Update/AIUpdate/ChinookAIUpdate.cpp | 6 +- .../AIUpdate/DeliverPayloadAIUpdate.cpp | 8 +- .../Object/Update/AIUpdate/JetAIUpdate.cpp | 10 +- .../Update/AIUpdate/MissileAIUpdate.cpp | 4 +- .../Update/AIUpdate/POWTruckAIUpdate.cpp | 2 +- .../Update/AIUpdate/RailroadGuideAIUpdate.cpp | 12 +- .../Object/Update/CleanupHazardUpdate.cpp | 4 +- .../Object/Update/CommandButtonHuntUpdate.cpp | 2 +- .../DockUpdate/SupplyWarehouseDockUpdate.cpp | 4 +- .../Object/Update/NeutronMissileUpdate.cpp | 6 +- .../GameLogic/Object/Update/PhysicsUpdate.cpp | 44 +++--- .../Object/Update/PointDefenseLaserUpdate.cpp | 6 +- .../Update/SpectreGunshipDeploymentUpdate.cpp | 2 +- .../GameLogic/Object/Update/StealthUpdate.cpp | 2 +- .../Object/Update/TensileFormationUpdate.cpp | 2 +- .../GameLogic/Object/Update/ToppleUpdate.cpp | 8 +- .../Source/GameLogic/Object/Weapon.cpp | 24 +-- .../Source/GameLogic/System/GameLogic.cpp | 16 +- cmake/compilers.cmake | 2 +- cmake/gamemath.cmake | 2 +- 82 files changed, 534 insertions(+), 543 deletions(-) diff --git a/Core/GameEngine/Include/Common/Diagnostic/SimulationMathCrc.h b/Core/GameEngine/Include/Common/Diagnostic/SimulationMathCrc.h index 81396b1a8a5..530e707e561 100644 --- a/Core/GameEngine/Include/Common/Diagnostic/SimulationMathCrc.h +++ b/Core/GameEngine/Include/Common/Diagnostic/SimulationMathCrc.h @@ -19,7 +19,7 @@ #pragma once // Flags for diagnostic math benchmarks -// #define RUN_MATH_BENCHMARK_REPLAY400_FLAG +#define RUN_MATH_BENCHMARK_REPLAY400_FLAG (0) class SimulationMathCrc { diff --git a/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp b/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp index c7d4e05adcb..cebc1ec59d3 100644 --- a/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp +++ b/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp @@ -39,18 +39,18 @@ static void appendSimulationMathCrc_Deterministic(XferCRC &xfer) 0.9f, 1.0f, 2.1f, 1.2f); factorsMatrix.Set( - WWMath::Sin(0.7f) * WWMath::Log10fOrigin(2.3f), - WWMath::Cos(1.1f) * WWMath::PowfOrigin(1.1f, 2.0f), - WWMath::TanfOrigin(0.3f), - WWMath::ASinfOrigin(0.967302263f), - WWMath::ACosfOrigin(0.967302263f), - WWMath::AtanfOrigin(0.967302263f) * WWMath::PowfOrigin(1.1f, 2.0f), - WWMath::Atan2fOrigin(0.4f, 1.3f), - WWMath::SinhfOrigin(0.2f), - WWMath::CoshfOrigin(0.4f) * WWMath::TanhfOrigin(0.5f), - WWMath::SqrtfOrigin(55788.84375f), - WWMath::ExpfOrigin(0.1f) * WWMath::Log10fOrigin(2.3f), - WWMath::LogfOrigin(1.4f)); + WWMath::Sin(0.7f) * WWMath::Log10f_Origin(2.3f), + WWMath::Cos(1.1f) * WWMath::Powf_Origin(1.1f, 2.0f), + WWMath::Tanf_Origin(0.3f), + WWMath::ASinf_Origin(0.967302263f), + WWMath::ACosf_Origin(0.967302263f), + WWMath::Atanf_Origin(0.967302263f) * WWMath::Powf_Origin(1.1f, 2.0f), + WWMath::Atan2f_Origin(0.4f, 1.3f), + WWMath::Sinhf_Origin(0.2f), + WWMath::Coshf_Origin(0.4f) * WWMath::Tanhf_Origin(0.5f), + WWMath::Sqrtf_Origin(55788.84375f), + WWMath::Expf_Origin(0.1f) * WWMath::Log10f_Origin(2.3f), + WWMath::Logf_Origin(1.4f)); Matrix3D::Multiply(matrix, factorsMatrix, &matrix); matrix.Get_Inverse(matrix); @@ -111,6 +111,7 @@ void SimulationMathCrc::runBenchmark(int iterations) UnsignedInt crcDet = 0; setFPMode(); + for (i = 0; i < iterations; ++i) { XferCRC xfer; @@ -127,6 +128,7 @@ void SimulationMathCrc::runBenchmark(int iterations) UnsignedInt crcNat = 0; setFPMode(); + for (i = 0; i < iterations; ++i) { XferCRC xfer; @@ -139,7 +141,7 @@ void SimulationMathCrc::runBenchmark(int iterations) clock_t endNat = clock(); double timeNatMs = (double)(endNat - startNat) / CLOCKS_PER_SEC * 1000.0; - printf("\n================ MATH BENCHMARK (%d iters) ================\n", iterations); + printf("\n================ MATH BENCHMARK (%d iterations) ================\n", iterations); printf("Deterministic (WWMath): CRC = %08X, Time = %.2f ms\n", crcDet, timeDetMs); printf("Native (system math): CRC = %08X, Time = %.2f ms\n", crcNat, timeNatMs); printf("===========================================================\n\n"); diff --git a/Core/GameEngine/Source/Common/INI/INI.cpp b/Core/GameEngine/Source/Common/INI/INI.cpp index 901d49935a3..e51d17b12af 100644 --- a/Core/GameEngine/Source/Common/INI/INI.cpp +++ b/Core/GameEngine/Source/Common/INI/INI.cpp @@ -1789,7 +1789,7 @@ void INI::parseDurationReal( INI *ini, void * /*instance*/, void *store, const v void INI::parseDurationUnsignedInt( INI *ini, void * /*instance*/, void *store, const void* /*userData*/ ) { UnsignedInt val = scanUnsignedInt(ini->getNextToken()); - *(UnsignedInt *)store = (UnsignedInt)WWMath::CeilfOrigin(ConvertDurationFromMsecsToFrames((Real)val)); + *(UnsignedInt *)store = (UnsignedInt)WWMath::Ceilf_Origin(ConvertDurationFromMsecsToFrames((Real)val)); } // ------------------------------------------------------------------------------------------------ @@ -1797,7 +1797,7 @@ void INI::parseDurationUnsignedInt( INI *ini, void * /*instance*/, void *store, void INI::parseDurationUnsignedShort( INI *ini, void * /*instance*/, void *store, const void* /*userData*/ ) { UnsignedInt val = scanUnsignedInt(ini->getNextToken()); - *(UnsignedShort *)store = (UnsignedShort)WWMath::CeilfOrigin(ConvertDurationFromMsecsToFrames((Real)val)); + *(UnsignedShort *)store = (UnsignedShort)WWMath::Ceilf_Origin(ConvertDurationFromMsecsToFrames((Real)val)); } //------------------------------------------------------------------------------------------------- diff --git a/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp b/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp index d73fa771825..a102a5f145e 100644 --- a/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp +++ b/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp @@ -727,9 +727,9 @@ inline Bool isReallyClose(const Coord3D& a, const Coord3D& b) { const Real CLOSE_ENOUGH = 0.1f; return - WWMath::FAbsOrigin(a.x-b.x) <= CLOSE_ENOUGH && - WWMath::FAbsOrigin(a.y-b.y) <= CLOSE_ENOUGH && - WWMath::FAbsOrigin(a.z-b.z) <= CLOSE_ENOUGH; + WWMath::FAbs_Origin(a.x-b.x) <= CLOSE_ENOUGH && + WWMath::FAbs_Origin(a.y-b.y) <= CLOSE_ENOUGH && + WWMath::FAbs_Origin(a.z-b.z) <= CLOSE_ENOUGH; } /** @@ -921,7 +921,7 @@ void Path::computePointOnPath( // compute distance of point from this path segment Real toDistSqr = sqr(toPos.x) + sqr(toPos.y); Real offsetDistSq = toDistSqr - sqr(alongPathDist); - Real offsetDist = (offsetDistSq <= 0.0) ? 0.0 : WWMath::SqrtOrigin(offsetDistSq); + Real offsetDist = (offsetDistSq <= 0.0) ? 0.0 : WWMath::Sqrt_Origin(offsetDistSq); // If we are basically on the path, return the next path node as the movement goal. // However, the farther off the path we get, the movement goal becomes closer to our @@ -1011,8 +1011,8 @@ void Path::computePointOnPath( out.posOnPath.x = closeNodePos->x + alongPathDist * segmentDirNorm.x; out.posOnPath.y = closeNodePos->y + alongPathDist * segmentDirNorm.y; out.posOnPath.z = closeNodePos->z; - Real dx = WWMath::FAbsOrigin(pos.x - out.posOnPath.x); - Real dy = WWMath::FAbsOrigin(pos.y - out.posOnPath.y); + Real dx = WWMath::FAbs_Origin(pos.x - out.posOnPath.x); + Real dy = WWMath::FAbs_Origin(pos.y - out.posOnPath.y); if (dx<1 && dy<1 && closeNode->getNextOptimized() && closeNode->getNextOptimized()->getNextOptimized()) { out.posOnPath = *closeNode->getNextOptimized()->getNextOptimized()->getPosition(); } @@ -2070,7 +2070,7 @@ UnsignedInt PathfindCell::costToGoal( PathfindCell *goal ) Int dy = m_info->m_pos.y - goal->getYIndex(); #define NO_REAL_DIST #ifdef REAL_DIST - Int cost = COST_ORTHOGONAL*WWMath::SqrtOrigin(dx*dx + dy*dy); + Int cost = COST_ORTHOGONAL*WWMath::Sqrt_Origin(dx*dx + dy*dy); #else if (dx<0) dx = -dx; if (dy<0) dy = -dy; @@ -2096,7 +2096,7 @@ UnsignedInt PathfindCell::costToHierGoal( PathfindCell *goal ) } Int dx = m_info->m_pos.x - goal->getXIndex(); Int dy = m_info->m_pos.y - goal->getYIndex(); - Int cost = REAL_TO_INT_FLOOR(COST_ORTHOGONAL*WWMath::SqrtOrigin(dx*dx + dy*dy) + 0.5f); + Int cost = REAL_TO_INT_FLOOR(COST_ORTHOGONAL*WWMath::Sqrt_Origin(dx*dx + dy*dy) + 0.5f); return cost; } @@ -3963,8 +3963,8 @@ Bool PathfindLayer::isPointOnWall(ObjectID *wallPieces, Int numPieces, const Coo Real pty = pt->y - obj->getPosition()->y; // inverse-rotate it to the right coord system - Real ptx_new = (Real)WWMath::FAbsOrigin(ptx*c - pty*s); - Real pty_new = (Real)WWMath::FAbsOrigin(ptx*s + pty*c); + Real ptx_new = (Real)WWMath::FAbs_Origin(ptx*c - pty*s); + Real pty_new = (Real)WWMath::FAbs_Origin(ptx*s + pty*c); if (ptx_new <= major && pty_new <= minor) { @@ -6415,7 +6415,7 @@ Int Pathfinder::examineNeighboringCells(PathfindCell *parentCell, PathfindCell * toPos.y = newCellCoord.y * PATHFIND_CELL_SIZE_F ; toPos.z = TheTerrainLogic->getGroundHeight(toPos.x , toPos.y); - if ( WWMath::FAbsOrigin(fromPos.z - toPos.z)getPinched()) { @@ -6440,7 +6440,7 @@ Int Pathfinder::examineNeighboringCells(PathfindCell *parentCell, PathfindCell * } else { dx = newCellCoord.x - goalCell->getXIndex(); dy = newCellCoord.y - goalCell->getYIndex(); - costRemaining = COST_ORTHOGONAL*WWMath::SqrtOrigin(dx*dx + dy*dy); + costRemaining = COST_ORTHOGONAL*WWMath::Sqrt_Origin(dx*dx + dy*dy); costRemaining -= attackDistance/2; if (costRemaining<0) costRemaining=0; @@ -6764,7 +6764,7 @@ Path *Pathfinder::internalFindPath( Object *obj, const LocomotorSet& locomotorSe dx = from->x - to->x; dy = from->y - to->y; - Int count = WWMath::SqrtOrigin(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); + Int count = WWMath::Sqrt_Origin(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); if (count<2) count = 2; Int i; color.green = 0; @@ -7455,7 +7455,7 @@ Path *Pathfinder::findGroundPath( const Coord3D *from, dx = from->x - to->x; dy = from->y - to->y; - Int count = WWMath::SqrtOrigin(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); + Int count = WWMath::Sqrt_Origin(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); if (count<2) count = 2; Int i; color.green = 0; @@ -8159,7 +8159,7 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu dx = from->x - to->x; dy = from->y - to->y; - Int count = WWMath::SqrtOrigin(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); + Int count = WWMath::Sqrt_Origin(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); if (count<2) count = 2; Int i; color.green = 0; @@ -11216,7 +11216,7 @@ Path *Pathfinder::findSafePath( const Object *obj, const LocomotorSet& locomotor farthestDistanceSqr = distSqr; if (cellCount > MAX_CELLS) { #ifdef INTENSE_DEBUG - DEBUG_LOG(("Took intermediate path, dist %f, goal dist %f", WWMath::SqrtOrigin(farthestDistanceSqr), repulsorRadius)); + DEBUG_LOG(("Took intermediate path, dist %f, goal dist %f", WWMath::Sqrt_Origin(farthestDistanceSqr), repulsorRadius)); #endif ok = true; // Already a big search, just take this one. } diff --git a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h index 3526310a2b1..9d65851902c 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h +++ b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h @@ -41,16 +41,10 @@ #include #include -// TheSuperHackers @fix VC6 does not support long long or required by GameMath (gmath.h). // Use __has_include because wwmath.h is transitively included by targets that may not link gamemath. -#if !(defined(_MSC_VER) && _MSC_VER < 1300) #if defined(__has_include) && __has_include("gmath.h") #include "gmath.h" -#endif -#endif - -#if !(defined(_MSC_VER) && _MSC_VER < 1300) -#define USE_DETERMINISTIC_MATH +#define USE_DETERMINISTIC_MATH (1) #endif /* @@ -145,7 +139,7 @@ static WWINLINE float Fast_Asin(float val); static WWINLINE float Asin(float val); -#ifdef USE_DETERMINISTIC_MATH +#if 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); } #else @@ -155,18 +149,18 @@ static WWINLINE float Atan2(float y,float x) { return static_cast(atan2( // Trig wrappers: replace global Sin/Cos/Tan/ACos/ASin from deleted Trig.cpp. // Original Trig.cpp called CRT float functions (sinf, cosf, etc.). -#ifdef USE_DETERMINISTIC_MATH - 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); } +#if USE_DETERMINISTIC_MATH + static WWINLINE float Sin_Trig(float x) { return gm_sinf(x); } + static WWINLINE float Cos_Trig(float x) { return gm_cosf(x); } + static WWINLINE float Tan_Trig(float x) { return gm_tanf(x); } + static WWINLINE float ACos_Trig(float x) { return gm_acosf(x); } + static WWINLINE float ASin_Trig(float x) { return gm_asinf(x); } #else - 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); } + static WWINLINE float Sin_Trig(float x) { return sinf(x); } + static WWINLINE float Cos_Trig(float x) { return cosf(x); } + static WWINLINE float Tan_Trig(float x) { return tanf(x); } + static WWINLINE float ACos_Trig(float x) { return acosf(x); } + static WWINLINE float ASin_Trig(float x) { return asinf(x); } #endif // Origin wrappers: replace bare CRT math calls in GameLogic. @@ -174,57 +168,58 @@ static WWINLINE float Atan2(float y,float x) { return static_cast(atan2( // Note: double overloads narrow to float before calling GameMath (gm_*f). // GameMath only provides float-precision functions. All call sites pass float-width // values, so the narrowing is lossless in practice. -#ifdef USE_DETERMINISTIC_MATH - static WWINLINE double SqrtOrigin(double x) { return (double)gm_sqrtf((float)x); } - static WWINLINE float SqrtfOrigin(float x) { return gm_sqrtf(x); } - static WWINLINE double Atan2Origin(double y, double x) { return (double)gm_atan2f((float)y, (float)x); } - static WWINLINE float Atan2fOrigin(float y, float x) { return gm_atan2f(y, x); } - static WWINLINE double AtanOrigin(double x) { return (double)gm_atanf((float)x); } - static WWINLINE float AtanfOrigin(float x) { return gm_atanf(x); } - static WWINLINE double ACosOrigin(double x) { return (double)gm_acosf((float)x); } - static WWINLINE float ACosfOrigin(float x) { return gm_acosf(x); } - static WWINLINE double ASinOrigin(double x) { return (double)gm_asinf((float)x); } - static WWINLINE float ASinfOrigin(float x) { return gm_asinf(x); } - static WWINLINE double TanOrigin(double x) { return (double)gm_tanf((float)x); } - static WWINLINE float TanfOrigin(float x) { return gm_tanf(x); } - static WWINLINE double FAbsOrigin(double x) { return (double)gm_fabsf((float)x); } - static WWINLINE float FAbsfOrigin(float x) { return gm_fabsf(x); } - static WWINLINE double PowOrigin(double x, double y) { return (double)gm_powf((float)x, (float)y); } - static WWINLINE float PowfOrigin(float x, float y) { return gm_powf(x, y); } - static WWINLINE double CeilOrigin(double x) { return (double)gm_ceilf((float)x); } - static WWINLINE float CeilfOrigin(float x) { return gm_ceilf(x); } - static WWINLINE float ExpfOrigin(float x) { return gm_expf(x); } - static WWINLINE float Log10fOrigin(float x) { return gm_log10f(x); } - static WWINLINE float LogfOrigin(float x) { return gm_logf(x); } - static WWINLINE float SinhfOrigin(float x) { return gm_sinhf(x); } - static WWINLINE float CoshfOrigin(float x) { return gm_coshf(x); } - static WWINLINE float TanhfOrigin(float x) { return gm_tanhf(x); } +#if USE_DETERMINISTIC_MATH + static WWINLINE double Sqrt_Origin(double x) { return (double)gm_sqrtf((float)x); } + static WWINLINE float Sqrtf_Origin(float x) { return gm_sqrtf(x); } + static WWINLINE double Atan2_Origin(double y, double x) { return (double)gm_atan2f((float)y, (float)x); } + static WWINLINE float Atan2f_Origin(float y, float x) { return gm_atan2f(y, x); } + static WWINLINE double Atan_Origin(double x) { return (double)gm_atanf((float)x); } + static WWINLINE float Atanf_Origin(float x) { return gm_atanf(x); } + static WWINLINE double ACos_Origin(double x) { return (double)gm_acosf((float)x); } + static WWINLINE float ACosf_Origin(float x) { return gm_acosf(x); } + static WWINLINE double ASin_Origin(double x) { return (double)gm_asinf((float)x); } + static WWINLINE float ASinf_Origin(float x) { return gm_asinf(x); } + static WWINLINE double Tan_Origin(double x) { return (double)gm_tanf((float)x); } + static WWINLINE float Tanf_Origin(float x) { return gm_tanf(x); } + static WWINLINE double FAbs_Origin(double x) { return (double)gm_fabsf((float)x); } + static WWINLINE float FAbsf_Origin(float x) { return gm_fabsf(x); } + static WWINLINE double Pow_Origin(double x, double y) { return (double)gm_powf((float)x, (float)y); } + static WWINLINE float Powf_Origin(float x, float y) { return gm_powf(x, y); } + static WWINLINE double Ceil_Origin(double x) { return (double)gm_ceilf((float)x); } + static WWINLINE float Ceilf_Origin(float x) { return gm_ceilf(x); } + static WWINLINE float Expf_Origin(float x) { return gm_expf(x); } + static WWINLINE float Log10f_Origin(float x) { return gm_log10f(x); } + static WWINLINE float Logf_Origin(float x) { return gm_logf(x); } + static WWINLINE float Sinhf_Origin(float x) { return gm_sinhf(x); } + static WWINLINE float Coshf_Origin(float x) { return gm_coshf(x); } + static WWINLINE float Tanhf_Origin(float x) { return gm_tanhf(x); } #else - static WWINLINE double SqrtOrigin(double x) { return sqrt(x); } - static WWINLINE float SqrtfOrigin(float x) { return sqrtf(x); } - static WWINLINE double Atan2Origin(double y, double x) { return atan2(y, x); } - static WWINLINE float Atan2fOrigin(float y, float x) { return atan2f(y, x); } - static WWINLINE double AtanOrigin(double x) { return atan(x); } - static WWINLINE float AtanfOrigin(float x) { return atanf(x); } - static WWINLINE double ACosOrigin(double x) { return acos(x); } - static WWINLINE float ACosfOrigin(float x) { return acosf(x); } - static WWINLINE double ASinOrigin(double x) { return asin(x); } - static WWINLINE float ASinfOrigin(float x) { return asinf(x); } - static WWINLINE double TanOrigin(double x) { return tan(x); } - static WWINLINE float TanfOrigin(float x) { return tanf(x); } - static WWINLINE double FAbsOrigin(double x) { return fabs(x); } - static WWINLINE float FAbsfOrigin(float x) { return fabsf(x); } - static WWINLINE double PowOrigin(double x, double y) { return pow(x, y); } - static WWINLINE float PowfOrigin(float x, float y) { return powf(x, y); } - static WWINLINE double CeilOrigin(double x) { return ceil(x); } - static WWINLINE float CeilfOrigin(float x) { return ceilf(x); } - static WWINLINE float ExpfOrigin(float x) { return expf(x); } - static WWINLINE float Log10fOrigin(float x) { return log10f(x); } - static WWINLINE float LogfOrigin(float x) { return logf(x); } - static WWINLINE float SinhfOrigin(float x) { return sinhf(x); } - static WWINLINE float CoshfOrigin(float x) { return coshf(x); } - static WWINLINE float TanhfOrigin(float x) { return tanhf(x); } + static WWINLINE double Sqrt_Origin(double x) { return sqrt(x); } + static WWINLINE float Sqrtf_Origin(float x) { return sqrtf(x); } + static WWINLINE double Atan2_Origin(double y, double x) { return atan2(y, x); } + static WWINLINE float Atan2f_Origin(float y, float x) { return atan2f(y, x); } + static WWINLINE double Atan_Origin(double x) { return atan(x); } + static WWINLINE float Atanf_Origin(float x) { return atanf(x); } + static WWINLINE double ACos_Origin(double x) { return acos(x); } + static WWINLINE float ACosf_Origin(float x) { return acosf(x); } + static WWINLINE double ASin_Origin(double x) { return asin(x); } + static WWINLINE float ASinf_Origin(float x) { return asinf(x); } + static WWINLINE double Tan_Origin(double x) { return tan(x); } + static WWINLINE float Tanf_Origin(float x) { return tanf(x); } + static WWINLINE double FAbs_Origin(double x) { return fabs(x); } + static WWINLINE float FAbsf_Origin(float x) { return fabsf(x); } + static WWINLINE double Pow_Origin(double x, double y) { return pow(x, y); } + static WWINLINE float Powf_Origin(float x, float y) { return powf(x, y); } + static WWINLINE double Ceil_Origin(double x) { return ceil(x); } + static WWINLINE float Ceilf_Origin(float x) { return ceilf(x); } + static WWINLINE float Expf_Origin(float x) { return expf(x); } + static WWINLINE float Log10f_Origin(float x) { return log10f(x); } + static WWINLINE float Logf_Origin(float x) { return logf(x); } + static WWINLINE float Sinhf_Origin(float x) { return sinhf(x); } + static WWINLINE float Coshf_Origin(float x) { return coshf(x); } + static WWINLINE float Tanhf_Origin(float x) { return tanhf(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); } @@ -403,7 +398,7 @@ WWINLINE bool WWMath::Is_Valid_Double(double x) // Float to long // ---------------------------------------------------------------------------- -#if defined(USE_DETERMINISTIC_MATH) +#if USE_DETERMINISTIC_MATH WWINLINE long WWMath::Float_To_Long(float f) { return gm_lrintf(f); @@ -429,7 +424,7 @@ WWINLINE long WWMath::Float_To_Long(float f) WWINLINE long WWMath::Float_To_Long(double f) { -#if defined(USE_DETERMINISTIC_MATH) +#if USE_DETERMINISTIC_MATH return gm_lrint(f); #elif defined(_MSC_VER) && defined(_M_IX86) long retval; @@ -445,7 +440,7 @@ WWINLINE long WWMath::Float_To_Long(double f) // Cos // ---------------------------------------------------------------------------- -#if defined(USE_DETERMINISTIC_MATH) +#if USE_DETERMINISTIC_MATH WWINLINE float WWMath::Cos(float val) { return gm_cosf(val); @@ -472,7 +467,7 @@ WWINLINE float WWMath::Cos(float val) // Sin // ---------------------------------------------------------------------------- -#if defined(USE_DETERMINISTIC_MATH) +#if USE_DETERMINISTIC_MATH WWINLINE float WWMath::Sin(float val) { return gm_sinf(val); @@ -623,7 +618,7 @@ WWINLINE float WWMath::Fast_Acos(float val) WWINLINE float WWMath::Acos(float val) { -#ifdef USE_DETERMINISTIC_MATH +#if USE_DETERMINISTIC_MATH return gm_acosf(val); #else return (float)acos(val); @@ -664,7 +659,7 @@ WWINLINE float WWMath::Fast_Asin(float val) WWINLINE float WWMath::Asin(float val) { -#ifdef USE_DETERMINISTIC_MATH +#if USE_DETERMINISTIC_MATH return gm_asinf(val); #else return (float)asin(val); @@ -675,7 +670,7 @@ WWINLINE float WWMath::Asin(float val) // Sqrt // ---------------------------------------------------------------------------- -#if defined(USE_DETERMINISTIC_MATH) +#if USE_DETERMINISTIC_MATH WWINLINE float WWMath::Sqrt(float val) { return gm_sqrtf(val); @@ -728,7 +723,7 @@ WWINLINE int WWMath::Float_To_Int_Floor (const float& f) // Inverse square root // ---------------------------------------------------------------------------- -#if defined(USE_DETERMINISTIC_MATH) +#if USE_DETERMINISTIC_MATH WWINLINE float WWMath::Inv_Sqrt(float val) { return 1.0f / gm_sqrtf(val); diff --git a/Generals/Code/GameEngine/Source/Common/RTS/Player.cpp b/Generals/Code/GameEngine/Source/Common/RTS/Player.cpp index 6250c452368..4b8280bcfb1 100644 --- a/Generals/Code/GameEngine/Source/Common/RTS/Player.cpp +++ b/Generals/Code/GameEngine/Source/Common/RTS/Player.cpp @@ -2327,7 +2327,7 @@ void Player::doBountyForKill(const Object* killer, const Object* victim) Int bounty = REAL_TO_INT_CEIL(costToBuild * m_cashBountyPercent); #else // TheSuperHackers @bugfix Stubbjax 20/02/2026 Subtract epsilon to ensure bounty is rounded up correctly. - Int bounty = WWMath::CeilOrigin((costToBuild * m_cashBountyPercent) - WWMATH_EPSILON); + Int bounty = WWMath::Ceil_Origin((costToBuild * m_cashBountyPercent) - WWMATH_EPSILON); #endif if( bounty ) diff --git a/Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp b/Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp index 561d5246ee5..b675000a5eb 100644 --- a/Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp +++ b/Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp @@ -1405,7 +1405,7 @@ Bool BuildAssistant::moveObjectsForConstruction( const ThingTemplate *whatToBuil Bool anyUnmovables = false; MemoryPoolObjectHolder hold( iter ); - Real radius = WWMath::SqrtOrigin(WWMath::PowOrigin(gi.getMajorRadius(), 2) + WWMath::PowOrigin(gi.getMinorRadius(), 2)); + Real radius = WWMath::Sqrt_Origin(WWMath::Pow_Origin(gi.getMajorRadius(), 2) + WWMath::Pow_Origin(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 dbe3279be50..e7b1bdb1813 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 = WWMath::SqrtOrigin(sqr(thatPos.x - thisCenter.x) + sqr(thatPos.y - thisCenter.y)); + Real dxy = WWMath::Sqrt_Origin(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 = WWMath::Atan2Origin(dz, dxy); + maxPitch = WWMath::Atan2_Origin(dz, dxy); dz = (thatPos.z - that.getMaxHeightBelowPosition()) - thisCenter.z; - minPitch = WWMath::Atan2Origin(dz, dxy); + minPitch = WWMath::Atan2_Origin(dz, dxy); } //============================================================================= @@ -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 = WWMath::SqrtOrigin(sqr(dx) + sqr(dy)); + Real radius = WWMath::Sqrt_Origin(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 = WWMath::SqrtOrigin(sqr(dx) + sqr(dy)); + Real radius = WWMath::Sqrt_Origin(sqr(dx) + sqr(dy)); return (radius <= m_majorRadius); break; } @@ -506,8 +506,8 @@ void GeometryInfo::calcBoundingStuff() case GEOMETRY_BOX: { - m_boundingCircleRadius = WWMath::SqrtOrigin(sqr(m_majorRadius) + sqr(m_minorRadius)); - m_boundingSphereRadius = WWMath::SqrtOrigin(sqr(m_majorRadius) + sqr(m_minorRadius) + sqr(m_height*0.5)); + m_boundingCircleRadius = WWMath::Sqrt_Origin(sqr(m_majorRadius) + sqr(m_minorRadius)); + m_boundingSphereRadius = WWMath::Sqrt_Origin(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 index d7d9ab3db9c..592d2c25869 100644 --- a/Generals/Code/GameEngine/Source/Common/System/Trig.cpp +++ b/Generals/Code/GameEngine/Source/Common/System/Trig.cpp @@ -51,32 +51,32 @@ Real Sin(Real x) { - return WWMath::SinTrig(x); + return WWMath::Sin_Trig(x); } Real Cos(Real x) { - return WWMath::CosTrig(x); + return WWMath::Cos_Trig(x); } Real Tan(Real x) { - return WWMath::TanTrig(x); + return WWMath::Tan_Trig(x); } Real ACos(Real x) { - return WWMath::ACosTrig(x); + return WWMath::ACos_Trig(x); } Real ASin(Real x) { - return WWMath::ASinTrig(x); + return WWMath::ASin_Trig(x); } double Sqrt(double x) { - return WWMath::SqrtOrigin(x); + return WWMath::Sqrt_Origin(x); } #ifdef REGENERATE_TRIG_TABLES diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AI.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AI.cpp index ecd327cec5d..e79efe431c3 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 = WWMath::SqrtOrigin(distSqr); + Real dist = WWMath::Sqrt_Origin(distSqr); Int modifier = dist/getAiData()->m_attackPriorityDistanceModifier; Int modPriority = curPriority-modifier; if (modPriority < 1) diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp index c2ef8bd3fda..67de1e572d0 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp @@ -482,7 +482,7 @@ Object *AIPlayer::buildStructureNow(const ThingTemplate *bldgPlan, BuildListInfo { Coord3D rallyPoint; Bool gotOffset = false; - if (WWMath::FAbsOrigin(info->getRallyOffset()->x) > 1.0f || WWMath::FAbsOrigin(info->getRallyOffset()->y)>1.0f) { + if (WWMath::FAbs_Origin(info->getRallyOffset()->x) > 1.0f || WWMath::FAbs_Origin(info->getRallyOffset()->y)>1.0f) { gotOffset; } if (!exitInterface->getNaturalRallyPoint(rallyPoint)) { @@ -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 = WWMath::SqrtOrigin(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); + Int count = WWMath::Sqrt_Origin(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); if (count<2) count = 2; Int i; color.green = 1; @@ -662,7 +662,7 @@ Object *AIPlayer::buildStructureWithDozer(const ThingTemplate *bldgPlan, BuildLi { Coord3D rallyPoint; Bool gotOffset = false; - if (WWMath::FAbsOrigin(info->getRallyOffset()->x) > 1.0f || WWMath::FAbsOrigin(info->getRallyOffset()->y)>1.0f) { + if (WWMath::FAbs_Origin(info->getRallyOffset()->x) > 1.0f || WWMath::FAbs_Origin(info->getRallyOffset()->y)>1.0f) { gotOffset; } if (!exitInterface->getNaturalRallyPoint(rallyPoint)) { @@ -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)) { @@ -2806,7 +2806,7 @@ void AIPlayer::computeCenterAndRadiusOfBase(Coord3D *center, Real *radius) Real radSqr = dx*dx+dy*dy; if (radSqr>maxRadSqr) maxRadSqr=radSqr; } - *radius = WWMath::SqrtOrigin(maxRadSqr); + *radius = WWMath::Sqrt_Origin(maxRadSqr); } //---------------------------------------------------------------------------------------------------------- diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp index 9ddc0c054f9..17ab979250f 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp @@ -524,7 +524,7 @@ StateReturnType AIRappelState::onEnter() obj->setLayer(layerAtDest); AIUpdateInterface *ai = obj->getAI(); - Real MAX_RAPPEL_RATE = WWMath::FAbsOrigin(TheGlobalData->m_gravity) * LOGICFRAMES_PER_SECOND * 2.5f; + Real MAX_RAPPEL_RATE = WWMath::FAbs_Origin(TheGlobalData->m_gravity) * LOGICFRAMES_PER_SECOND * 2.5f; m_rappelRate = -min(ai->getDesiredSpeed(), MAX_RAPPEL_RATE); return STATE_CONTINUE; @@ -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.", WWMath::SqrtOrigin(distSqr))); + DEBUG_LOG(("AIAttackMoveToState::update Distance from goal %f, retrying.", WWMath::Sqrt_Origin(distSqr))); ret = STATE_CONTINUE; m_retryCount--; @@ -3802,7 +3802,7 @@ void AIFollowWaypointPathState::computeGoal(Bool useGroupOffsets) if (m_priorWaypoint) { dx = dest.x - m_priorWaypoint->getLocation()->x; dy = dest.y - m_priorWaypoint->getLocation()->y; - angle = WWMath::Atan2Origin(dy, dx); + angle = WWMath::Atan2_Origin(dy, dx); Real deltaAngle = angle - m_angle; Real s = sin(deltaAngle); Real c = cos(deltaAngle); @@ -3811,7 +3811,7 @@ void AIFollowWaypointPathState::computeGoal(Bool useGroupOffsets) m_groupOffset.x = x; m_groupOffset.y = y; } else { - angle = WWMath::Atan2Origin(dy, dx); + angle = WWMath::Atan2_Origin(dy, dx); } m_angle = angle; #endif @@ -4933,7 +4933,7 @@ StateReturnType AIAttackAimAtTargetState::update() //DEBUG_LOG(("AIM: desired %f, actual %f, delta %f, aimDelta %f, goalpos %f %f",rad2deg(obj->getOrientation() + relAngle),rad2deg(obj->getOrientation()),rad2deg(relAngle),rad2deg(aimDelta),victim->getPosition()->x,victim->getPosition()->y)); if (m_canTurnInPlace) { - if (WWMath::FAbsOrigin(relAngle) > aimDelta) + if (WWMath::FAbs_Origin(relAngle) > aimDelta) { Real desiredAngle = source->getOrientation() + relAngle; sourceAI->setLocomotorGoalOrientation(desiredAngle); @@ -4945,7 +4945,7 @@ StateReturnType AIAttackAimAtTargetState::update() sourceAI->setLocomotorGoalPositionExplicit(m_isAttackingObject ? *victim->getPosition() : *getMachineGoalPosition()); } - if (WWMath::FAbsOrigin(relAngle) < aimDelta /*&& !m_preAttackFrames*/ ) + if (WWMath::FAbs_Origin(relAngle) < aimDelta /*&& !m_preAttackFrames*/ ) { AIUpdateInterface* victimAI = victim ? victim->getAI() : nullptr; // add ourself as a targeter BEFORE calling isTemporarilyPreventingAimSuccess(). @@ -6983,7 +6983,7 @@ StateReturnType AIFaceState::update() Real relAngle = ThePartitionManager->getRelativeAngle2D( obj, pos ); const Real REL_THRESH = 0.035f; // about 2 degrees. (getRelativeAngle2D is current only accurate to about 1.25 degrees) - if( WWMath::FAbsOrigin( relAngle ) < REL_THRESH ) + if( WWMath::FAbs_Origin( relAngle ) < REL_THRESH ) { return STATE_SUCCESS; } diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp index 22085b0c6d8..61e07c1d3bd 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp @@ -386,7 +386,7 @@ Bool TurretAI::friend_turnTowardsAngle(Real desiredAngle, Real rateModifier, Rea Real angleDiff = normalizeAngle(desiredAngle - actualAngle); // Are we close enough to the desired angle to just snap there? - if (WWMath::FAbsOrigin(angleDiff) < turnRate) + if (WWMath::FAbs_Origin(angleDiff) < turnRate) { // we are centered actualAngle = desiredAngle; @@ -409,7 +409,7 @@ Bool TurretAI::friend_turnTowardsAngle(Real desiredAngle, Real rateModifier, Rea if( m_angle != origAngle ) getOwner()->reactToTurretChange( m_whichTurret, origAngle, m_pitch ); - Bool aligned = WWMath::FAbsOrigin(m_angle - desiredAngle) <= relThresh; + Bool aligned = WWMath::FAbs_Origin(m_angle - desiredAngle) <= relThresh; return aligned; } @@ -427,7 +427,7 @@ Bool TurretAI::friend_turnTowardsPitch(Real desiredPitch, Real rateModifier) Real pitchRate = getPitchRate() * rateModifier; Real pitchDiff = normalizeAngle(desiredPitch - actualPitch); - if (WWMath::FAbsOrigin(pitchDiff) < pitchRate) + if (WWMath::FAbs_Origin(pitchDiff) < pitchRate) { // we are centered actualPitch = desiredPitch; @@ -1070,7 +1070,7 @@ StateReturnType TurretAIAimTurretState::update() turret->friend_setPositiveSweep(!turret->friend_getPositiveSweep()); Real angleDiff = normalizeAngle(relAngle - turret->getTurretAngle()); - turnAlignedToNemesis = (WWMath::FAbsOrigin(angleDiff) < sweep); + turnAlignedToNemesis = (WWMath::FAbs_Origin(angleDiff) < sweep); } Bool pitchAlignedToNemesis = true; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp b/Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp index d1884a02e73..e377b66d84f 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 = WWMath::SqrtOrigin(halfHeight*halfHeight + halfWidth*halfWidth); + m_radius = WWMath::Sqrt_Origin(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 0fbf0547113..37f9c570720 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 WWMath::Atan2Origin(xvec.y, xvec.x) == angle. So we must construct + that WWMath::Atan2_Origin(xvec.y, xvec.x) == angle. So we must construct the matrix carefully to ensure this! */ x.x = Cos( angle ); @@ -1489,7 +1489,7 @@ void makeAlignToNormalMatrix( Real angle, const Coord3D& pos, const Coord3D& nor x.normalize(); } - DEBUG_ASSERTCRASH(WWMath::FAbsOrigin(x.x*z.x + x.y*z.y + x.z*z.z)<0.0001,("dot is not zero (%f)",WWMath::FAbsOrigin(x.x*z.x + x.y*z.y + x.z*z.z))); + DEBUG_ASSERTCRASH(WWMath::FAbs_Origin(x.x*z.x + x.y*z.y + x.z*z.z)<0.0001,("dot is not zero (%f)",WWMath::FAbs_Origin(x.x*z.x + x.y*z.y + x.z*z.z))); // now computing the y vector is trivial. y.crossProduct( &z, &x, &y ); @@ -1685,12 +1685,12 @@ PathfindLayerEnum TerrainLogic::getLayerForDestination(const Coord3D *pos) { Bridge *pBridge = getFirstBridge(); PathfindLayerEnum bestLayer = LAYER_GROUND; - Real bestDistance = WWMath::FAbsOrigin(pos->z - getGroundHeight(pos->x, pos->y)); + Real bestDistance = WWMath::FAbs_Origin(pos->z - getGroundHeight(pos->x, pos->y)); if (bestDistance > TheAI->pathfinder()->getWallHeight()/2) { // check wall. if (TheAI->pathfinder()->isPointOnWall(pos)) { - Real delta = WWMath::FAbsOrigin(pos->z-TheAI->pathfinder()->getWallHeight()); + Real delta = WWMath::FAbs_Origin(pos->z-TheAI->pathfinder()->getWallHeight()); if (deltaisPointOnBridge(pos) ) { - Real delta = WWMath::FAbsOrigin(pos->z-pBridge->getBridgeHeight(pos, nullptr)); + Real delta = WWMath::FAbs_Origin(pos->z-pBridge->getBridgeHeight(pos, nullptr)); if (deltagetLayer(); bestDistance = delta; @@ -1724,7 +1724,7 @@ PathfindLayerEnum TerrainLogic::getHighestLayerForDestination(const Coord3D *pos if (TheAI->pathfinder()->isPointOnWall(pos)) { Real delta = pos->z - TheAI->pathfinder()->getWallHeight(); // must be ABOVE (or on) the wall for this call. (srj) - if (delta >= 0 && WWMath::FAbsOrigin(delta) < WWMath::FAbsOrigin(bestDistance)) { + if (delta >= 0 && WWMath::FAbs_Origin(delta) < WWMath::FAbs_Origin(bestDistance)) { bestLayer = (PathfindLayerEnum)LAYER_WALL; bestDistance = delta; } @@ -1739,7 +1739,7 @@ PathfindLayerEnum TerrainLogic::getHighestLayerForDestination(const Coord3D *pos if (pBridge->isPointOnBridge(pos) ) { Real delta = pos->z - pBridge->getBridgeHeight(pos, nullptr); // must be ABOVE (or on) the bridge for this call. (srj) - if (delta >= 0 && WWMath::FAbsOrigin(delta) < WWMath::FAbsOrigin(bestDistance)) { + if (delta >= 0 && WWMath::FAbs_Origin(delta) < WWMath::FAbs_Origin(bestDistance)) { bestLayer = pBridge->getLayer(); bestDistance = delta; } @@ -1788,7 +1788,7 @@ Bool TerrainLogic::objectInteractsWithBridgeLayer(Object *obj, Int layer, Bool c if (match) { Real bridgeHeight = pBridge->getBridgeHeight(obj->getPosition(), nullptr); - Real delta = WWMath::FAbsOrigin(obj->getPosition()->z-bridgeHeight); + Real delta = WWMath::FAbs_Origin(obj->getPosition()->z-bridgeHeight); if (delta>LAYER_Z_CLOSE_ENOUGH_F) { return false; } @@ -1837,7 +1837,7 @@ Bool TerrainLogic::objectInteractsWithBridgeEnd(Object *obj, Int layer) const if (match) { Real bridgeHeight = pBridge->getBridgeHeight(obj->getPosition(), nullptr); - Real delta = WWMath::FAbsOrigin(obj->getPosition()->z-bridgeHeight); + Real delta = WWMath::FAbs_Origin(obj->getPosition()->z-bridgeHeight); if (delta>LAYER_Z_CLOSE_ENOUGH_F) { return false; @@ -2055,10 +2055,10 @@ Coord3D TerrainLogic::findClosestEdgePoint ( const Coord3D *closestTo ) const getExtent( &mapExtent ); Real distances[4]; - distances[0] = WWMath::FAbsOrigin( closestTo->y - mapExtent.lo.y );//top - distances[1] = WWMath::FAbsOrigin( closestTo->x - mapExtent.hi.x );//right - distances[2] = WWMath::FAbsOrigin( closestTo->y - mapExtent.hi.y );//bottom - distances[3] = WWMath::FAbsOrigin( closestTo->x - mapExtent.lo.x );//left + distances[0] = WWMath::FAbs_Origin( closestTo->y - mapExtent.lo.y );//top + distances[1] = WWMath::FAbs_Origin( closestTo->x - mapExtent.hi.x );//right + distances[2] = WWMath::FAbs_Origin( closestTo->y - mapExtent.hi.y );//bottom + distances[3] = WWMath::FAbs_Origin( closestTo->x - mapExtent.lo.x );//left Real bestDistance = distances[0]; Int bestDistanceIndex = 0; for( Int lameIndex = 1; lameIndex < 4; lameIndex++ ) @@ -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 = WWMath::SqrtOrigin( affectedRegion.width() * affectedRegion.width() + + Real maxDist = WWMath::Sqrt_Origin( 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 924d99db6ab..345829b3e7a 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp @@ -169,24 +169,24 @@ static Bool calcTrajectory( Real dz = end.z - start.z; // calculating the angle is trivial. - angle = WWMath::Atan2Origin(dy, dx); + angle = WWMath::Atan2_Origin(dy, dx); // calculating the pitch requires a bit more effort. Real horizDistSqr = sqr(dx) + sqr(dy); - Real horizDist = WWMath::SqrtOrigin(horizDistSqr); + Real horizDist = WWMath::Sqrt_Origin(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) - Real gravity = WWMath::FAbsOrigin(TheGlobalData->m_gravity); + Real gravity = WWMath::FAbs_Origin(TheGlobalData->m_gravity); Real gravityTwoDZ = gravity * 2.0f * dz; // 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 = WWMath::Atan2Origin(dz, horizDist); + Real theta = WWMath::Atan2_Origin(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; - if (WWMath::FAbsOrigin(theta) > SHALLOW_ANGLE) + if (WWMath::FAbs_Origin(theta) > SHALLOW_ANGLE) { Real t = horizDist / velocity; Real vz = (dz/t + 0.5f*gravity*t); @@ -287,7 +287,7 @@ static Bool calcTrajectory( #endif vx = velocity*cosPitches[preferred]; - Real actualRange = (vx*(vz + WWMath::SqrtOrigin(root)))/gravity; + Real actualRange = (vx*(vz + WWMath::Sqrt_Origin(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 = WWMath::SqrtOrigin(ThePartitionManager->getDistanceSquared( projectile, &victimPosToUse, FROM_CENTER_2D ) ); + Real range = WWMath::Sqrt_Origin(ThePartitionManager->getDistanceSquared( projectile, &victimPosToUse, FROM_CENTER_2D ) ); Real rangeRatio = (range - minRange) / (maxRange - minRange); m_flightPathSpeed = (rangeRatio * (weaponSpeed - minWeaponSpeed)) + minWeaponSpeed; } @@ -441,7 +441,7 @@ Bool DumbProjectileBehavior::calcFlightPath(Bool recalcNumSegments) if (recalcNumSegments) { Real flightDistance = flightCurve.getApproximateLength(); - m_flightPathSegments = WWMath::CeilOrigin( flightDistance / m_flightPathSpeed ); + m_flightPathSegments = WWMath::Ceil_Origin( flightDistance / m_flightPathSpeed ); } flightCurve.getSegmentPoints( m_flightPathSegments, &m_flightPath ); DEBUG_ASSERTCRASH(m_flightPathSegments == m_flightPath.size(), ("m_flightPathSegments mismatch")); @@ -596,7 +596,7 @@ UpdateSleepTime DumbProjectileBehavior::update() Real distVictimMovedSqr = sqr(delta.x) + sqr(delta.y) + sqr(delta.z); if (distVictimMovedSqr > 0.1f) { - Real distVictimMoved = WWMath::SqrtfOrigin(distVictimMovedSqr); + Real distVictimMoved = WWMath::Sqrtf_Origin(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 b197c8f0f1a..bd4c13100ca 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 = WWMath::SqrtOrigin(sqr(dx) + sqr(dy)); + Real len = WWMath::Sqrt_Origin(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 ec96df057be..1b41e4e4e15 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(WWMath::SqrtfOrigin(2.0f * (start.z - endOnGround.z) / WWMath::FAbsOrigin(TheGlobalData->m_gravity))); + UnsignedInt fallingTime = REAL_TO_INT_CEIL(WWMath::Sqrtf_Origin(2.0f * (start.z - endOnGround.z) / WWMath::FAbs_Origin(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,8 +580,8 @@ 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 = WWMath::SqrtOrigin(sqr(dx) + sqr(dy)); - if (dist <= 0.1f && WWMath::FAbsOrigin(dz) <= 0.1f) + Real dist = WWMath::Sqrt_Origin(sqr(dx) + sqr(dy)); + if (dist <= 0.1f && WWMath::FAbs_Origin(dz) <= 0.1f) { obj->setPosition(&endOnGround); m_scootFramesLeft = 0; @@ -590,7 +590,7 @@ void MinefieldBehavior::setScootParms(const Coord3D& start, const Coord3D& end) { Real t = (Real)scootFromStartingPointTime; Real scootFromStartingPointSpeed = dist / t; - Real accelMag = WWMath::FAbsOrigin(2.0f * (dist - scootFromStartingPointSpeed*t)/sqr(t)); + Real accelMag = WWMath::FAbs_Origin(2.0f * (dist - scootFromStartingPointSpeed*t)/sqr(t)); Real dxNorm = (dist <= 0.1f) ? 0.0f : (dx / dist); Real dyNorm = (dist <= 0.1f) ? 0.0f : (dy / dist); m_scootVel.x = dxNorm * scootFromStartingPointSpeed; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp index b770e8e9506..cf17f4714a3 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 = WWMath::Atan2Origin(force.y, force.x); + Real orientation = WWMath::Atan2_Origin(force.y, force.x); physics->setAngles(orientation, 0, 0); obj->getDrawable()->setModelConditionState(MODELCONDITION_EXPLODED_FLAILING); m_flags |= (1<getPosition()->z) >= d->m_paraOpenDist) + if (WWMath::FAbs_Origin(m_startZ - parachute->getPosition()->z) >= d->m_paraOpenDist) { m_opened = true; parachute->clearAndSetModelConditionState(MODELCONDITION_FREEFALL, MODELCONDITION_PARACHUTING); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp index 6a1a838249d..62666ff1539 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp @@ -84,7 +84,7 @@ static Real calcSlowDownDist(Real curSpeed, Real desiredSpeed, Real maxBraking) if (delta <= 0) return 0.0f; - Real dist = (sqr(delta) / WWMath::FAbsOrigin(maxBraking)) * 0.5f; + Real dist = (sqr(delta) / WWMath::FAbs_Origin(maxBraking)) * 0.5f; // use a little fudge so that things can stop "on a dime" more easily... const Real FUDGE = 1.05f; @@ -95,14 +95,14 @@ static Real calcSlowDownDist(Real curSpeed, Real desiredSpeed, Real maxBraking) inline Bool isNearlyZero(Real a) { const Real TINY_EPSILON = 0.001f; - return WWMath::FAbsOrigin(a) < TINY_EPSILON; + return WWMath::FAbs_Origin(a) < TINY_EPSILON; } //----------------------------------------------------------------------------- inline Bool isNearly(Real a, Real val) { const Real TINY_EPSILON = 0.001f; - return WWMath::FAbsOrigin(a - val) < TINY_EPSILON; + return WWMath::FAbs_Origin(a - val) < TINY_EPSILON; } //----------------------------------------------------------------------------- @@ -141,7 +141,7 @@ static Real tryToRotateVector3D( } } - if (WWMath::FAbsOrigin(angleBetween) <= maxAngle) + if (WWMath::FAbs_Origin(angleBetween) <= maxAngle) { // close enough actualDir = goalDir; @@ -231,9 +231,9 @@ static void calcDirectionToApplyThrust( Bool foundSolution = false; Real distToGoalSqr = vecToGoal.Length2(); - Real distToGoal = WWMath::SqrtOrigin(distToGoalSqr); + Real distToGoal = WWMath::Sqrt_Origin(distToGoalSqr); Real curVelMagSqr = curVel.Length2(); - Real curVelMag = WWMath::SqrtOrigin(curVelMagSqr); + Real curVelMag = WWMath::Sqrt_Origin(curVelMagSqr); Real maxAccelSqr = sqr(maxAccel); Real denom = curVelMagSqr - maxAccelSqr; @@ -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 = WWMath::SqrtOrigin(dx*dx+dy*dy); + Real dist = WWMath::Sqrt_Origin(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 = WWMath::SqrtOrigin(dx*dx+dy*dy+dz*dz); + dist = WWMath::Sqrt_Origin(dx*dx+dy*dy+dz*dz); Real vel = physics->getVelocityMagnitude(); if (vel < MIN_VEL) vel = MIN_VEL; @@ -1107,7 +1107,7 @@ void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalP // Normalize. if (dist > 0.001f) { - Real vel = WWMath::FAbsOrigin(physics->getForwardSpeed2D()); + Real vel = WWMath::FAbs_Origin(physics->getForwardSpeed2D()); if (vel < MIN_VEL) vel = MIN_VEL; if (vel > dist) @@ -1152,7 +1152,7 @@ void Locomotor::moveTowardsPositionTreads(Object* obj, PhysicsBehavior *physics, // Modulate speed according to turning. The more we have to turn, the slower we go // const Real QUAETERPI = PI / 4.0f; - Real angleCoeff = (Real)WWMath::FAbsOrigin( relAngle ) / QUAETERPI; + Real angleCoeff = (Real)WWMath::FAbs_Origin( relAngle ) / QUAETERPI; if (angleCoeff > 1.0f) angleCoeff = 1.0; @@ -1223,7 +1223,7 @@ void Locomotor::moveTowardsPositionTreads(Object* obj, PhysicsBehavior *physics, see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (WWMath::FAbsOrigin(accelForce) > WWMath::FAbsOrigin(maxForceNeeded)) + if (WWMath::FAbs_Origin(accelForce) > WWMath::FAbs_Origin(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); @@ -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 = WWMath::Atan2Origin(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2_Origin(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real relAngle = stdAngleDiff(desiredAngle, angle); Bool moveBackwards = false; @@ -1275,14 +1275,14 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, #if 1 if (actualSpeed==0.0f) { setFlag(MOVING_BACKWARDS, false); - if (m_template->m_canMoveBackward && WWMath::FAbsOrigin(relAngle) > PI/2) { + if (m_template->m_canMoveBackward && WWMath::FAbs_Origin(relAngle) > PI/2) { setFlag(MOVING_BACKWARDS, true ); setFlag(DOING_THREE_POINT_TURN, onPathDistToGoal>5*obj->getGeometryInfo().getMajorRadius()); } } if (getFlag(MOVING_BACKWARDS)) { - if (WWMath::FAbsOrigin(relAngle) < PI/2) { + if (WWMath::FAbs_Origin(relAngle) < PI/2) { moveBackwards = false; setFlag(MOVING_BACKWARDS, false); } else { @@ -1298,7 +1298,7 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, #endif const Real SMALL_TURN = PI / 20.0f; - if ((Real)WWMath::FAbsOrigin( relAngle ) > SMALL_TURN) + if ((Real)WWMath::FAbs_Origin( relAngle ) > SMALL_TURN) { if (desiredSpeed>turnSpeed) { @@ -1323,7 +1323,7 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, const Real FIFTEEN_DEGREES = PI / 12.0f; const Real PROJECT_FRAMES = LOGICFRAMES_PER_SECOND/2; // Project out 1/2 second. - if (WWMath::FAbsOrigin( relAngle ) > FIFTEEN_DEGREES) + if (WWMath::FAbs_Origin( relAngle ) > FIFTEEN_DEGREES) { // If we're turning more than 10 degrees, check & see if we're moving into "impassable territory" Real distance = PROJECT_FRAMES * (goalSpeed+actualSpeed)/2.0f; @@ -1462,7 +1462,7 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (WWMath::FAbsOrigin(accelForce) > WWMath::FAbsOrigin(maxForceNeeded)) + if (WWMath::FAbs_Origin(accelForce) > WWMath::FAbs_Origin(maxForceNeeded)) accelForce = maxForceNeeded; //DEBUG_LOG(("Braking %d, actualSpeed %f, goalSpeed %f, delta %f, accel %f", getFlag(IS_BRAKING), @@ -1533,7 +1533,7 @@ Bool Locomotor::fixInvalidPosition(Object* obj, PhysicsBehavior *physics) //physics->clearAcceleration(); if (dot<0) { - dot = WWMath::SqrtOrigin(-dot); + dot = WWMath::Sqrt_Origin(-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 = WWMath::Atan2Origin(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2_Origin(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; @@ -1623,7 +1623,7 @@ void Locomotor::moveTowardsPositionLegs(Object* obj, PhysicsBehavior *physics, c // Modulate speed according to turning. The more we have to turn, the slower we go // const Real QUARTERPI = PI / 4.0f; - Real angleCoeff = (Real)WWMath::FAbsOrigin( relAngle ) / (QUARTERPI); + Real angleCoeff = (Real)WWMath::FAbs_Origin( relAngle ) / (QUARTERPI); if (angleCoeff > 1.0f) angleCoeff = 1.0; @@ -1653,7 +1653,7 @@ void Locomotor::moveTowardsPositionLegs(Object* obj, PhysicsBehavior *physics, c see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (WWMath::FAbsOrigin(accelForce) > WWMath::FAbsOrigin(maxForceNeeded)) + if (WWMath::FAbs_Origin(accelForce) > WWMath::FAbs_Origin(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); @@ -1695,7 +1695,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, if (dz*dz > sqr(PATHFIND_CELL_SIZE_F)) { setFlag(CLIMBING, true); } - if (WWMath::FAbsOrigin(dz)<1) { + if (WWMath::FAbs_Origin(dz)<1) { setFlag(CLIMBING, false); } @@ -1715,7 +1715,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, moveBackwards = true; } - Real groundSlope = WWMath::FAbsOrigin(delta.z - pos.z); + Real groundSlope = WWMath::FAbs_Origin(delta.z - pos.z); if (groundSlope<1.0f) groundSlope = 1.0f; if (groundSlope>1.0f) { @@ -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 = WWMath::Atan2Origin(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2_Origin(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real relAngle = stdAngleDiff(desiredAngle, angle); if (moveBackwards) { @@ -1744,7 +1744,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, // Modulate speed according to turning. The more we have to turn, the slower we go // const Real QUARTERPI = PI / 4.0f; - Real angleCoeff = (Real)WWMath::FAbsOrigin( relAngle ) / (QUARTERPI); + Real angleCoeff = (Real)WWMath::FAbs_Origin( relAngle ) / (QUARTERPI); if (angleCoeff > 1.0f) angleCoeff = 1.0; @@ -1786,7 +1786,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (WWMath::FAbsOrigin(accelForce) > WWMath::FAbsOrigin(maxForceNeeded)) + if (WWMath::FAbs_Origin(accelForce) > WWMath::FAbs_Origin(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); @@ -1813,7 +1813,7 @@ void Locomotor::moveTowardsPositionWings(Object* obj, PhysicsBehavior *physics, Real dx = goalPos.x - pos->x; Real dy = goalPos.y - pos->y; Real dz = goalPos.z - pos->z; - if (WWMath::FAbsOrigin(dz) > m_circleThresh) + if (WWMath::FAbs_Origin(dz) > m_circleThresh) { // aim for the spot on the opposite side of the circle. @@ -1821,7 +1821,7 @@ void Locomotor::moveTowardsPositionWings(Object* obj, PhysicsBehavior *physics, Real angleTowardPos = (isNearlyZero(dx) && isNearlyZero(dy)) ? obj->getOrientation() : - WWMath::Atan2Origin(dy, dx); + WWMath::Atan2_Origin(dy, dx); Real aimDir = (PI - PI/8); angleTowardPos += aimDir; @@ -1910,7 +1910,7 @@ void Locomotor::moveTowardsPositionThrust(Object* obj, PhysicsBehavior *physics, // so we tend to "level out" at that height. we don't use this till // below, but go ahead and calc it now... Real MAX_VERTICAL_DAMP_RANGE = m_preferredHeight * 0.5; - delta = WWMath::FAbsOrigin(delta); + delta = WWMath::FAbs_Origin(delta); if (delta > MAX_VERTICAL_DAMP_RANGE) delta = MAX_VERTICAL_DAMP_RANGE; zDirDamping = 1.0f - (delta / MAX_VERTICAL_DAMP_RANGE); @@ -2027,7 +2027,7 @@ Real Locomotor::calcLiftToUseAtPt(Object* obj, PhysicsBehavior *physics, Real cu // see how far we need to slow to dead stop, given max braking Real desiredAccel; const Real TINY_ACCEL = 0.001f; - if (WWMath::FAbsOrigin(maxAccel) > TINY_ACCEL) + if (WWMath::FAbs_Origin(maxAccel) > TINY_ACCEL) { Real deltaZ = preferredHeight - curZ; // calc how far it will take for us to go from cur speed to zero speed, at max accel. @@ -2035,14 +2035,14 @@ Real Locomotor::calcLiftToUseAtPt(Object* obj, PhysicsBehavior *physics, Real cu // in theory, the above is the correct calculation, but in practice, // doesn't work in some situations (eg, opening of USA01 map). Why, I dunno. // But for now I have gone back to the old, looks-incorrect-to-me-but-works calc. (srj) - Real brakeDist = (sqr(curVelZ) / WWMath::FAbsOrigin(maxAccel)); - if (WWMath::FAbsOrigin(brakeDist) > WWMath::FAbsOrigin(deltaZ)) + Real brakeDist = (sqr(curVelZ) / WWMath::FAbs_Origin(maxAccel)); + if (WWMath::FAbs_Origin(brakeDist) > WWMath::FAbs_Origin(deltaZ)) { // if the dist-to-accel (or dist-to-brake) is further than the dist-to-go, // use the max accel. desiredAccel = maxAccel; } - else if (WWMath::FAbsOrigin(curVelZ) > m_template->m_speedLimitZ) + else if (WWMath::FAbs_Origin(curVelZ) > m_template->m_speedLimitZ) { // or, if we're going too fast, limit it here. desiredAccel = m_template->m_speedLimitZ - curVelZ; @@ -2116,8 +2116,8 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 Real dx =goalPos.x - turnPos.x; 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 (WWMath::FAbsOrigin(dx)<0.1f && WWMath::FAbsOrigin(dy)<0.1f) return TURN_NONE; - Real desiredAngle = WWMath::Atan2Origin(dy, dx); + if (WWMath::FAbs_Origin(dx)<0.1f && WWMath::FAbs_Origin(dy)<0.1f) return TURN_NONE; + Real desiredAngle = WWMath::Atan2_Origin(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 = WWMath::Atan2Origin(desiredPos.y - turnPos.y, desiredPos.x - turnPos.x); + Real angleDesiredForTurnPos = WWMath::Atan2_Origin(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 = WWMath::Atan2Origin(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2_Origin(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real amount = stdAngleDiff(desiredAngle, angle); if (relAngle) *relAngle = amount; if (amount>maxTurnRate) { @@ -2333,8 +2333,8 @@ void Locomotor::moveTowardsPositionOther(Object* obj, PhysicsBehavior *physics, //fabs(goalPos.y - pos->y),fabs(goalPos.x - pos->x), //fabs(goalPos.y - pos->y)/goalSpeed,fabs(goalPos.x - pos->x)/goalSpeed)); if (getFlag(ULTRA_ACCURATE) && - WWMath::FAbsOrigin(goalPos.y - pos->y) <= goalSpeed * m_template->m_ultraAccurateSlideIntoPlaceFactor && - WWMath::FAbsOrigin(goalPos.x - pos->x) <= goalSpeed * m_template->m_ultraAccurateSlideIntoPlaceFactor) + WWMath::FAbs_Origin(goalPos.y - pos->y) <= goalSpeed * m_template->m_ultraAccurateSlideIntoPlaceFactor && + WWMath::FAbs_Origin(goalPos.x - pos->x) <= goalSpeed * m_template->m_ultraAccurateSlideIntoPlaceFactor) { // don't turn, just slide in the right direction physics->setTurning(TURN_NONE); @@ -2373,7 +2373,7 @@ void Locomotor::moveTowardsPositionOther(Object* obj, PhysicsBehavior *physics, see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (WWMath::FAbsOrigin(accelForce) > WWMath::FAbsOrigin(maxForceNeeded)) + if (WWMath::FAbs_Origin(accelForce) > WWMath::FAbs_Origin(maxForceNeeded)) accelForce = maxForceNeeded; Coord3D force; @@ -2488,7 +2488,7 @@ void Locomotor::maintainCurrentPositionWings(Object* obj, PhysicsBehavior *physi Real angleTowardMaintainPos = (isNearlyZero(dx) && isNearlyZero(dy)) ? obj->getOrientation() : - WWMath::Atan2Origin(dy, dx); + WWMath::Atan2_Origin(dy, dx); Real aimDir = (PI - PI/8); if (turnRadius < 0) @@ -2522,7 +2522,7 @@ void Locomotor::maintainCurrentPositionHover(Object* obj, PhysicsBehavior *physi // Real minSpeed = max( 1.0E-10f, m_template->m_minSpeed ); Real speedDelta = minSpeed - actualSpeed; - if (WWMath::FAbsOrigin(speedDelta) > minSpeed) + if (WWMath::FAbs_Origin(speedDelta) > minSpeed) { Real mass = physics->getMass(); Real acceleration = (speedDelta > 0.0f) ? maxAcceleration : -getBraking(); @@ -2533,7 +2533,7 @@ void Locomotor::maintainCurrentPositionHover(Object* obj, PhysicsBehavior *physi see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (WWMath::FAbsOrigin(accelForce) > WWMath::FAbsOrigin(maxForceNeeded)) + if (WWMath::FAbs_Origin(accelForce) > WWMath::FAbs_Origin(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp index cc544a37e37..75a74aff5cb 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp @@ -1594,13 +1594,13 @@ inline Bool isPosDifferent(const Coord3D* a, const Coord3D* b) // so we must put in some cleverness... const Real THRESH = 0.01f; - if (WWMath::FAbsOrigin(a->x - b->x) > THRESH) + if (WWMath::FAbs_Origin(a->x - b->x) > THRESH) return true; - if (WWMath::FAbsOrigin(a->y - b->y) > THRESH) + if (WWMath::FAbs_Origin(a->y - b->y) > THRESH) return true; - if (WWMath::FAbsOrigin(a->z - b->z) > THRESH) + if (WWMath::FAbs_Origin(a->z - b->z) > THRESH) return true; return false; @@ -1616,7 +1616,7 @@ inline Bool isAngleDifferent(Real a, Real b) const Real THRESH = 0.01f; // in radians, this is approx 1/2 degree. - if (WWMath::FAbsOrigin(a - b) > THRESH) + if (WWMath::FAbs_Origin(a - b) > THRESH) return true; return false; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp index 3c80a648899..5dda768f394 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 = WWMath::SqrtOrigin( dx*dx + dy*dy ); + Real length = WWMath::Sqrt_Origin( dx*dx + dy*dy ); //Normalize length dx /= length; @@ -348,7 +348,7 @@ class DeliverPayloadNugget : public ObjectCreationNugget } - Real orient = WWMath::Atan2Origin( moveToPos.y - startPos.y, moveToPos.x - startPos.x); + Real orient = WWMath::Atan2_Origin( 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 = WWMath::Atan2Origin(force.y, force.x); + orientation = WWMath::Atan2_Origin(force.y, force.x); } } @@ -1155,7 +1155,7 @@ class GenericObjectCreationNugget : public ObjectCreationNugget objUp->applyForce(&force); if (m_orientInForceDirection) { - orientation = WWMath::Atan2Origin(force.y, force.x); + orientation = WWMath::Atan2_Origin(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 3130ecf8f09..2811bfbeee6 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp @@ -411,13 +411,13 @@ static void testRotatedPointsAgainstRect( Real pty = pts->y - a->position.y; // inverse-rotate it to the right coord system - Real ptx_new = (Real)WWMath::FAbsOrigin(ptx*c - pty*s); - Real pty_new = (Real)WWMath::FAbsOrigin(ptx*s + pty*c); + Real ptx_new = (Real)WWMath::FAbs_Origin(ptx*c - pty*s); + Real pty_new = (Real)WWMath::FAbs_Origin(ptx*s + pty*c); #ifdef INTENSE_DEBUG Real mag_a = sqr(ptx)+sqr(pty); Real mag_b = sqr(ptx_new)+sqr(pty_new); - DEBUG_ASSERTCRASH(WWMath::FAbsOrigin(mag_a - mag_b) <= 1.0, ("hmm, unlikely")); + DEBUG_ASSERTCRASH(WWMath::FAbs_Origin(mag_a - mag_b) <= 1.0, ("hmm, unlikely")); #endif if (ptx_new <= major && pty_new <= minor) @@ -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)WWMath::SqrtfOrigin(sqr(a->geom.getMajorRadius()) - sqr(b_bot - a->position.z))); + amod.geom.setMajorRadius((Real)WWMath::Sqrtf_Origin(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)WWMath::SqrtfOrigin(sqr(a->geom.getMajorRadius()) - sqr(a->position.z - b_top))); + amod.geom.setMajorRadius((Real)WWMath::Sqrtf_Origin(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 = WWMath::SqrtfOrigin(actualDistSqr); + Real actualDist = WWMath::Sqrtf_Origin(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 = WWMath::SqrtfOrigin(actualDistSqr); + Real actualDist = WWMath::Sqrtf_Origin(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)(WWMath::SqrtfOrigin(majorRadius*majorRadius + minorRadius*minorRadius)); + Real diagonal = (Real)(WWMath::Sqrtf_Origin(majorRadius*majorRadius + minorRadius*minorRadius)); Int cells = ThePartitionManager->worldToCellDist(diagonal*2) + 1; result = cells * cells; break; @@ -2636,7 +2636,7 @@ static void calcHeights(const Region3D& world, Real cellSize, Int x, Int y, Real Real xbase = world.lo.x + (x * cellSize); Real ybase = world.lo.y + (y * cellSize); const Real ROUGH_STEP_SIZE = 2; // roughly every 2 ft, please - Real numSteps = WWMath::CeilfOrigin(cellSize / ROUGH_STEP_SIZE); + Real numSteps = WWMath::Ceilf_Origin(cellSize / ROUGH_STEP_SIZE); Real step = cellSize / numSteps; loZ = HUGE_DIST; // huge positive hiZ = -HUGE_DIST; // huge negative @@ -3210,7 +3210,7 @@ Int PartitionManager::calcMinRadius(const ICoord2D& cur) } // double, not real - double dist = WWMath::SqrtfOrigin(minDistSqr); + double dist = WWMath::Sqrtf_Origin(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 = WWMath::SqrtOrigin(dx*dx + dy*dy); + double maxPossibleDist = WWMath::Sqrt_Origin(dx*dx + dy*dy); m_maxGcoRadius = REAL_TO_INT_CEIL(maxPossibleDist / cellSize); @@ -3498,7 +3498,7 @@ Object *PartitionManager::getClosestObjects( } if (closestDistArg) { - *closestDistArg = (Real)WWMath::SqrtfOrigin(closestDistSqr); + *closestDistArg = (Real)WWMath::Sqrtf_Origin(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)WWMath::SqrtfOrigin(sqr(v.x) + sqr(v.y)); + Real dist = (Real)WWMath::Sqrtf_Origin(sqr(v.x) + sqr(v.y)); // normalize if (dist == 0.0f) @@ -3803,7 +3803,7 @@ Bool PartitionManager::tryPosition( const Coord3D *center, pos.z = TheTerrainLogic->getGroundHeight( pos.x, pos.y ); } - if (WWMath::FAbsOrigin(pos.z - center->z) > options->maxZDelta) + if (WWMath::FAbs_Origin(pos.z - center->z) > options->maxZDelta) return FALSE; // @@ -4556,7 +4556,7 @@ Int PartitionManager::iterateCellsBreadthFirst(const Coord3D *pos, CellBreadthFi //----------------------------------------------------------------------------- static Real calcDist2D(Real x1, Real y1, Real x2, Real y2) { - return WWMath::SqrtfOrigin(sqr(x1-x2) + sqr(y1-y2)); + return WWMath::Sqrtf_Origin(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 = WWMath::SqrtOrigin( WWMath::PowOrigin(x - parms->xCenter, 2) + WWMath::PowOrigin(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt_Origin( WWMath::Pow_Origin(x - parms->xCenter, 2) + WWMath::Pow_Origin(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 = WWMath::SqrtOrigin( WWMath::PowOrigin(x - parms->xCenter, 2) + WWMath::PowOrigin(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt_Origin( WWMath::Pow_Origin(x - parms->xCenter, 2) + WWMath::Pow_Origin(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 = WWMath::SqrtOrigin( WWMath::PowOrigin(x - parms->xCenter, 2) + WWMath::PowOrigin(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt_Origin( WWMath::Pow_Origin(x - parms->xCenter, 2) + WWMath::Pow_Origin(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 = WWMath::SqrtOrigin( WWMath::PowOrigin(x - parms->xCenter, 2) + WWMath::PowOrigin(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt_Origin( WWMath::Pow_Origin(x - parms->xCenter, 2) + WWMath::Pow_Origin(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 95ee0a7e140..3aa96ea857c 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp @@ -1282,8 +1282,8 @@ Bool AIUpdateInterface::blockedBy(Object *other) // If we are near our final goal, don't get stuck. if (goalCell.x>0 && goalCell.y>0) { - Real dx = WWMath::FAbsOrigin(goalPos.x-pos.x); - Real dy = WWMath::FAbsOrigin(goalPos.y-pos.y); + Real dx = WWMath::FAbs_Origin(goalPos.x-pos.x); + Real dy = WWMath::FAbs_Origin(goalPos.y-pos.y); if (dxgetRelativeAngle2D( getObject(), &info.posOnPath ); } - if (WWMath::FAbsOrigin(deltaAngle)>PI/30) + if (WWMath::FAbs_Origin(deltaAngle)>PI/30) { return TRUE; } @@ -2230,7 +2230,7 @@ UpdateSleepTime AIUpdateInterface::doLocomotor() } else { - Real dist = WWMath::SqrtfOrigin(dSqr); + Real dist = WWMath::Sqrtf_Origin(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 WWMath::SqrtOrigin( distance );// Other paths return dots of normalized vectors, so one sqrt ain't so bad + return WWMath::Sqrt_Origin( 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 WWMath::SqrtOrigin(distSqr); + return WWMath::Sqrt_Origin(distSqr); } else { @@ -2465,7 +2465,7 @@ Real AIUpdateInterface::getLocomotorDistanceToGoal() } if (distgetExtent( &terrainExtent ); const Real FUDGE = 1.2f; - Real HUGE_DIST = FUDGE * WWMath::SqrtOrigin(sqr(terrainExtent.hi.x - terrainExtent.lo.x) + sqr(terrainExtent.hi.y - terrainExtent.lo.y)); + Real HUGE_DIST = FUDGE * WWMath::Sqrt_Origin(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; @@ -569,7 +569,7 @@ class ChinookCombatDropState : public State { if (it->ropeLen < it->ropeLenMax) { - it->ropeSpeed += WWMath::FAbsOrigin(TheGlobalData->m_gravity); + it->ropeSpeed += WWMath::FAbs_Origin(TheGlobalData->m_gravity); if (it->ropeSpeed > d->m_ropeDropSpeed) it->ropeSpeed = d->m_ropeDropSpeed; it->ropeLen += it->ropeSpeed; @@ -761,7 +761,7 @@ class ChinookMoveToBldgState : public AIMoveToState StateReturnType status = AIMoveToState::update(); const Real THRESH = 3.0f; - if (status != STATE_CONTINUE && WWMath::FAbsOrigin(obj->getPosition()->z - m_destZ) > THRESH) + if (status != STATE_CONTINUE && WWMath::FAbs_Origin(obj->getPosition()->z - m_destZ) > THRESH) status = STATE_CONTINUE; return status; @@ -840,7 +840,7 @@ ChinookAIUpdateModuleData::ChinookAIUpdateModuleData() m_minDropHeight = 30.0f; m_ropeFinalHeight = 0.0f; m_ropeDropSpeed = 1e10f; // um, fast. - m_rappelSpeed = WWMath::FAbsOrigin(TheGlobalData->m_gravity) * LOGICFRAMES_PER_SECOND * 0.5f; + m_rappelSpeed = WWMath::FAbs_Origin(TheGlobalData->m_gravity) * LOGICFRAMES_PER_SECOND * 0.5f; m_ropeWobbleLen = 10.0f; m_ropeWobbleAmp = 1.0f; m_ropeWobbleRate = 0.1f; 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 a5fbc85d8f6..93e3a279b37 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 = WWMath::SqrtOrigin( endDiveDistanceSquared ); - Real currentDistance = WWMath::SqrtOrigin( currentDistanceSquared ); + Real endDiveDistance = WWMath::Sqrt_Origin( endDiveDistanceSquared ); + Real currentDistance = WWMath::Sqrt_Origin( currentDistanceSquared ); Real diveRatio = (startDiveDistance - currentDistance) / (startDiveDistance - endDiveDistance); @@ -1081,7 +1081,7 @@ StateReturnType RecoverFromOffMapState::update() // Success if we should try aga enterCoord.z = owner->getPosition()->z; owner->setPosition(&enterCoord); - Real enterAngle = WWMath::Atan2Origin(ai->getMoveToPos()->y - enterCoord.y, ai->getMoveToPos()->x - enterCoord.x); + Real enterAngle = WWMath::Atan2_Origin(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 * WWMath::SqrtOrigin(sqr(terrainExtent.hi.x - terrainExtent.lo.x) + sqr(terrainExtent.hi.y - terrainExtent.lo.y)); + Real HUGE_DIST = FUDGE * WWMath::Sqrt_Origin(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 74b10c53d19..ce4f5be3cfc 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp @@ -457,8 +457,8 @@ class JetOrHeliTaxiState : public AIMoveOutOfTheWayState Coord3D intermedPt; Bool intermed = false; - Real orient = WWMath::Atan2Origin(ppinfo.runwayPrep.y - ppinfo.parkingSpace.y, ppinfo.runwayPrep.x - ppinfo.parkingSpace.x); - if (WWMath::FAbsOrigin(stdAngleDiff(orient, ppinfo.parkingOrientation)) > PI/128) + Real orient = WWMath::Atan2_Origin(ppinfo.runwayPrep.y - ppinfo.parkingSpace.y, ppinfo.runwayPrep.x - ppinfo.parkingSpace.x); + if (WWMath::FAbs_Origin(stdAngleDiff(orient, ppinfo.parkingOrientation)) > PI/128) { intermedPt.z = (ppinfo.parkingSpace.z + ppinfo.runwayPrep.z) * 0.5f; intermed = intersectInfiniteLine2D( @@ -884,7 +884,7 @@ class HeliTakeoffOrLandingState : public State } else { - Real dist = WWMath::SqrtfOrigin(dSqr); + Real dist = WWMath::Sqrtf_Origin(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); @@ -1012,7 +1012,7 @@ class JetOrHeliParkOrientState : public State return STATE_FAILURE; const Real THRESH = 0.001f; - if (WWMath::FAbsOrigin(stdAngleDiff(jet->getOrientation(), ppinfo.parkingOrientation)) <= THRESH) + if (WWMath::FAbs_Origin(stdAngleDiff(jet->getOrientation(), ppinfo.parkingOrientation)) <= THRESH) return STATE_SUCCESS; // magically position it correctly. @@ -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(WWMath::Atan2Origin(dy, dx)); + m_lockonDrawable->setOrientation(WWMath::Atan2_Origin(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 ec81067b278..b6453b43afc 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 = WWMath::SqrtOrigin(sqr(dx)+sqr(dy)); + Real xyDist = WWMath::Sqrt_Origin(sqr(dx)+sqr(dy)); if (xyDist<1) xyDist = 1; Real zFactor = 0; if (deltaZ>0) { @@ -619,7 +619,7 @@ UpdateSleepTime MissileAIUpdate::update() Coord3D newPos = *getObject()->getPosition(); if (m_noTurnDistLeft > 0.0f && m_state >= IGNITION) { - Real distThisTurn = WWMath::SqrtfOrigin(sqr(newPos.x-m_prevPos.x) + sqr(newPos.y-m_prevPos.y) + sqr(newPos.z-m_prevPos.z)); + Real distThisTurn = WWMath::Sqrtf_Origin(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/POWTruckAIUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/POWTruckAIUpdate.cpp index ac85df56e69..44f7640b7b6 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/POWTruckAIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/POWTruckAIUpdate.cpp @@ -480,7 +480,7 @@ void POWTruckAIUpdate::updateCollectingTarget() { // are we close enough to tell them to start moving to us - Real distSq = WWMath::PowOrigin( us->getGeometryInfo().getBoundingSphereRadius() * 2.0f, 2 ); + Real distSq = WWMath::Pow_Origin( us->getGeometryInfo().getBoundingSphereRadius() * 2.0f, 2 ); if( ThePartitionManager->getDistanceSquared( us, target, FROM_CENTER_2D ) <= distSq ) { 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 78ba5dc24af..1336fd877b2 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)WWMath::SqrtfOrigin( dlt.x*dlt.x + dlt.y*dlt.y + dlt.z*dlt.z); + Real dist = (Real)WWMath::Sqrtf_Origin( 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. @@ -472,8 +472,8 @@ void RailroadBehavior::playImpactSound(Object *victim, const Coord3D *impactPosi impact.setPosition(impactPosition); if ( theirPhys ) { - vel += WWMath::FAbsOrigin(theirPhys->getVelocity()->length()); - mass += WWMath::FAbsOrigin(theirPhys->getMass()); + vel += WWMath::FAbs_Origin(theirPhys->getVelocity()->length()); + mass += WWMath::FAbs_Origin(theirPhys->getMass()); vel /= 2; mass /= 2;//average of him and me @@ -675,7 +675,7 @@ UpdateSleepTime RailroadBehavior::update() if ( m_conductorState == APPLY_BRAKES ) { conductorPullInfo.speed *= modData->m_braking; - if (WWMath::FAbsOrigin(conductorPullInfo.speed) < 0.01f) + if (WWMath::FAbs_Origin(conductorPullInfo.speed) < 0.01f) { conductorPullInfo.speed = 0; ///////////////////////////////////////( &m_hissySteamSound ); @@ -1193,7 +1193,7 @@ void alignToTerrain( Real angle, const Coord3D& pos, const Coord3D& normal, Matr x.normalize(); } - DEBUG_ASSERTCRASH(WWMath::FAbsOrigin(x.x*z.x + x.y*z.y + x.z*z.z)<0.0001,("dot is not zero")); + DEBUG_ASSERTCRASH(WWMath::FAbs_Origin(x.x*z.x + x.y*z.y + x.z*z.z)<0.0001,("dot is not zero")); // now computing the y vector is trivial. y.crossProduct( &z, &x, &y ); @@ -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 = WWMath::Atan2Origin(dy, dx); + Real desiredAngle = WWMath::Atan2_Origin(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 6054662da83..5e50d8eb351 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 = WWMath::SqrtOrigin( ThePartitionManager->getDistanceSquared( obj, &m_pos, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt_Origin( 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 = WWMath::SqrtOrigin( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt_Origin( 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 538123add49..70bf9e7bfe2 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 = WWMath::SqrtOrigin(distSqr); + Real dist = WWMath::Sqrt_Origin(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 0487e1be939..fdd52739e3c 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).", WWMath::SqrtOrigin(curDistSqr), WWMath::SqrtOrigin(closeEnoughSqr))); + DEBUG_LOG(("Failing dock, dist %f, not close enough(%f).", WWMath::Sqrt_Origin(curDistSqr), WWMath::Sqrt_Origin(closeEnoughSqr))); // Make it twitch a little. Coord3D newPos = *docker->getPosition(); Real range = 0.4*PATHFIND_CELL_SIZE_F; @@ -170,7 +170,7 @@ void SupplyWarehouseDockUpdate::setDockCrippled( Bool setting ) void SupplyWarehouseDockUpdate::setCashValue( Int cashValue ) { // A script can tell us our set value, and we need to figure out the boxes needed to provide that. - m_boxesStored = WWMath::CeilOrigin(cashValue / (float)TheGlobalData->m_baseValuePerSupplyBox); + m_boxesStored = WWMath::Ceil_Origin(cashValue / (float)TheGlobalData->m_baseValuePerSupplyBox); Drawable *draw = getObject()->getDrawable(); if( draw ) { diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp index 305979e6408..eb83e160ff8 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp @@ -297,7 +297,7 @@ static Real calcTransform(const Object* obj, const Coord3D *pos, Real maxTurnRat Real angle = (Real)ACos( c ); Vector3 newDir; - if (WWMath::FAbsOrigin(angle) < maxTurnRate) + if (WWMath::FAbs_Origin(angle) < maxTurnRate) { // close enough -- point exactly in the right dir newDir = otherDir; @@ -355,7 +355,7 @@ void NeutronMissileUpdate::doAttack() // // Modulate speed according to turning. The more we have to turn, the slower we go // - Real angleCoeff = (Real)WWMath::FAbsOrigin( relAngle ) / (PI / 2.0f); + Real angleCoeff = (Real)WWMath::FAbs_Origin( relAngle ) / (PI / 2.0f); if (angleCoeff > 1.0f) angleCoeff = 1.0; } @@ -512,7 +512,7 @@ UpdateSleepTime NeutronMissileUpdate::update() if (m_noTurnDistLeft > 0.0f && oldPosValid) { Coord3D newPos = *getObject()->getPosition(); - Real distThisTurn = WWMath::SqrtOrigin(sqr(newPos.x-oldPos.x) + sqr(newPos.y-oldPos.y) + sqr(newPos.z-oldPos.z)); + Real distThisTurn = WWMath::Sqrt_Origin(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/PhysicsUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp index df7bd65c63a..c5ba5cf0d46 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp @@ -93,7 +93,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 WWMath::SqrtOrigin(WWMath::FAbsOrigin(2.0f * TheGlobalData->m_gravity * height)); + return WWMath::Sqrt_Origin(WWMath::FAbs_Origin(2.0f * TheGlobalData->m_gravity * height)); } //------------------------------------------------------------------------------------------------- @@ -438,7 +438,7 @@ Bool PhysicsBehavior::handleBounce(Real oldZ, Real newZ, Real groundZ, Coord3D* Real vz = getVelocity()->z; if (oldZ > groundZ && vz < 0.0f) { - desiredAccelZ = WWMath::FAbsOrigin(vz) * stiffness; + desiredAccelZ = WWMath::FAbs_Origin(vz) * stiffness; } bounceForce->x = 0.0f; @@ -470,7 +470,7 @@ Bool PhysicsBehavior::handleBounce(Real oldZ, Real newZ, Real groundZ, Coord3D* inline Bool isVerySmall3D(const Coord3D& v) { const Real THRESH = 0.01f; - return (WWMath::FAbsOrigin(v.x) < THRESH && WWMath::FAbsOrigin(v.y) < THRESH && WWMath::FAbsOrigin(v.z) < THRESH); + return (WWMath::FAbs_Origin(v.x) < THRESH && WWMath::FAbs_Origin(v.y) < THRESH && WWMath::FAbs_Origin(v.z) < THRESH); } //------------------------------------------------------------------------------------------------- @@ -569,9 +569,9 @@ UpdateSleepTime PhysicsBehavior::update() // when vel gets tiny, just clamp to zero const Real THRESH = 0.001f; - if (WWMath::FAbsfOrigin(m_vel.x) < THRESH) m_vel.x = 0.0f; - if (WWMath::FAbsfOrigin(m_vel.y) < THRESH) m_vel.y = 0.0f; - if (WWMath::FAbsfOrigin(m_vel.z) < THRESH) m_vel.z = 0.0f; + if (WWMath::FAbsf_Origin(m_vel.x) < THRESH) m_vel.x = 0.0f; + if (WWMath::FAbsf_Origin(m_vel.y) < THRESH) m_vel.y = 0.0f; + if (WWMath::FAbsf_Origin(m_vel.z) < THRESH) m_vel.z = 0.0f; m_velMag = INVALID_VEL_MAG; @@ -636,8 +636,8 @@ UpdateSleepTime PhysicsBehavior::update() if (offset != 0.0f) { Vector3 xvec = mtx.Get_X_Vector(); - Real xy = WWMath::SqrtfOrigin(sqr(xvec.X) + sqr(xvec.Y)); - Real pitchAngle = WWMath::Atan2Origin(xvec.Z, xy); + Real xy = WWMath::Sqrtf_Origin(sqr(xvec.X) + sqr(xvec.Y)); + Real pitchAngle = WWMath::Atan2_Origin(xvec.Z, xy); Real remainingAngle = (offset > 0) ? ((PI/2) - pitchAngle) : (-(PI/2) + pitchAngle); Real s = Sin(remainingAngle); pitchRateToUse *= s; @@ -737,8 +737,8 @@ UpdateSleepTime PhysicsBehavior::update() // going down hills don't injure themselves (unless the hill is really steep) const Real MIN_ANGLE_TAN = 3.0f; // roughly 71 degrees const Real TINY_DELTA = 0.01f; - if ((WWMath::FAbsOrigin(m_vel.x) <= TINY_DELTA || WWMath::FAbsOrigin(activeVelZ / m_vel.x) >= MIN_ANGLE_TAN) && - (WWMath::FAbsOrigin(m_vel.y) <= TINY_DELTA || WWMath::FAbsOrigin(activeVelZ / m_vel.y) >= MIN_ANGLE_TAN)) + if ((WWMath::FAbs_Origin(m_vel.x) <= TINY_DELTA || WWMath::FAbs_Origin(activeVelZ / m_vel.x) >= MIN_ANGLE_TAN) && + (WWMath::FAbs_Origin(m_vel.y) <= TINY_DELTA || WWMath::FAbs_Origin(activeVelZ / m_vel.y) >= MIN_ANGLE_TAN)) { Real damageAmt = netSpeed * getMass() * d->m_fallHeightDamageFactor; @@ -817,7 +817,7 @@ Real PhysicsBehavior::getVelocityMagnitude() const { if (m_velMag == INVALID_VEL_MAG) { - m_velMag = (Real)WWMath::SqrtfOrigin( sqr(m_vel.x) + sqr(m_vel.y) + sqr(m_vel.z) ); + m_velMag = (Real)WWMath::Sqrtf_Origin( sqr(m_vel.x) + sqr(m_vel.y) + sqr(m_vel.z) ); } return m_velMag; } @@ -839,7 +839,7 @@ Real PhysicsBehavior::getForwardSpeed2D() const Real speedSquared = vx*vx + vy*vy; // DEBUG_ASSERTCRASH( speedSquared != 0, ("zero speedSquared will overflow sqrtf()!") );// lorenzen... sanity check - Real speed = (Real)WWMath::SqrtfOrigin( speedSquared ); + Real speed = (Real)WWMath::Sqrtf_Origin( speedSquared ); if (dot >= 0.0f) return speed; @@ -862,7 +862,7 @@ Real PhysicsBehavior::getForwardSpeed3D() const Real dot = vx + vy + vz; - Real speed = (Real)WWMath::SqrtfOrigin( vx*vx + vy*vy + vz*vz ); + Real speed = (Real)WWMath::Sqrtf_Origin( vx*vx + vy*vy + vz*vz ); if (dot >= 0.0f) return speed; @@ -885,7 +885,7 @@ Bool PhysicsBehavior::wasPreviouslyOverlapped(Object *obj) const //------------------------------------------------------------------------------------------------- void PhysicsBehavior::scrubVelocityZ( Real desiredVelocity ) { - if (WWMath::FAbsOrigin(desiredVelocity) < 0.001f) + if (WWMath::FAbs_Origin(desiredVelocity) < 0.001f) { m_vel.z = 0; } @@ -909,7 +909,7 @@ void PhysicsBehavior::scrubVelocity2D( Real desiredVelocity ) } else { - Real curVelocity = WWMath::SqrtfOrigin(m_vel.x*m_vel.x + m_vel.y*m_vel.y); + Real curVelocity = WWMath::Sqrtf_Origin(m_vel.x*m_vel.x + m_vel.y*m_vel.y); if (desiredVelocity > curVelocity) { return; @@ -992,9 +992,9 @@ void PhysicsBehavior::doBounceSound(const Coord3D& prevPos) //Real vel = fabs(getVelocity()->z); // can't use velocity, because it's already been updated this frame, and will be zero... (srj) - Real vel = WWMath::FAbsOrigin(prevPos.z - getObject()->getPosition()->z); + Real vel = WWMath::FAbs_Origin(prevPos.z - getObject()->getPosition()->z); - Real mass = WWMath::FAbsOrigin(getMass()); + Real mass = WWMath::FAbs_Origin(getMass()); if (vel > NORMAL_VEL_Z) { vel = NORMAL_VEL_Z; } @@ -1194,7 +1194,7 @@ void PhysicsBehavior::onCollide( Object *other, const Coord3D *loc, const Coord3 m_lastCollidee = other->getID(); - Real dist = WWMath::SqrtfOrigin(distSqr); + Real dist = WWMath::Sqrtf_Origin(distSqr); Real overlap = usRadius + themRadius - dist; // if objects are coincident, dist is zero, so force would be infinite -- clearly @@ -1297,7 +1297,7 @@ static Bool perpsLogicallyEqual( Real perpOne, Real perpTwo ) { // Equality with a wiggle fudge. const Real PERP_RANGE = 0.15f; - return WWMath::FAbsOrigin( perpOne - perpTwo ) <= PERP_RANGE; + return WWMath::FAbs_Origin( perpOne - perpTwo ) <= PERP_RANGE; } //------------------------------------------------------------------------------------------------- diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp index 6bd4e5d9441..ecec158b606 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 = WWMath::SqrtOrigin( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt_Origin( 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 = WWMath::SqrtOrigin( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt_Origin( 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 = WWMath::SqrtOrigin( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); + fDist = WWMath::Sqrt_Origin( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); } } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp index 9d542899c41..4d6e97f36c7 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp @@ -411,7 +411,7 @@ UpdateSleepTime StealthUpdate::update() m_disguiseHalfpointReached = true; } //Opacity ranges from full to none at midpoint and full again at the end - Real opacity = WWMath::FAbsOrigin( 1.0f - (factor * 2.0f) ); + Real opacity = WWMath::FAbs_Origin( 1.0f - (factor * 2.0f) ); Real overrideOpacity = opacity < 1.0f ? 0.0f : 1.0f; draw->setEffectiveOpacity( opacity, overrideOpacity ); if( !m_disguiseTransitionFrames && !m_transitioningToDisguise ) diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/TensileFormationUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/TensileFormationUpdate.cpp index cf1657308fb..6d3e1b2cf32 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/TensileFormationUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/TensileFormationUpdate.cpp @@ -348,7 +348,7 @@ UpdateSleepTime TensileFormationUpdate::update() else draw->clearModelConditionFlags(MAKE_MODELCONDITION_MASK(MODELCONDITION_MOVING)); - if ( WWMath::FAbsOrigin( pos->z - newPos.z ) > 0.2f && m_life < 100) + if ( WWMath::FAbs_Origin( pos->z - newPos.z ) > 0.2f && m_life < 100) draw->setModelConditionFlags(MAKE_MODELCONDITION_MASK(MODELCONDITION_FREEFALL)); else draw->clearModelConditionFlags(MAKE_MODELCONDITION_MASK(MODELCONDITION_FREEFALL)); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp index f74ef2c8211..c819e57ad06 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp @@ -130,7 +130,7 @@ static Real angleClosestTo(Real a1, Real a2, Real desired) { a1 = normalizeAngle(a1); a2 = normalizeAngle(a2); - return (WWMath::FAbsOrigin(stdAngleDiff(desired, a1)) < WWMath::FAbsOrigin(stdAngleDiff(desired, a2))) ? a1 : a2; + return (WWMath::FAbs_Origin(stdAngleDiff(desired, a1)) < WWMath::FAbs_Origin(stdAngleDiff(desired, a2))) ? a1 : a2; } //------------------------------------------------------------------------------------------------- @@ -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(WWMath::Atan2Origin(m_toppleDirection.y, m_toppleDirection.x)); + Real toppleAngle = normalizeAngle(WWMath::Atan2_Origin(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 @@ -298,7 +298,7 @@ UpdateSleepTime ToppleUpdate::update() m_angularVelocity *= -d->m_bounceVelocityPercent; if( BitIsSet( m_options, TOPPLE_OPTIONS_NO_BOUNCE ) == TRUE || - WWMath::FAbsOrigin(m_angularVelocity) < VELOCITY_BOUNCE_LIMIT ) + WWMath::FAbs_Origin(m_angularVelocity) < VELOCITY_BOUNCE_LIMIT ) { // too slow, just stop m_angularVelocity = 0; @@ -338,7 +338,7 @@ UpdateSleepTime ToppleUpdate::update() } } } - else if( WWMath::FAbsOrigin(m_angularVelocity) >= VELOCITY_BOUNCE_SOUND_LIMIT ) + else if( WWMath::FAbs_Origin(m_angularVelocity) >= VELOCITY_BOUNCE_SOUND_LIMIT ) { // fast enough bounce to warrant the bounce fx if( BitIsSet( m_options, TOPPLE_OPTIONS_NO_FX ) == FALSE ) diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp index 13aa3afd1e6..d60aaafd245 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp @@ -383,8 +383,8 @@ void WeaponTemplate::reset() // No matter what we have now, we want to convert it to frames from msec. // ShotDelay used to use parseDurationUnsignedInt, and we are expanding on that. - self->m_minDelayBetweenShots = WWMath::CeilfOrigin(ConvertDurationFromMsecsToFrames((Real)self->m_minDelayBetweenShots)); - self->m_maxDelayBetweenShots = WWMath::CeilfOrigin(ConvertDurationFromMsecsToFrames((Real)self->m_maxDelayBetweenShots)); + self->m_minDelayBetweenShots = WWMath::Ceilf_Origin(ConvertDurationFromMsecsToFrames((Real)self->m_minDelayBetweenShots)); + self->m_maxDelayBetweenShots = WWMath::Ceilf_Origin(ConvertDurationFromMsecsToFrames((Real)self->m_maxDelayBetweenShots)); } @@ -847,7 +847,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?",WWMath::SqrtfOrigin(distSqr),WWMath::SqrtfOrigin(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::Sqrtf_Origin(distSqr),WWMath::Sqrtf_Origin(minAttackRangeSqr))); //-extraLogging #if defined(RTS_DEBUG) @@ -873,7 +873,7 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate targetPos.set( victimPos ); } Real reAngle = getWeaponRecoilAmount(); - Real reDir = reAngle != 0.0f ? (WWMath::Atan2Origin(victimPos->y - sourcePos->y, victimPos->x - sourcePos->x)) : 0.0f; + Real reDir = reAngle != 0.0f ? (WWMath::Atan2_Origin(victimPos->y - sourcePos->y, victimPos->x - sourcePos->x)) : 0.0f; VeterancyLevel v = sourceObj->getVeterancyLevel(); const FXList* fx = isProjectileDetonation ? getProjectileDetonateFX(v) : getFireFX(v); @@ -1920,11 +1920,11 @@ Bool Weapon::computeApproachTarget(const Object *source, const Object *target, c if (source->isAboveTerrain()) { // Don't do a 180 degree turn. - Real angle = WWMath::Atan2Origin(-dir.y, -dir.x); + Real angle = WWMath::Atan2_Origin(-dir.y, -dir.x); Real relAngle = source->getOrientation()- angle; if (relAngle>2*PI) relAngle -= 2*PI; if (relAngle<-2*PI) relAngle += 2*PI; - if (WWMath::FAbsOrigin(relAngle)getPosition(); const Real ACCEPTABLE_DZ = 10.0f; - if (WWMath::FAbsOrigin(dst->z - src->z) < ACCEPTABLE_DZ) + if (WWMath::FAbs_Origin(dst->z - src->z) < ACCEPTABLE_DZ) return true; // always good enough if dz is small, regardless of pitch Real minPitch, maxPitch; diff --git a/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp index c52d014f622..8e0e22a50e9 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp @@ -808,7 +808,7 @@ static void populateRandomStartPosition( GameInfo *game ) { Coord3D p1 = c1->second; Coord3D p2 = c2->second; - startSpotDistance[i][j] = WWMath::SqrtOrigin( sqr(p1.x-p2.x) + sqr(p1.y-p2.y) ); + startSpotDistance[i][j] = WWMath::Sqrt_Origin( sqr(p1.x-p2.x) + sqr(p1.y-p2.y) ); } } else diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp index d47a41250fd..89e1adab198 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp @@ -2433,7 +2433,7 @@ void Player::doBountyForKill(const Object* killer, const Object* victim) Int bounty = REAL_TO_INT_CEIL(costToBuild * m_cashBountyPercent); #else // TheSuperHackers @bugfix Stubbjax 20/02/2026 Subtract epsilon to ensure bounty is rounded up correctly. - Int bounty = WWMath::CeilOrigin((costToBuild * m_cashBountyPercent) - WWMATH_EPSILON); + Int bounty = WWMath::Ceil_Origin((costToBuild * m_cashBountyPercent) - WWMATH_EPSILON); #endif if( bounty ) diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp index f3c8de32339..99f3b986589 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp @@ -1435,7 +1435,7 @@ Bool BuildAssistant::moveObjectsForConstruction( const ThingTemplate *whatToBuil Bool anyUnmovables = false; MemoryPoolObjectHolder hold( iter ); - Real radius = WWMath::SqrtOrigin(WWMath::PowOrigin(gi.getMajorRadius(), 2) + WWMath::PowOrigin(gi.getMinorRadius(), 2)); + Real radius = WWMath::Sqrt_Origin(WWMath::Pow_Origin(gi.getMajorRadius(), 2) + WWMath::Pow_Origin(gi.getMinorRadius(), 2)); 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 9f2e61f71af..df62ccb6f51 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/Geometry.cpp +++ b/GeneralsMD/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 = WWMath::SqrtOrigin(sqr(thatPos.x - thisCenter.x) + sqr(thatPos.y - thisCenter.y)); + Real dxy = WWMath::Sqrt_Origin(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 = WWMath::Atan2Origin(dz, dxy); + maxPitch = WWMath::Atan2_Origin(dz, dxy); dz = (thatPos.z - that.getMaxHeightBelowPosition()) - thisCenter.z; - minPitch = WWMath::Atan2Origin(dz, dxy); + minPitch = WWMath::Atan2_Origin(dz, dxy); } //============================================================================= @@ -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 = WWMath::SqrtOrigin(sqr(dx) + sqr(dy)); + Real radius = WWMath::Sqrt_Origin(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 = WWMath::SqrtOrigin(sqr(dx) + sqr(dy)); + Real radius = WWMath::Sqrt_Origin(sqr(dx) + sqr(dy)); return (radius <= m_majorRadius); break; } @@ -506,8 +506,8 @@ void GeometryInfo::calcBoundingStuff() case GEOMETRY_BOX: { - m_boundingCircleRadius = WWMath::SqrtOrigin(sqr(m_majorRadius) + sqr(m_minorRadius)); - m_boundingSphereRadius = WWMath::SqrtOrigin(sqr(m_majorRadius) + sqr(m_minorRadius) + sqr(m_height*0.5)); + m_boundingCircleRadius = WWMath::Sqrt_Origin(sqr(m_majorRadius) + sqr(m_minorRadius)); + m_boundingSphereRadius = WWMath::Sqrt_Origin(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 c63dc2f9429..b805da8dd2f 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp @@ -51,32 +51,32 @@ Real Sin(Real x) { - return WWMath::SinTrig(x); + return WWMath::Sin_Trig(x); } Real Cos(Real x) { - return WWMath::CosTrig(x); + return WWMath::Cos_Trig(x); } Real Tan(Real x) { - return WWMath::TanTrig(x); + return WWMath::Tan_Trig(x); } Real ACos(Real x) { - return WWMath::ACosTrig(x); + return WWMath::ACos_Trig(x); } Real ASin(Real x) { - return WWMath::ASinTrig(x); + return WWMath::ASin_Trig(x); } double Sqrt(double x) { - return WWMath::SqrtOrigin(x); + return WWMath::Sqrt_Origin(x); } #ifdef REGENERATE_TRIG_TABLES diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp index 3d7c46c1ce0..e1ac594164c 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 = WWMath::SqrtOrigin(distSqr); + Real dist = WWMath::Sqrt_Origin(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 93fb03b1e72..880764ac8c8 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp @@ -489,7 +489,7 @@ Object *AIPlayer::buildStructureNow(const ThingTemplate *bldgPlan, BuildListInfo { Coord3D rallyPoint; Bool gotOffset = false; - if (WWMath::FAbsOrigin(info->getRallyOffset()->x) > 1.0f || WWMath::FAbsOrigin(info->getRallyOffset()->y)>1.0f) { + if (WWMath::FAbs_Origin(info->getRallyOffset()->x) > 1.0f || WWMath::FAbs_Origin(info->getRallyOffset()->y)>1.0f) { gotOffset; } if (!exitInterface->getNaturalRallyPoint(rallyPoint)) { @@ -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 = WWMath::SqrtOrigin(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); + Int count = WWMath::Sqrt_Origin(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); if (count<2) count = 2; Int i; color.green = 1; @@ -669,7 +669,7 @@ Object *AIPlayer::buildStructureWithDozer(const ThingTemplate *bldgPlan, BuildLi { Coord3D rallyPoint; Bool gotOffset = false; - if (WWMath::FAbsOrigin(info->getRallyOffset()->x) > 1.0f || WWMath::FAbsOrigin(info->getRallyOffset()->y)>1.0f) { + if (WWMath::FAbs_Origin(info->getRallyOffset()->x) > 1.0f || WWMath::FAbs_Origin(info->getRallyOffset()->y)>1.0f) { gotOffset; } if (!exitInterface->getNaturalRallyPoint(rallyPoint)) { @@ -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)) @@ -3139,7 +3139,7 @@ void AIPlayer::computeCenterAndRadiusOfBase(Coord3D *center, Real *radius) Real radSqr = dx*dx+dy*dy; if (radSqr>maxRadSqr) maxRadSqr=radSqr; } - *radius = WWMath::SqrtOrigin(maxRadSqr); + *radius = WWMath::Sqrt_Origin(maxRadSqr); } //---------------------------------------------------------------------------------------------------------- diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp index 46471922c06..4218ddd220b 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp @@ -527,7 +527,7 @@ StateReturnType AIRappelState::onEnter() obj->setLayer(layerAtDest); AIUpdateInterface *ai = obj->getAI(); - Real MAX_RAPPEL_RATE = WWMath::FAbsOrigin(TheGlobalData->m_gravity) * LOGICFRAMES_PER_SECOND * 2.5f; + Real MAX_RAPPEL_RATE = WWMath::FAbs_Origin(TheGlobalData->m_gravity) * LOGICFRAMES_PER_SECOND * 2.5f; m_rappelRate = -min(ai->getDesiredSpeed(), MAX_RAPPEL_RATE); return STATE_CONTINUE; @@ -3674,7 +3674,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.", WWMath::SqrtOrigin(distSqr))); + DEBUG_LOG(("AIAttackMoveToState::update Distance from goal %f, retrying.", WWMath::Sqrt_Origin(distSqr))); ret = STATE_CONTINUE; m_retryCount--; @@ -3904,7 +3904,7 @@ void AIFollowWaypointPathState::computeGoal(Bool useGroupOffsets) if (m_priorWaypoint) { dx = dest.x - m_priorWaypoint->getLocation()->x; dy = dest.y - m_priorWaypoint->getLocation()->y; - angle = WWMath::Atan2Origin(dy, dx); + angle = WWMath::Atan2_Origin(dy, dx); Real deltaAngle = angle - m_angle; Real s = sin(deltaAngle); Real c = cos(deltaAngle); @@ -3913,7 +3913,7 @@ void AIFollowWaypointPathState::computeGoal(Bool useGroupOffsets) m_groupOffset.x = x; m_groupOffset.y = y; } else { - angle = WWMath::Atan2Origin(dy, dx); + angle = WWMath::Atan2_Origin(dy, dx); } m_angle = angle; #endif @@ -5078,7 +5078,7 @@ StateReturnType AIAttackAimAtTargetState::update() //DEBUG_LOG(("AIM: desired %f, actual %f, delta %f, aimDelta %f, goalpos %f %f",rad2deg(obj->getOrientation() + relAngle),rad2deg(obj->getOrientation()),rad2deg(relAngle),rad2deg(aimDelta),victim->getPosition()->x,victim->getPosition()->y)); if (m_canTurnInPlace) { - if (WWMath::FAbsOrigin(relAngle) > aimDelta) + if (WWMath::FAbs_Origin(relAngle) > aimDelta) { Real desiredAngle = source->getOrientation() + relAngle; sourceAI->setLocomotorGoalOrientation(desiredAngle); @@ -5090,7 +5090,7 @@ StateReturnType AIAttackAimAtTargetState::update() sourceAI->setLocomotorGoalPositionExplicit(m_isAttackingObject ? *victim->getPosition() : *getMachineGoalPosition()); } - if (WWMath::FAbsOrigin(relAngle) < aimDelta /*&& !m_preAttackFrames*/ ) + if (WWMath::FAbs_Origin(relAngle) < aimDelta /*&& !m_preAttackFrames*/ ) { AIUpdateInterface* victimAI = victim ? victim->getAI() : nullptr; // add ourself as a targeter BEFORE calling isTemporarilyPreventingAimSuccess(). @@ -7484,7 +7484,7 @@ StateReturnType AIFaceState::update() Real relAngle = ThePartitionManager->getRelativeAngle2D( obj, pos ); const Real REL_THRESH = 0.035f; // about 2 degrees. (getRelativeAngle2D is current only accurate to about 1.25 degrees) - if( WWMath::FAbsOrigin( relAngle ) < REL_THRESH ) + if( WWMath::FAbs_Origin( relAngle ) < REL_THRESH ) { return STATE_SUCCESS; } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp index 09bf72c68bf..118f89f28ba 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp @@ -386,7 +386,7 @@ Bool TurretAI::friend_turnTowardsAngle(Real desiredAngle, Real rateModifier, Rea Real angleDiff = normalizeAngle(desiredAngle - actualAngle); // Are we close enough to the desired angle to just snap there? - if (WWMath::FAbsOrigin(angleDiff) < turnRate) + if (WWMath::FAbs_Origin(angleDiff) < turnRate) { // we are centered actualAngle = desiredAngle; @@ -409,7 +409,7 @@ Bool TurretAI::friend_turnTowardsAngle(Real desiredAngle, Real rateModifier, Rea if( m_angle != origAngle ) getOwner()->reactToTurretChange( m_whichTurret, origAngle, m_pitch ); - Bool aligned = WWMath::FAbsOrigin(m_angle - desiredAngle) <= relThresh; + Bool aligned = WWMath::FAbs_Origin(m_angle - desiredAngle) <= relThresh; return aligned; } @@ -427,7 +427,7 @@ Bool TurretAI::friend_turnTowardsPitch(Real desiredPitch, Real rateModifier) Real pitchRate = getPitchRate() * rateModifier; Real pitchDiff = normalizeAngle(desiredPitch - actualPitch); - if (WWMath::FAbsOrigin(pitchDiff) < pitchRate) + if (WWMath::FAbs_Origin(pitchDiff) < pitchRate) { // we are centered actualPitch = desiredPitch; @@ -1087,7 +1087,7 @@ StateReturnType TurretAIAimTurretState::update() turret->friend_setPositiveSweep(!turret->friend_getPositiveSweep()); Real angleDiff = normalizeAngle(relAngle - turret->getTurretAngle()); - turnAlignedToNemesis = (WWMath::FAbsOrigin(angleDiff) < sweep); + turnAlignedToNemesis = (WWMath::FAbs_Origin(angleDiff) < sweep); } Bool pitchAlignedToNemesis = true; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp index 5a1c6f524ae..5f54e730239 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 = WWMath::SqrtOrigin(halfHeight*halfHeight + halfWidth*halfWidth); + m_radius = WWMath::Sqrt_Origin(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 bb894275466..c8b7ae7d799 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 WWMath::Atan2Origin(xvec.y, xvec.x) == angle. So we must construct + that WWMath::Atan2_Origin(xvec.y, xvec.x) == angle. So we must construct the matrix carefully to ensure this! */ x.x = Cos( angle ); @@ -1489,7 +1489,7 @@ void makeAlignToNormalMatrix( Real angle, const Coord3D& pos, const Coord3D& nor x.normalize(); } - DEBUG_ASSERTCRASH(WWMath::FAbsOrigin(x.x*z.x + x.y*z.y + x.z*z.z)<0.0001,("dot is not zero (%f)",WWMath::FAbsOrigin(x.x*z.x + x.y*z.y + x.z*z.z))); + DEBUG_ASSERTCRASH(WWMath::FAbs_Origin(x.x*z.x + x.y*z.y + x.z*z.z)<0.0001,("dot is not zero (%f)",WWMath::FAbs_Origin(x.x*z.x + x.y*z.y + x.z*z.z))); // now computing the y vector is trivial. y.crossProduct( &z, &x, &y ); @@ -1685,12 +1685,12 @@ PathfindLayerEnum TerrainLogic::getLayerForDestination(const Coord3D *pos) { Bridge *pBridge = getFirstBridge(); PathfindLayerEnum bestLayer = LAYER_GROUND; - Real bestDistance = WWMath::FAbsOrigin(pos->z - getGroundHeight(pos->x, pos->y)); + Real bestDistance = WWMath::FAbs_Origin(pos->z - getGroundHeight(pos->x, pos->y)); if (bestDistance > TheAI->pathfinder()->getWallHeight()/2) { // check wall. if (TheAI->pathfinder()->isPointOnWall(pos)) { - Real delta = WWMath::FAbsOrigin(pos->z-TheAI->pathfinder()->getWallHeight()); + Real delta = WWMath::FAbs_Origin(pos->z-TheAI->pathfinder()->getWallHeight()); if (deltaisPointOnBridge(pos) ) { - Real delta = WWMath::FAbsOrigin(pos->z-pBridge->getBridgeHeight(pos, nullptr)); + Real delta = WWMath::FAbs_Origin(pos->z-pBridge->getBridgeHeight(pos, nullptr)); if (deltagetLayer(); bestDistance = delta; @@ -1724,7 +1724,7 @@ PathfindLayerEnum TerrainLogic::getHighestLayerForDestination(const Coord3D *pos if (TheAI->pathfinder()->isPointOnWall(pos)) { Real delta = pos->z - TheAI->pathfinder()->getWallHeight(); // must be ABOVE (or on) the wall for this call. (srj) - if (delta >= 0 && WWMath::FAbsOrigin(delta) < WWMath::FAbsOrigin(bestDistance)) { + if (delta >= 0 && WWMath::FAbs_Origin(delta) < WWMath::FAbs_Origin(bestDistance)) { bestLayer = (PathfindLayerEnum)LAYER_WALL; bestDistance = delta; } @@ -1739,7 +1739,7 @@ PathfindLayerEnum TerrainLogic::getHighestLayerForDestination(const Coord3D *pos if (pBridge->isPointOnBridge(pos) ) { Real delta = pos->z - pBridge->getBridgeHeight(pos, nullptr); // must be ABOVE (or on) the bridge for this call. (srj) - if (delta >= 0 && WWMath::FAbsOrigin(delta) < WWMath::FAbsOrigin(bestDistance)) { + if (delta >= 0 && WWMath::FAbs_Origin(delta) < WWMath::FAbs_Origin(bestDistance)) { bestLayer = pBridge->getLayer(); bestDistance = delta; } @@ -1788,7 +1788,7 @@ Bool TerrainLogic::objectInteractsWithBridgeLayer(Object *obj, Int layer, Bool c if (match) { Real bridgeHeight = pBridge->getBridgeHeight(obj->getPosition(), nullptr); - Real delta = WWMath::FAbsOrigin(obj->getPosition()->z-bridgeHeight); + Real delta = WWMath::FAbs_Origin(obj->getPosition()->z-bridgeHeight); if (delta>LAYER_Z_CLOSE_ENOUGH_F) { return false; } @@ -1837,7 +1837,7 @@ Bool TerrainLogic::objectInteractsWithBridgeEnd(Object *obj, Int layer) const if (match) { Real bridgeHeight = pBridge->getBridgeHeight(obj->getPosition(), nullptr); - Real delta = WWMath::FAbsOrigin(obj->getPosition()->z-bridgeHeight); + Real delta = WWMath::FAbs_Origin(obj->getPosition()->z-bridgeHeight); if (delta>LAYER_Z_CLOSE_ENOUGH_F) { return false; @@ -2055,10 +2055,10 @@ Coord3D TerrainLogic::findClosestEdgePoint ( const Coord3D *closestTo ) const getExtent( &mapExtent ); Real distances[4]; - distances[0] = WWMath::FAbsOrigin( closestTo->y - mapExtent.lo.y );//top - distances[1] = WWMath::FAbsOrigin( closestTo->x - mapExtent.hi.x );//right - distances[2] = WWMath::FAbsOrigin( closestTo->y - mapExtent.hi.y );//bottom - distances[3] = WWMath::FAbsOrigin( closestTo->x - mapExtent.lo.x );//left + distances[0] = WWMath::FAbs_Origin( closestTo->y - mapExtent.lo.y );//top + distances[1] = WWMath::FAbs_Origin( closestTo->x - mapExtent.hi.x );//right + distances[2] = WWMath::FAbs_Origin( closestTo->y - mapExtent.hi.y );//bottom + distances[3] = WWMath::FAbs_Origin( closestTo->x - mapExtent.lo.x );//left Real bestDistance = distances[0]; Int bestDistanceIndex = 0; for( Int lameIndex = 1; lameIndex < 4; lameIndex++ ) @@ -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 = WWMath::SqrtOrigin( affectedRegion.width() * affectedRegion.width() + + Real maxDist = WWMath::Sqrt_Origin( 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 = WWMath::SqrtOrigin( sqr( deltaX ) + sqr( deltaY ) ); + Real distance = WWMath::Sqrt_Origin( 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 b17fcc0ac38..bdc690c7c2f 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp @@ -172,24 +172,24 @@ static Bool calcTrajectory( Real dz = end.z - start.z; // calculating the angle is trivial. - angle = WWMath::Atan2Origin(dy, dx); + angle = WWMath::Atan2_Origin(dy, dx); // calculating the pitch requires a bit more effort. Real horizDistSqr = sqr(dx) + sqr(dy); - Real horizDist = WWMath::SqrtOrigin(horizDistSqr); + Real horizDist = WWMath::Sqrt_Origin(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) - Real gravity = WWMath::FAbsOrigin(TheGlobalData->m_gravity); + Real gravity = WWMath::FAbs_Origin(TheGlobalData->m_gravity); Real gravityTwoDZ = gravity * 2.0f * dz; // 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 = WWMath::Atan2Origin(dz, horizDist); + Real theta = WWMath::Atan2_Origin(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; - if (WWMath::FAbsOrigin(theta) > SHALLOW_ANGLE) + if (WWMath::FAbs_Origin(theta) > SHALLOW_ANGLE) { Real t = horizDist / velocity; Real vz = (dz/t + 0.5f*gravity*t); @@ -290,7 +290,7 @@ static Bool calcTrajectory( #endif vx = velocity*cosPitches[preferred]; - Real actualRange = (vx*(vz + WWMath::SqrtOrigin(root)))/gravity; + Real actualRange = (vx*(vz + WWMath::Sqrt_Origin(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 = WWMath::SqrtOrigin(ThePartitionManager->getDistanceSquared( projectile, &victimPosToUse, FROM_CENTER_2D ) ); + Real range = WWMath::Sqrt_Origin(ThePartitionManager->getDistanceSquared( projectile, &victimPosToUse, FROM_CENTER_2D ) ); Real rangeRatio = (range - minRange) / (maxRange - minRange); m_flightPathSpeed = (rangeRatio * (weaponSpeed - minWeaponSpeed)) + minWeaponSpeed; } @@ -444,7 +444,7 @@ Bool DumbProjectileBehavior::calcFlightPath(Bool recalcNumSegments) if (recalcNumSegments) { Real flightDistance = flightCurve.getApproximateLength(); - m_flightPathSegments = WWMath::CeilOrigin( flightDistance / m_flightPathSpeed ); + m_flightPathSegments = WWMath::Ceil_Origin( flightDistance / m_flightPathSpeed ); } // TheSuperHackers @info The way flight paths are used requires at least two curve points. @@ -611,7 +611,7 @@ UpdateSleepTime DumbProjectileBehavior::update() Real distVictimMovedSqr = sqr(delta.x) + sqr(delta.y) + sqr(delta.z); if (distVictimMovedSqr > 0.1f) { - Real distVictimMoved = WWMath::SqrtfOrigin(distVictimMovedSqr); + Real distVictimMoved = WWMath::Sqrtf_Origin(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 1f89505fc1f..44fb2522a9f 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 = WWMath::SqrtOrigin(sqr(dx) + sqr(dy)); + Real len = WWMath::Sqrt_Origin(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 ec7c314fc70..079e312397e 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(WWMath::SqrtfOrigin(2.0f * (start.z - endOnGround.z) / WWMath::FAbsOrigin(TheGlobalData->m_gravity))); + UnsignedInt fallingTime = REAL_TO_INT_CEIL(WWMath::Sqrtf_Origin(2.0f * (start.z - endOnGround.z) / WWMath::FAbs_Origin(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,8 +588,8 @@ 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 = WWMath::SqrtOrigin(sqr(dx) + sqr(dy)); - if (dist <= 0.1f && WWMath::FAbsOrigin(dz) <= 0.1f) + Real dist = WWMath::Sqrt_Origin(sqr(dx) + sqr(dy)); + if (dist <= 0.1f && WWMath::FAbs_Origin(dz) <= 0.1f) { obj->setPosition(&endOnGround); m_scootFramesLeft = 0; @@ -598,7 +598,7 @@ void MinefieldBehavior::setScootParms(const Coord3D& start, const Coord3D& end) { Real t = (Real)scootFromStartingPointTime; Real scootFromStartingPointSpeed = dist / t; - Real accelMag = WWMath::FAbsOrigin(2.0f * (dist - scootFromStartingPointSpeed*t)/sqr(t)); + Real accelMag = WWMath::FAbs_Origin(2.0f * (dist - scootFromStartingPointSpeed*t)/sqr(t)); Real dxNorm = (dist <= 0.1f) ? 0.0f : (dx / dist); Real dyNorm = (dist <= 0.1f) ? 0.0f : (dy / dist); m_scootVel.x = dxNorm * scootFromStartingPointSpeed; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp index 92dcfe36bbd..cbbc659f6d3 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 = WWMath::Atan2Origin(force.y, force.x); + Real orientation = WWMath::Atan2_Origin(force.y, force.x); physics->setAngles(orientation, 0, 0); obj->getDrawable()->setModelConditionState(MODELCONDITION_EXPLODED_FLAILING); m_flags |= (1<getPosition()->z) >= d->m_paraOpenDist) + if (WWMath::FAbs_Origin(m_startZ - parachute->getPosition()->z) >= d->m_paraOpenDist) { m_opened = true; parachute->clearAndSetModelConditionState(MODELCONDITION_FREEFALL, MODELCONDITION_PARACHUTING); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp index e942f2ed44d..b681c2f7921 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp @@ -84,7 +84,7 @@ static Real calcSlowDownDist(Real curSpeed, Real desiredSpeed, Real maxBraking) if (delta <= 0) return 0.0f; - Real dist = (sqr(delta) / WWMath::FAbsOrigin(maxBraking)) * 0.5f; + Real dist = (sqr(delta) / WWMath::FAbs_Origin(maxBraking)) * 0.5f; // use a little fudge so that things can stop "on a dime" more easily... const Real FUDGE = 1.05f; @@ -95,14 +95,14 @@ static Real calcSlowDownDist(Real curSpeed, Real desiredSpeed, Real maxBraking) inline Bool isNearlyZero(Real a) { const Real TINY_EPSILON = 0.001f; - return WWMath::FAbsOrigin(a) < TINY_EPSILON; + return WWMath::FAbs_Origin(a) < TINY_EPSILON; } //----------------------------------------------------------------------------- inline Bool isNearly(Real a, Real val) { const Real TINY_EPSILON = 0.001f; - return WWMath::FAbsOrigin(a - val) < TINY_EPSILON; + return WWMath::FAbs_Origin(a - val) < TINY_EPSILON; } //----------------------------------------------------------------------------- @@ -141,7 +141,7 @@ static Real tryToRotateVector3D( } } - if (WWMath::FAbsOrigin(angleBetween) <= maxAngle) + if (WWMath::FAbs_Origin(angleBetween) <= maxAngle) { // close enough actualDir = goalDir; @@ -231,9 +231,9 @@ static void calcDirectionToApplyThrust( Bool foundSolution = false; Real distToGoalSqr = vecToGoal.Length2(); - Real distToGoal = WWMath::SqrtOrigin(distToGoalSqr); + Real distToGoal = WWMath::Sqrt_Origin(distToGoalSqr); Real curVelMagSqr = curVel.Length2(); - Real curVelMag = WWMath::SqrtOrigin(curVelMagSqr); + Real curVelMag = WWMath::Sqrt_Origin(curVelMagSqr); Real maxAccelSqr = sqr(maxAccel); Real denom = curVelMagSqr - maxAccelSqr; @@ -995,7 +995,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 = WWMath::SqrtOrigin(dx*dx+dy*dy); + Real dist = WWMath::Sqrt_Origin(dx*dx+dy*dy); if (dist>onPathDistToGoal) { if (!obj->isKindOf(KINDOF_PROJECTILE) && dist>2*onPathDistToGoal) @@ -1113,7 +1113,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 = WWMath::SqrtOrigin(dx*dx+dy*dy+dz*dz); + dist = WWMath::Sqrt_Origin(dx*dx+dy*dy+dz*dz); Real vel = physics->getVelocityMagnitude(); if (vel < MIN_VEL) vel = MIN_VEL; @@ -1137,7 +1137,7 @@ void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalP // Normalize. if (dist > 0.001f) { - Real vel = WWMath::FAbsOrigin(physics->getForwardSpeed2D()); + Real vel = WWMath::FAbs_Origin(physics->getForwardSpeed2D()); if (vel < MIN_VEL) vel = MIN_VEL; if (vel > dist) @@ -1182,7 +1182,7 @@ void Locomotor::moveTowardsPositionTreads(Object* obj, PhysicsBehavior *physics, // Modulate speed according to turning. The more we have to turn, the slower we go // const Real QUAETERPI = PI / 4.0f; - Real angleCoeff = (Real)WWMath::FAbsOrigin( relAngle ) / QUAETERPI; + Real angleCoeff = (Real)WWMath::FAbs_Origin( relAngle ) / QUAETERPI; if (angleCoeff > 1.0f) angleCoeff = 1.0; @@ -1253,7 +1253,7 @@ void Locomotor::moveTowardsPositionTreads(Object* obj, PhysicsBehavior *physics, see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (WWMath::FAbsOrigin(accelForce) > WWMath::FAbsOrigin(maxForceNeeded)) + if (WWMath::FAbs_Origin(accelForce) > WWMath::FAbs_Origin(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); @@ -1288,7 +1288,7 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, Real angle = obj->getOrientation(); // Real relAngle = ThePartitionManager->getRelativeAngle2D( obj, &goalPos ); // Real desiredAngle = angle + relAngle; - Real desiredAngle = WWMath::Atan2Origin(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2_Origin(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real relAngle = stdAngleDiff(desiredAngle, angle); Bool moveBackwards = false; @@ -1305,14 +1305,14 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, #if 1 if (actualSpeed==0.0f) { setFlag(MOVING_BACKWARDS, false); - if (m_template->m_canMoveBackward && WWMath::FAbsOrigin(relAngle) > PI/2) { + if (m_template->m_canMoveBackward && WWMath::FAbs_Origin(relAngle) > PI/2) { setFlag(MOVING_BACKWARDS, true ); setFlag(DOING_THREE_POINT_TURN, onPathDistToGoal>5*obj->getGeometryInfo().getMajorRadius()); } } if (getFlag(MOVING_BACKWARDS)) { - if (WWMath::FAbsOrigin(relAngle) < PI/2) { + if (WWMath::FAbs_Origin(relAngle) < PI/2) { moveBackwards = false; setFlag(MOVING_BACKWARDS, false); } else { @@ -1328,7 +1328,7 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, #endif const Real SMALL_TURN = PI / 20.0f; - if ((Real)WWMath::FAbsOrigin( relAngle ) > SMALL_TURN) + if ((Real)WWMath::FAbs_Origin( relAngle ) > SMALL_TURN) { if (desiredSpeed>turnSpeed) { @@ -1353,7 +1353,7 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, const Real FIFTEEN_DEGREES = PI / 12.0f; const Real PROJECT_FRAMES = LOGICFRAMES_PER_SECOND/2; // Project out 1/2 second. - if (WWMath::FAbsOrigin( relAngle ) > FIFTEEN_DEGREES) + if (WWMath::FAbs_Origin( relAngle ) > FIFTEEN_DEGREES) { // If we're turning more than 10 degrees, check & see if we're moving into "impassable territory" Real distance = PROJECT_FRAMES * (goalSpeed+actualSpeed)/2.0f; @@ -1492,7 +1492,7 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (WWMath::FAbsOrigin(accelForce) > WWMath::FAbsOrigin(maxForceNeeded)) + if (WWMath::FAbs_Origin(accelForce) > WWMath::FAbs_Origin(maxForceNeeded)) accelForce = maxForceNeeded; //DEBUG_LOG(("Braking %d, actualSpeed %f, goalSpeed %f, delta %f, accel %f", getFlag(IS_BRAKING), @@ -1563,7 +1563,7 @@ Bool Locomotor::fixInvalidPosition(Object* obj, PhysicsBehavior *physics) //physics->clearAcceleration(); if (dot<0) { - dot = WWMath::SqrtOrigin(-dot); + dot = WWMath::Sqrt_Origin(-dot); correctionNormalized.x *= dot*physics->getMass(); correctionNormalized.y *= dot*physics->getMass(); physics->applyMotiveForce(&correctionNormalized); @@ -1627,7 +1627,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 = WWMath::Atan2Origin(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2_Origin(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; @@ -1653,7 +1653,7 @@ void Locomotor::moveTowardsPositionLegs(Object* obj, PhysicsBehavior *physics, c // Modulate speed according to turning. The more we have to turn, the slower we go // const Real QUARTERPI = PI / 4.0f; - Real angleCoeff = (Real)WWMath::FAbsOrigin( relAngle ) / (QUARTERPI); + Real angleCoeff = (Real)WWMath::FAbs_Origin( relAngle ) / (QUARTERPI); if (angleCoeff > 1.0f) angleCoeff = 1.0; @@ -1683,7 +1683,7 @@ void Locomotor::moveTowardsPositionLegs(Object* obj, PhysicsBehavior *physics, c see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (WWMath::FAbsOrigin(accelForce) > WWMath::FAbsOrigin(maxForceNeeded)) + if (WWMath::FAbs_Origin(accelForce) > WWMath::FAbs_Origin(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); @@ -1725,7 +1725,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, if (dz*dz > sqr(PATHFIND_CELL_SIZE_F)) { setFlag(CLIMBING, true); } - if (WWMath::FAbsOrigin(dz)<1) { + if (WWMath::FAbs_Origin(dz)<1) { setFlag(CLIMBING, false); } @@ -1745,7 +1745,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, moveBackwards = true; } - Real groundSlope = WWMath::FAbsOrigin(delta.z - pos.z); + Real groundSlope = WWMath::FAbs_Origin(delta.z - pos.z); if (groundSlope<1.0f) groundSlope = 1.0f; if (groundSlope>1.0f) { @@ -1760,7 +1760,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, Real angle = obj->getOrientation(); // Real relAngle = ThePartitionManager->getRelativeAngle2D( obj, &goalPos ); // Real desiredAngle = angle + relAngle; - Real desiredAngle = WWMath::Atan2Origin(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2_Origin(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real relAngle = stdAngleDiff(desiredAngle, angle); if (moveBackwards) { @@ -1774,7 +1774,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, // Modulate speed according to turning. The more we have to turn, the slower we go // const Real QUARTERPI = PI / 4.0f; - Real angleCoeff = (Real)WWMath::FAbsOrigin( relAngle ) / (QUARTERPI); + Real angleCoeff = (Real)WWMath::FAbs_Origin( relAngle ) / (QUARTERPI); if (angleCoeff > 1.0f) angleCoeff = 1.0; @@ -1816,7 +1816,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (WWMath::FAbsOrigin(accelForce) > WWMath::FAbsOrigin(maxForceNeeded)) + if (WWMath::FAbs_Origin(accelForce) > WWMath::FAbs_Origin(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); @@ -1843,7 +1843,7 @@ void Locomotor::moveTowardsPositionWings(Object* obj, PhysicsBehavior *physics, Real dx = goalPos.x - pos->x; Real dy = goalPos.y - pos->y; Real dz = goalPos.z - pos->z; - if (WWMath::FAbsOrigin(dz) > m_circleThresh) + if (WWMath::FAbs_Origin(dz) > m_circleThresh) { // aim for the spot on the opposite side of the circle. @@ -1851,7 +1851,7 @@ void Locomotor::moveTowardsPositionWings(Object* obj, PhysicsBehavior *physics, Real angleTowardPos = (isNearlyZero(dx) && isNearlyZero(dy)) ? obj->getOrientation() : - WWMath::Atan2Origin(dy, dx); + WWMath::Atan2_Origin(dy, dx); Real aimDir = (PI - PI/8); angleTowardPos += aimDir; @@ -1940,7 +1940,7 @@ void Locomotor::moveTowardsPositionThrust(Object* obj, PhysicsBehavior *physics, // so we tend to "level out" at that height. we don't use this till // below, but go ahead and calc it now... Real MAX_VERTICAL_DAMP_RANGE = m_preferredHeight * 0.5; - delta = WWMath::FAbsOrigin(delta); + delta = WWMath::FAbs_Origin(delta); if (delta > MAX_VERTICAL_DAMP_RANGE) delta = MAX_VERTICAL_DAMP_RANGE; zDirDamping = 1.0f - (delta / MAX_VERTICAL_DAMP_RANGE); @@ -2057,7 +2057,7 @@ Real Locomotor::calcLiftToUseAtPt(Object* obj, PhysicsBehavior *physics, Real cu // see how far we need to slow to dead stop, given max braking Real desiredAccel; const Real TINY_ACCEL = 0.001f; - if (WWMath::FAbsOrigin(maxAccel) > TINY_ACCEL) + if (WWMath::FAbs_Origin(maxAccel) > TINY_ACCEL) { Real deltaZ = preferredHeight - curZ; // calc how far it will take for us to go from cur speed to zero speed, at max accel. @@ -2065,14 +2065,14 @@ Real Locomotor::calcLiftToUseAtPt(Object* obj, PhysicsBehavior *physics, Real cu // in theory, the above is the correct calculation, but in practice, // doesn't work in some situations (eg, opening of USA01 map). Why, I dunno. // But for now I have gone back to the old, looks-incorrect-to-me-but-works calc. (srj) - Real brakeDist = (sqr(curVelZ) / WWMath::FAbsOrigin(maxAccel)); - if (WWMath::FAbsOrigin(brakeDist) > WWMath::FAbsOrigin(deltaZ)) + Real brakeDist = (sqr(curVelZ) / WWMath::FAbs_Origin(maxAccel)); + if (WWMath::FAbs_Origin(brakeDist) > WWMath::FAbs_Origin(deltaZ)) { // if the dist-to-accel (or dist-to-brake) is further than the dist-to-go, // use the max accel. desiredAccel = maxAccel; } - else if (WWMath::FAbsOrigin(curVelZ) > m_template->m_speedLimitZ) + else if (WWMath::FAbs_Origin(curVelZ) > m_template->m_speedLimitZ) { // or, if we're going too fast, limit it here. desiredAccel = m_template->m_speedLimitZ - curVelZ; @@ -2146,8 +2146,8 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 Real dx =goalPos.x - turnPos.x; 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 (WWMath::FAbsOrigin(dx)<0.1f && WWMath::FAbsOrigin(dy)<0.1f) return TURN_NONE; - Real desiredAngle = WWMath::Atan2Origin(dy, dx); + if (WWMath::FAbs_Origin(dx)<0.1f && WWMath::FAbs_Origin(dy)<0.1f) return TURN_NONE; + Real desiredAngle = WWMath::Atan2_Origin(dy, dx); Real amount = stdAngleDiff(desiredAngle, angle); if (relAngle) *relAngle = amount; if (amount>maxTurnRate) { @@ -2169,7 +2169,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 = WWMath::Atan2Origin(desiredPos.y - turnPos.y, desiredPos.x - turnPos.x); + Real angleDesiredForTurnPos = WWMath::Atan2_Origin(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 +2185,7 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 } else { - Real desiredAngle = WWMath::Atan2Origin(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2_Origin(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real amount = stdAngleDiff(desiredAngle, angle); if (relAngle) *relAngle = amount; if (amount>maxTurnRate) { @@ -2363,8 +2363,8 @@ void Locomotor::moveTowardsPositionOther(Object* obj, PhysicsBehavior *physics, //fabs(goalPos.y - pos->y),fabs(goalPos.x - pos->x), //fabs(goalPos.y - pos->y)/goalSpeed,fabs(goalPos.x - pos->x)/goalSpeed)); if (getFlag(ULTRA_ACCURATE) && - WWMath::FAbsOrigin(goalPos.y - pos->y) <= goalSpeed * m_template->m_ultraAccurateSlideIntoPlaceFactor && - WWMath::FAbsOrigin(goalPos.x - pos->x) <= goalSpeed * m_template->m_ultraAccurateSlideIntoPlaceFactor) + WWMath::FAbs_Origin(goalPos.y - pos->y) <= goalSpeed * m_template->m_ultraAccurateSlideIntoPlaceFactor && + WWMath::FAbs_Origin(goalPos.x - pos->x) <= goalSpeed * m_template->m_ultraAccurateSlideIntoPlaceFactor) { // don't turn, just slide in the right direction physics->setTurning(TURN_NONE); @@ -2403,7 +2403,7 @@ void Locomotor::moveTowardsPositionOther(Object* obj, PhysicsBehavior *physics, see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (WWMath::FAbsOrigin(accelForce) > WWMath::FAbsOrigin(maxForceNeeded)) + if (WWMath::FAbs_Origin(accelForce) > WWMath::FAbs_Origin(maxForceNeeded)) accelForce = maxForceNeeded; Coord3D force; @@ -2519,7 +2519,7 @@ void Locomotor::maintainCurrentPositionWings(Object* obj, PhysicsBehavior *physi Real angleTowardMaintainPos = (isNearlyZero(dx) && isNearlyZero(dy)) ? obj->getOrientation() : - WWMath::Atan2Origin(dy, dx); + WWMath::Atan2_Origin(dy, dx); Real aimDir = (PI - PI/8); if (turnRadius < 0) @@ -2553,7 +2553,7 @@ void Locomotor::maintainCurrentPositionHover(Object* obj, PhysicsBehavior *physi // Real minSpeed = max( 1.0E-10f, m_template->m_minSpeed ); Real speedDelta = minSpeed - actualSpeed; - if (WWMath::FAbsOrigin(speedDelta) > minSpeed) + if (WWMath::FAbs_Origin(speedDelta) > minSpeed) { Real mass = physics->getMass(); Real acceleration = (speedDelta > 0.0f) ? maxAcceleration : -getBraking(); @@ -2564,7 +2564,7 @@ void Locomotor::maintainCurrentPositionHover(Object* obj, PhysicsBehavior *physi see how much force we really need to achieve our goal speed... */ Real maxForceNeeded = mass * speedDelta; - if (WWMath::FAbsOrigin(accelForce) > WWMath::FAbsOrigin(maxForceNeeded)) + if (WWMath::FAbs_Origin(accelForce) > WWMath::FAbs_Origin(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp index bb6d883cb27..d7c4aab0dc1 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp @@ -1754,13 +1754,13 @@ inline Bool isPosDifferent(const Coord3D* a, const Coord3D* b) // so we must put in some cleverness... const Real THRESH = 0.01f; - if (WWMath::FAbsOrigin(a->x - b->x) > THRESH) + if (WWMath::FAbs_Origin(a->x - b->x) > THRESH) return true; - if (WWMath::FAbsOrigin(a->y - b->y) > THRESH) + if (WWMath::FAbs_Origin(a->y - b->y) > THRESH) return true; - if (WWMath::FAbsOrigin(a->z - b->z) > THRESH) + if (WWMath::FAbs_Origin(a->z - b->z) > THRESH) return true; return false; @@ -1776,7 +1776,7 @@ inline Bool isAngleDifferent(Real a, Real b) const Real THRESH = 0.01f; // in radians, this is approx 1/2 degree. - if (WWMath::FAbsOrigin(a - b) > THRESH) + if (WWMath::FAbs_Origin(a - b) > THRESH) return true; return false; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp index 89bb9f39023..8783874cd1b 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 = WWMath::SqrtOrigin( dx*dx + dy*dy ); + Real length = WWMath::Sqrt_Origin( dx*dx + dy*dy ); //Normalize length dx /= length; @@ -357,7 +357,7 @@ class DeliverPayloadNugget : public ObjectCreationNugget } - Real orient = WWMath::Atan2Origin( moveToPos.y - startPos.y, moveToPos.x - startPos.x); + Real orient = WWMath::Atan2_Origin( moveToPos.y - startPos.y, moveToPos.x - startPos.x); if( m_data.m_distToTarget > 0 ) { const Real SLOP = 1.5f; @@ -1105,7 +1105,7 @@ class GenericObjectCreationNugget : public ObjectCreationNugget objUp->applyForce(&force); if (m_orientInForceDirection) - orientation = WWMath::Atan2Origin(force.y, force.x); + orientation = WWMath::Atan2_Origin(force.y, force.x); } } @@ -1193,7 +1193,7 @@ class GenericObjectCreationNugget : public ObjectCreationNugget objUp->applyForce(&force); if (m_orientInForceDirection) { - orientation = WWMath::Atan2Origin(force.y, force.x); + orientation = WWMath::Atan2_Origin(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 6f8bf73cb0c..4dbc17d73d8 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp @@ -415,13 +415,13 @@ static void testRotatedPointsAgainstRect( Real pty = pts->y - a->position.y; // inverse-rotate it to the right coord system - Real ptx_new = (Real)WWMath::FAbsOrigin(ptx*c - pty*s); - Real pty_new = (Real)WWMath::FAbsOrigin(ptx*s + pty*c); + Real ptx_new = (Real)WWMath::FAbs_Origin(ptx*c - pty*s); + Real pty_new = (Real)WWMath::FAbs_Origin(ptx*s + pty*c); #ifdef INTENSE_DEBUG Real mag_a = sqr(ptx)+sqr(pty); Real mag_b = sqr(ptx_new)+sqr(pty_new); - DEBUG_ASSERTCRASH(WWMath::FAbsOrigin(mag_a - mag_b) <= 1.0, ("hmm, unlikely")); + DEBUG_ASSERTCRASH(WWMath::FAbs_Origin(mag_a - mag_b) <= 1.0, ("hmm, unlikely")); #endif if (ptx_new <= major && pty_new <= minor) @@ -621,7 +621,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)WWMath::SqrtfOrigin(sqr(a->geom.getMajorRadius()) - sqr(b_bot - a->position.z))); + amod.geom.setMajorRadius((Real)WWMath::Sqrtf_Origin(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: @@ -639,7 +639,7 @@ inline Bool z_collideTest_Sphere_Nonsphere(CollideTestProc xyproc, const Collide { CollideInfo amod = *a; amod.position.z = b_top; - amod.geom.setMajorRadius((Real)WWMath::SqrtfOrigin(sqr(a->geom.getMajorRadius()) - sqr(a->position.z - b_top))); + amod.geom.setMajorRadius((Real)WWMath::Sqrtf_Origin(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: @@ -827,7 +827,7 @@ static Bool distCalcProc_BoundaryAndBoundary_2D( if (totalRad > 0.0f) { - Real actualDist = WWMath::SqrtfOrigin(actualDistSqr); + Real actualDist = WWMath::Sqrtf_Origin(actualDistSqr); Real shrunkenDist = actualDist - totalRad; if (shrunkenDist <= 0.0f) { @@ -915,7 +915,7 @@ static Bool distCalcProc_BoundaryAndBoundary_3D( Real totalRad = (geomA?geomA->getBoundingSphereRadius():0) + (geomB?geomB->getBoundingSphereRadius():0); if (totalRad > 0.0f) { - Real actualDist = WWMath::SqrtfOrigin(actualDistSqr); + Real actualDist = WWMath::Sqrtf_Origin(actualDistSqr); Real shrunkenDist = actualDist - totalRad; if (shrunkenDist <= 0.0f) { @@ -2226,7 +2226,7 @@ Int PartitionData::calcMaxCoiForShape(GeometryType geom, Real majorRadius, Real } case GEOMETRY_BOX: { - Real diagonal = (Real)(WWMath::SqrtfOrigin(majorRadius*majorRadius + minorRadius*minorRadius)); + Real diagonal = (Real)(WWMath::Sqrtf_Origin(majorRadius*majorRadius + minorRadius*minorRadius)); Int cells = ThePartitionManager->worldToCellDist(diagonal*2) + 1; result = cells * cells; break; @@ -2643,7 +2643,7 @@ static void calcHeights(const Region3D& world, Real cellSize, Int x, Int y, Real Real xbase = world.lo.x + (x * cellSize); Real ybase = world.lo.y + (y * cellSize); const Real ROUGH_STEP_SIZE = MAP_XY_FACTOR; // no point in stepping smaller than grid scale - Real numSteps = WWMath::CeilfOrigin(cellSize / ROUGH_STEP_SIZE); + Real numSteps = WWMath::Ceilf_Origin(cellSize / ROUGH_STEP_SIZE); Real step = cellSize / numSteps; loZ = HUGE_DIST; // huge positive hiZ = -HUGE_DIST; // huge negative @@ -3217,7 +3217,7 @@ Int PartitionManager::calcMinRadius(const ICoord2D& cur) } // double, not real - double dist = WWMath::SqrtfOrigin(minDistSqr); + double dist = WWMath::Sqrtf_Origin(minDistSqr); Int minRadius = REAL_TO_INT_CEIL( dist / m_cellSize ); return minRadius; @@ -3235,7 +3235,7 @@ void PartitionManager::calcRadiusVec() // double, not real double dx = (double)cx * (double)cellSize; double dy = (double)cy * (double)cellSize; - double maxPossibleDist = WWMath::SqrtOrigin(dx*dx + dy*dy); + double maxPossibleDist = WWMath::Sqrt_Origin(dx*dx + dy*dy); m_maxGcoRadius = REAL_TO_INT_CEIL(maxPossibleDist / cellSize); @@ -3505,7 +3505,7 @@ Object *PartitionManager::getClosestObjects( } if (closestDistArg) { - *closestDistArg = (Real)WWMath::SqrtfOrigin(closestDistSqr); + *closestDistArg = (Real)WWMath::Sqrtf_Origin(closestDistSqr); } #ifdef RTS_DEBUG @@ -3632,7 +3632,7 @@ Real PartitionManager::getRelativeAngle2D( const Object *obj, const Coord3D *pos v.y = pos->y - objPos.y; v.z = 0.0f; - Real dist = (Real)WWMath::SqrtfOrigin(sqr(v.x) + sqr(v.y)); + Real dist = (Real)WWMath::Sqrtf_Origin(sqr(v.x) + sqr(v.y)); // normalize if (dist == 0.0f) @@ -3810,7 +3810,7 @@ Bool PartitionManager::tryPosition( const Coord3D *center, pos.z = TheTerrainLogic->getGroundHeight( pos.x, pos.y ); } - if (WWMath::FAbsOrigin(pos.z - center->z) > options->maxZDelta) + if (WWMath::FAbs_Origin(pos.z - center->z) > options->maxZDelta) return FALSE; // @@ -4566,7 +4566,7 @@ Int PartitionManager::iterateCellsBreadthFirst(const Coord3D *pos, CellBreadthFi //----------------------------------------------------------------------------- static Real calcDist2D(Real x1, Real y1, Real x2, Real y2) { - return WWMath::SqrtfOrigin(sqr(x1-x2) + sqr(y1-y2)); + return WWMath::Sqrtf_Origin(sqr(x1-x2) + sqr(y1-y2)); } //----------------------------------------------------------------------------- @@ -5757,7 +5757,7 @@ void hLineAddThreat(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = WWMath::SqrtOrigin( WWMath::PowOrigin(x - parms->xCenter, 2) + WWMath::PowOrigin(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt_Origin( WWMath::Pow_Origin(x - parms->xCenter, 2) + WWMath::Pow_Origin(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5785,7 +5785,7 @@ void hLineRemoveThreat(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = WWMath::SqrtOrigin( WWMath::PowOrigin(x - parms->xCenter, 2) + WWMath::PowOrigin(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt_Origin( WWMath::Pow_Origin(x - parms->xCenter, 2) + WWMath::Pow_Origin(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5813,7 +5813,7 @@ void hLineAddValue(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = WWMath::SqrtOrigin( WWMath::PowOrigin(x - parms->xCenter, 2) + WWMath::PowOrigin(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt_Origin( WWMath::Pow_Origin(x - parms->xCenter, 2) + WWMath::Pow_Origin(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5841,7 +5841,7 @@ void hLineRemoveValue(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = WWMath::SqrtOrigin( WWMath::PowOrigin(x - parms->xCenter, 2) + WWMath::PowOrigin(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt_Origin( WWMath::Pow_Origin(x - parms->xCenter, 2) + WWMath::Pow_Origin(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp index dc88acf91b3..6d2e64441c9 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp @@ -1296,8 +1296,8 @@ Bool AIUpdateInterface::blockedBy(Object *other) // If we are near our final goal, don't get stuck. if (goalCell.x>0 && goalCell.y>0) { - Real dx = WWMath::FAbsOrigin(goalPos.x-pos.x); - Real dy = WWMath::FAbsOrigin(goalPos.y-pos.y); + Real dx = WWMath::FAbs_Origin(goalPos.x-pos.x); + Real dy = WWMath::FAbs_Origin(goalPos.y-pos.y); if (dxgetRelativeAngle2D( getObject(), &info.posOnPath ); } - if (WWMath::FAbsOrigin(deltaAngle)>PI/30) + if (WWMath::FAbs_Origin(deltaAngle)>PI/30) { return TRUE; } @@ -2272,7 +2272,7 @@ UpdateSleepTime AIUpdateInterface::doLocomotor() } else { - Real dist = WWMath::SqrtfOrigin(dSqr); + Real dist = WWMath::Sqrtf_Origin(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 WWMath::SqrtOrigin( distance );// Other paths return dots of normalized vectors, so one sqrt ain't so bad + return WWMath::Sqrt_Origin( 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 WWMath::SqrtOrigin(distSqr); + return WWMath::Sqrt_Origin(distSqr); } else { @@ -2514,7 +2514,7 @@ Real AIUpdateInterface::getLocomotorDistanceToGoal() } if (distropeLen < it->ropeLenMax) { - it->ropeSpeed += WWMath::FAbsOrigin(TheGlobalData->m_gravity); + it->ropeSpeed += WWMath::FAbs_Origin(TheGlobalData->m_gravity); if (it->ropeSpeed > d->m_ropeDropSpeed) it->ropeSpeed = d->m_ropeDropSpeed; it->ropeLen += it->ropeSpeed; @@ -762,7 +762,7 @@ class ChinookMoveToBldgState : public AIMoveToState StateReturnType status = AIMoveToState::update(); const Real THRESH = 3.0f; - if (status != STATE_CONTINUE && WWMath::FAbsOrigin(obj->getPosition()->z - m_destZ) > THRESH) + if (status != STATE_CONTINUE && WWMath::FAbs_Origin(obj->getPosition()->z - m_destZ) > THRESH) status = STATE_CONTINUE; return status; @@ -891,7 +891,7 @@ ChinookAIUpdateModuleData::ChinookAIUpdateModuleData() m_minDropHeight = 30.0f; m_ropeFinalHeight = 0.0f; m_ropeDropSpeed = 1e10f; // um, fast. - m_rappelSpeed = WWMath::FAbsOrigin(TheGlobalData->m_gravity) * LOGICFRAMES_PER_SECOND * 0.5f; + m_rappelSpeed = WWMath::FAbs_Origin(TheGlobalData->m_gravity) * LOGICFRAMES_PER_SECOND * 0.5f; m_ropeWobbleLen = 10.0f; m_ropeWobbleAmp = 1.0f; m_ropeWobbleRate = 0.1f; 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 3e6ead39fb1..7c33c70ff2c 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp @@ -202,8 +202,8 @@ UpdateSleepTime DeliverPayloadAIUpdate::update() { //Calc strafe ratio Real startDiveDistance = getData()->m_diveStartDistance; - Real endDiveDistance = WWMath::SqrtOrigin( endDiveDistanceSquared ); - Real currentDistance = WWMath::SqrtOrigin( currentDistanceSquared ); + Real endDiveDistance = WWMath::Sqrt_Origin( endDiveDistanceSquared ); + Real currentDistance = WWMath::Sqrt_Origin( currentDistanceSquared ); Real diveRatio = (startDiveDistance - currentDistance) / (startDiveDistance - endDiveDistance); @@ -1108,7 +1108,7 @@ StateReturnType RecoverFromOffMapState::update() // Success if we should try aga enterCoord.z = owner->getPosition()->z; owner->setPosition(&enterCoord); - Real enterAngle = WWMath::Atan2Origin(ai->getMoveToPos()->y - enterCoord.y, ai->getMoveToPos()->x - enterCoord.x); + Real enterAngle = WWMath::Atan2_Origin(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 * WWMath::SqrtOrigin(sqr(terrainExtent.hi.x - terrainExtent.lo.x) + sqr(terrainExtent.hi.y - terrainExtent.lo.y)); + Real HUGE_DIST = FUDGE * WWMath::Sqrt_Origin(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 8f970922928..950b2d6c5b3 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp @@ -516,8 +516,8 @@ class JetOrHeliTaxiState : public AIMoveOutOfTheWayState Coord3D intermedPt; Bool intermed = false; - Real orient = WWMath::Atan2Origin(ppinfo.runwayPrep.y - ppinfo.parkingSpace.y, ppinfo.runwayPrep.x - ppinfo.parkingSpace.x); - if (WWMath::FAbsOrigin(stdAngleDiff(orient, ppinfo.parkingOrientation)) > PI/128) + Real orient = WWMath::Atan2_Origin(ppinfo.runwayPrep.y - ppinfo.parkingSpace.y, ppinfo.runwayPrep.x - ppinfo.parkingSpace.x); + if (WWMath::FAbs_Origin(stdAngleDiff(orient, ppinfo.parkingOrientation)) > PI/128) { intermedPt.z = (ppinfo.parkingSpace.z + ppinfo.runwayPrep.z) * 0.5f; intermed = intersectInfiniteLine2D( @@ -1071,7 +1071,7 @@ class HeliTakeoffOrLandingState : public State } else { - Real dist = WWMath::SqrtfOrigin(dSqr); + Real dist = WWMath::Sqrtf_Origin(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); @@ -1199,7 +1199,7 @@ class JetOrHeliParkOrientState : public State return STATE_FAILURE; const Real THRESH = 0.001f; - if (WWMath::FAbsOrigin(stdAngleDiff(jet->getOrientation(), ppinfo.parkingOrientation)) <= THRESH) + if (WWMath::FAbs_Origin(stdAngleDiff(jet->getOrientation(), ppinfo.parkingOrientation)) <= THRESH) return STATE_SUCCESS; // magically position it correctly. @@ -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(WWMath::Atan2Origin(dy, dx)); + m_lockonDrawable->setOrientation(WWMath::Atan2_Origin(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 08c342b7c03..96b2b482813 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 = WWMath::SqrtOrigin(sqr(dx)+sqr(dy)); + Real xyDist = WWMath::Sqrt_Origin(sqr(dx)+sqr(dy)); if (xyDist<1) xyDist = 1; Real zFactor = 0; if (deltaZ>0) { @@ -649,7 +649,7 @@ UpdateSleepTime MissileAIUpdate::update() Coord3D newPos = *getObject()->getPosition(); if (m_noTurnDistLeft > 0.0f && m_state >= IGNITION) { - Real distThisTurn = WWMath::SqrtfOrigin(sqr(newPos.x-m_prevPos.x) + sqr(newPos.y-m_prevPos.y) + sqr(newPos.z-m_prevPos.z)); + Real distThisTurn = WWMath::Sqrtf_Origin(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/POWTruckAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/POWTruckAIUpdate.cpp index bcbab2e4600..81204144701 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/POWTruckAIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/POWTruckAIUpdate.cpp @@ -480,7 +480,7 @@ void POWTruckAIUpdate::updateCollectingTarget() { // are we close enough to tell them to start moving to us - Real distSq = WWMath::PowOrigin( us->getGeometryInfo().getBoundingSphereRadius() * 2.0f, 2 ); + Real distSq = WWMath::Pow_Origin( us->getGeometryInfo().getBoundingSphereRadius() * 2.0f, 2 ); if( ThePartitionManager->getDistanceSquared( us, target, FROM_CENTER_2D ) <= distSq ) { 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 39847819b0c..702ae10a195 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)WWMath::SqrtfOrigin( dlt.x*dlt.x + dlt.y*dlt.y + dlt.z*dlt.z); + Real dist = (Real)WWMath::Sqrtf_Origin( 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. @@ -467,8 +467,8 @@ void RailroadBehavior::playImpactSound(Object *victim, const Coord3D *impactPosi impact.setPosition(impactPosition); if ( theirPhys ) { - vel += WWMath::FAbsOrigin(theirPhys->getVelocity()->length()); - mass += WWMath::FAbsOrigin(theirPhys->getMass()); + vel += WWMath::FAbs_Origin(theirPhys->getVelocity()->length()); + mass += WWMath::FAbs_Origin(theirPhys->getMass()); vel /= 2; mass /= 2;//average of him and me @@ -700,7 +700,7 @@ UpdateSleepTime RailroadBehavior::update() if ( m_conductorState == APPLY_BRAKES ) { conductorPullInfo.speed *= modData->m_braking; - if (WWMath::FAbsOrigin(conductorPullInfo.speed) < 0.1f) + if (WWMath::FAbs_Origin(conductorPullInfo.speed) < 0.1f) { conductorPullInfo.speed = 0; ///////////////////////////////////////( &m_hissySteamSound ); @@ -1233,7 +1233,7 @@ void alignToTerrain( Real angle, const Coord3D& pos, const Coord3D& normal, Matr x.normalize(); } - DEBUG_ASSERTCRASH(WWMath::FAbsOrigin(x.x*z.x + x.y*z.y + x.z*z.z)<0.0001,("dot is not zero")); + DEBUG_ASSERTCRASH(WWMath::FAbs_Origin(x.x*z.x + x.y*z.y + x.z*z.z)<0.0001,("dot is not zero")); // now computing the y vector is trivial. y.crossProduct( &z, &x, &y ); @@ -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 = WWMath::Atan2Origin(dy, dx); + Real desiredAngle = WWMath::Atan2_Origin(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 78fee0b7978..298e42e9171 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 = WWMath::SqrtOrigin( ThePartitionManager->getDistanceSquared( obj, &m_pos, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt_Origin( 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 = WWMath::SqrtOrigin( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt_Origin( 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 c769f4880d5..a6bd4cf0a73 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 = WWMath::SqrtOrigin(distSqr); + Real dist = WWMath::Sqrt_Origin(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 a00ebef152f..4cffc259c62 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).", WWMath::SqrtOrigin(curDistSqr), WWMath::SqrtOrigin(closeEnoughSqr))); + DEBUG_LOG(("Failing dock, dist %f, not close enough(%f).", WWMath::Sqrt_Origin(curDistSqr), WWMath::Sqrt_Origin(closeEnoughSqr))); // Make it twitch a little. Coord3D newPos = *docker->getPosition(); Real range = 0.4*PATHFIND_CELL_SIZE_F; @@ -170,7 +170,7 @@ void SupplyWarehouseDockUpdate::setDockCrippled( Bool setting ) void SupplyWarehouseDockUpdate::setCashValue( Int cashValue ) { // A script can tell us our set value, and we need to figure out the boxes needed to provide that. - m_boxesStored = WWMath::CeilOrigin(cashValue / (float)TheGlobalData->m_baseValuePerSupplyBox); + m_boxesStored = WWMath::Ceil_Origin(cashValue / (float)TheGlobalData->m_baseValuePerSupplyBox); Drawable *draw = getObject()->getDrawable(); if( draw ) { diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp index 73b623e1902..7c3161df07e 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp @@ -297,7 +297,7 @@ static Real calcTransform(const Object* obj, const Coord3D *pos, Real maxTurnRat Real angle = (Real)ACos( c ); Vector3 newDir; - if (WWMath::FAbsOrigin(angle) < maxTurnRate) + if (WWMath::FAbs_Origin(angle) < maxTurnRate) { // close enough -- point exactly in the right dir newDir = otherDir; @@ -355,7 +355,7 @@ void NeutronMissileUpdate::doAttack() // // Modulate speed according to turning. The more we have to turn, the slower we go // - Real angleCoeff = (Real)WWMath::FAbsOrigin( relAngle ) / (PI / 2.0f); + Real angleCoeff = (Real)WWMath::FAbs_Origin( relAngle ) / (PI / 2.0f); if (angleCoeff > 1.0f) angleCoeff = 1.0; } @@ -512,7 +512,7 @@ UpdateSleepTime NeutronMissileUpdate::update() if (m_noTurnDistLeft > 0.0f && oldPosValid) { Coord3D newPos = *getObject()->getPosition(); - Real distThisTurn = WWMath::SqrtOrigin(sqr(newPos.x-oldPos.x) + sqr(newPos.y-oldPos.y) + sqr(newPos.z-oldPos.z)); + Real distThisTurn = WWMath::Sqrt_Origin(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 b4196f0ec1b..50a5f73afda 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp @@ -101,7 +101,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 WWMath::SqrtOrigin(WWMath::FAbsOrigin(2.0f * TheGlobalData->m_gravity * height)); + return WWMath::Sqrt_Origin(WWMath::FAbs_Origin(2.0f * TheGlobalData->m_gravity * height)); } //------------------------------------------------------------------------------------------------- @@ -511,7 +511,7 @@ Bool PhysicsBehavior::handleBounce(Real oldZ, Real newZ, Real groundZ, Coord3D* Real vz = getVelocity()->z; if (oldZ > groundZ && vz < 0.0f) { - desiredAccelZ = WWMath::FAbsOrigin(vz) * stiffness; + desiredAccelZ = WWMath::FAbs_Origin(vz) * stiffness; } bounceForce->x = 0.0f; @@ -553,7 +553,7 @@ Bool PhysicsBehavior::handleBounce(Real oldZ, Real newZ, Real groundZ, Coord3D* inline Bool isVerySmall3D(const Coord3D& v) { const Real THRESH = 0.01f; - return (WWMath::FAbsOrigin(v.x) < THRESH && WWMath::FAbsOrigin(v.y) < THRESH && WWMath::FAbsOrigin(v.z) < THRESH); + return (WWMath::FAbs_Origin(v.x) < THRESH && WWMath::FAbs_Origin(v.y) < THRESH && WWMath::FAbs_Origin(v.z) < THRESH); } //------------------------------------------------------------------------------------------------- @@ -653,9 +653,9 @@ UpdateSleepTime PhysicsBehavior::update() // when vel gets tiny, just clamp to zero const Real THRESH = 0.001f; - if (WWMath::FAbsfOrigin(m_vel.x) < THRESH) m_vel.x = 0.0f; - if (WWMath::FAbsfOrigin(m_vel.y) < THRESH) m_vel.y = 0.0f; - if (WWMath::FAbsfOrigin(m_vel.z) < THRESH) m_vel.z = 0.0f; + if (WWMath::FAbsf_Origin(m_vel.x) < THRESH) m_vel.x = 0.0f; + if (WWMath::FAbsf_Origin(m_vel.y) < THRESH) m_vel.y = 0.0f; + if (WWMath::FAbsf_Origin(m_vel.z) < THRESH) m_vel.z = 0.0f; m_velMag = INVALID_VEL_MAG; @@ -687,9 +687,9 @@ UpdateSleepTime PhysicsBehavior::update() // Check when to clear the stunned status if (getIsStunned()) { - if ( (WWMath::FAbsOrigin(m_vel.x) < STUN_RELIEF_EPSILON && - WWMath::FAbsOrigin(m_vel.y) < STUN_RELIEF_EPSILON && - WWMath::FAbsOrigin(m_vel.z) < STUN_RELIEF_EPSILON) + if ( (WWMath::FAbs_Origin(m_vel.x) < STUN_RELIEF_EPSILON && + WWMath::FAbs_Origin(m_vel.y) < STUN_RELIEF_EPSILON && + WWMath::FAbs_Origin(m_vel.z) < STUN_RELIEF_EPSILON) || obj->isSignificantlyAboveTerrain() == FALSE ) { @@ -735,8 +735,8 @@ UpdateSleepTime PhysicsBehavior::update() if (offset != 0.0f) { Vector3 xvec = mtx.Get_X_Vector(); - Real xy = WWMath::SqrtfOrigin(sqr(xvec.X) + sqr(xvec.Y)); - Real pitchAngle = WWMath::Atan2Origin(xvec.Z, xy); + Real xy = WWMath::Sqrtf_Origin(sqr(xvec.X) + sqr(xvec.Y)); + Real pitchAngle = WWMath::Atan2_Origin(xvec.Z, xy); Real remainingAngle = (offset > 0) ? ((PI/2) - pitchAngle) : (-(PI/2) + pitchAngle); Real s = Sin(remainingAngle); pitchRateToUse *= s; @@ -862,8 +862,8 @@ UpdateSleepTime PhysicsBehavior::update() // going down hills don't injure themselves (unless the hill is really steep) const Real MIN_ANGLE_TAN = 3.0f; // roughly 71 degrees const Real TINY_DELTA = 0.01f; - if ((WWMath::FAbsOrigin(m_vel.x) <= TINY_DELTA || WWMath::FAbsOrigin(activeVelZ / m_vel.x) >= MIN_ANGLE_TAN) && - (WWMath::FAbsOrigin(m_vel.y) <= TINY_DELTA || WWMath::FAbsOrigin(activeVelZ / m_vel.y) >= MIN_ANGLE_TAN)) + if ((WWMath::FAbs_Origin(m_vel.x) <= TINY_DELTA || WWMath::FAbs_Origin(activeVelZ / m_vel.x) >= MIN_ANGLE_TAN) && + (WWMath::FAbs_Origin(m_vel.y) <= TINY_DELTA || WWMath::FAbs_Origin(activeVelZ / m_vel.y) >= MIN_ANGLE_TAN)) { Real damageAmt = netSpeed * getMass() * d->m_fallHeightDamageFactor; @@ -942,7 +942,7 @@ Real PhysicsBehavior::getVelocityMagnitude() const { if (m_velMag == INVALID_VEL_MAG) { - m_velMag = (Real)WWMath::SqrtfOrigin( sqr(m_vel.x) + sqr(m_vel.y) + sqr(m_vel.z) ); + m_velMag = (Real)WWMath::Sqrtf_Origin( sqr(m_vel.x) + sqr(m_vel.y) + sqr(m_vel.z) ); } return m_velMag; } @@ -964,7 +964,7 @@ Real PhysicsBehavior::getForwardSpeed2D() const Real speedSquared = vx*vx + vy*vy; // DEBUG_ASSERTCRASH( speedSquared != 0, ("zero speedSquared will overflow sqrtf()!") );// lorenzen... sanity check - Real speed = (Real)WWMath::SqrtfOrigin( speedSquared ); + Real speed = (Real)WWMath::Sqrtf_Origin( speedSquared ); if (dot >= 0.0f) return speed; @@ -987,7 +987,7 @@ Real PhysicsBehavior::getForwardSpeed3D() const Real dot = vx + vy + vz; - Real speed = (Real)WWMath::SqrtfOrigin( vx*vx + vy*vy + vz*vz ); + Real speed = (Real)WWMath::Sqrtf_Origin( vx*vx + vy*vy + vz*vz ); if (dot >= 0.0f) return speed; @@ -1010,7 +1010,7 @@ Bool PhysicsBehavior::wasPreviouslyOverlapped(Object *obj) const //------------------------------------------------------------------------------------------------- void PhysicsBehavior::scrubVelocityZ( Real desiredVelocity ) { - if (WWMath::FAbsOrigin(desiredVelocity) < 0.001f) + if (WWMath::FAbs_Origin(desiredVelocity) < 0.001f) { m_vel.z = 0; } @@ -1034,7 +1034,7 @@ void PhysicsBehavior::scrubVelocity2D( Real desiredVelocity ) } else { - Real curVelocity = WWMath::SqrtfOrigin(m_vel.x*m_vel.x + m_vel.y*m_vel.y); + Real curVelocity = WWMath::Sqrtf_Origin(m_vel.x*m_vel.x + m_vel.y*m_vel.y); if (desiredVelocity > curVelocity) { return; @@ -1117,9 +1117,9 @@ void PhysicsBehavior::doBounceSound(const Coord3D& prevPos) //Real vel = fabs(getVelocity()->z); // can't use velocity, because it's already been updated this frame, and will be zero... (srj) - Real vel = WWMath::FAbsOrigin(prevPos.z - getObject()->getPosition()->z); + Real vel = WWMath::FAbs_Origin(prevPos.z - getObject()->getPosition()->z); - Real mass = WWMath::FAbsOrigin(getMass()); + Real mass = WWMath::FAbs_Origin(getMass()); if (vel > NORMAL_VEL_Z) { vel = NORMAL_VEL_Z; } @@ -1319,7 +1319,7 @@ void PhysicsBehavior::onCollide( Object *other, const Coord3D *loc, const Coord3 m_lastCollidee = other->getID(); - Real dist = WWMath::SqrtfOrigin(distSqr); + Real dist = WWMath::Sqrtf_Origin(distSqr); Real overlap = usRadius + themRadius - dist; // if objects are coincident, dist is zero, so force would be infinite -- clearly @@ -1422,7 +1422,7 @@ static Bool perpsLogicallyEqual( Real perpOne, Real perpTwo ) { // Equality with a wiggle fudge. const Real PERP_RANGE = 0.15f; - return WWMath::FAbsOrigin( perpOne - perpTwo ) <= PERP_RANGE; + return WWMath::FAbs_Origin( perpOne - perpTwo ) <= PERP_RANGE; } //------------------------------------------------------------------------------------------------- diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp index 6772e21c55f..c0830dff103 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 = WWMath::SqrtOrigin( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt_Origin( 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 = WWMath::SqrtOrigin( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt_Origin( 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 = WWMath::SqrtOrigin( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); + fDist = WWMath::Sqrt_Origin( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); } } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipDeploymentUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipDeploymentUpdate.cpp index 1e550a40f6f..8f9d54a8ae7 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 = WWMath::Atan2Origin( m_initialTargetPosition.y - creationCoord.y, m_initialTargetPosition.x - creationCoord.x); + Real orient = WWMath::Atan2_Origin( 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 795b3f7d333..5b4e7607ed3 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp @@ -670,7 +670,7 @@ UpdateSleepTime StealthUpdate::update() m_disguiseHalfpointReached = true; } //Opacity ranges from full to none at midpoint and full again at the end - Real opacity = WWMath::FAbsOrigin( 1.0f - (factor * 2.0f) ); + Real opacity = WWMath::FAbs_Origin( 1.0f - (factor * 2.0f) ); Real overrideOpacity = opacity < 1.0f ? 0.0f : 1.0f; draw->setEffectiveOpacity( opacity, overrideOpacity ); if( !m_disguiseTransitionFrames && !m_transitioningToDisguise ) diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/TensileFormationUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/TensileFormationUpdate.cpp index f80e99d1185..ee70001b3e8 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/TensileFormationUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/TensileFormationUpdate.cpp @@ -348,7 +348,7 @@ UpdateSleepTime TensileFormationUpdate::update() else draw->clearModelConditionFlags(MAKE_MODELCONDITION_MASK(MODELCONDITION_MOVING)); - if ( WWMath::FAbsOrigin( pos->z - newPos.z ) > 0.2f && m_life < 100) + if ( WWMath::FAbs_Origin( pos->z - newPos.z ) > 0.2f && m_life < 100) draw->setModelConditionFlags(MAKE_MODELCONDITION_MASK(MODELCONDITION_FREEFALL)); else draw->clearModelConditionFlags(MAKE_MODELCONDITION_MASK(MODELCONDITION_FREEFALL)); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp index 93975b7d940..9d755ba6308 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ToppleUpdate.cpp @@ -130,7 +130,7 @@ static Real angleClosestTo(Real a1, Real a2, Real desired) { a1 = normalizeAngle(a1); a2 = normalizeAngle(a2); - return (WWMath::FAbsOrigin(stdAngleDiff(desired, a1)) < WWMath::FAbsOrigin(stdAngleDiff(desired, a2))) ? a1 : a2; + return (WWMath::FAbs_Origin(stdAngleDiff(desired, a1)) < WWMath::FAbs_Origin(stdAngleDiff(desired, a2))) ? a1 : a2; } //------------------------------------------------------------------------------------------------- @@ -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(WWMath::Atan2Origin(m_toppleDirection.y, m_toppleDirection.x)); + Real toppleAngle = normalizeAngle(WWMath::Atan2_Origin(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 @@ -298,7 +298,7 @@ UpdateSleepTime ToppleUpdate::update() m_angularVelocity *= -d->m_bounceVelocityPercent; if( BitIsSet( m_options, TOPPLE_OPTIONS_NO_BOUNCE ) == TRUE || - WWMath::FAbsOrigin(m_angularVelocity) < VELOCITY_BOUNCE_LIMIT ) + WWMath::FAbs_Origin(m_angularVelocity) < VELOCITY_BOUNCE_LIMIT ) { // too slow, just stop m_angularVelocity = 0; @@ -338,7 +338,7 @@ UpdateSleepTime ToppleUpdate::update() } } } - else if( WWMath::FAbsOrigin(m_angularVelocity) >= VELOCITY_BOUNCE_SOUND_LIMIT ) + else if( WWMath::FAbs_Origin(m_angularVelocity) >= VELOCITY_BOUNCE_SOUND_LIMIT ) { // fast enough bounce to warrant the bounce fx if( BitIsSet( m_options, TOPPLE_OPTIONS_NO_FX ) == FALSE ) diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp index 880e630768a..40fe3a22a29 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp @@ -397,8 +397,8 @@ void WeaponTemplate::reset() // No matter what we have now, we want to convert it to frames from msec. // ShotDelay used to use parseDurationUnsignedInt, and we are expanding on that. - self->m_minDelayBetweenShots = WWMath::CeilfOrigin(ConvertDurationFromMsecsToFrames((Real)self->m_minDelayBetweenShots)); - self->m_maxDelayBetweenShots = WWMath::CeilfOrigin(ConvertDurationFromMsecsToFrames((Real)self->m_maxDelayBetweenShots)); + self->m_minDelayBetweenShots = WWMath::Ceilf_Origin(ConvertDurationFromMsecsToFrames((Real)self->m_minDelayBetweenShots)); + self->m_maxDelayBetweenShots = WWMath::Ceilf_Origin(ConvertDurationFromMsecsToFrames((Real)self->m_maxDelayBetweenShots)); } @@ -879,7 +879,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?",WWMath::SqrtfOrigin(distSqr),WWMath::SqrtfOrigin(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::Sqrtf_Origin(distSqr),WWMath::Sqrtf_Origin(minAttackRangeSqr))); //-extraLogging #if defined(RTS_DEBUG) @@ -905,7 +905,7 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate targetPos.set( victimPos ); } Real reAngle = getWeaponRecoilAmount(); - Real reDir = reAngle != 0.0f ? (WWMath::Atan2Origin(victimPos->y - sourcePos->y, victimPos->x - sourcePos->x)) : 0.0f; + Real reDir = reAngle != 0.0f ? (WWMath::Atan2_Origin(victimPos->y - sourcePos->y, victimPos->x - sourcePos->x)) : 0.0f; VeterancyLevel v = sourceObj->getVeterancyLevel(); const FXList* fx = isProjectileDetonation ? getProjectileDetonateFX(v) : getFireFX(v); @@ -1502,9 +1502,9 @@ void WeaponTemplate::dealDamageInternal(ObjectID sourceID, ObjectID victimID, co Coord3D shockWaveVector = damageDirection; // Guard against zero vector. Make vector straight up if that is the case - if (WWMath::FAbsOrigin(shockWaveVector.x) < WWMATH_EPSILON && - WWMath::FAbsOrigin(shockWaveVector.y) < WWMATH_EPSILON && - WWMath::FAbsOrigin(shockWaveVector.z) < WWMATH_EPSILON) + if (WWMath::FAbs_Origin(shockWaveVector.x) < WWMATH_EPSILON && + WWMath::FAbs_Origin(shockWaveVector.y) < WWMATH_EPSILON && + WWMath::FAbs_Origin(shockWaveVector.z) < WWMATH_EPSILON) { shockWaveVector.z = 1.0f; } @@ -2117,11 +2117,11 @@ Bool Weapon::computeApproachTarget(const Object *source, const Object *target, c if (source->isAboveTerrain()) { // Don't do a 180 degree turn. - Real angle = WWMath::Atan2Origin(-dir.y, -dir.x); + Real angle = WWMath::Atan2_Origin(-dir.y, -dir.x); Real relAngle = source->getOrientation()- angle; if (relAngle>2*PI) relAngle -= 2*PI; if (relAngle<-2*PI) relAngle += 2*PI; - if (WWMath::FAbsOrigin(relAngle)getPosition(); const Real ACCEPTABLE_DZ = 10.0f; - if (WWMath::FAbsOrigin(dst->z - src->z) < ACCEPTABLE_DZ) + if (WWMath::FAbs_Origin(dst->z - src->z) < ACCEPTABLE_DZ) return true; // always good enough if dz is small, regardless of pitch Real minPitch, maxPitch; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp index 230c921b674..2627099fdca 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp @@ -849,7 +849,7 @@ static void populateRandomStartPosition( GameInfo *game ) { Coord3D p1 = c1->second; Coord3D p2 = c2->second; - startSpotDistance[i][j] = WWMath::SqrtOrigin( sqr(p1.x-p2.x) + sqr(p1.y-p2.y) ); + startSpotDistance[i][j] = WWMath::Sqrt_Origin( sqr(p1.x-p2.x) + sqr(p1.y-p2.y) ); } } else @@ -3739,19 +3739,13 @@ void GameLogic::update() TheTerrainLogic->UPDATE(); } -#ifdef RUN_MATH_BENCHMARK_REPLAY400_FLAG - static int s_replayStartFrame = -1; +#if RUN_MATH_BENCHMARK_REPLAY400_FLAG static bool s_benchmarkRun = false; - if (!s_benchmarkRun && TheRecorder && TheRecorder->isPlaybackMode()) + if (!s_benchmarkRun && m_frame == 400) { - if (s_replayStartFrame == -1) { - s_replayStartFrame = m_frame; - } - else if (m_frame == s_replayStartFrame + 400) { - SimulationMathCrc::runBenchmark(10000); - s_benchmarkRun = true; - } + SimulationMathCrc::runBenchmark(10000); + s_benchmarkRun = true; } #endif diff --git a/cmake/compilers.cmake b/cmake/compilers.cmake index afaf5df2387..cd047333108 100644 --- a/cmake/compilers.cmake +++ b/cmake/compilers.cmake @@ -51,7 +51,7 @@ if (NOT IS_VS6_BUILD) add_compile_options(/Zc:__cplusplus) else() add_compile_options(-Wsuggest-override) - # TheSuperHackers @fix Prevent FMA contraction (a*b+c -> fmadd) which skips intermediate + # Prevent FMA contraction (a*b+c -> fmadd) which skips intermediate # rounding and breaks cross-platform deterministic math parity with MSVC (/fp:precise). add_compile_options(-ffp-contract=off) endif() diff --git a/cmake/gamemath.cmake b/cmake/gamemath.cmake index 55e31898d0b..57dfaf4adfc 100644 --- a/cmake/gamemath.cmake +++ b/cmake/gamemath.cmake @@ -12,5 +12,5 @@ FetchContent_Declare( FetchContent_MakeAvailable(gamemath) # Ensure GameMath includes are available to ALL targets -# to prevent ODR violations and ensure USE_DETERMINISTIC_MATH activates consistently. +# to prevent one-definition-rule violations and ensure USE_DETERMINISTIC_MATH activates consistently. include_directories(${gamemath_SOURCE_DIR}/include) From 1856ad93d514ec7fdb9b7384c3b00ffe8c14495f Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Fri, 8 May 2026 12:13:15 +0300 Subject: [PATCH 9/9] style(math): Fix indentation of if statements in benchmark --- .../Source/Common/Diagnostic/SimulationMathCrc.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp b/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp index cebc1ec59d3..23091caff97 100644 --- a/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp +++ b/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp @@ -118,7 +118,8 @@ void SimulationMathCrc::runBenchmark(int iterations) xfer.open("SimMathDet"); appendSimulationMathCrc_Deterministic(xfer); xfer.close(); - if (i == 0) crcDet = xfer.getCRC(); + if (i == 0) + crcDet = xfer.getCRC(); } _fpreset(); clock_t endDet = clock(); @@ -135,7 +136,8 @@ void SimulationMathCrc::runBenchmark(int iterations) xfer.open("SimMathNat"); appendSimulationMathCrc_Native(xfer); xfer.close(); - if (i == 0) crcNat = xfer.getCRC(); + if (i == 0) + crcNat = xfer.getCRC(); } _fpreset(); clock_t endNat = clock();