Skip to content

Commit 64ff831

Browse files
committed
fix: Route GameLogic trig calls and base trig functions through WWMath
1 parent 1c5613d commit 64ff831

38 files changed

Lines changed: 145 additions & 139 deletions

Generals/Code/GameEngine/Source/Common/System/BuildAssistant.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -752,8 +752,8 @@ Bool BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos,
752752
if (myFactoryExitWidth>0) {
753753
myExitPos = *worldPos;
754754
checkMyExit = true;
755-
Real c = (Real)cos(angle);
756-
Real s = (Real)sin(angle);
755+
Real c = (Real)Cos(angle);
756+
Real s = (Real)Sin(angle);
757757
Real offset = build->getTemplateGeometryInfo().getMajorRadius() + myFactoryExitWidth/2.0f;
758758
myExitPos.x += c*offset;
759759
myExitPos.y += s*offset;
@@ -787,8 +787,8 @@ Bool BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos,
787787
if (themFactoryExitWidth>0) {
788788
hisExitPos = *them->getPosition();
789789
checkHisExit = true;
790-
Real c = (Real)cos(them->getOrientation());
791-
Real s = (Real)sin(them->getOrientation());
790+
Real c = (Real)Cos(them->getOrientation());
791+
Real s = (Real)Sin(them->getOrientation());
792792
Real offset = them->getGeometryInfo().getMajorRadius() + themFactoryExitWidth/2.0f;
793793
hisExitPos.x += c*offset;
794794
hisExitPos.y += s*offset;
@@ -1405,7 +1405,7 @@ Bool BuildAssistant::moveObjectsForConstruction( const ThingTemplate *whatToBuil
14051405
Bool anyUnmovables = false;
14061406
MemoryPoolObjectHolder hold( iter );
14071407

1408-
Real radius = sqrt(pow(gi.getMajorRadius(), 2) + pow(gi.getMinorRadius(), 2));
1408+
Real radius = Sqrt(pow(gi.getMajorRadius(), 2) + pow(gi.getMinorRadius(), 2));
14091409
radius *= 1.4f; // Fudge the distance,
14101410

14111411
for( Object *them = iter->first(); them; them = iter->next() )

Generals/Code/GameEngine/Source/Common/System/Geometry.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,17 @@ void GeometryInfo::calcPitches(const Coord3D& thisPos, const GeometryInfo& that,
173173
Coord3D thisCenter;
174174
getCenterPosition(thisPos, thisCenter);
175175

176-
Real dxy = sqrt(sqr(thatPos.x - thisCenter.x) + sqr(thatPos.y - thisCenter.y));
176+
Real dxy = Sqrt(sqr(thatPos.x - thisCenter.x) + sqr(thatPos.y - thisCenter.y));
177177

178178
Real dz;
179179

180180
/** @todo srj -- this could be better, by calcing it for all the corners, not just top-center
181181
and bottom-center... oh well */
182182
dz = (thatPos.z + that.getMaxHeightAbovePosition()) - thisCenter.z;
183-
maxPitch = atan2(dz, dxy);
183+
maxPitch = Atan2(dz, dxy);
184184

185185
dz = (thatPos.z - that.getMaxHeightBelowPosition()) - thisCenter.z;
186-
minPitch = atan2(dz, dxy);
186+
minPitch = Atan2(dz, dxy);
187187
}
188188

189189
//=============================================================================
@@ -279,8 +279,8 @@ void GeometryInfo::get2DBounds(const Coord3D& geomCenter, Real angle, Region2D&
279279

280280
case GEOMETRY_BOX:
281281
{
282-
Real c = (Real)cos(angle);
283-
Real s = (Real)sin(angle);
282+
Real c = (Real)Cos(angle);
283+
Real s = (Real)Sin(angle);
284284
Real exc = m_majorRadius*c;
285285
Real eyc = m_minorRadius*c;
286286
Real exs = m_majorRadius*s;
@@ -329,7 +329,7 @@ void GeometryInfo::clipPointToFootprint(const Coord3D& geomCenter, Coord3D& ptTo
329329
{
330330
Real dx = ptToClip.x - geomCenter.x;
331331
Real dy = ptToClip.y - geomCenter.y;
332-
Real radius = sqrt(sqr(dx) + sqr(dy));
332+
Real radius = Sqrt(sqr(dx) + sqr(dy));
333333
if (radius > m_majorRadius)
334334
{
335335
Real ratio = m_majorRadius / radius;
@@ -361,7 +361,7 @@ Bool GeometryInfo::isPointInFootprint(const Coord3D& geomCenter, const Coord3D&
361361
{
362362
Real dx = pt.x - geomCenter.x;
363363
Real dy = pt.y - geomCenter.y;
364-
Real radius = sqrt(sqr(dx) + sqr(dy));
364+
Real radius = Sqrt(sqr(dx) + sqr(dy));
365365
return (radius <= m_majorRadius);
366366
break;
367367
}
@@ -506,8 +506,8 @@ void GeometryInfo::calcBoundingStuff()
506506

507507
case GEOMETRY_BOX:
508508
{
509-
m_boundingCircleRadius = sqrt(sqr(m_majorRadius) + sqr(m_minorRadius));
510-
m_boundingSphereRadius = sqrt(sqr(m_majorRadius) + sqr(m_minorRadius) + sqr(m_height*0.5));
509+
m_boundingCircleRadius = Sqrt(sqr(m_majorRadius) + sqr(m_minorRadius));
510+
m_boundingSphereRadius = Sqrt(sqr(m_majorRadius) + sqr(m_minorRadius) + sqr(m_height*0.5));
511511
break;
512512
}
513513
};

Generals/Code/GameEngine/Source/Common/System/Trig.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
#include "Lib/BaseType.h"
3636
#include "Lib/trig.h"
37+
#include "WWMath/wwmath.h"
3738

3839
#define TWOPI 6.28318530718f
3940
#define DEG2RAD 0.0174532925199f
@@ -48,32 +49,37 @@
4849

4950
Real Sin(Real x)
5051
{
51-
return sinf(x);
52+
return WWMath::Sin(x);
5253
}
5354

5455
Real Cos(Real x)
5556
{
56-
return cosf(x);
57+
return WWMath::Cos(x);
5758
}
5859

5960
Real Tan(Real x)
6061
{
61-
return tanf(x);
62+
return WWMath::Tan(x);
6263
}
6364

6465
Real ACos(Real x)
6566
{
66-
return acosf(x);
67+
return WWMath::Acos(x);
6768
}
6869

6970
Real ASin(Real x)
7071
{
71-
return asinf(x);
72+
return WWMath::Asin(x);
7273
}
7374

7475
Real Atan2(Real y, Real x)
7576
{
76-
return atan2f(y, x);
77+
return WWMath::Atan2(y, x);
78+
}
79+
80+
Real Sqrt(Real x)
81+
{
82+
return WWMath::Sqrt(x);
7783
}
7884

7985
#ifdef REGENERATE_TRIG_TABLES

Generals/Code/GameEngine/Source/GameLogic/AI/AI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ Object *AI::findClosestEnemy( const Object *me, Real range, UnsignedInt qualifie
709709
}
710710

711711
Real distSqr = ThePartitionManager->getDistanceSquared(me, theEnemy, FROM_BOUNDINGSPHERE_2D);
712-
Real dist = sqrt(distSqr);
712+
Real dist = Sqrt(distSqr);
713713
Int modifier = dist/getAiData()->m_attackPriorityDistanceModifier;
714714
Int modPriority = curPriority-modifier;
715715
if (modPriority < 1)

Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,8 +1839,8 @@ void getHelicopterOffset( Coord3D& posOut, Int idx )
18391839
}
18401840

18411841
Coord3D tempCtr = posOut;
1842-
posOut.x = tempCtr.x + (sin(angle) * radius);
1843-
posOut.y = tempCtr.y + (cos(angle) * radius);
1842+
posOut.x = tempCtr.x + (Sin(angle) * radius);
1843+
posOut.y = tempCtr.y + (Cos(angle) * radius);
18441844

18451845
}
18461846

Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ Object *AIPlayer::buildStructureWithDozer(const ThingTemplate *bldgPlan, BuildLi
640640
dx = dozer->getPosition()->x - pos.x;
641641
dy = dozer->getPosition()->y - pos.y;
642642

643-
Int count = sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2);
643+
Int count = Sqrt(dx*dx+dy*dy)/(PATHFIND_CELL_SIZE_F/2);
644644
if (count<2) count = 2;
645645
Int i;
646646
color.green = 1;
@@ -1245,7 +1245,7 @@ Int AIPlayer::getPlayerSuperweaponValue(Coord3D *center, Int playerNdx, Real rad
12451245
Real dx = center->x - pos.x;
12461246
Real dy = center->y - pos.y;
12471247
if (dx*dx+dy*dy<radSqr) {
1248-
Real dist = sqrt(dx*dx+dy*dy);
1248+
Real dist = Sqrt(dx*dx+dy*dy);
12491249
Real factor = 1.0f - (dist/(2*radius)); // 1.0 in center, 0.5 on edges.
12501250
Real value = pObj->getTemplate()->calcCostToBuild(pPlayer);
12511251
if (pObj->isKindOf(KINDOF_COMMANDCENTER)) {
@@ -2807,7 +2807,7 @@ void AIPlayer::computeCenterAndRadiusOfBase(Coord3D *center, Real *radius)
28072807
Real radSqr = dx*dx+dy*dy;
28082808
if (radSqr>maxRadSqr) maxRadSqr=radSqr;
28092809
}
2810-
*radius = sqrt(maxRadSqr);
2810+
*radius = Sqrt(maxRadSqr);
28112811
}
28122812

28132813
//----------------------------------------------------------------------------------------------------------

Generals/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,8 @@ void AISkirmishPlayer::buildAIBaseDefenseStructure(const AsciiString &thingName,
663663
}
664664

665665
if (angle > PI/3) break;
666-
Real s = sin(angle);
667-
Real c = cos(angle);
666+
Real s = Sin(angle);
667+
Real c = Cos(angle);
668668

669669
// TheSuperHackers @info helmutbuhler 21/04/2025 This debug mutates the code to become CRC incompatible
670670
#if defined(RTS_DEBUG) || !RETAIL_COMPATIBLE_CRC
@@ -1029,8 +1029,8 @@ void AISkirmishPlayer::adjustBuildList(BuildListInfo *list)
10291029

10301030
angle += 3*PI/4;
10311031

1032-
Real s = sin(angle);
1033-
Real c = cos(angle);
1032+
Real s = Sin(angle);
1033+
Real c = Cos(angle);
10341034

10351035
cur = list;
10361036
while (cur) {

Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3575,7 +3575,7 @@ StateReturnType AIAttackMoveToState::update()
35753575
if (distSqr < sqr(ATTACK_CLOSE_ENOUGH_CELLS*PATHFIND_CELL_SIZE_F)) {
35763576
return ret;
35773577
}
3578-
DEBUG_LOG(("AIAttackMoveToState::update Distance from goal %f, retrying.", sqrt(distSqr)));
3578+
DEBUG_LOG(("AIAttackMoveToState::update Distance from goal %f, retrying.", Sqrt(distSqr)));
35793579

35803580
ret = STATE_CONTINUE;
35813581
m_retryCount--;
@@ -3805,16 +3805,16 @@ void AIFollowWaypointPathState::computeGoal(Bool useGroupOffsets)
38053805
if (m_priorWaypoint) {
38063806
dx = dest.x - m_priorWaypoint->getLocation()->x;
38073807
dy = dest.y - m_priorWaypoint->getLocation()->y;
3808-
angle = atan2(dy, dx);
3808+
angle = Atan2(dy, dx);
38093809
Real deltaAngle = angle - m_angle;
3810-
Real s = sin(deltaAngle);
3811-
Real c = cos(deltaAngle);
3810+
Real s = Sin(deltaAngle);
3811+
Real c = Cos(deltaAngle);
38123812
Real x = m_groupOffset.x * c - m_groupOffset.y * s;
38133813
Real y = m_groupOffset.y * c + m_groupOffset.x * s;
38143814
m_groupOffset.x = x;
38153815
m_groupOffset.y = y;
38163816
} else {
3817-
angle = atan2(dy, dx);
3817+
angle = Atan2(dy, dx);
38183818
}
38193819
m_angle = angle;
38203820
#endif

Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ void PolygonTrigger::updateBounds() const
270270
Real halfWidth = (m_bounds.hi.x - m_bounds.lo.x) / 2.0f;
271271
Real halfHeight = (m_bounds.hi.y + m_bounds.lo.y) / 2.0f;
272272

273-
m_radius = sqrt(halfHeight*halfHeight + halfWidth*halfWidth);
273+
m_radius = Sqrt(halfHeight*halfHeight + halfWidth*halfWidth);
274274
}
275275

276276

Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,7 @@ void makeAlignToNormalMatrix( Real angle, const Coord3D& pos, const Coord3D& nor
14681468
/*
14691469
It is extremely important that the resulting matrix is such that
14701470
the xvector points in the angle we specified; specifically,
1471-
that atan2(xvec.y, xvec.x) == angle. So we must construct
1471+
that Atan2(xvec.y, xvec.x) == angle. So we must construct
14721472
the matrix carefully to ensure this!
14731473
*/
14741474
x.x = Cos( angle );
@@ -2369,7 +2369,7 @@ void TerrainLogic::setWaterHeight( const WaterHandle *water, Real height, Real d
23692369
center.z = 0.0f; // irrelavant
23702370

23712371
// the max radius to scan around us is the diagonal of the bounding region
2372-
Real maxDist = sqrt( affectedRegion.width() * affectedRegion.width() +
2372+
Real maxDist = Sqrt( affectedRegion.width() * affectedRegion.width() +
23732373
affectedRegion.height() * affectedRegion.height() );
23742374

23752375
// scan the objects in the area of the water affected

0 commit comments

Comments
 (0)