From affae3eee93528bd7ddfb31810fc27b6916b1d87 Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Wed, 19 Aug 2026 19:22:06 +0300 Subject: [PATCH 01/15] build(cmake): Add gamemath library and deterministic math build options Introduces the gamemath.cmake module and wires HAS_GAMEMATH / USE_DETERMINISTIC_MATH through the compiler configuration. --- CMakeLists.txt | 3 +++ Core/CMakeLists.txt | 1 + cmake/compilers.cmake | 3 +++ cmake/gamemath.cmake | 16 ++++++++++++++++ 4 files changed, 23 insertions(+) create mode 100644 cmake/gamemath.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 39062e3fbe6..7014ac3379f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,9 @@ endif() include(cmake/config.cmake) include(cmake/gamespy.cmake) +if (NOT IS_VS6_BUILD) + include(cmake/gamemath.cmake) +endif() include(cmake/lzhl.cmake) include(cmake/stb.cmake) diff --git a/Core/CMakeLists.txt b/Core/CMakeLists.txt index 110ff1152d0..50d1863b56c 100644 --- a/Core/CMakeLists.txt +++ b/Core/CMakeLists.txt @@ -12,6 +12,7 @@ target_include_directories(corei_libraries_source_wwvegas INTERFACE "Libraries/S target_include_directories(corei_main INTERFACE "Main") target_sources(corei_libraries_include PRIVATE + Libraries/Include/Lib/BaseDefines.h Libraries/Include/Lib/BaseType.h Libraries/Include/Lib/BaseTypeCore.h Libraries/Include/Lib/trig.h diff --git a/cmake/compilers.cmake b/cmake/compilers.cmake index c5c4d5118c2..cd047333108 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..57dfaf4adfc --- /dev/null +++ b/cmake/gamemath.cmake @@ -0,0 +1,16 @@ +# FORCE is required to guarantee cross-platform bit-exact determinism. +# Intrinsics would use platform-specific SIMD, breaking CRC parity between architectures. +set(GM_ENABLE_INTRINSICS OFF CACHE BOOL "Disable intrinsics for cross-arch determinism" FORCE) +set(GM_ENABLE_TESTS OFF CACHE BOOL "Disable GameMath tests" FORCE) + +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 8b068231d698d6a397e24ca833597746bf331449 Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Wed, 19 Aug 2026 19:22:06 +0300 Subject: [PATCH 02/15] feat(basedefines): Add RETAIL_COMPATIBLE_CRC and USE_DETERMINISTIC_MATH switches 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. --- Core/Libraries/Include/Lib/BaseDefines.h | 37 +++++++++++++++++++ Core/Libraries/Include/Lib/BaseType.h | 26 +++++++++---- Core/Libraries/Include/Lib/trig.h | 2 + .../Source/WWVegas/WWLib/WWDefines.h | 2 + Core/Libraries/Source/WWVegas/WWLib/visualc.h | 17 --------- 5 files changed, 59 insertions(+), 25 deletions(-) create mode 100644 Core/Libraries/Include/Lib/BaseDefines.h diff --git a/Core/Libraries/Include/Lib/BaseDefines.h b/Core/Libraries/Include/Lib/BaseDefines.h new file mode 100644 index 00000000000..662009d86e8 --- /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 // Cannot actually use deterministic math :( +#endif diff --git a/Core/Libraries/Include/Lib/BaseType.h b/Core/Libraries/Include/Lib/BaseType.h index 8b5e760aff4..2b6e5507219 100644 --- a/Core/Libraries/Include/Lib/BaseType.h +++ b/Core/Libraries/Include/Lib/BaseType.h @@ -29,8 +29,9 @@ #pragma once -#include "Lib/BaseTypeCore.h" -#include "Lib/trig.h" +#include "BaseDefines.h" +#include "BaseTypeCore.h" +#include "trig.h" //----------------------------------------------------------------------------- typedef wchar_t WideChar; ///< multi-byte character representations @@ -224,7 +225,7 @@ __forceinline float fast_float_ceil(float f) #define INT_TO_REAL(x) ((Real)(x)) // 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 @@ -283,7 +284,7 @@ struct Coord2D return x == value && y == value; } - Real length() const { return (Real)sqrt( x*x + y*y ); } + Real length() const { return Sqrt( x*x + y*y ); } Real lengthSqr() const { return x*x + y*y; } void normalize() @@ -355,7 +356,7 @@ inline Real Coord2D::toAngle() const vector.x = x; vector.y = y; - Real dist = (Real)sqrt(vector.x * vector.x + vector.y * vector.y); + Real dist = Sqrt(vector.x * vector.x + vector.y * vector.y); // normalize if (dist == 0.0f) @@ -422,7 +423,7 @@ struct ICoord2D return x == value && y == value; } - Int length() const { return (Int)sqrt( (double)(x*x + y*y) ); } + Int length() const { return (Int)Sqrt( (double)(x*x + y*y) ); } Int lengthSqr() const { return x*x + y*y; } void add( const ICoord2D &a ) @@ -519,7 +520,16 @@ struct Coord3D { Real x, y, z; - Real length() const { return (Real)sqrt( x*x + y*y + z*z ); } + Real length() const + { +#if RETAIL_COMPATIBLE_CRC + // Must not touch this function because it affects its inline-ability + // and therefore changes the logic at an unknown call site that relies on it. It is a bug. + return (Real)sqrt( x*x + y*y + z*z ); +#else + return Sqrt( x*x + y*y + z*z ); +#endif + } Real lengthSqr() const { return ( x*x + y*y + z*z ); } void normalize() @@ -631,7 +641,7 @@ struct ICoord3D { Int x, y, z; - Int length() const { return (Int)sqrt( (double)(x*x + y*y + z*z) ); } + Int length() const { return (Int)Sqrt( (double)(x*x + y*y + z*z) ); } Int lengthSqr() const { return x*x + y*y + z*z; } void zero() diff --git a/Core/Libraries/Include/Lib/trig.h b/Core/Libraries/Include/Lib/trig.h index d6f3fa22cd8..27fa8cb8391 100644 --- a/Core/Libraries/Include/Lib/trig.h +++ b/Core/Libraries/Include/Lib/trig.h @@ -28,3 +28,5 @@ Real Cos(Real); Real Tan(Real); Real ACos(Real); Real ASin(Real x); +Real Sqrt(Real x); +double Sqrt(double 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/Core/Libraries/Source/WWVegas/WWLib/visualc.h b/Core/Libraries/Source/WWVegas/WWLib/visualc.h index a400314d917..31639b9e623 100644 --- a/Core/Libraries/Source/WWVegas/WWLib/visualc.h +++ b/Core/Libraries/Source/WWVegas/WWLib/visualc.h @@ -103,22 +103,5 @@ #pragma warning(disable : 4711) - -#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 38b22e440dde949143b3260227948941cd01be91 Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Wed, 19 Aug 2026 19:22:06 +0300 Subject: [PATCH 03/15] feat(wwmath): Add deterministic math entry points 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. --- .../Source/WWVegas/WWMath/wwmath.cpp | 9 + Core/Libraries/Source/WWVegas/WWMath/wwmath.h | 1162 +++++++++++------ 2 files changed, 789 insertions(+), 382 deletions(-) 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 8262f2732de..1266609f3c3 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/wwmath.h +++ b/Core/Libraries/Source/WWVegas/WWMath/wwmath.h @@ -40,18 +40,24 @@ #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_PI 3.141592654f -#define WWMATH_TWO_PI 6.283185308f +#define WWMATH_HALF_PI 1.570796327f +#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 +80,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]; @@ -87,105 +92,777 @@ 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: // 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 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 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 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); +// Prevent automatic compiler promotion of float arguments to double-precision variants. +// Single-precision math in GameMath (gm_*f) is guaranteed to be cross-platform bit-identical, +// whereas double-precision math (gm_*) can diverge by 1 ULP due to FPU precision differences (x87 vs NEON). +static WWINLINE float Sin(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); + +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(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); } +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 + +static WWINLINE float Div_Safe(float dividend, float divisor, float fallback = 0.0f); +static WWINLINE double Div_Safe(double dividend, double divisor, double fallback = 0.0); + +}; + +WWINLINE double WWMath::Pow(double x, double y) { - int value=*(int*)&val; - value&=0x7fffffff; - return *(float*)&value; +#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 } -static WWINLINE int Float_To_Int_Chop(const float& f); -static WWINLINE int Float_To_Int_Floor(const float& f); +WWINLINE float WWMath::Sqrt(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_sqrtf(x); +#else + return sqrtf(x); +#endif +} -#if defined(_MSC_VER) && defined(_M_IX86) -static WWINLINE float Cos(float val); -static WWINLINE float Sin(float val); -static WWINLINE float Sqrt(float val); -static WWINLINE float Inv_Sqrt(float a); // Some 30% faster inverse square root than regular C++ compiled, from Intel's math library -static WWINLINE long Float_To_Long(float f); +WWINLINE double WWMath::Sqrt(double x) +{ +#if USE_DETERMINISTIC_MATH + return gm_sqrt(x); #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 sqrt(x); +#endif +} + +WWINLINE float WWMath::Sqrtf(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_sqrtf(x); +#else + return sqrtf(x); #endif +} + +WWINLINE float WWMath::Inv_Sqrt_Legacy(float a) +{ +#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; + + __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 -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); + 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) -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); + 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 -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); + fstp retval + } -static float Random_Float(); + return retval; -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); +#else + return 1.0f / (float)sqrt((double)a); +#endif +} -static WWINLINE int Float_As_Int(const float f) { return *((int*)&f); } +WWINLINE double WWMath::Inv_Sqrt(double x) +{ + return 1.0 / Sqrt(x); +} -// 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); +WWINLINE float WWMath::Inv_Sqrtf(float x) +{ + return 1.0f / Sqrtf(x); +} -// 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::Fast_Acos(float val) +{ + // Near -1 and +1, the table becomes too inaccurate + if (Fabsf_Legacy(val) > 0.975f) { + return Acos(val); + } -static WWINLINE long Float_To_Long(double f); + val*=float(ARC_TABLE_SIZE/2); -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; } + int idx0=Float_To_Int_Floor(val); + int idx1=idx0+1; + float frac=val-(float)idx0; -static WWINLINE bool Is_Valid_Float(float x); -static WWINLINE bool Is_Valid_Double(double x); + idx0+=ARC_TABLE_SIZE/2; + idx1+=ARC_TABLE_SIZE/2; -static WWINLINE float Normalize_Angle(float angle); // Normalizes the angle to the range -PI..PI + // 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]; +} + +WWINLINE float WWMath::Fast_Asin(float val) +{ + // Near -1 and +1, the table becomes too inaccurate + if (Fabsf_Legacy(val) > 0.975f) { + return 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]; +} + +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) +{ +#if USE_DETERMINISTIC_MATH + return gm_acosf(x); +#else + return acosf(x); +#endif +} + +WWINLINE float WWMath::Asin(float x) +{ +#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) +{ +#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); +#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 double WWMath::Atan2(double x, double y) +{ +#if USE_DETERMINISTIC_MATH + return (double) gm_atan2f((float)x, (float)y); +#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) +{ + 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 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] + fcos + fstp [retval] + } + return retval; + +#else + return cosf(val); +#endif +} + +WWINLINE float WWMath::Sin(float val) +{ +#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] + fsin + fstp [retval] + } + return retval; + +#else + return sinf(val); +#endif +} + +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 double WWMath::Ceil(double x) +{ +#if USE_DETERMINISTIC_MATH + return gm_ceil(x); +#else + return ceil(x); +#endif +} + +WWINLINE float WWMath::Ceilf(float x) +{ +#if USE_DETERMINISTIC_MATH + return gm_ceilf(x); +#else + return ceilf(x); +#endif +} + +WWINLINE double WWMath::Floor(double x) +{ +#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::Sign(float val) +WWINLINE float WWMath::Logf(float x) { - if (val > 0.0f) { - return +1.0f; - } - if (val < 0.0f) { - return -1.0f; - } - return 0.0f; +#if USE_DETERMINISTIC_MATH + return gm_logf(x); +#else + return logf(x); +#endif } WWINLINE bool WWMath::Fast_Is_Float_Positive(const float & val) @@ -309,278 +986,43 @@ 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) { - long i; +#if USE_DETERMINISTIC_MATH + return gm_lrintf(f); +#elif 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) { -#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] 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); -} -#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); + return (long)f; #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) +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 @@ -590,7 +1032,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 @@ -606,69 +1048,25 @@ 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) +WWINLINE float WWMath::Normalize_Angle(float angle) { - 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; + return angle - (WWMATH_TWO_PI * Floor((angle + WWMATH_PI) / WWMATH_TWO_PI)); } -#else -WWINLINE float WWMath::Inv_Sqrt(float val) + +WWINLINE float WWMath::Div_Safe(float dividend, float divisor, float fallback) { - return 1.0f / (float)sqrt(val); -} +#if USE_DETERMINISTIC_MATH + return (divisor == 0.0f) ? fallback : dividend / divisor; +#else + return dividend / divisor; #endif +} -WWINLINE float WWMath::Normalize_Angle(float angle) +WWINLINE double WWMath::Div_Safe(double dividend, double divisor, double fallback) { - return angle - (WWMATH_TWO_PI * Floor((angle + WWMATH_PI) / WWMATH_TWO_PI)); +#if USE_DETERMINISTIC_MATH + return (divisor == 0.0) ? fallback : dividend / divisor; +#else + return dividend / divisor; +#endif } From 3d7e3fd8d5c19978482c69f549dc3d22892355a1 Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Wed, 19 Aug 2026 19:22:06 +0300 Subject: [PATCH 04/15] refactor(wwmath): Route WWMath call sites through the deterministic wrappers --- .../Source/WWVegas/WWMath/CMakeLists.txt | 6 + 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 | 20 +-- .../Source/WWVegas/WWMath/matrix3d.cpp | 18 +-- .../Source/WWVegas/WWMath/matrix3d.h | 42 +++--- .../Libraries/Source/WWVegas/WWMath/matrix4.h | 2 +- .../Libraries/Source/WWVegas/WWMath/obbox.cpp | 16 +-- Core/Libraries/Source/WWVegas/WWMath/obbox.h | 20 +-- Core/Libraries/Source/WWVegas/WWMath/quat.cpp | 44 +++--- Core/Libraries/Source/WWVegas/WWMath/quat.h | 8 +- Core/Libraries/Source/WWVegas/WWMath/sphere.h | 4 +- Core/Libraries/Source/WWVegas/WWMath/tri.cpp | 18 +-- .../Source/WWVegas/WWMath/v3_rnd.cpp | 2 +- .../Libraries/Source/WWVegas/WWMath/vector2.h | 16 +-- .../Libraries/Source/WWVegas/WWMath/vector3.h | 22 +-- .../Libraries/Source/WWVegas/WWMath/vector4.h | 4 +- .../Source/WWVegas/WWMath/vehiclecurve.cpp | 40 +++--- 27 files changed, 306 insertions(+), 300 deletions(-) diff --git a/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt b/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt index dca9eb68fef..4669b675165 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt +++ b/Core/Libraries/Source/WWVegas/WWMath/CMakeLists.txt @@ -91,5 +91,11 @@ target_link_libraries(core_wwmath PRIVATE core_wwsaveload ) +if (NOT IS_VS6_BUILD) + target_link_libraries(core_wwmath PUBLIC + gamemath + ) +endif() + # @todo Test its impact and see what to do with the legacy functions. #add_compile_definitions(core_wwmath PUBLIC ALLOW_TEMPORARIES) # Enables legacy math with "temporaries" diff --git a/Core/Libraries/Source/WWVegas/WWMath/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 5cf23f242b4..15d27779e84 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..379053fb5e9 100644 --- a/Core/Libraries/Source/WWVegas/WWMath/matrix3.h +++ b/Core/Libraries/Source/WWVegas/WWMath/matrix3.h @@ -361,12 +361,12 @@ 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) { - 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; } } @@ -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) @@ -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..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; @@ -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 e9e5c976183..55368684c66 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); } @@ -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])), @@ -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); @@ -1055,8 +1055,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); @@ -1093,8 +1093,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); @@ -1131,8 +1131,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); @@ -1274,8 +1274,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); @@ -1308,8 +1308,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); @@ -1342,8 +1342,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/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 d262891f412..31d6a47b1c3 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) { @@ -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/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/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/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..3db367dedb2 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); @@ -356,7 +356,7 @@ WWINLINE Vector2 Normalize(const Vector2 & vec) *========================================================================*/ WWINLINE float Vector2::Length() const { - return (float)WWMath::Sqrt(Length2()); + return WWMath::Sqrt(Length2()); } /************************************************************************** @@ -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..f558c340813 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; } @@ -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/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..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) { // @@ -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; From 03aa438b1fac27fb304f6a132cfc5fbe264fd017 Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Wed, 19 Aug 2026 19:22:06 +0300 Subject: [PATCH 05/15] refactor(ww3d2): Route Core WW3D2 math through WWMath --- .../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 +++++------ 13 files changed, 40 insertions(+), 40 deletions(-) diff --git a/Core/Libraries/Source/WWVegas/WW3D2/animatedsoundmgr.cpp b/Core/Libraries/Source/WWVegas/WW3D2/animatedsoundmgr.cpp index be3d790d3ba..1466cbfc981 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/animatedsoundmgr.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/animatedsoundmgr.cpp @@ -512,7 +512,7 @@ AnimatedSoundMgrClass::Trigger_Sound // // Don't trigger the sound if its skipped too far past... // - //if (WWMath::Fabs (new_frame - old_frame) < 3.0F) { + //if (WWMath::Fabsf (new_frame - old_frame) < 3.0F) { // // Stop the audio? diff --git a/Core/Libraries/Source/WWVegas/WW3D2/colorspace.h b/Core/Libraries/Source/WWVegas/WW3D2/colorspace.h index 4b366e6f895..082a30a5a86 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/colorspace.h +++ b/Core/Libraries/Source/WWVegas/WW3D2/colorspace.h @@ -95,7 +95,7 @@ inline void HSV_To_RGB(Vector3 &rgb, const Vector3 &hsv) if (h==360.0f) h=0.0f; h/=60.0f; - i=WWMath::Floor(h); + i=WWMath::Floorf(h); f=h-i; p=v*(1.0f-s); q=v*(1.0f-(s*f)); diff --git a/Core/Libraries/Source/WWVegas/WW3D2/coltest.cpp b/Core/Libraries/Source/WWVegas/WW3D2/coltest.cpp index 5639973d50b..71ff8c728fd 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/coltest.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/coltest.cpp @@ -71,7 +71,7 @@ AABoxCollisionTestClass::AABoxCollisionTestClass(const AABoxClass & aabox,const bool AABoxCollisionTestClass::Cull(const AABoxClass & box) { // const float MOVE_THRESHOLD = 2.0f; -// if (WWMath::Fabs(Move.X) + WWMath::Fabs(Move.Y) + WWMath::Fabs(Move.Z) > 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 fc64894f36b..4f705ce47cf 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/htree.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/htree.cpp @@ -866,7 +866,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 @@ -1204,8 +1204,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 9ee3d934f1a..ba4b2a03a07 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/ringobj.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/ringobj.cpp @@ -1538,8 +1538,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 9a1c2de806d..5a78a5f1273 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 b373dead1f7..48dc2b2f573 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/streak.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/streak.cpp @@ -362,7 +362,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 ae718524197..0d8de7c376f 100644 --- a/Core/Libraries/Source/WWVegas/WW3D2/texproject.cpp +++ b/Core/Libraries/Source/WWVegas/WW3D2/texproject.cpp @@ -940,7 +940,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; } @@ -958,8 +958,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; } From 22fc2121a3c1833eb6ac7eecf06c2a5e5a266f2a Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Wed, 19 Aug 2026 19:22:06 +0300 Subject: [PATCH 06/15] feat(crc): Report deterministic math state in SimulationMathCrc diagnostics --- .../Common/Diagnostic/SimulationMathCrc.h | 4 + .../Common/Diagnostic/SimulationMathCrc.cpp | 105 +++++++++++++++--- 2 files changed, 95 insertions(+), 14 deletions(-) diff --git a/Core/GameEngine/Include/Common/Diagnostic/SimulationMathCrc.h b/Core/GameEngine/Include/Common/Diagnostic/SimulationMathCrc.h index 031bc2e3f88..530e707e561 100644 --- a/Core/GameEngine/Include/Common/Diagnostic/SimulationMathCrc.h +++ b/Core/GameEngine/Include/Common/Diagnostic/SimulationMathCrc.h @@ -18,8 +18,12 @@ #pragma once +// Flags for diagnostic math benchmarks +#define RUN_MATH_BENCHMARK_REPLAY400_FLAG (0) + class SimulationMathCrc { public: static UnsignedInt calculate(); + static void runBenchmark(int iterations = 10000); }; diff --git a/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp b/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp index 1b062f44e34..8c23e9e63ec 100644 --- a/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp +++ b/Core/GameEngine/Source/Common/Diagnostic/SimulationMathCrc.cpp @@ -25,8 +25,10 @@ #include "GameLogic/FPUControl.h" #include +#include +#include -static void appendSimulationMathCrc(XferCRC &xfer) +static void appendSimulationMathCrc_Deterministic(XferCRC &xfer) { Matrix3D matrix; Matrix3D factorsMatrix; @@ -37,18 +39,48 @@ 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), - 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); + + xfer.xferMatrix3D(&matrix); +} + +static void appendSimulationMathCrc_Native(XferCRC &xfer) +{ + Matrix3D matrix; + Matrix3D factorsMatrix; + + matrix.Set( + 4.1f, 1.2f, 0.3f, 0.4f, + 0.5f, 3.6f, 0.7f, 0.8f, + 0.9f, 1.0f, 2.1f, 1.2f); + + factorsMatrix.Set( + (float)(::sin(0.7) * ::log10(2.3)), + (float)(::cos(1.1) * ::pow(1.1, 2.0)), + (float)::tan(0.3), + (float)::asin(0.967302263), + (float)::acos(0.967302263), + (float)(::atan(0.967302263) * ::pow(1.1, 2.0)), + (float)::atan2(0.4, 1.3), + (float)::sinh(0.2), + (float)(::cosh(0.4) * ::tanh(0.5)), + (float)::sqrt(55788.84375), + (float)(::exp(0.1) * ::log10(2.3)), + (float)::log(1.4)); Matrix3D::Multiply(matrix, factorsMatrix, &matrix); matrix.Get_Inverse(matrix); @@ -63,7 +95,7 @@ UnsignedInt SimulationMathCrc::calculate() setFPMode(); - appendSimulationMathCrc(xfer); + appendSimulationMathCrc_Deterministic(xfer); _fpreset(); @@ -71,3 +103,48 @@ UnsignedInt SimulationMathCrc::calculate() return xfer.getCRC(); } + +void SimulationMathCrc::runBenchmark(int iterations) +{ + int i; + clock_t startDet = clock(); + UnsignedInt crcDet = 0; + + setFPMode(); + + for (i = 0; i < iterations; ++i) + { + XferCRC xfer; + xfer.open("SimMathDet"); + appendSimulationMathCrc_Deterministic(xfer); + xfer.close(); + if (i == 0) + crcDet = xfer.getCRC(); + } + _fpreset(); + clock_t endDet = clock(); + double timeDetMs = (double)(endDet - startDet) / CLOCKS_PER_SEC * 1000.0; + + clock_t startNat = clock(); + UnsignedInt crcNat = 0; + + setFPMode(); + + for (i = 0; i < iterations; ++i) + { + XferCRC xfer; + xfer.open("SimMathNat"); + appendSimulationMathCrc_Native(xfer); + xfer.close(); + if (i == 0) + crcNat = xfer.getCRC(); + } + _fpreset(); + clock_t endNat = clock(); + double timeNatMs = (double)(endNat - startNat) / CLOCKS_PER_SEC * 1000.0; + + printf("\n================ MATH BENCHMARK (%d iterations) ================\n", iterations); + printf("Deterministic (WWMath): CRC = %08X, Time = %.2f ms\n", crcDet, timeDetMs); + printf("Native (system math): CRC = %08X, Time = %.2f ms\n", crcNat, timeNatMs); + printf("===========================================================\n\n"); +} From 118a3f06f15ada845a38242f20da772c3986b742 Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Wed, 19 Aug 2026 19:22:06 +0300 Subject: [PATCH 07/15] refactor(gameengine): Route Core game engine math through WWMath --- .../GameEngine/Include/Common/BezierSegment.h | 27 +++++++++++++++ Core/GameEngine/Include/Common/GameDefines.h | 4 +-- .../Source/Common/Bezier/BezFwdIterator.cpp | 6 ++-- .../Source/Common/Bezier/BezierSegment.cpp | 8 ++--- Core/GameEngine/Source/Common/INI/INI.cpp | 4 +-- .../GameClient/MessageStream/LookAtXlat.cpp | 2 +- .../Source/GameLogic/AI/AIPathfind.cpp | 34 +++++++++---------- 7 files changed, 55 insertions(+), 30 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/Include/Common/GameDefines.h b/Core/GameEngine/Include/Common/GameDefines.h index be20d29c292..d7f2052e58a 100644 --- a/Core/GameEngine/Include/Common/GameDefines.h +++ b/Core/GameEngine/Include/Common/GameDefines.h @@ -91,9 +91,7 @@ #define PRESERVE_RETAIL_PARTICLES (1) // Preserve original look of particles present in retail Generals 1.08 and Zero Hour 1.04 #endif -#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_XFER_SAVE #define RETAIL_COMPATIBLE_XFER_SAVE (1) // Game is expected to be Xfer Save compatible with retail Generals 1.08, Zero Hour 1.04 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 3154ec0f351..877dbca6768 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); } //------------------------------------------------------------------------------------------------- diff --git a/Core/GameEngine/Source/Common/INI/INI.cpp b/Core/GameEngine/Source/Common/INI/INI.cpp index e3c174a5d54..3ec8fef72fa 100644 --- a/Core/GameEngine/Source/Common/INI/INI.cpp +++ b/Core/GameEngine/Source/Common/INI/INI.cpp @@ -1788,7 +1788,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)); } // ------------------------------------------------------------------------------------------------ @@ -1796,7 +1796,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/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/GameEngine/Source/GameLogic/AI/AIPathfind.cpp b/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp index 4377e6d2105..a6d3d5ad2b7 100644 --- a/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp +++ b/Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp @@ -727,9 +727,9 @@ inline Bool isReallyClose(const Coord3D& a, const Coord3D& b) { const Real CLOSE_ENOUGH = 0.1f; return - fabs(a.x-b.x) <= CLOSE_ENOUGH && - fabs(a.y-b.y) <= CLOSE_ENOUGH && - fabs(a.z-b.z) <= CLOSE_ENOUGH; + WWMath::Fabs(a.x-b.x) <= CLOSE_ENOUGH && + WWMath::Fabs(a.y-b.y) <= CLOSE_ENOUGH && + WWMath::Fabs(a.z-b.z) <= CLOSE_ENOUGH; } /** @@ -921,14 +921,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; @@ -1011,8 +1011,8 @@ void Path::computePointOnPath( out.posOnPath.x = closeNodePos->x + alongPathDist * segmentDirNorm.x; out.posOnPath.y = closeNodePos->y + alongPathDist * segmentDirNorm.y; out.posOnPath.z = closeNodePos->z; - Real dx = fabs(pos.x - out.posOnPath.x); - Real dy = fabs(pos.y - out.posOnPath.y); + Real dx = WWMath::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(); } @@ -2091,7 +2091,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; @@ -2117,7 +2117,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; } @@ -3984,8 +3984,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) { @@ -6440,7 +6440,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()) { @@ -6465,7 +6465,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; @@ -6789,7 +6789,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; @@ -7480,7 +7480,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; @@ -8184,7 +8184,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; @@ -11237,7 +11237,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. } From 3925fc606f2d3b6b789bcfdd9c82f1f2f6bdeddb Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Wed, 19 Aug 2026 19:22:07 +0300 Subject: [PATCH 08/15] refactor(device): Route device and tools math through the legacy WWMath variants --- .../W3DDevice/GameClient/BaseHeightMap.cpp | 2 +- .../W3DDevice/GameClient/CameraShakeSystem.cpp | 2 +- .../GameClient/Drawable/Draw/W3DTankDraw.cpp | 4 ++-- .../Drawable/Draw/W3DTankTruckDraw.cpp | 4 ++-- .../Source/W3DDevice/GameClient/HeightMap.cpp | 4 ++-- .../Source/W3DDevice/GameClient/W3DMouse.cpp | 10 +++++----- .../W3DDevice/GameClient/W3DParticleSys.cpp | 12 ++++++------ .../GameClient/W3DProfilerFrameCapture.cpp | 2 +- .../W3DDevice/GameClient/W3DTreeBuffer.cpp | 8 ++++---- .../Source/W3DDevice/GameClient/W3DView.cpp | 4 ++-- Core/Tools/W3DView/RingSizePropPage.cpp | 2 +- Core/Tools/W3DView/SphereSizePropPage.cpp | 2 +- .../GameClient/Shadow/W3DVolumetricShadow.cpp | 12 ++++++------ .../W3DDevice/GameClient/W3DAssetManager.cpp | 12 ++++++------ .../WorldBuilder/src/GlobalLightOptions.cpp | 12 ++++++------ .../GameClient/Shadow/W3DVolumetricShadow.cpp | 18 +++++++++--------- .../W3DDevice/GameClient/W3DAssetManager.cpp | 12 ++++++------ .../WorldBuilder/src/GlobalLightOptions.cpp | 12 ++++++------ 18 files changed, 67 insertions(+), 67 deletions(-) diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp index e8687783f3e..0f5db72fec6 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp @@ -1722,7 +1722,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/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 a00746a0fb9..e900c30e4b9 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++; } @@ -398,7 +398,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 8d936948ed6..07f288a72a6 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++; } @@ -720,7 +720,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 b84ea8663ff..edb8a4d4937 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp @@ -1767,8 +1767,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/W3DMouse.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DMouse.cpp index 814bb83cce5..e71887c051e 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DMouse.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DMouse.cpp @@ -567,8 +567,8 @@ void W3DMouse::draw() { offset = TheInGameUI->getScrollAmount(); offset.normalize(); - Real theta = atan2(-offset.y, offset.x); - theta -= (Real)M_PI/2; + Real theta = WWMath::Atan2(-offset.y, offset.x); + theta -= (Real)WWMATH_HALF_PI; tm.Rotate_Z(theta); } cursorModels[m_currentW3DCursor]->Set_Transform(tm); @@ -671,13 +671,13 @@ void W3DMouse::setCursorDirection(MouseCursor cursor) if (offset.x || offset.y) { offset.normalize(); - Real theta = atan2(offset.y, offset.x); - theta = fmod(theta+M_PI*2,M_PI*2); + Real theta = WWMath::Atan2(offset.y, offset.x); + 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/W3DParticleSys.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp index c2a1b9c6fc4..59229429a3c 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp @@ -168,13 +168,13 @@ void W3DParticleSystemManager::doParticles(RenderInfoClass &rinfo) Real psize = p->getSize(); //Cull particle to edges of screen and terrain. - if (WWMath::Fabs( pos->x - bcX ) > ( beX + psize ) ) + if (WWMath::Fabsf_Legacy( pos->x - bcX ) > ( beX + psize ) ) continue; - if (WWMath::Fabs( pos->y - bcY ) > ( beY + psize ) ) + if (WWMath::Fabsf_Legacy( pos->y - bcY ) > ( beY + psize ) ) continue; - if (WWMath::Fabs( pos->z - bcZ ) > ( beZ + psize ) ) + if (WWMath::Fabsf_Legacy( pos->z - bcZ ) > ( beZ + psize ) ) continue; if (Smudge *smudge = TheSmudgeManager->findSmudge(p)) @@ -207,13 +207,13 @@ void W3DParticleSystemManager::doParticles(RenderInfoClass &rinfo) psize = p->getSize(); //Cull particle to edges of screen and terrain. - if (WWMath::Fabs(pos->x - bcX) > (beX + psize)) + if (WWMath::Fabsf_Legacy(pos->x - bcX) > (beX + psize)) continue; - if (WWMath::Fabs(pos->y - bcY) > (beY + psize)) + if (WWMath::Fabsf_Legacy(pos->y - bcY) > (beY + psize)) continue; - if (WWMath::Fabs(pos->z - bcZ) > (beZ + psize)) + if (WWMath::Fabsf_Legacy(pos->z - bcZ) > (beZ + psize)) continue; m_fieldParticleCount += ( sys->getPriority() == AREA_EFFECT && sys->m_isGroundAligned != FALSE ); diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DProfilerFrameCapture.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DProfilerFrameCapture.cpp index 90a8d931982..2f5071c37ee 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 7ac29bec1b1..a049fb682a5 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp @@ -1351,8 +1351,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; @@ -1396,8 +1396,8 @@ Bool W3DTreeBuffer::updateTreePosition(DrawableID id, Coord3D location, Real ang for (i=0; iisUsingAirborneLocomotor() && cameraLockObj->isAboveTerrainOrWater()) { Matrix3D camXForm; - Real idealZRot = cameraLockObj->getOrientation() - M_PI_2; + Real idealZRot = cameraLockObj->getOrientation() - WWMATH_HALF_PI; if (m_snapImmediate) { @@ -2234,7 +2234,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/Tools/W3DView/RingSizePropPage.cpp b/Core/Tools/W3DView/RingSizePropPage.cpp index bd7c6e32e63..5d7e7b35e84 100644 --- a/Core/Tools/W3DView/RingSizePropPage.cpp +++ b/Core/Tools/W3DView/RingSizePropPage.cpp @@ -735,5 +735,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 f46f07455d0..54648574745 100644 --- a/Core/Tools/W3DView/SphereSizePropPage.cpp +++ b/Core/Tools/W3DView/SphereSizePropPage.cpp @@ -555,5 +555,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/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp index 6e26d71f8ac..c1178fd4fa1 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp @@ -1686,9 +1686,9 @@ void W3DVolumetricShadow::Update() if (fabs(pos.Z - groundHeight) >= 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 @@ -1699,9 +1699,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 383777eaef5..10afeec2a56 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp @@ -688,7 +688,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); @@ -1303,9 +1303,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); @@ -1402,8 +1402,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/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/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp index 33b42a8c03e..be3ab41219c 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp @@ -1792,9 +1792,9 @@ void W3DVolumetricShadow::Update() if (fabs(pos.Z - groundHeight) >= 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 @@ -1805,9 +1805,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 @@ -1948,7 +1948,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) { @@ -1957,7 +1957,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) { @@ -1965,7 +1965,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 899dfcb3f74..a9f89e85988 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DAssetManager.cpp @@ -718,7 +718,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); @@ -1330,9 +1330,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); @@ -1429,8 +1429,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/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 726b929a2fa865c54cefae37f896bb37797c257a Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Wed, 19 Aug 2026 19:22:07 +0300 Subject: [PATCH 09/15] refactor(common): Route Trig and Common math through WWMath --- .../GameEngine/Source/Common/RTS/Player.cpp | 2 +- .../Source/Common/System/BuildAssistant.cpp | 10 +- .../Source/Common/System/Geometry.cpp | 18 +-- .../GameEngine/Source/Common/System/Trig.cpp | 123 +++--------------- .../GameEngine/Source/Common/RTS/Player.cpp | 2 +- .../Source/Common/System/BuildAssistant.cpp | 10 +- .../Source/Common/System/Geometry.cpp | 18 +-- .../GameEngine/Source/Common/System/Trig.cpp | 123 +++--------------- 8 files changed, 60 insertions(+), 246 deletions(-) diff --git a/Generals/Code/GameEngine/Source/Common/RTS/Player.cpp b/Generals/Code/GameEngine/Source/Common/RTS/Player.cpp index 6ff00eaf6db..e46997387c5 100644 --- a/Generals/Code/GameEngine/Source/Common/RTS/Player.cpp +++ b/Generals/Code/GameEngine/Source/Common/RTS/Player.cpp @@ -2367,7 +2367,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 6f362160d5c..944d639315c 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/Common/System/Trig.cpp b/Generals/Code/GameEngine/Source/Common/System/Trig.cpp index b09c4cb55d8..7cd4808f1a2 100644 --- a/Generals/Code/GameEngine/Source/Common/System/Trig.cpp +++ b/Generals/Code/GameEngine/Source/Common/System/Trig.cpp @@ -29,117 +29,24 @@ #include "PreRTS.h" -#include -#include - #include "Lib/BaseType.h" #include "Lib/trig.h" -#define TWOPI 6.28318530718f -#define DEG2RAD 0.0174532925199f -#define TRIG_RES 4096 - -// the following are for fixed point ints with 12 fractional bits -#define INT_ONE 4096 -#define INT_TWOPI 25736 -#define INT_THREEPIOVERTWO 19302 -#define INT_PI 12868 -#define INT_HALFPI 6434 - -Real Sin(Real x) -{ - return sinf(x); -} - -Real Cos(Real x) -{ - return cosf(x); -} - -Real Tan(Real x) -{ - return tanf(x); -} - -Real ACos(Real x) -{ - return acosf(x); -} - -Real ASin(Real x) -{ - return asinf(x); -} +#if USE_DETERMINISTIC_MATH +#include "gmath.h" +#endif -#ifdef REGENERATE_TRIG_TABLES -void initTrig() +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) { - 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; i0) { 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/Common/System/Trig.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp index 2ffb79bbae2..bfedd93bd5a 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/Trig.cpp @@ -29,117 +29,24 @@ #include "PreRTS.h" -#include -#include - #include "Lib/BaseType.h" #include "Lib/trig.h" -#define TWOPI 6.28318530718f -#define DEG2RAD 0.0174532925199f -#define TRIG_RES 4096 - -// the following are for fixed point ints with 12 fractional bits -#define INT_ONE 4096 -#define INT_TWOPI 25736 -#define INT_THREEPIOVERTWO 19302 -#define INT_PI 12868 -#define INT_HALFPI 6434 - -Real Sin(Real x) -{ - return sinf(x); -} - -Real Cos(Real x) -{ - return cosf(x); -} - -Real Tan(Real x) -{ - return tanf(x); -} - -Real ACos(Real x) -{ - return acosf(x); -} - -Real ASin(Real x) -{ - return asinf(x); -} +#if USE_DETERMINISTIC_MATH +#include "gmath.h" +#endif -#ifdef REGENERATE_TRIG_TABLES -void initTrig() +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) { - static Byte inited = FALSE; - Real angle, r; - int i; - - if (inited) - return; - - inited = TRUE; - - static int columns = 8; - int column = 0; - FILE *fp = fopen("trig.txt", "w"); - fprintf(fp, "static Int sinLookup[TRIG_RES] = {\n"); - for( i=0; i Date: Wed, 19 Aug 2026 19:22:07 +0300 Subject: [PATCH 10/15] refactor(gamelogic): Route simulation math through WWMath Replaces direct libm calls 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. --- .../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 +++--- .../Behavior/DumbProjectileBehavior.cpp | 18 ++-- .../Behavior/GenerateMinefieldBehavior.cpp | 2 +- .../Object/Behavior/MinefieldBehavior.cpp | 8 +- .../Object/Behavior/SlowDeathBehavior.cpp | 7 +- .../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 | 61 ++++++++----- .../SpecialPower/SpecialPowerModule.cpp | 5 +- .../GameLogic/Object/Update/AIUpdate.cpp | 14 +-- .../Update/AIUpdate/ChinookAIUpdate.cpp | 8 +- .../AIUpdate/DeliverPayloadAIUpdate.cpp | 8 +- .../Object/Update/AIUpdate/JetAIUpdate.cpp | 10 +-- .../Update/AIUpdate/MissileAIUpdate.cpp | 4 +- .../Update/AIUpdate/POWTruckAIUpdate.cpp | 2 +- .../Update/AIUpdate/RailroadGuideAIUpdate.cpp | 12 +-- .../Object/Update/CleanupHazardUpdate.cpp | 4 +- .../Object/Update/CommandButtonHuntUpdate.cpp | 2 +- .../DockUpdate/SupplyWarehouseDockUpdate.cpp | 4 +- .../DynamicShroudClearingRangeUpdate.cpp | 4 +- .../GameLogic/Object/Update/FloatUpdate.cpp | 4 +- .../Object/Update/NeutronMissileUpdate.cpp | 6 +- .../Update/ParticleUplinkCannonUpdate.cpp | 2 +- .../GameLogic/Object/Update/PhysicsUpdate.cpp | 38 ++++---- .../Object/Update/PointDefenseLaserUpdate.cpp | 6 +- .../GameLogic/Object/Update/StealthUpdate.cpp | 2 +- .../Object/Update/TensileFormationUpdate.cpp | 2 +- .../GameLogic/Object/Update/ToppleUpdate.cpp | 8 +- .../Source/GameLogic/Object/Weapon.cpp | 18 ++-- .../Source/GameLogic/System/GameLogic.cpp | 2 +- .../GameEngine/Source/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 +- .../Source/GameLogic/Map/PolygonTrigger.cpp | 2 +- .../Source/GameLogic/Map/TerrainLogic.cpp | 30 +++---- .../Object/Behavior/BridgeBehavior.cpp | 2 +- .../Behavior/DumbProjectileBehavior.cpp | 18 ++-- .../Behavior/GenerateMinefieldBehavior.cpp | 6 +- .../Object/Behavior/MinefieldBehavior.cpp | 10 +-- .../Object/Behavior/SlowDeathBehavior.cpp | 7 +- .../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 | 10 +-- .../GameLogic/Object/PartitionManager.cpp | 61 ++++++++----- .../SpecialPower/SpecialPowerModule.cpp | 5 +- .../GameLogic/Object/Update/AIUpdate.cpp | 14 +-- .../Update/AIUpdate/ChinookAIUpdate.cpp | 6 +- .../AIUpdate/DeliverPayloadAIUpdate.cpp | 13 +-- .../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 +- .../Object/Update/NeutronMissileUpdate.cpp | 6 +- .../Update/ParticleUplinkCannonUpdate.cpp | 2 +- .../GameLogic/Object/Update/PhysicsUpdate.cpp | 46 +++++----- .../Object/Update/PointDefenseLaserUpdate.cpp | 6 +- .../GameLogic/Object/Update/SlavedUpdate.cpp | 4 +- .../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 | 13 ++- 83 files changed, 496 insertions(+), 454 deletions(-) diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AI.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AI.cpp index ad9493ccf4f..bf6eda26328 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::Sqrt(distSqr); Int modifier = dist/getAiData()->m_attackPriorityDistanceModifier; Int modPriority = curPriority-modifier; if (modPriority < 1) diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp index 1799a20e537..c48db784241 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 2472c2ffefc..f4e026bad3d 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)) { @@ -1251,7 +1251,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)) { @@ -2812,7 +2812,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 afb876af064..382237663b9 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp @@ -663,8 +663,8 @@ void AISkirmishPlayer::buildAIBaseDefenseStructure(const AsciiString &thingName, } if (angle > PI/3) break; - Real s = sin(angle); - Real c = cos(angle); + Real s = WWMath::Sin(angle); + Real c = WWMath::Cos(angle); // TheSuperHackers @info helmutbuhler 21/04/2025 This debug mutates the code to become CRC incompatible #if defined(RTS_DEBUG) || !RETAIL_COMPATIBLE_CRC @@ -1029,8 +1029,8 @@ void AISkirmishPlayer::adjustBuildList(BuildListInfo *list) angle += 3*PI/4; - Real s = sin(angle); - Real c = cos(angle); + Real s = WWMath::Sin(angle); + Real c = WWMath::Cos(angle); cur = list; while (cur) { diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp index 385ae65a089..405102a386c 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; @@ -3579,7 +3579,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--; @@ -3809,16 +3809,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 @@ -4940,7 +4940,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); @@ -4952,7 +4952,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(). @@ -6996,7 +6996,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 6cea7c6227a..c17f6f8315a 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp @@ -270,7 +270,7 @@ void PolygonTrigger::updateBounds() const Real halfWidth = (m_bounds.hi.x - m_bounds.lo.x) / 2.0f; Real halfHeight = (m_bounds.hi.y + m_bounds.lo.y) / 2.0f; - m_radius = sqrt(halfHeight*halfHeight + halfWidth*halfWidth); + m_radius = WWMath::Sqrt(halfHeight*halfHeight + halfWidth*halfWidth); } diff --git a/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp b/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp index 00386047267..777676daee6 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp @@ -1469,7 +1469,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 ); @@ -1490,7 +1490,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 ); @@ -1691,12 +1691,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; @@ -1730,7 +1730,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; } @@ -1745,7 +1745,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; } @@ -1794,7 +1794,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; } @@ -1843,7 +1843,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; @@ -2073,10 +2073,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++ ) @@ -2387,7 +2387,7 @@ void TerrainLogic::setWaterHeight( const WaterHandle *water, Real height, Real d center.z = 0.0f; // irrelavant // the max radius to scan around us is the diagonal of the bounding region - Real maxDist = sqrt( affectedRegion.width() * affectedRegion.width() + + Real maxDist = WWMath::Sqrt( affectedRegion.width() * affectedRegion.width() + affectedRegion.height() * affectedRegion.height() ); // scan the objects in the area of the water affected 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..0a2fcbdc46a 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp @@ -179,8 +179,9 @@ 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(); - Int overkillModifier = overkillPercent * getSlowDeathBehaviorModuleData()->m_modifierBonusPerOverkillPercent; + Real maxHealth = getObject()->getBodyModule()->getMaxHealth(); + Real overkillPercent = WWMath::Div_Safe((float)overkillDamage, maxHealth, 0.0f); + Int overkillModifier = (Int)(overkillPercent * getSlowDeathBehaviorModuleData()->m_modifierBonusPerOverkillPercent); return max( getSlowDeathBehaviorModuleData()->m_probabilityModifier + overkillModifier, 1 ); } @@ -299,7 +300,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 06e3f370d88..a81e2654ce6 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp @@ -84,7 +84,7 @@ static Real calcSlowDownDist(Real curSpeed, Real desiredSpeed, Real maxBraking) if (delta <= 0) return 0.0f; - Real dist = (sqr(delta) / fabs(maxBraking)) * 0.5f; + Real dist = (sqr(delta) / WWMath::Fabs(maxBraking)) * 0.5f; // use a little fudge so that things can stop "on a dime" more easily... const Real FUDGE = 1.05f; @@ -95,14 +95,14 @@ static Real calcSlowDownDist(Real curSpeed, Real desiredSpeed, Real maxBraking) inline Bool isNearlyZero(Real a) { const Real TINY_EPSILON = 0.001f; - return fabs(a) < TINY_EPSILON; + return WWMath::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; } //----------------------------------------------------------------------------- @@ -141,7 +141,7 @@ static Real tryToRotateVector3D( } } - if (fabs(angleBetween) <= maxAngle) + if (WWMath::Fabs(angleBetween) <= maxAngle) { // close enough actualDir = goalDir; @@ -231,9 +231,9 @@ static void calcDirectionToApplyThrust( Bool foundSolution = false; Real distToGoalSqr = vecToGoal.Length2(); - Real distToGoal = sqrt(distToGoalSqr); + Real distToGoal = WWMath::Sqrt(distToGoalSqr); Real curVelMagSqr = curVel.Length2(); - Real curVelMag = sqrt(curVelMagSqr); + Real curVelMag = WWMath::Sqrt(curVelMagSqr); Real maxAccelSqr = sqr(maxAccel); Real denom = curVelMagSqr - maxAccelSqr; @@ -1002,7 +1002,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) @@ -1120,7 +1120,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; @@ -1144,7 +1144,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) @@ -1189,7 +1189,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; @@ -1260,7 +1260,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(); @@ -1295,7 +1295,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; @@ -1312,14 +1312,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 { @@ -1335,7 +1335,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) { @@ -1360,7 +1360,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; @@ -1499,7 +1499,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), @@ -1570,7 +1570,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); @@ -1634,7 +1634,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; @@ -1660,7 +1660,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; @@ -1690,7 +1690,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(); @@ -1732,7 +1732,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); } @@ -1752,7 +1752,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) { @@ -1767,7 +1767,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) { @@ -1781,7 +1781,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; @@ -1823,7 +1823,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(); @@ -1850,7 +1850,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. @@ -1858,7 +1858,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; @@ -1947,7 +1947,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); @@ -2064,7 +2064,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. @@ -2072,14 +2072,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; @@ -2153,8 +2153,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) { @@ -2176,7 +2176,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. @@ -2192,7 +2192,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) { @@ -2370,8 +2370,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); @@ -2410,7 +2410,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; @@ -2526,7 +2526,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) @@ -2560,7 +2560,7 @@ void Locomotor::maintainCurrentPositionHover(Object* obj, PhysicsBehavior *physi // Real minSpeed = max( 1.0E-10f, m_template->m_minSpeed ); Real speedDelta = minSpeed - actualSpeed; - if (fabs(speedDelta) > minSpeed) + if (WWMath::Fabs(speedDelta) > minSpeed) { Real mass = physics->getMass(); Real acceleration = (speedDelta > 0.0f) ? maxAcceleration : -getBraking(); @@ -2571,7 +2571,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 d5748b002e4..b54fd04c5ad 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp @@ -1647,13 +1647,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; @@ -1669,7 +1669,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 a894d9331a2..ca2d2bc2aa6 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 f9b464c58bd..15640b424e2 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) { @@ -2219,7 +2219,7 @@ Int PartitionData::calcMaxCoiForShape(GeometryType geom, Real majorRadius, Real } case GEOMETRY_BOX: { - Real diagonal = (Real)(sqrtf(majorRadius*majorRadius + minorRadius*minorRadius)); + Real diagonal = (Real)(WWMath::Sqrtf(majorRadius*majorRadius + minorRadius*minorRadius)); Int cells = ThePartitionManager->worldToCellDist(diagonal*2) + 1; result = cells * cells; break; @@ -2636,7 +2636,7 @@ static void calcHeights(const Region3D& world, Real cellSize, Int x, Int y, Real Real xbase = world.lo.x + (x * cellSize); Real ybase = world.lo.y + (y * cellSize); const Real ROUGH_STEP_SIZE = 2; // roughly every 2 ft, please - Real numSteps = ceilf(cellSize / ROUGH_STEP_SIZE); + Real numSteps = WWMath::Ceilf(cellSize / ROUGH_STEP_SIZE); Real step = cellSize / numSteps; loZ = HUGE_DIST; // huge positive hiZ = -HUGE_DIST; // huge negative @@ -3195,22 +3195,34 @@ Int PartitionManager::calcMinRadius(const ICoord2D& cur) so it really shouldn't matter... (I hope) */ +#if RETAIL_COMPATIBLE_CRC double minDistSqr = 1e12; // double, not real +#else + Real minDistSqr = 1e12f; +#endif for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { - // double, not real +#if RETAIL_COMPATIBLE_CRC double dx = centerPos[i].x - otherPos[j].x; double dy = centerPos[i].y - otherPos[j].y; double curDistSqr = dx*dx + dy*dy; +#else + Real dx = centerPos[i].x - otherPos[j].x; + Real dy = centerPos[i].y - otherPos[j].y; + Real curDistSqr = dx*dx + dy*dy; +#endif if (minDistSqr > curDistSqr) minDistSqr = curDistSqr; } } - // double, not real - double dist = sqrtf(minDistSqr); +#if RETAIL_COMPATIBLE_CRC + double dist = WWMath::Sqrtf(minDistSqr); +#else + Real dist = WWMath::Sqrtf(minDistSqr); +#endif Int minRadius = REAL_TO_INT_CEIL( dist / m_cellSize ); return minRadius; @@ -3225,10 +3237,15 @@ void PartitionManager::calcRadiusVec() Int cx = getCellCountX(); Int cy = getCellCountY(); - // double, not real +#if RETAIL_COMPATIBLE_CRC double dx = (double)cx * (double)cellSize; double dy = (double)cy * (double)cellSize; - double maxPossibleDist = sqrt(dx*dx + dy*dy); + double maxPossibleDist = WWMath::Sqrt(dx*dx + dy*dy); +#else + Real dx = (Real)cx * cellSize; + Real dy = (Real)cy * cellSize; + Real maxPossibleDist = WWMath::Sqrtf(dx*dx + dy*dy); +#endif m_maxGcoRadius = REAL_TO_INT_CEIL(maxPossibleDist / cellSize); @@ -3498,7 +3515,7 @@ Object *PartitionManager::getClosestObjects( } if (closestDistArg) { - *closestDistArg = (Real)sqrtf(closestDistSqr); + *closestDistArg = (Real)WWMath::Sqrtf(closestDistSqr); } #ifdef RTS_DEBUG @@ -3625,7 +3642,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) @@ -3803,7 +3820,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; // @@ -4556,7 +4573,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)); } //----------------------------------------------------------------------------- @@ -5715,7 +5732,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; @@ -5743,7 +5760,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; @@ -5771,7 +5788,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; @@ -5799,7 +5816,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/SpecialPower/SpecialPowerModule.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp index ee0112820dc..838534795a3 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp @@ -98,11 +98,8 @@ SpecialPowerModule::SpecialPowerModule( Thing *thing, const ModuleData *moduleDa : BehaviorModule( thing, moduleData ) { -#if RETAIL_COMPATIBLE_CRC + m_availableOnFrame = 0; -#else - m_availableOnFrame = 0xFFFFFFFF; -#endif m_pausedCount = 0; m_pausedOnFrame = 0; m_pausedPercent = 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 c49ae77d861..f25062b9ce4 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 e053a0d4b55..1d8fce44416 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/JetAIUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp index 8aabf776799..e990b144629 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 688a0918a5a..5d6f623b2c7 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) { @@ -619,7 +619,7 @@ UpdateSleepTime MissileAIUpdate::update() Coord3D newPos = *getObject()->getPosition(); if (m_noTurnDistLeft > 0.0f && m_state >= IGNITION) { - Real distThisTurn = sqrtf(sqr(newPos.x-m_prevPos.x) + sqr(newPos.y-m_prevPos.y) + sqr(newPos.z-m_prevPos.z)); + Real distThisTurn = WWMath::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 dc83acdf5db..52333f5c8b5 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 24d9d6498ed..b74afb4dd9e 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. @@ -472,8 +472,8 @@ void RailroadBehavior::playImpactSound(Object *victim, const Coord3D *impactPosi impact.setPosition(impactPosition); if ( theirPhys ) { - vel += fabs(theirPhys->getVelocity()->length()); - mass += fabs(theirPhys->getMass()); + vel += WWMath::Fabs(theirPhys->getVelocity()->length()); + mass += WWMath::Fabs(theirPhys->getMass()); vel /= 2; mass /= 2;//average of him and me @@ -675,7 +675,7 @@ UpdateSleepTime RailroadBehavior::update() if ( m_conductorState == APPLY_BRAKES ) { conductorPullInfo.speed *= modData->m_braking; - if (fabs(conductorPullInfo.speed) < 0.01f) + if (WWMath::Fabs(conductorPullInfo.speed) < 0.01f) { conductorPullInfo.speed = 0; ///////////////////////////////////////( &m_hissySteamSound ); @@ -1193,7 +1193,7 @@ void alignToTerrain( Real angle, const Coord3D& pos, const Coord3D& normal, Matr x.normalize(); } - DEBUG_ASSERTCRASH(fabs(x.x*z.x + x.y*z.y + x.z*z.z)<0.0001,("dot is not zero")); + DEBUG_ASSERTCRASH(WWMath::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 ); @@ -1259,7 +1259,7 @@ void RailroadBehavior::updatePositionTrackDistance( PullInfo *pullerInfo, PullIn trackPosDelta.z = 0; Real dx = pullerInfo->towHitchPosition.x - turnPos.x; Real dy = pullerInfo->towHitchPosition.y - turnPos.y; - Real desiredAngle = atan2(dy, dx); + Real desiredAngle = WWMath::Atan2(dy, dx); Real relAngle = stdAngleDiff(desiredAngle, obj->getTransformMatrix()->Get_Z_Rotation()); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp index 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 5ad5b511a23..5d919cfbb31 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/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 44c344ff071..1ac10d290e3 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp @@ -479,7 +479,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 d379cb43662..a5e71bc6c3f 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; } @@ -838,7 +838,7 @@ Real PhysicsBehavior::getForwardSpeed2D() const Real speedSquared = vx*vx + vy*vy; // DEBUG_ASSERTCRASH( speedSquared != 0, ("zero speedSquared will overflow sqrtf()!") );// lorenzen... sanity check - Real speed = (Real)sqrtf( speedSquared ); + Real speed = (Real)WWMath::Sqrtf( speedSquared ); if (dot >= 0.0f) return speed; @@ -861,7 +861,7 @@ Real PhysicsBehavior::getForwardSpeed3D() const Real dot = vx + vy + vz; - 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; @@ -884,7 +884,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; } @@ -908,7 +908,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; @@ -991,9 +991,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; } @@ -1193,7 +1193,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 @@ -1334,7 +1334,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/StealthUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp index a653701eca8..b92d9743a34 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp @@ -411,7 +411,7 @@ UpdateSleepTime StealthUpdate::update() m_disguiseHalfpointReached = true; } //Opacity ranges from full to none at midpoint and full again at the end - Real opacity = fabs( 1.0f - (factor * 2.0f) ); + Real opacity = WWMath::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 8e883698a05..1f3f72d5d52 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)); } @@ -869,7 +869,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) @@ -895,7 +895,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); @@ -1942,11 +1942,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 932caa24f82..8bf91668dbb 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp @@ -808,7 +808,7 @@ static void populateRandomStartPosition( GameInfo *game ) { Coord3D p1 = c1->second; Coord3D p2 = c2->second; - startSpotDistance[i][j] = sqrt( sqr(p1.x-p2.x) + sqr(p1.y-p2.y) ); + startSpotDistance[i][j] = WWMath::Sqrt( sqr(p1.x-p2.x) + sqr(p1.y-p2.y) ); } } else diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp index 975cb6f832c..ecdb13874ab 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, 0.0f); 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 607a643e560..64d7e03f067 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 330969a65ed..104d3c5487a 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)) { @@ -1360,7 +1360,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)) @@ -3145,7 +3145,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 0a1a7ea64da..09144ea94e0 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp @@ -636,7 +636,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, 0.0f); Int selector; Real angle; @@ -672,8 +672,8 @@ void AISkirmishPlayer::buildAIBaseDefenseStructure(const AsciiString &thingName, } if (angle > PI/3) break; - Real s = sin(angle); - Real c = cos(angle); + Real s = WWMath::Sin(angle); + Real c = WWMath::Cos(angle); // TheSuperHackers @info helmutbuhler 21/04/2025 This debug mutates the code to become CRC incompatible #if defined(RTS_DEBUG) || !RETAIL_COMPATIBLE_CRC @@ -1038,8 +1038,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 93474df91f7..908a660f9cf 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; @@ -3681,7 +3681,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--; @@ -3911,16 +3911,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 @@ -5085,7 +5085,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); @@ -5097,7 +5097,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(). @@ -7497,7 +7497,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/Map/PolygonTrigger.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp index 4f19ee9cfc2..69791c9fd76 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp @@ -286,7 +286,7 @@ void PolygonTrigger::updateBounds() const Real halfWidth = (m_bounds.hi.x - m_bounds.lo.x) / 2.0f; Real halfHeight = (m_bounds.hi.y + m_bounds.lo.y) / 2.0f; - m_radius = sqrt(halfHeight*halfHeight + halfWidth*halfWidth); + m_radius = WWMath::Sqrt(halfHeight*halfHeight + halfWidth*halfWidth); } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp index 5a3d16f86ae..626e7e534e9 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp @@ -1469,7 +1469,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 ); @@ -1490,7 +1490,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 ); @@ -1691,12 +1691,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; @@ -1730,7 +1730,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; } @@ -1745,7 +1745,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; } @@ -1794,7 +1794,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; } @@ -1843,7 +1843,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; @@ -2073,10 +2073,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++ ) @@ -2387,7 +2387,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 @@ -2897,7 +2897,7 @@ void TerrainLogic::createCraterInTerrain(Object *obj) deltaX = ( i * MAP_XY_FACTOR ) - pos->x; deltaY = ( j * MAP_XY_FACTOR ) - pos->y; - Real distance = sqrt( sqr( deltaX ) + sqr( deltaY ) ); + Real distance = WWMath::Sqrt( sqr( deltaX ) + sqr( deltaY ) ); if ( distance < radius ) //inside circle { diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/BridgeBehavior.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/BridgeBehavior.cpp index 307b5e3a65d..ce8700e5655 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, 0.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..dbb5acb6ff3 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(), 0.0f); 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..74e537acd50 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp @@ -179,8 +179,9 @@ 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(); - Int overkillModifier = overkillPercent * getSlowDeathBehaviorModuleData()->m_modifierBonusPerOverkillPercent; + Real maxHealth = getObject()->getBodyModule()->getMaxHealth(); + Real overkillPercent = WWMath::Div_Safe((float)overkillDamage, maxHealth, 0.0f); + Int overkillModifier = (Int)(overkillPercent * getSlowDeathBehaviorModuleData()->m_modifierBonusPerOverkillPercent); return max( getSlowDeathBehaviorModuleData()->m_probabilityModifier + overkillModifier, 1 ); } @@ -299,7 +300,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 205c1a99457..98f36a119ff 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Locomotor.cpp @@ -84,7 +84,7 @@ static Real calcSlowDownDist(Real curSpeed, Real desiredSpeed, Real maxBraking) if (delta <= 0) return 0.0f; - Real dist = (sqr(delta) / fabs(maxBraking)) * 0.5f; + Real dist = (sqr(delta) / WWMath::Fabs(maxBraking)) * 0.5f; // use a little fudge so that things can stop "on a dime" more easily... const Real FUDGE = 1.05f; @@ -95,14 +95,14 @@ static Real calcSlowDownDist(Real curSpeed, Real desiredSpeed, Real maxBraking) inline Bool isNearlyZero(Real a) { const Real TINY_EPSILON = 0.001f; - return fabs(a) < TINY_EPSILON; + return WWMath::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; } //----------------------------------------------------------------------------- @@ -141,7 +141,7 @@ static Real tryToRotateVector3D( } } - if (fabs(angleBetween) <= maxAngle) + if (WWMath::Fabs(angleBetween) <= maxAngle) { // close enough actualDir = goalDir; @@ -231,9 +231,9 @@ static void calcDirectionToApplyThrust( Bool foundSolution = false; Real distToGoalSqr = vecToGoal.Length2(); - Real distToGoal = sqrt(distToGoalSqr); + Real distToGoal = WWMath::Sqrt(distToGoalSqr); Real curVelMagSqr = curVel.Length2(); - Real curVelMag = sqrt(curVelMagSqr); + Real curVelMag = WWMath::Sqrt(curVelMagSqr); Real maxAccelSqr = sqr(maxAccel); Real denom = curVelMagSqr - maxAccelSqr; @@ -1002,7 +1002,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) @@ -1120,7 +1120,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; @@ -1144,7 +1144,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) @@ -1189,7 +1189,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; @@ -1260,7 +1260,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(); @@ -1295,7 +1295,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; @@ -1312,14 +1312,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 { @@ -1335,7 +1335,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) { @@ -1360,7 +1360,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; @@ -1499,7 +1499,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), @@ -1570,7 +1570,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); @@ -1634,7 +1634,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; @@ -1660,7 +1660,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; @@ -1690,7 +1690,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(); @@ -1732,7 +1732,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); } @@ -1752,7 +1752,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) { @@ -1767,7 +1767,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) { @@ -1781,7 +1781,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; @@ -1823,7 +1823,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(); @@ -1850,7 +1850,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. @@ -1858,7 +1858,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; @@ -1947,7 +1947,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); @@ -2064,7 +2064,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. @@ -2072,14 +2072,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; @@ -2153,8 +2153,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) { @@ -2176,7 +2176,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. @@ -2192,7 +2192,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) { @@ -2370,8 +2370,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); @@ -2410,7 +2410,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; @@ -2526,7 +2526,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) @@ -2560,7 +2560,7 @@ void Locomotor::maintainCurrentPositionHover(Object* obj, PhysicsBehavior *physi // Real minSpeed = max( 1.0E-10f, m_template->m_minSpeed ); Real speedDelta = minSpeed - actualSpeed; - if (fabs(speedDelta) > minSpeed) + if (WWMath::Fabs(speedDelta) > minSpeed) { Real mass = physics->getMass(); Real acceleration = (speedDelta > 0.0f) ? maxAcceleration : -getBraking(); @@ -2571,7 +2571,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 629cf11f4fe..7bedb3a45cd 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp @@ -1807,13 +1807,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; @@ -1829,7 +1829,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 9d9ffce18b1..2e0533a1781 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp @@ -33,7 +33,7 @@ #define DEFINE_SHADOW_NAMES // for TheShadowNames[] #define DEFINE_WEAPONSLOTTYPE_NAMES -#define NO_DEBUG_CRC +//#define NO_DEBUG_CRC #include "Common/AudioEventRTS.h" #include "Common/DrawModule.h" @@ -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 a5f0a55128c..90774238c1a 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) { @@ -2226,7 +2226,7 @@ Int PartitionData::calcMaxCoiForShape(GeometryType geom, Real majorRadius, Real } case GEOMETRY_BOX: { - Real diagonal = (Real)(sqrtf(majorRadius*majorRadius + minorRadius*minorRadius)); + Real diagonal = (Real)(WWMath::Sqrtf(majorRadius*majorRadius + minorRadius*minorRadius)); Int cells = ThePartitionManager->worldToCellDist(diagonal*2) + 1; result = cells * cells; break; @@ -2643,7 +2643,7 @@ static void calcHeights(const Region3D& world, Real cellSize, Int x, Int y, Real Real xbase = world.lo.x + (x * cellSize); Real ybase = world.lo.y + (y * cellSize); const Real ROUGH_STEP_SIZE = MAP_XY_FACTOR; // no point in stepping smaller than grid scale - Real numSteps = ceilf(cellSize / ROUGH_STEP_SIZE); + Real numSteps = WWMath::Ceilf(cellSize / ROUGH_STEP_SIZE); Real step = cellSize / numSteps; loZ = HUGE_DIST; // huge positive hiZ = -HUGE_DIST; // huge negative @@ -3202,22 +3202,34 @@ Int PartitionManager::calcMinRadius(const ICoord2D& cur) so it really shouldn't matter... (I hope) */ +#if RETAIL_COMPATIBLE_CRC double minDistSqr = 1e12; // double, not real +#else + Real minDistSqr = 1e12f; +#endif for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { - // double, not real +#if RETAIL_COMPATIBLE_CRC double dx = centerPos[i].x - otherPos[j].x; double dy = centerPos[i].y - otherPos[j].y; double curDistSqr = dx*dx + dy*dy; +#else + Real dx = centerPos[i].x - otherPos[j].x; + Real dy = centerPos[i].y - otherPos[j].y; + Real curDistSqr = dx*dx + dy*dy; +#endif if (minDistSqr > curDistSqr) minDistSqr = curDistSqr; } } - // double, not real - double dist = sqrtf(minDistSqr); +#if RETAIL_COMPATIBLE_CRC + double dist = WWMath::Sqrtf(minDistSqr); +#else + Real dist = WWMath::Sqrtf(minDistSqr); +#endif Int minRadius = REAL_TO_INT_CEIL( dist / m_cellSize ); return minRadius; @@ -3232,10 +3244,15 @@ void PartitionManager::calcRadiusVec() Int cx = getCellCountX(); Int cy = getCellCountY(); - // double, not real +#if RETAIL_COMPATIBLE_CRC double dx = (double)cx * (double)cellSize; double dy = (double)cy * (double)cellSize; - double maxPossibleDist = sqrt(dx*dx + dy*dy); + double maxPossibleDist = WWMath::Sqrt(dx*dx + dy*dy); +#else + Real dx = (Real)cx * cellSize; + Real dy = (Real)cy * cellSize; + Real maxPossibleDist = WWMath::Sqrtf(dx*dx + dy*dy); +#endif m_maxGcoRadius = REAL_TO_INT_CEIL(maxPossibleDist / cellSize); @@ -3505,7 +3522,7 @@ Object *PartitionManager::getClosestObjects( } if (closestDistArg) { - *closestDistArg = (Real)sqrtf(closestDistSqr); + *closestDistArg = (Real)WWMath::Sqrtf(closestDistSqr); } #ifdef RTS_DEBUG @@ -3632,7 +3649,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) @@ -3810,7 +3827,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; // @@ -4566,7 +4583,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)); } //----------------------------------------------------------------------------- @@ -5757,7 +5774,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; @@ -5785,7 +5802,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; @@ -5813,7 +5830,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; @@ -5841,7 +5858,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/SpecialPower/SpecialPowerModule.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp index f6ded8447fe..76b35302557 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp @@ -99,11 +99,8 @@ SpecialPowerModule::SpecialPowerModule( Thing *thing, const ModuleData *moduleDa : BehaviorModule( thing, moduleData ) { -#if RETAIL_COMPATIBLE_CRC + m_availableOnFrame = 0; -#else - m_availableOnFrame = 0xFFFFFFFF; -#endif m_pausedCount = 0; m_pausedOnFrame = 0; m_pausedPercent = 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 977aec18670..292b423840c 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 ca618b60a80..eb0c74947af 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,11 @@ Real DeliverPayloadAIUpdate::calcMinTurnRadius(Real* timeToTravelThatDist) const so we just eliminate the middleman: */ - Real minTurnRadius = (maxTurnRate > 0.0f) ? (maxSpeed / maxTurnRate) : 999999.0f; + // determine required turn radius based on our current speed and max turn rate + Real minTurnRadius = WWMath::Div_Safe(maxSpeed, maxTurnRate, 999999.0f); if (timeToTravelThatDist) - *timeToTravelThatDist = minTurnRadius / maxSpeed; + *timeToTravelThatDist = WWMath::Div_Safe(minTurnRadius, maxSpeed, 999999.0f); return minTurnRadius; } @@ -1108,7 +1109,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 +1149,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 2ccaaa00d38..dea0e8e3689 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, 100.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 998825c9648..47e7cf498fd 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 78b44dc99ca..e136a2ec0e0 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) { @@ -649,7 +649,7 @@ UpdateSleepTime MissileAIUpdate::update() Coord3D newPos = *getObject()->getPosition(); if (m_noTurnDistLeft > 0.0f && m_state >= IGNITION) { - Real distThisTurn = sqrtf(sqr(newPos.x-m_prevPos.x) + sqr(newPos.y-m_prevPos.y) + sqr(newPos.z-m_prevPos.z)); + Real distThisTurn = WWMath::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 cfe716f8440..b4ef88d8bed 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 1ece8505529..4d3fad6131b 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. @@ -467,8 +467,8 @@ void RailroadBehavior::playImpactSound(Object *victim, const Coord3D *impactPosi impact.setPosition(impactPosition); if ( theirPhys ) { - vel += fabs(theirPhys->getVelocity()->length()); - mass += fabs(theirPhys->getMass()); + vel += WWMath::Fabs(theirPhys->getVelocity()->length()); + mass += WWMath::Fabs(theirPhys->getMass()); vel /= 2; mass /= 2;//average of him and me @@ -700,7 +700,7 @@ UpdateSleepTime RailroadBehavior::update() if ( m_conductorState == APPLY_BRAKES ) { conductorPullInfo.speed *= modData->m_braking; - if (fabs(conductorPullInfo.speed) < 0.1f) + if (WWMath::Fabs(conductorPullInfo.speed) < 0.1f) { conductorPullInfo.speed = 0; ///////////////////////////////////////( &m_hissySteamSound ); @@ -1233,7 +1233,7 @@ void alignToTerrain( Real angle, const Coord3D& pos, const Coord3D& normal, Matr x.normalize(); } - DEBUG_ASSERTCRASH(fabs(x.x*z.x + x.y*z.y + x.z*z.z)<0.0001,("dot is not zero")); + DEBUG_ASSERTCRASH(WWMath::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 ); @@ -1299,7 +1299,7 @@ void RailroadBehavior::updatePositionTrackDistance( PullInfo *pullerInfo, PullIn trackPosDelta.z = 0; Real dx = pullerInfo->towHitchPosition.x - turnPos.x; Real dy = pullerInfo->towHitchPosition.y - turnPos.y; - Real desiredAngle = atan2(dy, dx); + Real desiredAngle = WWMath::Atan2(dy, dx); Real relAngle = stdAngleDiff(desiredAngle, obj->getTransformMatrix()->Get_Z_Rotation()); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/CleanupHazardUpdate.cpp index 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..e7910856017 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, 0.0f); 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 e7100955fb6..d29b6055388 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/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 f8452289f2d..950d34336c5 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp @@ -531,7 +531,7 @@ UpdateSleepTime ParticleUplinkCannonUpdate::update() Real cxDistance = (factor * data->m_swathOfDeathDistance ) - (data->m_swathOfDeathDistance * 0.5f); //cx is cartesian x //Now calculate the amplitude value. - Real height = sin( radians ); + Real height = 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 3ee2c96c1ff..cf33d2cf4f6 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/PhysicsUpdate.cpp @@ -29,7 +29,7 @@ #include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine // please talk to MDC (x36804) before taking this out -#define NO_DEBUG_CRC +//#define NO_DEBUG_CRC #include "Common/PerfTimer.h" #include "Common/Player.h" @@ -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 ) { @@ -734,8 +734,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; @@ -861,8 +861,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; @@ -941,7 +941,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; } @@ -963,7 +963,7 @@ Real PhysicsBehavior::getForwardSpeed2D() const Real speedSquared = vx*vx + vy*vy; // DEBUG_ASSERTCRASH( speedSquared != 0, ("zero speedSquared will overflow sqrtf()!") );// lorenzen... sanity check - Real speed = (Real)sqrtf( speedSquared ); + Real speed = (Real)WWMath::Sqrtf( speedSquared ); if (dot >= 0.0f) return speed; @@ -986,7 +986,7 @@ Real PhysicsBehavior::getForwardSpeed3D() const Real dot = vx + vy + vz; - 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; @@ -1009,7 +1009,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; } @@ -1033,7 +1033,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; @@ -1116,9 +1116,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; } @@ -1318,7 +1318,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 @@ -1459,7 +1459,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 fa7883d6335..815b5f123cb 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp @@ -196,11 +196,11 @@ UpdateSleepTime SlavedUpdate::update() if( data->m_repairRatePerSecond > 0.0f ) { BodyModuleInterface *body = master->getBodyModule(); - if( body ) + if (body) { Real health = body->getHealth(); Real maxHealth = body->getMaxHealth(); - healthPercentage = (Int)(health / maxHealth * 100.0f); + healthPercentage = (Int)(WWMath::Div_Safe(health, maxHealth, 0.0f) * 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 c23caf3d715..e6e0ab6fad5 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 8f09c707af2..c1de266f811 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/StealthUpdate.cpp @@ -670,7 +670,7 @@ UpdateSleepTime StealthUpdate::update() m_disguiseHalfpointReached = true; } //Opacity ranges from full to none at midpoint and full again at the end - Real opacity = fabs( 1.0f - (factor * 2.0f) ); + Real opacity = WWMath::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..d7dcf3bc7eb 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, 1.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 475811e44c0..5d6637b1523 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)); } @@ -890,7 +890,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) @@ -916,7 +916,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); @@ -1019,7 +1019,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; @@ -1513,9 +1513,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; } @@ -2128,11 +2128,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 60bae04f186..0258bdd838c 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp @@ -33,6 +33,7 @@ #include "Common/AudioHandleSpecialValues.h" #include "Common/BuildAssistant.h" #include "Common/CRCDebug.h" +#include "Common/Diagnostic/SimulationMathCrc.h" #include "Common/FramePacer.h" #include "Common/GameAudio.h" #include "Common/GameEngine.h" @@ -848,7 +849,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 @@ -3753,6 +3754,16 @@ void GameLogic::update() TheTerrainLogic->UPDATE(); } +#if RUN_MATH_BENCHMARK_REPLAY400_FLAG + static bool s_benchmarkRun = false; + + if (!s_benchmarkRun && m_frame == 400) + { + SimulationMathCrc::runBenchmark(10000); + s_benchmarkRun = true; + } +#endif + // force CRC calculation, so we can keep a cache of the last N CRCs. We do this right where the recorder // would be getting the CRC anyway, so replays can get the CRCs from the exact instant in time as the original. Bool isMPGameOrReplay = (TheRecorder && TheRecorder->isMultiplayer() && getGameMode() != GAME_SHELL && getGameMode() != GAME_NONE); From c55e8227ead92a15e88d6bf7e4f355ba5f7dc81a Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Wed, 19 Aug 2026 19:22:07 +0300 Subject: [PATCH 11/15] refactor(ww3d2): Route per-game WW3D2 and InGameUI math through WWMath --- .../GameEngine/Source/GameClient/InGameUI.cpp | 2 +- .../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 +-- .../GameEngine/Source/GameClient/InGameUI.cpp | 2 +- .../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 +-- 14 files changed, 40 insertions(+), 40 deletions(-) diff --git a/Generals/Code/GameEngine/Source/GameClient/InGameUI.cpp b/Generals/Code/GameEngine/Source/GameClient/InGameUI.cpp index 91c3bec2bf2..58ec09ea83d 100644 --- a/Generals/Code/GameEngine/Source/GameClient/InGameUI.cpp +++ b/Generals/Code/GameEngine/Source/GameClient/InGameUI.cpp @@ -1631,7 +1631,7 @@ void InGameUI::handleBuildPlacements() if (isInForceAttackMode()) { const Real snapRadians = DEG_TO_RADF(45); - angle = WWMath::Round(angle / snapRadians) * snapRadians; + angle = WWMath::Roundf(angle / snapRadians) * snapRadians; } } } diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/camera.cpp b/Generals/Code/Libraries/Source/WWVegas/WW3D2/camera.cpp index 8f838f954a9..376495b2aac 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/camera.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/camera.cpp @@ -769,13 +769,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 26642645d59..c56fefbb256 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp @@ -846,7 +846,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 9f644336998..6352331b073 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/part_emt.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/part_emt.cpp @@ -661,7 +661,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 34b430bacf2..0f174454d6f 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/render2d.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/render2d.cpp @@ -198,8 +198,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() ) { // Global bais setting diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp index e323d96d34d..802972481e2 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp @@ -1664,7 +1664,7 @@ void InGameUI::handleBuildPlacements() if (isInForceAttackMode()) { const Real snapRadians = DEG_TO_RADF(45); - angle = WWMath::Round(angle / snapRadians) * snapRadians; + angle = WWMath::Roundf(angle / snapRadians) * snapRadians; } } } diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/camera.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/camera.cpp index 90332efb9b4..4cc1f37aaab 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/camera.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/camera.cpp @@ -769,13 +769,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 174d98e517e..e7afd0ce75b 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/motchan.cpp @@ -861,7 +861,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 bdab80fac63..6b1d7619429 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/part_emt.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/part_emt.cpp @@ -670,7 +670,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 e8ff2abe59e..ce48fe09744 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2d.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/render2d.cpp @@ -222,8 +222,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() ) { // Global bais setting From 56a9dbf0597e2a3fea12e3578239d9b708c00d85 Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Wed, 19 Aug 2026 19:23:19 +0300 Subject: [PATCH 12/15] refactor(neutronmissile): Route debug blast circle math through WWMath Keeps the GameLogic sources free of direct libm calls after the nuke radius debug draw was added. --- .../Object/Update/NeutronMissileSlowDeathUpdate.cpp | 7 ++++--- .../Object/Update/NeutronMissileSlowDeathUpdate.cpp | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileSlowDeathUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileSlowDeathUpdate.cpp index 654734aa275..c6b355e8a5b 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/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileSlowDeathUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/NeutronMissileSlowDeathUpdate.cpp index 8a3e971fea4..e4bb89c4e05 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 ); From 1085d07a5297a37b270653c61a2435c08ac0ee3c Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Fri, 21 Aug 2026 02:10:11 +0300 Subject: [PATCH 13/15] build(gamemath): Let GameMath keep its own intrinsics default The override was a precaution and never had a measurement behind it. A Windows replay run built with intrinsics enabled produced CRC logs that are byte-identical to the run with them disabled, so the override only cost speed. --- cmake/gamemath.cmake | 3 --- 1 file changed, 3 deletions(-) diff --git a/cmake/gamemath.cmake b/cmake/gamemath.cmake index 57dfaf4adfc..67f732ab45f 100644 --- a/cmake/gamemath.cmake +++ b/cmake/gamemath.cmake @@ -1,6 +1,3 @@ -# FORCE is required to guarantee cross-platform bit-exact determinism. -# Intrinsics would use platform-specific SIMD, breaking CRC parity between architectures. -set(GM_ENABLE_INTRINSICS OFF CACHE BOOL "Disable intrinsics for cross-arch determinism" FORCE) set(GM_ENABLE_TESTS OFF CACHE BOOL "Disable GameMath tests" FORCE) FetchContent_Declare( From 7a4f6f1b7c6585c0a2383667a39d9f3aea73ee5b Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Sat, 22 Aug 2026 02:40:14 +0300 Subject: [PATCH 14/15] bugfix(gamelogic): Guard the remaining Generals divisions Four divisions in Generals were left unguarded while Zero Hour already routed the same places through WWMath::Div_Safe. Fallback values match the Zero Hour side so the two games behave alike. --- .../Source/GameLogic/Object/Behavior/BridgeBehavior.cpp | 2 +- .../Code/GameEngine/Source/GameLogic/Object/Body/ActiveBody.cpp | 2 +- .../Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cpp | 2 +- .../GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/BridgeBehavior.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/BridgeBehavior.cpp index f2af520f00f..6e5c3aa4b00 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, 0.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/Body/ActiveBody.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Body/ActiveBody.cpp index bea29c00a96..050d84c28fb 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Body/ActiveBody.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Body/ActiveBody.cpp @@ -661,7 +661,7 @@ void ActiveBody::setMaxHealth( Real maxHealth, MaxHealthChangeType healthChangeT { //400/500 (80%) + 100 becomes 480/600 (80%) //200/500 (40%) - 100 becomes 160/400 (40%) - Real ratio = m_currentHealth / prevMaxHealth; + Real ratio = WWMath::Div_Safe(m_currentHealth, prevMaxHealth, 1.0f); Real newHealth = maxHealth * ratio; internalChangeHealth( newHealth - m_currentHealth ); break; 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 c5a3eb001f2..015f3701089 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, 100.0f); goalObject->setConstructionPercent( goalObject->getConstructionPercent() + percentProgressThisFrame ); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp index 3b8d84456a8..61cb49a9284 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/SlavedUpdate.cpp @@ -195,7 +195,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, 0.0f) * 100.0f); } } From 47bc6ac92d847471734ca08a3c1f3194f0d4b327 Mon Sep 17 00:00:00 2001 From: Okladnoj Date: Thu, 3 Sep 2026 18:54:37 +0300 Subject: [PATCH 15/15] bugfix(gamelogic): Restore the upstream logic the math routing dropped Routing simulation math through WWMath took three pieces of surrounding logic with it that had nothing to do with math. SpecialPowerModule lost the guard that holds a special power unavailable while its object is still under construction, added upstream in #1218. Without it m_availableOnFrame starts at zero rather than 0xFFFFFFFF when RETAIL_COMPATIBLE_CRC is off, and isReady reports the power ready until the creation callback sets the timer. Both games had it, both lost it. DeliverPayloadAIUpdate lost the explicit maxTurnRate > 0 test around the turn radius division. Div_Safe only stands in for it where deterministic math is compiled in, and only for a divisor of exactly zero, so the retail path was left dividing by zero where it used to fall back to 999999. Removing that test changes game logic rather than math, so the retail form is now the original expression and the guarded division sits in the other branch. ObjectCreationList had NO_DEBUG_CRC commented out, which lets CRCDebug.h define DEBUG_CRC and wakes the 27 DUMP calls further down the file in any build with debug logging. --- .../GameLogic/Object/SpecialPower/SpecialPowerModule.cpp | 5 ++++- .../Source/GameLogic/Object/ObjectCreationList.cpp | 2 +- .../GameLogic/Object/SpecialPower/SpecialPowerModule.cpp | 5 ++++- .../Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp | 4 ++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp index 838534795a3..ee0112820dc 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp @@ -98,8 +98,11 @@ SpecialPowerModule::SpecialPowerModule( Thing *thing, const ModuleData *moduleDa : BehaviorModule( thing, moduleData ) { - +#if RETAIL_COMPATIBLE_CRC m_availableOnFrame = 0; +#else + m_availableOnFrame = 0xFFFFFFFF; +#endif m_pausedCount = 0; m_pausedOnFrame = 0; m_pausedPercent = 0.0f; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp index 2e0533a1781..1413be7248f 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp @@ -33,7 +33,7 @@ #define DEFINE_SHADOW_NAMES // for TheShadowNames[] #define DEFINE_WEAPONSLOTTYPE_NAMES -//#define NO_DEBUG_CRC +#define NO_DEBUG_CRC #include "Common/AudioEventRTS.h" #include "Common/DrawModule.h" diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp index 76b35302557..f6ded8447fe 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/SpecialPower/SpecialPowerModule.cpp @@ -99,8 +99,11 @@ SpecialPowerModule::SpecialPowerModule( Thing *thing, const ModuleData *moduleDa : BehaviorModule( thing, moduleData ) { - +#if RETAIL_COMPATIBLE_CRC m_availableOnFrame = 0; +#else + m_availableOnFrame = 0xFFFFFFFF; +#endif m_pausedCount = 0; m_pausedOnFrame = 0; m_pausedPercent = 0.0f; 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 eb0c74947af..9a1a6fe6b00 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp @@ -345,7 +345,11 @@ 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, 999999.0f); +#endif if (timeToTravelThatDist) *timeToTravelThatDist = WWMath::Div_Safe(minTurnRadius, maxSpeed, 999999.0f);