Skip to content

Commit 129eae9

Browse files
committed
feat: add WWMath::CosTrig/SinTrig wrappers for backward-compatible Trig.cpp replacement
SinTrig/CosTrig use cosf/sinf (matching original Trig.cpp CRT behavior) without USE_DETERMINISTIC_MATH, and gm_cosf/gm_sinf with it enabled. This preserves CRC compatibility with retail replays in non-deterministic builds while providing cross-platform determinism when USE_DETERMINISTIC_MATH is active.
1 parent 5e3d599 commit 129eae9

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3955,8 +3955,8 @@ Bool PathfindLayer::isPointOnWall(ObjectID *wallPieces, Int numPieces, const Coo
39553955
Real major = obj->getGeometryInfo().getMajorRadius();
39563956
Real minor = (obj->getGeometryInfo().getGeomType() == GEOMETRY_SPHERE) ? obj->getGeometryInfo().getMajorRadius() : obj->getGeometryInfo().getMinorRadius();
39573957

3958-
Real c = (Real)WWMath::Cos(-obj->getOrientation());
3959-
Real s = (Real)WWMath::Sin(-obj->getOrientation());
3958+
Real c = (Real)WWMath::CosTrig(-obj->getOrientation());
3959+
Real s = (Real)WWMath::SinTrig(-obj->getOrientation());
39603960

39613961
// convert to a delta relative to rect ctr
39623962
Real ptx = pt->x - obj->getPosition()->x;
@@ -4223,8 +4223,8 @@ void Pathfinder::classifyFence( Object *obj, Bool insert )
42234223
Real halfsizeY = PATHFIND_CELL_SIZE_F/10.0f;
42244224
Real fenceOffset = obj->getTemplate()->getFenceXOffset();
42254225

4226-
Real c = (Real)WWMath::Cos(angle);
4227-
Real s = (Real)WWMath::Sin(angle);
4226+
Real c = (Real)WWMath::CosTrig(angle);
4227+
Real s = (Real)WWMath::SinTrig(angle);
42284228

42294229
const Real STEP_SIZE = PATHFIND_CELL_SIZE_F * 0.5f; // in theory, should be PATHFIND_CELL_SIZE_F exactly, but needs to be smaller to avoid aliasing problems
42304230
Real ydx = s * STEP_SIZE;
@@ -4431,8 +4431,8 @@ void Pathfinder::internal_classifyObjectFootprint( Object *obj, Bool insert )
44314431
Real halfsizeX = obj->getGeometryInfo().getMajorRadius();
44324432
Real halfsizeY = obj->getGeometryInfo().getMinorRadius();
44334433

4434-
Real c = (Real)WWMath::Cos(angle);
4435-
Real s = (Real)WWMath::Sin(angle);
4434+
Real c = (Real)WWMath::CosTrig(angle);
4435+
Real s = (Real)WWMath::SinTrig(angle);
44364436

44374437
const Real STEP_SIZE = PATHFIND_CELL_SIZE_F * 0.5f; // in theory, should be PATHFIND_CELL_SIZE_F exactly, but needs to be smaller to avoid aliasing problems
44384438
Real ydx = s * STEP_SIZE;

Core/Libraries/Source/WWVegas/WWMath/wwmath.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,19 @@ static WWINLINE float Asin(float val);
157157
static WWINLINE float Log(float x) { return gm_logf(x); }
158158
static WWINLINE float Log10(float x) { return gm_log10f(x); }
159159
static WWINLINE float Pow(float x, float y) { return gm_powf(x, y); }
160+
static WWINLINE float SinTrig(float x) { return gm_sinf(x); }
161+
static WWINLINE float CosTrig(float x) { return gm_cosf(x); }
162+
static WWINLINE float TanTrig(float x) { return gm_tanf(x); }
163+
static WWINLINE float ACosTrig(float x) { return gm_acosf(x); }
164+
static WWINLINE float ASinTrig(float x) { return gm_asinf(x); }
160165
#else
161166
static WWINLINE float Atan(float x) { return static_cast<float>(atan(x)); }
162167
static WWINLINE float Atan2(float y,float x) { return static_cast<float>(atan2(y,x)); }
168+
static WWINLINE float SinTrig(float x) { return sinf(x); }
169+
static WWINLINE float CosTrig(float x) { return cosf(x); }
170+
static WWINLINE float TanTrig(float x) { return tanf(x); }
171+
static WWINLINE float ACosTrig(float x) { return acosf(x); }
172+
static WWINLINE float ASinTrig(float x) { return asinf(x); }
163173
#endif
164174
static WWINLINE float Sign(float val);
165175
static WWINLINE float Ceil(float val) { return ceilf(val); }

0 commit comments

Comments
 (0)