Skip to content

Commit 9daa569

Browse files
committed
feat: Replace WWMath::Cos/Sin with CosTrig/SinTrig in game logic (Generals + GeneralsMD)
All game logic files that originally used global Cos()/Sin() from Trig.cpp now use WWMath::CosTrig()/SinTrig() which preserves cosf()/sinf() behavior without USE_DETERMINISTIC_MATH, and routes through gm_cosf()/gm_sinf() when deterministic math is enabled.
1 parent d28bcb2 commit 9daa569

63 files changed

Lines changed: 267 additions & 267 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 4 additions & 4 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)WWMath::Cos(angle);
756-
Real s = (Real)WWMath::Sin(angle);
755+
Real c = (Real)WWMath::CosTrig(angle);
756+
Real s = (Real)WWMath::SinTrig(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)WWMath::Cos(them->getOrientation());
791-
Real s = (Real)WWMath::Sin(them->getOrientation());
790+
Real c = (Real)WWMath::CosTrig(them->getOrientation());
791+
Real s = (Real)WWMath::SinTrig(them->getOrientation());
792792
Real offset = them->getGeometryInfo().getMajorRadius() + themFactoryExitWidth/2.0f;
793793
hisExitPos.x += c*offset;
794794
hisExitPos.y += s*offset;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ void GeometryInfo::get2DBounds(const Coord3D& geomCenter, Real angle, Region2D&
279279

280280
case GEOMETRY_BOX:
281281
{
282-
Real c = (Real)WWMath::Cos(angle);
283-
Real s = (Real)WWMath::Sin(angle);
282+
Real c = (Real)WWMath::CosTrig(angle);
283+
Real s = (Real)WWMath::SinTrig(angle);
284284
Real exc = m_majorRadius*c;
285285
Real eyc = m_minorRadius*c;
286286
Real exs = m_majorRadius*s;
@@ -398,8 +398,8 @@ void GeometryInfo::makeRandomOffsetWithinFootprint(Coord3D& pt) const
398398
#else
399399
Real radius = GameLogicRandomValueReal(0.0f, m_boundingCircleRadius);
400400
Real angle = GameLogicRandomValueReal(-PI, PI);
401-
pt.x = radius * WWMath::Cos(angle);
402-
pt.y = radius * WWMath::Sin(angle);
401+
pt.x = radius * WWMath::CosTrig(angle);
402+
pt.y = radius * WWMath::SinTrig(angle);
403403
pt.z = 0.0f;
404404
#endif
405405
break;

Generals/Code/GameEngine/Source/Common/Thing/Thing.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ const Coord3D* Thing::getUnitDirectionVector2D() const
109109
if (!(m_cacheFlags & VALID_DIRVECTOR))
110110
{
111111
Real angle = getOrientation();
112-
m_cachedDirVector.x = WWMath::Cos( angle );
113-
m_cachedDirVector.y = WWMath::Sin( angle );
112+
m_cachedDirVector.x = WWMath::CosTrig( angle );
113+
m_cachedDirVector.y = WWMath::SinTrig( angle );
114114
m_cachedDirVector.z = 0;
115115
m_cacheFlags |= VALID_DIRVECTOR;
116116
}
@@ -229,8 +229,8 @@ void Thing::setOrientation( Real angle )
229229
z.y = 0.0f;
230230
z.z = 1.0f;
231231

232-
u.x = WWMath::Cos(angle);
233-
u.y = WWMath::Sin(angle);
232+
u.x = WWMath::CosTrig(angle);
233+
u.y = WWMath::SinTrig(angle);
234234
u.z = 0.0f;
235235

236236
y.crossProduct( &z, &u, &y );

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 + (WWMath::Sin(angle) * radius);
1843-
posOut.y = tempCtr.y + (WWMath::Cos(angle) * radius);
1842+
posOut.x = tempCtr.x + (WWMath::SinTrig(angle) * radius);
1843+
posOut.y = tempCtr.y + (WWMath::CosTrig(angle) * radius);
18441844

18451845
}
18461846

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 = WWMath::Sin(angle);
667-
Real c = WWMath::Cos(angle);
666+
Real s = WWMath::SinTrig(angle);
667+
Real c = WWMath::CosTrig(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 = WWMath::Sin(angle);
1033-
Real c = WWMath::Cos(angle);
1032+
Real s = WWMath::SinTrig(angle);
1033+
Real c = WWMath::CosTrig(angle);
10341034

10351035
cur = list;
10361036
while (cur) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,8 @@ StateReturnType AIRappelState::update()
604604
bldg->getGeometryInfo().getBoundingCircleRadius());
605605
Real angle = GameLogicRandomValueReal( PI, 2*PI );//Downish.
606606
Coord3D startPosition = *bldg->getPosition();
607-
startPosition.x += offset * WWMath::Cos( angle );
608-
startPosition.y += offset * WWMath::Sin( angle );
607+
startPosition.x += offset * WWMath::CosTrig( angle );
608+
startPosition.y += offset * WWMath::SinTrig( angle );
609609
startPosition.z = TheTerrainLogic->getGroundHeight( startPosition.x, startPosition.y );
610610

611611
obj->setPosition( &startPosition );
@@ -3804,8 +3804,8 @@ void AIFollowWaypointPathState::computeGoal(Bool useGroupOffsets)
38043804
dy = dest.y - m_priorWaypoint->getLocation()->y;
38053805
angle = WWMath::Atan2(dy, dx);
38063806
Real deltaAngle = angle - m_angle;
3807-
Real s = WWMath::Sin(deltaAngle);
3808-
Real c = WWMath::Cos(deltaAngle);
3807+
Real s = WWMath::SinTrig(deltaAngle);
3808+
Real c = WWMath::CosTrig(deltaAngle);
38093809
Real x = m_groupOffset.x * c - m_groupOffset.y * s;
38103810
Real y = m_groupOffset.y * c + m_groupOffset.x * s;
38113811
m_groupOffset.x = x;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,8 @@ Bridge::Bridge(Object *bridgeObj)
339339
Real halfsizeY = bridgeObj->getGeometryInfo().getMinorRadius();
340340
m_bridgeInfo.bridgeWidth = 2*halfsizeY;
341341

342-
Real c = (Real)WWMath::Cos(angle);
343-
Real s = (Real)WWMath::Sin(angle);
342+
Real c = (Real)WWMath::CosTrig(angle);
343+
Real s = (Real)WWMath::SinTrig(angle);
344344

345345
m_bridgeInfo.fromLeft.set(pos->x-halfsizeX*c-halfsizeY*s, pos->y + halfsizeY*c - halfsizeX*s, pos->z);
346346
m_bridgeInfo.toLeft.set(pos->x+halfsizeX*c-halfsizeY*s, pos->y + halfsizeY*c + halfsizeX*s, pos->z);
@@ -1471,8 +1471,8 @@ void makeAlignToNormalMatrix( Real angle, const Coord3D& pos, const Coord3D& nor
14711471
that WWMath::Atan2(xvec.y, xvec.x) == angle. So we must construct
14721472
the matrix carefully to ensure this!
14731473
*/
1474-
x.x = WWMath::Cos( angle );
1475-
x.y = WWMath::Sin( angle );
1474+
x.x = WWMath::CosTrig( angle );
1475+
x.y = WWMath::SinTrig( angle );
14761476
x.z = 0.0f;
14771477
//x.normalize(); -- redundant; is normalized by definition
14781478

@@ -2652,8 +2652,8 @@ void TerrainLogic::flattenTerrain(Object *obj)
26522652
Real halfsizeY = obj->getGeometryInfo().getMinorRadius();
26532653

26542654

2655-
Real c = (Real)WWMath::Cos(angle);
2656-
Real s = (Real)WWMath::Sin(angle);
2655+
Real c = (Real)WWMath::CosTrig(angle);
2656+
Real s = (Real)WWMath::SinTrig(angle);
26572657

26582658
Vector3 topLeft(pos->x-halfsizeX*c-halfsizeY*s, pos->y + halfsizeY*c - halfsizeX*s, 0);
26592659
Vector3 topRight(pos->x+halfsizeX*c-halfsizeY*s, pos->y + halfsizeY*c + halfsizeX*s, 0);

Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/DumbProjectileBehavior.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,10 @@ static Bool calcTrajectory(
225225
// calc the horiz-speed & time for each.
226226
// note that time can only be negative for 90<angle<270, and since we
227227
// ruled those out above, we're gold.
228-
sinPitches[0] = WWMath::Sin(pitches[0]);
229-
sinPitches[1] = WWMath::Sin(pitches[1]);
230-
cosPitches[0] = WWMath::Cos(pitches[0]);
231-
cosPitches[1] = WWMath::Cos(pitches[1]);
228+
sinPitches[0] = WWMath::SinTrig(pitches[0]);
229+
sinPitches[1] = WWMath::SinTrig(pitches[1]);
230+
cosPitches[0] = WWMath::CosTrig(pitches[0]);
231+
cosPitches[1] = WWMath::CosTrig(pitches[1]);
232232
Real t0 = (horizDist / (velocity * cosPitches[0]));
233233
Real t1 = (horizDist / (velocity * cosPitches[1]));
234234

Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/GenerateMinefieldBehavior.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ void GenerateMinefieldBehavior::placeMinesAroundCircle(const Coord3D& pos, Real
304304
for (Real angle = 0; angle < angleLim; angle += angleInc)
305305
{
306306
Coord3D pt;
307-
pt.x = pos.x + radius * WWMath::Cos(angle);
308-
pt.y = pos.y + radius * WWMath::Sin(angle);
307+
pt.x = pos.x + radius * WWMath::CosTrig(angle);
308+
pt.y = pos.y + radius * WWMath::SinTrig(angle);
309309
pt.z = TheTerrainLogic->getGroundHeight( pt.x, pt.y );
310310
offsetBySmallRandomAmount(pt, mineJitter);
311311
placeMineAt(pt, mineTemplate, team, obj);

Generals/Code/GameEngine/Source/GameLogic/Object/Behavior/ParkingPlaceBehavior.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,8 @@ Bool ParkingPlaceBehavior::reserveSpace(ObjectID id, Real parkingOffset, Parking
327327
info->parkingSpace = d->m_parkInHangars ? ppi->m_hangarStart : ppi->m_location;
328328
if (parkingOffset != 0.0f)
329329
{
330-
info->parkingSpace.x += parkingOffset * WWMath::Cos(ppi->m_orientation);
331-
info->parkingSpace.y += parkingOffset * WWMath::Sin(ppi->m_orientation);
330+
info->parkingSpace.x += parkingOffset * WWMath::CosTrig(ppi->m_orientation);
331+
info->parkingSpace.y += parkingOffset * WWMath::SinTrig(ppi->m_orientation);
332332
}
333333
info->runwayPrep = ppi->m_prep;
334334
info->parkingOrientation = d->m_parkInHangars ? ppi->m_hangarStartOrient : ppi->m_orientation;

0 commit comments

Comments
 (0)