From 39e1da0ff5bb05a5ff899e3b6f68fa79c820a91a Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Wed, 19 Aug 2026 19:22:06 +0300 Subject: [PATCH 1/9] build(cmake): Add gamemath library and deterministic math build options (#2670) Introduces the gamemath.cmake module and wires HAS_GAMEMATH / USE_DETERMINISTIC_MATH through the compiler configuration. --- CMakeLists.txt | 5 +++++ cmake/compilers.cmake | 3 +++ cmake/gamemath.cmake | 13 +++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 cmake/gamemath.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index eef5514bab1..f3d7d6599eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,6 +65,11 @@ endif() include(cmake/config.cmake) include(cmake/gamespy.cmake) +if (IS_VS6_BUILD) + add_library(gamemath INTERFACE) +else() + include(cmake/gamemath.cmake) +endif() include(cmake/lzhl.cmake) include(cmake/stb.cmake) diff --git a/cmake/compilers.cmake b/cmake/compilers.cmake index 501971700db..03f84f6d9bd 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) + # 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) diff --git a/cmake/gamemath.cmake b/cmake/gamemath.cmake new file mode 100644 index 00000000000..67f732ab45f --- /dev/null +++ b/cmake/gamemath.cmake @@ -0,0 +1,13 @@ +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 one-definition-rule violations and ensure USE_DETERMINISTIC_MATH activates consistently. +include_directories(${gamemath_SOURCE_DIR}/include) From b7d9c3e7931b05917c3c19ba8baed7d31428e522 Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Mon, 28 Sep 2026 08:57:52 +0300 Subject: [PATCH 2/9] chore(basedefines): Add RETAIL_COMPATIBLE_CRC and USE_DETERMINISTIC_MATH switches (#2670) Moves RETAIL_COMPATIBLE_CRC into BaseDefines.h so that WWMath can see it without depending on GameDefines.h, and adds USE_DETERMINISTIC_MATH which is disabled automatically when retail CRC compatibility is required. BaseFunctions.h and Coord2D.h include BaseDefines.h, which enables the RETAIL_COMPATIBLE_CRC condition of REAL_TO_INT_CEIL, REAL_TO_INT_FLOOR and Coord2D::toAngle. config-retail.cmake collects the RETAIL_COMPATIBLE_ defines of BaseDefines.h as well, so RTS_BUILD_OPTION_RETAIL_COMPATIBLE_GAME keeps controlling RETAIL_COMPATIBLE_CRC. --- Core/GameEngine/Include/Common/GameDefines.h | 4 +- Core/Libraries/CMakeLists.txt | 1 + Core/Libraries/Include/Lib/BaseDefines.h | 37 +++++++++++++++++++ Core/Libraries/Include/Lib/BaseFunctions.h | 4 +- Core/Libraries/Include/Lib/Coord2D.h | 3 +- .../Source/WWVegas/WWLib/WWDefines.h | 2 + cmake/config-retail.cmake | 4 ++ 7 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 Core/Libraries/Include/Lib/BaseDefines.h diff --git a/Core/GameEngine/Include/Common/GameDefines.h b/Core/GameEngine/Include/Common/GameDefines.h index 9800b7d3787..9ca8eb70b35 100644 --- a/Core/GameEngine/Include/Common/GameDefines.h +++ b/Core/GameEngine/Include/Common/GameDefines.h @@ -123,9 +123,7 @@ // Note: Retail compatibility must not be broken before this project officially does. // Use RETAIL_COMPATIBLE_CRC, RETAIL_COMPATIBLE_DATA and RETAIL_COMPATIBLE_XFER_SAVE to guard breaking changes. -#ifndef RETAIL_COMPATIBLE_CRC -#define RETAIL_COMPATIBLE_CRC (1) // Game is expected to be CRC compatible with retail Generals 1.08, Zero Hour 1.04 -#endif +// RETAIL_COMPATIBLE_CRC is default defined in BaseDefines.h #ifndef RETAIL_COMPATIBLE_DATA #define RETAIL_COMPATIBLE_DATA (1) // Game and tool data files are expected to be compatible with retail Generals 1.08 and Zero Hour 1.04 diff --git a/Core/Libraries/CMakeLists.txt b/Core/Libraries/CMakeLists.txt index b5a52b0fd53..1e013bbcc53 100644 --- a/Core/Libraries/CMakeLists.txt +++ b/Core/Libraries/CMakeLists.txt @@ -1,5 +1,6 @@ # Base headers and debug utilities shared by all libraries set(LIBRARIES_INCLUDE_SRC + Include/Lib/BaseDefines.h Include/Lib/BaseFunctions.h Include/Lib/BaseType.h Include/Lib/Coord2D.h diff --git a/Core/Libraries/Include/Lib/BaseDefines.h b/Core/Libraries/Include/Lib/BaseDefines.h new file mode 100644 index 00000000000..88d10a8fc15 --- /dev/null +++ b/Core/Libraries/Include/Lib/BaseDefines.h @@ -0,0 +1,37 @@ +/* +** Command & Conquer Generals Zero Hour(tm) +** Copyright 2026 TheSuperHackers +** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +*/ + +#pragma once + +#ifndef RETAIL_COMPATIBLE_CRC +#define RETAIL_COMPATIBLE_CRC (1) // Game is expected to be CRC compatible with retail Generals 1.08, Zero Hour 1.04 +#endif + +#ifndef USE_DETERMINISTIC_MATH +#define USE_DETERMINISTIC_MATH (1) // Game uses deterministic math for game simulation compatibility among different system architectures in peer to peer networks +#endif + +#if defined(__has_include) +#if __has_include("gmath.h") +#define HAS_GAMEMATH (1) +#endif +#endif + +#if !HAS_GAMEMATH || RETAIL_COMPATIBLE_CRC +#undef USE_DETERMINISTIC_MATH // Unfortunately cannot actually use deterministic math +#endif diff --git a/Core/Libraries/Include/Lib/BaseFunctions.h b/Core/Libraries/Include/Lib/BaseFunctions.h index b4d9346391e..b221b407046 100644 --- a/Core/Libraries/Include/Lib/BaseFunctions.h +++ b/Core/Libraries/Include/Lib/BaseFunctions.h @@ -18,6 +18,8 @@ #pragma once +#include "BaseDefines.h" + //----------------------------------------------------------------------------- inline Real rad2deg(Real rad) { return rad * (180/PI); } inline Real deg2rad(Real rad) { return rad * (PI/180); } @@ -90,7 +92,7 @@ __forceinline float fast_float_ceil(float f) } // once we've ceiled/floored, trunc and round are identical, and currently, round is faster... (srj) -#if RTS_GENERALS /*&& RETAIL_COMPATIBLE_CRC*/ +#if RTS_GENERALS && RETAIL_COMPATIBLE_CRC #define REAL_TO_INT_CEIL(x) (fast_float2long_round(ceilf(x))) #define REAL_TO_INT_FLOOR(x) (fast_float2long_round(floorf(x))) #else diff --git a/Core/Libraries/Include/Lib/Coord2D.h b/Core/Libraries/Include/Lib/Coord2D.h index f3faa62aa66..8f6dc8c11be 100644 --- a/Core/Libraries/Include/Lib/Coord2D.h +++ b/Core/Libraries/Include/Lib/Coord2D.h @@ -18,6 +18,7 @@ #pragma once +#include "BaseDefines.h" #include "trig.h" // NOTE: Keep the types simple; avoid constructors and destructors so they can be used within unions @@ -134,7 +135,7 @@ inline Coord2D operator-( const Coord2D &a, const Coord2D &b ) inline Real Coord2D::toAngle() const { -#if RTS_GENERALS /*&& RETAIL_COMPATIBLE_CRC*/ +#if RTS_GENERALS && RETAIL_COMPATIBLE_CRC Coord2D vector; vector.x = x; diff --git a/Core/Libraries/Source/WWVegas/WWLib/WWDefines.h b/Core/Libraries/Source/WWVegas/WWLib/WWDefines.h index eb25d597db8..853a3716579 100644 --- a/Core/Libraries/Source/WWVegas/WWLib/WWDefines.h +++ b/Core/Libraries/Source/WWVegas/WWLib/WWDefines.h @@ -18,6 +18,8 @@ #pragma once +#include "Lib/BaseDefines.h" + // Enable translation and rotation interpolation for raw animation (HRawAnimClass) updates. // This was intentionally disabled in the retail version, but likely not fully thought through. // Interpolation is certainly desired for animations that move and rotate meshes, but may not be diff --git a/cmake/config-retail.cmake b/cmake/config-retail.cmake index a9e6a279326..c86e60b2d48 100644 --- a/cmake/config-retail.cmake +++ b/cmake/config-retail.cmake @@ -4,8 +4,12 @@ set(RTS_BUILD_OPTION_RETAIL_COMPATIBLE_GAME "DEFAULT" CACHE STRING "Build for re set_property(CACHE RTS_BUILD_OPTION_RETAIL_COMPATIBLE_GAME PROPERTY STRINGS DEFAULT ON OFF) collect_defines_from_file(_retail_guards "${CMAKE_CURRENT_SOURCE_DIR}/Core/GameEngine/Include/Common/GameDefines.h" "RETAIL_COMPATIBLE_") +collect_defines_from_file(_retail_base_guards "${CMAKE_CURRENT_SOURCE_DIR}/Core/Libraries/Include/Lib/BaseDefines.h" "RETAIL_COMPATIBLE_") +list(APPEND _retail_guards ${_retail_base_guards}) +list(REMOVE_DUPLICATES _retail_guards) define_tristate_option(RTS_BUILD_OPTION_RETAIL_COMPATIBLE_GAME RetailCompatibleGame "Build with Retail Compatibility" "${_retail_guards}" "") unset(_retail_guards) +unset(_retail_base_guards) if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "12.0.8804" AND NOT RTS_BUILD_OPTION_RETAIL_COMPATIBLE_GAME STREQUAL "OFF") message(NOTICE "") From 1b9d5e09bb3e090afbe37d797ef5e4e37d00f61e Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Mon, 14 Sep 2026 17:16:08 +0300 Subject: [PATCH 3/9] refactor(wwmath): Reorder and reformat WWMath functions (#2670) Moves the WWMath declarations and definitions into the layout used by the deterministic math entry points, so that the next commit only adds and changes functions in place. Merges the per-platform duplicate definitions into one body with the platform branches inside, moves the inline bodies of Fabs, Atan, Atan2, Ceil and Floor out of the class and drops the section banners. No functional change. --- Core/Libraries/Source/WWVegas/WWMath/wwmath.h | 695 ++++++++---------- 1 file changed, 320 insertions(+), 375 deletions(-) diff --git a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h index 8262f2732de..1f0f6e38466 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h +++ b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h @@ -46,12 +46,12 @@ */ #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_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_SQRT2 1.414213562f +#define WWMATH_SQRT3 1.732050808f #define WWMATH_OOSQRT2 0.707106781f #define WWMATH_OOSQRT3 0.577350269f @@ -74,7 +74,6 @@ #define DEG_TO_RADF(x) (((float)x)*WWMATH_PI/180.0f) #endif - const int ARC_TABLE_SIZE=1024; const int SIN_TABLE_SIZE=1024; extern float _FastAcosTable[ARC_TABLE_SIZE]; @@ -93,89 +92,338 @@ class WWMath // Initialization and Shutdown. Other math sub-systems which require initialization and // shutdown processing will be handled in these functions -static void Init(); -static void Shutdown(); +static void Init(); +static void Shutdown(); + +static WWINLINE float Sqrt(float val); +static WWINLINE float Inv_Sqrt(float a); + +static WWINLINE float Fast_Acos(float val); +static WWINLINE float Fast_Asin(float val); +static WWINLINE float Acos(float val); +static WWINLINE float Asin(float val); +static WWINLINE float Atan(float x); +static WWINLINE float Atan2(float y, float x); + +static WWINLINE float Fast_Cos(float val); +static WWINLINE float Fast_Inv_Cos(float val); +static WWINLINE float Fast_Sin(float val); +static WWINLINE float Fast_Inv_Sin(float val); +static WWINLINE float Cos(float val); +static WWINLINE float Sin(float val); + +static WWINLINE float Fabs(float val); + +static WWINLINE float Ceil(float val); +static WWINLINE float Floor(float val); +static WWINLINE float Round(float val) { return floorf(val + 0.5f); } +static WWINLINE float Sign(float val); + +static WWINLINE bool Fast_Is_Float_Positive(const float & val); +static WWINLINE bool Is_Power_Of_2(const unsigned int val); + +static float Random_Float(); + +static WWINLINE float Random_Float(float min,float max); +static WWINLINE float Clamp(float val, float min = 0.0f, float max = 1.0f); +static WWINLINE double Clamp(double val, double min = 0.0f, double max = 1.0f); +static WWINLINE int Clamp_Int(int val, int min_val, int max_val); +static WWINLINE float Wrap(float val, float min = 0.0f, float max = 1.0f); +static WWINLINE double Wrap(double val, double min = 0.0f, double max = 1.0f); +static WWINLINE float Min(float a, float b); +static WWINLINE float Max(float a, float b); + +// Linearly interpolates between a and b using parameter t in [0, 1]. +// t = 0 returns a, t = 1 returns b, values in between return a proportionate blend. +static WWINLINE float Lerp(float a, float b, float t); +static WWINLINE double Lerp(double a, double b, float t); + +// Computes the interpolation parameter t such that v = Lerp(a, b, t). +// Returns where v lies between a and b as a ratio, typically in [0, 1]. +static WWINLINE float Inverse_Lerp(float a, float b, float v); +static WWINLINE double Inverse_Lerp(double a, double b, float v); + +static WWINLINE bool Is_Valid_Float(float x); +static WWINLINE bool Is_Valid_Double(double x); + +static WWINLINE int Float_To_Int_Chop(const float& f); +static WWINLINE int Float_To_Int_Floor(const float& f); +static WWINLINE long Float_To_Long(float f); +static WWINLINE long Float_To_Long(double f); +static WWINLINE int Float_As_Int(const float f) { return *((int*)&f); } +static WWINLINE unsigned char Unit_Float_To_Byte(float f) { return (unsigned char)(f*255.0f); } +static WWINLINE float Byte_To_Unit_Float(unsigned char byte) { return ((float)byte) / 255.0f; } -// These are meant to be a collection of small math utility functions to be optimized at some point. -static WWINLINE float Fabs(float val) +static WWINLINE float Normalize_Angle(float angle); // Normalizes the angle to the range -PI..PI + +}; + +WWINLINE float WWMath::Sqrt(float val) { - int value=*(int*)&val; - value&=0x7fffffff; - return *(float*)&value; -} +#if defined(_MSC_VER) && defined(_M_IX86) + float retval; + __asm { + fld [val] + fsqrt + fstp [retval] + } + return retval; -static WWINLINE int Float_To_Int_Chop(const float& f); -static WWINLINE int Float_To_Int_Floor(const float& f); +#else + return (float)sqrt(val); +#endif +} +WWINLINE float WWMath::Inv_Sqrt(float a) +{ #if defined(_MSC_VER) && defined(_M_IX86) -static WWINLINE float Cos(float val); -static WWINLINE float Sin(float val); -static WWINLINE float Sqrt(float val); -static WWINLINE float Inv_Sqrt(float a); // Some 30% faster inverse square root than regular C++ compiled, from Intel's math library -static WWINLINE long Float_To_Long(float f); + // Some 30% faster inverse square root than regular C++ compiled, from Intel's math library + float retval; + + __asm { + mov eax, 0be6eb508h + mov DWORD PTR [esp-12],03fc00000h ; 1.5 on the stack + sub eax, DWORD PTR [a]; a + sub DWORD PTR [a], 800000h ; a/2 a=Y0 + shr eax, 1 ; firs approx in eax=R0 + mov DWORD PTR [esp-8], eax + + fld DWORD PTR [esp-8] ;r + fmul st, st ;r*r + fld DWORD PTR [esp-8] ;r + fxch st(1) + fmul DWORD PTR [a];a ;r*r*y0 + fld DWORD PTR [esp-12];load 1.5 + fld st(0) + fsub st,st(2) ;r1 = 1.5 - y1 + ;x1 = st(3) + ;y1 = st(2) + ;1.5 = st(1) + ;r1 = st(0) + + fld st(1) + fxch st(1) + fmul st(3),st ; y2=y1*r1*... + fmul st(3),st ; y2=y1*r1*r1 + fmulp st(4),st ; x2=x1*r1 + fsub st,st(2) ; r2=1.5-y2 + ;x2=st(3) + ;y2=st(2) + ;1.5=st(1) + ;r2 = st(0) + + fmul st(2),st ;y3=y2*r2*... + fmul st(3),st ;x3=x2*r2 + fmulp st(2),st ;y3=y2*r2*r2 + fxch st(1) + fsubp st(1),st ;r3= 1.5 - y3 + ;x3 = st(1) + ;r3 = st(0) + fmulp st(1), st + + fstp retval + } + + return retval; + #else -static WWINLINE float Cos(float val); -static WWINLINE float Sin(float val); -static WWINLINE float Sqrt(float val); -static WWINLINE float Inv_Sqrt(float a); -static WWINLINE long Float_To_Long(float f); + return 1.0f / (float)sqrt(a); #endif +} + +WWINLINE float WWMath::Fast_Acos(float val) +{ + // Near -1 and +1, the table becomes too inaccurate + if (Fabs(val) > 0.975f) { + return Acos(val); + } + + val*=float(ARC_TABLE_SIZE/2); + + int idx0=Float_To_Int_Floor(val); + int idx1=idx0+1; + float frac=val-(float)idx0; + idx0+=ARC_TABLE_SIZE/2; + idx1+=ARC_TABLE_SIZE/2; -static WWINLINE float Fast_Sin(float val); -static WWINLINE float Fast_Inv_Sin(float val); -static WWINLINE float Fast_Cos(float val); -static WWINLINE float Fast_Inv_Cos(float val); + // we dont even get close to the edge of the table... + assert((idx0 >= 0) && (idx0 < ARC_TABLE_SIZE)); + assert((idx1 >= 0) && (idx1 < ARC_TABLE_SIZE)); -static WWINLINE float Fast_Acos(float val); -static WWINLINE float Acos(float val); -static WWINLINE float Fast_Asin(float val); -static WWINLINE float Asin(float val); + // compute and return the interpolated value + return (1.0f - frac) * _FastAcosTable[idx0] + frac * _FastAcosTable[idx1]; +} +WWINLINE float WWMath::Fast_Asin(float val) +{ + // Near -1 and +1, the table becomes too inaccurate + if (Fabs(val) > 0.975f) { + return Asin(val); + } -static WWINLINE float Atan(float x) { return static_cast(atan(x)); } -static WWINLINE float Atan2(float y,float x) { return static_cast(atan2(y,x)); } -static WWINLINE float Sign(float val); -static WWINLINE float Ceil(float val) { return ceilf(val); } -static WWINLINE float Floor(float val) { return floorf(val); } -static WWINLINE float Round(float val) { return floorf(val + 0.5f); } -static WWINLINE bool Fast_Is_Float_Positive(const float & val); -static WWINLINE bool Is_Power_Of_2(const unsigned int val); + val*=float(ARC_TABLE_SIZE/2); -static float Random_Float(); + int idx0=Float_To_Int_Floor(val); + int idx1=idx0+1; + float frac=val-(float)idx0; -static WWINLINE float Random_Float(float min,float max); -static WWINLINE float Clamp(float val, float min = 0.0f, float max = 1.0f); -static WWINLINE double Clamp(double val, double min = 0.0f, double max = 1.0f); -static WWINLINE int Clamp_Int(int val, int min_val, int max_val); -static WWINLINE float Wrap(float val, float min = 0.0f, float max = 1.0f); -static WWINLINE double Wrap(double val, double min = 0.0f, double max = 1.0f); -static WWINLINE float Min(float a, float b); -static WWINLINE float Max(float a, float b); + idx0+=ARC_TABLE_SIZE/2; + idx1+=ARC_TABLE_SIZE/2; -static WWINLINE int Float_As_Int(const float f) { return *((int*)&f); } + // we dont even get close to the edge of the table... + assert((idx0 >= 0) && (idx0 < ARC_TABLE_SIZE)); + assert((idx1 >= 0) && (idx1 < ARC_TABLE_SIZE)); -// Linearly interpolates between a and b using parameter t in [0, 1]. -// t = 0 returns a, t = 1 returns b, values in between return a proportionate blend. -static WWINLINE float Lerp(float a, float b, float t); -static WWINLINE double Lerp(double a, double b, float t); + // compute and return the interpolated value + return (1.0f - frac) * _FastAsinTable[idx0] + frac * _FastAsinTable[idx1]; +} -// Computes the interpolation parameter t such that v = Lerp(a, b, t). -// Returns where v lies between a and b as a ratio, typically in [0, 1]. -static WWINLINE float Inverse_Lerp(float a, float b, float v); -static WWINLINE double Inverse_Lerp(double a, double b, float v); +WWINLINE float WWMath::Acos(float val) +{ + return (float)acos(val); +} -static WWINLINE long Float_To_Long(double f); +WWINLINE float WWMath::Asin(float val) +{ + return (float)asin(val); +} -static WWINLINE unsigned char Unit_Float_To_Byte(float f) { return (unsigned char)(f*255.0f); } -static WWINLINE float Byte_To_Unit_Float(unsigned char byte) { return ((float)byte) / 255.0f; } +WWINLINE float WWMath::Atan(float x) +{ + return static_cast(atan(x)); +} -static WWINLINE bool Is_Valid_Float(float x); -static WWINLINE bool Is_Valid_Double(double x); +WWINLINE float WWMath::Atan2(float y, float x) +{ + return static_cast(atan2(y,x)); +} -static WWINLINE float Normalize_Angle(float angle); // Normalizes the angle to the range -PI..PI +WWINLINE float WWMath::Fast_Cos(float val) +{ + val+=(WWMATH_PI * 0.5f); + val*=float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); -}; + int idx0=Float_To_Int_Floor(val); + int idx1=idx0+1; + float frac=val-(float)idx0; + + idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1); + idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1); + + return (1.0f - frac) * _FastSinTable[idx0] + frac * _FastSinTable[idx1]; +} + +WWINLINE float WWMath::Fast_Inv_Cos(float val) +{ +#if 0 // TODO: more testing, not reliable! + float index = val + (WWMATH_PI * 0.5f); + index *= float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); + + int idx0=Float_To_Int_Chop(index); + int idx1=idx0+1; + float frac=val-(float)idx0; + + idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1); + idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1); + + // The table becomes inaccurate near 0 and 2pi so fall back to doing a divide. + if ((idx0 <= 2) || (idx0 >= SIN_TABLE_SIZE-3)) { + return 1.0f / Fast_Cos(val); + } else { + return (1.0f - frac) * _FastInvSinTable[idx0] + frac * _FastInvSinTable[idx1]; + } +#else + return 1.0f / Fast_Cos(val); +#endif +} + +WWINLINE float WWMath::Fast_Sin(float val) +{ + val*=float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); + + int idx0=Float_To_Int_Floor(val); + int idx1=idx0+1; + float frac=val-(float)idx0; + + idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1); + idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1); + + return (1.0f - frac) * _FastSinTable[idx0] + frac * _FastSinTable[idx1]; +} + +WWINLINE float WWMath::Fast_Inv_Sin(float val) +{ +#if 0 // TODO: more testing, not reliable! + float index = val * float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); + + int idx0=Float_To_Int_Floor(index); + int idx1=idx0+1; + float frac=val-(float)idx0; + + idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1); + idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1); + + // The table becomes inaccurate near 0 and 2pi so fall back to doing a divide. + const int BUFFER = 16; + if ((idx0 <= BUFFER) || (idx0 >= SIN_TABLE_SIZE-BUFFER-1)) { + return 1.0f / Fast_Sin(val); + } else { + return (1.0f - frac) * _FastInvSinTable[idx0] + frac * _FastInvSinTable[idx1]; + } +#else + return 1.0f / Fast_Sin(val); +#endif +} + +WWINLINE float WWMath::Cos(float val) +{ +#if defined(_MSC_VER) && defined(_M_IX86) + float retval; + __asm { + fld [val] + fcos + fstp [retval] + } + return retval; + +#else + return cosf(val); +#endif +} + +WWINLINE float WWMath::Sin(float val) +{ +#if defined(_MSC_VER) && defined(_M_IX86) + float retval; + __asm { + fld [val] + fsin + fstp [retval] + } + return retval; + +#else + return sinf(val); +#endif +} + +WWINLINE float WWMath::Fabs(float val) +{ + int value=*(int*)&val; + value&=0x7fffffff; + return *(float*)&value; +} + +WWINLINE float WWMath::Ceil(float val) +{ + return ceilf(val); +} + +WWINLINE float WWMath::Floor(float val) +{ + return floorf(val); +} WWINLINE float WWMath::Sign(float val) { @@ -309,28 +557,20 @@ WWINLINE bool WWMath::Is_Valid_Double(double x) return true; } -// ---------------------------------------------------------------------------- -// Float to long -// ---------------------------------------------------------------------------- - -#if defined(_MSC_VER) && defined(_M_IX86) WWINLINE long WWMath::Float_To_Long(float f) { +#if defined(_MSC_VER) && defined(_M_IX86) long i; - __asm { fld [f] fistp [i] } - return i; -} + #else -WWINLINE long WWMath::Float_To_Long(float f) -{ - return (long) f; -} + return (long)f; #endif +} WWINLINE long WWMath::Float_To_Long(double f) { @@ -341,245 +581,12 @@ WWINLINE long WWMath::Float_To_Long(double f) fistp dword ptr [retval] } return retval; -#else - return (long) f; -#endif -} -// ---------------------------------------------------------------------------- -// Cos -// ---------------------------------------------------------------------------- - -#if defined(_MSC_VER) && defined(_M_IX86) -WWINLINE float WWMath::Cos(float val) -{ - float retval; - __asm { - fld [val] - fcos - fstp [retval] - } - return retval; -} #else -WWINLINE float WWMath::Cos(float val) -{ - return cosf(val); -} + return (long)f; #endif - -// ---------------------------------------------------------------------------- -// Sin -// ---------------------------------------------------------------------------- - -#if defined(_MSC_VER) && defined(_M_IX86) -WWINLINE float WWMath::Sin(float val) -{ - float retval; - __asm { - fld [val] - fsin - fstp [retval] - } - return retval; -} -#else -WWINLINE float WWMath::Sin(float val) -{ - return sinf(val); -} -#endif - -// ---------------------------------------------------------------------------- -// Fast, table based sin -// ---------------------------------------------------------------------------- - -WWINLINE float WWMath::Fast_Sin(float val) -{ - val*=float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); - - int idx0=Float_To_Int_Floor(val); - int idx1=idx0+1; - float frac=val-(float)idx0; - - idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1); - idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1); - - return (1.0f - frac) * _FastSinTable[idx0] + frac * _FastSinTable[idx1]; } -// ---------------------------------------------------------------------------- -// Fast, table based 1.0f/sin -// ---------------------------------------------------------------------------- - -WWINLINE float WWMath::Fast_Inv_Sin(float val) -{ -#if 0 // TODO: more testing, not reliable! - float index = val * float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); - - int idx0=Float_To_Int_Floor(index); - int idx1=idx0+1; - float frac=val-(float)idx0; - - idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1); - idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1); - - // The table becomes inaccurate near 0 and 2pi so fall back to doing a divide. - const int BUFFER = 16; - if ((idx0 <= BUFFER) || (idx0 >= SIN_TABLE_SIZE-BUFFER-1)) { - return 1.0f / WWMath::Fast_Sin(val); - } else { - return (1.0f - frac) * _FastInvSinTable[idx0] + frac * _FastInvSinTable[idx1]; - } -#else - return 1.0f / WWMath::Fast_Sin(val); -#endif -} - - -// ---------------------------------------------------------------------------- -// Fast, table based cos -// ---------------------------------------------------------------------------- - -WWINLINE float WWMath::Fast_Cos(float val) -{ - val+=(WWMATH_PI * 0.5f); - val*=float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); - - int idx0=Float_To_Int_Floor(val); - int idx1=idx0+1; - float frac=val-(float)idx0; - - idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1); - idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1); - - return (1.0f - frac) * _FastSinTable[idx0] + frac * _FastSinTable[idx1]; -} - -// ---------------------------------------------------------------------------- -// Fast, table based 1.0f/cos -// ---------------------------------------------------------------------------- - -WWINLINE float WWMath::Fast_Inv_Cos(float val) -{ -#if 0 // TODO: more testing, not reliable! - float index = val + (WWMATH_PI * 0.5f); - index *= float(SIN_TABLE_SIZE) / (2.0f * WWMATH_PI); - - int idx0=Float_To_Int_Chop(index); - int idx1=idx0+1; - float frac=val-(float)idx0; - - idx0 = ((unsigned)idx0) & (SIN_TABLE_SIZE-1); - idx1 = ((unsigned)idx1) & (SIN_TABLE_SIZE-1); - - // The table becomes inaccurate near 0 and 2pi so fall back to doing a divide. - if ((idx0 <= 2) || (idx0 >= SIN_TABLE_SIZE-3)) { - return 1.0f / WWMath::Fast_Cos(val); - } else { - return (1.0f - frac) * _FastInvSinTable[idx0] + frac * _FastInvSinTable[idx1]; - } -#else - return 1.0f / WWMath::Fast_Cos(val); -#endif -} - -// ---------------------------------------------------------------------------- -// Fast, table based arc cos -// ---------------------------------------------------------------------------- - -WWINLINE float WWMath::Fast_Acos(float val) -{ - // Near -1 and +1, the table becomes too inaccurate - if (WWMath::Fabs(val) > 0.975f) { - return WWMath::Acos(val); - } - - val*=float(ARC_TABLE_SIZE/2); - - int idx0=Float_To_Int_Floor(val); - int idx1=idx0+1; - float frac=val-(float)idx0; - - idx0+=ARC_TABLE_SIZE/2; - idx1+=ARC_TABLE_SIZE/2; - - // we dont even get close to the edge of the table... - assert((idx0 >= 0) && (idx0 < ARC_TABLE_SIZE)); - assert((idx1 >= 0) && (idx1 < ARC_TABLE_SIZE)); - - // compute and return the interpolated value - return (1.0f - frac) * _FastAcosTable[idx0] + frac * _FastAcosTable[idx1]; -} - -// ---------------------------------------------------------------------------- -// Arc cos -// ---------------------------------------------------------------------------- - -WWINLINE float WWMath::Acos(float val) -{ - return (float)acos(val); -} - -// ---------------------------------------------------------------------------- -// Fast, table based arc sin -// ---------------------------------------------------------------------------- - -WWINLINE float WWMath::Fast_Asin(float val) -{ - // Near -1 and +1, the table becomes too inaccurate - if (WWMath::Fabs(val) > 0.975f) { - return WWMath::Asin(val); - } - - val*=float(ARC_TABLE_SIZE/2); - - int idx0=Float_To_Int_Floor(val); - int idx1=idx0+1; - float frac=val-(float)idx0; - - idx0+=ARC_TABLE_SIZE/2; - idx1+=ARC_TABLE_SIZE/2; - - // we dont even get close to the edge of the table... - assert((idx0 >= 0) && (idx0 < ARC_TABLE_SIZE)); - assert((idx1 >= 0) && (idx1 < ARC_TABLE_SIZE)); - - // compute and return the interpolated value - return (1.0f - frac) * _FastAsinTable[idx0] + frac * _FastAsinTable[idx1]; -} - -// ---------------------------------------------------------------------------- -// Arc sin -// ---------------------------------------------------------------------------- - -WWINLINE float WWMath::Asin(float val) -{ - return (float)asin(val); -} - -// ---------------------------------------------------------------------------- -// Sqrt -// ---------------------------------------------------------------------------- - -#if defined(_MSC_VER) && defined(_M_IX86) -WWINLINE float WWMath::Sqrt(float val) -{ - float retval; - __asm { - fld [val] - fsqrt - fstp [retval] - } - return retval; -} -#else -WWINLINE float WWMath::Sqrt(float val) -{ - return (float)sqrt(val); -} -#endif - WWINLINE int WWMath::Float_To_Int_Chop(const float& f) { int a = *reinterpret_cast(&f); // take bit pattern of float into a register @@ -590,7 +597,7 @@ WWINLINE int WWMath::Float_To_Int_Chop(const float& f) return ((r ^ (sign)) - sign ) &~ (exponent>>31); // add original sign. If exponent was negative, make return value 0. } -WWINLINE int WWMath::Float_To_Int_Floor (const float& f) +WWINLINE int WWMath::Float_To_Int_Floor(const float& f) { int a = *reinterpret_cast(&f); // take bit pattern of float into a register int sign = (a>>31); // sign = 0xFFFFFFFF if original value is negative, 0 if positive @@ -606,68 +613,6 @@ WWINLINE int WWMath::Float_To_Int_Floor (const float& f) return r; } -// ---------------------------------------------------------------------------- -// Inverse square root -// ---------------------------------------------------------------------------- - -#if defined(_MSC_VER) && defined(_M_IX86) -WWINLINE float WWMath::Inv_Sqrt(float a) -{ - float retval; - - __asm { - mov eax, 0be6eb508h - mov DWORD PTR [esp-12],03fc00000h ; 1.5 on the stack - sub eax, DWORD PTR [a]; a - sub DWORD PTR [a], 800000h ; a/2 a=Y0 - shr eax, 1 ; firs approx in eax=R0 - mov DWORD PTR [esp-8], eax - - fld DWORD PTR [esp-8] ;r - fmul st, st ;r*r - fld DWORD PTR [esp-8] ;r - fxch st(1) - fmul DWORD PTR [a];a ;r*r*y0 - fld DWORD PTR [esp-12];load 1.5 - fld st(0) - fsub st,st(2) ;r1 = 1.5 - y1 - ;x1 = st(3) - ;y1 = st(2) - ;1.5 = st(1) - ;r1 = st(0) - - fld st(1) - fxch st(1) - fmul st(3),st ; y2=y1*r1*... - fmul st(3),st ; y2=y1*r1*r1 - fmulp st(4),st ; x2=x1*r1 - fsub st,st(2) ; r2=1.5-y2 - ;x2=st(3) - ;y2=st(2) - ;1.5=st(1) - ;r2 = st(0) - - fmul st(2),st ;y3=y2*r2*... - fmul st(3),st ;x3=x2*r2 - fmulp st(2),st ;y3=y2*r2*r2 - fxch st(1) - fsubp st(1),st ;r3= 1.5 - y3 - ;x3 = st(1) - ;r3 = st(0) - fmulp st(1), st - - fstp retval - } - - return retval; -} -#else -WWINLINE float WWMath::Inv_Sqrt(float val) -{ - return 1.0f / (float)sqrt(val); -} -#endif - WWINLINE float WWMath::Normalize_Angle(float angle) { return angle - (WWMATH_TWO_PI * Floor((angle + WWMATH_PI) / WWMATH_TWO_PI)); From 639975ba73b8340f4feac6d9d391897ebe4e8d61 Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Wed, 23 Sep 2026 13:34:24 +0300 Subject: [PATCH 4/9] feat(wwmath): Add deterministic math entry points (#2670) Adds the WWMath wrappers that dispatch between the deterministic gamemath implementation and the platform libm, plus the _Legacy variants used by rendering code that must stay outside the simulation. Adds WWMath::Div_Safe, which clamps the divisor to an epsilon under deterministic math. Routes the Trig.cpp functions through WWMath, adds Sqrt(Real) and Sqrt(double) there and drops the unused REGENERATE_TRIG_TABLES generator. Coord3D::length() keeps the original sqrt call under RETAIL_COMPATIBLE_CRC. Existing callers of the changed functions move to the _Legacy and float variants in this commit, so retail behaviour holds between commits. --- .../Common/Diagnostic/SimulationMathCrc.cpp | 4 +- .../GameClient/MessageStream/LookAtXlat.cpp | 2 +- .../GameClient/CameraShakeSystem.cpp | 2 +- .../GameClient/Drawable/Draw/W3DTankDraw.cpp | 4 +- .../Drawable/Draw/W3DTankTruckDraw.cpp | 4 +- .../Source/W3DDevice/GameClient/HeightMap.cpp | 4 +- .../W3DDevice/GameClient/W3DParticleSys.cpp | 6 +- .../GameClient/W3DProfilerFrameCapture.cpp | 2 +- .../W3DDevice/GameClient/W3DTreeBuffer.cpp | 8 +- Core/Libraries/Include/Lib/Coord2D.h | 4 +- Core/Libraries/Include/Lib/Coord3D.h | 13 +- Core/Libraries/Include/Lib/ICoord2D.h | 2 +- Core/Libraries/Include/Lib/ICoord3D.h | 2 +- Core/Libraries/Include/Lib/trig.h | 2 + .../Source/WWVegas/WW3D2/animatedsoundmgr.cpp | 2 +- .../Source/WWVegas/WW3D2/colorspace.h | 2 +- .../Source/WWVegas/WW3D2/coltest.cpp | 20 +- Core/Libraries/Source/WWVegas/WW3D2/hanim.cpp | 4 +- Core/Libraries/Source/WWVegas/WW3D2/htree.cpp | 6 +- Core/Libraries/Source/WWVegas/WW3D2/inttest.h | 12 +- .../Source/WWVegas/WW3D2/metalmap.cpp | 6 +- .../Source/WWVegas/WW3D2/ringobj.cpp | 4 +- .../Source/WWVegas/WW3D2/segline.cpp | 2 +- .../Source/WWVegas/WW3D2/shattersystem.cpp | 2 +- .../Libraries/Source/WWVegas/WW3D2/streak.cpp | 2 +- .../Source/WWVegas/WW3D2/texproject.cpp | 6 +- .../Source/WWVegas/WW3D2/visrasterizer.cpp | 12 +- .../Source/WWVegas/WWMath/CMakeLists.txt | 4 + Core/Libraries/Source/WWVegas/WWMath/aabox.h | 2 +- .../Source/WWVegas/WWMath/colmathaabox.cpp | 24 +- .../Source/WWVegas/WWMath/colmathaabox.h | 12 +- .../Source/WWVegas/WWMath/colmathaabtri.cpp | 60 +- .../Source/WWVegas/WWMath/colmathobbobb.cpp | 130 ++-- .../Source/WWVegas/WWMath/colmathobbox.cpp | 6 +- .../Source/WWVegas/WWMath/colmathobbtri.cpp | 62 +- .../Source/WWVegas/WWMath/colmathsphere.cpp | 12 +- .../Libraries/Source/WWVegas/WWMath/euler.cpp | 8 +- .../Source/WWVegas/WWMath/lookuptable.h | 2 +- .../Source/WWVegas/WWMath/matrix3.cpp | 6 +- .../Libraries/Source/WWVegas/WWMath/matrix3.h | 6 +- .../Source/WWVegas/WWMath/matrix3d.cpp | 8 +- .../Source/WWVegas/WWMath/matrix3d.h | 2 +- .../Libraries/Source/WWVegas/WWMath/obbox.cpp | 16 +- Core/Libraries/Source/WWVegas/WWMath/obbox.h | 20 +- Core/Libraries/Source/WWVegas/WWMath/quat.cpp | 32 +- Core/Libraries/Source/WWVegas/WWMath/quat.h | 8 +- Core/Libraries/Source/WWVegas/WWMath/tri.cpp | 18 +- .../Source/WWVegas/WWMath/v3_rnd.cpp | 2 +- .../Libraries/Source/WWVegas/WWMath/vector2.h | 14 +- .../Libraries/Source/WWVegas/WWMath/vector3.h | 16 +- .../Libraries/Source/WWVegas/WWMath/vector4.h | 4 +- .../Source/WWVegas/WWMath/vehiclecurve.cpp | 38 +- .../Source/WWVegas/WWMath/wwmath.cpp | 9 + Core/Libraries/Source/WWVegas/WWMath/wwmath.h | 567 ++++++++++++++++-- Core/Tools/W3DView/RingSizePropPage.cpp | 2 +- Core/Tools/W3DView/SphereSizePropPage.cpp | 2 +- .../GameEngine/Source/Common/System/Trig.cpp | 121 +--- .../GameEngine/Source/GameClient/InGameUI.cpp | 2 +- .../GameClient/Shadow/W3DVolumetricShadow.cpp | 12 +- .../W3DDevice/GameClient/W3DAssetManager.cpp | 12 +- .../Libraries/Source/WWVegas/WW3D2/camera.cpp | 4 +- .../Libraries/Source/WWVegas/WW3D2/mapper.cpp | 26 +- .../Source/WWVegas/WW3D2/motchan.cpp | 2 +- .../Source/WWVegas/WW3D2/part_emt.cpp | 2 +- .../Source/WWVegas/WW3D2/render2d.cpp | 4 +- .../WorldBuilder/src/GlobalLightOptions.cpp | 12 +- .../GameEngine/Source/Common/System/Trig.cpp | 121 +--- .../GameEngine/Source/GameClient/InGameUI.cpp | 2 +- .../GameClient/Shadow/W3DVolumetricShadow.cpp | 18 +- .../W3DDevice/GameClient/W3DAssetManager.cpp | 12 +- .../Libraries/Source/WWVegas/WW3D2/camera.cpp | 4 +- .../Source/WWVegas/WW3D2/lightenvironment.cpp | 2 +- .../Source/WWVegas/WW3D2/linegrp.cpp | 6 +- .../Libraries/Source/WWVegas/WW3D2/mapper.cpp | 18 +- .../Source/WWVegas/WW3D2/motchan.cpp | 2 +- .../Source/WWVegas/WW3D2/part_emt.cpp | 2 +- .../Source/WWVegas/WW3D2/render2d.cpp | 4 +- .../WorldBuilder/src/GlobalLightOptions.cpp | 12 +- 78 files changed, 965 insertions(+), 666 deletions(-) diff --git a/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp b/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp index 1b062f44e34..b40f0487b65 100644 --- a/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp +++ b/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp @@ -37,8 +37,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::Sinf(0.7f) * log10f(2.3f), + WWMath::Cosf(1.1f) * powf(1.1f, 2.0f), tanf(0.3f), asinf(0.967302263f), acosf(0.967302263f), diff --git a/Core/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp b/Core/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp index b4ef8bfdbbb..9bc70024463 100644 --- a/Core/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp +++ b/Core/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp @@ -374,7 +374,7 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage if (TheInGameUI->isInForceAttackMode()) { const Real snapRadians = DEG_TO_RADF(45); - targetAngle = WWMath::Round(targetAngle / snapRadians) * snapRadians; + targetAngle = WWMath::Roundf(targetAngle / snapRadians) * snapRadians; } TheTacticalView->userSetAngle(targetAngle); diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/CameraShakeSystem.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/CameraShakeSystem.cpp index 2d14980637c..195ffdbd762 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/CameraShakeSystem.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/CameraShakeSystem.cpp @@ -162,7 +162,7 @@ void CameraShakeSystemClass::CameraShakerClass::Compute_Rotations(const Vector3 float intensity = Intensity * (1.0f - WWMath::Sqrt(len2) / Radius) * (1.0f - ElapsedTime / Duration); for (int i=0; i<3; i++) { float omega = Omega[i] + (END_OMEGA - Omega[i]) * ElapsedTime; - (*set_angles)[i] += AXIS_ROTATION[i] * intensity * WWMath::Sin(omega * ElapsedTime + Phi[i]); + (*set_angles)[i] += AXIS_ROTATION[i] * intensity * WWMath::Sinf_Legacy(omega * ElapsedTime + Phi[i]); //WST 11/14/2002. Add in additional random fudge. There seems to be a too mathematical pattern of shake with the above Vector3 secondary_angles; diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankDraw.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankDraw.cpp index afdc6ca06c5..1a7251b2512 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankDraw.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankDraw.cpp @@ -224,7 +224,7 @@ void W3DTankDraw::updateTreadPositions(Real uvDelta) } // ensure coordinates of offset are in [0, 1] range: - offset_u = offset_u - WWMath::Floor(offset_u); + offset_u = offset_u - WWMath::Floorf(offset_u); pTread->m_materialSettings.customUVOffset.Set(offset_u,0); pTread++; } @@ -400,7 +400,7 @@ void W3DTankDraw::doDrawModule(const Matrix3D* transformMtx) { offset_u = pTread->m_materialSettings.customUVOffset.X - treadScrollSpeed; // ensure coordinates of offset are in [0, 1] range: - offset_u = offset_u - WWMath::Floor(offset_u); + offset_u = offset_u - WWMath::Floorf(offset_u); pTread->m_materialSettings.customUVOffset.Set(offset_u,0); pTread++; } diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankTruckDraw.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankTruckDraw.cpp index 783d6d089ae..710d834a1ee 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankTruckDraw.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankTruckDraw.cpp @@ -403,7 +403,7 @@ void W3DTankTruckDraw::updateTreadPositions(Real uvDelta) } // ensure coordinates of offset are in [0, 1] range: - offset_u = offset_u - WWMath::Floor(offset_u); + offset_u = offset_u - WWMath::Floorf(offset_u); pTread->m_materialSettings.customUVOffset.Set(offset_u,0); pTread++; } @@ -722,7 +722,7 @@ void W3DTankTruckDraw::doDrawModule(const Matrix3D* transformMtx) { offset_u = pTread->m_materialSettings.customUVOffset.X - treadScrollSpeed; // ensure coordinates of offset are in [0, 1] range: - offset_u = offset_u - WWMath::Floor(offset_u); + offset_u = offset_u - WWMath::Floorf(offset_u); pTread->m_materialSettings.customUVOffset.Set(offset_u,0); pTread++; } diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp index cea9b8e7275..4e3327fa5e9 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp @@ -1773,8 +1773,8 @@ void HeightMapRenderObjClass::updateCenter(CameraClass *camera, const Vector3 *c shiftPivot.X = viewDir.X * magicEdgeLenScale; shiftPivot.Y = viewDir.Y * magicEdgeLenScale; - newOrgX = WWMath::Round((cameraPivot->X + shiftPivot.X)/MAP_XY_FACTOR) - m_x/2 + m_map->getBorderSizeInline(); - newOrgY = WWMath::Round((cameraPivot->Y + shiftPivot.Y)/MAP_XY_FACTOR) - m_y/2 + m_map->getBorderSizeInline(); + newOrgX = WWMath::Roundf((cameraPivot->X + shiftPivot.X)/MAP_XY_FACTOR) - m_x/2 + m_map->getBorderSizeInline(); + newOrgY = WWMath::Roundf((cameraPivot->Y + shiftPivot.Y)/MAP_XY_FACTOR) - m_y/2 + m_map->getBorderSizeInline(); } WorldHeightMap::DrawArea newDrawArea = m_map->createDrawArea(newOrgX, newOrgY); diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp index c8c42484305..08713b76fc9 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp @@ -177,9 +177,9 @@ void W3DParticleSystemManager::doParticles(RenderInfoClass &rinfo) const Real psize = vp->getSize(); //Test if particle is at the screen or terrain edges. - if (WWMath::Fabs(pos->x - bcX) > (beX + psize) || - WWMath::Fabs(pos->y - bcY) > (beY + psize) || - WWMath::Fabs(pos->z - bcZ) > (beZ + psize)) + if (WWMath::Fabsf_Legacy(pos->x - bcX) > (beX + psize) || + WWMath::Fabsf_Legacy(pos->y - bcY) > (beY + psize) || + WWMath::Fabsf_Legacy(pos->z - bcZ) > (beZ + psize)) { vp->setIsCulled(true); continue; diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DProfilerFrameCapture.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DProfilerFrameCapture.cpp index baef20751b4..4c2f9b40a39 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DProfilerFrameCapture.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DProfilerFrameCapture.cpp @@ -95,7 +95,7 @@ void W3DProfilerFrameCapture::Capture(UnsignedInt displayWidth, UnsignedInt disp // allocate surface class const Real aspectRatio = (Real)displayHeight / (Real)displayWidth; - unsigned int profilerImageHeight = min((int)WWMath::Round(PROFILER_FRAME_IMAGE_SIZE * aspectRatio), PROFILER_FRAME_IMAGE_SIZE); + unsigned int profilerImageHeight = min((int)WWMath::Roundf(PROFILER_FRAME_IMAGE_SIZE * aspectRatio), PROFILER_FRAME_IMAGE_SIZE); SurfaceClass *surfaceClass = NEW_REF(SurfaceClass, (PROFILER_FRAME_IMAGE_SIZE, profilerImageHeight, WW3D_FORMAT_A8R8G8B8)); if (!surfaceClass) { diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp index 1e214b9fb50..43418f3120f 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp @@ -1353,8 +1353,8 @@ void W3DTreeBuffer::addTree(DrawableID id, Coord3D location, Real scale, Real an } Real randomScale = GameClientRandomValueReal( 1.0f - randomScaleAmount, 1.0f+ randomScaleAmount ); - m_trees[m_numTrees].sin = WWMath::Sin(angle); - m_trees[m_numTrees].cos = WWMath::Cos(angle); + m_trees[m_numTrees].sin = WWMath::Sinf_Legacy(angle); + m_trees[m_numTrees].cos = WWMath::Cosf_Legacy(angle); if (randomScaleAmount>0.0f) { // Randomizes the scale and orientation of trees. m_trees[m_numTrees].scale = scale*randomScale; @@ -1398,8 +1398,8 @@ Bool W3DTreeBuffer::updateTreePosition(DrawableID id, Coord3D location, Real ang for (i=0; i MOVE_THRESHOLD) { +// if (WWMath::Fabsf(Move.X) + WWMath::Fabsf(Move.Y) + WWMath::Fabsf(Move.Z) > MOVE_THRESHOLD) { // CastResultStruct res; // return !Box.Cast_To_Box(Move,box,&res); // } else { @@ -287,17 +287,17 @@ OBBoxCollisionTestClass::OBBoxCollisionTestClass Move(move) { Vector3 max_extent; - max_extent.X = WWMath::Fabs(Box.Basis[0][0] * Box.Extent.X) + - WWMath::Fabs(Box.Basis[0][1] * Box.Extent.Y) + - WWMath::Fabs(Box.Basis[0][2] * Box.Extent.Z) + 0.01f; + max_extent.X = WWMath::Fabsf_Legacy(Box.Basis[0][0] * Box.Extent.X) + + WWMath::Fabsf_Legacy(Box.Basis[0][1] * Box.Extent.Y) + + WWMath::Fabsf_Legacy(Box.Basis[0][2] * Box.Extent.Z) + 0.01f; - max_extent.Y = WWMath::Fabs(Box.Basis[1][0] * Box.Extent.X) + - WWMath::Fabs(Box.Basis[1][1] * Box.Extent.Y) + - WWMath::Fabs(Box.Basis[1][2] * Box.Extent.Z) + 0.01f; + max_extent.Y = WWMath::Fabsf_Legacy(Box.Basis[1][0] * Box.Extent.X) + + WWMath::Fabsf_Legacy(Box.Basis[1][1] * Box.Extent.Y) + + WWMath::Fabsf_Legacy(Box.Basis[1][2] * Box.Extent.Z) + 0.01f; - max_extent.Z = WWMath::Fabs(Box.Basis[2][0] * Box.Extent.X) + - WWMath::Fabs(Box.Basis[2][1] * Box.Extent.Y) + - WWMath::Fabs(Box.Basis[2][2] * Box.Extent.Z) + 0.01f; + max_extent.Z = WWMath::Fabsf_Legacy(Box.Basis[2][0] * Box.Extent.X) + + WWMath::Fabsf_Legacy(Box.Basis[2][1] * Box.Extent.Y) + + WWMath::Fabsf_Legacy(Box.Basis[2][2] * Box.Extent.Z) + 0.01f; SweepMin = Box.Center - max_extent; SweepMax = Box.Center + max_extent; diff --git a/Core/Libraries/Source/WWVegas/WW3D2/hanim.cpp b/Core/Libraries/Source/WWVegas/WW3D2/hanim.cpp index a5430b62c8e..25265bfd9fd 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/hanim.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/hanim.cpp @@ -304,7 +304,7 @@ bool HAnimComboClass::Normalize_Weights() } // weight_total should be very close to 1. If not, normalize this pivot's weights - if (weight_total != 0.0 && WWMath::Fabs( weight_total - 1.0 ) > WWMATH_EPSILON) { + if (weight_total != 0.0 && WWMath::Fabsf_Legacy( weight_total - 1.0 ) > WWMATH_EPSILON) { float oo_total = 1.0f / weight_total; for (anim_idx = 0; anim_idx < anim_count; anim_idx++ ) { if (Peek_Motion(anim_idx) != nullptr ) { @@ -329,7 +329,7 @@ bool HAnimComboClass::Normalize_Weights() } // weight_total should be very close to 1. If not, normalize this pivot's weights - if (weight_total != 0.0 && WWMath::Fabs( weight_total - 1.0 ) > WWMATH_EPSILON) { + if (weight_total != 0.0 && WWMath::Fabsf_Legacy( weight_total - 1.0 ) > WWMATH_EPSILON) { float oo_total = 1.0f / weight_total; for (anim_idx = 0; anim_idx < anim_count; anim_idx++ ) { if (Peek_Motion(anim_idx) != nullptr ) { diff --git a/Core/Libraries/Source/WWVegas/WW3D2/htree.cpp b/Core/Libraries/Source/WWVegas/WW3D2/htree.cpp index 8e3d2a095f5..75f9496dd10 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/htree.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/htree.cpp @@ -867,7 +867,7 @@ void HTreeClass::Combo_Update if (weight_total != 0.0f ) { // SKB: Removed assert because I have a case where I don't want normalization. // One anim moves X, the other moves Y. Assert was just in to warn programmers. -// WWASSERT(WWMath::Fabs( weight_total - 1.0 ) < WWMATH_EPSILON); +// WWASSERT(WWMath::Fabsf( weight_total - 1.0 ) < WWMATH_EPSILON); pivot->Transform.Translate(trans); #ifdef ALLOW_TEMPORARIES @@ -1217,8 +1217,8 @@ HTreeClass * HTreeClass::Create_Interpolated(const HTreeClass * tree_base, // Clone the first one, HTreeClass * new_tree = W3DNEW HTreeClass( *tree_base ); - float a_scale_abs = WWMath::Fabs( a_scale ); - float b_scale_abs = WWMath::Fabs( b_scale ); + float a_scale_abs = WWMath::Fabsf_Legacy( a_scale ); + float b_scale_abs = WWMath::Fabsf_Legacy( b_scale ); if ( a_scale_abs + b_scale_abs > 0 ) { diff --git a/Core/Libraries/Source/WWVegas/WW3D2/inttest.h b/Core/Libraries/Source/WWVegas/WW3D2/inttest.h index de97249bcd1..005552f7b5d 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/inttest.h +++ b/Core/Libraries/Source/WWVegas/WW3D2/inttest.h @@ -127,9 +127,9 @@ inline bool AABoxIntersectionTestClass::Cull(const AABoxClass & cull_box) Vector3::Subtract(cull_box.Center,Box.Center,&dc); Vector3::Add(cull_box.Extent,Box.Extent,&r); - if (WWMath::Fabs(dc.X) > r.X) return true; - if (WWMath::Fabs(dc.Y) > r.Y) return true; - if (WWMath::Fabs(dc.Z) > r.Z) return true; + if (WWMath::Fabsf_Legacy(dc.X) > r.X) return true; + if (WWMath::Fabsf_Legacy(dc.Y) > r.Y) return true; + if (WWMath::Fabsf_Legacy(dc.Z) > r.Z) return true; return false; } @@ -228,9 +228,9 @@ inline bool OBBoxIntersectionTestClass::Cull(const AABoxClass & cull_box) Vector3::Subtract(cull_box.Center,BoundingBox.Center,&dc); Vector3::Add(cull_box.Extent,BoundingBox.Extent,&r); - if (WWMath::Fabs(dc.X) > r.X) return true; - if (WWMath::Fabs(dc.Y) > r.Y) return true; - if (WWMath::Fabs(dc.Z) > r.Z) return true; + if (WWMath::Fabsf_Legacy(dc.X) > r.X) return true; + if (WWMath::Fabsf_Legacy(dc.Y) > r.Y) return true; + if (WWMath::Fabsf_Legacy(dc.Z) > r.Z) return true; return false; } diff --git a/Core/Libraries/Source/WWVegas/WW3D2/metalmap.cpp b/Core/Libraries/Source/WWVegas/WW3D2/metalmap.cpp index 48f5f08199e..488668b6527 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/metalmap.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/metalmap.cpp @@ -316,9 +316,9 @@ void MetalMapManagerClass::Update_Textures() result.Update_Min(white); // Clamp to white unsigned char b,g,r,a; - b= (unsigned char)WWMath::Floor(result.Z * 255.99f); // B - g= (unsigned char)WWMath::Floor(result.Y * 255.99f); // G - r= (unsigned char)WWMath::Floor(result.X * 255.99f); // R + b= (unsigned char)WWMath::Floorf(result.Z * 255.99f); // B + g= (unsigned char)WWMath::Floorf(result.Y * 255.99f); // G + r= (unsigned char)WWMath::Floorf(result.X * 255.99f); // R a= 0xFF; // A if (Use16Bit) { diff --git a/Core/Libraries/Source/WWVegas/WW3D2/ringobj.cpp b/Core/Libraries/Source/WWVegas/WW3D2/ringobj.cpp index e82c97476ca..fac9c2c054b 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/ringobj.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/ringobj.cpp @@ -1536,8 +1536,8 @@ void RingMeshClass::Generate(float radius, int slices) for (index = 0; index < Vertex_ct; index += 2) { - float x_pos = -WWMath::Sin (angle); - float y_pos = WWMath::Cos (angle); + float x_pos = -WWMath::Sinf_Legacy (angle); + float y_pos = WWMath::Cosf_Legacy (angle); // // Place the inner index diff --git a/Core/Libraries/Source/WWVegas/WW3D2/segline.cpp b/Core/Libraries/Source/WWVegas/WW3D2/segline.cpp index 9ae92675552..4c66ee6dcc3 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/segline.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/segline.cpp @@ -258,7 +258,7 @@ void SegmentedLineClass::Set_Opacity(float opacity) void SegmentedLineClass::Set_Noise_Amplitude(float amplitude) { - LineRenderer.Set_Noise_Amplitude(WWMath::Fabs(amplitude)); + LineRenderer.Set_Noise_Amplitude(WWMath::Fabsf_Legacy(amplitude)); Invalidate_Cached_Bounding_Volumes(); } diff --git a/Core/Libraries/Source/WWVegas/WW3D2/shattersystem.cpp b/Core/Libraries/Source/WWVegas/WW3D2/shattersystem.cpp index acec59e22ab..3538d143055 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/shattersystem.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/shattersystem.cpp @@ -450,7 +450,7 @@ void PolygonClass::Compute_Plane() ay /= (double)NumVerts; az /= (double)NumVerts; - double len = WWMath::Sqrt(nx*nx + ny*ny + nz*nz); + double len = WWMath::Sqrt((float)(nx*nx + ny*ny + nz*nz)); nx /= len; ny /= len; nz /= len; diff --git a/Core/Libraries/Source/WWVegas/WW3D2/streak.cpp b/Core/Libraries/Source/WWVegas/WW3D2/streak.cpp index 9ae04a398b5..05c3dc1ad72 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/streak.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/streak.cpp @@ -358,7 +358,7 @@ void StreakLineClass::Set_Opacity(float opacity) void StreakLineClass::Set_Noise_Amplitude(float amplitude) { - LineRenderer.Set_Noise_Amplitude(WWMath::Fabs(amplitude)); + LineRenderer.Set_Noise_Amplitude(WWMath::Fabsf_Legacy(amplitude)); Invalidate_Cached_Bounding_Volumes(); } diff --git a/Core/Libraries/Source/WWVegas/WW3D2/texproject.cpp b/Core/Libraries/Source/WWVegas/WW3D2/texproject.cpp index 38b5137398d..6fc1ccb5f78 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/texproject.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/texproject.cpp @@ -939,7 +939,7 @@ bool TexProjectClass::Compute_Perspective_Projection ** If the box is behind the viewpoint or the viewpoint is inside the box ** our FOV will be > 180 degrees. Have to give up */ - if ((box.Center.Z > 0.0f) || (box.Extent.Z > WWMath::Fabs(box.Center.Z))) { + if ((box.Center.Z > 0.0f) || (box.Extent.Z > WWMath::Fabsf_Legacy(box.Center.Z))) { return false; } @@ -957,8 +957,8 @@ bool TexProjectClass::Compute_Perspective_Projection zfar = box.Center.Z + user_zfar; } - float tan_hfov2 = WWMath::Fabs(box.Extent.X / (box.Center.Z + box.Extent.Z)); - float tan_vfov2 = WWMath::Fabs(box.Extent.Y / (box.Center.Z + box.Extent.Z)); + float tan_hfov2 = WWMath::Fabsf_Legacy(box.Extent.X / (box.Center.Z + box.Extent.Z)); + float tan_vfov2 = WWMath::Fabsf_Legacy(box.Extent.Y / (box.Center.Z + box.Extent.Z)); float hfov = 2.0f * WWMath::Atan(tan_hfov2); float vfov = 2.0f * WWMath::Atan(tan_vfov2); diff --git a/Core/Libraries/Source/WWVegas/WW3D2/visrasterizer.cpp b/Core/Libraries/Source/WWVegas/WW3D2/visrasterizer.cpp index ac61acc0257..a86abe5f2f2 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/visrasterizer.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/visrasterizer.cpp @@ -476,8 +476,8 @@ struct EdgeStruct { EdgeStruct(const GradientsStruct & grad,const Vector3 * verts,int top,int bottom) { - Y = WWMath::Ceil(verts[top].Y); - Height = WWMath::Ceil(verts[bottom].Y) - Y; + Y = WWMath::Ceilf(verts[top].Y); + Height = WWMath::Ceilf(verts[bottom].Y) - Y; float y_prestep = Y - verts[top].Y; float real_height = verts[bottom].Y - verts[top].Y; @@ -654,8 +654,8 @@ int IDBufferClass::Render_Occluder_Scanline(GradientsStruct & grads,EdgeStruct * return 0; } - int xstart = WWMath::Float_To_Long(WWMath::Max(WWMath::Ceil(left->X),1.0f)); - int width = WWMath::Float_To_Long(WWMath::Ceil(right->X)) - xstart; + int xstart = WWMath::Float_To_Long(WWMath::Max(WWMath::Ceilf(left->X),1.0f)); + int width = WWMath::Float_To_Long(WWMath::Ceilf(right->X)) - xstart; if (xstart + width > ResWidth) { width = ResWidth - xstart; } @@ -704,8 +704,8 @@ int IDBufferClass::Render_Non_Occluder_Scanline(GradientsStruct & grads,EdgeStru return 0; } - int xstart = WWMath::Float_To_Long(WWMath::Max(WWMath::Ceil(left->X),1)); - int width = WWMath::Float_To_Long(WWMath::Ceil(right->X)) - xstart; + int xstart = WWMath::Float_To_Long(WWMath::Max(WWMath::Ceilf(left->X),1)); + int width = WWMath::Float_To_Long(WWMath::Ceilf(right->X)) - xstart; if (xstart + width > ResWidth) { width = ResWidth - xstart; } diff --git a/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt b/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt index dca9eb68fef..fb1c164f7b0 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt +++ b/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt @@ -91,5 +91,9 @@ target_link_libraries(core_wwmath PRIVATE core_wwsaveload ) +target_link_libraries(core_wwmath PUBLIC + gamemath +) + # @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/aabox.h b/Core/Libraries/Source/WWVegas/WWMath/aabox.h index 15ea5d80548..d2084eb7eb9 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/aabox.h +++ b/Core/Libraries/Source/WWVegas/WWMath/aabox.h @@ -436,7 +436,7 @@ WWINLINE float AABoxClass::Project_To_Axis(const Vector3 & axis) const float z = Extent[2] * axis[2]; // projection is the sum of the absolute values of the projections of the three extents - return (WWMath::Fabs(x) + WWMath::Fabs(y) + WWMath::Fabs(z)); + return (WWMath::Fabsf_Legacy(x) + WWMath::Fabsf_Legacy(y) + WWMath::Fabsf_Legacy(z)); } /*********************************************************************************************** diff --git a/Core/Libraries/Source/WWVegas/WWMath/colmathaabox.cpp b/Core/Libraries/Source/WWVegas/WWMath/colmathaabox.cpp index ba3927b829f..00766417bea 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/colmathaabox.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/colmathaabox.cpp @@ -70,9 +70,9 @@ bool CollisionMath::Intersection_Test(const AABoxClass & box,const AABoxClass & { Vector3 dc = box2.Center - box.Center; - if (box.Extent.X + box2.Extent.X < WWMath::Fabs(dc.X)) return false; - if (box.Extent.Y + box2.Extent.Y < WWMath::Fabs(dc.Y)) return false; - if (box.Extent.Z + box2.Extent.Z < WWMath::Fabs(dc.Z)) return false; + if (box.Extent.X + box2.Extent.X < WWMath::Fabsf_Legacy(dc.X)) return false; + if (box.Extent.Y + box2.Extent.Y < WWMath::Fabsf_Legacy(dc.Y)) return false; + if (box.Extent.Z + box2.Extent.Z < WWMath::Fabsf_Legacy(dc.Z)) return false; return true; } @@ -101,9 +101,9 @@ CollisionMath::OverlapType CollisionMath::Overlap_Test(const AABoxClass & box,co // // Check to see if the sphere is completely outside the box // - if (WWMath::Fabs(dist.X) > extent.X) return OUTSIDE; - if (WWMath::Fabs(dist.Y) > extent.Y) return OUTSIDE; - if (WWMath::Fabs(dist.Z) > extent.Z) return OUTSIDE; + if (WWMath::Fabsf_Legacy(dist.X) > extent.X) return OUTSIDE; + if (WWMath::Fabsf_Legacy(dist.Y) > extent.Y) return OUTSIDE; + if (WWMath::Fabsf_Legacy(dist.Z) > extent.Z) return OUTSIDE; return INSIDE; } @@ -224,21 +224,21 @@ CollisionMath::OverlapType CollisionMath::Overlap_Test(const AABoxClass & box,co // that 'dp' will always project to zero for this axis. Vector3 axis; axis.Set(0,-line.Get_Dir().Z,line.Get_Dir().Y); // == (1,0,0) cross (x,y,z) - box_proj = WWMath::Fabs(axis.Y*box.Extent.Y) + WWMath::Fabs(axis.Z*box.Extent.Z); + box_proj = WWMath::Fabsf_Legacy(axis.Y*box.Extent.Y) + WWMath::Fabsf_Legacy(axis.Z*box.Extent.Z); p0_proj = Vector3::Dot_Product(axis,dp0); - if (WWMath::Fabs(p0_proj) > box_proj) return OUTSIDE; + if (WWMath::Fabsf_Legacy(p0_proj) > box_proj) return OUTSIDE; // Project box and line onto (y cross line) axis.Set(line.Get_Dir().Z,0,-line.Get_Dir().X); // == (0,1,0) cross (x,y,z) - box_proj = WWMath::Fabs(axis.X*box.Extent.X) + WWMath::Fabs(axis.Z*box.Extent.Z); + box_proj = WWMath::Fabsf_Legacy(axis.X*box.Extent.X) + WWMath::Fabsf_Legacy(axis.Z*box.Extent.Z); p0_proj = Vector3::Dot_Product(axis,dp0); - if (WWMath::Fabs(p0_proj) > box_proj) return OUTSIDE; + if (WWMath::Fabsf_Legacy(p0_proj) > box_proj) return OUTSIDE; // Project box and line onto (z cross line) axis.Set(-line.Get_Dir().Y,line.Get_Dir().X,0); // == (0,0,1) cross (x,y,z) - box_proj = WWMath::Fabs(axis.X*box.Extent.X) + WWMath::Fabs(axis.Y*box.Extent.Y); + box_proj = WWMath::Fabsf_Legacy(axis.X*box.Extent.X) + WWMath::Fabsf_Legacy(axis.Y*box.Extent.Y); p0_proj = Vector3::Dot_Product(axis,dp0); - if (WWMath::Fabs(p0_proj) > box_proj) return OUTSIDE; + if (WWMath::Fabsf_Legacy(p0_proj) > box_proj) return OUTSIDE; } return OVERLAPPED; diff --git a/Core/Libraries/Source/WWVegas/WWMath/colmathaabox.h b/Core/Libraries/Source/WWVegas/WWMath/colmathaabox.h index 11db1895db2..316f9a4600f 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/colmathaabox.h +++ b/Core/Libraries/Source/WWVegas/WWMath/colmathaabox.h @@ -60,9 +60,9 @@ *=============================================================================================*/ WWINLINE CollisionMath::OverlapType CollisionMath::Overlap_Test(const AABoxClass & box,const Vector3 & point) { - if (WWMath::Fabs(point.X - box.Center.X) > box.Extent.X) return POS; - if (WWMath::Fabs(point.Y - box.Center.Y) > box.Extent.Y) return POS; - if (WWMath::Fabs(point.Z - box.Center.Z) > box.Extent.Z) return POS; + if (WWMath::Fabsf_Legacy(point.X - box.Center.X) > box.Extent.X) return POS; + if (WWMath::Fabsf_Legacy(point.Y - box.Center.Y) > box.Extent.Y) return POS; + if (WWMath::Fabsf_Legacy(point.Z - box.Center.Z) > box.Extent.Z) return POS; return NEG; } @@ -84,9 +84,9 @@ WWINLINE CollisionMath::OverlapType CollisionMath::Overlap_Test(const AABoxClass Vector3 dc; Vector3::Subtract(box2.Center,box.Center,&dc); - if (box.Extent.X + box2.Extent.X < WWMath::Fabs(dc.X)) return POS; - if (box.Extent.Y + box2.Extent.Y < WWMath::Fabs(dc.Y)) return POS; - if (box.Extent.Z + box2.Extent.Z < WWMath::Fabs(dc.Z)) return POS; + if (box.Extent.X + box2.Extent.X < WWMath::Fabsf_Legacy(dc.X)) return POS; + if (box.Extent.Y + box2.Extent.Y < WWMath::Fabsf_Legacy(dc.Y)) return POS; + if (box.Extent.Z + box2.Extent.Z < WWMath::Fabsf_Legacy(dc.Z)) return POS; if ( (dc.X + box2.Extent.X <= box.Extent.X) && (dc.Y + box2.Extent.Y <= box.Extent.Y) && diff --git a/Core/Libraries/Source/WWVegas/WWMath/colmathaabtri.cpp b/Core/Libraries/Source/WWVegas/WWMath/colmathaabtri.cpp index da1cc6c3ee4..ba833fb20c4 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/colmathaabtri.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/colmathaabtri.cpp @@ -288,9 +288,9 @@ static inline bool aabtri_check_axis() } // compute coordinates of the leading edge of the box at t0 and t1 - leb0 = CollisionContext.Box->Extent.X * WWMath::Fabs(CollisionContext.TestAxis.X) + - CollisionContext.Box->Extent.Y * WWMath::Fabs(CollisionContext.TestAxis.Y) + - CollisionContext.Box->Extent.Z * WWMath::Fabs(CollisionContext.TestAxis.Z); + leb0 = CollisionContext.Box->Extent.X * WWMath::Fabsf_Legacy(CollisionContext.TestAxis.X) + + CollisionContext.Box->Extent.Y * WWMath::Fabsf_Legacy(CollisionContext.TestAxis.Y) + + CollisionContext.Box->Extent.Z * WWMath::Fabsf_Legacy(CollisionContext.TestAxis.Z); leb1 = leb0 + axismove; // compute coordinate of "leading edge of the triangle" relative to the box center. @@ -449,9 +449,9 @@ static inline bool aabtri_check_normal_axis() CollisionContext.TestSide = 1.0f; } - leb0 = CollisionContext.Box->Extent.X * WWMath::Fabs(CollisionContext.AN[0]) + - CollisionContext.Box->Extent.Y * WWMath::Fabs(CollisionContext.AN[1]) + - CollisionContext.Box->Extent.Z * WWMath::Fabs(CollisionContext.AN[2]); + leb0 = CollisionContext.Box->Extent.X * WWMath::Fabsf_Legacy(CollisionContext.AN[0]) + + CollisionContext.Box->Extent.Y * WWMath::Fabsf_Legacy(CollisionContext.AN[1]) + + CollisionContext.Box->Extent.Z * WWMath::Fabsf_Legacy(CollisionContext.AN[2]); leb1 = leb0 + axismove; CollisionContext.TestPoint = 0; lp = dist; // this is the "optimization", don't have to find lp @@ -574,7 +574,7 @@ inline void VERIFY_CROSS(const Vector3 & a, const Vector3 & b,const Vector3 & cr Vector3 tmp_cross; Vector3::Cross_Product(a,b,&tmp_cross); Vector3 diff = cross - tmp_cross; - WWASSERT(WWMath::Fabs(diff.Length()) < 0.0001f); + WWASSERT(WWMath::Fabsf_Legacy(diff.Length()) < 0.0001f); #endif } @@ -650,7 +650,7 @@ bool CollisionMath::Collide CollisionContext.TestAxisId = AXIS_A0E0; if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = CollisionContext.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(CollisionContext.AE[2][0]) + box.Extent[2]*WWMath::Fabs(CollisionContext.AE[1][0]); + leb0 = box.Extent[1]*WWMath::Fabsf_Legacy(CollisionContext.AE[2][0]) + box.Extent[2]*WWMath::Fabsf_Legacy(CollisionContext.AE[1][0]); if (aabtri_check_cross_axis(dp,2,leb0)) goto exit; } @@ -663,7 +663,7 @@ bool CollisionMath::Collide CollisionContext.TestAxisId = AXIS_A0E1; if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -CollisionContext.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(CollisionContext.AE[2][1]) + box.Extent[2]*WWMath::Fabs(CollisionContext.AE[1][1]); + leb0 = box.Extent[1]*WWMath::Fabsf_Legacy(CollisionContext.AE[2][1]) + box.Extent[2]*WWMath::Fabsf_Legacy(CollisionContext.AE[1][1]); if (aabtri_check_cross_axis(dp,1,leb0)) goto exit; } @@ -681,7 +681,7 @@ bool CollisionMath::Collide if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -CollisionContext.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(CollisionContext.AE[2][2]) + box.Extent[2]*WWMath::Fabs(CollisionContext.AE[1][2]); + leb0 = box.Extent[1]*WWMath::Fabsf_Legacy(CollisionContext.AE[2][2]) + box.Extent[2]*WWMath::Fabsf_Legacy(CollisionContext.AE[1][2]); if (aabtri_check_cross_axis(dp,1,leb0)) goto exit; } @@ -694,7 +694,7 @@ bool CollisionMath::Collide CollisionContext.TestAxisId = AXIS_A1E0; if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = CollisionContext.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(CollisionContext.AE[2][0]) + box.Extent[2]*WWMath::Fabs(CollisionContext.AE[0][0]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(CollisionContext.AE[2][0]) + box.Extent[2]*WWMath::Fabsf_Legacy(CollisionContext.AE[0][0]); if (aabtri_check_cross_axis(dp,2,leb0)) goto exit; } @@ -707,7 +707,7 @@ bool CollisionMath::Collide CollisionContext.TestAxisId = AXIS_A1E1; if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -CollisionContext.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(CollisionContext.AE[2][1]) + box.Extent[2]*WWMath::Fabs(CollisionContext.AE[0][1]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(CollisionContext.AE[2][1]) + box.Extent[2]*WWMath::Fabsf_Legacy(CollisionContext.AE[0][1]); if (aabtri_check_cross_axis(dp,1,leb0)) goto exit; } @@ -720,7 +720,7 @@ bool CollisionMath::Collide CollisionContext.TestAxisId = AXIS_A1E2; if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -CollisionContext.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(CollisionContext.AE[2][2]) + box.Extent[2]*WWMath::Fabs(CollisionContext.AE[0][2]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(CollisionContext.AE[2][2]) + box.Extent[2]*WWMath::Fabsf_Legacy(CollisionContext.AE[0][2]); if (aabtri_check_cross_axis(dp,1,leb0)) goto exit; } @@ -733,7 +733,7 @@ bool CollisionMath::Collide CollisionContext.TestAxisId = AXIS_A2E0; if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = CollisionContext.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(CollisionContext.AE[1][0]) + box.Extent[1]*WWMath::Fabs(CollisionContext.AE[0][0]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(CollisionContext.AE[1][0]) + box.Extent[1]*WWMath::Fabsf_Legacy(CollisionContext.AE[0][0]); if (aabtri_check_cross_axis(dp,2,leb0)) goto exit; } @@ -746,7 +746,7 @@ bool CollisionMath::Collide CollisionContext.TestAxisId = AXIS_A2E1; if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -CollisionContext.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(CollisionContext.AE[1][1]) + box.Extent[1]*WWMath::Fabs(CollisionContext.AE[0][1]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(CollisionContext.AE[1][1]) + box.Extent[1]*WWMath::Fabsf_Legacy(CollisionContext.AE[0][1]); if (aabtri_check_cross_axis(dp,1,leb0)) goto exit; } @@ -759,7 +759,7 @@ bool CollisionMath::Collide CollisionContext.TestAxisId = AXIS_A2E2; if (CollisionContext.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -CollisionContext.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(CollisionContext.AE[1][2]) + box.Extent[1]*WWMath::Fabs(CollisionContext.AE[0][2]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(CollisionContext.AE[1][2]) + box.Extent[1]*WWMath::Fabsf_Legacy(CollisionContext.AE[0][2]); if (aabtri_check_cross_axis(dp,1,leb0)) goto exit; } @@ -830,11 +830,11 @@ bool CollisionMath::Collide ** If this polygon cuts off more of the move -OR- this polygon cuts ** of the same amount but has a "better" normal, then use this normal */ - if ( (WWMath::Fabs(CollisionContext.MaxFrac - result->Fraction) > WWMATH_EPSILON) || + if ( (WWMath::Fabsf_Legacy(CollisionContext.MaxFrac - result->Fraction) > WWMATH_EPSILON) || (Vector3::Dot_Product(tmp_norm,move) < Vector3::Dot_Product(result->Normal,move))) { result->Normal = tmp_norm; - WWASSERT(WWMath::Fabs(result->Normal.Length() - 1.0f) < WWMATH_EPSILON); + WWASSERT(WWMath::Fabsf_Legacy(result->Normal.Length() - 1.0f) < WWMATH_EPSILON); } result->Fraction = CollisionContext.MaxFrac; @@ -1017,9 +1017,9 @@ static inline bool aabtri_intersect_normal_axis axis = -axis; } - leb0 = IntersectContext.Box->Extent.X * WWMath::Fabs(IntersectContext.AN[0]) + - IntersectContext.Box->Extent.Y * WWMath::Fabs(IntersectContext.AN[1]) + - IntersectContext.Box->Extent.Z * WWMath::Fabs(IntersectContext.AN[2]); + leb0 = IntersectContext.Box->Extent.X * WWMath::Fabsf_Legacy(IntersectContext.AN[0]) + + IntersectContext.Box->Extent.Y * WWMath::Fabsf_Legacy(IntersectContext.AN[1]) + + IntersectContext.Box->Extent.Z * WWMath::Fabsf_Legacy(IntersectContext.AN[2]); lp = dist; // this is the "optimization", don't have to find lp return (lp - leb0 > -WWMATH_EPSILON); @@ -1085,7 +1085,7 @@ bool CollisionMath::Intersection_Test(const AABoxClass & box,const TriClass & tr axis = IntersectContext.AxE[0][0]; if (axis.Length2() > AXISLEN_EPSILON2) { dp = IntersectContext.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(IntersectContext.AE[2][0]) + box.Extent[2]*WWMath::Fabs(IntersectContext.AE[1][0]); + leb0 = box.Extent[1]*WWMath::Fabsf_Legacy(IntersectContext.AE[2][0]) + box.Extent[2]*WWMath::Fabsf_Legacy(IntersectContext.AE[1][0]); if (aabtri_intersect_cross_axis(axis,dp,leb0)) return false; } @@ -1096,7 +1096,7 @@ bool CollisionMath::Intersection_Test(const AABoxClass & box,const TriClass & tr axis = IntersectContext.AxE[0][1]; if (axis.Length2() > AXISLEN_EPSILON2) { dp = -IntersectContext.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(IntersectContext.AE[2][1]) + box.Extent[2]*WWMath::Fabs(IntersectContext.AE[1][1]); + leb0 = box.Extent[1]*WWMath::Fabsf_Legacy(IntersectContext.AE[2][1]) + box.Extent[2]*WWMath::Fabsf_Legacy(IntersectContext.AE[1][1]); if (aabtri_intersect_cross_axis(axis,dp,leb0)) return false; } @@ -1109,7 +1109,7 @@ bool CollisionMath::Intersection_Test(const AABoxClass & box,const TriClass & tr IntersectContext.AE[2][2] = IntersectContext.E[2].Z; if (axis.Length2() > AXISLEN_EPSILON2) { dp = -IntersectContext.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(IntersectContext.AE[2][2]) + box.Extent[2]*WWMath::Fabs(IntersectContext.AE[1][2]); + leb0 = box.Extent[1]*WWMath::Fabsf_Legacy(IntersectContext.AE[2][2]) + box.Extent[2]*WWMath::Fabsf_Legacy(IntersectContext.AE[1][2]); if (aabtri_intersect_cross_axis(axis,dp,leb0)) return false; } @@ -1120,7 +1120,7 @@ bool CollisionMath::Intersection_Test(const AABoxClass & box,const TriClass & tr axis = IntersectContext.AxE[1][0]; if (axis.Length2() > AXISLEN_EPSILON2) { dp = IntersectContext.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(IntersectContext.AE[2][0]) + box.Extent[2]*WWMath::Fabs(IntersectContext.AE[0][0]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(IntersectContext.AE[2][0]) + box.Extent[2]*WWMath::Fabsf_Legacy(IntersectContext.AE[0][0]); if (aabtri_intersect_cross_axis(axis,dp,leb0)) return false; } @@ -1131,7 +1131,7 @@ bool CollisionMath::Intersection_Test(const AABoxClass & box,const TriClass & tr axis = IntersectContext.AxE[1][1]; if (axis.Length2() > AXISLEN_EPSILON2) { dp = -IntersectContext.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(IntersectContext.AE[2][1]) + box.Extent[2]*WWMath::Fabs(IntersectContext.AE[0][1]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(IntersectContext.AE[2][1]) + box.Extent[2]*WWMath::Fabsf_Legacy(IntersectContext.AE[0][1]); if (aabtri_intersect_cross_axis(axis,dp,leb0)) return false; } @@ -1143,7 +1143,7 @@ bool CollisionMath::Intersection_Test(const AABoxClass & box,const TriClass & tr IntersectContext.AE[0][2] = IntersectContext.E[2].X; if (axis.Length2() > AXISLEN_EPSILON2) { dp = -IntersectContext.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(IntersectContext.AE[2][2]) + box.Extent[2]*WWMath::Fabs(IntersectContext.AE[0][2]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(IntersectContext.AE[2][2]) + box.Extent[2]*WWMath::Fabsf_Legacy(IntersectContext.AE[0][2]); if (aabtri_intersect_cross_axis(axis,dp,leb0)) return false; } @@ -1154,7 +1154,7 @@ bool CollisionMath::Intersection_Test(const AABoxClass & box,const TriClass & tr axis = IntersectContext.AxE[2][0]; if (axis.Length2() > AXISLEN_EPSILON2) { dp = IntersectContext.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(IntersectContext.AE[1][0]) + box.Extent[1]*WWMath::Fabs(IntersectContext.AE[0][0]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(IntersectContext.AE[1][0]) + box.Extent[1]*WWMath::Fabsf_Legacy(IntersectContext.AE[0][0]); if (aabtri_intersect_cross_axis(axis,dp,leb0)) return false; } @@ -1165,7 +1165,7 @@ bool CollisionMath::Intersection_Test(const AABoxClass & box,const TriClass & tr axis = IntersectContext.AxE[2][1]; if (axis.Length2() > AXISLEN_EPSILON2) { dp = -IntersectContext.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(IntersectContext.AE[1][1]) + box.Extent[1]*WWMath::Fabs(IntersectContext.AE[0][1]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(IntersectContext.AE[1][1]) + box.Extent[1]*WWMath::Fabsf_Legacy(IntersectContext.AE[0][1]); if (aabtri_intersect_cross_axis(axis,dp,leb0)) return false; } @@ -1176,7 +1176,7 @@ bool CollisionMath::Intersection_Test(const AABoxClass & box,const TriClass & tr axis = IntersectContext.AxE[2][2]; if (axis.Length2() > AXISLEN_EPSILON2) { dp = -IntersectContext.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(IntersectContext.AE[1][2]) + box.Extent[1]*WWMath::Fabs(IntersectContext.AE[0][2]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(IntersectContext.AE[1][2]) + box.Extent[1]*WWMath::Fabsf_Legacy(IntersectContext.AE[0][2]); if (aabtri_intersect_cross_axis(axis,dp,leb0)) return false; } diff --git a/Core/Libraries/Source/WWVegas/WWMath/colmathobbobb.cpp b/Core/Libraries/Source/WWVegas/WWMath/colmathobbobb.cpp index d1e01f2522e..1fd97ad323b 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/colmathobbobb.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/colmathobbobb.cpp @@ -177,9 +177,9 @@ static bool obb_intersect_box0_basis // ra = box0 projection onto the axis // rb = box1 projection onto the axis float ra = context.Box0.Extent[axis_index]; - float rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[axis_index][0]) + - WWMath::Fabs(context.Box1.Extent[1]*context.AB[axis_index][1]) + - WWMath::Fabs(context.Box1.Extent[2]*context.AB[axis_index][2]); + float rb = WWMath::Fabsf_Legacy(context.Box1.Extent[0]*context.AB[axis_index][0]) + + WWMath::Fabsf_Legacy(context.Box1.Extent[1]*context.AB[axis_index][1]) + + WWMath::Fabsf_Legacy(context.Box1.Extent[2]*context.AB[axis_index][2]); float rsum = ra+rb; // u = projected distance between the box centers @@ -214,9 +214,9 @@ static bool obb_intersect_box1_basis { // ra = box0 projection onto the axis // rb = box1 projection onto the axis - float ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[0][axis_index]) + - WWMath::Fabs(context.Box0.Extent[1]*context.AB[1][axis_index]) + - WWMath::Fabs(context.Box0.Extent[2]*context.AB[2][axis_index]); + float ra = WWMath::Fabsf_Legacy(context.Box0.Extent[0]*context.AB[0][axis_index]) + + WWMath::Fabsf_Legacy(context.Box0.Extent[1]*context.AB[1][axis_index]) + + WWMath::Fabsf_Legacy(context.Box0.Extent[2]*context.AB[2][axis_index]); float rb = context.Box1.Extent[axis_index]; float rsum = ra+rb; @@ -340,8 +340,8 @@ bool intersect_obb_obb ///////////////////////////////////////////////////////////////////////// Vector3::Cross_Product(context.A[0],context.B[0],&axis); if (axis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[1]*context.AB[2][0])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[1][0]); - rb = WWMath::Fabs(context.Box1.Extent[1]*context.AB[0][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[0][1]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[1]*context.AB[2][0])+WWMath::Fabsf_Legacy(context.Box0.Extent[2]*context.AB[1][0]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[1]*context.AB[0][2])+WWMath::Fabsf_Legacy(context.Box1.Extent[2]*context.AB[0][1]); if (obb_intersect_axis(context,axis,ra,rb)) return false; } @@ -350,8 +350,8 @@ bool intersect_obb_obb ///////////////////////////////////////////////////////////////////////// Vector3::Cross_Product(context.A[0],context.B[1],&axis); if (axis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[1]*context.AB[2][1])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[1][1]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[0][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[0][0]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[1]*context.AB[2][1])+WWMath::Fabsf_Legacy(context.Box0.Extent[2]*context.AB[1][1]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[0]*context.AB[0][2])+WWMath::Fabsf_Legacy(context.Box1.Extent[2]*context.AB[0][0]); if (obb_intersect_axis(context,axis,ra,rb)) return false; } @@ -360,8 +360,8 @@ bool intersect_obb_obb ///////////////////////////////////////////////////////////////////////// Vector3::Cross_Product(context.A[0],context.B[2],&axis); if (axis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[1]*context.AB[2][2])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[1][2]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[0][1])+WWMath::Fabs(context.Box1.Extent[1]*context.AB[0][0]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[1]*context.AB[2][2])+WWMath::Fabsf_Legacy(context.Box0.Extent[2]*context.AB[1][2]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[0]*context.AB[0][1])+WWMath::Fabsf_Legacy(context.Box1.Extent[1]*context.AB[0][0]); if (obb_intersect_axis(context,axis,ra,rb)) return false; } @@ -370,8 +370,8 @@ bool intersect_obb_obb ///////////////////////////////////////////////////////////////////////// Vector3::Cross_Product(context.A[1],context.B[0],&axis); if (axis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[2][0])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[0][0]); - rb = WWMath::Fabs(context.Box1.Extent[1]*context.AB[1][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[1][1]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[0]*context.AB[2][0])+WWMath::Fabsf_Legacy(context.Box0.Extent[2]*context.AB[0][0]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[1]*context.AB[1][2])+WWMath::Fabsf_Legacy(context.Box1.Extent[2]*context.AB[1][1]); if (obb_intersect_axis(context,axis,ra,rb)) return false; } @@ -380,8 +380,8 @@ bool intersect_obb_obb ///////////////////////////////////////////////////////////////////////// Vector3::Cross_Product(context.A[1],context.B[1],&axis); if (axis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[2][1])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[0][1]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[1][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[1][0]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[0]*context.AB[2][1])+WWMath::Fabsf_Legacy(context.Box0.Extent[2]*context.AB[0][1]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[0]*context.AB[1][2])+WWMath::Fabsf_Legacy(context.Box1.Extent[2]*context.AB[1][0]); if (obb_intersect_axis(context,axis,ra,rb)) return false; } @@ -390,8 +390,8 @@ bool intersect_obb_obb ///////////////////////////////////////////////////////////////////////// Vector3::Cross_Product(context.A[1],context.B[2],&axis); if (axis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[2][2])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[0][2]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[1][1])+WWMath::Fabs(context.Box1.Extent[1]*context.AB[1][0]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[0]*context.AB[2][2])+WWMath::Fabsf_Legacy(context.Box0.Extent[2]*context.AB[0][2]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[0]*context.AB[1][1])+WWMath::Fabsf_Legacy(context.Box1.Extent[1]*context.AB[1][0]); if (obb_intersect_axis(context,axis,ra,rb)) return false; } @@ -400,8 +400,8 @@ bool intersect_obb_obb ///////////////////////////////////////////////////////////////////////// Vector3::Cross_Product(context.A[2],context.B[0],&axis); if (axis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[1][0])+WWMath::Fabs(context.Box0.Extent[1]*context.AB[0][0]); - rb = WWMath::Fabs(context.Box1.Extent[1]*context.AB[2][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[2][1]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[0]*context.AB[1][0])+WWMath::Fabsf_Legacy(context.Box0.Extent[1]*context.AB[0][0]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[1]*context.AB[2][2])+WWMath::Fabsf_Legacy(context.Box1.Extent[2]*context.AB[2][1]); if (obb_intersect_axis(context,axis,ra,rb)) return false; } @@ -410,8 +410,8 @@ bool intersect_obb_obb ///////////////////////////////////////////////////////////////////////// Vector3::Cross_Product(context.A[2],context.B[1],&axis); if (axis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[1][1])+WWMath::Fabs(context.Box0.Extent[1]*context.AB[0][1]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[2][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[2][0]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[0]*context.AB[1][1])+WWMath::Fabsf_Legacy(context.Box0.Extent[1]*context.AB[0][1]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[0]*context.AB[2][2])+WWMath::Fabsf_Legacy(context.Box1.Extent[2]*context.AB[2][0]); if (obb_intersect_axis(context,axis,ra,rb)) return false; } @@ -420,8 +420,8 @@ bool intersect_obb_obb ///////////////////////////////////////////////////////////////////////// Vector3::Cross_Product(context.A[2],context.B[2],&axis); if (axis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[1][2])+WWMath::Fabs(context.Box0.Extent[1]*context.AB[0][2]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[2][1])+WWMath::Fabs(context.Box1.Extent[1]*context.AB[2][0]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[0]*context.AB[1][2])+WWMath::Fabsf_Legacy(context.Box0.Extent[1]*context.AB[0][2]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[0]*context.AB[2][1])+WWMath::Fabsf_Legacy(context.Box1.Extent[1]*context.AB[2][0]); if (obb_intersect_axis(context,axis,ra,rb)) return false; } @@ -593,7 +593,7 @@ static inline bool obb_separation_test if ( u1 > rsum ) { context.MaxFrac = 1.0f; return true; - } else if (WWMath::Fabs(u1-u0) > 0.0f) { + } else if (WWMath::Fabsf_Legacy(u1-u0) > 0.0f) { tmp = (rsum-u0)/(u1-u0); if ( tmp > context.MaxFrac ) { context.MaxFrac = tmp; @@ -606,7 +606,7 @@ static inline bool obb_separation_test if ( u1 < -rsum ) { context.MaxFrac = 1.0f; return true; - } else if (WWMath::Fabs(u1-u0) > 0.0f) { + } else if (WWMath::Fabsf_Legacy(u1-u0) > 0.0f) { tmp = (-rsum-u0)/(u1-u0); if ( tmp > context.MaxFrac ) { context.MaxFrac = tmp; @@ -640,9 +640,9 @@ static bool obb_check_box0_basis // ra = box0 projection onto the axis // rb = box1 projection onto the axis float ra = context.Box0.Extent[axis_index]; - float rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[axis_index][0]) + - WWMath::Fabs(context.Box1.Extent[1]*context.AB[axis_index][1]) + - WWMath::Fabs(context.Box1.Extent[2]*context.AB[axis_index][2]); + float rb = WWMath::Fabsf_Legacy(context.Box1.Extent[0]*context.AB[axis_index][0]) + + WWMath::Fabsf_Legacy(context.Box1.Extent[1]*context.AB[axis_index][1]) + + WWMath::Fabsf_Legacy(context.Box1.Extent[2]*context.AB[axis_index][2]); // u0 = projected distance between the box centers at t0 // u1 = projected distance between the box centers at t1 @@ -673,9 +673,9 @@ static bool obb_check_box1_basis { // ra = box0 projection onto the axis // rb = box1 projection onto the axis - float ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[0][axis_index]) + - WWMath::Fabs(context.Box0.Extent[1]*context.AB[1][axis_index]) + - WWMath::Fabs(context.Box0.Extent[2]*context.AB[2][axis_index]); + float ra = WWMath::Fabsf_Legacy(context.Box0.Extent[0]*context.AB[0][axis_index]) + + WWMath::Fabsf_Legacy(context.Box0.Extent[1]*context.AB[1][axis_index]) + + WWMath::Fabsf_Legacy(context.Box0.Extent[2]*context.AB[2][axis_index]); float rb = context.Box1.Extent[axis_index]; // u0 = projected distance between the box centers at t0 @@ -730,13 +730,13 @@ static inline void obb_compute_projections float * rb ) { - *ra = context.Box0.Extent.X * WWMath::Fabs(Vector3::Dot_Product(context.A[0],context.TestAxis)) + - context.Box0.Extent.Y * WWMath::Fabs(Vector3::Dot_Product(context.A[1],context.TestAxis)) + - context.Box0.Extent.Z * WWMath::Fabs(Vector3::Dot_Product(context.A[2],context.TestAxis)); + *ra = context.Box0.Extent.X * WWMath::Fabsf_Legacy(Vector3::Dot_Product(context.A[0],context.TestAxis)) + + context.Box0.Extent.Y * WWMath::Fabsf_Legacy(Vector3::Dot_Product(context.A[1],context.TestAxis)) + + context.Box0.Extent.Z * WWMath::Fabsf_Legacy(Vector3::Dot_Product(context.A[2],context.TestAxis)); - *rb = context.Box1.Extent.X * WWMath::Fabs(Vector3::Dot_Product(context.B[0],context.TestAxis)) + - context.Box1.Extent.Y * WWMath::Fabs(Vector3::Dot_Product(context.B[1],context.TestAxis)) + - context.Box1.Extent.Z * WWMath::Fabs(Vector3::Dot_Product(context.B[2],context.TestAxis)); + *rb = context.Box1.Extent.X * WWMath::Fabsf_Legacy(Vector3::Dot_Product(context.B[0],context.TestAxis)) + + context.Box1.Extent.Y * WWMath::Fabsf_Legacy(Vector3::Dot_Product(context.B[1],context.TestAxis)) + + context.Box1.Extent.Z * WWMath::Fabsf_Legacy(Vector3::Dot_Product(context.B[2],context.TestAxis)); } @@ -923,7 +923,7 @@ static inline void compute_contact_point(ObbCollisionStruct & context,CastResult y[2] = eval_side(context.AB[0][1],context.Side) * context.Box1.Extent[2]; den = (1.0f - context.AB[0][0] * context.AB[0][0]); - if (WWMath::Fabs(den) > 0.0f) { + if (WWMath::Fabsf_Legacy(den) > 0.0f) { x[0] = Vector3::Dot_Product(context.A[0],dcnew); x[0] += context.AB[0][0] * (Vector3::Dot_Product(-context.B[0],dcnew) + context.AB[1][0]*x[1] + context.AB[2][0]*x[2]); x[0] += context.AB[0][1] * y[1] + context.AB[0][2] * y[2]; @@ -940,7 +940,7 @@ static inline void compute_contact_point(ObbCollisionStruct & context,CastResult y[2] = -eval_side(context.AB[0][0],context.Side) * context.Box1.Extent[2]; den = (1.0f - context.AB[0][1] * context.AB[0][1]); - if (WWMath::Fabs(den) > 0.0f) { + if (WWMath::Fabsf_Legacy(den) > 0.0f) { x[0] = Vector3::Dot_Product(context.A[0],dcnew); x[0] += context.AB[0][1] * (Vector3::Dot_Product(-context.B[1],dcnew) + context.AB[1][1]*x[1] + context.AB[2][1]*x[2]); x[0] += context.AB[0][0] * y[0] + context.AB[0][2] * y[2]; @@ -957,7 +957,7 @@ static inline void compute_contact_point(ObbCollisionStruct & context,CastResult y[1] = eval_side(context.AB[0][0],context.Side) * context.Box1.Extent[1]; den = (1.0f - context.AB[0][2] * context.AB[0][2]); - if (WWMath::Fabs(den) > 0.0f) { + if (WWMath::Fabsf_Legacy(den) > 0.0f) { x[0] = Vector3::Dot_Product(context.A[0],dcnew); x[0] += context.AB[0][2] * (Vector3::Dot_Product(-context.B[2],dcnew) + context.AB[1][2]*x[1] + context.AB[2][2]*x[2]); x[0] += context.AB[0][0] * y[0] + context.AB[0][1] * y[1]; @@ -974,7 +974,7 @@ static inline void compute_contact_point(ObbCollisionStruct & context,CastResult y[2] = eval_side(context.AB[1][1],context.Side) * context.Box1.Extent[2]; den = (1.0f - context.AB[1][0] * context.AB[1][0]); - if (WWMath::Fabs(den) > 0.0f) { + if (WWMath::Fabsf_Legacy(den) > 0.0f) { x[1] = Vector3::Dot_Product(context.A[1],dcnew); x[1] += context.AB[1][0] * (Vector3::Dot_Product(-context.B[0],dcnew) + context.AB[0][0]*x[0] + context.AB[2][0]*x[2]); x[1] += context.AB[1][1] * y[1] + context.AB[1][2] * y[2]; @@ -991,7 +991,7 @@ static inline void compute_contact_point(ObbCollisionStruct & context,CastResult y[2] = -eval_side(context.AB[1][0],context.Side) * context.Box1.Extent[2]; den = 1.0f / (1.0f - context.AB[1][1] * context.AB[1][1]); - if (WWMath::Fabs(den) > 0.0f) { + if (WWMath::Fabsf_Legacy(den) > 0.0f) { x[1] = Vector3::Dot_Product(context.A[1],dcnew); x[1] += context.AB[1][1] * (Vector3::Dot_Product(-context.B[1],dcnew) + context.AB[0][1]*x[0] + context.AB[2][1]*x[2]); x[1] += context.AB[1][0] * y[0] + context.AB[1][2] * y[2]; @@ -1008,7 +1008,7 @@ static inline void compute_contact_point(ObbCollisionStruct & context,CastResult y[1] = eval_side(context.AB[1][0],context.Side) * context.Box1.Extent[1]; den = (1.0f - context.AB[1][2] * context.AB[1][2]); - if (WWMath::Fabs(den) > 0.0f) { + if (WWMath::Fabsf_Legacy(den) > 0.0f) { x[1] = Vector3::Dot_Product(context.A[1],dcnew); x[1] += context.AB[1][2] * (Vector3::Dot_Product(-context.B[2],dcnew) + context.AB[0][2]*x[0] + context.AB[2][2]*x[2]); x[1] += context.AB[1][0] * y[0] + context.AB[1][1] * y[1]; @@ -1025,7 +1025,7 @@ static inline void compute_contact_point(ObbCollisionStruct & context,CastResult y[2] = eval_side(context.AB[2][1],context.Side) * context.Box1.Extent[2]; den = (1.0f - context.AB[2][0] * context.AB[2][0]); - if (WWMath::Fabs(den) > 0.0f) { + if (WWMath::Fabsf_Legacy(den) > 0.0f) { x[2] = Vector3::Dot_Product(context.A[2],dcnew); x[2] += context.AB[2][0] * (Vector3::Dot_Product(-context.B[0],dcnew) + context.AB[0][0]*x[0] + context.AB[1][0]*x[1]); x[2] += context.AB[2][1] * y[1] + context.AB[2][2] * y[2]; @@ -1042,7 +1042,7 @@ static inline void compute_contact_point(ObbCollisionStruct & context,CastResult y[2] = -eval_side(context.AB[2][0],context.Side) * context.Box1.Extent[2]; den = (1.0f - context.AB[2][1] * context.AB[2][1]); - if (WWMath::Fabs(den) > 0.0f) { + if (WWMath::Fabsf_Legacy(den) > 0.0f) { x[2] = Vector3::Dot_Product(context.A[2],dcnew); x[2] += context.AB[2][1] * (Vector3::Dot_Product(-context.B[1],dcnew) + context.AB[0][1]*x[0] + context.AB[1][1]*x[1]); x[2] += context.AB[2][0] * y[0] + context.AB[2][2] * y[2]; @@ -1059,7 +1059,7 @@ static inline void compute_contact_point(ObbCollisionStruct & context,CastResult y[1] = eval_side(context.AB[2][0],context.Side) * context.Box1.Extent[1]; den = (1.0f - context.AB[2][2] * context.AB[2][2]); - if (WWMath::Fabs(den) > 0.0f) { + if (WWMath::Fabsf_Legacy(den) > 0.0f) { x[2] = Vector3::Dot_Product(context.A[2],dcnew); x[2] += context.AB[2][2] * (Vector3::Dot_Product(-context.B[2],dcnew) + context.AB[0][2]*x[0] + context.AB[1][2]*x[1]); x[2] += context.AB[2][0] * y[0] + context.AB[2][1] * y[1]; @@ -1177,8 +1177,8 @@ bool collide_obb_obb Vector3::Cross_Product(context.A[0],context.B[0],&context.TestAxis); context.TestAxisId = AXIS_A0B0; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[1]*context.AB[2][0])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[1][0]); - rb = WWMath::Fabs(context.Box1.Extent[1]*context.AB[0][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[0][1]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[1]*context.AB[2][0])+WWMath::Fabsf_Legacy(context.Box0.Extent[2]*context.AB[1][0]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[1]*context.AB[0][2])+WWMath::Fabsf_Legacy(context.Box1.Extent[2]*context.AB[0][1]); if (obb_check_axis(context,ra,rb)) goto exit; } @@ -1188,8 +1188,8 @@ bool collide_obb_obb Vector3::Cross_Product(context.A[0],context.B[1],&context.TestAxis); context.TestAxisId = AXIS_A0B1; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[1]*context.AB[2][1])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[1][1]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[0][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[0][0]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[1]*context.AB[2][1])+WWMath::Fabsf_Legacy(context.Box0.Extent[2]*context.AB[1][1]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[0]*context.AB[0][2])+WWMath::Fabsf_Legacy(context.Box1.Extent[2]*context.AB[0][0]); if (obb_check_axis(context,ra,rb)) goto exit; } @@ -1199,8 +1199,8 @@ bool collide_obb_obb Vector3::Cross_Product(context.A[0],context.B[2],&context.TestAxis); context.TestAxisId = AXIS_A0B2; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[1]*context.AB[2][2])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[1][2]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[0][1])+WWMath::Fabs(context.Box1.Extent[1]*context.AB[0][0]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[1]*context.AB[2][2])+WWMath::Fabsf_Legacy(context.Box0.Extent[2]*context.AB[1][2]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[0]*context.AB[0][1])+WWMath::Fabsf_Legacy(context.Box1.Extent[1]*context.AB[0][0]); if (obb_check_axis(context,ra,rb)) goto exit; } @@ -1210,8 +1210,8 @@ bool collide_obb_obb Vector3::Cross_Product(context.A[1],context.B[0],&context.TestAxis); context.TestAxisId = AXIS_A1B0; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[2][0])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[0][0]); - rb = WWMath::Fabs(context.Box1.Extent[1]*context.AB[1][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[1][1]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[0]*context.AB[2][0])+WWMath::Fabsf_Legacy(context.Box0.Extent[2]*context.AB[0][0]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[1]*context.AB[1][2])+WWMath::Fabsf_Legacy(context.Box1.Extent[2]*context.AB[1][1]); if (obb_check_axis(context,ra,rb)) goto exit; } @@ -1221,8 +1221,8 @@ bool collide_obb_obb Vector3::Cross_Product(context.A[1],context.B[1],&context.TestAxis); context.TestAxisId = AXIS_A1B1; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[2][1])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[0][1]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[1][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[1][0]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[0]*context.AB[2][1])+WWMath::Fabsf_Legacy(context.Box0.Extent[2]*context.AB[0][1]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[0]*context.AB[1][2])+WWMath::Fabsf_Legacy(context.Box1.Extent[2]*context.AB[1][0]); if (obb_check_axis(context,ra,rb)) goto exit; } @@ -1232,8 +1232,8 @@ bool collide_obb_obb Vector3::Cross_Product(context.A[1],context.B[2],&context.TestAxis); context.TestAxisId = AXIS_A1B2; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[2][2])+WWMath::Fabs(context.Box0.Extent[2]*context.AB[0][2]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[1][1])+WWMath::Fabs(context.Box1.Extent[1]*context.AB[1][0]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[0]*context.AB[2][2])+WWMath::Fabsf_Legacy(context.Box0.Extent[2]*context.AB[0][2]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[0]*context.AB[1][1])+WWMath::Fabsf_Legacy(context.Box1.Extent[1]*context.AB[1][0]); if (obb_check_axis(context,ra,rb)) goto exit; } @@ -1243,8 +1243,8 @@ bool collide_obb_obb Vector3::Cross_Product(context.A[2],context.B[0],&context.TestAxis); context.TestAxisId = AXIS_A2B0; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[1][0])+WWMath::Fabs(context.Box0.Extent[1]*context.AB[0][0]); - rb = WWMath::Fabs(context.Box1.Extent[1]*context.AB[2][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[2][1]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[0]*context.AB[1][0])+WWMath::Fabsf_Legacy(context.Box0.Extent[1]*context.AB[0][0]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[1]*context.AB[2][2])+WWMath::Fabsf_Legacy(context.Box1.Extent[2]*context.AB[2][1]); if (obb_check_axis(context,ra,rb)) goto exit; } @@ -1254,8 +1254,8 @@ bool collide_obb_obb Vector3::Cross_Product(context.A[2],context.B[1],&context.TestAxis); context.TestAxisId = AXIS_A2B1; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[1][1])+WWMath::Fabs(context.Box0.Extent[1]*context.AB[0][1]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[2][2])+WWMath::Fabs(context.Box1.Extent[2]*context.AB[2][0]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[0]*context.AB[1][1])+WWMath::Fabsf_Legacy(context.Box0.Extent[1]*context.AB[0][1]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[0]*context.AB[2][2])+WWMath::Fabsf_Legacy(context.Box1.Extent[2]*context.AB[2][0]); if (obb_check_axis(context,ra,rb)) goto exit; } @@ -1265,8 +1265,8 @@ bool collide_obb_obb Vector3::Cross_Product(context.A[2],context.B[2],&context.TestAxis); context.TestAxisId = AXIS_A2B2; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { - ra = WWMath::Fabs(context.Box0.Extent[0]*context.AB[1][2])+WWMath::Fabs(context.Box0.Extent[1]*context.AB[0][2]); - rb = WWMath::Fabs(context.Box1.Extent[0]*context.AB[2][1])+WWMath::Fabs(context.Box1.Extent[1]*context.AB[2][0]); + ra = WWMath::Fabsf_Legacy(context.Box0.Extent[0]*context.AB[1][2])+WWMath::Fabsf_Legacy(context.Box0.Extent[1]*context.AB[0][2]); + rb = WWMath::Fabsf_Legacy(context.Box1.Extent[0]*context.AB[2][1])+WWMath::Fabsf_Legacy(context.Box1.Extent[1]*context.AB[2][0]); if (obb_check_axis(context,ra,rb)) goto exit; } diff --git a/Core/Libraries/Source/WWVegas/WWMath/colmathobbox.cpp b/Core/Libraries/Source/WWVegas/WWMath/colmathobbox.cpp index c7a71d2b87d..2368738e4ce 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/colmathobbox.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/colmathobbox.cpp @@ -59,13 +59,13 @@ CollisionMath::Overlap_Test(const OBBoxClass & box,const Vector3 & point) Matrix3x3::Transpose_Rotate_Vector(box.Basis,(point - box.Center),&localpoint); // if the point is outside any of the extents, it is outside the box - if (WWMath::Fabs(localpoint.X) > box.Extent.X) { + if (WWMath::Fabsf_Legacy(localpoint.X) > box.Extent.X) { return OUTSIDE; } - if (WWMath::Fabs(localpoint.Y) > box.Extent.Y) { + if (WWMath::Fabsf_Legacy(localpoint.Y) > box.Extent.Y) { return OUTSIDE; } - if (WWMath::Fabs(localpoint.Z) > box.Extent.Z) { + if (WWMath::Fabsf_Legacy(localpoint.Z) > box.Extent.Z) { return OUTSIDE; } return INSIDE; diff --git a/Core/Libraries/Source/WWVegas/WWMath/colmathobbtri.cpp b/Core/Libraries/Source/WWVegas/WWMath/colmathobbtri.cpp index 18ea575286c..4cdab9251be 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/colmathobbtri.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/colmathobbtri.cpp @@ -313,9 +313,9 @@ static inline bool obbtri_check_collision_axis(BTCollisionStruct & context) } // compute coordinates of the leading edge of the box at t0 and t1 - leb0 = context.Box.Extent.X * WWMath::Fabs(Vector3::Dot_Product(context.TestAxis,context.A[0])) + - context.Box.Extent.Y * WWMath::Fabs(Vector3::Dot_Product(context.TestAxis,context.A[1])) + - context.Box.Extent.Z * WWMath::Fabs(Vector3::Dot_Product(context.TestAxis,context.A[2])); + leb0 = context.Box.Extent.X * WWMath::Fabsf_Legacy(Vector3::Dot_Product(context.TestAxis,context.A[0])) + + context.Box.Extent.Y * WWMath::Fabsf_Legacy(Vector3::Dot_Product(context.TestAxis,context.A[1])) + + context.Box.Extent.Z * WWMath::Fabsf_Legacy(Vector3::Dot_Product(context.TestAxis,context.A[2])); leb1 = leb0 + axismove; // compute coordinate of "leading edge of the triangle" relative to the box center. @@ -479,9 +479,9 @@ static inline bool obbtri_check_collision_normal_axis(BTCollisionStruct & contex context.TestSide = 1.0f; } - leb0 = context.Box.Extent.X * WWMath::Fabs(context.AN[0]) + - context.Box.Extent.Y * WWMath::Fabs(context.AN[1]) + - context.Box.Extent.Z * WWMath::Fabs(context.AN[2]); + leb0 = context.Box.Extent.X * WWMath::Fabsf_Legacy(context.AN[0]) + + context.Box.Extent.Y * WWMath::Fabsf_Legacy(context.AN[1]) + + context.Box.Extent.Z * WWMath::Fabsf_Legacy(context.AN[2]); leb1 = leb0 + axismove; context.TestPoint = 0; lp = dist; // this is the "optimization", don't have to find lp @@ -610,7 +610,7 @@ static inline void eval_A0_point(const BTCollisionStruct & context,float * x,int if (context.Point == 0) { yval = 0.0f; } else { yval = 1.0f; } den = Vector3::Dot_Product(context.N,context.AxE[0][edge]); - if (WWMath::Fabs(den) > 0.0f) { + if (WWMath::Fabsf_Legacy(den) > 0.0f) { Vector3::Cross_Product(context.FinalD,context.E[edge],&DxE); x[0] = Vector3::Dot_Product(context.N,DxE); @@ -653,7 +653,7 @@ static inline void eval_A1_point(const BTCollisionStruct & context,float * x,int if (context.Point == 0) { yval = 0.0f; } else { yval = 1.0f; } den = Vector3::Dot_Product(context.N,context.AxE[1][edge]); - if (WWMath::Fabs(den) > 0.0f) { + if (WWMath::Fabsf_Legacy(den) > 0.0f) { Vector3::Cross_Product(context.FinalD,context.E[edge],&DxE); x[1] = Vector3::Dot_Product(context.N,DxE); @@ -695,7 +695,7 @@ static inline void eval_A2_point(const BTCollisionStruct & context,float * x,int if (context.Point == 0) { yval = 0.0f; } else { yval = 1.0f; } den = Vector3::Dot_Product(context.N,context.AxE[2][edge]); - if (WWMath::Fabs(den) > 0.0f) { + if (WWMath::Fabsf_Legacy(den) > 0.0f) { Vector3::Cross_Product(context.FinalD,context.E[edge],&DxE); x[2] = Vector3::Dot_Product(context.N,DxE); @@ -937,7 +937,7 @@ bool CollisionMath::Collide context.TestAxisId = AXIS_A0E0; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = context.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(context.AE[2][0]) + box.Extent[2]*WWMath::Fabs(context.AE[1][0]); + leb0 = box.Extent[1]*WWMath::Fabsf_Legacy(context.AE[2][0]) + box.Extent[2]*WWMath::Fabsf_Legacy(context.AE[1][0]); if (obbtri_check_collision_cross_axis(context,dp,2,leb0)) goto exit; } @@ -949,7 +949,7 @@ bool CollisionMath::Collide context.TestAxisId = AXIS_A0E1; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -context.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(context.AE[2][1]) + box.Extent[2]*WWMath::Fabs(context.AE[1][1]); + leb0 = box.Extent[1]*WWMath::Fabsf_Legacy(context.AE[2][1]) + box.Extent[2]*WWMath::Fabsf_Legacy(context.AE[1][1]); if (obbtri_check_collision_cross_axis(context,dp,1,leb0)) goto exit; } @@ -963,7 +963,7 @@ bool CollisionMath::Collide context.AE[2][2] = Vector3::Dot_Product(context.A[2],context.E[2]); if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -context.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(context.AE[2][2]) + box.Extent[2]*WWMath::Fabs(context.AE[1][2]); + leb0 = box.Extent[1]*WWMath::Fabsf_Legacy(context.AE[2][2]) + box.Extent[2]*WWMath::Fabsf_Legacy(context.AE[1][2]); if (obbtri_check_collision_cross_axis(context,dp,1,leb0)) goto exit; } @@ -975,7 +975,7 @@ bool CollisionMath::Collide context.TestAxisId = AXIS_A1E0; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = context.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[2][0]) + box.Extent[2]*WWMath::Fabs(context.AE[0][0]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(context.AE[2][0]) + box.Extent[2]*WWMath::Fabsf_Legacy(context.AE[0][0]); if (obbtri_check_collision_cross_axis(context,dp,2,leb0)) goto exit; } @@ -987,7 +987,7 @@ bool CollisionMath::Collide context.TestAxisId = AXIS_A1E1; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -context.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[2][1]) + box.Extent[2]*WWMath::Fabs(context.AE[0][1]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(context.AE[2][1]) + box.Extent[2]*WWMath::Fabsf_Legacy(context.AE[0][1]); if (obbtri_check_collision_cross_axis(context,dp,1,leb0)) goto exit; } @@ -1000,7 +1000,7 @@ bool CollisionMath::Collide context.AE[0][2] = Vector3::Dot_Product(context.A[0],context.E[2]); if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -context.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[2][2]) + box.Extent[2]*WWMath::Fabs(context.AE[0][2]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(context.AE[2][2]) + box.Extent[2]*WWMath::Fabsf_Legacy(context.AE[0][2]); if (obbtri_check_collision_cross_axis(context,dp,1,leb0)) goto exit; } @@ -1012,7 +1012,7 @@ bool CollisionMath::Collide context.TestAxisId = AXIS_A2E0; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = context.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[1][0]) + box.Extent[1]*WWMath::Fabs(context.AE[0][0]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(context.AE[1][0]) + box.Extent[1]*WWMath::Fabsf_Legacy(context.AE[0][0]); if (obbtri_check_collision_cross_axis(context,dp,2,leb0)) goto exit; } @@ -1024,7 +1024,7 @@ bool CollisionMath::Collide context.TestAxisId = AXIS_A2E1; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -context.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[1][1]) + box.Extent[1]*WWMath::Fabs(context.AE[0][1]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(context.AE[1][1]) + box.Extent[1]*WWMath::Fabsf_Legacy(context.AE[0][1]); if (obbtri_check_collision_cross_axis(context,dp,1,leb0)) goto exit; } @@ -1036,7 +1036,7 @@ bool CollisionMath::Collide context.TestAxisId = AXIS_A2E2; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -context.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[1][2]) + box.Extent[1]*WWMath::Fabs(context.AE[0][2]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(context.AE[1][2]) + box.Extent[1]*WWMath::Fabsf_Legacy(context.AE[0][2]); if (obbtri_check_collision_cross_axis(context,dp,1,leb0)) goto exit; } @@ -1098,7 +1098,7 @@ bool CollisionMath::Collide Vector3 normal; obbtri_compute_contact_normal(context,&normal); - if ( (WWMath::Fabs(context.MaxFrac - result->Fraction) > WWMATH_EPSILON) || + if ( (WWMath::Fabsf_Legacy(context.MaxFrac - result->Fraction) > WWMATH_EPSILON) || (Vector3::Dot_Product(normal,move) < Vector3::Dot_Product(result->Normal,move)) ) { result->Normal = normal; //obbtri_compute_contact_normal(context,result); @@ -1337,9 +1337,9 @@ static inline bool obbtri_check_intersection_normal_axis dist = -dist; } - leb0 = context.Box.Extent.X * WWMath::Fabs(context.AN[0]) + - context.Box.Extent.Y * WWMath::Fabs(context.AN[1]) + - context.Box.Extent.Z * WWMath::Fabs(context.AN[2]); + leb0 = context.Box.Extent.X * WWMath::Fabsf_Legacy(context.AN[0]) + + context.Box.Extent.Y * WWMath::Fabsf_Legacy(context.AN[1]) + + context.Box.Extent.Z * WWMath::Fabsf_Legacy(context.AN[2]); lp = dist; // this is the "optimization", don't have to find lp return obbtri_intersection_separation_test(context,lp,leb0); @@ -1408,7 +1408,7 @@ bool CollisionMath::Intersection_Test(const OBBoxClass & box,const TriClass & tr context.TestAxis = context.AxE[0][0]; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = context.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(context.AE[2][0]) + box.Extent[2]*WWMath::Fabs(context.AE[1][0]); + leb0 = box.Extent[1]*WWMath::Fabsf_Legacy(context.AE[2][0]) + box.Extent[2]*WWMath::Fabsf_Legacy(context.AE[1][0]); if (obbtri_check_intersection_cross_axis(context,dp,leb0)) return false; } @@ -1419,7 +1419,7 @@ bool CollisionMath::Intersection_Test(const OBBoxClass & box,const TriClass & tr context.TestAxis = context.AxE[0][1]; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -context.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(context.AE[2][1]) + box.Extent[2]*WWMath::Fabs(context.AE[1][1]); + leb0 = box.Extent[1]*WWMath::Fabsf_Legacy(context.AE[2][1]) + box.Extent[2]*WWMath::Fabsf_Legacy(context.AE[1][1]); if (obbtri_check_intersection_cross_axis(context,dp,leb0)) return false; } @@ -1432,7 +1432,7 @@ bool CollisionMath::Intersection_Test(const OBBoxClass & box,const TriClass & tr context.AE[2][2] = Vector3::Dot_Product(context.A[2],context.E[2]); if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -context.AN[0]; - leb0 = box.Extent[1]*WWMath::Fabs(context.AE[2][2]) + box.Extent[2]*WWMath::Fabs(context.AE[1][2]); + leb0 = box.Extent[1]*WWMath::Fabsf_Legacy(context.AE[2][2]) + box.Extent[2]*WWMath::Fabsf_Legacy(context.AE[1][2]); if (obbtri_check_intersection_cross_axis(context,dp,leb0)) return false; } @@ -1443,7 +1443,7 @@ bool CollisionMath::Intersection_Test(const OBBoxClass & box,const TriClass & tr context.TestAxis = context.AxE[1][0]; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = context.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[2][0]) + box.Extent[2]*WWMath::Fabs(context.AE[0][0]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(context.AE[2][0]) + box.Extent[2]*WWMath::Fabsf_Legacy(context.AE[0][0]); if (obbtri_check_intersection_cross_axis(context,dp,leb0)) return false; } @@ -1454,7 +1454,7 @@ bool CollisionMath::Intersection_Test(const OBBoxClass & box,const TriClass & tr context.TestAxis = context.AxE[1][1]; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -context.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[2][1]) + box.Extent[2]*WWMath::Fabs(context.AE[0][1]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(context.AE[2][1]) + box.Extent[2]*WWMath::Fabsf_Legacy(context.AE[0][1]); if (obbtri_check_intersection_cross_axis(context,dp,leb0)) return false; } @@ -1466,7 +1466,7 @@ bool CollisionMath::Intersection_Test(const OBBoxClass & box,const TriClass & tr context.AE[0][2] = Vector3::Dot_Product(context.A[0],context.E[2]); if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -context.AN[1]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[2][2]) + box.Extent[2]*WWMath::Fabs(context.AE[0][2]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(context.AE[2][2]) + box.Extent[2]*WWMath::Fabsf_Legacy(context.AE[0][2]); if (obbtri_check_intersection_cross_axis(context,dp,leb0)) return false; } @@ -1477,7 +1477,7 @@ bool CollisionMath::Intersection_Test(const OBBoxClass & box,const TriClass & tr context.TestAxis = context.AxE[2][0]; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = context.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[1][0]) + box.Extent[1]*WWMath::Fabs(context.AE[0][0]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(context.AE[1][0]) + box.Extent[1]*WWMath::Fabsf_Legacy(context.AE[0][0]); if (obbtri_check_intersection_cross_axis(context,dp,leb0)) return false; } @@ -1488,7 +1488,7 @@ bool CollisionMath::Intersection_Test(const OBBoxClass & box,const TriClass & tr context.TestAxis = context.AxE[2][1]; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -context.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[1][1]) + box.Extent[1]*WWMath::Fabs(context.AE[0][1]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(context.AE[1][1]) + box.Extent[1]*WWMath::Fabsf_Legacy(context.AE[0][1]); if (obbtri_check_intersection_cross_axis(context,dp,leb0)) return false; } @@ -1499,7 +1499,7 @@ bool CollisionMath::Intersection_Test(const OBBoxClass & box,const TriClass & tr context.TestAxis = context.AxE[2][2]; if (context.TestAxis.Length2() > AXISLEN_EPSILON2) { dp = -context.AN[2]; - leb0 = box.Extent[0]*WWMath::Fabs(context.AE[1][2]) + box.Extent[1]*WWMath::Fabs(context.AE[0][2]); + leb0 = box.Extent[0]*WWMath::Fabsf_Legacy(context.AE[1][2]) + box.Extent[1]*WWMath::Fabsf_Legacy(context.AE[0][2]); if (obbtri_check_intersection_cross_axis(context,dp,leb0)) return false; } diff --git a/Core/Libraries/Source/WWVegas/WWMath/colmathsphere.cpp b/Core/Libraries/Source/WWVegas/WWMath/colmathsphere.cpp index fb024348cea..84e8cf1e4af 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/colmathsphere.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/colmathsphere.cpp @@ -75,9 +75,9 @@ bool CollisionMath::Intersection_Test(const SphereClass & sphere,const AABoxClas ** against a cube which encloses the sphere... */ Vector3 dc = box.Center - sphere.Center; - if (WWMath::Fabs(dc.X) < box.Extent.X + sphere.Radius) return false; - if (WWMath::Fabs(dc.Y) < box.Extent.Y + sphere.Radius) return false; - if (WWMath::Fabs(dc.Z) < box.Extent.Z + sphere.Radius) return false; + if (WWMath::Fabsf_Legacy(dc.X) < box.Extent.X + sphere.Radius) return false; + if (WWMath::Fabsf_Legacy(dc.Y) < box.Extent.Y + sphere.Radius) return false; + if (WWMath::Fabsf_Legacy(dc.Z) < box.Extent.Z + sphere.Radius) return false; return true; } @@ -103,9 +103,9 @@ bool CollisionMath::Intersection_Test(const SphereClass & sphere,const OBBoxClas Vector3 box_rel_center; Matrix3D::Inverse_Transform_Vector(tm,sphere.Center,&box_rel_center); - if (box.Extent.X < WWMath::Fabs(box_rel_center.X)) return false; - if (box.Extent.Y < WWMath::Fabs(box_rel_center.Y)) return false; - if (box.Extent.Z < WWMath::Fabs(box_rel_center.Z)) return false; + if (box.Extent.X < WWMath::Fabsf_Legacy(box_rel_center.X)) return false; + if (box.Extent.Y < WWMath::Fabsf_Legacy(box_rel_center.Y)) return false; + if (box.Extent.Z < WWMath::Fabsf_Legacy(box_rel_center.Z)) return false; return true; } diff --git a/Core/Libraries/Source/WWVegas/WWMath/euler.cpp b/Core/Libraries/Source/WWVegas/WWMath/euler.cpp index 4f9f5f07a9c..d03dc15826e 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/euler.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/euler.cpp @@ -180,7 +180,7 @@ void EulerAnglesClass::From_Matrix(const Matrix3D & M, int order) _euler_unpack_order(order,i,j,k,h,n,s,f); if (s == EULER_REPEAT_YES) { - double sy = sqrt(M[i][j]*M[i][j] + M[i][k]*M[i][k]); + float sy = WWMath::Sqrt(M[i][j]*M[i][j] + M[i][k]*M[i][k]); if (sy > 16*FLT_EPSILON) { @@ -197,7 +197,7 @@ void EulerAnglesClass::From_Matrix(const Matrix3D & M, int order) } else { - double cy = sqrt(M[i][i]*M[i][i] + M[j][i]*M[j][i]); + float cy = WWMath::Sqrt(M[i][i]*M[i][i] + M[j][i]*M[j][i]); if (cy > 16*FLT_EPSILON) { @@ -284,8 +284,8 @@ void EulerAnglesClass::To_Matrix(Matrix3D & M) } ti = a0; tj = a1; th = a2; - ci = WWMath::Cos(ti); cj = WWMath::Cos(tj); ch = WWMath::Cos(th); - si = WWMath::Sin(ti); sj = WWMath::Sin(tj); sh = WWMath::Sin(th); + ci = WWMath::Cosf_Legacy(ti); cj = WWMath::Cosf_Legacy(tj); ch = WWMath::Cosf_Legacy(th); + si = WWMath::Sinf_Legacy(ti); sj = WWMath::Sinf_Legacy(tj); sh = WWMath::Sinf_Legacy(th); cc = ci*ch; cs = ci*sh; diff --git a/Core/Libraries/Source/WWVegas/WWMath/lookuptable.h b/Core/Libraries/Source/WWVegas/WWMath/lookuptable.h index 5cba6a0e2c2..0eb6d064c35 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/lookuptable.h +++ b/Core/Libraries/Source/WWVegas/WWMath/lookuptable.h @@ -86,7 +86,7 @@ inline float LookupTableClass::Get_Value(float input) } float normalized_input = (float)(OutputSamples.Length()-1) * (input - MinInputValue) * OOMaxMinusMin; - float input0 = WWMath::Floor(normalized_input); + float input0 = WWMath::Floorf(normalized_input); int index0 = WWMath::Float_To_Long(input0); int index1 = index0+1; diff --git a/Core/Libraries/Source/WWVegas/WWMath/matrix3.cpp b/Core/Libraries/Source/WWVegas/WWMath/matrix3.cpp index fa85c2396bf..c0b15e44186 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/matrix3.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/matrix3.cpp @@ -338,9 +338,9 @@ int Matrix3x3::Is_Orthogonal() const if (Vector3::Dot_Product(y,z) > WWMATH_EPSILON) return 0; if (Vector3::Dot_Product(z,x) > WWMATH_EPSILON) return 0; - if (WWMath::Fabs(x.Length() - 1.0f) > WWMATH_EPSILON) return 0; - if (WWMath::Fabs(y.Length() - 1.0f) > WWMATH_EPSILON) return 0; - if (WWMath::Fabs(z.Length() - 1.0f) > WWMATH_EPSILON) return 0; + if (WWMath::Fabsf_Legacy(x.Length() - 1.0f) > WWMATH_EPSILON) return 0; + if (WWMath::Fabsf_Legacy(y.Length() - 1.0f) > WWMATH_EPSILON) return 0; + if (WWMath::Fabsf_Legacy(z.Length() - 1.0f) > WWMATH_EPSILON) return 0; return 1; } diff --git a/Core/Libraries/Source/WWVegas/WWMath/matrix3.h b/Core/Libraries/Source/WWVegas/WWMath/matrix3.h index 22fb3bbb5e7..610a1db0a30 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/matrix3.h +++ b/Core/Libraries/Source/WWVegas/WWMath/matrix3.h @@ -366,7 +366,7 @@ WWINLINE void Matrix3x3::Set(const Vector3 & axis,float angle) WWINLINE void Matrix3x3::Set(const Vector3 & axis,float s,float c) { - WWASSERT(WWMath::Fabs(axis.Length2() - 1.0f) < 0.001f); + WWASSERT(WWMath::Fabsf_Legacy(axis.Length2() - 1.0f) < 0.001f); Row[0].Set( (float)(axis[0]*axis[0] + c*(1.0f - axis[0]*axis[0])), @@ -437,7 +437,7 @@ WWINLINE Matrix3x3 Matrix3x3::Inverse() const // Gauss-Jordan elimination wit // Find largest pivot in column j among rows j..3 i1 = j; for (i=j+1; i<3; i++) { - if (WWMath::Fabs(a[i][j]) > WWMath::Fabs(a[i1][j])) { + if (WWMath::Fabsf_Legacy(a[i][j]) > WWMath::Fabsf_Legacy(a[i1][j])) { i1 = i; } } @@ -1018,7 +1018,7 @@ WWINLINE void Matrix3x3::Rotate_AABox_Extent(const Vector3 & extent,Vector3 * se (*set_extent)[i] = 0.0f; for (int j=0; j<3; j++) { - (*set_extent)[i] += WWMath::Fabs(Row[i][j] * extent[j]); + (*set_extent)[i] += WWMath::Fabsf_Legacy(Row[i][j] * extent[j]); } } } diff --git a/Core/Libraries/Source/WWVegas/WWMath/matrix3d.cpp b/Core/Libraries/Source/WWVegas/WWMath/matrix3d.cpp index 5f2c886884a..47458073918 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/matrix3d.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/matrix3d.cpp @@ -1121,7 +1121,7 @@ void Matrix3D::Transform_Center_Extent_AABox for (int j=0; j<3; j++) { (*set_center)[i] += Row[i][j] * center[j]; - (*set_extent)[i] += WWMath::Fabs(Row[i][j] * extent[j]); + (*set_extent)[i] += WWMath::Fabsf_Legacy(Row[i][j] * extent[j]); } } @@ -1150,9 +1150,9 @@ int Matrix3D::Is_Orthogonal() const if (Vector3::Dot_Product(y,z) > WWMATH_EPSILON) return 0; if (Vector3::Dot_Product(z,x) > WWMATH_EPSILON) return 0; - if (WWMath::Fabs(x.Length2() - 1.0f) > WWMATH_EPSILON) return 0; - if (WWMath::Fabs(y.Length2() - 1.0f) > WWMATH_EPSILON) return 0; - if (WWMath::Fabs(z.Length2() - 1.0f) > WWMATH_EPSILON) return 0; + if (WWMath::Fabsf_Legacy(x.Length2() - 1.0f) > WWMATH_EPSILON) return 0; + if (WWMath::Fabsf_Legacy(y.Length2() - 1.0f) > WWMATH_EPSILON) return 0; + if (WWMath::Fabsf_Legacy(z.Length2() - 1.0f) > WWMATH_EPSILON) return 0; return 1; } diff --git a/Core/Libraries/Source/WWVegas/WWMath/matrix3d.h b/Core/Libraries/Source/WWVegas/WWMath/matrix3d.h index 658d1a09ac8..f22898cc4b1 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/matrix3d.h +++ b/Core/Libraries/Source/WWVegas/WWMath/matrix3d.h @@ -586,7 +586,7 @@ WWINLINE void Matrix3D::Set(const Vector3 & axis,float angle) *=============================================================================================*/ WWINLINE void Matrix3D::Set(const Vector3 & axis,float s,float c) { - assert(WWMath::Fabs(axis.Length2() - 1.0f) < 0.001f); + assert(WWMath::Fabsf_Legacy(axis.Length2() - 1.0f) < 0.001f); Row[0].Set( (float)(axis[0]*axis[0] + c*(1.0f - axis[0]*axis[0])), diff --git a/Core/Libraries/Source/WWVegas/WWMath/obbox.cpp b/Core/Libraries/Source/WWVegas/WWMath/obbox.cpp index 68aa7c48456..b6f82984c17 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/obbox.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/obbox.cpp @@ -161,13 +161,13 @@ OBBoxClass::OBBoxClass(const Vector3 * /*points*/, int /*n*/) float dx = pt[i].x - box.center.x; float dy = pt[i].y - box.center.y; float dz = pt[i].z - box.center.z; - float absdot = float(WWMath::Fabs(U.x*dx+U.y*dy+U.z*dz)); + float absdot = float(WWMath::Fabsf(U.x*dx+U.y*dy+U.z*dz)); if ( absdot > amax ) amax = absdot; - absdot = float(WWMath::Fabs(V.x*dx+V.y*dy+V.z*dz)); + absdot = float(WWMath::Fabsf(V.x*dx+V.y*dy+V.z*dz)); if ( absdot > bmax ) bmax = absdot; - absdot = float(WWMath::Fabs(W.x*dx+W.y*dy+W.z*dz)); + absdot = float(WWMath::Fabsf(W.x*dx+W.y*dy+W.z*dz)); if ( absdot > cmax ) cmax = absdot; } @@ -264,13 +264,13 @@ void OBBoxClass::Init_From_Box_Points(Vector3 * points,int num) float dy = points[i].Y - Center.Y; float dz = points[i].Z - Center.Z; - float xprj = float(WWMath::Fabs(axis0.X * dx + axis0.Y * dy + axis0.Z * dz)); + float xprj = float(WWMath::Fabsf_Legacy(axis0.X * dx + axis0.Y * dy + axis0.Z * dz)); if (xprj > Extent.X) Extent.X = xprj; - float yprj = float(WWMath::Fabs(axis1.X * dx + axis1.Y * dy + axis1.Z * dz)); + float yprj = float(WWMath::Fabsf_Legacy(axis1.X * dx + axis1.Y * dy + axis1.Z * dz)); if (yprj > Extent.Y) Extent.Y = yprj; - float zprj = float(WWMath::Fabs(axis2.X * dx + axis2.Y * dy + axis2.Z * dz)); + float zprj = float(WWMath::Fabsf_Legacy(axis2.X * dx + axis2.Y * dy + axis2.Z * dz)); if (zprj > Extent.Z) Extent.Z = zprj; } } @@ -334,7 +334,7 @@ bool Oriented_Boxes_Intersect_On_Axis ra = box0.Project_To_Axis(axis); rb = box1.Project_To_Axis(axis); - rsum = WWMath::Fabs(ra) + WWMath::Fabs(rb); + rsum = WWMath::Fabsf_Legacy(ra) + WWMath::Fabsf_Legacy(rb); // project the center distance onto the line: Vector3 C = box1.Center - box0.Center; @@ -456,7 +456,7 @@ bool Oriented_Boxes_Collide_On_Axis ra = box0.Project_To_Axis(axis); rb = box1.Project_To_Axis(axis); - rsum = WWMath::Fabs(ra) + WWMath::Fabs(rb); + rsum = WWMath::Fabsf_Legacy(ra) + WWMath::Fabsf_Legacy(rb); // project the center distance onto the line: Vector3 C = box1.Center - box0.Center; diff --git a/Core/Libraries/Source/WWVegas/WWMath/obbox.h b/Core/Libraries/Source/WWVegas/WWMath/obbox.h index 83c3ff2686b..5199059c14d 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/obbox.h +++ b/Core/Libraries/Source/WWVegas/WWMath/obbox.h @@ -136,7 +136,7 @@ inline float OBBoxClass::Project_To_Axis(const Vector3 & axis) const float z = Extent[2] * Vector3::Dot_Product(axis,Vector3(Basis[0][2],Basis[1][2],Basis[2][2])); // projection is the sum of the absolute values of the projections of the three extents - return (WWMath::Fabs(x) + WWMath::Fabs(y) + WWMath::Fabs(z)); + return (WWMath::Fabsf_Legacy(x) + WWMath::Fabsf_Legacy(y) + WWMath::Fabsf_Legacy(z)); } @@ -214,17 +214,17 @@ inline void OBBoxClass::Compute_Axis_Aligned_Extent(Vector3 * set_extent) const WWASSERT(set_extent != nullptr); // x extent is the box projected onto the x axis - set_extent->X = WWMath::Fabs(Extent[0] * Basis[0][0]) + - WWMath::Fabs(Extent[1] * Basis[0][1]) + - WWMath::Fabs(Extent[2] * Basis[0][2]); + set_extent->X = WWMath::Fabsf_Legacy(Extent[0] * Basis[0][0]) + + WWMath::Fabsf_Legacy(Extent[1] * Basis[0][1]) + + WWMath::Fabsf_Legacy(Extent[2] * Basis[0][2]); - set_extent->Y = WWMath::Fabs(Extent[0] * Basis[1][0]) + - WWMath::Fabs(Extent[1] * Basis[1][1]) + - WWMath::Fabs(Extent[2] * Basis[1][2]); + set_extent->Y = WWMath::Fabsf_Legacy(Extent[0] * Basis[1][0]) + + WWMath::Fabsf_Legacy(Extent[1] * Basis[1][1]) + + WWMath::Fabsf_Legacy(Extent[2] * Basis[1][2]); - set_extent->Z = WWMath::Fabs(Extent[0] * Basis[2][0]) + - WWMath::Fabs(Extent[1] * Basis[2][1]) + - WWMath::Fabs(Extent[2] * Basis[2][2]); + set_extent->Z = WWMath::Fabsf_Legacy(Extent[0] * Basis[2][0]) + + WWMath::Fabsf_Legacy(Extent[1] * Basis[2][1]) + + WWMath::Fabsf_Legacy(Extent[2] * Basis[2][2]); } diff --git a/Core/Libraries/Source/WWVegas/WWMath/quat.cpp b/Core/Libraries/Source/WWVegas/WWMath/quat.cpp index 7dc48e91bdf..091e8514542 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/quat.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/quat.cpp @@ -87,8 +87,8 @@ static float project_to_sphere(float,float,float); *=============================================================================================*/ Quaternion::Quaternion(const Vector3 & axis,float angle) { - float s = WWMath::Sin(angle/2); - float c = WWMath::Cos(angle/2); + float s = WWMath::Sinf_Legacy(angle/2); + float c = WWMath::Cosf_Legacy(angle/2); X = s * axis.X; Y = s * axis.Y; Z = s * axis.Z; @@ -114,7 +114,7 @@ void Quaternion::Normalize() if (0.0f == len2) { return; } else { - float inv_mag = WWMath::Inv_Sqrt(len2); + float inv_mag = WWMath::Inv_Sqrt_Legacy(len2); X *= inv_mag; Y *= inv_mag; @@ -228,8 +228,8 @@ Quaternion Axis_To_Quat(const Vector3 &a, float phi) q[1] = tmp[1]; q[2] = tmp[2]; - q.Scale(WWMath::Sin(phi / 2.0f)); - q[3] = WWMath::Cos(phi / 2.0f); + q.Scale(WWMath::Sinf_Legacy(phi / 2.0f)); + q[3] = WWMath::Cosf_Legacy(phi / 2.0f); return q; } @@ -325,10 +325,10 @@ void __cdecl Fast_Slerp(Quaternion& res, const Quaternion & p,const Quaternion & // normal slerp! // else { // theta = WWMath::Acos(cos_t); -// sin_t = WWMath::Sin(theta); +// sin_t = WWMath::Sinf_Legacy(theta); // oo_sin_t = 1.0 / sin_t; -// beta = WWMath::Sin(theta - alpha*theta) * oo_sin_t; -// alpha = WWMath::Sin(alpha*theta) * oo_sin_t; +// beta = WWMath::Sinf_Legacy(theta - alpha*theta) * oo_sin_t; +// alpha = WWMath::Sinf_Legacy(alpha*theta) * oo_sin_t; // } // if (qflip) { // alpha = -alpha; @@ -513,10 +513,10 @@ void Slerp(Quaternion& res, const Quaternion & p,const Quaternion & q,float alph // normal slerp! theta = WWMath::Acos(cos_t); - float sin_t = WWMath::Sin(theta); + float sin_t = WWMath::Sinf_Legacy(theta); oo_sin_t = 1.0f / sin_t; - beta = WWMath::Sin(theta - alpha*theta) * oo_sin_t; - alpha = WWMath::Sin(alpha*theta) * oo_sin_t; + beta = WWMath::Sinf_Legacy(theta - alpha*theta) * oo_sin_t; + alpha = WWMath::Sinf_Legacy(alpha*theta) * oo_sin_t; } if (qflip) { @@ -568,7 +568,7 @@ void Slerp_Setup(const Quaternion & p,const Quaternion & q,SlerpInfoStruct * sle slerpinfo->Linear = false; slerpinfo->Theta = WWMath::Acos(cos_t); - slerpinfo->SinT = WWMath::Sin(slerpinfo->Theta); + slerpinfo->SinT = WWMath::Sinf_Legacy(slerpinfo->Theta); } } @@ -600,8 +600,8 @@ Quaternion Cached_Slerp(const Quaternion & p,const Quaternion & q,float alpha,Sl // normal slerp! oo_sin_t = 1.0f / slerpinfo->Theta; - beta = WWMath::Sin(slerpinfo->Theta - alpha*slerpinfo->Theta) * oo_sin_t; - alpha = WWMath::Sin(alpha*slerpinfo->Theta) * oo_sin_t; + beta = WWMath::Sinf_Legacy(slerpinfo->Theta - alpha*slerpinfo->Theta) * oo_sin_t; + alpha = WWMath::Sinf_Legacy(alpha*slerpinfo->Theta) * oo_sin_t; } if (slerpinfo->Flip) { @@ -632,8 +632,8 @@ void Cached_Slerp(const Quaternion & p,const Quaternion & q,float alpha,SlerpInf // normal slerp! oo_sin_t = 1.0f / slerpinfo->Theta; - beta = WWMath::Sin(slerpinfo->Theta - alpha*slerpinfo->Theta) * oo_sin_t; - alpha = WWMath::Sin(alpha*slerpinfo->Theta) * oo_sin_t; + beta = WWMath::Sinf_Legacy(slerpinfo->Theta - alpha*slerpinfo->Theta) * oo_sin_t; + alpha = WWMath::Sinf_Legacy(alpha*slerpinfo->Theta) * oo_sin_t; } if (slerpinfo->Flip) { diff --git a/Core/Libraries/Source/WWVegas/WWMath/quat.h b/Core/Libraries/Source/WWVegas/WWMath/quat.h index 6b9ef24e700..a1c6d36f75d 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/quat.h +++ b/Core/Libraries/Source/WWVegas/WWMath/quat.h @@ -277,10 +277,10 @@ WWINLINE bool Quaternion::Is_Valid() const WWINLINE bool Equal_Within_Epsilon(const Quaternion &a, const Quaternion &b, float epsilon) { - return( (WWMath::Fabs(a.X - b.X) < epsilon) && - (WWMath::Fabs(a.Y - b.Y) < epsilon) && - (WWMath::Fabs(a.Z - b.Z) < epsilon) && - (WWMath::Fabs(a.W - b.W) < epsilon) ); + return( (WWMath::Fabsf_Legacy(a.X - b.X) < epsilon) && + (WWMath::Fabsf_Legacy(a.Y - b.Y) < epsilon) && + (WWMath::Fabsf_Legacy(a.Z - b.Z) < epsilon) && + (WWMath::Fabsf_Legacy(a.W - b.W) < epsilon) ); } /*********************************************************************************************** diff --git a/Core/Libraries/Source/WWVegas/WWMath/tri.cpp b/Core/Libraries/Source/WWVegas/WWMath/tri.cpp index 854991cf587..5f8d1449306 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/tri.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/tri.cpp @@ -59,9 +59,9 @@ static inline void find_dominant_plane_fast(const TriClass & tri, FDPRec& info) /* ** Find the largest component of the normal */ - float x = WWMath::Fabs(tri.N->X); - float y = WWMath::Fabs(tri.N->Y); - float z = WWMath::Fabs(tri.N->Z); + float x = WWMath::Fabsf_Legacy(tri.N->X); + float y = WWMath::Fabsf_Legacy(tri.N->Y); + float z = WWMath::Fabsf_Legacy(tri.N->Z); float val = x; int ni = 0; @@ -86,9 +86,9 @@ static inline void find_dominant_plane(const TriClass & tri, int * axis1,int * a ** Find the largest component of the normal */ int ni = 0; - float x = WWMath::Fabs(tri.N->X); - float y = WWMath::Fabs(tri.N->Y); - float z = WWMath::Fabs(tri.N->Z); + float x = WWMath::Fabsf_Legacy(tri.N->X); + float y = WWMath::Fabsf_Legacy(tri.N->Y); + float z = WWMath::Fabsf_Legacy(tri.N->Z); float val = x; if (y > val) { @@ -146,9 +146,9 @@ void TriClass::Find_Dominant_Plane(int * axis1,int * axis2) const ** Find the largest component of the normal */ int ni = 0; - float x = WWMath::Fabs(N->X); - float y = WWMath::Fabs(N->Y); - float z = WWMath::Fabs(N->Z); + float x = WWMath::Fabsf_Legacy(N->X); + float y = WWMath::Fabsf_Legacy(N->Y); + float z = WWMath::Fabsf_Legacy(N->Z); float val = x; if (y > val) { diff --git a/Core/Libraries/Source/WWVegas/WWMath/v3_rnd.cpp b/Core/Libraries/Source/WWVegas/WWMath/v3_rnd.cpp index ebbd9bf572c..3b8e235fdd1 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/v3_rnd.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/v3_rnd.cpp @@ -118,7 +118,7 @@ void Vector3HollowSphereRandomizer::Get_Vector(Vector3 &vector) if (v_l2 <= 1.0f && v_l2 > 0.0f) break; } - float scale = Radius * WWMath::Inv_Sqrt(v_l2); + float scale = Radius * WWMath::Inv_Sqrt_Legacy(v_l2); vector.X *= scale; vector.Y *= scale; diff --git a/Core/Libraries/Source/WWVegas/WWMath/vector2.h b/Core/Libraries/Source/WWVegas/WWMath/vector2.h index 456e831a569..2fe734cee66 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/vector2.h +++ b/Core/Libraries/Source/WWVegas/WWMath/vector2.h @@ -309,7 +309,7 @@ WWINLINE bool operator != (const Vector2 &a,const Vector2 &b) *========================================================================*/ WWINLINE bool Equal_Within_Epsilon(const Vector2 &a,const Vector2 &b,float epsilon) { - return( (WWMath::Fabs(a.X - b.X) < epsilon) && (WWMath::Fabs(a.Y - b.Y) < epsilon) ); + return( (WWMath::Fabsf_Legacy(a.X - b.X) < epsilon) && (WWMath::Fabsf_Legacy(a.Y - b.Y) < epsilon) ); } /************************************************************************** @@ -327,7 +327,7 @@ WWINLINE void Vector2::Normalize() { float len2 = Length2(); if (len2 != 0.0f) { - float oolen = WWMath::Inv_Sqrt(len2); + float oolen = WWMath::Inv_Sqrt_Legacy(len2); X *= oolen; Y *= oolen; } @@ -337,7 +337,7 @@ WWINLINE Vector2 Normalize(const Vector2 & vec) { float len2 = vec.Length2(); if (len2 != 0.0f) { - float oolen = WWMath::Inv_Sqrt(len2); + float oolen = WWMath::Inv_Sqrt_Legacy(len2); return vec / oolen; } return Vector2(0.0f,0.0f); @@ -389,7 +389,7 @@ WWINLINE float Vector2::Length2() const *========================================================================*/ WWINLINE void Vector2::Rotate(float theta) { - Rotate(WWMath::Sin(theta), WWMath::Cos(theta)); + Rotate(WWMath::Sinf_Legacy(theta), WWMath::Cosf_Legacy(theta)); } /************************************************************************** @@ -429,7 +429,7 @@ WWINLINE void Vector2::Rotate(float s, float c) *========================================================================*/ WWINLINE bool Vector2::Rotate_Towards_Vector(Vector2 &target, float max_theta, bool & positive_turn) { - return Rotate_Towards_Vector(target, WWMath::Sin(max_theta), WWMath::Cos(max_theta), positive_turn); + return Rotate_Towards_Vector(target, WWMath::Sinf_Legacy(max_theta), WWMath::Cosf_Legacy(max_theta), positive_turn); } /************************************************************************** @@ -597,8 +597,8 @@ WWINLINE float Quick_Distance(float x1, float y1, float x2, float y2) float x_diff = x1 - x2; float y_diff = y1 - y2; - WWMath::Fabs(x_diff); - WWMath::Fabs(y_diff); + WWMath::Fabsf_Legacy(x_diff); + WWMath::Fabsf_Legacy(y_diff); if (x_diff > y_diff) { diff --git a/Core/Libraries/Source/WWVegas/WWMath/vector3.h b/Core/Libraries/Source/WWVegas/WWMath/vector3.h index e1cb8ed4383..3a74fd91e04 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/vector3.h +++ b/Core/Libraries/Source/WWVegas/WWMath/vector3.h @@ -343,9 +343,9 @@ WWINLINE bool operator != (const Vector3 &a,const Vector3 &b) *========================================================================*/ WWINLINE bool Equal_Within_Epsilon(const Vector3 &a,const Vector3 &b,float epsilon) { - return( (WWMath::Fabs(a.X - b.X) < epsilon) && - (WWMath::Fabs(a.Y - b.Y) < epsilon) && - (WWMath::Fabs(a.Z - b.Z) < epsilon) ); + return( (WWMath::Fabsf_Legacy(a.X - b.X) < epsilon) && + (WWMath::Fabsf_Legacy(a.Y - b.Y) < epsilon) && + (WWMath::Fabsf_Legacy(a.Z - b.Z) < epsilon) ); } @@ -419,7 +419,7 @@ WWINLINE void Vector3::Normalize() float len2 = Length2(); if (len2 != 0.0f) { - float oolen = WWMath::Inv_Sqrt(len2); + float oolen = WWMath::Inv_Sqrt_Legacy(len2); X *= oolen; Y *= oolen; Z *= oolen; @@ -432,7 +432,7 @@ WWINLINE Vector3 Normalize(const Vector3 & vec) float len2 = vec.Length2(); if (len2 != 0.0f) { - float oolen = WWMath::Inv_Sqrt(len2); + float oolen = WWMath::Inv_Sqrt_Legacy(len2); return vec * oolen; } return vec; @@ -488,9 +488,9 @@ WWINLINE float Vector3::Quick_Length() const { // this method of approximating the length comes from Graphics Gems 1 and // supposedly gives an error of +/- 8% - float max = WWMath::Fabs(X); - float mid = WWMath::Fabs(Y); - float min = WWMath::Fabs(Z); + float max = WWMath::Fabsf_Legacy(X); + float mid = WWMath::Fabsf_Legacy(Y); + float min = WWMath::Fabsf_Legacy(Z); float tmp; if (max < mid) { tmp = max; max = mid; mid = tmp; } diff --git a/Core/Libraries/Source/WWVegas/WWMath/vector4.h b/Core/Libraries/Source/WWVegas/WWMath/vector4.h index c0bc336ac9c..21601bc4f25 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/vector4.h +++ b/Core/Libraries/Source/WWVegas/WWMath/vector4.h @@ -272,7 +272,7 @@ WWINLINE void Vector4::Normalize() { float len2 = Length2(); if (len2 != 0.0f) { - float oolen = WWMath::Inv_Sqrt(len2); + float oolen = WWMath::Inv_Sqrt_Legacy(len2); X *= oolen; Y *= oolen; Z *= oolen; @@ -284,7 +284,7 @@ WWINLINE Vector4 Normalize(const Vector4 & vec) { float len2 = vec.Length2(); if (len2 != 0.0f) { - float oolen = WWMath::Inv_Sqrt(len2); + float oolen = WWMath::Inv_Sqrt_Legacy(len2); return vec * oolen; } return Vector4(0.0f,0.0f,0.0f,0.0f); diff --git a/Core/Libraries/Source/WWVegas/WWMath/vehiclecurve.cpp b/Core/Libraries/Source/WWVegas/WWMath/vehiclecurve.cpp index ddacd48b50e..d92aa0a09c2 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/vehiclecurve.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/vehiclecurve.cpp @@ -197,8 +197,8 @@ Find_Turn_Arc // Find the shortest delta between the two angles (either clockwise or // counterclockwise). // - float delta1 = WWMath::Fabs (::Get_Angle_Delta (angle1, angle2, true)); - float delta2 = WWMath::Fabs (::Get_Angle_Delta (angle1, angle2, false)); + float delta1 = WWMath::Fabsf_Legacy (::Get_Angle_Delta (angle1, angle2, true)); + float delta2 = WWMath::Fabsf_Legacy (::Get_Angle_Delta (angle1, angle2, false)); if (delta1 < delta2) { avg_angle = angle1 - (delta1 * 0.5F); } else { @@ -208,8 +208,8 @@ Find_Turn_Arc // // Find the point on the circle at this angle // - arc_center->X = curr_pt.X + (radius * ::WWMath::Cos (avg_angle)); - arc_center->Y = curr_pt.Y + (radius * ::WWMath::Sin (avg_angle)); + arc_center->X = curr_pt.X + (radius * ::WWMath::Cosf_Legacy (avg_angle)); + arc_center->Y = curr_pt.Y + (radius * ::WWMath::Sinf_Legacy (avg_angle)); arc_center->Z = curr_pt.Z; // @@ -378,12 +378,12 @@ VehicleCurveClass::Update_Arc_List () // Determine at what points these angles intersect the arc // Vector3 point_in (0, 0, 0); - point_in.X = arc_center.X + (m_Radius * ::WWMath::Sin (point_angle + angle_in_delta)); - point_in.Y = arc_center.Y + (m_Radius * -::WWMath::Cos (point_angle + angle_in_delta)); + point_in.X = arc_center.X + (m_Radius * ::WWMath::Sinf_Legacy (point_angle + angle_in_delta)); + point_in.Y = arc_center.Y + (m_Radius * -::WWMath::Cosf_Legacy (point_angle + angle_in_delta)); Vector3 point_out (0, 0, 0); - point_out.X = arc_center.X + (m_Radius * ::WWMath::Sin (point_angle + angle_out_delta)); - point_out.Y = arc_center.Y + (m_Radius * -::WWMath::Cos (point_angle + angle_out_delta)); + point_out.X = arc_center.X + (m_Radius * ::WWMath::Sinf_Legacy (point_angle + angle_out_delta)); + point_out.Y = arc_center.Y + (m_Radius * -::WWMath::Cosf_Legacy (point_angle + angle_out_delta)); // // Sanity check to ensure the vehicle doesn't try to go the long way around the @@ -489,8 +489,8 @@ VehicleCurveClass::Evaluate (float time, Vector3 *set_val) // - Straight line from exit of last curve to enter of this curve // - Enter curve for the current point // - float arc_length0 = arc_info0.radius * WWMath::Fabs (arc_info0.angle_out_delta); - float arc_length1 = arc_info1.radius * WWMath::Fabs (arc_info1.angle_in_delta); + float arc_length0 = arc_info0.radius * WWMath::Fabsf_Legacy (arc_info0.angle_out_delta); + float arc_length1 = arc_info1.radius * WWMath::Fabsf_Legacy (arc_info1.angle_in_delta); float other_length = ((arc_info1.point_in - arc_info0.point_out).Length ()) / 2; float total_length = arc_length0 + arc_length1 + other_length; @@ -513,10 +513,10 @@ VehicleCurveClass::Evaluate (float time, Vector3 *set_val) //float angle = arc_info0.point_angle + (arc_info0.angle_out_delta) * percent; float angle = arc_info0.point_angle + arc_info0.angle_out_delta; - set_val->X = arc_info0.center.X + (arc_info0.radius * ::WWMath::Sin (angle)); - set_val->Y = arc_info0.center.Y + (arc_info0.radius * -::WWMath::Cos (angle)); + set_val->X = arc_info0.center.X + (arc_info0.radius * ::WWMath::Sinf_Legacy (angle)); + set_val->Y = arc_info0.center.Y + (arc_info0.radius * -::WWMath::Cosf_Legacy (angle)); - m_Sharpness = WWMath::Clamp (WWMath::Fabs (arc_info0.angle_out_delta) / DEG_TO_RADF (15), 0, 1.0F); + m_Sharpness = WWMath::Clamp (WWMath::Fabsf_Legacy (arc_info0.angle_out_delta) / DEG_TO_RADF (15), 0, 1.0F); m_SharpnessPos.X = set_val->X; m_SharpnessPos.Y = set_val->Y; m_SharpnessPos.Z = Keys[index0].Point.Z + (Keys[index1].Point.Z - Keys[index0].Point.Z) * seg_time; @@ -542,7 +542,7 @@ VehicleCurveClass::Evaluate (float time, Vector3 *set_val) //set_val->X = arc_info0.point_out.X + (arc_info1.point_in.X - arc_info0.point_out.X) * percent; //set_val->Y = arc_info0.point_out.Y + (arc_info1.point_in.Y - arc_info0.point_out.Y) * percent; - m_Sharpness = WWMath::Clamp (WWMath::Fabs (arc_info1.angle_out_delta) / DEG_TO_RADF (15), 0, 1.0F); + m_Sharpness = WWMath::Clamp (WWMath::Fabsf_Legacy (arc_info1.angle_out_delta) / DEG_TO_RADF (15), 0, 1.0F); m_SharpnessPos = arc_info1.point_in; m_LastTime = Keys[index0].Time + (Keys[index1].Time - Keys[index0].Time) * time2; @@ -556,15 +556,15 @@ VehicleCurveClass::Evaluate (float time, Vector3 *set_val) /*float percent = 1.0F - ((seg_time - time2) / (1.0F - time2)); float angle = arc_info1.point_angle + (arc_info1.angle_in_delta * percent); - set_val->X = arc_info1.center.X + (arc_info1.radius * ::WWMath::Sin (angle)); - set_val->Y = arc_info1.center.Y + (arc_info1.radius * -::WWMath::Cos (angle)); */ + set_val->X = arc_info1.center.X + (arc_info1.radius * ::WWMath::Sinf_Legacy (angle)); + set_val->Y = arc_info1.center.Y + (arc_info1.radius * -::WWMath::Cosf_Legacy (angle)); */ float angle = arc_info1.point_angle + (arc_info1.angle_out_delta); - set_val->X = arc_info1.center.X + (arc_info1.radius * ::WWMath::Sin (angle)); - set_val->Y = arc_info1.center.Y + (arc_info1.radius * -::WWMath::Cos (angle)); + set_val->X = arc_info1.center.X + (arc_info1.radius * ::WWMath::Sinf_Legacy (angle)); + set_val->Y = arc_info1.center.Y + (arc_info1.radius * -::WWMath::Cosf_Legacy (angle)); - m_Sharpness = WWMath::Clamp (WWMath::Fabs (arc_info1.angle_out_delta) / DEG_TO_RADF (15), 0, 1.0F); + m_Sharpness = WWMath::Clamp (WWMath::Fabsf_Legacy (arc_info1.angle_out_delta) / DEG_TO_RADF (15), 0, 1.0F); m_SharpnessPos.X = set_val->X; m_SharpnessPos.Y = set_val->Y; m_SharpnessPos.Z = Keys[index0].Point.Z + (Keys[index1].Point.Z - Keys[index0].Point.Z) * seg_time; diff --git a/Core/Libraries/Source/WWVegas/WWMath/wwmath.cpp b/Core/Libraries/Source/WWVegas/WWMath/wwmath.cpp index 526d1556650..62e29520f38 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/wwmath.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/wwmath.cpp @@ -55,13 +55,22 @@ void WWMath::Init() int a=0; for (;a0) { _FastInvSinTable[a]=1.0f/_FastSinTable[a]; diff --git a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h index 1f0f6e38466..ae26451e3ca 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h +++ b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h @@ -40,12 +40,18 @@ #include #include #include +#include "Lib/BaseDefines.h" + +#if USE_DETERMINISTIC_MATH +#include "gmath.h" +#endif /* ** Some global constants. */ #define WWMATH_EPSILON 0.0001f #define WWMATH_EPSILON2 WWMATH_EPSILON * WWMATH_EPSILON +#define WWMATH_HALF_PI 1.570796327f #define WWMATH_PI 3.141592654f #define WWMATH_TWO_PI 6.283185308f #define WWMATH_FLOAT_MAX (FLT_MAX) @@ -86,6 +92,7 @@ extern float _FastInvSinTable[SIN_TABLE_SIZE]; ** Include the various other header files in the WWMATH library ** in order to get matrices, quaternions, etc. */ +// TheSuperHackers @todo The Legacy functions can be removed when retail compatibility is abandoned. class WWMath { public: @@ -95,29 +102,75 @@ class WWMath static void Init(); static void Shutdown(); -static WWINLINE float Sqrt(float val); -static WWINLINE float Inv_Sqrt(float a); +// The float overloads of Sqrt, Acos, Asin, Atan, Atan2, Cos, Sin, Tan and Fabs keep a float argument +// from being promoted to the double overload. With deterministic math they call the single-precision +// GameMath functions (gm_*f), which are guaranteed to be cross-platform bit-identical, whereas the +// double-precision ones (gm_*) can diverge by 1 ULP due to FPU precision differences (x87 vs NEON). +static WWINLINE double Pow(double x, double y); +static WWINLINE float Powf(float x, float y); +static WWINLINE float Sqrt(float x); +static WWINLINE double Sqrt(double x); +static WWINLINE float Sqrtf(float x); +static WWINLINE float Inv_Sqrt_Legacy(float a); +static WWINLINE double Inv_Sqrt(double x); +static WWINLINE float Inv_Sqrtf(float x); static WWINLINE float Fast_Acos(float val); static WWINLINE float Fast_Asin(float val); -static WWINLINE float Acos(float val); -static WWINLINE float Asin(float val); +static WWINLINE float Acos(float x); +static WWINLINE double Acos(double x); +static WWINLINE float Acosf(float x); +static WWINLINE float Asin(float x); +static WWINLINE double Asin(double x); +static WWINLINE float Asinf(float x); static WWINLINE float Atan(float x); -static WWINLINE float Atan2(float y, float x); +static WWINLINE double Atan(double x); +static WWINLINE float Atanf(float x); +static WWINLINE float Atan2(float x, float y); +static WWINLINE double Atan2(double x, double y); +static WWINLINE float Atan2f(float x, float y); static WWINLINE float Fast_Cos(float val); static WWINLINE float Fast_Inv_Cos(float val); static WWINLINE float Fast_Sin(float val); static WWINLINE float Fast_Inv_Sin(float val); static WWINLINE float Cos(float val); +static WWINLINE double Cos(double val); +static WWINLINE float Cosf(float val); +static WWINLINE float Cosf_Legacy(float val); static WWINLINE float Sin(float val); - -static WWINLINE float Fabs(float val); - -static WWINLINE float Ceil(float val); -static WWINLINE float Floor(float val); -static WWINLINE float Round(float val) { return floorf(val + 0.5f); } -static WWINLINE float Sign(float val); +static WWINLINE double Sin(double val); +static WWINLINE float Sinf(float val); +static WWINLINE float Sinf_Legacy(float val); +static WWINLINE float Tan(float x); +static WWINLINE double Tan(double x); +static WWINLINE float Tanf(float x); + +static WWINLINE double Cosh(double x); +static WWINLINE float Coshf(float x); +static WWINLINE double Sinh(double x); +static WWINLINE float Sinhf(float x); +static WWINLINE double Tanh(double x); +static WWINLINE float Tanhf(float x); + +static WWINLINE float Fabs(float x); +static WWINLINE double Fabs(double x); +static WWINLINE float Fabsf(float x); +static WWINLINE float Fabsf_Legacy(float val); + +static WWINLINE double Ceil(double x); +static WWINLINE float Ceilf(float x); +static WWINLINE double Floor(double x); +static WWINLINE float Floorf(float x); +static WWINLINE double Round(double x) { return Floor(x + 0.5); } +static WWINLINE float Roundf(float x) { return Floorf(x + 0.5f); } + +static WWINLINE double Exp(double x); +static WWINLINE float Expf(float x); +static WWINLINE double Log10(double x); +static WWINLINE float Log10f(float x); +static WWINLINE double Log(double x); +static WWINLINE float Logf(float x); static WWINLINE bool Fast_Is_Float_Positive(const float & val); static WWINLINE bool Is_Power_Of_2(const unsigned int val); @@ -146,8 +199,8 @@ static WWINLINE double Inverse_Lerp(double a, double b, float v); static WWINLINE bool Is_Valid_Float(float x); static WWINLINE bool Is_Valid_Double(double x); -static WWINLINE int Float_To_Int_Chop(const float& f); -static WWINLINE int Float_To_Int_Floor(const float& f); +static WWINLINE int Float_To_Int_Chop(float f); +static WWINLINE int Float_To_Int_Floor(float f); static WWINLINE long Float_To_Long(float f); static WWINLINE long Float_To_Long(double f); static WWINLINE int Float_As_Int(const float f) { return *((int*)&f); } @@ -156,27 +209,62 @@ static WWINLINE float Byte_To_Unit_Float(unsigned char byte) { return ((float)by static WWINLINE float Normalize_Angle(float angle); // Normalizes the angle to the range -PI..PI +static WWINLINE float Div_Safe(float dividend, float divisor, float epsilon = WWMATH_EPSILON); +static WWINLINE double Div_Safe(double dividend, double divisor, double epsilon = WWMATH_EPSILON); + }; -WWINLINE float WWMath::Sqrt(float val) +WWINLINE double WWMath::Pow(double x, double y) { -#if defined(_MSC_VER) && defined(_M_IX86) - float retval; - __asm { - fld [val] - fsqrt - fstp [retval] - } - return retval; +#if USE_DETERMINISTIC_MATH + return (double)gm_powf((float)x, (float)y); // gm_pow diverges on x87, gm_powf is bit-identical +#else + return pow(x, y); +#endif +} + +WWINLINE float WWMath::Powf(float x, float y) +{ +#if USE_DETERMINISTIC_MATH + return gm_powf(x, y); +#else + return powf(x, y); +#endif +} +WWINLINE float WWMath::Sqrt(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_sqrtf(x); +#else + return sqrtf(x); +#endif +} + +WWINLINE double WWMath::Sqrt(double x) +{ +#if USE_DETERMINISTIC_MATH + return gm_sqrt(x); +#else + return sqrt(x); +#endif +} + +WWINLINE float WWMath::Sqrtf(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_sqrtf(x); #else - return (float)sqrt(val); + return sqrtf(x); #endif } -WWINLINE float WWMath::Inv_Sqrt(float a) +WWINLINE float WWMath::Inv_Sqrt_Legacy(float a) { -#if defined(_MSC_VER) && defined(_M_IX86) +#if USE_DETERMINISTIC_MATH + return 1.0f / gm_sqrtf(a); + +#elif defined(_MSC_VER) && defined(_M_IX86) // Some 30% faster inverse square root than regular C++ compiled, from Intel's math library float retval; @@ -227,14 +315,24 @@ WWINLINE float WWMath::Inv_Sqrt(float a) return retval; #else - return 1.0f / (float)sqrt(a); + return 1.0f / (float)sqrt((double)a); #endif } +WWINLINE double WWMath::Inv_Sqrt(double x) +{ + return 1.0 / Sqrt(x); +} + +WWINLINE float WWMath::Inv_Sqrtf(float x) +{ + return 1.0f / Sqrtf(x); +} + WWINLINE float WWMath::Fast_Acos(float val) { // Near -1 and +1, the table becomes too inaccurate - if (Fabs(val) > 0.975f) { + if (Fabsf_Legacy(val) > 0.975f) { return Acos(val); } @@ -258,7 +356,7 @@ WWINLINE float WWMath::Fast_Acos(float val) WWINLINE float WWMath::Fast_Asin(float val) { // Near -1 and +1, the table becomes too inaccurate - if (Fabs(val) > 0.975f) { + if (Fabsf_Legacy(val) > 0.975f) { return Asin(val); } @@ -279,24 +377,112 @@ WWINLINE float WWMath::Fast_Asin(float val) return (1.0f - frac) * _FastAsinTable[idx0] + frac * _FastAsinTable[idx1]; } -WWINLINE float WWMath::Acos(float val) +WWINLINE float WWMath::Acos(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_acosf(x); +#else + return (float)acos((double)x); +#endif +} + +WWINLINE double WWMath::Acos(double x) +{ +#if USE_DETERMINISTIC_MATH + return gm_acos(x); +#else + return acos(x); +#endif +} + +WWINLINE float WWMath::Acosf(float x) { - return (float)acos(val); +#if USE_DETERMINISTIC_MATH + return gm_acosf(x); +#else + return acosf(x); +#endif } -WWINLINE float WWMath::Asin(float val) +WWINLINE float WWMath::Asin(float x) { - return (float)asin(val); +#if USE_DETERMINISTIC_MATH + return gm_asinf(x); +#else + return (float)asin((double)x); +#endif +} + +WWINLINE double WWMath::Asin(double x) +{ +#if USE_DETERMINISTIC_MATH + return gm_asin(x); +#else + return asin(x); +#endif +} + +WWINLINE float WWMath::Asinf(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_asinf(x); +#else + return asinf(x); +#endif } WWINLINE float WWMath::Atan(float x) { - return static_cast(atan(x)); +#if USE_DETERMINISTIC_MATH + return gm_atanf(x); +#else + return (float)atan((double)x); +#endif +} + +WWINLINE double WWMath::Atan(double x) +{ +#if USE_DETERMINISTIC_MATH + return (double) gm_atanf((float)x); // gm_atan diverges on x87, gm_atanf is bit-identical +#else + return atan(x); +#endif +} + +WWINLINE float WWMath::Atanf(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_atanf(x); +#else + return atanf(x); +#endif +} + +WWINLINE float WWMath::Atan2(float x, float y) +{ +#if USE_DETERMINISTIC_MATH + return gm_atan2f(x, y); +#else + return (float)atan2((double)x, (double)y); +#endif } -WWINLINE float WWMath::Atan2(float y, float x) +WWINLINE double WWMath::Atan2(double x, double y) { - return static_cast(atan2(y,x)); +#if USE_DETERMINISTIC_MATH + return (double) gm_atan2f((float)x, (float)y); // gm_atan2 diverges on x87, gm_atan2f is bit-identical +#else + return atan2(x, y); +#endif +} + +WWINLINE float WWMath::Atan2f(float x, float y) +{ +#if USE_DETERMINISTIC_MATH + return gm_atan2f(x, y); +#else + return atan2f(x, y); +#endif } WWINLINE float WWMath::Fast_Cos(float val) @@ -378,7 +564,37 @@ WWINLINE float WWMath::Fast_Inv_Sin(float val) WWINLINE float WWMath::Cos(float val) { -#if defined(_MSC_VER) && defined(_M_IX86) +#if USE_DETERMINISTIC_MATH + return gm_cosf(val); +#else + return (float)cos((double)val); +#endif +} + +WWINLINE double WWMath::Cos(double val) +{ +#if USE_DETERMINISTIC_MATH + return gm_cos(val); +#else + return cos(val); +#endif +} + +WWINLINE float WWMath::Cosf(float val) +{ +#if USE_DETERMINISTIC_MATH + return gm_cosf(val); +#else + return cosf(val); +#endif +} + +WWINLINE float WWMath::Cosf_Legacy(float val) +{ +#if USE_DETERMINISTIC_MATH + return gm_cosf(val); + +#elif defined(_MSC_VER) && defined(_M_IX86) float retval; __asm { fld [val] @@ -394,7 +610,37 @@ WWINLINE float WWMath::Cos(float val) WWINLINE float WWMath::Sin(float val) { -#if defined(_MSC_VER) && defined(_M_IX86) +#if USE_DETERMINISTIC_MATH + return gm_sinf(val); +#else + return (float)sin((double)val); +#endif +} + +WWINLINE double WWMath::Sin(double val) +{ +#if USE_DETERMINISTIC_MATH + return gm_sin(val); +#else + return sin(val); +#endif +} + +WWINLINE float WWMath::Sinf(float val) +{ +#if USE_DETERMINISTIC_MATH + return gm_sinf(val); +#else + return sinf(val); +#endif +} + +WWINLINE float WWMath::Sinf_Legacy(float val) +{ +#if USE_DETERMINISTIC_MATH + return gm_sinf(val); + +#elif defined(_MSC_VER) && defined(_M_IX86) float retval; __asm { fld [val] @@ -408,32 +654,217 @@ WWINLINE float WWMath::Sin(float val) #endif } -WWINLINE float WWMath::Fabs(float val) +WWINLINE float WWMath::Tan(float x) { +#if USE_DETERMINISTIC_MATH + return gm_tanf(x); +#else + return (float)tan((double)x); +#endif +} + +WWINLINE double WWMath::Tan(double x) +{ +#if USE_DETERMINISTIC_MATH + return gm_tan(x); +#else + return tan(x); +#endif +} + +WWINLINE float WWMath::Tanf(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_tanf(x); +#else + return tanf(x); +#endif +} + +WWINLINE double WWMath::Cosh(double x) +{ +#if USE_DETERMINISTIC_MATH + return gm_cosh(x); +#else + return cosh(x); +#endif +} + +WWINLINE float WWMath::Coshf(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_coshf(x); +#else + return coshf(x); +#endif +} + +WWINLINE double WWMath::Sinh(double x) +{ +#if USE_DETERMINISTIC_MATH + return gm_sinh(x); +#else + return sinh(x); +#endif +} + +WWINLINE float WWMath::Sinhf(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_sinhf(x); +#else + return sinhf(x); +#endif +} + +WWINLINE double WWMath::Tanh(double x) +{ +#if USE_DETERMINISTIC_MATH + return gm_tanh(x); +#else + return tanh(x); +#endif +} + +WWINLINE float WWMath::Tanhf(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_tanhf(x); +#else + return tanhf(x); +#endif +} + +WWINLINE float WWMath::Fabs(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_fabsf(x); +#else + return (float)fabs((double)x); +#endif +} + +WWINLINE double WWMath::Fabs(double x) +{ +#if USE_DETERMINISTIC_MATH + return gm_fabs(x); +#else + return fabs(x); +#endif +} + +WWINLINE float WWMath::Fabsf(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_fabsf(x); +#else + return fabsf(x); +#endif +} + +WWINLINE float WWMath::Fabsf_Legacy(float val) +{ +#if USE_DETERMINISTIC_MATH + return gm_fabsf(val); + +#elif defined(_MSC_VER) && defined(_M_IX86) int value=*(int*)&val; value&=0x7fffffff; return *(float*)&value; + +#else + return fabsf(val); +#endif } -WWINLINE float WWMath::Ceil(float val) +WWINLINE double WWMath::Ceil(double x) { - return ceilf(val); +#if USE_DETERMINISTIC_MATH + return gm_ceil(x); +#else + return ceil(x); +#endif } -WWINLINE float WWMath::Floor(float val) +WWINLINE float WWMath::Ceilf(float x) { - return floorf(val); +#if USE_DETERMINISTIC_MATH + return gm_ceilf(x); +#else + return ceilf(x); +#endif } -WWINLINE float WWMath::Sign(float val) +WWINLINE double WWMath::Floor(double x) { - if (val > 0.0f) { - return +1.0f; - } - if (val < 0.0f) { - return -1.0f; - } - return 0.0f; +#if USE_DETERMINISTIC_MATH + return gm_floor(x); +#else + return floor(x); +#endif +} + +WWINLINE float WWMath::Floorf(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_floorf(x); +#else + return floorf(x); +#endif +} + +WWINLINE double WWMath::Exp(double x) +{ +#if USE_DETERMINISTIC_MATH + return gm_exp(x); +#else + return exp(x); +#endif +} + +WWINLINE float WWMath::Expf(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_expf(x); +#else + return expf(x); +#endif +} + +WWINLINE double WWMath::Log10(double x) +{ +#if USE_DETERMINISTIC_MATH + return gm_log10(x); +#else + return log10(x); +#endif +} + +WWINLINE float WWMath::Log10f(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_log10f(x); +#else + return log10f(x); +#endif +} + +WWINLINE double WWMath::Log(double x) +{ +#if USE_DETERMINISTIC_MATH + return gm_log(x); +#else + return log(x); +#endif +} + +WWINLINE float WWMath::Logf(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_logf(x); +#else + return logf(x); +#endif } WWINLINE bool WWMath::Fast_Is_Float_Positive(const float & val) @@ -559,7 +990,10 @@ WWINLINE bool WWMath::Is_Valid_Double(double x) WWINLINE long WWMath::Float_To_Long(float f) { -#if defined(_MSC_VER) && defined(_M_IX86) +#if USE_DETERMINISTIC_MATH + return gm_lrintf(f); + +#elif defined(_MSC_VER) && defined(_M_IX86) long i; __asm { fld [f] @@ -574,7 +1008,10 @@ WWINLINE long WWMath::Float_To_Long(float f) WWINLINE long WWMath::Float_To_Long(double f) { -#if defined(_MSC_VER) && defined(_M_IX86) +#if USE_DETERMINISTIC_MATH + return gm_lrint(f); + +#elif defined(_MSC_VER) && defined(_M_IX86) long retval; __asm { fld qword ptr [f] @@ -587,7 +1024,7 @@ WWINLINE long WWMath::Float_To_Long(double f) #endif } -WWINLINE int WWMath::Float_To_Int_Chop(const float& f) +WWINLINE int WWMath::Float_To_Int_Chop(float f) { int a = *reinterpret_cast(&f); // take bit pattern of float into a register int sign = (a>>31); // sign = 0xFFFFFFFF if original value is negative, 0 if positive @@ -597,7 +1034,7 @@ WWINLINE int WWMath::Float_To_Int_Chop(const float& f) return ((r ^ (sign)) - sign ) &~ (exponent>>31); // add original sign. If exponent was negative, make return value 0. } -WWINLINE int WWMath::Float_To_Int_Floor(const float& f) +WWINLINE int WWMath::Float_To_Int_Floor(float f) { int a = *reinterpret_cast(&f); // take bit pattern of float into a register int sign = (a>>31); // sign = 0xFFFFFFFF if original value is negative, 0 if positive @@ -615,5 +1052,23 @@ WWINLINE int WWMath::Float_To_Int_Floor(const float& f) WWINLINE float WWMath::Normalize_Angle(float angle) { - return angle - (WWMATH_TWO_PI * Floor((angle + WWMATH_PI) / WWMATH_TWO_PI)); + return angle - (WWMATH_TWO_PI * Floorf((angle + WWMATH_PI) / WWMATH_TWO_PI)); +} + +WWINLINE float WWMath::Div_Safe(float dividend, float divisor, float epsilon) +{ +#if USE_DETERMINISTIC_MATH + return dividend / max(divisor, epsilon); +#else + return dividend / divisor; +#endif +} + +WWINLINE double WWMath::Div_Safe(double dividend, double divisor, double epsilon) +{ +#if USE_DETERMINISTIC_MATH + return dividend / max(divisor, epsilon); +#else + return dividend / divisor; +#endif } diff --git a/Core/Tools/W3DView/RingSizePropPage.cpp b/Core/Tools/W3DView/RingSizePropPage.cpp index f7bfc61f9c6..4c4019a46eb 100644 --- a/Core/Tools/W3DView/RingSizePropPage.cpp +++ b/Core/Tools/W3DView/RingSizePropPage.cpp @@ -733,5 +733,5 @@ Is_LERP { float percent = (curr_time - last_time) / (next_time - last_time); float interpolated_value = last_value + ((next_value-last_value) * percent); - return bool(WWMath::Fabs (interpolated_value - curr_value) < WWMATH_EPSILON); + return bool(WWMath::Fabsf (interpolated_value - curr_value) < WWMATH_EPSILON); } diff --git a/Core/Tools/W3DView/SphereSizePropPage.cpp b/Core/Tools/W3DView/SphereSizePropPage.cpp index f33274fcaee..7c034fa74d5 100644 --- a/Core/Tools/W3DView/SphereSizePropPage.cpp +++ b/Core/Tools/W3DView/SphereSizePropPage.cpp @@ -554,5 +554,5 @@ Is_LERP { float percent = (curr_time - last_time) / (next_time - last_time); float interpolated_value = last_value + ((next_value-last_value) * percent); - return bool(WWMath::Fabs (interpolated_value - curr_value) < WWMATH_EPSILON); + return bool(WWMath::Fabsf (interpolated_value - curr_value) < WWMATH_EPSILON); } diff --git a/Generals/Code/GameEngine/Source/Common/System/Trig.cpp b/Generals/Code/GameEngine/Source/Common/System/Trig.cpp index 4f15372752c..3190e7334de 100644 --- a/Generals/Code/GameEngine/Source/Common/System/Trig.cpp +++ b/Generals/Code/GameEngine/Source/Common/System/Trig.cpp @@ -30,115 +30,24 @@ #include "PreRTS.h" #include -#include #include "Lib/trig.h" -#define TWOPI 6.28318530718f -#define DEG2RAD 0.0174532925199f -#define TRIG_RES 4096 +#if USE_DETERMINISTIC_MATH +#include "gmath.h" +#endif -// the following are for fixed point ints with 12 fractional bits -#define INT_ONE 4096 -#define INT_TWOPI 25736 -#define INT_THREEPIOVERTWO 19302 -#define INT_PI 12868 -#define INT_HALFPI 6434 - -Real Sin(Real x) -{ - return sinf(x); -} - -Real Cos(Real x) +Real Sin(Real x) { return WWMath::Sinf(x); } +Real Cos(Real x) { return WWMath::Cosf(x); } +Real Tan(Real x) { return WWMath::Tanf(x); } +Real ACos(Real x) { return WWMath::Acosf(x); } +Real ASin(Real x) { return WWMath::Asinf(x); } +Real Sqrt(Real x) { - return cosf(x); +#if USE_DETERMINISTIC_MATH + return gm_sqrtf(x); +#else + return (Real)sqrt((double)x); +#endif } - -Real Tan(Real x) -{ - return tanf(x); -} - -Real ACos(Real x) -{ - return acosf(x); -} - -Real ASin(Real x) -{ - return asinf(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= AIRBORNE_UNIT_GROUND_DELTA) { Real extent = MAX_SHADOW_LENGTH_EXTRA_AIRBORNE_SCALE_FACTOR * m_robjExtent; - if (WWMath::Fabs(pos.X - bcX) > (beX + extent) || - WWMath::Fabs(pos.Y - bcY) > (beY + extent) || - WWMath::Fabs(pos.Z - bcZ) > (beZ + extent)) + if (WWMath::Fabsf_Legacy(pos.X - bcX) > (beX + extent) || + WWMath::Fabsf_Legacy(pos.Y - bcY) > (beY + extent) || + WWMath::Fabsf_Legacy(pos.Z - bcZ) > (beZ + extent)) return; //shadow can't be visible so no point in updating. //this unit is above ground, extend shadow volume to reach lowest point on the terrain plus extra bit to make @@ -1714,9 +1714,9 @@ void W3DVolumetricShadow::Update() //normal object that is not floating above ground so we don't need to extend the shadow lower than the object's //base since it should be sitting directly at ground level. - if (WWMath::Fabs(pos.X - bcX) > (beX + m_robjExtent) || - WWMath::Fabs(pos.Y - bcY) > (beY + m_robjExtent) || - WWMath::Fabs(pos.Z - bcZ) > (beZ + m_robjExtent)) + if (WWMath::Fabsf_Legacy(pos.X - bcX) > (beX + m_robjExtent) || + WWMath::Fabsf_Legacy(pos.Y - bcY) > (beY + m_robjExtent) || + WWMath::Fabsf_Legacy(pos.Z - bcZ) > (beZ + m_robjExtent)) return; //shadow can't be visible so no point in updating. //check if this object has never had it's extrusion length updated. Will only be true for diff --git a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp index f2bcf516014..e1ded183f36 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp @@ -694,7 +694,7 @@ RenderObjClass * W3DAssetManager::Create_Render_Obj( GetPrecisionTimer(&startTime64); #endif - Bool reallyscale = (WWMath::Fabs(scale - ident_scale) > scale_epsilon); + Bool reallyscale = (WWMath::Fabsf_Legacy(scale - ident_scale) > scale_epsilon); Bool reallycolor = (color & 0xFFFFFF) != 0; //black is not a valid color and assumes no custom coloring. Bool reallytexture = (oldTexture != nullptr && newTexture != nullptr); @@ -1313,9 +1313,9 @@ static inline void Munge_Texture_Name(char *newname, const char *oldname, const RenderObjClass * W3DAssetManager::Create_Render_Obj(const char * name,float scale, const Vector3 &hsv_shift) { Bool isGranny = false; - Bool reallyscale = (WWMath::Fabs(scale - ident_scale) > scale_epsilon); - Bool reallyhsv_shift = (WWMath::Fabs(hsv_shift.X - ident_HSV.X) > H_epsilon || - WWMath::Fabs(hsv_shift.Y - ident_HSV.Y) > S_epsilon || WWMath::Fabs(hsv_shift.Z - ident_HSV.Z) > V_epsilon); + Bool reallyscale = (WWMath::Fabsf(scale - ident_scale) > scale_epsilon); + Bool reallyhsv_shift = (WWMath::Fabsf(hsv_shift.X - ident_HSV.X) > H_epsilon || + WWMath::Fabsf(hsv_shift.Y - ident_HSV.Y) > S_epsilon || WWMath::Fabsf(hsv_shift.Z - ident_HSV.Z) > V_epsilon); // base case, no scale or hue shifting if (!reallyscale && !reallyhsv_shift) return WW3DAssetManager::Create_Render_Obj(name); @@ -1415,8 +1415,8 @@ TextureClass * W3DAssetManager::Get_Texture_With_HSV_Shift(const char * filename { WWPROFILE( "W3DAssetManager::Get_Texture with HSV shift" ); - Bool is_hsv_shift = (WWMath::Fabs(hsv_shift.X - ident_HSV.X) > H_epsilon || - WWMath::Fabs(hsv_shift.Y - ident_HSV.Y) > S_epsilon || WWMath::Fabs(hsv_shift.Z - ident_HSV.Z) > V_epsilon); + Bool is_hsv_shift = (WWMath::Fabsf(hsv_shift.X - ident_HSV.X) > H_epsilon || + WWMath::Fabsf(hsv_shift.Y - ident_HSV.Y) > S_epsilon || WWMath::Fabsf(hsv_shift.Z - ident_HSV.Z) > V_epsilon); if (!is_hsv_shift) { diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/camera.cpp b/Generals/Code/Libraries/Source/WWVegas/WW3D2/camera.cpp index 6dbfaaa773e..284f5b526f6 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/camera.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/camera.cpp @@ -770,13 +770,13 @@ void CameraClass::Get_Clip_Planes(float & znear,float & zfar) const float CameraClass::Get_Horizontal_FOV() const { float width = ViewPlane.Max.X - ViewPlane.Min.X; - return 2*WWMath::Atan2(width,2.0); + return 2*WWMath::Atan2(width,2.0f); } float CameraClass::Get_Vertical_FOV() const { float height = ViewPlane.Max.Y - ViewPlane.Min.Y; - return 2*WWMath::Atan2(height,2.0); + return 2*WWMath::Atan2(height,2.0f); } float CameraClass::Get_Aspect_Ratio() const diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/mapper.cpp b/Generals/Code/Libraries/Source/WWVegas/WW3D2/mapper.cpp index b60e78bc4c6..a2d135b5a6d 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/mapper.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/mapper.cpp @@ -102,8 +102,8 @@ void LinearOffsetTextureMapperClass::Apply(int uv_array_index) float offset_v = CurrentUVOffset.Y + UVOffsetDeltaPerMS.Y * del; // ensure both coordinates of offset are in [0, 1] range: - offset_u = offset_u - WWMath::Floor(offset_u); - offset_v = offset_v - WWMath::Floor(offset_v); + offset_u = offset_u - WWMath::Floorf(offset_u); + offset_v = offset_v - WWMath::Floorf(offset_v); // Set up the offset matrix Matrix3D m(true); @@ -326,8 +326,8 @@ void RotateTextureMapperClass::Apply(int uv_array_index) // Set up the rotation matrix float c,s; - c=WWMath::Cos(CurrentAngle); - s=WWMath::Sin(CurrentAngle); + c=WWMath::Cosf_Legacy(CurrentAngle); + s=WWMath::Sinf_Legacy(CurrentAngle); Matrix4x4 m(true); // subtract center @@ -392,8 +392,8 @@ void SineLinearOffsetTextureMapperClass::Apply(int uv_array_index) float offset_v=VAFP.X*sin(VAFP.Y*CurrentAngle+VAFP.Z*WWMATH_PI); // ensure both coordinates of offset are in [0, 1] range: - offset_u = offset_u - WWMath::Floor(offset_u); - offset_v = offset_v - WWMath::Floor(offset_v); + offset_u = offset_u - WWMath::Floorf(offset_u); + offset_v = offset_v - WWMath::Floorf(offset_v); // Set up the offset matrix Matrix3D m(true); @@ -455,8 +455,8 @@ void StepLinearOffsetTextureMapperClass::Apply(int uv_array_index) } // ensure both coordinates of offset are in [0, 1] range: - CurrentStep.U -= WWMath::Floor(CurrentStep.U); - CurrentStep.V -= WWMath::Floor(CurrentStep.V); + CurrentStep.U -= WWMath::Floorf(CurrentStep.U); + CurrentStep.V -= WWMath::Floorf(CurrentStep.V); // Set up the offset matrix Matrix3D m(true); @@ -533,8 +533,8 @@ void ZigZagLinearOffsetTextureMapperClass::Apply(int uv_array_index) } // ensure both coordinates of offset are in [0, 1] range: - offset_u = offset_u - WWMath::Floor(offset_u); - offset_v = offset_v - WWMath::Floor(offset_v); + offset_u = offset_u - WWMath::Floorf(offset_u); + offset_v = offset_v - WWMath::Floorf(offset_v); // Set up the offset matrix Matrix3D m(true); @@ -642,7 +642,7 @@ void EdgeMapperClass::Apply(int uv_array_index) LastUsedSyncTime=now; VOffset+=delta*VSpeed; - VOffset-=WWMath::Floor(VOffset); + VOffset-=WWMath::Floorf(VOffset); // takes the Z component and // uses it to index the texture @@ -740,8 +740,8 @@ void ScreenMapperClass::Apply(int uv_array_index) float offset_v = CurrentUVOffset.Y + UVOffsetDeltaPerMS.Y * del; // ensure both coordinates of offset are in [0, 1] range: - offset_u = offset_u - WWMath::Floor(offset_u); - offset_v = offset_v - WWMath::Floor(offset_v); + offset_u = offset_u - WWMath::Floorf(offset_u); + offset_v = offset_v - WWMath::Floorf(offset_v); // multiply by projection matrix // followed by scale and translation diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp b/Generals/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp index 13bfe752c3b..a40eac2ea2a 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp @@ -850,7 +850,7 @@ AdaptiveDeltaMotionChannelClass::AdaptiveDeltaMotionChannelClass() : //ratio = ((ratio + 1.0f) / 128.0f); ratio/=((float) FILTER_TABLE_GEN_SIZE); - filtertable[i + FILTER_TABLE_GEN_START] = 1.0f - WWMath::Sin( DEG_TO_RAD(90.0f * ratio)); + filtertable[i + FILTER_TABLE_GEN_START] = 1.0f - WWMath::Sinf_Legacy( DEG_TO_RAD(90.0f * ratio)); } table_valid = true; diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/part_emt.cpp b/Generals/Code/Libraries/Source/WWVegas/WW3D2/part_emt.cpp index a0b7778928f..0b7f65dfa16 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/part_emt.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/part_emt.cpp @@ -664,7 +664,7 @@ void ParticleEmitterClass::Initialize_Particle(NewParticleStruct * newpart, Vector3 outwards; float pos_l2 = rand_pos.Length2(); if (pos_l2) { - outwards = rand_pos * (OutwardVel * WWMath::Inv_Sqrt(pos_l2)); + outwards = rand_pos * (OutwardVel * WWMath::Inv_Sqrt_Legacy(pos_l2)); } else { outwards.X = OutwardVel; outwards.Y = 0.0f; diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/render2d.cpp b/Generals/Code/Libraries/Source/WWVegas/WW3D2/render2d.cpp index 8a47a7a6123..a96d0f45512 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/render2d.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/render2d.cpp @@ -200,8 +200,8 @@ Vector2 Render2DClass::Convert_Vert( const Vector2 & v ) out.Y = (out.Y - 1.0f) * (Get_Screen_Resolution().Height() * -0.5f); // Round to nearest pixel - out.X = WWMath::Floor( out.X + 0.5f ); - out.Y = WWMath::Floor( out.Y + 0.5f ); + out.X = WWMath::Floorf( out.X + 0.5f ); + out.Y = WWMath::Floorf( out.Y + 0.5f ); // Bias if ( WW3D::Is_Screen_UV_Biased() ) { diff --git a/Generals/Code/Tools/WorldBuilder/src/GlobalLightOptions.cpp b/Generals/Code/Tools/WorldBuilder/src/GlobalLightOptions.cpp index 1eaa4ba4f2c..daccb868e94 100644 --- a/Generals/Code/Tools/WorldBuilder/src/GlobalLightOptions.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/GlobalLightOptions.cpp @@ -54,8 +54,8 @@ static void calcNewLight(Int lr, Int fb, Vector3 *newLight) newLight->Set(0,0,-1); Real yAngle = PI*(lr-90)/180; Real xAngle = PI*(fb-90)/180; - Real zAngle = xAngle * WWMath::Sin(yAngle); - xAngle *= WWMath::Cos(yAngle); + Real zAngle = xAngle * WWMath::Sinf(yAngle); + xAngle *= WWMath::Cosf(yAngle); newLight->Rotate_Y(yAngle); newLight->Rotate_X(xAngle); newLight->Rotate_Z(zAngle); @@ -94,8 +94,8 @@ void GlobalLightOptions::updateEditFields() void GlobalLightOptions::showLightFeedback(Int lightIndex) { Vector3 light(0,0,0); - light.X = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*cos(m_angleAzimuth[lightIndex]/180.0f*PI);// -WWMath::Sin(PI*(m_angleLR[lightIndex]-90)/180); - light.Y = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*sin(m_angleAzimuth[lightIndex]/180.0f*PI);//-WWMath::Sin(PI*(m_angleFB[lightIndex]-90)/180); + light.X = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*cos(m_angleAzimuth[lightIndex]/180.0f*PI);// -WWMath::Sinf(PI*(m_angleLR[lightIndex]-90)/180); + light.Y = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*sin(m_angleAzimuth[lightIndex]/180.0f*PI);//-WWMath::Sinf(PI*(m_angleFB[lightIndex]-90)/180); light.Z = cos (PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI); WbView3d * pView = CWorldBuilderDoc::GetActive3DView(); @@ -109,8 +109,8 @@ void GlobalLightOptions::showLightFeedback(Int lightIndex) void GlobalLightOptions::applyAngle(Int lightIndex) { Vector3 light(0,0,0); - light.X = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*cos(m_angleAzimuth[lightIndex]/180.0f*PI);// -WWMath::Sin(PI*(m_angleLR[lightIndex]-90)/180); - light.Y = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*sin(m_angleAzimuth[lightIndex]/180.0f*PI);//-WWMath::Sin(PI*(m_angleFB[lightIndex]-90)/180); + light.X = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*cos(m_angleAzimuth[lightIndex]/180.0f*PI);// -WWMath::Sinf(PI*(m_angleLR[lightIndex]-90)/180); + light.Y = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*sin(m_angleAzimuth[lightIndex]/180.0f*PI);//-WWMath::Sinf(PI*(m_angleFB[lightIndex]-90)/180); light.Z = cos (PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI); CString str; diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp index 8b1f461ef84..541b9afc6e2 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp @@ -30,115 +30,24 @@ #include "PreRTS.h" #include -#include #include "Lib/trig.h" -#define TWOPI 6.28318530718f -#define DEG2RAD 0.0174532925199f -#define TRIG_RES 4096 +#if USE_DETERMINISTIC_MATH +#include "gmath.h" +#endif -// the following are for fixed point ints with 12 fractional bits -#define INT_ONE 4096 -#define INT_TWOPI 25736 -#define INT_THREEPIOVERTWO 19302 -#define INT_PI 12868 -#define INT_HALFPI 6434 - -Real Sin(Real x) -{ - return sinf(x); -} - -Real Cos(Real x) +Real Sin(Real x) { return WWMath::Sinf(x); } +Real Cos(Real x) { return WWMath::Cosf(x); } +Real Tan(Real x) { return WWMath::Tanf(x); } +Real ACos(Real x) { return WWMath::Acosf(x); } +Real ASin(Real x) { return WWMath::Asinf(x); } +Real Sqrt(Real x) { - return cosf(x); +#if USE_DETERMINISTIC_MATH + return gm_sqrtf(x); +#else + return (Real)sqrt((double)x); +#endif } - -Real Tan(Real x) -{ - return tanf(x); -} - -Real ACos(Real x) -{ - return acosf(x); -} - -Real ASin(Real x) -{ - return asinf(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= AIRBORNE_UNIT_GROUND_DELTA) { Real extent = MAX_SHADOW_LENGTH_EXTRA_AIRBORNE_SCALE_FACTOR * m_robjExtent; - if (WWMath::Fabs(pos.X - bcX) > (beX + extent) || - WWMath::Fabs(pos.Y - bcY) > (beY + extent) || - WWMath::Fabs(pos.Z - bcZ) > (beZ + extent)) + if (WWMath::Fabsf_Legacy(pos.X - bcX) > (beX + extent) || + WWMath::Fabsf_Legacy(pos.Y - bcY) > (beY + extent) || + WWMath::Fabsf_Legacy(pos.Z - bcZ) > (beZ + extent)) return; //shadow can't be visible so no point in updating. //this unit is above ground, extend shadow volume to reach lowest point on the terrain plus extra bit to make @@ -1821,9 +1821,9 @@ void W3DVolumetricShadow::Update() //normal object that is not floating above ground so we don't need to extend the shadow lower than the object's //base since it should be sitting directly at ground level. - if (WWMath::Fabs(pos.X - bcX) > (beX + m_robjExtent) || - WWMath::Fabs(pos.Y - bcY) > (beY + m_robjExtent) || - WWMath::Fabs(pos.Z - bcZ) > (beZ + m_robjExtent)) + if (WWMath::Fabsf_Legacy(pos.X - bcX) > (beX + m_robjExtent) || + WWMath::Fabsf_Legacy(pos.Y - bcY) > (beY + m_robjExtent) || + WWMath::Fabsf_Legacy(pos.Z - bcZ) > (beZ + m_robjExtent)) return; //shadow can't be visible so no point in updating. //check if this object has never had it's extrusion length updated. Will only be true for @@ -1969,7 +1969,7 @@ void W3DVolumetricShadow::updateMeshVolume(Int meshIndex, Int lightIndex, const Vector3 vb = (Vector3 &)objectToWorld[0]; va.Normalize(); vb.Normalize(); - Real cosAngle = WWMath::Fabs(Vector3::Dot_Product(va,vb)); + Real cosAngle = WWMath::Fabsf_Legacy(Vector3::Dot_Product(va,vb)); if (cosAngle >= cosAngleToCare) { @@ -1978,7 +1978,7 @@ void W3DVolumetricShadow::updateMeshVolume(Int meshIndex, Int lightIndex, const vb = (Vector3 &)objectToWorld[1]; va.Normalize(); vb.Normalize(); - cosAngle = WWMath::Fabs(Vector3::Dot_Product(va,vb)); + cosAngle = WWMath::Fabsf_Legacy(Vector3::Dot_Product(va,vb)); if (cosAngle >= cosAngleToCare) { @@ -1986,7 +1986,7 @@ void W3DVolumetricShadow::updateMeshVolume(Int meshIndex, Int lightIndex, const vb = (Vector3 &)objectToWorld[2]; va.Normalize(); vb.Normalize(); - cosAngle = WWMath::Fabs(Vector3::Dot_Product(va,vb)); + cosAngle = WWMath::Fabsf_Legacy(Vector3::Dot_Product(va,vb)); if (cosAngle < cosAngleToCare) isMeshRotating=true; } diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp index 597b5e505f9..55f3f987f46 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp @@ -724,7 +724,7 @@ RenderObjClass * W3DAssetManager::Create_Render_Obj( GetPrecisionTimer(&startTime64); #endif - Bool reallyscale = (WWMath::Fabs(scale - ident_scale) > scale_epsilon); + Bool reallyscale = (WWMath::Fabsf_Legacy(scale - ident_scale) > scale_epsilon); Bool reallycolor = (color & 0xFFFFFF) != 0; //black is not a valid color and assumes no custom coloring. Bool reallytexture = (oldTexture != nullptr && newTexture != nullptr); @@ -1340,9 +1340,9 @@ static inline void Munge_Texture_Name(char *newname, const char *oldname, const RenderObjClass * W3DAssetManager::Create_Render_Obj(const char * name,float scale, const Vector3 &hsv_shift) { Bool isGranny = false; - Bool reallyscale = (WWMath::Fabs(scale - ident_scale) > scale_epsilon); - Bool reallyhsv_shift = (WWMath::Fabs(hsv_shift.X - ident_HSV.X) > H_epsilon || - WWMath::Fabs(hsv_shift.Y - ident_HSV.Y) > S_epsilon || WWMath::Fabs(hsv_shift.Z - ident_HSV.Z) > V_epsilon); + Bool reallyscale = (WWMath::Fabsf(scale - ident_scale) > scale_epsilon); + Bool reallyhsv_shift = (WWMath::Fabsf(hsv_shift.X - ident_HSV.X) > H_epsilon || + WWMath::Fabsf(hsv_shift.Y - ident_HSV.Y) > S_epsilon || WWMath::Fabsf(hsv_shift.Z - ident_HSV.Z) > V_epsilon); // base case, no scale or hue shifting if (!reallyscale && !reallyhsv_shift) return WW3DAssetManager::Create_Render_Obj(name); @@ -1442,8 +1442,8 @@ TextureClass * W3DAssetManager::Get_Texture_With_HSV_Shift(const char * filename { WWPROFILE( "W3DAssetManager::Get_Texture with HSV shift" ); - Bool is_hsv_shift = (WWMath::Fabs(hsv_shift.X - ident_HSV.X) > H_epsilon || - WWMath::Fabs(hsv_shift.Y - ident_HSV.Y) > S_epsilon || WWMath::Fabs(hsv_shift.Z - ident_HSV.Z) > V_epsilon); + Bool is_hsv_shift = (WWMath::Fabsf(hsv_shift.X - ident_HSV.X) > H_epsilon || + WWMath::Fabsf(hsv_shift.Y - ident_HSV.Y) > S_epsilon || WWMath::Fabsf(hsv_shift.Z - ident_HSV.Z) > V_epsilon); if (!is_hsv_shift) { diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/camera.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/camera.cpp index 0e2af8a84de..81da14ba944 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/camera.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/camera.cpp @@ -770,13 +770,13 @@ void CameraClass::Get_Clip_Planes(float & znear,float & zfar) const float CameraClass::Get_Horizontal_FOV() const { float width = ViewPlane.Max.X - ViewPlane.Min.X; - return 2*WWMath::Atan2(width,2.0); + return 2*WWMath::Atan2(width,2.0f); } float CameraClass::Get_Vertical_FOV() const { float height = ViewPlane.Max.Y - ViewPlane.Min.Y; - return 2*WWMath::Atan2(height,2.0); + return 2*WWMath::Atan2(height,2.0f); } float CameraClass::Get_Aspect_Ratio() const diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/lightenvironment.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/lightenvironment.cpp index 9bd45bfc659..91417899a48 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/lightenvironment.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/lightenvironment.cpp @@ -107,7 +107,7 @@ void LightEnvironmentClass::InputLightStruct::Init_From_Point_Or_Spot_Light if (light.Get_Flag(LightClass::FAR_ATTENUATION)) { - if (WWMath::Fabs(atten_end - atten_start) < WWMATH_EPSILON) { + if (WWMath::Fabsf_Legacy(atten_end - atten_start) < WWMATH_EPSILON) { /* ** Start and end are equal, attenuation is a "step" function diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/linegrp.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/linegrp.cpp index 797b36fbcb9..bebf4e4dd2a 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/linegrp.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/linegrp.cpp @@ -269,9 +269,9 @@ void LineGroupClass::Render(RenderInfoClass &rinfo) const bool sort = (Shader.Get_Dst_Blend_Func() != ShaderClass::DSTBLEND_ZERO) && (Shader.Get_Alpha_Test() == ShaderClass::ALPHATEST_DISABLE) && (WW3D::Is_Sorting_Enabled()); // the 3 offsets in view space - const static Vector3 offset_a = Vector3(WWMath::Cos(WWMATH_PI / 2), WWMath::Sin(WWMATH_PI /2 ), 0); - const static Vector3 offset_b = Vector3(WWMath::Cos(7 * WWMATH_PI / 6), WWMath::Sin(7 * WWMATH_PI / 6), 0); - const static Vector3 offset_c = Vector3(WWMath::Cos(11 * WWMATH_PI / 6), WWMath::Sin(11 * WWMATH_PI / 6), 0); + const static Vector3 offset_a = Vector3(WWMath::Cosf_Legacy(WWMATH_PI / 2), WWMath::Sinf_Legacy(WWMATH_PI /2 ), 0); + const static Vector3 offset_b = Vector3(WWMath::Cosf_Legacy(7 * WWMATH_PI / 6), WWMath::Sinf_Legacy(7 * WWMATH_PI / 6), 0); + const static Vector3 offset_c = Vector3(WWMath::Cosf_Legacy(11 * WWMATH_PI / 6), WWMath::Sinf_Legacy(11 * WWMATH_PI / 6), 0); static Vector3 offset[3]; diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/mapper.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/mapper.cpp index 21d44498110..ec74c3e8afc 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/mapper.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/mapper.cpp @@ -168,8 +168,8 @@ void LinearOffsetTextureMapperClass::Calculate_Texture_Matrix(Matrix4x4 &tex_mat // If ClampFix is TRUE we clamp the offsets between -Scale and +Scale with no wraparound. // This works well for clamped textures. if (!ClampFix) { - offset_u = offset_u - WWMath::Floor(offset_u); - offset_v = offset_v - WWMath::Floor(offset_v); + offset_u = offset_u - WWMath::Floorf(offset_u); + offset_v = offset_v - WWMath::Floorf(offset_v); } else { offset_u = WWMath::Clamp(offset_u, -Scale.X, Scale.X); offset_v = WWMath::Clamp(offset_v, -Scale.Y, Scale.Y); @@ -372,8 +372,8 @@ void RotateTextureMapperClass::Calculate_Texture_Matrix(Matrix4x4 &tex_matrix) // Set up the rotation matrix float c,s; - c=WWMath::Cos(CurrentAngle); - s=WWMath::Sin(CurrentAngle); + c=WWMath::Cosf_Legacy(CurrentAngle); + s=WWMath::Sinf_Legacy(CurrentAngle); tex_matrix.Make_Identity(); // subtract center @@ -514,8 +514,8 @@ void StepLinearOffsetTextureMapperClass::Calculate_Texture_Matrix(Matrix4x4 &tex // If ClampFix is TRUE we clamp the offsets between -Scale and +Scale with no wraparound. // This works well for clamped textures. if (!ClampFix) { - CurrentStep.U -= WWMath::Floor(CurrentStep.U); - CurrentStep.V -= WWMath::Floor(CurrentStep.V); + CurrentStep.U -= WWMath::Floorf(CurrentStep.U); + CurrentStep.V -= WWMath::Floorf(CurrentStep.V); } else { CurrentStep.U = WWMath::Clamp(CurrentStep.U, -Scale.X, Scale.X); CurrentStep.V = WWMath::Clamp(CurrentStep.V, -Scale.Y, Scale.Y); @@ -732,7 +732,7 @@ void EdgeMapperClass::Calculate_Texture_Matrix(Matrix4x4 &tex_matrix) LastUsedSyncTime=now; VOffset+=delta*VSpeed; - VOffset-=WWMath::Floor(VOffset); + VOffset-=WWMath::Floorf(VOffset); // takes the Z component and // uses it to index the texture @@ -918,8 +918,8 @@ void ScreenMapperClass::Calculate_Texture_Matrix(Matrix4x4 &tex_matrix) // If ClampFix is TRUE we clamp the offsets between -Scale and +Scale with no wraparound. // This works well for clamped textures. if (!ClampFix) { - offset_u = offset_u - WWMath::Floor(offset_u); - offset_v = offset_v - WWMath::Floor(offset_v); + offset_u = offset_u - WWMath::Floorf(offset_u); + offset_v = offset_v - WWMath::Floorf(offset_v); } else { offset_u = WWMath::Clamp(offset_u, -Scale.X, Scale.X); offset_v = WWMath::Clamp(offset_v, -Scale.Y, Scale.Y); diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp index 458df2bb472..d6bff509543 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp @@ -865,7 +865,7 @@ AdaptiveDeltaMotionChannelClass::AdaptiveDeltaMotionChannelClass() : //ratio = ((ratio + 1.0f) / 128.0f); ratio/=((float) FILTER_TABLE_GEN_SIZE); - filtertable[i + FILTER_TABLE_GEN_START] = 1.0f - WWMath::Sin( DEG_TO_RAD(90.0f * ratio)); + filtertable[i + FILTER_TABLE_GEN_START] = 1.0f - WWMath::Sinf_Legacy( DEG_TO_RAD(90.0f * ratio)); } table_valid = true; diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/part_emt.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/part_emt.cpp index acd08ead531..29b3c241999 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/part_emt.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/part_emt.cpp @@ -673,7 +673,7 @@ void ParticleEmitterClass::Initialize_Particle(NewParticleStruct * newpart, Vector3 outwards; float pos_l2 = rand_pos.Length2(); if (pos_l2) { - outwards = rand_pos * (OutwardVel * WWMath::Inv_Sqrt(pos_l2)); + outwards = rand_pos * (OutwardVel * WWMath::Inv_Sqrt_Legacy(pos_l2)); } else { outwards.X = OutwardVel; outwards.Y = 0.0f; diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2d.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2d.cpp index 1b2fdc3d93d..85e57ac9db1 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2d.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2d.cpp @@ -224,8 +224,8 @@ Vector2 Render2DClass::Convert_Vert( const Vector2 & v ) out.Y = (out.Y - 1.0f) * (Get_Screen_Resolution().Height() * -0.5f); // Round to nearest pixel - out.X = WWMath::Floor( out.X + 0.5f ); - out.Y = WWMath::Floor( out.Y + 0.5f ); + out.X = WWMath::Floorf( out.X + 0.5f ); + out.Y = WWMath::Floorf( out.Y + 0.5f ); // Bias if ( WW3D::Is_Screen_UV_Biased() ) { diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/GlobalLightOptions.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/GlobalLightOptions.cpp index 02b654bcf9d..929638d6b31 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/GlobalLightOptions.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/GlobalLightOptions.cpp @@ -54,8 +54,8 @@ static void calcNewLight(Int lr, Int fb, Vector3 *newLight) newLight->Set(0,0,-1); Real yAngle = PI*(lr-90)/180; Real xAngle = PI*(fb-90)/180; - Real zAngle = xAngle * WWMath::Sin(yAngle); - xAngle *= WWMath::Cos(yAngle); + Real zAngle = xAngle * WWMath::Sinf(yAngle); + xAngle *= WWMath::Cosf(yAngle); newLight->Rotate_Y(yAngle); newLight->Rotate_X(xAngle); newLight->Rotate_Z(zAngle); @@ -94,8 +94,8 @@ void GlobalLightOptions::updateEditFields() void GlobalLightOptions::showLightFeedback(Int lightIndex) { Vector3 light(0,0,0); - light.X = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*cos(m_angleAzimuth[lightIndex]/180.0f*PI);// -WWMath::Sin(PI*(m_angleLR[lightIndex]-90)/180); - light.Y = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*sin(m_angleAzimuth[lightIndex]/180.0f*PI);//-WWMath::Sin(PI*(m_angleFB[lightIndex]-90)/180); + light.X = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*cos(m_angleAzimuth[lightIndex]/180.0f*PI);// -WWMath::Sinf(PI*(m_angleLR[lightIndex]-90)/180); + light.Y = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*sin(m_angleAzimuth[lightIndex]/180.0f*PI);//-WWMath::Sinf(PI*(m_angleFB[lightIndex]-90)/180); light.Z = cos (PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI); WbView3d * pView = CWorldBuilderDoc::GetActive3DView(); @@ -109,8 +109,8 @@ void GlobalLightOptions::showLightFeedback(Int lightIndex) void GlobalLightOptions::applyAngle(Int lightIndex) { Vector3 light(0,0,0); - light.X = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*cos(m_angleAzimuth[lightIndex]/180.0f*PI);// -WWMath::Sin(PI*(m_angleLR[lightIndex]-90)/180); - light.Y = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*sin(m_angleAzimuth[lightIndex]/180.0f*PI);//-WWMath::Sin(PI*(m_angleFB[lightIndex]-90)/180); + light.X = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*cos(m_angleAzimuth[lightIndex]/180.0f*PI);// -WWMath::Sinf(PI*(m_angleLR[lightIndex]-90)/180); + light.Y = sin(PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI)*sin(m_angleAzimuth[lightIndex]/180.0f*PI);//-WWMath::Sinf(PI*(m_angleFB[lightIndex]-90)/180); light.Z = cos (PI/2.0f+m_angleElevation[lightIndex]/180.0f*PI); CString str; From d0ea7a96683d70e7067bb82e19da7f44e26550a5 Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Wed, 23 Sep 2026 13:34:24 +0300 Subject: [PATCH 5/9] refactor(wwmath): Route WWMath call sites through the deterministic wrappers (#2670) Replaces the libm calls inside the WWMath library itself (matrices, quaternions, vectors, spheres and vehicle curves) with the WWMath wrappers. --- .../Libraries/Source/WWVegas/WWMath/matrix3.h | 14 +++---- .../Source/WWVegas/WWMath/matrix3d.cpp | 10 ++--- .../Source/WWVegas/WWMath/matrix3d.h | 40 +++++++++---------- .../Libraries/Source/WWVegas/WWMath/matrix4.h | 2 +- Core/Libraries/Source/WWVegas/WWMath/quat.cpp | 12 +++--- Core/Libraries/Source/WWVegas/WWMath/sphere.h | 4 +- .../Libraries/Source/WWVegas/WWMath/vector2.h | 2 +- .../Libraries/Source/WWVegas/WWMath/vector3.h | 6 +-- .../Source/WWVegas/WWMath/vehiclecurve.cpp | 2 +- 9 files changed, 46 insertions(+), 46 deletions(-) diff --git a/Core/Libraries/Source/WWVegas/WWMath/matrix3.h b/Core/Libraries/Source/WWVegas/WWMath/matrix3.h index 610a1db0a30..379053fb5e9 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/matrix3.h +++ b/Core/Libraries/Source/WWVegas/WWMath/matrix3.h @@ -361,7 +361,7 @@ WWINLINE Matrix3x3::Matrix3x3(const Vector3 & axis,float s_angle,float c_angle) WWINLINE void Matrix3x3::Set(const Vector3 & axis,float angle) { - Set(axis,sinf(angle),cosf(angle)); + Set(axis,WWMath::Sinf(angle),WWMath::Cosf(angle)); } WWINLINE void Matrix3x3::Set(const Vector3 & axis,float s,float c) @@ -775,7 +775,7 @@ WWINLINE int operator != (const Matrix3x3 & a, const Matrix3x3 & b) *=============================================================================================*/ WWINLINE void Matrix3x3::Rotate_X(float theta) { - Rotate_X(sinf(theta),cosf(theta)); + Rotate_X(WWMath::Sinf(theta),WWMath::Cosf(theta)); } WWINLINE void Matrix3x3::Rotate_X(float s,float c) @@ -809,7 +809,7 @@ WWINLINE void Matrix3x3::Rotate_X(float s,float c) *=============================================================================================*/ WWINLINE void Matrix3x3::Rotate_Y(float theta) { - Rotate_Y(sinf(theta),cosf(theta)); + Rotate_Y(WWMath::Sinf(theta),WWMath::Cosf(theta)); } WWINLINE void Matrix3x3::Rotate_Y(float s,float c) @@ -844,7 +844,7 @@ WWINLINE void Matrix3x3::Rotate_Y(float s,float c) *=============================================================================================*/ WWINLINE void Matrix3x3::Rotate_Z(float theta) { - Rotate_Z(sinf(theta),cosf(theta)); + Rotate_Z(WWMath::Sinf(theta),WWMath::Cosf(theta)); } WWINLINE void Matrix3x3::Rotate_Z(float s,float c) @@ -898,7 +898,7 @@ WWINLINE Matrix3x3 Create_X_Rotation_Matrix3(float s,float c) WWINLINE Matrix3x3 Create_X_Rotation_Matrix3(float rad) { - return Create_X_Rotation_Matrix3(sinf(rad),cosf(rad)); + return Create_X_Rotation_Matrix3(WWMath::Sinf(rad),WWMath::Cosf(rad)); } /*********************************************************************************************** @@ -934,7 +934,7 @@ WWINLINE Matrix3x3 Create_Y_Rotation_Matrix3(float s,float c) WWINLINE Matrix3x3 Create_Y_Rotation_Matrix3(float rad) { - return Create_Y_Rotation_Matrix3(sinf(rad),cosf(rad)); + return Create_Y_Rotation_Matrix3(WWMath::Sinf(rad),WWMath::Cosf(rad)); } /*********************************************************************************************** @@ -970,7 +970,7 @@ WWINLINE Matrix3x3 Create_Z_Rotation_Matrix3(float s,float c) WWINLINE Matrix3x3 Create_Z_Rotation_Matrix3(float rad) { - return Create_Z_Rotation_Matrix3(sinf(rad),cosf(rad)); + return Create_Z_Rotation_Matrix3(WWMath::Sinf(rad),WWMath::Cosf(rad)); } WWINLINE void Matrix3x3::Rotate_Vector(const Matrix3x3 & A,const Vector3 & in,Vector3 * out) diff --git a/Core/Libraries/Source/WWVegas/WWMath/matrix3d.cpp b/Core/Libraries/Source/WWVegas/WWMath/matrix3d.cpp index 47458073918..517ab181522 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/matrix3d.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/matrix3d.cpp @@ -372,7 +372,7 @@ void Matrix3D::Look_At_Dir(const Vector3 &pos, const Vector3 &dir, float roll) float dz = dir.Z; // length of projection onto XY plane - float len2 = (float)WWMath::Sqrt(dx*dx + dy*dy); + float len2 = WWMath::Sqrt(dx*dx + dy*dy); // pitch sinp = dz; @@ -414,7 +414,7 @@ void Matrix3D::buildTransformMatrix( const Vector3 &pos, const Vector3 &dir ) float sinp, cosp; // sine and cosine of the pitch ("up-down" tilt about y) float siny, cosy; // sine and cosine of the yaw ("left-right"tilt about z) - float len2 = (float)sqrt( (dir.X * dir.X) + (dir.Y * dir.Y) ); + float len2 = (float)WWMath::Sqrt( (dir.X * dir.X) + (dir.Y * dir.Y) ); sinp = dir.Z; cosp = len2; @@ -472,8 +472,8 @@ void Matrix3D::Obj_Look_At(const Vector3 &p,const Vector3 &t,float roll) dy = (t[1] - p[1]); dz = (t[2] - p[2]); - len1 = (float)sqrt(dx*dx + dy*dy + dz*dz); - len2 = (float)sqrt(dx*dx + dy*dy); + len1 = (float)WWMath::Sqrt(dx*dx + dy*dy + dz*dz); + len2 = (float)WWMath::Sqrt(dx*dx + dy*dy); if (len1 != 0.0f) { sinp = dz/len1; @@ -552,7 +552,7 @@ Matrix3D * Matrix3D::Get_Inverse(Matrix3D * out, float * detOut, const Matrix3D if (detOut) *detOut = det; - if (fabsf(det) < 1e-8f) + if (WWMath::Fabsf(det) < 1e-8f) return NULL; const float invDet = 1.0f / det; diff --git a/Core/Libraries/Source/WWVegas/WWMath/matrix3d.h b/Core/Libraries/Source/WWVegas/WWMath/matrix3d.h index f22898cc4b1..3fec2bd76c4 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/matrix3d.h +++ b/Core/Libraries/Source/WWVegas/WWMath/matrix3d.h @@ -566,8 +566,8 @@ WWINLINE void Matrix3D::Set( const Vector3 &x, // x-axis unit vector *=============================================================================================*/ WWINLINE void Matrix3D::Set(const Vector3 & axis,float angle) { - float c = cosf(angle); - float s = sinf(angle); + float c = WWMath::Cosf(angle); + float s = WWMath::Sinf(angle); Set(axis,s,c); } @@ -768,8 +768,8 @@ WWINLINE void Matrix3D::Rotate_X(float theta) float tmp1,tmp2; float s,c; - s = sinf(theta); - c = cosf(theta); + s = WWMath::Sinf(theta); + c = WWMath::Cosf(theta); tmp1 = Row[0][1]; tmp2 = Row[0][2]; Row[0][1] = (float)( c*tmp1 + s*tmp2); @@ -836,8 +836,8 @@ WWINLINE void Matrix3D::Rotate_Y(float theta) float tmp1,tmp2; float s,c; - s = sinf(theta); - c = cosf(theta); + s = WWMath::Sinf(theta); + c = WWMath::Cosf(theta); tmp1 = Row[0][0]; tmp2 = Row[0][2]; Row[0][0] = (float)(c*tmp1 - s*tmp2); @@ -903,8 +903,8 @@ WWINLINE void Matrix3D::Rotate_Z(float theta) float tmp1,tmp2; float c,s; - c = cosf(theta); - s = sinf(theta); + c = WWMath::Cosf(theta); + s = WWMath::Sinf(theta); tmp1 = Row[0][0]; tmp2 = Row[0][1]; Row[0][0] = (float)( c*tmp1 + s*tmp2); @@ -1058,8 +1058,8 @@ WWINLINE void Matrix3D::Pre_Rotate_X(float theta) float tmp1,tmp2; float c,s; - c = cosf(theta); - s = sinf(theta); + c = WWMath::Cosf(theta); + s = WWMath::Sinf(theta); tmp1 = Row[1][0]; tmp2 = Row[2][0]; Row[1][0] = (float)(c*tmp1 - s*tmp2); @@ -1096,8 +1096,8 @@ WWINLINE void Matrix3D::Pre_Rotate_Y(float theta) float tmp1,tmp2; float c,s; - c = cosf(theta); - s = sinf(theta); + c = WWMath::Cosf(theta); + s = WWMath::Sinf(theta); tmp1 = Row[0][0]; tmp2 = Row[2][0]; Row[0][0] = (float)( c*tmp1 + s*tmp2); @@ -1134,8 +1134,8 @@ WWINLINE void Matrix3D::Pre_Rotate_Z(float theta) float tmp1,tmp2; float c,s; - c = cosf(theta); - s = sinf(theta); + c = WWMath::Cosf(theta); + s = WWMath::Sinf(theta); tmp1 = Row[0][0]; tmp2 = Row[1][0]; Row[0][0] = (float)(c*tmp1 - s*tmp2); @@ -1277,8 +1277,8 @@ WWINLINE void Matrix3D::In_Place_Pre_Rotate_X(float theta) float tmp1,tmp2; float c,s; - c = cosf(theta); - s = sinf(theta); + c = WWMath::Cosf(theta); + s = WWMath::Sinf(theta); tmp1 = Row[1][0]; tmp2 = Row[2][0]; Row[1][0] = (float)(c*tmp1 - s*tmp2); @@ -1311,8 +1311,8 @@ WWINLINE void Matrix3D::In_Place_Pre_Rotate_Y(float theta) float tmp1,tmp2; float c,s; - c = cosf(theta); - s = sinf(theta); + c = WWMath::Cosf(theta); + s = WWMath::Sinf(theta); tmp1 = Row[0][0]; tmp2 = Row[2][0]; Row[0][0] = (float)( c*tmp1 + s*tmp2); @@ -1345,8 +1345,8 @@ WWINLINE void Matrix3D::In_Place_Pre_Rotate_Z(float theta) float tmp1,tmp2; float c,s; - c = cosf(theta); - s = sinf(theta); + c = WWMath::Cosf(theta); + s = WWMath::Sinf(theta); tmp1 = Row[0][0]; tmp2 = Row[1][0]; Row[0][0] = (float)(c*tmp1 - s*tmp2); diff --git a/Core/Libraries/Source/WWVegas/WWMath/matrix4.h b/Core/Libraries/Source/WWVegas/WWMath/matrix4.h index 626d441d4e9..834c1341a5b 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/matrix4.h +++ b/Core/Libraries/Source/WWVegas/WWMath/matrix4.h @@ -574,7 +574,7 @@ WWINLINE Matrix4x4* Matrix4x4::Inverse(Matrix4x4* out, float* detOut, const Matr if (detOut) *detOut = det; - if (fabsf(det) < 1e-8f) + if (WWMath::Fabsf(det) < 1e-8f) return NULL; const float invDet = 1.0f / det; diff --git a/Core/Libraries/Source/WWVegas/WWMath/quat.cpp b/Core/Libraries/Source/WWVegas/WWMath/quat.cpp index 091e8514542..930a3ea9a2f 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/quat.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/quat.cpp @@ -670,7 +670,7 @@ Quaternion Build_Quaternion(const Matrix3D & mat) if (tr > 0.0f) { - s = sqrt(tr + 1.0); + s = WWMath::Sqrt(tr + 1.0); q[3] = s * 0.5; s = 0.5 / s; @@ -686,7 +686,7 @@ Quaternion Build_Quaternion(const Matrix3D & mat) j = _nxt[i]; k = _nxt[j]; - s = sqrt((mat[i][i] - (mat[j][j] + mat[k][k])) + 1.0); + s = WWMath::Sqrt((mat[i][i] - (mat[j][j] + mat[k][k])) + 1.0); q[i] = s * 0.5; if (s != 0.0) { @@ -713,7 +713,7 @@ Quaternion Build_Quaternion(const Matrix3x3 & mat) if (tr > 0.0) { - s = sqrt(tr + 1.0); + s = WWMath::Sqrt(tr + 1.0); q[3] = s * 0.5; s = 0.5 / s; @@ -730,7 +730,7 @@ Quaternion Build_Quaternion(const Matrix3x3 & mat) j = _nxt[i]; k = _nxt[j]; - s = sqrt( (mat[i][i] - (mat[j][j]+mat[k][k])) + 1.0); + s = WWMath::Sqrt( (mat[i][i] - (mat[j][j]+mat[k][k])) + 1.0); q[i] = s * 0.5; @@ -757,7 +757,7 @@ Quaternion Build_Quaternion(const Matrix4x4 & mat) if (tr > 0.0) { - s = sqrt(tr + 1.0); + s = WWMath::Sqrt(tr + 1.0); q[3] = s * 0.5; s = 0.5 / s; @@ -774,7 +774,7 @@ Quaternion Build_Quaternion(const Matrix4x4 & mat) j = _nxt[i]; k = _nxt[j]; - s = sqrt( (mat[i][i] - (mat[j][j]+mat[k][k])) + 1.0); + s = WWMath::Sqrt( (mat[i][i] - (mat[j][j]+mat[k][k])) + 1.0); q[i] = s * 0.5; if (s != 0.0) { diff --git a/Core/Libraries/Source/WWVegas/WWMath/sphere.h b/Core/Libraries/Source/WWVegas/WWMath/sphere.h index 1c97e904f1e..3afec2888de 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/sphere.h +++ b/Core/Libraries/Source/WWVegas/WWMath/sphere.h @@ -193,7 +193,7 @@ inline SphereClass::SphereClass(const Vector3 *Position,const int VertCount) dz = dia2.Z - center.Z; double radsqr = dx*dx + dy*dy + dz*dz; - double radius = sqrt(radsqr); + double radius = WWMath::Sqrt(radsqr); // SECOND PASS: @@ -210,7 +210,7 @@ inline SphereClass::SphereClass(const Vector3 *Position,const int VertCount) // this point was outside the old sphere, compute a new // center point and radius which contains this point - double testrad = sqrt(testrad2); + double testrad = WWMath::Sqrt(testrad2); // adjust center and radius radius = (radius + testrad) / 2.0; diff --git a/Core/Libraries/Source/WWVegas/WWMath/vector2.h b/Core/Libraries/Source/WWVegas/WWMath/vector2.h index 2fe734cee66..3db367dedb2 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/vector2.h +++ b/Core/Libraries/Source/WWVegas/WWMath/vector2.h @@ -356,7 +356,7 @@ WWINLINE Vector2 Normalize(const Vector2 & vec) *========================================================================*/ WWINLINE float Vector2::Length() const { - return (float)WWMath::Sqrt(Length2()); + return WWMath::Sqrt(Length2()); } /************************************************************************** diff --git a/Core/Libraries/Source/WWVegas/WWMath/vector3.h b/Core/Libraries/Source/WWVegas/WWMath/vector3.h index 3a74fd91e04..f558c340813 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/vector3.h +++ b/Core/Libraries/Source/WWVegas/WWMath/vector3.h @@ -708,7 +708,7 @@ WWINLINE void Vector3::Scale(const Vector3 & scale) *=============================================================================================*/ WWINLINE void Vector3::Rotate_X(float angle) { - Rotate_X(sinf(angle),cosf(angle)); + Rotate_X(WWMath::Sinf(angle),WWMath::Cosf(angle)); } @@ -748,7 +748,7 @@ WWINLINE void Vector3::Rotate_X(float s_angle,float c_angle) *=============================================================================================*/ WWINLINE void Vector3::Rotate_Y(float angle) { - Rotate_Y(sinf(angle),cosf(angle)); + Rotate_Y(WWMath::Sinf(angle),WWMath::Cosf(angle)); } @@ -788,7 +788,7 @@ WWINLINE void Vector3::Rotate_Y(float s_angle,float c_angle) *=============================================================================================*/ WWINLINE void Vector3::Rotate_Z(float angle) { - Rotate_Z(sinf(angle),cosf(angle)); + Rotate_Z(WWMath::Sinf(angle),WWMath::Cosf(angle)); } diff --git a/Core/Libraries/Source/WWVegas/WWMath/vehiclecurve.cpp b/Core/Libraries/Source/WWVegas/WWMath/vehiclecurve.cpp index d92aa0a09c2..cd6ba177417 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/vehiclecurve.cpp +++ b/Core/Libraries/Source/WWVegas/WWMath/vehiclecurve.cpp @@ -95,7 +95,7 @@ Find_Tangent // float delta_x = point.X - center.X; float delta_y = point.Y - center.Y; - float dist = ::sqrt (delta_x * delta_x + delta_y * delta_y); + float dist = WWMath::Sqrt(delta_x * delta_x + delta_y * delta_y); if (dist >= radius) { // From a5b3e0259510dae0202f6994e3d8bf87107b76bf Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Tue, 22 Sep 2026 20:35:46 +0300 Subject: [PATCH 6/9] refactor(gameengine): Route game engine math through WWMath (#2670) Replaces the remaining direct libm calls in the shared engine code and in the game simulation of both Generals and Zero Hour with the WWMath wrappers, so that the simulation uses the deterministic implementation when it is enabled. --- .../Common/Diagnostic/SimulationMathCrc.cpp | 24 +++--- Core/GameEngine/Source/Common/INI/INI.cpp | 4 +- .../Source/GameLogic/AI/AIPathfind.cpp | 12 +-- .../Source/GameLogic/AI/Pathfinder/Path.cpp | 14 +-- .../GameLogic/AI/Pathfinder/PathfindCell.cpp | 4 +- .../GameLogic/AI/Pathfinder/PathfindLayer.cpp | 4 +- .../Source/GameLogic/Map/PolygonTrigger.cpp | 2 +- .../Source/GameLogic/Map/TerrainLogic.cpp | 30 +++---- .../W3DDevice/GameClient/BaseHeightMap.cpp | 2 +- .../Source/W3DDevice/GameClient/W3DMouse.cpp | 4 +- .../GameEngine/Source/Common/RTS/Player.cpp | 2 +- .../Source/Common/System/BuildAssistant.cpp | 10 +-- .../Source/Common/System/Geometry.cpp | 18 ++-- .../GameEngine/Source/GameLogic/AI/AI.cpp | 2 +- .../Source/GameLogic/AI/AIGroup.cpp | 4 +- .../Source/GameLogic/AI/AIPlayer.cpp | 10 +-- .../Source/GameLogic/AI/AISkirmishPlayer.cpp | 8 +- .../Source/GameLogic/AI/AIStates.cpp | 18 ++-- .../Source/GameLogic/AI/TurretAI.cpp | 8 +- .../Source/GameLogic/Map/PolygonTrigger.cpp | 2 +- .../Source/GameLogic/Map/TerrainLogic.cpp | 28 +++--- .../Object/Behavior/BridgeBehavior.cpp | 2 +- .../Behavior/DumbProjectileBehavior.cpp | 18 ++-- .../Behavior/GenerateMinefieldBehavior.cpp | 2 +- .../Object/Behavior/MinefieldBehavior.cpp | 8 +- .../Object/Behavior/SlowDeathBehavior.cpp | 4 +- .../GameLogic/Object/Body/ActiveBody.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 | 62 +++++++------ .../GameLogic/Object/Update/AIUpdate.cpp | 14 +-- .../Update/AIUpdate/ChinookAIUpdate.cpp | 8 +- .../AIUpdate/DeliverPayloadAIUpdate.cpp | 8 +- .../Object/Update/AIUpdate/DozerAIUpdate.cpp | 2 +- .../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 +- .../DynamicShroudClearingRangeUpdate.cpp | 4 +- .../GameLogic/Object/Update/FloatUpdate.cpp | 4 +- .../Update/NeutronMissileSlowDeathUpdate.cpp | 7 +- .../Object/Update/NeutronMissileUpdate.cpp | 6 +- .../Update/ParticleUplinkCannonUpdate.cpp | 2 +- .../GameLogic/Object/Update/PhysicsUpdate.cpp | 38 ++++---- .../Object/Update/PointDefenseLaserUpdate.cpp | 6 +- .../GameLogic/Object/Update/SlavedUpdate.cpp | 2 +- .../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 | 10 +-- .../Source/Common/System/Geometry.cpp | 18 ++-- .../GameEngine/Source/GameLogic/AI/AI.cpp | 4 +- .../Source/GameLogic/AI/AIGroup.cpp | 4 +- .../Source/GameLogic/AI/AIPlayer.cpp | 10 +-- .../Source/GameLogic/AI/AISkirmishPlayer.cpp | 10 +-- .../Source/GameLogic/AI/AIStates.cpp | 18 ++-- .../Source/GameLogic/AI/TurretAI.cpp | 8 +- .../Object/Behavior/BridgeBehavior.cpp | 2 +- .../Behavior/DumbProjectileBehavior.cpp | 18 ++-- .../Behavior/GenerateMinefieldBehavior.cpp | 6 +- .../Object/Behavior/MinefieldBehavior.cpp | 10 +-- .../Object/Behavior/SlowDeathBehavior.cpp | 4 +- .../GameLogic/Object/Body/ActiveBody.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 | 62 +++++++------ .../GameLogic/Object/Update/AIUpdate.cpp | 14 +-- .../Update/AIUpdate/ChinookAIUpdate.cpp | 6 +- .../AIUpdate/DeliverPayloadAIUpdate.cpp | 15 ++-- .../Object/Update/AIUpdate/DozerAIUpdate.cpp | 2 +- .../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 | 4 +- .../DockUpdate/SupplyWarehouseDockUpdate.cpp | 4 +- .../DynamicShroudClearingRangeUpdate.cpp | 4 +- .../GameLogic/Object/Update/FloatUpdate.cpp | 4 +- .../Update/NeutronMissileSlowDeathUpdate.cpp | 7 +- .../Object/Update/NeutronMissileUpdate.cpp | 6 +- .../Update/ParticleUplinkCannonUpdate.cpp | 2 +- .../GameLogic/Object/Update/PhysicsUpdate.cpp | 44 +++++----- .../Object/Update/PointDefenseLaserUpdate.cpp | 6 +- .../GameLogic/Object/Update/SlavedUpdate.cpp | 2 +- .../Update/SpectreGunshipDeploymentUpdate.cpp | 2 +- .../GameLogic/Object/Update/StealthUpdate.cpp | 2 +- .../Object/Update/TensileFormationUpdate.cpp | 2 +- .../GameLogic/Object/Update/ToppleUpdate.cpp | 10 +-- .../Source/GameLogic/Object/Weapon.cpp | 26 +++--- .../Source/GameLogic/System/GameLogic.cpp | 2 +- 101 files changed, 551 insertions(+), 520 deletions(-) diff --git a/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp b/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp index b40f0487b65..7bcae67bb17 100644 --- a/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp +++ b/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp @@ -37,18 +37,18 @@ static void appendSimulationMathCrc(XferCRC &xfer) 0.9f, 1.0f, 2.1f, 1.2f); factorsMatrix.Set( - WWMath::Sinf(0.7f) * log10f(2.3f), - WWMath::Cosf(1.1f) * powf(1.1f, 2.0f), - tanf(0.3f), - asinf(0.967302263f), - acosf(0.967302263f), - atanf(0.967302263f) * powf(1.1f, 2.0f), - atan2f(0.4f, 1.3f), - sinhf(0.2f), - coshf(0.4f) * tanhf(0.5f), - sqrtf(55788.84375f), - expf(0.1f) * log10f(2.3f), - logf(1.4f)); + WWMath::Sinf(0.7f) * WWMath::Log10f(2.3f), + WWMath::Cosf(1.1f) * WWMath::Powf(1.1f, 2.0f), + WWMath::Tanf(0.3f), + WWMath::Asinf(0.967302263f), + WWMath::Acosf(0.967302263f), + WWMath::Atanf(0.967302263f) * WWMath::Powf(1.1f, 2.0f), + WWMath::Atan2f(0.4f, 1.3f), + WWMath::Sinhf(0.2f), + WWMath::Coshf(0.4f) * WWMath::Tanhf(0.5f), + WWMath::Sqrtf(55788.84375f), + WWMath::Expf(0.1f) * WWMath::Log10f(2.3f), + WWMath::Logf(1.4f)); Matrix3D::Multiply(matrix, factorsMatrix, &matrix); matrix.Get_Inverse(matrix); diff --git a/Core/GameEngine/Source/Common/INI/INI.cpp b/Core/GameEngine/Source/Common/INI/INI.cpp index a30d5b03cfe..04b52a04762 100644 --- a/Core/GameEngine/Source/Common/INI/INI.cpp +++ b/Core/GameEngine/Source/Common/INI/INI.cpp @@ -1798,7 +1798,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::Ceilf(ConvertDurationFromMsecsToFrames((Real)val)); } // ------------------------------------------------------------------------------------------------ @@ -1806,7 +1806,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::Ceilf(ConvertDurationFromMsecsToFrames((Real)val)); } //------------------------------------------------------------------------------------------------- diff --git a/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp b/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp index ec7267b6cb9..b0e3dd703a5 100644 --- a/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp +++ b/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp @@ -2535,7 +2535,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()) { @@ -2560,7 +2560,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::Sqrt((float)(dx*dx + dy*dy)); costRemaining -= attackDistance/2; if (costRemaining<0) costRemaining=0; @@ -2884,7 +2884,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::Sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); if (count<2) count = 2; Int i; color.green = 0; @@ -3581,7 +3581,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::Sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); if (count<2) count = 2; Int i; color.green = 0; @@ -4277,7 +4277,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::Sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); if (count<2) count = 2; Int i; color.green = 0; @@ -7346,7 +7346,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::Sqrt(farthestDistanceSqr), repulsorRadius)); #endif ok = true; // Already a big search, just take this one. } diff --git a/Core/GameEngine/Source/GameLogic/AI/Pathfinder/Path.cpp b/Core/GameEngine/Source/GameLogic/AI/Pathfinder/Path.cpp index ca4c3c79411..fbd7fae588a 100644 --- a/Core/GameEngine/Source/GameLogic/AI/Pathfinder/Path.cpp +++ b/Core/GameEngine/Source/GameLogic/AI/Pathfinder/Path.cpp @@ -511,9 +511,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::Fabs(a.x-b.x) <= CLOSE_ENOUGH && + WWMath::Fabs(a.y-b.y) <= CLOSE_ENOUGH && + WWMath::Fabs(a.z-b.z) <= CLOSE_ENOUGH; } /** @@ -695,14 +695,14 @@ 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::Sqrt(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 // projected position on the path. If we are very far off the path, we will move // directly towards the nearest point on the path, and not the next path node. const Real maxPathError = 3.0f * PATHFIND_CELL_SIZE_F; - const Real maxPathErrorInv = 1.0 / maxPathError; + const Real maxPathErrorInv = 1.0f / maxPathError; Real k = offsetDist * maxPathErrorInv; if (k > 1.0f) k = 1.0f; @@ -785,8 +785,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::Fabs(pos.x - out.posOnPath.x); + Real dy = WWMath::Fabs(pos.y - out.posOnPath.y); if (dx<1 && dy<1 && closeNode->getNextOptimized() && closeNode->getNextOptimized()->getNextOptimized()) { out.posOnPath = *closeNode->getNextOptimized()->getNextOptimized()->getPosition(); } diff --git a/Core/GameEngine/Source/GameLogic/AI/Pathfinder/PathfindCell.cpp b/Core/GameEngine/Source/GameLogic/AI/Pathfinder/PathfindCell.cpp index 4c3d16c8520..2008c8298fe 100644 --- a/Core/GameEngine/Source/GameLogic/AI/Pathfinder/PathfindCell.cpp +++ b/Core/GameEngine/Source/GameLogic/AI/Pathfinder/PathfindCell.cpp @@ -861,7 +861,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::Sqrt((float)(dx*dx + dy*dy)); #else if (dx<0) dx = -dx; if (dy<0) dy = -dy; @@ -887,7 +887,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::Sqrt((float)(dx*dx + dy*dy)) + 0.5f); return cost; } diff --git a/Core/GameEngine/Source/GameLogic/AI/Pathfinder/PathfindLayer.cpp b/Core/GameEngine/Source/GameLogic/AI/Pathfinder/PathfindLayer.cpp index 7a1901172e0..10f65b857f5 100644 --- a/Core/GameEngine/Source/GameLogic/AI/Pathfinder/PathfindLayer.cpp +++ b/Core/GameEngine/Source/GameLogic/AI/Pathfinder/PathfindLayer.cpp @@ -614,8 +614,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::Fabs(ptx*c - pty*s); + Real pty_new = (Real)WWMath::Fabs(ptx*s + pty*c); if (ptx_new <= major && pty_new <= minor) { diff --git a/Core/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp b/Core/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp index e163ce30f8f..b212c2d5779 100644 --- a/Core/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp +++ b/Core/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp @@ -292,7 +292,7 @@ void PolygonTrigger::updateBounds() const Real halfWidth = (m_bounds.hi.x - m_bounds.lo.x) / 2.0f; Real halfHeight = (m_bounds.hi.y + m_bounds.lo.y) / 2.0f; - m_radius = sqrt(halfHeight*halfHeight + halfWidth*halfWidth); + m_radius = WWMath::Sqrt(halfHeight*halfHeight + halfWidth*halfWidth); } diff --git a/Core/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp b/Core/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp index 2225b35618f..863564360dc 100644 --- a/Core/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp +++ b/Core/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp @@ -1434,7 +1434,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::Atan2(xvec.y, xvec.x) == angle. So we must construct the matrix carefully to ensure this! */ x.x = Cos( angle ); @@ -1455,7 +1455,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::Fabs(x.x*z.x + x.y*z.y + x.z*z.z)<0.0001,("dot is not zero (%f)",WWMath::Fabs(x.x*z.x + x.y*z.y + x.z*z.z))); // now computing the y vector is trivial. y.crossProduct( z, x, y ); @@ -1656,12 +1656,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::Fabs(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::Fabs(pos->z-TheAI->pathfinder()->getWallHeight()); if (deltaisPointOnBridge(pos) ) { - Real delta = fabs(pos->z-pBridge->getBridgeHeight(pos, nullptr)); + Real delta = WWMath::Fabs(pos->z-pBridge->getBridgeHeight(pos, nullptr)); if (deltagetLayer(); bestDistance = delta; @@ -1695,7 +1695,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::Fabs(delta) < WWMath::Fabs(bestDistance)) { bestLayer = (PathfindLayerEnum)LAYER_WALL; bestDistance = delta; } @@ -1710,7 +1710,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::Fabs(delta) < WWMath::Fabs(bestDistance)) { bestLayer = pBridge->getLayer(); bestDistance = delta; } @@ -1758,7 +1758,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::Fabs(obj->getPosition()->z-bridgeHeight); if (delta>LAYER_Z_CLOSE_ENOUGH_F) { return false; } @@ -1806,7 +1806,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::Fabs(obj->getPosition()->z-bridgeHeight); if (delta>LAYER_Z_CLOSE_ENOUGH_F) { return false; @@ -2036,10 +2036,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::Fabs( closestTo->y - mapExtent.lo.y );//top + distances[1] = WWMath::Fabs( closestTo->x - mapExtent.hi.x );//right + distances[2] = WWMath::Fabs( closestTo->y - mapExtent.hi.y );//bottom + distances[3] = WWMath::Fabs( closestTo->x - mapExtent.lo.x );//left Real bestDistance = distances[0]; Int bestDistanceIndex = 0; for( Int lameIndex = 1; lameIndex < 4; lameIndex++ ) @@ -2350,7 +2350,7 @@ void TerrainLogic::setWaterHeight( const WaterHandle *water, Real height, Real d center.z = 0.0f; // irrelevant // the max radius to scan around us is the diagonal of the bounding region - Real maxDist = sqrt( affectedRegion.width() * affectedRegion.width() + + Real maxDist = WWMath::Sqrt( affectedRegion.width() * affectedRegion.width() + affectedRegion.height() * affectedRegion.height() ); // scan the objects in the area of the water affected @@ -2870,7 +2870,7 @@ void TerrainLogic::createCraterInTerrain(Object *obj) deltaX = ( i * MAP_XY_FACTOR ) - pos->x; deltaY = ( j * MAP_XY_FACTOR ) - pos->y; - Real distance = sqrt( sqr( deltaX ) + sqr( deltaY ) ); + Real distance = WWMath::Sqrt( sqr( deltaX ) + sqr( deltaY ) ); if ( distance < radius ) //inside circle { diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp index 4cbe7db3bad..9515f864a5e 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp @@ -1734,7 +1734,7 @@ void BaseHeightMapRenderObjClass::updateViewImpassableAreas(Bool partial, Int mi } // save calculating the tangent over and over again. - Real tanImpassableRad = tan(m_curImpassableSlope / 360.f * 2 * PI); + Real tanImpassableRad = WWMath::Tan(m_curImpassableSlope / 360.f * 2 * PI); for (Int j = minY; j < maxY; ++j) { for (Int i = minX; i < maxX; ++i) { m_showAsVisibleCliff[i + j * xSize] = evaluateAsVisibleCliff(i, j, tanImpassableRad); diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DMouse.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DMouse.cpp index 501ecbf09d1..8d21e481280 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DMouse.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DMouse.cpp @@ -570,7 +570,7 @@ void W3DMouse::draw() { offset = TheInGameUI->getScrollAmount(); offset.normalize(); - Real theta = atan2(-offset.y, offset.x); + Real theta = WWMath::Atan2(-offset.y, offset.x); theta -= (Real)M_PI/2; tm.Rotate_Z(theta); } @@ -678,7 +678,7 @@ void W3DMouse::setCursorDirection(MouseCursor cursor) if (offset.x || offset.y) { offset.normalize(); - Real theta = atan2(offset.y, offset.x); + Real theta = WWMath::Atan2(offset.y, offset.x); theta = fmod(theta+M_PI*2,M_PI*2); Int numDirections=m_cursorInfo[m_currentCursor].numDirections; //Figure out which of our predrawn cursor orientations best matches the diff --git a/Generals/Code/GameEngine/Source/Common/RTS/Player.cpp b/Generals/Code/GameEngine/Source/Common/RTS/Player.cpp index 3aed1cc755e..d2e46b2922a 100644 --- a/Generals/Code/GameEngine/Source/Common/RTS/Player.cpp +++ b/Generals/Code/GameEngine/Source/Common/RTS/Player.cpp @@ -2370,7 +2370,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::Ceil((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 4b6f48e8ecc..dea4ecb27e5 100644 --- a/Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp +++ b/Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp @@ -752,8 +752,8 @@ Bool BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos, if (myFactoryExitWidth>0) { myExitPos = *worldPos; checkMyExit = true; - Real c = (Real)cos(angle); - Real s = (Real)sin(angle); + Real c = (Real)WWMath::Cos(angle); + Real s = (Real)WWMath::Sin(angle); Real offset = build->getTemplateGeometryInfo().getMajorRadius() + myFactoryExitWidth/2.0f; myExitPos.x += c*offset; myExitPos.y += s*offset; @@ -787,8 +787,8 @@ Bool BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos, if (themFactoryExitWidth>0) { hisExitPos = *them->getPosition(); checkHisExit = true; - Real c = (Real)cos(them->getOrientation()); - Real s = (Real)sin(them->getOrientation()); + Real c = (Real)WWMath::Cos(them->getOrientation()); + Real s = (Real)WWMath::Sin(them->getOrientation()); Real offset = them->getGeometryInfo().getMajorRadius() + themFactoryExitWidth/2.0f; hisExitPos.x += c*offset; hisExitPos.y += s*offset; @@ -1405,7 +1405,7 @@ Bool BuildAssistant::moveObjectsForConstruction( const ThingTemplate *whatToBuil Bool anyUnmovables = false; MemoryPoolObjectHolder hold( iter ); - Real radius = sqrt(pow(gi.getMajorRadius(), 2) + pow(gi.getMinorRadius(), 2)); + Real radius = WWMath::Sqrt(WWMath::Pow(gi.getMajorRadius(), 2) + WWMath::Pow(gi.getMinorRadius(), 2)); radius *= 1.4f; // Fudge the distance, for( Object *them = iter->first(); them; them = iter->next() ) diff --git a/Generals/Code/GameEngine/Source/Common/System/Geometry.cpp b/Generals/Code/GameEngine/Source/Common/System/Geometry.cpp index 2e4c35a2421..66b04f57ea4 100644 --- a/Generals/Code/GameEngine/Source/Common/System/Geometry.cpp +++ b/Generals/Code/GameEngine/Source/Common/System/Geometry.cpp @@ -173,17 +173,17 @@ void GeometryInfo::calcPitches(const Coord3D& thisPos, const GeometryInfo& that, Coord3D thisCenter; getCenterPosition(thisPos, thisCenter); - Real dxy = sqrt(sqr(thatPos.x - thisCenter.x) + sqr(thatPos.y - thisCenter.y)); + Real dxy = WWMath::Sqrt(sqr(thatPos.x - thisCenter.x) + sqr(thatPos.y - thisCenter.y)); Real dz; /** @todo srj -- this could be better, by calcing it for all the corners, not just top-center and bottom-center... oh well */ dz = (thatPos.z + that.getMaxHeightAbovePosition()) - thisCenter.z; - maxPitch = atan2(dz, dxy); + maxPitch = WWMath::Atan2(dz, dxy); dz = (thatPos.z - that.getMaxHeightBelowPosition()) - thisCenter.z; - minPitch = atan2(dz, dxy); + minPitch = WWMath::Atan2(dz, dxy); } //============================================================================= @@ -279,8 +279,8 @@ void GeometryInfo::get2DBounds(const Coord3D& geomCenter, Real angle, Region2D& case GEOMETRY_BOX: { - Real c = (Real)cos(angle); - Real s = (Real)sin(angle); + Real c = (Real)WWMath::Cos(angle); + Real s = (Real)WWMath::Sin(angle); Real exc = m_majorRadius*c; Real eyc = m_minorRadius*c; Real exs = m_majorRadius*s; @@ -329,7 +329,7 @@ void GeometryInfo::clipPointToFootprint(const Coord3D& geomCenter, Coord3D& ptTo { Real dx = ptToClip.x - geomCenter.x; Real dy = ptToClip.y - geomCenter.y; - Real radius = sqrt(sqr(dx) + sqr(dy)); + Real radius = WWMath::Sqrt(sqr(dx) + sqr(dy)); if (radius > m_majorRadius) { Real ratio = m_majorRadius / radius; @@ -361,7 +361,7 @@ Bool GeometryInfo::isPointInFootprint(const Coord3D& geomCenter, const Coord3D& { Real dx = pt.x - geomCenter.x; Real dy = pt.y - geomCenter.y; - Real radius = sqrt(sqr(dx) + sqr(dy)); + Real radius = WWMath::Sqrt(sqr(dx) + sqr(dy)); return (radius <= m_majorRadius); break; } @@ -506,8 +506,8 @@ void GeometryInfo::calcBoundingStuff() case GEOMETRY_BOX: { - m_boundingCircleRadius = sqrt(sqr(m_majorRadius) + sqr(m_minorRadius)); - m_boundingSphereRadius = sqrt(sqr(m_majorRadius) + sqr(m_minorRadius) + sqr(m_height*0.5)); + m_boundingCircleRadius = WWMath::Sqrt(sqr(m_majorRadius) + sqr(m_minorRadius)); + m_boundingSphereRadius = WWMath::Sqrt(sqr(m_majorRadius) + sqr(m_minorRadius) + sqr(m_height*0.5)); break; } }; diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AI.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AI.cpp index ad9493ccf4f..b4004ab5fcd 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AI.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AI.cpp @@ -712,7 +712,7 @@ Object *AI::findClosestEnemy( const Object *me, Real range, UnsignedInt qualifie } Real distSqr = ThePartitionManager->getDistanceSquared(me, theEnemy, FROM_BOUNDINGSPHERE_2D); - Real dist = sqrt(distSqr); + Real dist = WWMath::Sqrtf(distSqr); Int modifier = dist/getAiData()->m_attackPriorityDistanceModifier; Int modPriority = curPriority-modifier; if (modPriority < 1) diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp index 1568ec2f8fb..a2711399207 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp @@ -1839,8 +1839,8 @@ void getHelicopterOffset( Coord3D& posOut, Int idx ) } Coord3D tempCtr = posOut; - posOut.x = tempCtr.x + (sin(angle) * radius); - posOut.y = tempCtr.y + (cos(angle) * radius); + posOut.x = tempCtr.x + (WWMath::Sin(angle) * radius); + posOut.y = tempCtr.y + (WWMath::Cos(angle) * radius); } diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp index 5a9159f7635..1421b406483 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp @@ -488,7 +488,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::Fabs(info->getRallyOffset()->x) > 1.0f || WWMath::Fabs(info->getRallyOffset()->y)>1.0f) { gotOffset; } if (!exitInterface->getNaturalRallyPoint(rallyPoint)) { @@ -646,7 +646,7 @@ Object *AIPlayer::buildStructureWithDozer(const ThingTemplate *bldgPlan, BuildLi dx = dozer->getPosition()->x - pos.x; dy = dozer->getPosition()->y - pos.y; - Int count = sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); + Int count = WWMath::Sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); if (count<2) count = 2; Int i; color.green = 1; @@ -668,7 +668,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::Fabs(info->getRallyOffset()->x) > 1.0f || WWMath::Fabs(info->getRallyOffset()->y)>1.0f) { gotOffset; } if (!exitInterface->getNaturalRallyPoint(rallyPoint)) { @@ -1269,7 +1269,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)) { @@ -2834,7 +2834,7 @@ void AIPlayer::computeCenterAndRadiusOfBase(Coord3D *center, Real *radius) Real radSqr = dx*dx+dy*dy; if (radSqr>maxRadSqr) maxRadSqr=radSqr; } - *radius = sqrt(maxRadSqr); + *radius = WWMath::Sqrt(maxRadSqr); } //---------------------------------------------------------------------------------------------------------- diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp index 6533eb28460..8966011fafd 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp @@ -663,8 +663,8 @@ void AISkirmishPlayer::buildAIBaseDefenseStructure(const AsciiString &thingName, } if (angle > PI/3) break; - Real s = sin(angle); - Real c = cos(angle); + Real s = WWMath::Sin(angle); + Real c = WWMath::Cos(angle); // TheSuperHackers @info helmutbuhler 21/04/2025 This debug mutates the code to become CRC incompatible #if defined(RTS_DEBUG) || !RETAIL_COMPATIBLE_CRC @@ -1030,8 +1030,8 @@ void AISkirmishPlayer::adjustBuildList(BuildListInfo *list) angle += 3*PI/4; - Real s = sin(angle); - Real c = cos(angle); + Real s = WWMath::Sin(angle); + Real c = WWMath::Cos(angle); cur = list; while (cur) { diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp index ff9cd77e1cb..0005d1c9e49 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::Fabs(TheGlobalData->m_gravity) * LOGICFRAMES_PER_SECOND * 2.5f; m_rappelRate = -min(ai->getDesiredSpeed(), MAX_RAPPEL_RATE); return STATE_CONTINUE; @@ -3585,7 +3585,7 @@ StateReturnType AIAttackMoveToState::update() if (distSqr < sqr(ATTACK_CLOSE_ENOUGH_CELLS*PATHFIND_CELL_SIZE_F)) { return ret; } - DEBUG_LOG(("AIAttackMoveToState::update Distance from goal %f, retrying.", sqrt(distSqr))); + DEBUG_LOG(("AIAttackMoveToState::update Distance from goal %f, retrying.", WWMath::Sqrt(distSqr))); ret = STATE_CONTINUE; m_retryCount--; @@ -3815,16 +3815,16 @@ void AIFollowWaypointPathState::computeGoal(Bool useGroupOffsets) if (m_priorWaypoint) { dx = dest.x - m_priorWaypoint->getLocation()->x; dy = dest.y - m_priorWaypoint->getLocation()->y; - angle = atan2(dy, dx); + angle = WWMath::Atan2(dy, dx); Real deltaAngle = angle - m_angle; - Real s = sin(deltaAngle); - Real c = cos(deltaAngle); + Real s = WWMath::Sin(deltaAngle); + Real c = WWMath::Cos(deltaAngle); Real x = m_groupOffset.x * c - m_groupOffset.y * s; Real y = m_groupOffset.y * c + m_groupOffset.x * s; m_groupOffset.x = x; m_groupOffset.y = y; } else { - angle = atan2(dy, dx); + angle = WWMath::Atan2(dy, dx); } m_angle = angle; #endif @@ -4946,7 +4946,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::Fabs(relAngle) > aimDelta) { Real desiredAngle = source->getOrientation() + relAngle; sourceAI->setLocomotorGoalOrientation(desiredAngle); @@ -4958,7 +4958,7 @@ StateReturnType AIAttackAimAtTargetState::update() sourceAI->setLocomotorGoalPositionExplicit(m_isAttackingObject ? *victim->getPosition() : *getMachineGoalPosition()); } - if (fabs(relAngle) < aimDelta /*&& !m_preAttackFrames*/ ) + if (WWMath::Fabs(relAngle) < aimDelta /*&& !m_preAttackFrames*/ ) { AIUpdateInterface* victimAI = victim ? victim->getAI() : nullptr; // add ourself as a targeter BEFORE calling isTemporarilyPreventingAimSuccess(). @@ -7004,7 +7004,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::Fabs( 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 ba41dd60151..cdf0802f400 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp @@ -401,7 +401,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::Fabs(angleDiff) < turnRate) { // we are centered actualAngle = desiredAngle; @@ -424,7 +424,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::Fabs(m_angle - desiredAngle) <= relThresh; return aligned; } @@ -442,7 +442,7 @@ Bool TurretAI::friend_turnTowardsPitch(Real desiredPitch, Real rateModifier) Real pitchRate = getPitchRate() * rateModifier; Real pitchDiff = normalizeAngle(desiredPitch - actualPitch); - if (fabs(pitchDiff) < pitchRate) + if (WWMath::Fabs(pitchDiff) < pitchRate) { // we are centered actualPitch = desiredPitch; @@ -1085,7 +1085,7 @@ StateReturnType TurretAIAimTurretState::update() turret->friend_setPositiveSweep(!turret->friend_getPositiveSweep()); Real angleDiff = normalizeAngle(relAngle - turret->getTurretAngle()); - turnAlignedToNemesis = (fabs(angleDiff) < sweep); + turnAlignedToNemesis = (WWMath::Fabs(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 9c0064294fa..96191534ff5 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp @@ -292,7 +292,7 @@ void PolygonTrigger::updateBounds() const Real halfWidth = (m_bounds.hi.x - m_bounds.lo.x) / 2.0f; Real halfHeight = (m_bounds.hi.y + m_bounds.lo.y) / 2.0f; - m_radius = sqrt(halfHeight*halfHeight + halfWidth*halfWidth); + m_radius = WWMath::Sqrt(halfHeight*halfHeight + halfWidth*halfWidth); } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp b/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp index 1b402424162..668962450ef 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp @@ -1434,7 +1434,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::Atan2(xvec.y, xvec.x) == angle. So we must construct the matrix carefully to ensure this! */ x.x = Cos( angle ); @@ -1455,7 +1455,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::Fabs(x.x*z.x + x.y*z.y + x.z*z.z)<0.0001,("dot is not zero (%f)",WWMath::Fabs(x.x*z.x + x.y*z.y + x.z*z.z))); // now computing the y vector is trivial. y.crossProduct( z, x, y ); @@ -1656,12 +1656,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::Fabs(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::Fabs(pos->z-TheAI->pathfinder()->getWallHeight()); if (deltaisPointOnBridge(pos) ) { - Real delta = fabs(pos->z-pBridge->getBridgeHeight(pos, nullptr)); + Real delta = WWMath::Fabs(pos->z-pBridge->getBridgeHeight(pos, nullptr)); if (deltagetLayer(); bestDistance = delta; @@ -1695,7 +1695,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::Fabs(delta) < WWMath::Fabs(bestDistance)) { bestLayer = (PathfindLayerEnum)LAYER_WALL; bestDistance = delta; } @@ -1710,7 +1710,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::Fabs(delta) < WWMath::Fabs(bestDistance)) { bestLayer = pBridge->getLayer(); bestDistance = delta; } @@ -1758,7 +1758,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::Fabs(obj->getPosition()->z-bridgeHeight); if (delta>LAYER_Z_CLOSE_ENOUGH_F) { return false; } @@ -1806,7 +1806,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::Fabs(obj->getPosition()->z-bridgeHeight); if (delta>LAYER_Z_CLOSE_ENOUGH_F) { return false; @@ -2036,10 +2036,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::Fabs( closestTo->y - mapExtent.lo.y );//top + distances[1] = WWMath::Fabs( closestTo->x - mapExtent.hi.x );//right + distances[2] = WWMath::Fabs( closestTo->y - mapExtent.hi.y );//bottom + distances[3] = WWMath::Fabs( closestTo->x - mapExtent.lo.x );//left Real bestDistance = distances[0]; Int bestDistanceIndex = 0; for( Int lameIndex = 1; lameIndex < 4; lameIndex++ ) @@ -2350,7 +2350,7 @@ void TerrainLogic::setWaterHeight( const WaterHandle *water, Real height, Real d center.z = 0.0f; // irrelevant // the max radius to scan around us is the diagonal of the bounding region - Real maxDist = sqrt( affectedRegion.width() * affectedRegion.width() + + Real maxDist = WWMath::Sqrt( affectedRegion.width() * affectedRegion.width() + affectedRegion.height() * affectedRegion.height() ); // scan the objects in the area of the water affected diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/BridgeBehavior.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/BridgeBehavior.cpp index f2af520f00f..11b4a911249 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/BridgeBehavior.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/BridgeBehavior.cpp @@ -1115,7 +1115,7 @@ void BridgeBehavior::createScaffolding() // to the center area of the bridge // Real tileDistance = leftVector.length(); - Int numObjects = REAL_TO_INT_CEIL( tileDistance / spacing ) + 1; + Int numObjects = REAL_TO_INT_CEIL( WWMath::Div_Safe(tileDistance, spacing, 1.0f) ) + 1; // // given the number of objects that we need to tile across the whole bridge, we will diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp index 7c4bc633863..91de7df18d0 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::Atan2(dy, dx); // calculating the pitch requires a bit more effort. Real horizDistSqr = sqr(dx) + sqr(dy); - Real horizDist = sqrt(horizDistSqr); + Real horizDist = WWMath::Sqrt(horizDistSqr); // calc the two possible pitches that will cover the given horizontal range. // (this is actually only true if dz==0, but is a good first guess) - Real gravity = fabs(TheGlobalData->m_gravity); + Real gravity = WWMath::Fabs(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::Atan2(dz, horizDist); // if the angle isn't pretty shallow, we can get a better initial guess by using // the code below... const Real SHALLOW_ANGLE = 0.5f * PI / 180.0f; - if (fabs(theta) > SHALLOW_ANGLE) + if (WWMath::Fabs(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::Sqrt(root)))/gravity; const Real CLOSE_ENOUGH_RANGE = 5.0f; if (tooClose || (actualRange < horizDist - CLOSE_ENOUGH_RANGE)) { @@ -366,7 +366,7 @@ void DumbProjectileBehavior::projectileFireAtObjectOrPosition( const Object *vic // Some weapons want to scale their start speed to the range Real minRange = detWeap->getMinimumAttackRange(); Real maxRange = detWeap->getUnmodifiedAttackRange(); - Real range = sqrt(ThePartitionManager->getDistanceSquared( projectile, &victimPosToUse, FROM_CENTER_2D ) ); + Real range = WWMath::Sqrt(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 = (Int)WWMath::Ceil( WWMath::Div_Safe(flightDistance, m_flightPathSpeed, 1.0f) ); } 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::Sqrtf(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..335e4bc02de 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp @@ -232,7 +232,7 @@ void GenerateMinefieldBehavior::placeMinesAlongLine(const Coord3D& posStart, con Real dx = posEnd.x - posStart.x; Real dy = posEnd.y - posStart.y; - Real len = sqrt(sqr(dx) + sqr(dy)); + Real len = WWMath::Sqrt(sqr(dx) + sqr(dy)); Real mineRadius = mineTemplate->getTemplateGeometryInfo().getBoundingCircleRadius(); Real mineDiameter = mineRadius * 2.0f; Real mineJitter = mineRadius*d->m_randomJitter; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp index 5a4b2727060..f0d474ebb35 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::Sqrtf(2.0f * (start.z - endOnGround.z) / WWMath::Fabs(TheGlobalData->m_gravity))); // we can scoot after we land, but don't want to stop scooting before we land if (scootFromStartingPointTime < fallingTime) scootFromStartingPointTime = fallingTime; @@ -580,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::Sqrt(sqr(dx) + sqr(dy)); + if (dist <= 0.1f && WWMath::Fabs(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::Fabs(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..2fe6dda5775 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp @@ -179,7 +179,7 @@ Int SlowDeathBehavior::getProbabilityModifier( const DamageInfo *damageInfo ) co // severly killed, and more sedate ones when only slightly killed. // eg ( 200 hp max, had 10 left, took 50 damage, 40 overkill, (40/200) * 100 = 20 overkill %) Int overkillDamage = damageInfo->out.m_actualDamageDealt - damageInfo->out.m_actualDamageClipped; - Real overkillPercent = (float)overkillDamage / (float)getObject()->getBodyModule()->getMaxHealth(); + Real overkillPercent = WWMath::Div_Safe((float)overkillDamage, (float)getObject()->getBodyModule()->getMaxHealth()); Int overkillModifier = overkillPercent * getSlowDeathBehaviorModuleData()->m_modifierBonusPerOverkillPercent; return max( getSlowDeathBehaviorModuleData()->m_probabilityModifier + overkillModifier, 1 ); @@ -299,7 +299,7 @@ void SlowDeathBehavior::beginSlowDeath(const DamageInfo *damageInfo) physics->setExtraBounciness(-1.0); // we don't want this guy to bounce at all physics->setExtraFriction(-3 * SECONDS_PER_LOGICFRAME_REAL); // reduce his ground friction a bit physics->setAllowBouncing(true); - Real orientation = atan2(force.y, force.x); + Real orientation = WWMath::Atan2(force.y, force.x); physics->setAngles(orientation, 0, 0); obj->getDrawable()->setModelConditionState(MODELCONDITION_EXPLODED_FLAILING); m_flags |= (1<getPosition()->z) >= d->m_paraOpenDist) + if (WWMath::Fabs(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 fecde3e7f78..58aedc79d8d 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp @@ -119,7 +119,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::Fabs(maxBraking)) * 0.5f; // use a little fudge so that things can stop "on a dime" more easily... const Real FUDGE = 1.05f; @@ -130,14 +130,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::Fabs(a) < TINY_EPSILON; } //----------------------------------------------------------------------------- inline Bool isNearly(Real a, Real val) { const Real TINY_EPSILON = 0.001f; - return fabs(a - val) < TINY_EPSILON; + return WWMath::Fabs(a - val) < TINY_EPSILON; } //----------------------------------------------------------------------------- @@ -176,7 +176,7 @@ static Real tryToRotateVector3D( } } - if (fabs(angleBetween) <= maxAngle) + if (WWMath::Fabs(angleBetween) <= maxAngle) { // close enough actualDir = goalDir; @@ -266,9 +266,9 @@ static void calcDirectionToApplyThrust( Bool foundSolution = false; Real distToGoalSqr = vecToGoal.Length2(); - Real distToGoal = sqrt(distToGoalSqr); + Real distToGoal = WWMath::Sqrt(distToGoalSqr); Real curVelMagSqr = curVel.Length2(); - Real curVelMag = sqrt(curVelMagSqr); + Real curVelMag = WWMath::Sqrt(curVelMagSqr); Real maxAccelSqr = sqr(maxAccel); Real denom = curVelMagSqr - maxAccelSqr; @@ -1098,7 +1098,7 @@ void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalP Real dx = goalPos.x - obj->getPosition()->x; Real dy = goalPos.y - obj->getPosition()->y; Real dz = goalPos.z - obj->getPosition()->z; - Real dist = sqrt(dx*dx+dy*dy); + Real dist = WWMath::Sqrt(dx*dx+dy*dy); if (dist>onPathDistToGoal) { if (!obj->isKindOf(KINDOF_PROJECTILE) && dist>2*onPathDistToGoal) @@ -1216,7 +1216,7 @@ void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalP // Projectiles never stop braking once they start. jba. obj->setStatus( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_BRAKING ) ); // Projectiles cheat in 3 dimensions. - dist = sqrt(dx*dx+dy*dy+dz*dz); + dist = WWMath::Sqrt(dx*dx+dy*dy+dz*dz); Real vel = physics->getVelocityMagnitude(); if (vel < MIN_VEL) vel = MIN_VEL; @@ -1240,7 +1240,7 @@ void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalP // Normalize. if (dist > 0.001f) { - Real vel = fabs(physics->getForwardSpeed2D()); + Real vel = WWMath::Fabs(physics->getForwardSpeed2D()); if (vel < MIN_VEL) vel = MIN_VEL; if (vel > dist) @@ -1285,7 +1285,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::Fabs( relAngle ) / QUAETERPI; if (angleCoeff > 1.0f) angleCoeff = 1.0; @@ -1356,7 +1356,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::Fabs(accelForce) > WWMath::Fabs(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); @@ -1391,7 +1391,7 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, Real angle = obj->getOrientation(); // Real relAngle = ThePartitionManager->getRelativeAngle2D( obj, &goalPos ); // Real desiredAngle = angle + relAngle; - Real desiredAngle = atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real relAngle = stdAngleDiff(desiredAngle, angle); Bool moveBackwards = false; @@ -1408,14 +1408,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::Fabs(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::Fabs(relAngle) < PI/2) { moveBackwards = false; setFlag(MOVING_BACKWARDS, false); } else { @@ -1431,7 +1431,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::Fabs( relAngle ) > SMALL_TURN) { if (desiredSpeed>turnSpeed) { @@ -1456,7 +1456,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::Fabs( 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; @@ -1595,7 +1595,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::Fabs(accelForce) > WWMath::Fabs(maxForceNeeded)) accelForce = maxForceNeeded; //DEBUG_LOG(("Braking %d, actualSpeed %f, goalSpeed %f, delta %f, accel %f", getFlag(IS_BRAKING), @@ -1666,7 +1666,7 @@ Bool Locomotor::fixInvalidPosition(Object* obj, PhysicsBehavior *physics) //physics->clearAcceleration(); if (dot<0) { - dot = sqrt(-dot); + dot = WWMath::Sqrt(-dot); correctionNormalized.x *= dot*physics->getMass(); correctionNormalized.y *= dot*physics->getMass(); physics->applyMotiveForce(&correctionNormalized); @@ -1730,7 +1730,7 @@ void Locomotor::moveTowardsPositionLegs(Object* obj, PhysicsBehavior *physics, c Real angle = obj->getOrientation(); // Real relAngle = ThePartitionManager->getRelativeAngle2D( obj, &goalPos ); // Real desiredAngle = angle + relAngle; - Real desiredAngle = atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); if (m_template->m_wanderWidthFactor != 0.0f) { Real angleLimit = PI/8 * m_template->m_wanderWidthFactor; @@ -1756,7 +1756,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::Fabs( relAngle ) / (QUARTERPI); if (angleCoeff > 1.0f) angleCoeff = 1.0; @@ -1786,7 +1786,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::Fabs(accelForce) > WWMath::Fabs(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); @@ -1828,7 +1828,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::Fabs(dz)<1) { setFlag(CLIMBING, false); } @@ -1848,7 +1848,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, moveBackwards = true; } - Real groundSlope = fabs(delta.z - pos.z); + Real groundSlope = WWMath::Fabs(delta.z - pos.z); if (groundSlope<1.0f) groundSlope = 1.0f; if (groundSlope>1.0f) { @@ -1863,7 +1863,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, Real angle = obj->getOrientation(); // Real relAngle = ThePartitionManager->getRelativeAngle2D( obj, &goalPos ); // Real desiredAngle = angle + relAngle; - Real desiredAngle = atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real relAngle = stdAngleDiff(desiredAngle, angle); if (moveBackwards) { @@ -1877,7 +1877,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::Fabs( relAngle ) / (QUARTERPI); if (angleCoeff > 1.0f) angleCoeff = 1.0; @@ -1919,7 +1919,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::Fabs(accelForce) > WWMath::Fabs(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); @@ -1946,7 +1946,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::Fabs(dz) > m_circleThresh) { // aim for the spot on the opposite side of the circle. @@ -1954,7 +1954,7 @@ void Locomotor::moveTowardsPositionWings(Object* obj, PhysicsBehavior *physics, Real angleTowardPos = (isNearlyZero(dx) && isNearlyZero(dy)) ? obj->getOrientation() : - atan2(dy, dx); + WWMath::Atan2(dy, dx); Real aimDir = (PI - PI/8); angleTowardPos += aimDir; @@ -2043,7 +2043,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::Fabs(delta); if (delta > MAX_VERTICAL_DAMP_RANGE) delta = MAX_VERTICAL_DAMP_RANGE; zDirDamping = 1.0f - (delta / MAX_VERTICAL_DAMP_RANGE); @@ -2160,7 +2160,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::Fabs(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. @@ -2168,14 +2168,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::Fabs(maxAccel)); + if (WWMath::Fabs(brakeDist) > WWMath::Fabs(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::Fabs(curVelZ) > m_template->m_speedLimitZ) { // or, if we're going too fast, limit it here. desiredAccel = m_template->m_speedLimitZ - curVelZ; @@ -2249,8 +2249,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::Fabs(dx)<0.1f && WWMath::Fabs(dy)<0.1f) return TURN_NONE; + Real desiredAngle = WWMath::Atan2(dy, dx); Real amount = stdAngleDiff(desiredAngle, angle); if (relAngle) *relAngle = amount; if (amount>maxTurnRate) { @@ -2272,7 +2272,7 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 // so, the thing is, we want to rotate ourselves so that our *center* is rotated // by the given amount, but the rotation must be around turnPos. so do a little // back-calculation. - Real angleDesiredForTurnPos = atan2(desiredPos.y - turnPos.y, desiredPos.x - turnPos.x); + Real angleDesiredForTurnPos = WWMath::Atan2(desiredPos.y - turnPos.y, desiredPos.x - turnPos.x); amount = angleDesiredForTurnPos - angle; #endif /// @todo srj -- there's probably a more efficient & more direct way to do this. find it. @@ -2288,7 +2288,7 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 } else { - Real desiredAngle = atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real amount = stdAngleDiff(desiredAngle, angle); if (relAngle) *relAngle = amount; if (amount>maxTurnRate) { @@ -2466,8 +2466,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::Fabs(goalPos.y - pos->y) <= goalSpeed * m_template->m_ultraAccurateSlideIntoPlaceFactor && + WWMath::Fabs(goalPos.x - pos->x) <= goalSpeed * m_template->m_ultraAccurateSlideIntoPlaceFactor) { // don't turn, just slide in the right direction physics->setTurning(TURN_NONE); @@ -2506,7 +2506,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::Fabs(accelForce) > WWMath::Fabs(maxForceNeeded)) accelForce = maxForceNeeded; Coord3D force; @@ -2622,7 +2622,7 @@ void Locomotor::maintainCurrentPositionWings(Object* obj, PhysicsBehavior *physi Real angleTowardMaintainPos = (isNearlyZero(dx) && isNearlyZero(dy)) ? obj->getOrientation() : - atan2(dy, dx); + WWMath::Atan2(dy, dx); Real aimDir = (PI - PI/8); if (turnRadius < 0) @@ -2656,7 +2656,7 @@ void Locomotor::maintainCurrentPositionHover(Object* obj, PhysicsBehavior *physi // Real minSpeed = max( 1.0E-10f, getMinSpeed() ); Real speedDelta = minSpeed - actualSpeed; - if (fabs(speedDelta) > minSpeed) + if (WWMath::Fabs(speedDelta) > minSpeed) { Real mass = physics->getMass(); Real acceleration = (speedDelta > 0.0f) ? maxAcceleration : -getBraking(); @@ -2667,7 +2667,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::Fabs(accelForce) > WWMath::Fabs(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 e7d9dcac701..a8c1c64e4ed 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp @@ -1640,13 +1640,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::Fabs(a->x - b->x) > THRESH) return true; - if (fabs(a->y - b->y) > THRESH) + if (WWMath::Fabs(a->y - b->y) > THRESH) return true; - if (fabs(a->z - b->z) > THRESH) + if (WWMath::Fabs(a->z - b->z) > THRESH) return true; return false; @@ -1662,7 +1662,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::Fabs(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 30fe3c80083..67530b45360 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp @@ -281,7 +281,7 @@ class DeliverPayloadNugget : public ObjectCreationNugget Real dy = primary->y - secondary->y; //Calc length - Real length = sqrt( dx*dx + dy*dy ); + Real length = WWMath::Sqrt( dx*dx + dy*dy ); //Normalize length dx /= length; @@ -348,7 +348,7 @@ class DeliverPayloadNugget : public ObjectCreationNugget } - Real orient = atan2( moveToPos.y - startPos.y, moveToPos.x - startPos.x); + Real orient = WWMath::Atan2( moveToPos.y - startPos.y, moveToPos.x - startPos.x); if( m_data.m_distToTarget > 0 ) { const Real SLOP = 1.5f; @@ -1070,7 +1070,7 @@ class GenericObjectCreationNugget : public ObjectCreationNugget objUp->applyForce(&force); if (m_orientInForceDirection) - orientation = atan2(force.y, force.x); + orientation = WWMath::Atan2(force.y, force.x); } } @@ -1158,7 +1158,7 @@ class GenericObjectCreationNugget : public ObjectCreationNugget objUp->applyForce(&force); if (m_orientInForceDirection) { - orientation = atan2(force.y, force.x); + orientation = WWMath::Atan2(force.y, force.x); } DUMPREAL(orientation); objUp->setAngles(orientation, 0, 0); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp index 1af2196bbc4..e9c63559461 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::Fabs(ptx*c - pty*s); + Real pty_new = (Real)WWMath::Fabs(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::Fabs(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::Sqrtf(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::Sqrtf(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::Sqrtf(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::Sqrtf(actualDistSqr); Real shrunkenDist = actualDist - totalRad; if (shrunkenDist <= 0.0f) { @@ -2228,7 +2228,7 @@ Int PartitionData::calcMaxCoiForShape(GeometryType geom, Real majorRadius, Real } case GEOMETRY_BOX: { - Real diagonal = (Real)(sqrtf(majorRadius*majorRadius + minorRadius*minorRadius)); + Real diagonal = (Real)(WWMath::Sqrtf(majorRadius*majorRadius + minorRadius*minorRadius)); Int cells = ThePartitionManager->worldToCellDist(diagonal*2) + 1; result = cells * cells; break; @@ -2645,7 +2645,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::Ceilf(cellSize / ROUGH_STEP_SIZE); Real step = cellSize / numSteps; loZ = HUGE_DIST; // huge positive hiZ = -HUGE_DIST; // huge negative @@ -3204,22 +3204,28 @@ Int PartitionManager::calcMinRadius(const ICoord2D& cur) so it really shouldn't matter... (I hope) */ - double minDistSqr = 1e12; // double, not real +#if RETAIL_COMPATIBLE_CRC + typedef double RealOrDouble; +#else + typedef Real RealOrDouble; +#endif + + RealOrDouble minDistSqr = (RealOrDouble)1e12; // double, not real for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { // double, not real - double dx = centerPos[i].x - otherPos[j].x; - double dy = centerPos[i].y - otherPos[j].y; - double curDistSqr = dx*dx + dy*dy; + RealOrDouble dx = centerPos[i].x - otherPos[j].x; + RealOrDouble dy = centerPos[i].y - otherPos[j].y; + RealOrDouble curDistSqr = dx*dx + dy*dy; if (minDistSqr > curDistSqr) minDistSqr = curDistSqr; } } // double, not real - double dist = sqrtf(minDistSqr); + RealOrDouble dist = WWMath::Sqrtf(minDistSqr); Int minRadius = REAL_TO_INT_CEIL( dist / m_cellSize ); return minRadius; @@ -3234,10 +3240,16 @@ void PartitionManager::calcRadiusVec() Int cx = getCellCountX(); Int cy = getCellCountY(); +#if RETAIL_COMPATIBLE_CRC + typedef double RealOrDouble; +#else + typedef Real RealOrDouble; +#endif + // double, not real - double dx = (double)cx * (double)cellSize; - double dy = (double)cy * (double)cellSize; - double maxPossibleDist = sqrt(dx*dx + dy*dy); + RealOrDouble dx = (RealOrDouble)cx * (RealOrDouble)cellSize; + RealOrDouble dy = (RealOrDouble)cy * (RealOrDouble)cellSize; + RealOrDouble maxPossibleDist = WWMath::Sqrt(dx*dx + dy*dy); m_maxGcoRadius = REAL_TO_INT_CEIL(maxPossibleDist / cellSize); @@ -3507,7 +3519,7 @@ Object *PartitionManager::getClosestObjects( } if (closestDistArg) { - *closestDistArg = (Real)sqrtf(closestDistSqr); + *closestDistArg = (Real)WWMath::Sqrtf(closestDistSqr); } #ifdef RTS_DEBUG @@ -3634,7 +3646,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::Sqrtf(sqr(v.x) + sqr(v.y)); // normalize if (dist == 0.0f) @@ -3812,7 +3824,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::Fabs(pos.z - center->z) > options->maxZDelta) return FALSE; // @@ -4565,7 +4577,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::Sqrtf(sqr(x1-x2) + sqr(y1-y2)); } //----------------------------------------------------------------------------- @@ -5724,7 +5736,7 @@ void hLineAddThreat(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt( WWMath::Pow(x - parms->xCenter, 2) + WWMath::Pow(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5752,7 +5764,7 @@ void hLineRemoveThreat(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt( WWMath::Pow(x - parms->xCenter, 2) + WWMath::Pow(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5780,7 +5792,7 @@ void hLineAddValue(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt( WWMath::Pow(x - parms->xCenter, 2) + WWMath::Pow(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5808,7 +5820,7 @@ void hLineRemoveValue(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt( WWMath::Pow(x - parms->xCenter, 2) + WWMath::Pow(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp index 67c40c71a07..95b99c1efd3 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::Fabs(goalPos.x-pos.x); + Real dy = WWMath::Fabs(goalPos.y-pos.y); if (dxgetRelativeAngle2D( getObject(), &info.posOnPath ); } - if (fabs(deltaAngle)>PI/30) + if (WWMath::Fabs(deltaAngle)>PI/30) { return TRUE; } @@ -2230,7 +2230,7 @@ UpdateSleepTime AIUpdateInterface::doLocomotor() } else { - Real dist = sqrtf(dSqr); + Real dist = WWMath::Sqrtf(dSqr); if (dist<1) dist = 1; pos.x += 2*PATHFIND_CELL_SIZE_F*dx/(dist*LOGICFRAMES_PER_SECOND); pos.y += 2*PATHFIND_CELL_SIZE_F*dy/(dist*LOGICFRAMES_PER_SECOND); @@ -2424,7 +2424,7 @@ Real AIUpdateInterface::getLocomotorDistanceToGoal() dest = m_path->getLastNode()->getPosition(); } Real distance = ThePartitionManager->getDistanceSquared( me, dest, FROM_CENTER_3D ); - return sqrt( distance );// Other paths return dots of normalized vectors, so one sqrt ain't so bad + return WWMath::Sqrt( distance );// Other paths return dots of normalized vectors, so one sqrt ain't so bad } else { @@ -2456,7 +2456,7 @@ Real AIUpdateInterface::getLocomotorDistanceToGoal() { if (sqr(dist) > distSqr) { - return sqrt(distSqr); + return WWMath::Sqrt(distSqr); } else { @@ -2465,7 +2465,7 @@ Real AIUpdateInterface::getLocomotorDistanceToGoal() } if (distgetExtent( &terrainExtent ); const Real FUDGE = 1.2f; - Real HUGE_DIST = FUDGE * sqrt(sqr(terrainExtent.hi.x - terrainExtent.lo.x) + sqr(terrainExtent.hi.y - terrainExtent.lo.y)); + Real HUGE_DIST = FUDGE * WWMath::Sqrt(sqr(terrainExtent.hi.x - terrainExtent.lo.x) + sqr(terrainExtent.hi.y - terrainExtent.lo.y)); exitCoord.x += dir->x * HUGE_DIST; exitCoord.y += dir->y * HUGE_DIST; @@ -569,7 +569,7 @@ class ChinookCombatDropState : public State { if (it->ropeLen < it->ropeLenMax) { - it->ropeSpeed += fabs(TheGlobalData->m_gravity); + it->ropeSpeed += WWMath::Fabs(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::Fabs(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::Fabs(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 69e70011b20..7559014b5e4 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp @@ -201,8 +201,8 @@ UpdateSleepTime DeliverPayloadAIUpdate::update() { //Calc strafe ratio Real startDiveDistance = getData()->m_diveStartDistance; - Real endDiveDistance = sqrt( endDiveDistanceSquared ); - Real currentDistance = sqrt( currentDistanceSquared ); + Real endDiveDistance = WWMath::Sqrt( endDiveDistanceSquared ); + Real currentDistance = WWMath::Sqrt( currentDistanceSquared ); Real diveRatio = (startDiveDistance - currentDistance) / (startDiveDistance - endDiveDistance); @@ -1081,7 +1081,7 @@ StateReturnType RecoverFromOffMapState::update() // Success if we should try aga enterCoord.z = owner->getPosition()->z; owner->setPosition(&enterCoord); - Real enterAngle = atan2(ai->getMoveToPos()->y - enterCoord.y, ai->getMoveToPos()->x - enterCoord.x); + Real enterAngle = WWMath::Atan2(ai->getMoveToPos()->y - enterCoord.y, ai->getMoveToPos()->x - enterCoord.x); owner->setOrientation(enterAngle); PhysicsBehavior* physics = owner->getPhysics(); @@ -1121,7 +1121,7 @@ StateReturnType HeadOffMapState::onEnter() // Give move order out of town Region3D terrainExtent; TheTerrainLogic->getExtent( &terrainExtent ); const Real FUDGE = 1.2f; - Real HUGE_DIST = FUDGE * sqrt(sqr(terrainExtent.hi.x - terrainExtent.lo.x) + sqr(terrainExtent.hi.y - terrainExtent.lo.y)); + Real HUGE_DIST = FUDGE * WWMath::Sqrt(sqr(terrainExtent.hi.x - terrainExtent.lo.x) + sqr(terrainExtent.hi.y - terrainExtent.lo.y)); exitCoord.x += dir->x * HUGE_DIST; exitCoord.y += dir->y * HUGE_DIST; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cpp index 9cf9445e34b..c18bd46a1bf 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cpp @@ -530,7 +530,7 @@ StateReturnType DozerActionDoActionState::update() // increase the construction percent of the goal object Int framesToBuild = goalObject->getTemplate()->calcTimeToBuild( dozer->getControllingPlayer() ); - Real percentProgressThisFrame = 100.0f / framesToBuild; + Real percentProgressThisFrame = WWMath::Div_Safe(100.0f, (Real)framesToBuild, 1.0f); goalObject->setConstructionPercent( goalObject->getConstructionPercent() + percentProgressThisFrame ); 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 3e19f6cbaad..fa6817fbc85 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp @@ -461,8 +461,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::Atan2(ppinfo.runwayPrep.y - ppinfo.parkingSpace.y, ppinfo.runwayPrep.x - ppinfo.parkingSpace.x); + if (WWMath::Fabs(stdAngleDiff(orient, ppinfo.parkingOrientation)) > PI/128) { intermedPt.z = (ppinfo.parkingSpace.z + ppinfo.runwayPrep.z) * 0.5f; intermed = intersectInfiniteLine2D( @@ -895,7 +895,7 @@ class HeliTakeoffOrLandingState : public State } else { - Real dist = sqrtf(dSqr); + Real dist = WWMath::Sqrtf(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); @@ -1023,7 +1023,7 @@ class JetOrHeliParkOrientState : public State return STATE_FAILURE; const Real THRESH = 0.001f; - if (fabs(stdAngleDiff(jet->getOrientation(), ppinfo.parkingOrientation)) <= THRESH) + if (WWMath::Fabs(stdAngleDiff(jet->getOrientation(), ppinfo.parkingOrientation)) <= THRESH) return STATE_SUCCESS; // magically position it correctly. @@ -2093,7 +2093,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::Atan2(dy, dx)); // the Gaussian sum, to avoid keeping a running total: // diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp index d246a79a484..6ced09c6ed6 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp @@ -223,7 +223,7 @@ void MissileAIUpdate::projectileFireAtObjectOrPosition( const Object *victim, co Real deltaZ = victimPos->z - obj->getPosition()->z; Real dx = victimPos->x - obj->getPosition()->x; Real dy = victimPos->y - obj->getPosition()->y; - Real xyDist = sqrt(sqr(dx)+sqr(dy)); + Real xyDist = WWMath::Sqrt(sqr(dx)+sqr(dy)); if (xyDist<1) xyDist = 1; Real zFactor = 0; if (deltaZ>0) { @@ -632,7 +632,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::Sqrtf(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 403d00eea9b..ab69d95546f 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::Pow( 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 456b6e391f7..a6b9e2b3ab8 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::Sqrtf( 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. @@ -473,8 +473,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::Fabs(theirPhys->getVelocity()->length()); + mass += WWMath::Fabs(theirPhys->getMass()); vel /= 2; mass /= 2;//average of him and me @@ -676,7 +676,7 @@ UpdateSleepTime RailroadBehavior::update() if ( m_conductorState == APPLY_BRAKES ) { conductorPullInfo.speed *= modData->m_braking; - if (fabs(conductorPullInfo.speed) < 0.01f) + if (WWMath::Fabs(conductorPullInfo.speed) < 0.01f) { conductorPullInfo.speed = 0; ///////////////////////////////////////( &m_hissySteamSound ); @@ -1194,7 +1194,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::Fabs(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 ); @@ -1260,7 +1260,7 @@ void RailroadBehavior::updatePositionTrackDistance( PullInfo *pullerInfo, PullIn trackPosDelta.z = 0; Real dx = pullerInfo->towHitchPosition.x - turnPos.x; Real dy = pullerInfo->towHitchPosition.y - turnPos.y; - Real desiredAngle = atan2(dy, dx); + Real desiredAngle = WWMath::Atan2(dy, dx); Real relAngle = stdAngleDiff(desiredAngle, obj->getTransformMatrix()->Get_Z_Rotation()); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp index 8a23910d7d3..57cc8f8211a 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp @@ -172,7 +172,7 @@ UpdateSleepTime CleanupHazardUpdate::update() AIUpdateInterface *ai = obj->getAI(); if( ai && (ai->isIdle() || ai->isBusy()) ) { - Real fDist = sqrt( ThePartitionManager->getDistanceSquared( obj, &m_pos, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( obj, &m_pos, FROM_CENTER_2D ) ); if( fDist < 25.0f ) { //Abort clean area because there's nothing left to clean! @@ -204,7 +204,7 @@ void CleanupHazardUpdate::fireWhenReady() bonus.clear(); Real fireRange = m_weaponTemplate->getAttackRange( bonus ); Object *me = getObject(); - Real fDist = sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); if( fDist < fireRange ) { //We are currently in range! diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp index e7df932630c..936da747afe 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp @@ -290,7 +290,7 @@ Object* CommandButtonHuntUpdate::scanClosestTarget() } } Real distSqr = ThePartitionManager->getDistanceSquared(me, other, FROM_BOUNDINGSPHERE_2D); - Real dist = sqrt(distSqr); + Real dist = WWMath::Sqrt(distSqr); Int curPriority = data->m_scanRange - dist; if (info) curPriority = info->getPriority(other->getTemplate()); if (curPriority == 0) diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp index 62ac01c158a..faac75b83d4 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp @@ -95,7 +95,7 @@ Bool SupplyWarehouseDockUpdate::action( Object* docker, Object *drone ) Real closeEnoughSqr = sqr(docker->getGeometryInfo().getBoundingCircleRadius()*2); Real curDistSqr = ThePartitionManager->getDistanceSquared(docker, getObject(), FROM_BOUNDINGSPHERE_2D); if (curDistSqr > closeEnoughSqr) { - DEBUG_LOG(("Failing dock, dist %f, not close enough(%f).", sqrt(curDistSqr), sqrt(closeEnoughSqr))); + DEBUG_LOG(("Failing dock, dist %f, not close enough(%f).", WWMath::Sqrt(curDistSqr), WWMath::Sqrt(closeEnoughSqr))); // Make it twitch a little. Coord3D newPos = *docker->getPosition(); Real range = 0.4*PATHFIND_CELL_SIZE_F; @@ -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::Ceil(cashValue / (float)TheGlobalData->m_baseValuePerSupplyBox); Drawable *draw = getObject()->getDrawable(); if( draw ) { diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp index be29d3af98c..fd875bb58aa 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp @@ -166,8 +166,8 @@ void DynamicShroudClearingRangeUpdate::animateGridDecals() for (int d = 0; d < GRID_FX_DECAL_COUNT; ++d) { - pos.x = ctr->x + (sinf(angle) * radius); - pos.y = ctr->y + (cosf(angle) * radius); + pos.x = ctr->x + (WWMath::Sinf(angle) * radius); + pos.y = ctr->y + (WWMath::Cosf(angle) * radius); pos.x -= ((Int)pos.x)%23; pos.y -= ((Int)pos.y)%23; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp index 29f256c4801..40d350662bd 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp @@ -119,8 +119,8 @@ UpdateSleepTime FloatUpdate::update() { Real angle = INT_TO_REAL(TheGameLogic->getFrame()); - Real yaw = sin(angle * 0.0291f) * 0.05f; - Real pitch = sin(angle * 0.0515f) * 0.05f; + Real yaw = WWMath::Sin(angle * 0.0291f) * 0.05f; + Real pitch = WWMath::Sin(angle * 0.0515f) * 0.05f; Matrix3D mx = *draw->getInstanceMatrix(); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileSlowDeathUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileSlowDeathUpdate.cpp index b5db757f54e..281de71fab6 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileSlowDeathUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileSlowDeathUpdate.cpp @@ -45,6 +45,7 @@ #include "GameLogic/Module/NeutronMissileSlowDeathUpdate.h" #include "GameLogic/Module/ToppleUpdate.h" #include "GameLogic/TerrainLogic.h" +#include "WWMath/wwmath.h" /////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -298,7 +299,7 @@ static void debugDrawBlastCircle( const Coord3D *center, Real radius, Real tileW // space the icons roughly one tile apart along the circumference, within sane bounds tileWidth = max( tileWidth, 1.0f ); - Int segments = (Int)ceilf( (2.0f * PI * radius) / tileWidth * 0.5f ); + Int segments = (Int)WWMath::Ceilf( (2.0f * PI * radius) / tileWidth * 0.5f ); segments = clamp(1, segments, 256); for( Int i = 0; i < segments; ++i ) @@ -306,8 +307,8 @@ static void debugDrawBlastCircle( const Coord3D *center, Real radius, Real tileW Real angle = (2.0f * PI * i) / segments; Coord3D pos; - pos.x = center->x + radius * cosf( angle ); - pos.y = center->y + radius * sinf( angle ); + pos.x = center->x + radius * WWMath::Cosf( angle ); + pos.y = center->y + radius * WWMath::Sinf( angle ); pos.z = TheTerrainLogic->getGroundHeight( pos.x, pos.y ); addIcon( &pos, tileWidth, frameDuration, color ); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp index 9bf55521dde..172b323e01b 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::Fabs(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::Fabs( 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::Sqrt(sqr(newPos.x-oldPos.x) + sqr(newPos.y-oldPos.y) + sqr(newPos.z-oldPos.z)); //DEBUG_LOG(("noTurnDist goes from %f to %f",m_noTurnDistLeft,m_noTurnDistLeft-distThisTurn)); m_noTurnDistLeft -= distThisTurn; } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp index 05b938eb7c7..8fdf54efb75 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp @@ -497,7 +497,7 @@ UpdateSleepTime ParticleUplinkCannonUpdate::update() Real cxDistance = (factor * data->m_swathOfDeathDistance ) - (data->m_swathOfDeathDistance * 0.5f); //cx is cartesian x //Now calculate the amplitude value. - Real height = sin( radians ); + Real height = WWMath::Sin( radians ); Real cxHeight = height * data->m_swathOfDeathAmplitude; Coord3D buildingToInitialTargetVector; diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp index 9f29e48c42e..2a302af61f0 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp @@ -95,7 +95,7 @@ static Real heightToSpeed(Real height) { // don't bother trying to remember how far we've fallen; instead, // back-calc it from our speed & gravity... v = sqrt(2*g*h) - return sqrt(fabs(2.0f * TheGlobalData->m_gravity * height)); + return WWMath::Sqrt(WWMath::Fabs(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::Fabs(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::Fabs(v.x) < THRESH && WWMath::Fabs(v.y) < THRESH && WWMath::Fabs(v.z) < THRESH); } //------------------------------------------------------------------------------------------------- @@ -568,9 +568,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::Fabsf(m_vel.x) < THRESH) m_vel.x = 0.0f; + if (WWMath::Fabsf(m_vel.y) < THRESH) m_vel.y = 0.0f; + if (WWMath::Fabsf(m_vel.z) < THRESH) m_vel.z = 0.0f; m_velMag = INVALID_VEL_MAG; @@ -635,8 +635,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::Sqrtf(sqr(xvec.X) + sqr(xvec.Y)); + Real pitchAngle = WWMath::Atan2(xvec.Z, xy); Real remainingAngle = (offset > 0) ? ((PI/2) - pitchAngle) : (-(PI/2) + pitchAngle); Real s = Sin(remainingAngle); pitchRateToUse *= s; @@ -736,8 +736,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::Fabs(m_vel.x) <= TINY_DELTA || WWMath::Fabs(activeVelZ / m_vel.x) >= MIN_ANGLE_TAN) && + (WWMath::Fabs(m_vel.y) <= TINY_DELTA || WWMath::Fabs(activeVelZ / m_vel.y) >= MIN_ANGLE_TAN)) { Real damageAmt = netSpeed * getMass() * d->m_fallHeightDamageFactor; @@ -816,7 +816,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::Sqrtf( sqr(m_vel.x) + sqr(m_vel.y) + sqr(m_vel.z) ); } return m_velMag; } @@ -835,7 +835,7 @@ Real PhysicsBehavior::getForwardSpeed2D() const if (useLegacyForwardSpeed()) { - Real speed = (Real)sqrtf( vx*vx + vy*vy ); + Real speed = (Real)WWMath::Sqrtf( vx*vx + vy*vy ); if (dot >= 0.0f) return speed; return -speed; @@ -864,7 +864,7 @@ Real PhysicsBehavior::getForwardSpeed3D() const if (useLegacyForwardSpeed()) { - Real speed = (Real)sqrtf( vx*vx + vy*vy + vz*vz ); + Real speed = (Real)WWMath::Sqrtf( vx*vx + vy*vy + vz*vz ); if (dot >= 0.0f) return speed; return -speed; @@ -900,7 +900,7 @@ Bool PhysicsBehavior::wasPreviouslyOverlapped(Object *obj) const //------------------------------------------------------------------------------------------------- void PhysicsBehavior::scrubVelocityZ( Real desiredVelocity ) { - if (fabs(desiredVelocity) < 0.001f) + if (WWMath::Fabs(desiredVelocity) < 0.001f) { m_vel.z = 0; } @@ -924,7 +924,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::Sqrtf(m_vel.x*m_vel.x + m_vel.y*m_vel.y); if (desiredVelocity > curVelocity) { return; @@ -1007,9 +1007,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::Fabs(prevPos.z - getObject()->getPosition()->z); - Real mass = fabs(getMass()); + Real mass = WWMath::Fabs(getMass()); if (vel > NORMAL_VEL_Z) { vel = NORMAL_VEL_Z; } @@ -1209,7 +1209,7 @@ void PhysicsBehavior::onCollide( Object *other, const Coord3D *loc, const Coord3 m_lastCollidee = other->getID(); - Real dist = sqrtf(distSqr); + Real dist = WWMath::Sqrtf(distSqr); Real overlap = usRadius + themRadius - dist; // if objects are coincident, dist is zero, so force would be infinite -- clearly @@ -1350,7 +1350,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::Fabs( 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 7c12ee6fd36..6546c004c3d 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp @@ -167,7 +167,7 @@ void PointDefenseLaserUpdate::fireWhenReady() bonus.clear(); Real fireRange = data->m_weaponTemplate->getAttackRange( bonus ); Object *me = getObject(); - Real fDist = sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); if( fDist < fireRange ) { //We are currently in range! @@ -285,7 +285,7 @@ Object* PointDefenseLaserUpdate::scanClosestTarget() continue; } - Real fDist = sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); if( fDist <= fireRange ) { @@ -312,7 +312,7 @@ Object* PointDefenseLaserUpdate::scanClosestTarget() pos.add( *other->getPosition() ); //Recalculate the distance. - fDist = sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); + fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); } } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp index c92b2bd1a7e..3d61438f9a2 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp @@ -196,7 +196,7 @@ UpdateSleepTime SlavedUpdate::update() { Real health = body->getHealth(); Real maxHealth = body->getMaxHealth(); - healthPercentage = (Int)(health / maxHealth * 100.0f); + healthPercentage = (Int)(WWMath::Div_Safe(health, maxHealth) * 100.0f); } } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp index 2034604e7fa..84bb14e3730 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp @@ -412,7 +412,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::Fabs( 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 30b216a4484..f6e7b05ee8d 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::Fabs( 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..335d8f39e33 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::Fabs(stdAngleDiff(desired, a1)) < WWMath::Fabs(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::Atan2(m_toppleDirection.y, m_toppleDirection.x)); if (d->m_toppleLeftOrRightOnly) { // it's a fence or such, and can only topple left or right, so pick the closest @@ -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::Fabs(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::Fabs(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 2c8cc417691..2291ed2180d 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp @@ -384,8 +384,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::Ceilf(ConvertDurationFromMsecsToFrames((Real)self->m_minDelayBetweenShots)); + self->m_maxDelayBetweenShots = WWMath::Ceilf(ConvertDurationFromMsecsToFrames((Real)self->m_maxDelayBetweenShots)); } @@ -878,7 +878,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::Sqrtf(distSqr),WWMath::Sqrtf(minAttackRangeSqr))); //-extraLogging #if defined(RTS_DEBUG) @@ -904,7 +904,7 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate targetPos.set( *victimPos ); } Real reAngle = getWeaponRecoilAmount(); - Real reDir = reAngle != 0.0f ? (atan2(victimPos->y - sourcePos->y, victimPos->x - sourcePos->x)) : 0.0f; + Real reDir = reAngle != 0.0f ? (WWMath::Atan2(victimPos->y - sourcePos->y, victimPos->x - sourcePos->x)) : 0.0f; VeterancyLevel v = sourceObj->getVeterancyLevel(); const FXList* fx = isProjectileDetonation ? getProjectileDetonateFX(v) : getFireFX(v); @@ -1951,11 +1951,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::Atan2(-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::Fabs(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 09048b600d6..db81adbdd8e 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp @@ -799,7 +799,7 @@ static void populateRandomStartPosition( GameInfo *game ) { Coord3D p1 = c1->second; Coord3D p2 = c2->second; - startSpotDistance[i][j] = sqrt( sqr(p1.x-p2.x) + sqr(p1.y-p2.y) ); + startSpotDistance[i][j] = WWMath::Sqrt( sqr(p1.x-p2.x) + sqr(p1.y-p2.y) ); } } else diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp index 832909462f0..9439759e534 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp @@ -2469,7 +2469,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::Ceil((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 712becb74e8..81956a45742 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp @@ -806,8 +806,8 @@ LegalBuildCode BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos if (myFactoryExitWidth>0) { myExitPos = *worldPos; checkMyExit = true; - Real c = (Real)cos(angle); - Real s = (Real)sin(angle); + Real c = (Real)WWMath::Cos(angle); + Real s = (Real)WWMath::Sin(angle); Real offset = build->getTemplateGeometryInfo().getMajorRadius() + myFactoryExitWidth/2.0f; myExitPos.x += c*offset; myExitPos.y += s*offset; @@ -854,8 +854,8 @@ LegalBuildCode BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos if (themFactoryExitWidth>0) { hisExitPos = *them->getPosition(); checkHisExit = true; - Real c = (Real)cos(them->getOrientation()); - Real s = (Real)sin(them->getOrientation()); + Real c = (Real)WWMath::Cos(them->getOrientation()); + Real s = (Real)WWMath::Sin(them->getOrientation()); Real offset = them->getGeometryInfo().getMajorRadius() + themFactoryExitWidth/2.0f; hisExitPos.x += c*offset; hisExitPos.y += s*offset; @@ -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::Sqrt(WWMath::Pow(gi.getMajorRadius(), 2) + WWMath::Pow(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 1f927ae2615..16f47f2e951 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::Sqrt(sqr(thatPos.x - thisCenter.x) + sqr(thatPos.y - thisCenter.y)); Real dz; /** @todo srj -- this could be better, by calcing it for all the corners, not just top-center and bottom-center... oh well */ dz = (thatPos.z + that.getMaxHeightAbovePosition()) - thisCenter.z; - maxPitch = atan2(dz, dxy); + maxPitch = WWMath::Atan2(dz, dxy); dz = (thatPos.z - that.getMaxHeightBelowPosition()) - thisCenter.z; - minPitch = atan2(dz, dxy); + minPitch = WWMath::Atan2(dz, dxy); } //============================================================================= @@ -279,8 +279,8 @@ void GeometryInfo::get2DBounds(const Coord3D& geomCenter, Real angle, Region2D& case GEOMETRY_BOX: { - Real c = (Real)cos(angle); - Real s = (Real)sin(angle); + Real c = (Real)WWMath::Cos(angle); + Real s = (Real)WWMath::Sin(angle); Real exc = m_majorRadius*c; Real eyc = m_minorRadius*c; Real exs = m_majorRadius*s; @@ -329,7 +329,7 @@ void GeometryInfo::clipPointToFootprint(const Coord3D& geomCenter, Coord3D& ptTo { Real dx = ptToClip.x - geomCenter.x; Real dy = ptToClip.y - geomCenter.y; - Real radius = sqrt(sqr(dx) + sqr(dy)); + Real radius = WWMath::Sqrt(sqr(dx) + sqr(dy)); if (radius > m_majorRadius) { Real ratio = m_majorRadius / radius; @@ -361,7 +361,7 @@ Bool GeometryInfo::isPointInFootprint(const Coord3D& geomCenter, const Coord3D& { Real dx = pt.x - geomCenter.x; Real dy = pt.y - geomCenter.y; - Real radius = sqrt(sqr(dx) + sqr(dy)); + Real radius = WWMath::Sqrt(sqr(dx) + sqr(dy)); return (radius <= m_majorRadius); break; } @@ -506,8 +506,8 @@ void GeometryInfo::calcBoundingStuff() case GEOMETRY_BOX: { - m_boundingCircleRadius = sqrt(sqr(m_majorRadius) + sqr(m_minorRadius)); - m_boundingSphereRadius = sqrt(sqr(m_majorRadius) + sqr(m_minorRadius) + sqr(m_height*0.5)); + m_boundingCircleRadius = WWMath::Sqrt(sqr(m_majorRadius) + sqr(m_minorRadius)); + m_boundingSphereRadius = WWMath::Sqrt(sqr(m_majorRadius) + sqr(m_minorRadius) + sqr(m_height*0.5)); break; } }; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp index 975cb6f832c..42286c46251 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp @@ -715,8 +715,8 @@ Object *AI::findClosestEnemy( const Object *me, Real range, UnsignedInt qualifie } Real distSqr = ThePartitionManager->getDistanceSquared(me, theEnemy, FROM_BOUNDINGSPHERE_2D); - Real dist = sqrt(distSqr); - Int modifier = dist/getAiData()->m_attackPriorityDistanceModifier; + Real dist = WWMath::Sqrtf(distSqr); + Int modifier = (Int)WWMath::Div_Safe(dist, getAiData()->m_attackPriorityDistanceModifier); Int modPriority = curPriority-modifier; if (modPriority < 1) modPriority = 1; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp index a3b2bd6d42c..96a2efd2015 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp @@ -1883,8 +1883,8 @@ void getHelicopterOffset( Coord3D& posOut, Int idx ) } Coord3D tempCtr = posOut; - posOut.x = tempCtr.x + (sin(angle) * radius); - posOut.y = tempCtr.y + (cos(angle) * radius); + posOut.x = tempCtr.x + (WWMath::Sin(angle) * radius); + posOut.y = tempCtr.y + (WWMath::Cos(angle) * radius); } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp index 4ea3e5cfd84..04a9b31e1bb 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp @@ -495,7 +495,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::Fabs(info->getRallyOffset()->x) > 1.0f || WWMath::Fabs(info->getRallyOffset()->y)>1.0f) { gotOffset; } if (!exitInterface->getNaturalRallyPoint(rallyPoint)) { @@ -653,7 +653,7 @@ Object *AIPlayer::buildStructureWithDozer(const ThingTemplate *bldgPlan, BuildLi dx = dozer->getPosition()->x - pos.x; dy = dozer->getPosition()->y - pos.y; - Int count = sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); + Int count = WWMath::Sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2); if (count<2) count = 2; Int i; color.green = 1; @@ -675,7 +675,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::Fabs(info->getRallyOffset()->x) > 1.0f || WWMath::Fabs(info->getRallyOffset()->y)>1.0f) { gotOffset; } if (!exitInterface->getNaturalRallyPoint(rallyPoint)) { @@ -1378,7 +1378,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)) @@ -3167,7 +3167,7 @@ void AIPlayer::computeCenterAndRadiusOfBase(Coord3D *center, Real *radius) Real radSqr = dx*dx+dy*dy; if (radSqr>maxRadSqr) maxRadSqr=radSqr; } - *radius = sqrt(maxRadSqr); + *radius = WWMath::Sqrt(maxRadSqr); } //---------------------------------------------------------------------------------------------------------- diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp index 49591133153..b68b1df49e1 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp @@ -637,7 +637,7 @@ void AISkirmishPlayer::buildAIBaseDefenseStructure(const AsciiString &thingName, Real structureRadius = tTemplate->getTemplateGeometryInfo().getBoundingCircleRadius(); Real baseCircumference = 2*PI*defenseDistance; - Real angleOffset = 2*PI*(structureRadius*4/baseCircumference); + Real angleOffset = 2*PI*WWMath::Div_Safe(structureRadius*4, baseCircumference); Int selector; Real angle; @@ -673,8 +673,8 @@ void AISkirmishPlayer::buildAIBaseDefenseStructure(const AsciiString &thingName, } if (angle > PI/3) break; - Real s = sin(angle); - Real c = cos(angle); + Real s = WWMath::Sin(angle); + Real c = WWMath::Cos(angle); // TheSuperHackers @info helmutbuhler 21/04/2025 This debug mutates the code to become CRC incompatible #if defined(RTS_DEBUG) || !RETAIL_COMPATIBLE_CRC @@ -1040,8 +1040,8 @@ void AISkirmishPlayer::adjustBuildList(BuildListInfo *list) angle += 3*PI/4; - Real s = sin(angle); - Real c = cos(angle); + Real s = WWMath::Sin(angle); + Real c = WWMath::Cos(angle); cur = list; while (cur) { diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp index 43181918050..94c2b89a0bd 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::Fabs(TheGlobalData->m_gravity) * LOGICFRAMES_PER_SECOND * 2.5f; m_rappelRate = -min(ai->getDesiredSpeed(), MAX_RAPPEL_RATE); return STATE_CONTINUE; @@ -3687,7 +3687,7 @@ StateReturnType AIAttackMoveToState::update() if (distSqr < sqr(ATTACK_CLOSE_ENOUGH_CELLS*PATHFIND_CELL_SIZE_F)) { return ret; } - DEBUG_LOG(("AIAttackMoveToState::update Distance from goal %f, retrying.", sqrt(distSqr))); + DEBUG_LOG(("AIAttackMoveToState::update Distance from goal %f, retrying.", WWMath::Sqrt(distSqr))); ret = STATE_CONTINUE; m_retryCount--; @@ -3917,16 +3917,16 @@ void AIFollowWaypointPathState::computeGoal(Bool useGroupOffsets) if (m_priorWaypoint) { dx = dest.x - m_priorWaypoint->getLocation()->x; dy = dest.y - m_priorWaypoint->getLocation()->y; - angle = atan2(dy, dx); + angle = WWMath::Atan2(dy, dx); Real deltaAngle = angle - m_angle; - Real s = sin(deltaAngle); - Real c = cos(deltaAngle); + Real s = WWMath::Sin(deltaAngle); + Real c = WWMath::Cos(deltaAngle); Real x = m_groupOffset.x * c - m_groupOffset.y * s; Real y = m_groupOffset.y * c + m_groupOffset.x * s; m_groupOffset.x = x; m_groupOffset.y = y; } else { - angle = atan2(dy, dx); + angle = WWMath::Atan2(dy, dx); } m_angle = angle; #endif @@ -5092,7 +5092,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::Fabs(relAngle) > aimDelta) { Real desiredAngle = source->getOrientation() + relAngle; sourceAI->setLocomotorGoalOrientation(desiredAngle); @@ -5104,7 +5104,7 @@ StateReturnType AIAttackAimAtTargetState::update() sourceAI->setLocomotorGoalPositionExplicit(m_isAttackingObject ? *victim->getPosition() : *getMachineGoalPosition()); } - if (fabs(relAngle) < aimDelta /*&& !m_preAttackFrames*/ ) + if (WWMath::Fabs(relAngle) < aimDelta /*&& !m_preAttackFrames*/ ) { AIUpdateInterface* victimAI = victim ? victim->getAI() : nullptr; // add ourself as a targeter BEFORE calling isTemporarilyPreventingAimSuccess(). @@ -7508,7 +7508,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::Fabs( 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 02d7291071a..53eab1dc7c8 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp @@ -401,7 +401,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::Fabs(angleDiff) < turnRate) { // we are centered actualAngle = desiredAngle; @@ -424,7 +424,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::Fabs(m_angle - desiredAngle) <= relThresh; return aligned; } @@ -442,7 +442,7 @@ Bool TurretAI::friend_turnTowardsPitch(Real desiredPitch, Real rateModifier) Real pitchRate = getPitchRate() * rateModifier; Real pitchDiff = normalizeAngle(desiredPitch - actualPitch); - if (fabs(pitchDiff) < pitchRate) + if (WWMath::Fabs(pitchDiff) < pitchRate) { // we are centered actualPitch = desiredPitch; @@ -1102,7 +1102,7 @@ StateReturnType TurretAIAimTurretState::update() turret->friend_setPositiveSweep(!turret->friend_getPositiveSweep()); Real angleDiff = normalizeAngle(relAngle - turret->getTurretAngle()); - turnAlignedToNemesis = (fabs(angleDiff) < sweep); + turnAlignedToNemesis = (WWMath::Fabs(angleDiff) < sweep); } Bool pitchAlignedToNemesis = true; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/BridgeBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/BridgeBehavior.cpp index 307b5e3a65d..826de5c3260 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/BridgeBehavior.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/BridgeBehavior.cpp @@ -1115,7 +1115,7 @@ void BridgeBehavior::createScaffolding() // to the center area of the bridge // Real tileDistance = leftVector.length(); - Int numObjects = REAL_TO_INT_CEIL( tileDistance / spacing ) + 1; + Int numObjects = REAL_TO_INT_CEIL( WWMath::Div_Safe(tileDistance, spacing, 1.0f) ) + 1; // // given the number of objects that we need to tile across the whole bridge, we will diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp index 9b782240938..01efb550e74 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::Atan2(dy, dx); // calculating the pitch requires a bit more effort. Real horizDistSqr = sqr(dx) + sqr(dy); - Real horizDist = sqrt(horizDistSqr); + Real horizDist = WWMath::Sqrt(horizDistSqr); // calc the two possible pitches that will cover the given horizontal range. // (this is actually only true if dz==0, but is a good first guess) - Real gravity = fabs(TheGlobalData->m_gravity); + Real gravity = WWMath::Fabs(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::Atan2(dz, horizDist); // if the angle isn't pretty shallow, we can get a better initial guess by using // the code below... const Real SHALLOW_ANGLE = 0.5f * PI / 180.0f; - if (fabs(theta) > SHALLOW_ANGLE) + if (WWMath::Fabs(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::Sqrt(root)))/gravity; const Real CLOSE_ENOUGH_RANGE = 5.0f; if (tooClose || (actualRange < horizDist - CLOSE_ENOUGH_RANGE)) { @@ -369,7 +369,7 @@ void DumbProjectileBehavior::projectileFireAtObjectOrPosition( const Object *vic // Some weapons want to scale their start speed to the range Real minRange = detWeap->getMinimumAttackRange(); Real maxRange = detWeap->getUnmodifiedAttackRange(); - Real range = sqrt(ThePartitionManager->getDistanceSquared( projectile, &victimPosToUse, FROM_CENTER_2D ) ); + Real range = WWMath::Sqrt(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 = (Int)WWMath::Ceil( WWMath::Div_Safe(flightDistance, m_flightPathSpeed, 1.0f) ); } // 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::Sqrtf(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..5064dbb2601 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp @@ -248,11 +248,11 @@ void GenerateMinefieldBehavior::placeMinesAlongLine(const Coord3D& posStart, con Real dx = posEnd.x - posStart.x; Real dy = posEnd.y - posStart.y; - Real len = sqrt(sqr(dx) + sqr(dy)); + Real len = WWMath::Sqrt(sqr(dx) + sqr(dy)); Real mineRadius = mineTemplate->getTemplateGeometryInfo().getBoundingCircleRadius(); Real mineDiameter = mineRadius * 2.0f; Real mineJitter = mineRadius*d->m_randomJitter; - Int numMines = REAL_TO_INT_CEIL(len / mineDiameter); + Int numMines = REAL_TO_INT_CEIL(WWMath::Div_Safe(len, mineDiameter, 1.0f)); if (numMines < 1) numMines = 1; Real inc = len/numMines; @@ -312,7 +312,7 @@ void GenerateMinefieldBehavior::placeMinesAroundCircle(const Coord3D& pos, Real Real mineRadius = mineTemplate->getTemplateGeometryInfo().getBoundingCircleRadius(); Real mineDiameter = mineRadius * 2.0f; Real mineJitter = mineRadius*d->m_randomJitter; - Int numMines = REAL_TO_INT_CEIL(circum / mineDiameter); + Int numMines = REAL_TO_INT_CEIL(WWMath::Div_Safe(circum, mineDiameter, 1.0f)); if (numMines < 1) numMines = 1; Real angleInc = (2*PI)/numMines; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp index 7bdecb3be0d..12a32cb5d5a 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/MinefieldBehavior.cpp @@ -457,7 +457,7 @@ void MinefieldBehavior::onDamage( DamageInfo *damageInfo ) for (;;) { - Real virtualMinesExpectedF = ((Real)d->m_numVirtualMines * body->getHealth() / body->getMaxHealth()); + Real virtualMinesExpectedF = WWMath::Div_Safe((Real)d->m_numVirtualMines * body->getHealth(), body->getMaxHealth()); Int virtualMinesExpected = damageInfo->in.m_damageType == DAMAGE_HEALING ? REAL_TO_INT_FLOOR(virtualMinesExpectedF) : @@ -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::Sqrtf(2.0f * (start.z - endOnGround.z) / WWMath::Fabs(TheGlobalData->m_gravity))); // we can scoot after we land, but don't want to stop scooting before we land if (scootFromStartingPointTime < fallingTime) scootFromStartingPointTime = fallingTime; @@ -588,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::Sqrt(sqr(dx) + sqr(dy)); + if (dist <= 0.1f && WWMath::Fabs(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::Fabs(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..01e654e4a6e 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp @@ -179,7 +179,7 @@ Int SlowDeathBehavior::getProbabilityModifier( const DamageInfo *damageInfo ) co // severely killed, and more sedate ones when only slightly killed. // eg ( 200 hp max, had 10 left, took 50 damage, 40 overkill, (40/200) * 100 = 20 overkill %) Int overkillDamage = damageInfo->out.m_actualDamageDealt - damageInfo->out.m_actualDamageClipped; - Real overkillPercent = (float)overkillDamage / (float)getObject()->getBodyModule()->getMaxHealth(); + Real overkillPercent = WWMath::Div_Safe((float)overkillDamage, (float)getObject()->getBodyModule()->getMaxHealth()); Int overkillModifier = overkillPercent * getSlowDeathBehaviorModuleData()->m_modifierBonusPerOverkillPercent; return max( getSlowDeathBehaviorModuleData()->m_probabilityModifier + overkillModifier, 1 ); @@ -299,7 +299,7 @@ void SlowDeathBehavior::beginSlowDeath(const DamageInfo *damageInfo) physics->setExtraBounciness(-1.0); // we don't want this guy to bounce at all physics->setExtraFriction(-3 * SECONDS_PER_LOGICFRAME_REAL); // reduce his ground friction a bit physics->setAllowBouncing(true); - Real orientation = atan2(force.y, force.x); + Real orientation = WWMath::Atan2(force.y, force.x); physics->setAngles(orientation, 0, 0); obj->getDrawable()->setModelConditionState(MODELCONDITION_EXPLODED_FLAILING); m_flags |= (1<getPosition()->z) >= d->m_paraOpenDist) + if (WWMath::Fabs(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 13125d41522..659ad9a9a49 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp @@ -119,7 +119,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::Fabs(maxBraking)) * 0.5f; // use a little fudge so that things can stop "on a dime" more easily... const Real FUDGE = 1.05f; @@ -130,14 +130,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::Fabs(a) < TINY_EPSILON; } //----------------------------------------------------------------------------- inline Bool isNearly(Real a, Real val) { const Real TINY_EPSILON = 0.001f; - return fabs(a - val) < TINY_EPSILON; + return WWMath::Fabs(a - val) < TINY_EPSILON; } //----------------------------------------------------------------------------- @@ -176,7 +176,7 @@ static Real tryToRotateVector3D( } } - if (fabs(angleBetween) <= maxAngle) + if (WWMath::Fabs(angleBetween) <= maxAngle) { // close enough actualDir = goalDir; @@ -266,9 +266,9 @@ static void calcDirectionToApplyThrust( Bool foundSolution = false; Real distToGoalSqr = vecToGoal.Length2(); - Real distToGoal = sqrt(distToGoalSqr); + Real distToGoal = WWMath::Sqrt(distToGoalSqr); Real curVelMagSqr = curVel.Length2(); - Real curVelMag = sqrt(curVelMagSqr); + Real curVelMag = WWMath::Sqrt(curVelMagSqr); Real maxAccelSqr = sqr(maxAccel); Real denom = curVelMagSqr - maxAccelSqr; @@ -1098,7 +1098,7 @@ void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalP Real dx = goalPos.x - obj->getPosition()->x; Real dy = goalPos.y - obj->getPosition()->y; Real dz = goalPos.z - obj->getPosition()->z; - Real dist = sqrt(dx*dx+dy*dy); + Real dist = WWMath::Sqrt(dx*dx+dy*dy); if (dist>onPathDistToGoal) { if (!obj->isKindOf(KINDOF_PROJECTILE) && dist>2*onPathDistToGoal) @@ -1216,7 +1216,7 @@ void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalP // Projectiles never stop braking once they start. jba. obj->setStatus( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_BRAKING ) ); // Projectiles cheat in 3 dimensions. - dist = sqrt(dx*dx+dy*dy+dz*dz); + dist = WWMath::Sqrt(dx*dx+dy*dy+dz*dz); Real vel = physics->getVelocityMagnitude(); if (vel < MIN_VEL) vel = MIN_VEL; @@ -1240,7 +1240,7 @@ void Locomotor::locoUpdate_moveTowardsPosition(Object* obj, const Coord3D& goalP // Normalize. if (dist > 0.001f) { - Real vel = fabs(physics->getForwardSpeed2D()); + Real vel = WWMath::Fabs(physics->getForwardSpeed2D()); if (vel < MIN_VEL) vel = MIN_VEL; if (vel > dist) @@ -1285,7 +1285,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::Fabs( relAngle ) / QUAETERPI; if (angleCoeff > 1.0f) angleCoeff = 1.0; @@ -1356,7 +1356,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::Fabs(accelForce) > WWMath::Fabs(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); @@ -1391,7 +1391,7 @@ void Locomotor::moveTowardsPositionWheels(Object* obj, PhysicsBehavior *physics, Real angle = obj->getOrientation(); // Real relAngle = ThePartitionManager->getRelativeAngle2D( obj, &goalPos ); // Real desiredAngle = angle + relAngle; - Real desiredAngle = atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real relAngle = stdAngleDiff(desiredAngle, angle); Bool moveBackwards = false; @@ -1408,14 +1408,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::Fabs(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::Fabs(relAngle) < PI/2) { moveBackwards = false; setFlag(MOVING_BACKWARDS, false); } else { @@ -1431,7 +1431,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::Fabs( relAngle ) > SMALL_TURN) { if (desiredSpeed>turnSpeed) { @@ -1456,7 +1456,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::Fabs( 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; @@ -1595,7 +1595,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::Fabs(accelForce) > WWMath::Fabs(maxForceNeeded)) accelForce = maxForceNeeded; //DEBUG_LOG(("Braking %d, actualSpeed %f, goalSpeed %f, delta %f, accel %f", getFlag(IS_BRAKING), @@ -1666,7 +1666,7 @@ Bool Locomotor::fixInvalidPosition(Object* obj, PhysicsBehavior *physics) //physics->clearAcceleration(); if (dot<0) { - dot = sqrt(-dot); + dot = WWMath::Sqrt(-dot); correctionNormalized.x *= dot*physics->getMass(); correctionNormalized.y *= dot*physics->getMass(); physics->applyMotiveForce(&correctionNormalized); @@ -1730,7 +1730,7 @@ void Locomotor::moveTowardsPositionLegs(Object* obj, PhysicsBehavior *physics, c Real angle = obj->getOrientation(); // Real relAngle = ThePartitionManager->getRelativeAngle2D( obj, &goalPos ); // Real desiredAngle = angle + relAngle; - Real desiredAngle = atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); if (m_template->m_wanderWidthFactor != 0.0f) { Real angleLimit = PI/8 * m_template->m_wanderWidthFactor; @@ -1756,7 +1756,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::Fabs( relAngle ) / (QUARTERPI); if (angleCoeff > 1.0f) angleCoeff = 1.0; @@ -1786,7 +1786,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::Fabs(accelForce) > WWMath::Fabs(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); @@ -1828,7 +1828,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::Fabs(dz)<1) { setFlag(CLIMBING, false); } @@ -1848,7 +1848,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, moveBackwards = true; } - Real groundSlope = fabs(delta.z - pos.z); + Real groundSlope = WWMath::Fabs(delta.z - pos.z); if (groundSlope<1.0f) groundSlope = 1.0f; if (groundSlope>1.0f) { @@ -1863,7 +1863,7 @@ void Locomotor::moveTowardsPositionClimb(Object* obj, PhysicsBehavior *physics, Real angle = obj->getOrientation(); // Real relAngle = ThePartitionManager->getRelativeAngle2D( obj, &goalPos ); // Real desiredAngle = angle + relAngle; - Real desiredAngle = atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real relAngle = stdAngleDiff(desiredAngle, angle); if (moveBackwards) { @@ -1877,7 +1877,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::Fabs( relAngle ) / (QUARTERPI); if (angleCoeff > 1.0f) angleCoeff = 1.0; @@ -1919,7 +1919,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::Fabs(accelForce) > WWMath::Fabs(maxForceNeeded)) accelForce = maxForceNeeded; const Coord3D *dir = obj->getUnitDirectionVector2D(); @@ -1946,7 +1946,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::Fabs(dz) > m_circleThresh) { // aim for the spot on the opposite side of the circle. @@ -1954,7 +1954,7 @@ void Locomotor::moveTowardsPositionWings(Object* obj, PhysicsBehavior *physics, Real angleTowardPos = (isNearlyZero(dx) && isNearlyZero(dy)) ? obj->getOrientation() : - atan2(dy, dx); + WWMath::Atan2(dy, dx); Real aimDir = (PI - PI/8); angleTowardPos += aimDir; @@ -2043,7 +2043,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::Fabs(delta); if (delta > MAX_VERTICAL_DAMP_RANGE) delta = MAX_VERTICAL_DAMP_RANGE; zDirDamping = 1.0f - (delta / MAX_VERTICAL_DAMP_RANGE); @@ -2160,7 +2160,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::Fabs(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. @@ -2168,14 +2168,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::Fabs(maxAccel)); + if (WWMath::Fabs(brakeDist) > WWMath::Fabs(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::Fabs(curVelZ) > m_template->m_speedLimitZ) { // or, if we're going too fast, limit it here. desiredAccel = m_template->m_speedLimitZ - curVelZ; @@ -2249,8 +2249,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::Fabs(dx)<0.1f && WWMath::Fabs(dy)<0.1f) return TURN_NONE; + Real desiredAngle = WWMath::Atan2(dy, dx); Real amount = stdAngleDiff(desiredAngle, angle); if (relAngle) *relAngle = amount; if (amount>maxTurnRate) { @@ -2272,7 +2272,7 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 // so, the thing is, we want to rotate ourselves so that our *center* is rotated // by the given amount, but the rotation must be around turnPos. so do a little // back-calculation. - Real angleDesiredForTurnPos = atan2(desiredPos.y - turnPos.y, desiredPos.x - turnPos.x); + Real angleDesiredForTurnPos = WWMath::Atan2(desiredPos.y - turnPos.y, desiredPos.x - turnPos.x); amount = angleDesiredForTurnPos - angle; #endif /// @todo srj -- there's probably a more efficient & more direct way to do this. find it. @@ -2288,7 +2288,7 @@ PhysicsTurningType Locomotor::rotateObjAroundLocoPivot(Object* obj, const Coord3 } else { - Real desiredAngle = atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); + Real desiredAngle = WWMath::Atan2(goalPos.y - obj->getPosition()->y, goalPos.x - obj->getPosition()->x); Real amount = stdAngleDiff(desiredAngle, angle); if (relAngle) *relAngle = amount; if (amount>maxTurnRate) { @@ -2466,8 +2466,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::Fabs(goalPos.y - pos->y) <= goalSpeed * m_template->m_ultraAccurateSlideIntoPlaceFactor && + WWMath::Fabs(goalPos.x - pos->x) <= goalSpeed * m_template->m_ultraAccurateSlideIntoPlaceFactor) { // don't turn, just slide in the right direction physics->setTurning(TURN_NONE); @@ -2506,7 +2506,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::Fabs(accelForce) > WWMath::Fabs(maxForceNeeded)) accelForce = maxForceNeeded; Coord3D force; @@ -2622,7 +2622,7 @@ void Locomotor::maintainCurrentPositionWings(Object* obj, PhysicsBehavior *physi Real angleTowardMaintainPos = (isNearlyZero(dx) && isNearlyZero(dy)) ? obj->getOrientation() : - atan2(dy, dx); + WWMath::Atan2(dy, dx); Real aimDir = (PI - PI/8); if (turnRadius < 0) @@ -2656,7 +2656,7 @@ void Locomotor::maintainCurrentPositionHover(Object* obj, PhysicsBehavior *physi // Real minSpeed = max( 1.0E-10f, getMinSpeed() ); Real speedDelta = minSpeed - actualSpeed; - if (fabs(speedDelta) > minSpeed) + if (WWMath::Fabs(speedDelta) > minSpeed) { Real mass = physics->getMass(); Real acceleration = (speedDelta > 0.0f) ? maxAcceleration : -getBraking(); @@ -2667,7 +2667,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::Fabs(accelForce) > WWMath::Fabs(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 8f1a133e000..8d3599a6e29 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp @@ -1800,13 +1800,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::Fabs(a->x - b->x) > THRESH) return true; - if (fabs(a->y - b->y) > THRESH) + if (WWMath::Fabs(a->y - b->y) > THRESH) return true; - if (fabs(a->z - b->z) > THRESH) + if (WWMath::Fabs(a->z - b->z) > THRESH) return true; return false; @@ -1822,7 +1822,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::Fabs(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 284efc8fcbf..9c01e74915b 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp @@ -290,7 +290,7 @@ class DeliverPayloadNugget : public ObjectCreationNugget Real dy = primary->y - secondary->y; //Calc length - Real length = sqrt( dx*dx + dy*dy ); + Real length = WWMath::Sqrt( dx*dx + dy*dy ); //Normalize length dx /= length; @@ -357,7 +357,7 @@ class DeliverPayloadNugget : public ObjectCreationNugget } - Real orient = atan2( moveToPos.y - startPos.y, moveToPos.x - startPos.x); + Real orient = WWMath::Atan2( moveToPos.y - startPos.y, moveToPos.x - startPos.x); if( m_data.m_distToTarget > 0 ) { const Real SLOP = 1.5f; @@ -1108,7 +1108,7 @@ class GenericObjectCreationNugget : public ObjectCreationNugget objUp->applyForce(&force); if (m_orientInForceDirection) - orientation = atan2(force.y, force.x); + orientation = WWMath::Atan2(force.y, force.x); } } @@ -1196,7 +1196,7 @@ class GenericObjectCreationNugget : public ObjectCreationNugget objUp->applyForce(&force); if (m_orientInForceDirection) { - orientation = atan2(force.y, force.x); + orientation = WWMath::Atan2(force.y, force.x); } DUMPREAL(orientation); objUp->setAngles(orientation, 0, 0); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp index 48a8f5b91a4..2cee8603a2d 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::Fabs(ptx*c - pty*s); + Real pty_new = (Real)WWMath::Fabs(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::Fabs(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::Sqrtf(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::Sqrtf(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::Sqrtf(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::Sqrtf(actualDistSqr); Real shrunkenDist = actualDist - totalRad; if (shrunkenDist <= 0.0f) { @@ -2235,7 +2235,7 @@ Int PartitionData::calcMaxCoiForShape(GeometryType geom, Real majorRadius, Real } case GEOMETRY_BOX: { - Real diagonal = (Real)(sqrtf(majorRadius*majorRadius + minorRadius*minorRadius)); + Real diagonal = (Real)(WWMath::Sqrtf(majorRadius*majorRadius + minorRadius*minorRadius)); Int cells = ThePartitionManager->worldToCellDist(diagonal*2) + 1; result = cells * cells; break; @@ -2652,7 +2652,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::Ceilf(cellSize / ROUGH_STEP_SIZE); Real step = cellSize / numSteps; loZ = HUGE_DIST; // huge positive hiZ = -HUGE_DIST; // huge negative @@ -3211,22 +3211,28 @@ Int PartitionManager::calcMinRadius(const ICoord2D& cur) so it really shouldn't matter... (I hope) */ - double minDistSqr = 1e12; // double, not real +#if RETAIL_COMPATIBLE_CRC + typedef double RealOrDouble; +#else + typedef Real RealOrDouble; +#endif + + RealOrDouble minDistSqr = (RealOrDouble)1e12; // double, not real for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { // double, not real - double dx = centerPos[i].x - otherPos[j].x; - double dy = centerPos[i].y - otherPos[j].y; - double curDistSqr = dx*dx + dy*dy; + RealOrDouble dx = centerPos[i].x - otherPos[j].x; + RealOrDouble dy = centerPos[i].y - otherPos[j].y; + RealOrDouble curDistSqr = dx*dx + dy*dy; if (minDistSqr > curDistSqr) minDistSqr = curDistSqr; } } // double, not real - double dist = sqrtf(minDistSqr); + RealOrDouble dist = WWMath::Sqrtf(minDistSqr); Int minRadius = REAL_TO_INT_CEIL( dist / m_cellSize ); return minRadius; @@ -3241,10 +3247,16 @@ void PartitionManager::calcRadiusVec() Int cx = getCellCountX(); Int cy = getCellCountY(); +#if RETAIL_COMPATIBLE_CRC + typedef double RealOrDouble; +#else + typedef Real RealOrDouble; +#endif + // double, not real - double dx = (double)cx * (double)cellSize; - double dy = (double)cy * (double)cellSize; - double maxPossibleDist = sqrt(dx*dx + dy*dy); + RealOrDouble dx = (RealOrDouble)cx * (RealOrDouble)cellSize; + RealOrDouble dy = (RealOrDouble)cy * (RealOrDouble)cellSize; + RealOrDouble maxPossibleDist = WWMath::Sqrt(dx*dx + dy*dy); m_maxGcoRadius = REAL_TO_INT_CEIL(maxPossibleDist / cellSize); @@ -3514,7 +3526,7 @@ Object *PartitionManager::getClosestObjects( } if (closestDistArg) { - *closestDistArg = (Real)sqrtf(closestDistSqr); + *closestDistArg = (Real)WWMath::Sqrtf(closestDistSqr); } #ifdef RTS_DEBUG @@ -3641,7 +3653,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::Sqrtf(sqr(v.x) + sqr(v.y)); // normalize if (dist == 0.0f) @@ -3819,7 +3831,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::Fabs(pos.z - center->z) > options->maxZDelta) return FALSE; // @@ -4575,7 +4587,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::Sqrtf(sqr(x1-x2) + sqr(y1-y2)); } //----------------------------------------------------------------------------- @@ -5766,7 +5778,7 @@ void hLineAddThreat(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt( WWMath::Pow(x - parms->xCenter, 2) + WWMath::Pow(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5794,7 +5806,7 @@ void hLineRemoveThreat(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt( WWMath::Pow(x - parms->xCenter, 2) + WWMath::Pow(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5822,7 +5834,7 @@ void hLineAddValue(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt( WWMath::Pow(x - parms->xCenter, 2) + WWMath::Pow(y - parms->yCenter, 2) ); mulVal = 1 - distance / parms->radius; if (mulVal < 0.0f) mulVal = 0.0f; @@ -5850,7 +5862,7 @@ void hLineRemoveValue(Int x1, Int x2, Int y, void *threatValueParms) if (x < 0 || x >= ThePartitionManager->m_cellCountX) continue; - distance = sqrt( pow(x - parms->xCenter, 2) + pow(y - parms->yCenter, 2) ); + distance = WWMath::Sqrt( WWMath::Pow(x - parms->xCenter, 2) + WWMath::Pow(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 c6abb30e5c6..9c20d1a7e98 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::Fabs(goalPos.x-pos.x); + Real dy = WWMath::Fabs(goalPos.y-pos.y); if (dxgetRelativeAngle2D( getObject(), &info.posOnPath ); } - if (fabs(deltaAngle)>PI/30) + if (WWMath::Fabs(deltaAngle)>PI/30) { return TRUE; } @@ -2272,7 +2272,7 @@ UpdateSleepTime AIUpdateInterface::doLocomotor() } else { - Real dist = sqrtf(dSqr); + Real dist = WWMath::Sqrtf(dSqr); if (dist<1) dist = 1; pos.x += 2*PATHFIND_CELL_SIZE_F*dx/(dist*LOGICFRAMES_PER_SECOND); pos.y += 2*PATHFIND_CELL_SIZE_F*dy/(dist*LOGICFRAMES_PER_SECOND); @@ -2473,7 +2473,7 @@ Real AIUpdateInterface::getLocomotorDistanceToGoal() dest = m_path->getLastNode()->getPosition(); } Real distance = ThePartitionManager->getDistanceSquared( me, dest, FROM_CENTER_3D ); - return sqrt( distance );// Other paths return dots of normalized vectors, so one sqrt ain't so bad + return WWMath::Sqrt( distance );// Other paths return dots of normalized vectors, so one sqrt ain't so bad } else { @@ -2505,7 +2505,7 @@ Real AIUpdateInterface::getLocomotorDistanceToGoal() { if (sqr(dist) > distSqr) { - return sqrt(distSqr); + return WWMath::Sqrt(distSqr); } else { @@ -2514,7 +2514,7 @@ Real AIUpdateInterface::getLocomotorDistanceToGoal() } if (distropeLen < it->ropeLenMax) { - it->ropeSpeed += fabs(TheGlobalData->m_gravity); + it->ropeSpeed += WWMath::Fabs(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::Fabs(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::Fabs(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 b0141535da9..d1cd45ed2ad 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::Sqrt( endDiveDistanceSquared ); + Real currentDistance = WWMath::Sqrt( currentDistanceSquared ); Real diveRatio = (startDiveDistance - currentDistance) / (startDiveDistance - endDiveDistance); @@ -344,10 +344,15 @@ Real DeliverPayloadAIUpdate::calcMinTurnRadius(Real* timeToTravelThatDist) const so we just eliminate the middleman: */ + // determine required turn radius based on our current speed and max turn rate +#if RETAIL_COMPATIBLE_CRC Real minTurnRadius = (maxTurnRate > 0.0f) ? (maxSpeed / maxTurnRate) : 999999.0f; +#else + Real minTurnRadius = WWMath::Div_Safe(maxSpeed, maxTurnRate); +#endif if (timeToTravelThatDist) - *timeToTravelThatDist = minTurnRadius / maxSpeed; + *timeToTravelThatDist = WWMath::Div_Safe(minTurnRadius, maxSpeed); return minTurnRadius; } @@ -1108,7 +1113,7 @@ StateReturnType RecoverFromOffMapState::update() // Success if we should try aga enterCoord.z = owner->getPosition()->z; owner->setPosition(&enterCoord); - Real enterAngle = atan2(ai->getMoveToPos()->y - enterCoord.y, ai->getMoveToPos()->x - enterCoord.x); + Real enterAngle = WWMath::Atan2(ai->getMoveToPos()->y - enterCoord.y, ai->getMoveToPos()->x - enterCoord.x); owner->setOrientation(enterAngle); PhysicsBehavior* physics = owner->getPhysics(); @@ -1148,7 +1153,7 @@ StateReturnType HeadOffMapState::onEnter() // Give move order out of town Region3D terrainExtent; TheTerrainLogic->getExtent( &terrainExtent ); const Real FUDGE = 1.2f; - Real HUGE_DIST = FUDGE * sqrt(sqr(terrainExtent.hi.x - terrainExtent.lo.x) + sqr(terrainExtent.hi.y - terrainExtent.lo.y)); + Real HUGE_DIST = FUDGE * WWMath::Sqrt(sqr(terrainExtent.hi.x - terrainExtent.lo.x) + sqr(terrainExtent.hi.y - terrainExtent.lo.y)); exitCoord.x += dir->x * HUGE_DIST; exitCoord.y += dir->y * HUGE_DIST; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cpp index c0be8479510..9c9d7196cb2 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cpp @@ -530,7 +530,7 @@ StateReturnType DozerActionDoActionState::update() // increase the construction percent of the goal object Int framesToBuild = goalObject->getTemplate()->calcTimeToBuild( dozer->getControllingPlayer() ); - Real percentProgressThisFrame = 100.0f / framesToBuild; + Real percentProgressThisFrame = WWMath::Div_Safe(100.0f, (Real)framesToBuild, 1.0f); goalObject->setConstructionPercent( goalObject->getConstructionPercent() + percentProgressThisFrame ); 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 ff3a75ce975..de14a5d9cb6 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp @@ -520,8 +520,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::Atan2(ppinfo.runwayPrep.y - ppinfo.parkingSpace.y, ppinfo.runwayPrep.x - ppinfo.parkingSpace.x); + if (WWMath::Fabs(stdAngleDiff(orient, ppinfo.parkingOrientation)) > PI/128) { intermedPt.z = (ppinfo.parkingSpace.z + ppinfo.runwayPrep.z) * 0.5f; intermed = intersectInfiniteLine2D( @@ -1082,7 +1082,7 @@ class HeliTakeoffOrLandingState : public State } else { - Real dist = sqrtf(dSqr); + Real dist = WWMath::Sqrtf(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); @@ -1210,7 +1210,7 @@ class JetOrHeliParkOrientState : public State return STATE_FAILURE; const Real THRESH = 0.001f; - if (fabs(stdAngleDiff(jet->getOrientation(), ppinfo.parkingOrientation)) <= THRESH) + if (WWMath::Fabs(stdAngleDiff(jet->getOrientation(), ppinfo.parkingOrientation)) <= THRESH) return STATE_SUCCESS; // magically position it correctly. @@ -2320,7 +2320,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::Atan2(dy, dx)); // the Gaussian sum, to avoid keeping a running total: // diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp index e42f3621baa..a0cc1f59c81 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/MissileAIUpdate.cpp @@ -232,7 +232,7 @@ void MissileAIUpdate::projectileFireAtObjectOrPosition( const Object *victim, co Real deltaZ = victimPos->z - obj->getPosition()->z; Real dx = victimPos->x - obj->getPosition()->x; Real dy = victimPos->y - obj->getPosition()->y; - Real xyDist = sqrt(sqr(dx)+sqr(dy)); + Real xyDist = WWMath::Sqrt(sqr(dx)+sqr(dy)); if (xyDist<1) xyDist = 1; Real zFactor = 0; if (deltaZ>0) { @@ -662,7 +662,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::Sqrtf(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 1b9c6f4b136..e6f0f93596b 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::Pow( 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 1a90b76d21c..00f7037f5b1 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::Sqrtf( 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. @@ -468,8 +468,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::Fabs(theirPhys->getVelocity()->length()); + mass += WWMath::Fabs(theirPhys->getMass()); vel /= 2; mass /= 2;//average of him and me @@ -701,7 +701,7 @@ UpdateSleepTime RailroadBehavior::update() if ( m_conductorState == APPLY_BRAKES ) { conductorPullInfo.speed *= modData->m_braking; - if (fabs(conductorPullInfo.speed) < 0.1f) + if (WWMath::Fabs(conductorPullInfo.speed) < 0.1f) { conductorPullInfo.speed = 0; ///////////////////////////////////////( &m_hissySteamSound ); @@ -1234,7 +1234,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::Fabs(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 ); @@ -1300,7 +1300,7 @@ void RailroadBehavior::updatePositionTrackDistance( PullInfo *pullerInfo, PullIn trackPosDelta.z = 0; Real dx = pullerInfo->towHitchPosition.x - turnPos.x; Real dy = pullerInfo->towHitchPosition.y - turnPos.y; - Real desiredAngle = atan2(dy, dx); + Real desiredAngle = WWMath::Atan2(dy, dx); Real relAngle = stdAngleDiff(desiredAngle, obj->getTransformMatrix()->Get_Z_Rotation()); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp index 0d40b8eb230..2a14009633a 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp @@ -172,7 +172,7 @@ UpdateSleepTime CleanupHazardUpdate::update() AIUpdateInterface *ai = obj->getAI(); if( ai && (ai->isIdle() || ai->isBusy()) ) { - Real fDist = sqrt( ThePartitionManager->getDistanceSquared( obj, &m_pos, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( obj, &m_pos, FROM_CENTER_2D ) ); if( fDist < 25.0f ) { //Abort clean area because there's nothing left to clean! @@ -204,7 +204,7 @@ void CleanupHazardUpdate::fireWhenReady() bonus.clear(); Real fireRange = m_weaponTemplate->getAttackRange( bonus ); Object *me = getObject(); - Real fDist = sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); if( fDist < fireRange ) { //We are currently in range! diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp index 344f3e882ae..07888b63ccf 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CommandButtonHuntUpdate.cpp @@ -338,12 +338,12 @@ Object* CommandButtonHuntUpdate::scanClosestTarget() } } Real distSqr = ThePartitionManager->getDistanceSquared(me, other, FROM_BOUNDINGSPHERE_2D); - Real dist = sqrt(distSqr); + Real dist = WWMath::Sqrt(distSqr); Int curPriority = data->m_scanRange - dist; if (info) curPriority = info->getPriority(other->getTemplate()); if (curPriority == 0) continue; // don't attack 0 priority targets. - Int modifier = dist/TheAI->getAiData()->m_attackPriorityDistanceModifier; + Int modifier = (Int)WWMath::Div_Safe(dist, TheAI->getAiData()->m_attackPriorityDistanceModifier); Int modPriority = curPriority-modifier; if (modPriority < 1) modPriority = 1; 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..6937e3ea3be 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp @@ -95,7 +95,7 @@ Bool SupplyWarehouseDockUpdate::action( Object* docker, Object *drone ) Real closeEnoughSqr = sqr(docker->getGeometryInfo().getBoundingCircleRadius()*2); Real curDistSqr = ThePartitionManager->getDistanceSquared(docker, getObject(), FROM_BOUNDINGSPHERE_2D); if (curDistSqr > closeEnoughSqr) { - DEBUG_LOG(("Failing dock, dist %f, not close enough(%f).", sqrt(curDistSqr), sqrt(closeEnoughSqr))); + DEBUG_LOG(("Failing dock, dist %f, not close enough(%f).", WWMath::Sqrt(curDistSqr), WWMath::Sqrt(closeEnoughSqr))); // Make it twitch a little. Coord3D newPos = *docker->getPosition(); Real range = 0.4*PATHFIND_CELL_SIZE_F; @@ -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::Ceil(cashValue / (float)TheGlobalData->m_baseValuePerSupplyBox); Drawable *draw = getObject()->getDrawable(); if( draw ) { diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp index ce41891b4b2..333cb28bc51 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp @@ -166,8 +166,8 @@ void DynamicShroudClearingRangeUpdate::animateGridDecals() for (int d = 0; d < GRID_FX_DECAL_COUNT; ++d) { - pos.x = ctr->x + (sinf(angle) * radius); - pos.y = ctr->y + (cosf(angle) * radius); + pos.x = ctr->x + (WWMath::Sinf(angle) * radius); + pos.y = ctr->y + (WWMath::Cosf(angle) * radius); pos.x -= ((Int)pos.x)%23; pos.y -= ((Int)pos.y)%23; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp index 8959c3a4db6..0fd8ed5c2c3 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp @@ -119,8 +119,8 @@ UpdateSleepTime FloatUpdate::update() { Real angle = INT_TO_REAL(TheGameLogic->getFrame()); - Real yaw = sin(angle * 0.0291f) * 0.05f; - Real pitch = sin(angle * 0.0515f) * 0.05f; + Real yaw = WWMath::Sin(angle * 0.0291f) * 0.05f; + Real pitch = WWMath::Sin(angle * 0.0515f) * 0.05f; Matrix3D mx = *draw->getInstanceMatrix(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileSlowDeathUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileSlowDeathUpdate.cpp index b0c4e54116c..7f2b3ddd332 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileSlowDeathUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileSlowDeathUpdate.cpp @@ -45,6 +45,7 @@ #include "GameLogic/Module/NeutronMissileSlowDeathUpdate.h" #include "GameLogic/Module/ToppleUpdate.h" #include "GameLogic/TerrainLogic.h" +#include "WWMath/wwmath.h" /////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -298,7 +299,7 @@ static void debugDrawBlastCircle( const Coord3D *center, Real radius, Real tileW // space the icons roughly one tile apart along the circumference, within sane bounds tileWidth = max( tileWidth, 1.0f ); - Int segments = (Int)ceilf( (2.0f * PI * radius) / tileWidth * 0.5f ); + Int segments = (Int)WWMath::Ceilf( (2.0f * PI * radius) / tileWidth * 0.5f ); segments = clamp(1, segments, 256); for( Int i = 0; i < segments; ++i ) @@ -306,8 +307,8 @@ static void debugDrawBlastCircle( const Coord3D *center, Real radius, Real tileW Real angle = (2.0f * PI * i) / segments; Coord3D pos; - pos.x = center->x + radius * cosf( angle ); - pos.y = center->y + radius * sinf( angle ); + pos.x = center->x + radius * WWMath::Cosf( angle ); + pos.y = center->y + radius * WWMath::Sinf( angle ); pos.z = TheTerrainLogic->getGroundHeight( pos.x, pos.y ); addIcon( &pos, tileWidth, frameDuration, color ); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileUpdate.cpp index 62de8b3f53c..0955b8a078d 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::Fabs(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::Fabs( 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::Sqrt(sqr(newPos.x-oldPos.x) + sqr(newPos.y-oldPos.y) + sqr(newPos.z-oldPos.z)); //DEBUG_LOG(("noTurnDist goes from %f to %f",m_noTurnDistLeft,m_noTurnDistLeft-distThisTurn)); m_noTurnDistLeft -= distThisTurn; } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp index 8a2be2da39c..4853ae84a6e 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp @@ -535,7 +535,7 @@ UpdateSleepTime ParticleUplinkCannonUpdate::update() Real cxDistance = (factor * data->m_swathOfDeathDistance ) - (data->m_swathOfDeathDistance * 0.5f); //cx is cartesian x //Now calculate the amplitude value. - Real height = sin( radians ); + Real height = WWMath::Sin( radians ); Real cxHeight = height * data->m_swathOfDeathAmplitude; Coord3D buildingToInitialTargetVector; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp index ae2f459f6a6..a073dc64649 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp @@ -103,7 +103,7 @@ static Real heightToSpeed(Real height) { // don't bother trying to remember how far we've fallen; instead, // back-calc it from our speed & gravity... v = sqrt(2*g*h) - return sqrt(fabs(2.0f * TheGlobalData->m_gravity * height)); + return WWMath::Sqrt(WWMath::Fabs(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::Fabs(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::Fabs(v.x) < THRESH && WWMath::Fabs(v.y) < THRESH && WWMath::Fabs(v.z) < THRESH); } //------------------------------------------------------------------------------------------------- @@ -652,9 +652,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::Fabsf(m_vel.x) < THRESH) m_vel.x = 0.0f; + if (WWMath::Fabsf(m_vel.y) < THRESH) m_vel.y = 0.0f; + if (WWMath::Fabsf(m_vel.z) < THRESH) m_vel.z = 0.0f; m_velMag = INVALID_VEL_MAG; @@ -686,9 +686,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::Fabs(m_vel.x) < STUN_RELIEF_EPSILON && + WWMath::Fabs(m_vel.y) < STUN_RELIEF_EPSILON && + WWMath::Fabs(m_vel.z) < STUN_RELIEF_EPSILON) || obj->isSignificantlyAboveTerrain() == FALSE ) { setStunned(false); @@ -733,8 +733,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::Sqrtf(sqr(xvec.X) + sqr(xvec.Y)); + Real pitchAngle = WWMath::Atan2(xvec.Z, xy); Real remainingAngle = (offset > 0) ? ((PI/2) - pitchAngle) : (-(PI/2) + pitchAngle); Real s = Sin(remainingAngle); pitchRateToUse *= s; @@ -860,8 +860,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::Fabs(m_vel.x) <= TINY_DELTA || WWMath::Fabs(activeVelZ / m_vel.x) >= MIN_ANGLE_TAN) && + (WWMath::Fabs(m_vel.y) <= TINY_DELTA || WWMath::Fabs(activeVelZ / m_vel.y) >= MIN_ANGLE_TAN)) { Real damageAmt = netSpeed * getMass() * d->m_fallHeightDamageFactor; @@ -940,7 +940,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::Sqrtf( sqr(m_vel.x) + sqr(m_vel.y) + sqr(m_vel.z) ); } return m_velMag; } @@ -959,7 +959,7 @@ Real PhysicsBehavior::getForwardSpeed2D() const if (useLegacyForwardSpeed()) { - Real speed = (Real)sqrtf( vx*vx + vy*vy ); + Real speed = (Real)WWMath::Sqrtf( vx*vx + vy*vy ); if (dot >= 0.0f) return speed; return -speed; @@ -988,7 +988,7 @@ Real PhysicsBehavior::getForwardSpeed3D() const if (useLegacyForwardSpeed()) { - Real speed = (Real)sqrtf( vx*vx + vy*vy + vz*vz ); + Real speed = (Real)WWMath::Sqrtf( vx*vx + vy*vy + vz*vz ); if (dot >= 0.0f) return speed; return -speed; @@ -1024,7 +1024,7 @@ Bool PhysicsBehavior::wasPreviouslyOverlapped(Object *obj) const //------------------------------------------------------------------------------------------------- void PhysicsBehavior::scrubVelocityZ( Real desiredVelocity ) { - if (fabs(desiredVelocity) < 0.001f) + if (WWMath::Fabs(desiredVelocity) < 0.001f) { m_vel.z = 0; } @@ -1048,7 +1048,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::Sqrtf(m_vel.x*m_vel.x + m_vel.y*m_vel.y); if (desiredVelocity > curVelocity) { return; @@ -1131,9 +1131,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::Fabs(prevPos.z - getObject()->getPosition()->z); - Real mass = fabs(getMass()); + Real mass = WWMath::Fabs(getMass()); if (vel > NORMAL_VEL_Z) { vel = NORMAL_VEL_Z; } @@ -1333,7 +1333,7 @@ void PhysicsBehavior::onCollide( Object *other, const Coord3D *loc, const Coord3 m_lastCollidee = other->getID(); - Real dist = sqrtf(distSqr); + Real dist = WWMath::Sqrtf(distSqr); Real overlap = usRadius + themRadius - dist; // if objects are coincident, dist is zero, so force would be infinite -- clearly @@ -1474,7 +1474,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::Fabs( 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 0bbe34ac99b..33560cd0fd2 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PointDefenseLaserUpdate.cpp @@ -167,7 +167,7 @@ void PointDefenseLaserUpdate::fireWhenReady() bonus.clear(); Real fireRange = data->m_weaponTemplate->getAttackRange( bonus ); Object *me = getObject(); - Real fDist = sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( me, target, FROM_CENTER_2D ) ); if( fDist < fireRange ) { //We are currently in range! @@ -290,7 +290,7 @@ Object* PointDefenseLaserUpdate::scanClosestTarget() continue; } - Real fDist = sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); + Real fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); if( fDist <= fireRange ) { @@ -317,7 +317,7 @@ Object* PointDefenseLaserUpdate::scanClosestTarget() pos.add( *other->getPosition() ); //Recalculate the distance. - fDist = sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); + fDist = WWMath::Sqrt( ThePartitionManager->getDistanceSquared( me, other, FROM_CENTER_2D ) ); } } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp index dd878a09d73..eea4a1d2baa 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp @@ -201,7 +201,7 @@ UpdateSleepTime SlavedUpdate::update() { Real health = body->getHealth(); Real maxHealth = body->getMaxHealth(); - healthPercentage = (Int)(health / maxHealth * 100.0f); + healthPercentage = (Int)(WWMath::Div_Safe(health, maxHealth) * 100.0f); } } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipDeploymentUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipDeploymentUpdate.cpp index 40ddaf1f49a..b117ad68ffb 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipDeploymentUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipDeploymentUpdate.cpp @@ -218,7 +218,7 @@ Bool SpectreGunshipDeploymentUpdate::initiateIntentToDoSpecialPower(const Specia newGunship->setPosition( &creationCoord ); //ORIENTATION - Real orient = atan2( m_initialTargetPosition.y - creationCoord.y, m_initialTargetPosition.x - creationCoord.x); + Real orient = WWMath::Atan2( m_initialTargetPosition.y - creationCoord.y, m_initialTargetPosition.x - creationCoord.x); newGunship->setOrientation( orient ); // ID diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp index bba50bcdc10..b96059bc586 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp @@ -674,7 +674,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::Fabs( 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 08b1e976360..4c6192c6ba8 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::Fabs( 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..c665e04881f 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::Fabs(stdAngleDiff(desired, a1)) < WWMath::Fabs(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::Atan2(m_toppleDirection.y, m_toppleDirection.x)); if (d->m_toppleLeftOrRightOnly) { // it's a fence or such, and can only topple left or right, so pick the closest @@ -201,7 +201,7 @@ void ToppleUpdate::applyTopplingForce( const Coord3D* toppleDirection, Real topp } // desired angle is toppleAngle +/- pi/2, whichever is closer to curangle Real desiredAngleX = angleClosestTo(toppleAngle + PI/2, toppleAngle - PI/2, curAngleX); - m_numAngleDeltaX = REAL_TO_INT_FLOOR(ANGULAR_LIMIT / (m_angularVelocity * 2)); + m_numAngleDeltaX = REAL_TO_INT_FLOOR(WWMath::Div_Safe(ANGULAR_LIMIT, m_angularVelocity * 2.0f)); if (m_numAngleDeltaX < 1) m_numAngleDeltaX = 1; m_angleDeltaX = (desiredAngleX - curAngleX) / m_numAngleDeltaX; @@ -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::Fabs(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::Fabs(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 0cd912d485c..e876fbf0bb3 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp @@ -398,8 +398,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::Ceilf(ConvertDurationFromMsecsToFrames((Real)self->m_minDelayBetweenShots)); + self->m_maxDelayBetweenShots = WWMath::Ceilf(ConvertDurationFromMsecsToFrames((Real)self->m_maxDelayBetweenShots)); } @@ -899,7 +899,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::Sqrtf(distSqr),WWMath::Sqrtf(minAttackRangeSqr))); //-extraLogging #if defined(RTS_DEBUG) @@ -925,7 +925,7 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate targetPos.set( *victimPos ); } Real reAngle = getWeaponRecoilAmount(); - Real reDir = reAngle != 0.0f ? (atan2(victimPos->y - sourcePos->y, victimPos->x - sourcePos->x)) : 0.0f; + Real reDir = reAngle != 0.0f ? (WWMath::Atan2(victimPos->y - sourcePos->y, victimPos->x - sourcePos->x)) : 0.0f; VeterancyLevel v = sourceObj->getVeterancyLevel(); const FXList* fx = isProjectileDetonation ? getProjectileDetonateFX(v) : getFireFX(v); @@ -1028,7 +1028,7 @@ UnsignedInt WeaponTemplate::fireWeaponTemplate v.y = victimPos->y - sourcePos->y; v.z = victimPos->z - sourcePos->z; // don't round the result; we WANT a fractional-frame-delay in this case. - Real delayInFrames = (v.length() / getWeaponSpeed()); + Real delayInFrames = WWMath::Div_Safe(v.length(), getWeaponSpeed()); ObjectID damageID = getDamageDealtAtSelfPosition() ? INVALID_ID : victimID; @@ -1522,9 +1522,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::Fabs(shockWaveVector.x) < WWMATH_EPSILON && + WWMath::Fabs(shockWaveVector.y) < WWMATH_EPSILON && + WWMath::Fabs(shockWaveVector.z) < WWMATH_EPSILON) { shockWaveVector.z = 1.0f; } @@ -2137,11 +2137,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::Atan2(-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::Fabs(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 afe0b874f4d..cb8f3d4f8b6 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp @@ -833,7 +833,7 @@ static void populateRandomStartPosition( GameInfo *game ) { Coord3D p1 = c1->second; Coord3D p2 = c2->second; - startSpotDistance[i][j] = sqrt( sqr(p1.x-p2.x) + sqr(p1.y-p2.y) ); + startSpotDistance[i][j] = WWMath::Sqrt( sqr(p1.x-p2.x) + sqr(p1.y-p2.y) ); } } else From 6922fe607165a240f107dbe6bee19ceb075b2cb7 Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Wed, 23 Sep 2026 13:37:37 +0300 Subject: [PATCH 7/9] feat(bezier): Add deterministic D3DX vector math for BezierSegment (#2670) Adds BezierMath with D3DXVec4Transform and D3DXVec4Dot. Under USE_DETERMINISTIC_MATH they are computed in plain C++ with a fixed order of additions; otherwise they call D3DX as before. --- .../GameEngine/Include/Common/BezierSegment.h | 27 +++++++++++++++++++ .../Source/Common/Bezier/BezFwdIterator.cpp | 6 ++--- .../Source/Common/Bezier/BezierSegment.cpp | 8 +++--- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/Core/GameEngine/Include/Common/BezierSegment.h b/Core/GameEngine/Include/Common/BezierSegment.h index eb8dd12b6f9..4b3d4defbe3 100644 --- a/Core/GameEngine/Include/Common/BezierSegment.h +++ b/Core/GameEngine/Include/Common/BezierSegment.h @@ -31,9 +31,36 @@ #include #include "Common/STLTypedefs.h" +#include "Lib/BaseDefines.h" #define USUAL_TOLERANCE 1.0f +class BezierMath +{ +public: + static void D3DXVec4Transform(D3DXVECTOR4* out, const D3DXVECTOR4* v, const D3DXMATRIX* m) + { +#if USE_DETERMINISTIC_MATH + const float x = v->x, y = v->y, z = v->z, w = v->w; + out->x = ((x * m->m[0][0] + y * m->m[1][0]) + z * m->m[2][0]) + w * m->m[3][0]; + out->y = ((x * m->m[0][1] + y * m->m[1][1]) + z * m->m[2][1]) + w * m->m[3][1]; + out->z = ((x * m->m[0][2] + y * m->m[1][2]) + z * m->m[2][2]) + w * m->m[3][2]; + out->w = ((x * m->m[0][3] + y * m->m[1][3]) + z * m->m[2][3]) + w * m->m[3][3]; +#else + ::D3DXVec4Transform(out, v, m); +#endif + } + + static float D3DXVec4Dot(const D3DXVECTOR4* a, const D3DXVECTOR4* b) + { +#if USE_DETERMINISTIC_MATH + return ((a->x * b->x + a->y * b->y) + a->z * b->z) + a->w * b->w; +#else + return ::D3DXVec4Dot(a, b); +#endif + } +}; + class BezierSegment { protected: diff --git a/Core/GameEngine/Source/Common/Bezier/BezFwdIterator.cpp b/Core/GameEngine/Source/Common/Bezier/BezFwdIterator.cpp index 03f199fb338..0a5639a53a2 100644 --- a/Core/GameEngine/Source/Common/Bezier/BezFwdIterator.cpp +++ b/Core/GameEngine/Source/Common/Bezier/BezFwdIterator.cpp @@ -62,9 +62,9 @@ void BezFwdIterator::start() D3DXVECTOR4 pz(mBezSeg.m_controlPoints[0].z, mBezSeg.m_controlPoints[1].z, mBezSeg.m_controlPoints[2].z, mBezSeg.m_controlPoints[3].z); D3DXVECTOR4 cVec[3]; - D3DXVec4Transform(&cVec[0], &px, &BezierSegment::s_bezBasisMatrix); - D3DXVec4Transform(&cVec[1], &py, &BezierSegment::s_bezBasisMatrix); - D3DXVec4Transform(&cVec[2], &pz, &BezierSegment::s_bezBasisMatrix); + BezierMath::D3DXVec4Transform(&cVec[0], &px, &BezierSegment::s_bezBasisMatrix); + BezierMath::D3DXVec4Transform(&cVec[1], &py, &BezierSegment::s_bezBasisMatrix); + BezierMath::D3DXVec4Transform(&cVec[2], &pz, &BezierSegment::s_bezBasisMatrix); mCurrPoint = mBezSeg.m_controlPoints[0]; diff --git a/Core/GameEngine/Source/Common/Bezier/BezierSegment.cpp b/Core/GameEngine/Source/Common/Bezier/BezierSegment.cpp index 715d8d6d59d..2923cbe4833 100644 --- a/Core/GameEngine/Source/Common/Bezier/BezierSegment.cpp +++ b/Core/GameEngine/Source/Common/Bezier/BezierSegment.cpp @@ -109,11 +109,11 @@ void BezierSegment::evaluateBezSegmentAtT(Real tValue, Coord3D *outResult) const D3DXVECTOR4 zCoords(m_controlPoints[0].z, m_controlPoints[1].z, m_controlPoints[2].z, m_controlPoints[3].z); D3DXVECTOR4 tResult; - D3DXVec4Transform(&tResult, &tVec, &BezierSegment::s_bezBasisMatrix); + BezierMath::D3DXVec4Transform(&tResult, &tVec, &BezierSegment::s_bezBasisMatrix); - outResult->x = D3DXVec4Dot(&xCoords, &tResult); - outResult->y = D3DXVec4Dot(&yCoords, &tResult); - outResult->z = D3DXVec4Dot(&zCoords, &tResult); + outResult->x = BezierMath::D3DXVec4Dot(&xCoords, &tResult); + outResult->y = BezierMath::D3DXVec4Dot(&yCoords, &tResult); + outResult->z = BezierMath::D3DXVec4Dot(&zCoords, &tResult); } //------------------------------------------------------------------------------------------------- From d33ff9dd3232cac9f047f6485098a85beed8d875 Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Wed, 23 Sep 2026 13:37:54 +0300 Subject: [PATCH 8/9] refactor(visualc): Remove visualc.h (#2670) Removes the M_* math constants from visualc.h and switches their remaining uses in W3DMouse.cpp and W3DView.cpp to the WWMATH_* constants. Without them visualc.h is empty, so it is removed together with its include in always.h. --- .../Source/W3DDevice/GameClient/W3DMouse.cpp | 6 +- .../Source/W3DDevice/GameClient/W3DView.cpp | 4 +- .../Source/WWVegas/WWLib/CMakeLists.txt | 1 - Core/Libraries/Source/WWVegas/WWLib/always.h | 4 -- Core/Libraries/Source/WWVegas/WWLib/visualc.h | 59 ------------------- 5 files changed, 5 insertions(+), 69 deletions(-) delete mode 100644 Core/Libraries/Source/WWVegas/WWLib/visualc.h diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DMouse.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DMouse.cpp index 8d21e481280..5c7aa3a833a 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DMouse.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DMouse.cpp @@ -571,7 +571,7 @@ void W3DMouse::draw() offset = TheInGameUI->getScrollAmount(); offset.normalize(); Real theta = WWMath::Atan2(-offset.y, offset.x); - theta -= (Real)M_PI/2; + theta -= (Real)WWMATH_HALF_PI; tm.Rotate_Z(theta); } cursorModels[m_currentW3DCursor]->Set_Transform(tm); @@ -679,12 +679,12 @@ void W3DMouse::setCursorDirection(MouseCursor cursor) { offset.normalize(); Real theta = WWMath::Atan2(offset.y, offset.x); - theta = fmod(theta+M_PI*2,M_PI*2); + theta = fmod(theta+WWMATH_TWO_PI,WWMATH_TWO_PI); Int numDirections=m_cursorInfo[m_currentCursor].numDirections; //Figure out which of our predrawn cursor orientations best matches the //actual cursor direction. Frame 0 is assumed to point right and continue //clockwise. - m_directionFrame=(Int)(theta/(2.0f*M_PI/(Real)numDirections)+0.5f); + m_directionFrame=(Int)(theta/(WWMATH_TWO_PI/(Real)numDirections)+0.5f); if (m_directionFrame >= numDirections) m_directionFrame = 0; } diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp index 37be366a1b3..58f6a3460f8 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp @@ -1526,7 +1526,7 @@ void W3DView::update() if (cameraLockObj->isUsingAirborneLocomotor() && cameraLockObj->isAboveTerrainOrWater()) { Matrix3D camXForm; - Real idealZRot = cameraLockObj->getOrientation() - M_PI_2; + Real idealZRot = cameraLockObj->getOrientation() - WWMATH_HALF_PI; if (m_snapImmediate) { @@ -2237,7 +2237,7 @@ void W3DView::setPitchToDefault() void W3DView::setDefaultView(Real pitch, Real angle, Real maxHeight) { // MDC - we no longer want to rotate maps (design made all of them right to begin with) - // m_defaultAngle = angle * M_PI/180.0f; + // m_defaultAngle = angle * WWMATH_PI/180.0f; setDefaultPitch(pitch); m_maxHeightAboveGround = TheGlobalData->m_maxCameraHeight*maxHeight; if (m_minHeightAboveGround > m_maxHeightAboveGround) diff --git a/Core/Libraries/Source/WWVegas/WWLib/CMakeLists.txt b/Core/Libraries/Source/WWVegas/WWLib/CMakeLists.txt index 23d32b1dc66..7decc6cdca7 100644 --- a/Core/Libraries/Source/WWVegas/WWLib/CMakeLists.txt +++ b/Core/Libraries/Source/WWVegas/WWLib/CMakeLists.txt @@ -130,7 +130,6 @@ set(WWLIB_SRC utf8.h vector.cpp Vector.h - visualc.h widestring.cpp widestring.h win.h diff --git a/Core/Libraries/Source/WWVegas/WWLib/always.h b/Core/Libraries/Source/WWVegas/WWLib/always.h index 71eea07664b..836dca90c05 100644 --- a/Core/Libraries/Source/WWVegas/WWLib/always.h +++ b/Core/Libraries/Source/WWVegas/WWLib/always.h @@ -176,10 +176,6 @@ public: \ ** various compilers to a common behavior such that the C&C engine will compile without ** error or warning. */ -#if defined(_MSC_VER) -#include "visualc.h" -#endif - #if defined(__MINGW32__) || defined(__MINGW64__) #include "mingw.h" #endif diff --git a/Core/Libraries/Source/WWVegas/WWLib/visualc.h b/Core/Libraries/Source/WWVegas/WWLib/visualc.h deleted file mode 100644 index d35c4cc9a94..00000000000 --- a/Core/Libraries/Source/WWVegas/WWLib/visualc.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -** Command & Conquer Generals Zero Hour(tm) -** Copyright 2025 Electronic Arts Inc. -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -*/ - -/*********************************************************************************************** - *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S *** - *********************************************************************************************** - * * - * Project Name : Command & Conquer * - * * - * $Archive:: /Commando/Code/wwlib/visualc.h $* - * * - * $Author:: Greg_h $* - * * - * $Modtime:: 5/16/01 4:11p $* - * * - * $Revision:: 9 $* - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#pragma once - -#if defined(_MSC_VER) - - -#define M_E 2.71828182845904523536 -#define M_LOG2E 1.44269504088896340736 -#define M_LOG10E 0.434294481903251827651 -#define M_LN2 0.693147180559945309417 -#define M_LN10 2.30258509299404568402 -#define M_PI 3.14159265358979323846 -#define M_PI_2 1.57079632679489661923 -#define M_PI_4 0.785398163397448309616 -#define M_1_PI 0.318309886183790671538 -#define M_2_PI 0.636619772367581343076 -#define M_1_SQRTPI 0.564189583547756286948 -#define M_2_SQRTPI 1.12837916709551257390 -#define M_SQRT2 1.41421356237309504880 -#define M_SQRT_2 0.707106781186547524401 - - -#endif - From 9901042cf6fe56ced160ee12885bd2c1f42cefa0 Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Mon, 12 Oct 2026 10:36:59 +0300 Subject: [PATCH 9/9] test(wwmath): Add WWMath unit tests and benchmarks (#2670) Adds a unit test that checks the bits of each WWMath function with a deterministic implementation on fixed inputs, so a change in the math shows up from one build to the next. Deterministic math has one set of reference bits for every platform, the retail-compatible math one set for win32, where its branch is built with the tests; the test is skipped where a build configuration has none. A Google Benchmark times each WWMath function next to the CRT function it replaces. --- Benchmarks/Google/Core/CMakeLists.txt | 1 + .../WWVegas/WWMath/WWMathBenchmark.cpp | 138 +++++++++++ Tests/Google/Core/CMakeLists.txt | 5 + .../Libraries/WWVegas/WWMath/WWMathCalls.h | 213 +++++++++++++++++ .../Libraries/WWVegas/WWMath/WWMathDumps.h | 214 ++++++++++++++++++ .../Libraries/WWVegas/WWMath/WWMathKeys.h | 205 +++++++++++++++++ .../Libraries/WWVegas/WWMath/WWMathTest.cpp | 58 +++++ .../Libraries/WWVegas/WWMath/WWMathTestCase.h | 96 ++++++++ 8 files changed, 930 insertions(+) create mode 100644 Benchmarks/Google/Core/Libraries/WWVegas/WWMath/WWMathBenchmark.cpp create mode 100644 Tests/Google/Core/Libraries/WWVegas/WWMath/WWMathCalls.h create mode 100644 Tests/Google/Core/Libraries/WWVegas/WWMath/WWMathDumps.h create mode 100644 Tests/Google/Core/Libraries/WWVegas/WWMath/WWMathKeys.h create mode 100644 Tests/Google/Core/Libraries/WWVegas/WWMath/WWMathTest.cpp create mode 100644 Tests/Google/Core/Libraries/WWVegas/WWMath/WWMathTestCase.h diff --git a/Benchmarks/Google/Core/CMakeLists.txt b/Benchmarks/Google/Core/CMakeLists.txt index d18c2ea05fa..3396b9b593b 100644 --- a/Benchmarks/Google/Core/CMakeLists.txt +++ b/Benchmarks/Google/Core/CMakeLists.txt @@ -3,6 +3,7 @@ set(COREI_GOOGLEBENCHMARK_SRC GoogleBenchmarkMain.cpp GameEngine/Common/AsciiStringBenchmark.cpp Libraries/Compression/CompressionManagerBenchmark.cpp + Libraries/WWVegas/WWMath/WWMathBenchmark.cpp ) add_library(corei_googlebenchmark INTERFACE) diff --git a/Benchmarks/Google/Core/Libraries/WWVegas/WWMath/WWMathBenchmark.cpp b/Benchmarks/Google/Core/Libraries/WWVegas/WWMath/WWMathBenchmark.cpp new file mode 100644 index 00000000000..3dd6b6a64bd --- /dev/null +++ b/Benchmarks/Google/Core/Libraries/WWVegas/WWMath/WWMathBenchmark.cpp @@ -0,0 +1,138 @@ +/* +** Command & Conquer Generals Zero Hour(tm) +** Copyright 2026 TheSuperHackers +** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +*/ + +#include +#include + +#include "WWMath/wwmath.h" + +// Each WWMath function is timed next to the CRT function it replaces. + +template +static void BM_Unary(benchmark::State &state) +{ + T x = static_cast(0.5); + for (auto _ : state) + { + benchmark::DoNotOptimize(x); + benchmark::DoNotOptimize(Function(x)); + } +} + +template +static void BM_Binary(benchmark::State &state) +{ + T x = static_cast(0.4); + T y = static_cast(1.3); + for (auto _ : state) + { + benchmark::DoNotOptimize(x); + benchmark::DoNotOptimize(y); + benchmark::DoNotOptimize(Function(x, y)); + } +} + +BENCHMARK_TEMPLATE(BM_Unary, float, WWMath::Sinf); +BENCHMARK_TEMPLATE(BM_Unary, float, sinf); +BENCHMARK_TEMPLATE(BM_Unary, double, WWMath::Sin); +BENCHMARK_TEMPLATE(BM_Unary, double, sin); + +BENCHMARK_TEMPLATE(BM_Unary, float, WWMath::Cosf); +BENCHMARK_TEMPLATE(BM_Unary, float, cosf); +BENCHMARK_TEMPLATE(BM_Unary, double, WWMath::Cos); +BENCHMARK_TEMPLATE(BM_Unary, double, cos); + +BENCHMARK_TEMPLATE(BM_Unary, float, WWMath::Tanf); +BENCHMARK_TEMPLATE(BM_Unary, float, tanf); +BENCHMARK_TEMPLATE(BM_Unary, double, WWMath::Tan); +BENCHMARK_TEMPLATE(BM_Unary, double, tan); + +BENCHMARK_TEMPLATE(BM_Unary, float, WWMath::Asinf); +BENCHMARK_TEMPLATE(BM_Unary, float, asinf); +BENCHMARK_TEMPLATE(BM_Unary, double, WWMath::Asin); +BENCHMARK_TEMPLATE(BM_Unary, double, asin); + +BENCHMARK_TEMPLATE(BM_Unary, float, WWMath::Acosf); +BENCHMARK_TEMPLATE(BM_Unary, float, acosf); +BENCHMARK_TEMPLATE(BM_Unary, double, WWMath::Acos); +BENCHMARK_TEMPLATE(BM_Unary, double, acos); + +BENCHMARK_TEMPLATE(BM_Unary, float, WWMath::Atanf); +BENCHMARK_TEMPLATE(BM_Unary, float, atanf); +BENCHMARK_TEMPLATE(BM_Unary, double, WWMath::Atan); +BENCHMARK_TEMPLATE(BM_Unary, double, atan); + +BENCHMARK_TEMPLATE(BM_Binary, float, WWMath::Atan2f); +BENCHMARK_TEMPLATE(BM_Binary, float, atan2f); +BENCHMARK_TEMPLATE(BM_Binary, double, WWMath::Atan2); +BENCHMARK_TEMPLATE(BM_Binary, double, atan2); + +BENCHMARK_TEMPLATE(BM_Unary, float, WWMath::Sinhf); +BENCHMARK_TEMPLATE(BM_Unary, float, sinhf); +BENCHMARK_TEMPLATE(BM_Unary, double, WWMath::Sinh); +BENCHMARK_TEMPLATE(BM_Unary, double, sinh); + +BENCHMARK_TEMPLATE(BM_Unary, float, WWMath::Coshf); +BENCHMARK_TEMPLATE(BM_Unary, float, coshf); +BENCHMARK_TEMPLATE(BM_Unary, double, WWMath::Cosh); +BENCHMARK_TEMPLATE(BM_Unary, double, cosh); + +BENCHMARK_TEMPLATE(BM_Unary, float, WWMath::Tanhf); +BENCHMARK_TEMPLATE(BM_Unary, float, tanhf); +BENCHMARK_TEMPLATE(BM_Unary, double, WWMath::Tanh); +BENCHMARK_TEMPLATE(BM_Unary, double, tanh); + +BENCHMARK_TEMPLATE(BM_Unary, float, WWMath::Expf); +BENCHMARK_TEMPLATE(BM_Unary, float, expf); +BENCHMARK_TEMPLATE(BM_Unary, double, WWMath::Exp); +BENCHMARK_TEMPLATE(BM_Unary, double, exp); + +BENCHMARK_TEMPLATE(BM_Unary, float, WWMath::Logf); +BENCHMARK_TEMPLATE(BM_Unary, float, logf); +BENCHMARK_TEMPLATE(BM_Unary, double, WWMath::Log); +BENCHMARK_TEMPLATE(BM_Unary, double, log); + +BENCHMARK_TEMPLATE(BM_Unary, float, WWMath::Log10f); +BENCHMARK_TEMPLATE(BM_Unary, float, log10f); +BENCHMARK_TEMPLATE(BM_Unary, double, WWMath::Log10); +BENCHMARK_TEMPLATE(BM_Unary, double, log10); + +BENCHMARK_TEMPLATE(BM_Binary, float, WWMath::Powf); +BENCHMARK_TEMPLATE(BM_Binary, float, powf); +BENCHMARK_TEMPLATE(BM_Binary, double, WWMath::Pow); +BENCHMARK_TEMPLATE(BM_Binary, double, pow); + +BENCHMARK_TEMPLATE(BM_Unary, float, WWMath::Sqrtf); +BENCHMARK_TEMPLATE(BM_Unary, float, sqrtf); +BENCHMARK_TEMPLATE(BM_Unary, double, WWMath::Sqrt); +BENCHMARK_TEMPLATE(BM_Unary, double, sqrt); + +BENCHMARK_TEMPLATE(BM_Unary, float, WWMath::Fabsf); +BENCHMARK_TEMPLATE(BM_Unary, float, fabsf); +BENCHMARK_TEMPLATE(BM_Unary, double, WWMath::Fabs); +BENCHMARK_TEMPLATE(BM_Unary, double, fabs); + +BENCHMARK_TEMPLATE(BM_Unary, float, WWMath::Ceilf); +BENCHMARK_TEMPLATE(BM_Unary, float, ceilf); +BENCHMARK_TEMPLATE(BM_Unary, double, WWMath::Ceil); +BENCHMARK_TEMPLATE(BM_Unary, double, ceil); + +BENCHMARK_TEMPLATE(BM_Unary, float, WWMath::Floorf); +BENCHMARK_TEMPLATE(BM_Unary, float, floorf); +BENCHMARK_TEMPLATE(BM_Unary, double, WWMath::Floor); +BENCHMARK_TEMPLATE(BM_Unary, double, floor); diff --git a/Tests/Google/Core/CMakeLists.txt b/Tests/Google/Core/CMakeLists.txt index f4a850622cf..891aa8532a7 100644 --- a/Tests/Google/Core/CMakeLists.txt +++ b/Tests/Google/Core/CMakeLists.txt @@ -3,6 +3,11 @@ set(COREI_GOOGLETEST_SRC GoogleTestMain.cpp GameEngine/Common/AsciiStringTest.cpp Libraries/Compression/CompressionManagerTest.cpp + Libraries/WWVegas/WWMath/WWMathCalls.h + Libraries/WWVegas/WWMath/WWMathDumps.h + Libraries/WWVegas/WWMath/WWMathKeys.h + Libraries/WWVegas/WWMath/WWMathTest.cpp + Libraries/WWVegas/WWMath/WWMathTestCase.h ) add_library(corei_googletest INTERFACE) diff --git a/Tests/Google/Core/Libraries/WWVegas/WWMath/WWMathCalls.h b/Tests/Google/Core/Libraries/WWVegas/WWMath/WWMathCalls.h new file mode 100644 index 00000000000..b1e526c487a --- /dev/null +++ b/Tests/Google/Core/Libraries/WWVegas/WWMath/WWMathCalls.h @@ -0,0 +1,213 @@ +/* +** Command & Conquer Generals Zero Hour(tm) +** Copyright 2026 TheSuperHackers +** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +*/ + +#pragma once + +#include + +#include "WWMathKeys.h" +#include "WWMathTestCase.h" + +typedef std::string (*WWMathCall)(); + +struct WWMathCallEntry +{ + WWMathKey key; + WWMathCall call; +}; + +static constexpr WWMathCallEntry wwmathCalls[] = { + { WWMathKey::Sin_0_5f, [] { return toBitsString(WWMath::Sin(runtimeValue(0.5f))); } }, + { WWMathKey::Sin_2_7f, [] { return toBitsString(WWMath::Sin(runtimeValue(2.7f))); } }, + { WWMathKey::Sin_187_66f, [] { return toBitsString(WWMath::Sin(runtimeValue(187.66f))); } }, + { WWMathKey::Sin_0_5, [] { return toBitsString(WWMath::Sin(runtimeValue(0.5))); } }, + { WWMathKey::Sin_2_7, [] { return toBitsString(WWMath::Sin(runtimeValue(2.7))); } }, + { WWMathKey::Sin_187_66, [] { return toBitsString(WWMath::Sin(runtimeValue(187.66))); } }, + { WWMathKey::Sinf_0_5f, [] { return toBitsString(WWMath::Sinf(runtimeValue(0.5f))); } }, + { WWMathKey::Sinf_2_7f, [] { return toBitsString(WWMath::Sinf(runtimeValue(2.7f))); } }, + { WWMathKey::Sinf_187_66f, [] { return toBitsString(WWMath::Sinf(runtimeValue(187.66f))); } }, + { WWMathKey::Sinf_Legacy_0_5f, [] { return toBitsString(WWMath::Sinf_Legacy(runtimeValue(0.5f))); } }, + { WWMathKey::Sinf_Legacy_2_7f, [] { return toBitsString(WWMath::Sinf_Legacy(runtimeValue(2.7f))); } }, + { WWMathKey::Sinf_Legacy_187_66f, [] { return toBitsString(WWMath::Sinf_Legacy(runtimeValue(187.66f))); } }, + + { WWMathKey::Cos_0_5f, [] { return toBitsString(WWMath::Cos(runtimeValue(0.5f))); } }, + { WWMathKey::Cos_2_7f, [] { return toBitsString(WWMath::Cos(runtimeValue(2.7f))); } }, + { WWMathKey::Cos_187_66f, [] { return toBitsString(WWMath::Cos(runtimeValue(187.66f))); } }, + { WWMathKey::Cos_0_5, [] { return toBitsString(WWMath::Cos(runtimeValue(0.5))); } }, + { WWMathKey::Cos_2_7, [] { return toBitsString(WWMath::Cos(runtimeValue(2.7))); } }, + { WWMathKey::Cos_187_66, [] { return toBitsString(WWMath::Cos(runtimeValue(187.66))); } }, + { WWMathKey::Cosf_0_5f, [] { return toBitsString(WWMath::Cosf(runtimeValue(0.5f))); } }, + { WWMathKey::Cosf_2_7f, [] { return toBitsString(WWMath::Cosf(runtimeValue(2.7f))); } }, + { WWMathKey::Cosf_187_66f, [] { return toBitsString(WWMath::Cosf(runtimeValue(187.66f))); } }, + { WWMathKey::Cosf_Legacy_0_5f, [] { return toBitsString(WWMath::Cosf_Legacy(runtimeValue(0.5f))); } }, + { WWMathKey::Cosf_Legacy_2_7f, [] { return toBitsString(WWMath::Cosf_Legacy(runtimeValue(2.7f))); } }, + { WWMathKey::Cosf_Legacy_187_66f, [] { return toBitsString(WWMath::Cosf_Legacy(runtimeValue(187.66f))); } }, + + { WWMathKey::Tan_0_5f, [] { return toBitsString(WWMath::Tan(runtimeValue(0.5f))); } }, + { WWMathKey::Tan_2_7f, [] { return toBitsString(WWMath::Tan(runtimeValue(2.7f))); } }, + { WWMathKey::Tan_187_66f, [] { return toBitsString(WWMath::Tan(runtimeValue(187.66f))); } }, + { WWMathKey::Tan_0_5, [] { return toBitsString(WWMath::Tan(runtimeValue(0.5))); } }, + { WWMathKey::Tan_2_7, [] { return toBitsString(WWMath::Tan(runtimeValue(2.7))); } }, + { WWMathKey::Tan_187_66, [] { return toBitsString(WWMath::Tan(runtimeValue(187.66))); } }, + { WWMathKey::Tanf_0_5f, [] { return toBitsString(WWMath::Tanf(runtimeValue(0.5f))); } }, + { WWMathKey::Tanf_2_7f, [] { return toBitsString(WWMath::Tanf(runtimeValue(2.7f))); } }, + { WWMathKey::Tanf_187_66f, [] { return toBitsString(WWMath::Tanf(runtimeValue(187.66f))); } }, + + { WWMathKey::Asin_Minus0_5f, [] { return toBitsString(WWMath::Asin(runtimeValue(-0.5f))); } }, + { WWMathKey::Asin_0_25f, [] { return toBitsString(WWMath::Asin(runtimeValue(0.25f))); } }, + { WWMathKey::Asin_0_9f, [] { return toBitsString(WWMath::Asin(runtimeValue(0.9f))); } }, + { WWMathKey::Asin_Minus0_5, [] { return toBitsString(WWMath::Asin(runtimeValue(-0.5))); } }, + { WWMathKey::Asin_0_25, [] { return toBitsString(WWMath::Asin(runtimeValue(0.25))); } }, + { WWMathKey::Asin_0_9, [] { return toBitsString(WWMath::Asin(runtimeValue(0.9))); } }, + { WWMathKey::Asinf_Minus0_5f, [] { return toBitsString(WWMath::Asinf(runtimeValue(-0.5f))); } }, + { WWMathKey::Asinf_0_25f, [] { return toBitsString(WWMath::Asinf(runtimeValue(0.25f))); } }, + { WWMathKey::Asinf_0_9f, [] { return toBitsString(WWMath::Asinf(runtimeValue(0.9f))); } }, + + { WWMathKey::Acos_Minus0_5f, [] { return toBitsString(WWMath::Acos(runtimeValue(-0.5f))); } }, + { WWMathKey::Acos_0_25f, [] { return toBitsString(WWMath::Acos(runtimeValue(0.25f))); } }, + { WWMathKey::Acos_0_9f, [] { return toBitsString(WWMath::Acos(runtimeValue(0.9f))); } }, + { WWMathKey::Acos_Minus0_5, [] { return toBitsString(WWMath::Acos(runtimeValue(-0.5))); } }, + { WWMathKey::Acos_0_25, [] { return toBitsString(WWMath::Acos(runtimeValue(0.25))); } }, + { WWMathKey::Acos_0_9, [] { return toBitsString(WWMath::Acos(runtimeValue(0.9))); } }, + { WWMathKey::Acosf_Minus0_5f, [] { return toBitsString(WWMath::Acosf(runtimeValue(-0.5f))); } }, + { WWMathKey::Acosf_0_25f, [] { return toBitsString(WWMath::Acosf(runtimeValue(0.25f))); } }, + { WWMathKey::Acosf_0_9f, [] { return toBitsString(WWMath::Acosf(runtimeValue(0.9f))); } }, + + { WWMathKey::Atan_0_5f, [] { return toBitsString(WWMath::Atan(runtimeValue(0.5f))); } }, + { WWMathKey::Atan_2_7f, [] { return toBitsString(WWMath::Atan(runtimeValue(2.7f))); } }, + { WWMathKey::Atan_187_66f, [] { return toBitsString(WWMath::Atan(runtimeValue(187.66f))); } }, + { WWMathKey::Atan_0_5, [] { return toBitsString(WWMath::Atan(runtimeValue(0.5))); } }, + { WWMathKey::Atan_2_7, [] { return toBitsString(WWMath::Atan(runtimeValue(2.7))); } }, + { WWMathKey::Atan_187_66, [] { return toBitsString(WWMath::Atan(runtimeValue(187.66))); } }, + { WWMathKey::Atanf_0_5f, [] { return toBitsString(WWMath::Atanf(runtimeValue(0.5f))); } }, + { WWMathKey::Atanf_2_7f, [] { return toBitsString(WWMath::Atanf(runtimeValue(2.7f))); } }, + { WWMathKey::Atanf_187_66f, [] { return toBitsString(WWMath::Atanf(runtimeValue(187.66f))); } }, + + { WWMathKey::Atan2_0_4f_1_3f, [] { return toBitsString(WWMath::Atan2(runtimeValue(0.4f), runtimeValue(1.3f))); } }, + { WWMathKey::Atan2_2_7f_11_9f, [] { return toBitsString(WWMath::Atan2(runtimeValue(2.7f), runtimeValue(11.9f))); } }, + { WWMathKey::Atan2_Minus3_5f_2_0f, [] { return toBitsString(WWMath::Atan2(runtimeValue(-3.5f), runtimeValue(2.0f))); } }, + { WWMathKey::Atan2_0_4_1_3, [] { return toBitsString(WWMath::Atan2(runtimeValue(0.4), runtimeValue(1.3))); } }, + { WWMathKey::Atan2_2_7_11_9, [] { return toBitsString(WWMath::Atan2(runtimeValue(2.7), runtimeValue(11.9))); } }, + { WWMathKey::Atan2_Minus3_5_2_0, [] { return toBitsString(WWMath::Atan2(runtimeValue(-3.5), runtimeValue(2.0))); } }, + { WWMathKey::Atan2f_0_4f_1_3f, [] { return toBitsString(WWMath::Atan2f(runtimeValue(0.4f), runtimeValue(1.3f))); } }, + { WWMathKey::Atan2f_2_7f_11_9f, [] { return toBitsString(WWMath::Atan2f(runtimeValue(2.7f), runtimeValue(11.9f))); } }, + { WWMathKey::Atan2f_Minus3_5f_2_0f, [] { return toBitsString(WWMath::Atan2f(runtimeValue(-3.5f), runtimeValue(2.0f))); } }, + + { WWMathKey::Sinh_0_5, [] { return toBitsString(WWMath::Sinh(runtimeValue(0.5))); } }, + { WWMathKey::Sinh_Minus0_5, [] { return toBitsString(WWMath::Sinh(runtimeValue(-0.5))); } }, + { WWMathKey::Sinh_2_7, [] { return toBitsString(WWMath::Sinh(runtimeValue(2.7))); } }, + { WWMathKey::Sinhf_0_5f, [] { return toBitsString(WWMath::Sinhf(runtimeValue(0.5f))); } }, + { WWMathKey::Sinhf_Minus0_5f, [] { return toBitsString(WWMath::Sinhf(runtimeValue(-0.5f))); } }, + { WWMathKey::Sinhf_2_7f, [] { return toBitsString(WWMath::Sinhf(runtimeValue(2.7f))); } }, + + { WWMathKey::Cosh_0_5, [] { return toBitsString(WWMath::Cosh(runtimeValue(0.5))); } }, + { WWMathKey::Cosh_Minus0_5, [] { return toBitsString(WWMath::Cosh(runtimeValue(-0.5))); } }, + { WWMathKey::Cosh_2_7, [] { return toBitsString(WWMath::Cosh(runtimeValue(2.7))); } }, + { WWMathKey::Coshf_0_5f, [] { return toBitsString(WWMath::Coshf(runtimeValue(0.5f))); } }, + { WWMathKey::Coshf_Minus0_5f, [] { return toBitsString(WWMath::Coshf(runtimeValue(-0.5f))); } }, + { WWMathKey::Coshf_2_7f, [] { return toBitsString(WWMath::Coshf(runtimeValue(2.7f))); } }, + + { WWMathKey::Tanh_0_5, [] { return toBitsString(WWMath::Tanh(runtimeValue(0.5))); } }, + { WWMathKey::Tanh_Minus0_5, [] { return toBitsString(WWMath::Tanh(runtimeValue(-0.5))); } }, + { WWMathKey::Tanh_2_7, [] { return toBitsString(WWMath::Tanh(runtimeValue(2.7))); } }, + { WWMathKey::Tanhf_0_5f, [] { return toBitsString(WWMath::Tanhf(runtimeValue(0.5f))); } }, + { WWMathKey::Tanhf_Minus0_5f, [] { return toBitsString(WWMath::Tanhf(runtimeValue(-0.5f))); } }, + { WWMathKey::Tanhf_2_7f, [] { return toBitsString(WWMath::Tanhf(runtimeValue(2.7f))); } }, + + { WWMathKey::Exp_0_5, [] { return toBitsString(WWMath::Exp(runtimeValue(0.5))); } }, + { WWMathKey::Exp_Minus0_5, [] { return toBitsString(WWMath::Exp(runtimeValue(-0.5))); } }, + { WWMathKey::Exp_2_7, [] { return toBitsString(WWMath::Exp(runtimeValue(2.7))); } }, + { WWMathKey::Expf_0_5f, [] { return toBitsString(WWMath::Expf(runtimeValue(0.5f))); } }, + { WWMathKey::Expf_Minus0_5f, [] { return toBitsString(WWMath::Expf(runtimeValue(-0.5f))); } }, + { WWMathKey::Expf_2_7f, [] { return toBitsString(WWMath::Expf(runtimeValue(2.7f))); } }, + + { WWMathKey::Log_0_5, [] { return toBitsString(WWMath::Log(runtimeValue(0.5))); } }, + { WWMathKey::Log_2_7, [] { return toBitsString(WWMath::Log(runtimeValue(2.7))); } }, + { WWMathKey::Log_187_66, [] { return toBitsString(WWMath::Log(runtimeValue(187.66))); } }, + { WWMathKey::Logf_0_5f, [] { return toBitsString(WWMath::Logf(runtimeValue(0.5f))); } }, + { WWMathKey::Logf_2_7f, [] { return toBitsString(WWMath::Logf(runtimeValue(2.7f))); } }, + { WWMathKey::Logf_187_66f, [] { return toBitsString(WWMath::Logf(runtimeValue(187.66f))); } }, + + { WWMathKey::Log10_0_5, [] { return toBitsString(WWMath::Log10(runtimeValue(0.5))); } }, + { WWMathKey::Log10_2_7, [] { return toBitsString(WWMath::Log10(runtimeValue(2.7))); } }, + { WWMathKey::Log10_187_66, [] { return toBitsString(WWMath::Log10(runtimeValue(187.66))); } }, + { WWMathKey::Log10f_0_5f, [] { return toBitsString(WWMath::Log10f(runtimeValue(0.5f))); } }, + { WWMathKey::Log10f_2_7f, [] { return toBitsString(WWMath::Log10f(runtimeValue(2.7f))); } }, + { WWMathKey::Log10f_187_66f, [] { return toBitsString(WWMath::Log10f(runtimeValue(187.66f))); } }, + + { WWMathKey::Pow_0_4_1_3, [] { return toBitsString(WWMath::Pow(runtimeValue(0.4), runtimeValue(1.3))); } }, + { WWMathKey::Pow_2_7_11_9, [] { return toBitsString(WWMath::Pow(runtimeValue(2.7), runtimeValue(11.9))); } }, + { WWMathKey::Pow_Minus3_5_2_0, [] { return toBitsString(WWMath::Pow(runtimeValue(-3.5), runtimeValue(2.0))); } }, + { WWMathKey::Powf_0_4f_1_3f, [] { return toBitsString(WWMath::Powf(runtimeValue(0.4f), runtimeValue(1.3f))); } }, + { WWMathKey::Powf_2_7f_11_9f, [] { return toBitsString(WWMath::Powf(runtimeValue(2.7f), runtimeValue(11.9f))); } }, + { WWMathKey::Powf_Minus3_5f_2_0f, [] { return toBitsString(WWMath::Powf(runtimeValue(-3.5f), runtimeValue(2.0f))); } }, + + { WWMathKey::Sqrt_0_5f, [] { return toBitsString(WWMath::Sqrt(runtimeValue(0.5f))); } }, + { WWMathKey::Sqrt_2_7f, [] { return toBitsString(WWMath::Sqrt(runtimeValue(2.7f))); } }, + { WWMathKey::Sqrt_187_66f, [] { return toBitsString(WWMath::Sqrt(runtimeValue(187.66f))); } }, + { WWMathKey::Sqrt_0_5, [] { return toBitsString(WWMath::Sqrt(runtimeValue(0.5))); } }, + { WWMathKey::Sqrt_2_7, [] { return toBitsString(WWMath::Sqrt(runtimeValue(2.7))); } }, + { WWMathKey::Sqrt_187_66, [] { return toBitsString(WWMath::Sqrt(runtimeValue(187.66))); } }, + { WWMathKey::Sqrtf_0_5f, [] { return toBitsString(WWMath::Sqrtf(runtimeValue(0.5f))); } }, + { WWMathKey::Sqrtf_2_7f, [] { return toBitsString(WWMath::Sqrtf(runtimeValue(2.7f))); } }, + { WWMathKey::Sqrtf_187_66f, [] { return toBitsString(WWMath::Sqrtf(runtimeValue(187.66f))); } }, + { WWMathKey::Inv_Sqrt_Legacy_0_5f, [] { return toBitsString(WWMath::Inv_Sqrt_Legacy(runtimeValue(0.5f))); } }, + { WWMathKey::Inv_Sqrt_Legacy_2_7f, [] { return toBitsString(WWMath::Inv_Sqrt_Legacy(runtimeValue(2.7f))); } }, + { WWMathKey::Inv_Sqrt_Legacy_187_66f, [] { return toBitsString(WWMath::Inv_Sqrt_Legacy(runtimeValue(187.66f))); } }, + + { WWMathKey::Fabs_Minus0_5f, [] { return toBitsString(WWMath::Fabs(runtimeValue(-0.5f))); } }, + { WWMathKey::Fabs_2_7f, [] { return toBitsString(WWMath::Fabs(runtimeValue(2.7f))); } }, + { WWMathKey::Fabs_100_5f, [] { return toBitsString(WWMath::Fabs(runtimeValue(100.5f))); } }, + { WWMathKey::Fabs_Minus0_5, [] { return toBitsString(WWMath::Fabs(runtimeValue(-0.5))); } }, + { WWMathKey::Fabs_2_7, [] { return toBitsString(WWMath::Fabs(runtimeValue(2.7))); } }, + { WWMathKey::Fabs_100_5, [] { return toBitsString(WWMath::Fabs(runtimeValue(100.5))); } }, + { WWMathKey::Fabsf_Minus0_5f, [] { return toBitsString(WWMath::Fabsf(runtimeValue(-0.5f))); } }, + { WWMathKey::Fabsf_2_7f, [] { return toBitsString(WWMath::Fabsf(runtimeValue(2.7f))); } }, + { WWMathKey::Fabsf_100_5f, [] { return toBitsString(WWMath::Fabsf(runtimeValue(100.5f))); } }, + { WWMathKey::Fabsf_Legacy_Minus0_5f, [] { return toBitsString(WWMath::Fabsf_Legacy(runtimeValue(-0.5f))); } }, + { WWMathKey::Fabsf_Legacy_2_7f, [] { return toBitsString(WWMath::Fabsf_Legacy(runtimeValue(2.7f))); } }, + { WWMathKey::Fabsf_Legacy_100_5f, [] { return toBitsString(WWMath::Fabsf_Legacy(runtimeValue(100.5f))); } }, + + { WWMathKey::Ceil_Minus0_5, [] { return toBitsString(WWMath::Ceil(runtimeValue(-0.5))); } }, + { WWMathKey::Ceil_2_7, [] { return toBitsString(WWMath::Ceil(runtimeValue(2.7))); } }, + { WWMathKey::Ceil_100_5, [] { return toBitsString(WWMath::Ceil(runtimeValue(100.5))); } }, + { WWMathKey::Ceilf_Minus0_5f, [] { return toBitsString(WWMath::Ceilf(runtimeValue(-0.5f))); } }, + { WWMathKey::Ceilf_2_7f, [] { return toBitsString(WWMath::Ceilf(runtimeValue(2.7f))); } }, + { WWMathKey::Ceilf_100_5f, [] { return toBitsString(WWMath::Ceilf(runtimeValue(100.5f))); } }, + + { WWMathKey::Floor_Minus0_5, [] { return toBitsString(WWMath::Floor(runtimeValue(-0.5))); } }, + { WWMathKey::Floor_2_7, [] { return toBitsString(WWMath::Floor(runtimeValue(2.7))); } }, + { WWMathKey::Floor_100_5, [] { return toBitsString(WWMath::Floor(runtimeValue(100.5))); } }, + { WWMathKey::Floorf_Minus0_5f, [] { return toBitsString(WWMath::Floorf(runtimeValue(-0.5f))); } }, + { WWMathKey::Floorf_2_7f, [] { return toBitsString(WWMath::Floorf(runtimeValue(2.7f))); } }, + { WWMathKey::Floorf_100_5f, [] { return toBitsString(WWMath::Floorf(runtimeValue(100.5f))); } }, + + { WWMathKey::Float_To_Long_Minus0_5f, [] { return toBitsString(WWMath::Float_To_Long(runtimeValue(-0.5f))); } }, + { WWMathKey::Float_To_Long_2_7f, [] { return toBitsString(WWMath::Float_To_Long(runtimeValue(2.7f))); } }, + { WWMathKey::Float_To_Long_100_5f, [] { return toBitsString(WWMath::Float_To_Long(runtimeValue(100.5f))); } }, + { WWMathKey::Float_To_Long_Minus0_5, [] { return toBitsString(WWMath::Float_To_Long(runtimeValue(-0.5))); } }, + { WWMathKey::Float_To_Long_2_7, [] { return toBitsString(WWMath::Float_To_Long(runtimeValue(2.7))); } }, + { WWMathKey::Float_To_Long_100_5, [] { return toBitsString(WWMath::Float_To_Long(runtimeValue(100.5))); } }, + + { WWMathKey::Div_Safe_1_0f_3_0f, [] { return toBitsString(WWMath::Div_Safe(runtimeValue(1.0f), runtimeValue(3.0f))); } }, + { WWMathKey::Div_Safe_1_0f_0_0f, [] { return toBitsString(WWMath::Div_Safe(runtimeValue(1.0f), runtimeValue(0.0f))); } }, + { WWMathKey::Div_Safe_1_0_3_0, [] { return toBitsString(WWMath::Div_Safe(runtimeValue(1.0), runtimeValue(3.0))); } }, + { WWMathKey::Div_Safe_1_0_0_0, [] { return toBitsString(WWMath::Div_Safe(runtimeValue(1.0), runtimeValue(0.0))); } }, +}; + +static_assert(hasEveryKeyInOrder(wwmathCalls), "wwmathCalls must have one row per WWMathKey, in WWMathKey order"); diff --git a/Tests/Google/Core/Libraries/WWVegas/WWMath/WWMathDumps.h b/Tests/Google/Core/Libraries/WWVegas/WWMath/WWMathDumps.h new file mode 100644 index 00000000000..f306ce4e1d2 --- /dev/null +++ b/Tests/Google/Core/Libraries/WWVegas/WWMath/WWMathDumps.h @@ -0,0 +1,214 @@ +/* +** Command & Conquer Generals Zero Hour(tm) +** Copyright 2026 TheSuperHackers +** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +*/ + +#pragma once + +#include + +#include "WWMathKeys.h" +#include "WWMathTestCase.h" + +typedef std::array WWMathDump; + +struct WWMathDumpEntry +{ + WWMathKey key; + WWMathDump dump; +}; + +static constexpr WWMathDumpEntry wwmathDumps[] = { + // DETERMINISTIC RETAIL_COMPATIBLE + { WWMathKey::Sin_0_5f, { "3EF57744", "3EF57744" } }, + { WWMathKey::Sin_2_7f, { "3EDAD188", "3EDAD188" } }, + { WWMathKey::Sin_187_66f, { "BF3DDE0A", "BF3DDE0A" } }, + { WWMathKey::Sin_0_5, { "3FDEAEE8744B05F0", "3FDEAEE8744B05F0" } }, + { WWMathKey::Sin_2_7, { "3FDB5A312424A70C", "3FDB5A312424A70C" } }, + { WWMathKey::Sin_187_66, { "BFE7BBC6596262AE", "BFE7BBC6596262AE" } }, + { WWMathKey::Sinf_0_5f, { "3EF57744", "3EF57744" } }, + { WWMathKey::Sinf_2_7f, { "3EDAD188", "3EDAD188" } }, + { WWMathKey::Sinf_187_66f, { "BF3DDE0A", "BF3DDE0A" } }, + { WWMathKey::Sinf_Legacy_0_5f, { "3EF57744", "3EF57744" } }, + { WWMathKey::Sinf_Legacy_2_7f, { "3EDAD188", "3EDAD188" } }, + { WWMathKey::Sinf_Legacy_187_66f, { "BF3DDE0A", "BF3DDE0A" } }, + + { WWMathKey::Cos_0_5f, { "3F60A940", "3F60A940" } }, + { WWMathKey::Cos_2_7f, { "BF677146", "BF677146" } }, + { WWMathKey::Cos_187_66f, { "3F2BB74E", "3F2BB74E" } }, + { WWMathKey::Cos_0_5, { "3FEC1528065B7D50", "3FEC1528065B7D50" } }, + { WWMathKey::Cos_2_7, { "BFECEE28B36603A6", "BFECEE28B36603A6" } }, + { WWMathKey::Cos_187_66, { "3FE576E4096F1DE4", "3FE576E4096F1DE4" } }, + { WWMathKey::Cosf_0_5f, { "3F60A940", "3F60A940" } }, + { WWMathKey::Cosf_2_7f, { "BF677146", "BF677146" } }, + { WWMathKey::Cosf_187_66f, { "3F2BB74E", "3F2BB74E" } }, + { WWMathKey::Cosf_Legacy_0_5f, { "3F60A940", "3F60A940" } }, + { WWMathKey::Cosf_Legacy_2_7f, { "BF677146", "BF677146" } }, + { WWMathKey::Cosf_Legacy_187_66f, { "3F2BB74E", "3F2BB74E" } }, + + { WWMathKey::Tan_0_5f, { "3F0BDA7A", "3F0BDA7B" } }, + { WWMathKey::Tan_2_7f, { "BEF20959", "BEF20959" } }, + { WWMathKey::Tan_187_66f, { "BF8D87C1", "BF8D87C1" } }, + { WWMathKey::Tan_0_5, { "3FE17B4F5BF3474A", "3FE17B4F5BF3474A" } }, + { WWMathKey::Tan_2_7, { "BFDE412B62BA7143", "BFDE412B62BA7143" } }, + { WWMathKey::Tan_187_66, { "BFF1B1009E8D90B0", "BFF1B1009E8D90B0" } }, + { WWMathKey::Tanf_0_5f, { "3F0BDA7A", "3F0BDA7B" } }, + { WWMathKey::Tanf_2_7f, { "BEF20959", "BEF20959" } }, + { WWMathKey::Tanf_187_66f, { "BF8D87C1", "BF8D87C1" } }, + + { WWMathKey::Asin_Minus0_5f, { "BF060A94", "BF060A92" } }, + { WWMathKey::Asin_0_25f, { "3E815F4E", "3E815F4E" } }, + { WWMathKey::Asin_0_9f, { "3F8F549C", "3F8F549B" } }, + { WWMathKey::Asin_Minus0_5, { "BFE0C152382D7366", "BFE0C152382D7366" } }, + { WWMathKey::Asin_0_25, { "3FD02BE9CE0B87CD", "3FD02BE9CE0B87CD" } }, + { WWMathKey::Asin_0_9, { "3FF1EA93705FA172", "3FF1EA93705FA172" } }, + { WWMathKey::Asinf_Minus0_5f, { "BF060A94", "BF060A92" } }, + { WWMathKey::Asinf_0_25f, { "3E815F4E", "3E815F4E" } }, + { WWMathKey::Asinf_0_9f, { "3F8F549C", "3F8F549B" } }, + + { WWMathKey::Acos_Minus0_5f, { "40060A92", "40060A92" } }, + { WWMathKey::Acos_0_25f, { "3FA8B807", "3FA8B807" } }, + { WWMathKey::Acos_0_9f, { "3EE6ECFE", "3EE6ECFE" } }, + { WWMathKey::Acos_Minus0_5, { "4000C152382D7366", "4000C152382D7366" } }, + { WWMathKey::Acos_0_25, { "3FF51700E0C14B25", "3FF51700E0C14B25" } }, + { WWMathKey::Acos_0_9, { "3FDCDD9F8F922E98", "3FDCDD9F8F922E98" } }, + { WWMathKey::Acosf_Minus0_5f, { "40060A92", "40060A92" } }, + { WWMathKey::Acosf_0_25f, { "3FA8B807", "3FA8B807" } }, + { WWMathKey::Acosf_0_9f, { "3EE6ECFE", "3EE6ECFE" } }, + + { WWMathKey::Atan_0_5f, { "3EED6338", "3EED6338" } }, + { WWMathKey::Atan_2_7f, { "3F9BA8DC", "3F9BA8DC" } }, + { WWMathKey::Atan_187_66f, { "3FC8613E", "3FC8613E" } }, + { WWMathKey::Atan_0_5, { "3FDDAC6700000000", "3FDDAC670561BB4F" } }, + { WWMathKey::Atan_2_7, { "3FF3751B80000000", "3FF3751B7ED2AEC1" } }, + { WWMathKey::Atan_187_66, { "3FF90C27C0000000", "3FF90C27BEADA1E0" } }, + { WWMathKey::Atanf_0_5f, { "3EED6338", "3EED6338" } }, + { WWMathKey::Atanf_2_7f, { "3F9BA8DC", "3F9BA8DC" } }, + { WWMathKey::Atanf_187_66f, { "3FC8613E", "3FC8613E" } }, + + { WWMathKey::Atan2_0_4f_1_3f, { "3E98D4DA", "3E98D4DB" } }, + { WWMathKey::Atan2_2_7f_11_9f, { "3E6477D5", "3E6477D5" } }, + { WWMathKey::Atan2_Minus3_5f_2_0f, { "BF869C79", "BF869C79" } }, + { WWMathKey::Atan2_0_4_1_3, { "3FD31A9B40000000", "3FD31A9B43436DE1" } }, + { WWMathKey::Atan2_2_7_11_9, { "3FCC8EFAA0000000", "3FCC8EFA8684064B" } }, + { WWMathKey::Atan2_Minus3_5_2_0, { "BFF0D38F20000000", "BFF0D38F2C5BA09F" } }, + { WWMathKey::Atan2f_0_4f_1_3f, { "3E98D4DA", "3E98D4DB" } }, + { WWMathKey::Atan2f_2_7f_11_9f, { "3E6477D5", "3E6477D5" } }, + { WWMathKey::Atan2f_Minus3_5f_2_0f, { "BF869C79", "BF869C79" } }, + + { WWMathKey::Sinh_0_5, { "3FE0ACD00FE63B97", "3FE0ACD00FE63B97" } }, + { WWMathKey::Sinh_Minus0_5, { "BFE0ACD00FE63B97", "BFE0ACD00FE63B97" } }, + { WWMathKey::Sinh_2_7, { "401DA0036F88823C", "401DA0036F88823C" } }, + { WWMathKey::Sinhf_0_5f, { "3F056680", "3F056680" } }, + { WWMathKey::Sinhf_Minus0_5f, { "BF056680", "BF056680" } }, + { WWMathKey::Sinhf_2_7f, { "40ED001C", "40ED001C" } }, + + { WWMathKey::Cosh_0_5, { "3FF20AC1862AE8D0", "3FF20AC1862AE8D0" } }, + { WWMathKey::Cosh_Minus0_5, { "3FF20AC1862AE8D0", "3FF20AC1862AE8D0" } }, + { WWMathKey::Cosh_2_7, { "401DE4D4F525D240", "401DE4D4F525D23F" } }, + { WWMathKey::Coshf_0_5f, { "3F90560C", "3F90560C" } }, + { WWMathKey::Coshf_Minus0_5f, { "3F90560C", "3F90560C" } }, + { WWMathKey::Coshf_2_7f, { "40EF26A8", "40EF26A8" } }, + + { WWMathKey::Tanh_0_5, { "3FDD9353D7568AF3", "3FDD9353D7568AF3" } }, + { WWMathKey::Tanh_Minus0_5, { "BFDD9353D7568AF3", "BFDD9353D7568AF3" } }, + { WWMathKey::Tanh_2_7, { "3FEFB655437478D5", "3FEFB655437478D5" } }, + { WWMathKey::Tanhf_0_5f, { "3EEC9A9F", "3EEC9A9F" } }, + { WWMathKey::Tanhf_Minus0_5f, { "BEEC9A9F", "BEEC9A9F" } }, + { WWMathKey::Tanhf_2_7f, { "3F7DB2AA", "3F7DB2AA" } }, + + { WWMathKey::Exp_0_5, { "3FFA61298E1E069C", "3FFA61298E1E069C" } }, + { WWMathKey::Exp_Minus0_5, { "3FE368B2FC6F960A", "3FE368B2FC6F960A" } }, + { WWMathKey::Exp_2_7, { "402DC26C32572A3E", "402DC26C32572A3E" } }, + { WWMathKey::Expf_0_5f, { "3FD3094C", "3FD3094C" } }, + { WWMathKey::Expf_Minus0_5f, { "3F1B4598", "3F1B4598" } }, + { WWMathKey::Expf_2_7f, { "416E1362", "416E1362" } }, + + { WWMathKey::Log_0_5, { "BFE62E42FEFA39EF", "BFE62E42FEFA39EF" } }, + { WWMathKey::Log_2_7, { "3FEFC8B7F138BDEA", "3FEFC8B7F138BDEA" } }, + { WWMathKey::Log_187_66, { "4014F043528DBB65", "4014F043528DBB65" } }, + { WWMathKey::Logf_0_5f, { "BF317218", "BF317218" } }, + { WWMathKey::Logf_2_7f, { "3F7E45C0", "3F7E45C0" } }, + { WWMathKey::Logf_187_66f, { "40A7821B", "40A7821B" } }, + + { WWMathKey::Log10_0_5, { "BFD34413509F79FF", "BFD34413509F79FF" } }, + { WWMathKey::Log10_2_7, { "3FDB9B76C2EF81F8", "3FDB9B76C2EF81F8" } }, + { WWMathKey::Log10_187_66, { "40022FDD82152DEA", "40022FDD82152DEA" } }, + { WWMathKey::Log10f_0_5f, { "BE9A209B", "BE9A209B" } }, + { WWMathKey::Log10f_2_7f, { "3EDCDBB6", "3EDCDBB6" } }, + { WWMathKey::Log10f_187_66f, { "40117EEC", "40117EEC" } }, + + { WWMathKey::Pow_0_4_1_3, { "3FD3727E60000000", "3FD3727E49ADFAD4" } }, + { WWMathKey::Pow_2_7_11_9, { "410096F740000000", "410096F75FA58808" } }, + { WWMathKey::Pow_Minus3_5_2_0, { "4028800000000000", "4028800000000000" } }, + { WWMathKey::Powf_0_4f_1_3f, { "3E9B93F3", "3E9B93F3" } }, + { WWMathKey::Powf_2_7f_11_9f, { "4804B7BA", "4804B7BA" } }, + { WWMathKey::Powf_Minus3_5f_2_0f, { "41440000", "41440000" } }, + + { WWMathKey::Sqrt_0_5f, { "3F3504F3", "3F3504F3" } }, + { WWMathKey::Sqrt_2_7f, { "3FD25352", "3FD25352" } }, + { WWMathKey::Sqrt_187_66f, { "415B2EB7", "415B2EB7" } }, + { WWMathKey::Sqrt_0_5, { "3FE6A09E667F3BCD", "3FE6A09E667F3BCD" } }, + { WWMathKey::Sqrt_2_7, { "3FFA4A6A2F74C6AC", "3FFA4A6A2F74C6AC" } }, + { WWMathKey::Sqrt_187_66, { "402B65D6E280ACC1", "402B65D6E280ACC1" } }, + { WWMathKey::Sqrtf_0_5f, { "3F3504F3", "3F3504F3" } }, + { WWMathKey::Sqrtf_2_7f, { "3FD25352", "3FD25352" } }, + { WWMathKey::Sqrtf_187_66f, { "415B2EB7", "415B2EB7" } }, + { WWMathKey::Inv_Sqrt_Legacy_0_5f, { "3FB504F3", "3FB504F3" } }, + { WWMathKey::Inv_Sqrt_Legacy_2_7f, { "3F1BCBF0", "3F1BCBF0" } }, + { WWMathKey::Inv_Sqrt_Legacy_187_66f, { "3D958042", "3D958041" } }, + + { WWMathKey::Fabs_Minus0_5f, { "3F000000", "3F000000" } }, + { WWMathKey::Fabs_2_7f, { "402CCCCD", "402CCCCD" } }, + { WWMathKey::Fabs_100_5f, { "42C90000", "42C90000" } }, + { WWMathKey::Fabs_Minus0_5, { "3FE0000000000000", "3FE0000000000000" } }, + { WWMathKey::Fabs_2_7, { "400599999999999A", "400599999999999A" } }, + { WWMathKey::Fabs_100_5, { "4059200000000000", "4059200000000000" } }, + { WWMathKey::Fabsf_Minus0_5f, { "3F000000", "3F000000" } }, + { WWMathKey::Fabsf_2_7f, { "402CCCCD", "402CCCCD" } }, + { WWMathKey::Fabsf_100_5f, { "42C90000", "42C90000" } }, + { WWMathKey::Fabsf_Legacy_Minus0_5f, { "3F000000", "3F000000" } }, + { WWMathKey::Fabsf_Legacy_2_7f, { "402CCCCD", "402CCCCD" } }, + { WWMathKey::Fabsf_Legacy_100_5f, { "42C90000", "42C90000" } }, + + { WWMathKey::Ceil_Minus0_5, { "8000000000000000", "8000000000000000" } }, + { WWMathKey::Ceil_2_7, { "4008000000000000", "4008000000000000" } }, + { WWMathKey::Ceil_100_5, { "4059400000000000", "4059400000000000" } }, + { WWMathKey::Ceilf_Minus0_5f, { "80000000", "80000000" } }, + { WWMathKey::Ceilf_2_7f, { "40400000", "40400000" } }, + { WWMathKey::Ceilf_100_5f, { "42CA0000", "42CA0000" } }, + + { WWMathKey::Floor_Minus0_5, { "BFF0000000000000", "BFF0000000000000" } }, + { WWMathKey::Floor_2_7, { "4000000000000000", "4000000000000000" } }, + { WWMathKey::Floor_100_5, { "4059000000000000", "4059000000000000" } }, + { WWMathKey::Floorf_Minus0_5f, { "BF800000", "BF800000" } }, + { WWMathKey::Floorf_2_7f, { "40000000", "40000000" } }, + { WWMathKey::Floorf_100_5f, { "42C80000", "42C80000" } }, + + { WWMathKey::Float_To_Long_Minus0_5f, { "0", "0" } }, + { WWMathKey::Float_To_Long_2_7f, { "3", "3" } }, + { WWMathKey::Float_To_Long_100_5f, { "100", "100" } }, + { WWMathKey::Float_To_Long_Minus0_5, { "0", "0" } }, + { WWMathKey::Float_To_Long_2_7, { "3", "3" } }, + { WWMathKey::Float_To_Long_100_5, { "100", "100" } }, + + { WWMathKey::Div_Safe_1_0f_3_0f, { "3EAAAAAB", "3EAAAAAB" } }, + { WWMathKey::Div_Safe_1_0f_0_0f, { "461C4000", "7F800000" } }, + { WWMathKey::Div_Safe_1_0_3_0, { "3FD5555555555555", "3FD5555555555555" } }, + { WWMathKey::Div_Safe_1_0_0_0, { "40C3880008472404", "7FF0000000000000" } }, +}; + +static_assert(hasEveryKeyInOrder(wwmathDumps), "wwmathDumps must have one row per WWMathKey, in WWMathKey order"); diff --git a/Tests/Google/Core/Libraries/WWVegas/WWMath/WWMathKeys.h b/Tests/Google/Core/Libraries/WWVegas/WWMath/WWMathKeys.h new file mode 100644 index 00000000000..21c0b5ae732 --- /dev/null +++ b/Tests/Google/Core/Libraries/WWVegas/WWMath/WWMathKeys.h @@ -0,0 +1,205 @@ +/* +** Command & Conquer Generals Zero Hour(tm) +** Copyright 2026 TheSuperHackers +** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +*/ + +#pragma once + +#include + +// One list of keys gives both the WWMathKey enum and the test name of each key. +#define WWMATH_KEYS(KEY) \ + KEY(Sin_0_5f) \ + KEY(Sin_2_7f) \ + KEY(Sin_187_66f) \ + KEY(Sin_0_5) \ + KEY(Sin_2_7) \ + KEY(Sin_187_66) \ + KEY(Sinf_0_5f) \ + KEY(Sinf_2_7f) \ + KEY(Sinf_187_66f) \ + KEY(Sinf_Legacy_0_5f) \ + KEY(Sinf_Legacy_2_7f) \ + KEY(Sinf_Legacy_187_66f) \ + KEY(Cos_0_5f) \ + KEY(Cos_2_7f) \ + KEY(Cos_187_66f) \ + KEY(Cos_0_5) \ + KEY(Cos_2_7) \ + KEY(Cos_187_66) \ + KEY(Cosf_0_5f) \ + KEY(Cosf_2_7f) \ + KEY(Cosf_187_66f) \ + KEY(Cosf_Legacy_0_5f) \ + KEY(Cosf_Legacy_2_7f) \ + KEY(Cosf_Legacy_187_66f) \ + KEY(Tan_0_5f) \ + KEY(Tan_2_7f) \ + KEY(Tan_187_66f) \ + KEY(Tan_0_5) \ + KEY(Tan_2_7) \ + KEY(Tan_187_66) \ + KEY(Tanf_0_5f) \ + KEY(Tanf_2_7f) \ + KEY(Tanf_187_66f) \ + KEY(Asin_Minus0_5f) \ + KEY(Asin_0_25f) \ + KEY(Asin_0_9f) \ + KEY(Asin_Minus0_5) \ + KEY(Asin_0_25) \ + KEY(Asin_0_9) \ + KEY(Asinf_Minus0_5f) \ + KEY(Asinf_0_25f) \ + KEY(Asinf_0_9f) \ + KEY(Acos_Minus0_5f) \ + KEY(Acos_0_25f) \ + KEY(Acos_0_9f) \ + KEY(Acos_Minus0_5) \ + KEY(Acos_0_25) \ + KEY(Acos_0_9) \ + KEY(Acosf_Minus0_5f) \ + KEY(Acosf_0_25f) \ + KEY(Acosf_0_9f) \ + KEY(Atan_0_5f) \ + KEY(Atan_2_7f) \ + KEY(Atan_187_66f) \ + KEY(Atan_0_5) \ + KEY(Atan_2_7) \ + KEY(Atan_187_66) \ + KEY(Atanf_0_5f) \ + KEY(Atanf_2_7f) \ + KEY(Atanf_187_66f) \ + KEY(Atan2_0_4f_1_3f) \ + KEY(Atan2_2_7f_11_9f) \ + KEY(Atan2_Minus3_5f_2_0f) \ + KEY(Atan2_0_4_1_3) \ + KEY(Atan2_2_7_11_9) \ + KEY(Atan2_Minus3_5_2_0) \ + KEY(Atan2f_0_4f_1_3f) \ + KEY(Atan2f_2_7f_11_9f) \ + KEY(Atan2f_Minus3_5f_2_0f) \ + KEY(Sinh_0_5) \ + KEY(Sinh_Minus0_5) \ + KEY(Sinh_2_7) \ + KEY(Sinhf_0_5f) \ + KEY(Sinhf_Minus0_5f) \ + KEY(Sinhf_2_7f) \ + KEY(Cosh_0_5) \ + KEY(Cosh_Minus0_5) \ + KEY(Cosh_2_7) \ + KEY(Coshf_0_5f) \ + KEY(Coshf_Minus0_5f) \ + KEY(Coshf_2_7f) \ + KEY(Tanh_0_5) \ + KEY(Tanh_Minus0_5) \ + KEY(Tanh_2_7) \ + KEY(Tanhf_0_5f) \ + KEY(Tanhf_Minus0_5f) \ + KEY(Tanhf_2_7f) \ + KEY(Exp_0_5) \ + KEY(Exp_Minus0_5) \ + KEY(Exp_2_7) \ + KEY(Expf_0_5f) \ + KEY(Expf_Minus0_5f) \ + KEY(Expf_2_7f) \ + KEY(Log_0_5) \ + KEY(Log_2_7) \ + KEY(Log_187_66) \ + KEY(Logf_0_5f) \ + KEY(Logf_2_7f) \ + KEY(Logf_187_66f) \ + KEY(Log10_0_5) \ + KEY(Log10_2_7) \ + KEY(Log10_187_66) \ + KEY(Log10f_0_5f) \ + KEY(Log10f_2_7f) \ + KEY(Log10f_187_66f) \ + KEY(Pow_0_4_1_3) \ + KEY(Pow_2_7_11_9) \ + KEY(Pow_Minus3_5_2_0) \ + KEY(Powf_0_4f_1_3f) \ + KEY(Powf_2_7f_11_9f) \ + KEY(Powf_Minus3_5f_2_0f) \ + KEY(Sqrt_0_5f) \ + KEY(Sqrt_2_7f) \ + KEY(Sqrt_187_66f) \ + KEY(Sqrt_0_5) \ + KEY(Sqrt_2_7) \ + KEY(Sqrt_187_66) \ + KEY(Sqrtf_0_5f) \ + KEY(Sqrtf_2_7f) \ + KEY(Sqrtf_187_66f) \ + KEY(Inv_Sqrt_Legacy_0_5f) \ + KEY(Inv_Sqrt_Legacy_2_7f) \ + KEY(Inv_Sqrt_Legacy_187_66f) \ + KEY(Fabs_Minus0_5f) \ + KEY(Fabs_2_7f) \ + KEY(Fabs_100_5f) \ + KEY(Fabs_Minus0_5) \ + KEY(Fabs_2_7) \ + KEY(Fabs_100_5) \ + KEY(Fabsf_Minus0_5f) \ + KEY(Fabsf_2_7f) \ + KEY(Fabsf_100_5f) \ + KEY(Fabsf_Legacy_Minus0_5f) \ + KEY(Fabsf_Legacy_2_7f) \ + KEY(Fabsf_Legacy_100_5f) \ + KEY(Ceil_Minus0_5) \ + KEY(Ceil_2_7) \ + KEY(Ceil_100_5) \ + KEY(Ceilf_Minus0_5f) \ + KEY(Ceilf_2_7f) \ + KEY(Ceilf_100_5f) \ + KEY(Floor_Minus0_5) \ + KEY(Floor_2_7) \ + KEY(Floor_100_5) \ + KEY(Floorf_Minus0_5f) \ + KEY(Floorf_2_7f) \ + KEY(Floorf_100_5f) \ + KEY(Float_To_Long_Minus0_5f) \ + KEY(Float_To_Long_2_7f) \ + KEY(Float_To_Long_100_5f) \ + KEY(Float_To_Long_Minus0_5) \ + KEY(Float_To_Long_2_7) \ + KEY(Float_To_Long_100_5) \ + KEY(Div_Safe_1_0f_3_0f) \ + KEY(Div_Safe_1_0f_0_0f) \ + KEY(Div_Safe_1_0_3_0) \ + KEY(Div_Safe_1_0_0_0) + +#define WWMATH_KEY_ENUM_VALUE(key) key, +#define WWMATH_KEY_ENUM_ENTRY(key) WWMathKey::key, +#define WWMATH_KEY_NAME(key) #key, + +enum class WWMathKey +{ + WWMATH_KEYS(WWMATH_KEY_ENUM_VALUE) + Count +}; + +static constexpr WWMathKey wwmathKeys[] = { WWMATH_KEYS(WWMATH_KEY_ENUM_ENTRY) }; +static const char *const wwmathKeyNames[] = { WWMATH_KEYS(WWMATH_KEY_NAME) }; + +#undef WWMATH_KEY_ENUM_VALUE +#undef WWMATH_KEY_ENUM_ENTRY +#undef WWMATH_KEY_NAME + +constexpr size_t toIndex(WWMathKey key) +{ + return static_cast(key); +} + +constexpr size_t WWMATH_KEY_COUNT = toIndex(WWMathKey::Count); diff --git a/Tests/Google/Core/Libraries/WWVegas/WWMath/WWMathTest.cpp b/Tests/Google/Core/Libraries/WWVegas/WWMath/WWMathTest.cpp new file mode 100644 index 00000000000..2752502f095 --- /dev/null +++ b/Tests/Google/Core/Libraries/WWVegas/WWMath/WWMathTest.cpp @@ -0,0 +1,58 @@ +/* +** Command & Conquer Generals Zero Hour(tm) +** Copyright 2026 TheSuperHackers +** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +*/ + +#include +#include + +#include "WWMathCalls.h" +#include "WWMathDumps.h" +#include "WWMathKeys.h" +#include "WWMathTestCase.h" + +// Each WWMathKey is one test. The test runs the call of the key from wwmathCalls +// and compares its bits with the dump of the key from wwmathDumps, in the column +// of this build. Both tables hold the row of a key at the index of the key. + +static std::string testNameOf(const ::testing::TestParamInfo &info) +{ + return wwmathKeyNames[toIndex(info.param)]; +} + +class WWMathBits : public ::testing::TestWithParam +{ +protected: + void SetUp() override + { + if (wwmathColumn == WWMATH_COLUMN_NONE) + { + GTEST_SKIP() << "No WWMath dump column for this build configuration"; + } + } +}; + +TEST_P(WWMathBits, MatchesDump) +{ + const size_t index = toIndex(GetParam()); + const std::string computed = wwmathCalls[index].call(); + const char *dump = wwmathDumps[index].dump[wwmathColumn]; + ASSERT_NE(dump, nullptr) << "No dump in this column, computed " << computed; + + EXPECT_EQ(computed, dump); +} + +INSTANTIATE_TEST_SUITE_P(WWMath, WWMathBits, ::testing::ValuesIn(wwmathKeys), testNameOf); diff --git a/Tests/Google/Core/Libraries/WWVegas/WWMath/WWMathTestCase.h b/Tests/Google/Core/Libraries/WWVegas/WWMath/WWMathTestCase.h new file mode 100644 index 00000000000..79a01de4eee --- /dev/null +++ b/Tests/Google/Core/Libraries/WWVegas/WWMath/WWMathTestCase.h @@ -0,0 +1,96 @@ +/* +** Command & Conquer Generals Zero Hour(tm) +** Copyright 2026 TheSuperHackers +** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +*/ + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include "WWMath/wwmath.h" + +#include "WWMathKeys.h" + +// The game simulation must compute the same bits from one build to the next. +// Every call has a dump of its bits, with one column per build configuration. +// VC6 does not build the tests, so the retail-compatible branch is checked on win32. +enum WWMathColumn +{ + WWMATH_COLUMN_NONE = -1, + WWMATH_COLUMN_DETERMINISTIC, + WWMATH_COLUMN_RETAIL_COMPATIBLE, + WWMATH_COLUMN_COUNT +}; + +#if USE_DETERMINISTIC_MATH +static const WWMathColumn wwmathColumn = WWMATH_COLUMN_DETERMINISTIC; +#elif defined(_MSC_VER) && defined(_M_IX86) +static const WWMathColumn wwmathColumn = WWMATH_COLUMN_RETAIL_COMPATIBLE; +#else +static const WWMathColumn wwmathColumn = WWMATH_COLUMN_NONE; +#endif + +inline void PrintTo(WWMathKey key, std::ostream *stream) +{ + *stream << wwmathKeyNames[toIndex(key)]; +} + +// A table must have one row per WWMathKey, in WWMathKey order, so the row of a key is at its index. +template +constexpr bool hasEveryKeyInOrder(const Entry (&table)[Count]) +{ + if (Count != WWMATH_KEY_COUNT) + { + return false; + } + + for (size_t index = 0; index < Count; ++index) + { + if (toIndex(table[index].key) != index) + { + return false; + } + } + + return true; +} + +template +inline T runtimeValue(T value) +{ + volatile T runtime = value; + return runtime; +} + +inline std::string toBitsString(float value) +{ + return std::format("{:08X}", std::bit_cast(value)); +} + +inline std::string toBitsString(double value) +{ + return std::format("{:016X}", std::bit_cast(value)); +} + +inline std::string toBitsString(long value) +{ + return std::to_string(value); +}