Skip to content

Commit 9d4c78d

Browse files
committed
fix: route GameLogic trig calls through global Atan2/Sin/Cos wrappers
Add Atan2(Real,Real) to trig.h/Trig.cpp alongside existing Sin/Cos/Tan/ACos/ASin. Replace direct atan2/sin/sinf/cos/cosf calls in GameLogic with deterministic global wrappers (Sin, Cos, Atan2) that route through WWMath internally. Remove unnecessary WWMath/wwmath.h includes from GameLogic files.
1 parent 0f85408 commit 9d4c78d

13 files changed

Lines changed: 26 additions & 15 deletions

File tree

Core/Libraries/Include/Lib/trig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ Real Cos(Real);
2828
Real Tan(Real);
2929
Real ACos(Real);
3030
Real ASin(Real x);
31+
Real Atan2(Real y, Real x);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ Real ASin(Real x)
7171
return asinf(x);
7272
}
7373

74+
Real Atan2(Real y, Real x)
75+
{
76+
return atan2f(y, x);
77+
}
78+
7479
#ifdef REGENERATE_TRIG_TABLES
7580
void initTrig()
7681
{

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ Real ASin(Real x)
7272
return WWMath::Asin(x);
7373
}
7474

75+
Real Atan2(Real y, Real x)
76+
{
77+
return WWMath::Atan2(y, x);
78+
}
79+
7580
#ifdef REGENERATE_TRIG_TABLES
7681
void initTrig()
7782
{

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Behavior/SlowDeathBehavior.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ void SlowDeathBehavior::beginSlowDeath(const DamageInfo *damageInfo)
306306
physics->setExtraBounciness(-1.0); // we don't want this guy to bounce at all
307307
physics->setExtraFriction(-3 * SECONDS_PER_LOGICFRAME_REAL); // reduce his ground friction a bit
308308
physics->setAllowBouncing(true);
309-
Real orientation = atan2(force.y, force.x);
309+
Real orientation = Atan2(force.y, force.x);
310310
physics->setAngles(orientation, 0, 0);
311311
obj->getDrawable()->setModelConditionState(MODELCONDITION_EXPLODED_FLAILING);
312312
m_flags |= (1<<FLUNG_INTO_AIR);

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ class DeliverPayloadNugget : public ObjectCreationNugget
357357
}
358358

359359

360-
Real orient = atan2( moveToPos.y - startPos.y, moveToPos.x - startPos.x);
360+
Real orient = Atan2( moveToPos.y - startPos.y, moveToPos.x - startPos.x);
361361
if( m_data.m_distToTarget > 0 )
362362
{
363363
const Real SLOP = 1.5f;
@@ -1108,7 +1108,7 @@ class GenericObjectCreationNugget : public ObjectCreationNugget
11081108

11091109
objUp->applyForce(&force);
11101110
if (m_orientInForceDirection)
1111-
orientation = atan2(force.y, force.x);
1111+
orientation = Atan2(force.y, force.x);
11121112

11131113
}
11141114
}
@@ -1205,7 +1205,7 @@ class GenericObjectCreationNugget : public ObjectCreationNugget
12051205
objUp->applyForce(&force);
12061206
if (m_orientInForceDirection)
12071207
{
1208-
orientation = atan2(force.y, force.x);
1208+
orientation = Atan2(force.y, force.x);
12091209
}
12101210
DUMPREAL(orientation);
12111211
objUp->setAngles(orientation, 0, 0);

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DeliverPayloadAIUpdate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ StateReturnType RecoverFromOffMapState::update() // Success if we should try aga
11101110
enterCoord.z = owner->getPosition()->z;
11111111
owner->setPosition(&enterCoord);
11121112

1113-
Real enterAngle = atan2(ai->getMoveToPos()->y - enterCoord.y, ai->getMoveToPos()->x - enterCoord.x);
1113+
Real enterAngle = Atan2(ai->getMoveToPos()->y - enterCoord.y, ai->getMoveToPos()->x - enterCoord.x);
11141114
owner->setOrientation(enterAngle);
11151115

11161116
PhysicsBehavior* physics = owner->getPhysics();

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ class JetOrHeliTaxiState : public AIMoveOutOfTheWayState
516516

517517
Coord3D intermedPt;
518518
Bool intermed = false;
519-
Real orient = atan2(ppinfo.runwayPrep.y - ppinfo.parkingSpace.y, ppinfo.runwayPrep.x - ppinfo.parkingSpace.x);
519+
Real orient = Atan2(ppinfo.runwayPrep.y - ppinfo.parkingSpace.y, ppinfo.runwayPrep.x - ppinfo.parkingSpace.x);
520520
if (fabs(stdAngleDiff(orient, ppinfo.parkingOrientation)) > PI/128)
521521
{
522522
intermedPt.z = (ppinfo.parkingSpace.z + ppinfo.runwayPrep.z) * 0.5f;
@@ -2297,7 +2297,7 @@ void JetAIUpdate::positionLockon()
22972297
Real dx = getObject()->getPosition()->x - pos.x;
22982298
Real dy = getObject()->getPosition()->y - pos.y;
22992299
if (dx || dy)
2300-
m_lockonDrawable->setOrientation(atan2(dy, dx));
2300+
m_lockonDrawable->setOrientation(Atan2(dy, dx));
23012301

23022302
// the Gaussian sum, to avoid keeping a running total:
23032303
//

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/RailroadGuideAIUpdate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,7 @@ void RailroadBehavior::updatePositionTrackDistance( PullInfo *pullerInfo, PullIn
13041304
trackPosDelta.z = 0;
13051305
Real dx = pullerInfo->towHitchPosition.x - turnPos.x;
13061306
Real dy = pullerInfo->towHitchPosition.y - turnPos.y;
1307-
Real desiredAngle = atan2(dy, dx);
1307+
Real desiredAngle = Atan2(dy, dx);
13081308

13091309

13101310
Real relAngle = stdAngleDiff(desiredAngle, obj->getTransformMatrix()->Get_Z_Rotation());

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DynamicShroudClearingRangeUpdate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ void DynamicShroudClearingRangeUpdate::animateGridDecals()
166166

167167
for (int d = 0; d < GRID_FX_DECAL_COUNT; ++d)
168168
{
169-
pos.x = ctr->x + (sinf(angle) * radius);
170-
pos.y = ctr->y + (cosf(angle) * radius);
169+
pos.x = ctr->x + (Sin(angle) * radius);
170+
pos.y = ctr->y + (Cos(angle) * radius);
171171

172172
pos.x -= ((Int)pos.x)%23;
173173
pos.y -= ((Int)pos.y)%23;

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/FloatUpdate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ UpdateSleepTime FloatUpdate::update()
119119
{
120120

121121
Real angle = INT_TO_REAL(TheGameLogic->getFrame());
122-
Real yaw = sin(angle * 0.0291f) * 0.05f;
123-
Real pitch = sin(angle * 0.0515f) * 0.05f;
122+
Real yaw = Sin(angle * 0.0291f) * 0.05f;
123+
Real pitch = Sin(angle * 0.0515f) * 0.05f;
124124

125125
Matrix3D mx = *draw->getInstanceMatrix();
126126

0 commit comments

Comments
 (0)