Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Core/Libraries/Source/Lib/Include/Lib/BaseDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#endif

#if defined(__has_include)
#if __has_include("gmath.h")
#if __has_include(<gmath.h>)
#define HAS_GAMEMATH (1)
#endif
#endif
Expand Down
33 changes: 27 additions & 6 deletions Core/Libraries/Source/Lib/Include/Lib/BaseFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#include <Utility/bit_adapter.h>
#include "BaseDefines.h"

#if USE_DETERMINISTIC_MATH
#include <gmath.h>
#endif

//-----------------------------------------------------------------------------
inline Real rad2deg(Real rad) { return rad * (180/PI); }
inline Real deg2rad(Real rad) { return rad * (PI/180); }
Expand All @@ -46,8 +50,11 @@ __forceinline long fast_float2long_round(float f)
return i;
}

#if RTS_ZEROHOUR && RETAIL_COMPATIBLE_CRC
// super fast float trunc routine, works always (independent of any FPU modes)
// code courtesy of Martin Hoffesommer (grin)
// TheSuperHackers @info The shift count wraps at 32, so magnitudes of 2^32 and larger lose
// bits that are not fractional, and NaN becomes infinity. Retail Zero Hour depends on these results.
__forceinline float fast_float_trunc(float f)
{
#if defined(_MSC_VER) && _MSC_VER < 1300
Expand Down Expand Up @@ -75,6 +82,10 @@ __forceinline float fast_float_trunc(float f)
}

// same here, fast floor function
// TheSuperHackers @info Subtracting almost 1 only floors correctly if the FPU rounds toward zero, but the game
// rounds to nearest (see setFPMode). So negative whole numbers above -2^24 return n-1, for example -2 returns -3.
// Negative values closer to zero than about 3e-8 also return 0 instead of -1.
// Retail Zero Hour depends on these results.
__forceinline float fast_float_floor(float f)
{
static unsigned almost1=(126<<23)|0x7fffff;
Expand All @@ -84,21 +95,31 @@ __forceinline float fast_float_floor(float f)
}

// same here, fast ceil function
// TheSuperHackers @info Adding almost 1 only ceils correctly if the FPU rounds toward zero, but the game
// rounds to nearest (see setFPMode). So positive whole numbers below 2^24 return n+1, for example 2 returns 3.
// Positive values closer to zero than about 3e-8 also return 0 instead of 1.
// Retail Zero Hour depends on these results.
__forceinline float fast_float_ceil(float f)
{
static unsigned almost1=(126<<23)|0x7fffff;
if ( (std::bit_cast<unsigned>(f) &0x80000000)==0)
f+=std::bit_cast<float>(almost1);
return fast_float_trunc(f);
}
#endif // RTS_ZEROHOUR && RETAIL_COMPATIBLE_CRC

// once we've ceiled/floored, trunc and round are identical, and currently, round is faster... (srj)
#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)))
#if RTS_ZEROHOUR && RETAIL_COMPATIBLE_CRC
// once we've ceiled/floored, trunc and round are identical, and currently, round is faster... (srj)
#define REAL_TO_INT_CEIL(x) (fast_float2long_round(fast_float_ceil(x)))
#define REAL_TO_INT_FLOOR(x) (fast_float2long_round(fast_float_floor(x)))
#else
#define REAL_TO_INT_CEIL(x) (fast_float2long_round(fast_float_ceil(x)))
#define REAL_TO_INT_FLOOR(x) (fast_float2long_round(fast_float_floor(x)))
#if USE_DETERMINISTIC_MATH
#define REAL_TO_INT_CEIL(x) (fast_float2long_round(gm_ceilf(x)))
#define REAL_TO_INT_FLOOR(x) (fast_float2long_round(gm_floorf(x)))
#else
#define REAL_TO_INT_CEIL(x) (fast_float2long_round(ceilf(x)))
#define REAL_TO_INT_FLOOR(x) (fast_float2long_round(floorf(x)))
#endif
#endif

//-------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion Core/Libraries/Source/Lib/Trig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "Lib/trig.h"

#if USE_DETERMINISTIC_MATH
#include "gmath.h"
#include <gmath.h>
#endif

Real Sin(Real x)
Expand Down
2 changes: 1 addition & 1 deletion Core/Libraries/Source/WWVegas/WWMath/wwmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#include "Lib/BaseDefines.h"

#if USE_DETERMINISTIC_MATH
#include "gmath.h"
#include <gmath.h>
#endif

/*
Expand Down
Loading