Skip to content

Commit 1898abd

Browse files
committed
Move fixed-point PI into precision-specific template constants
1 parent 449979e commit 1898abd

3 files changed

Lines changed: 21 additions & 20 deletions

File tree

src/fixed.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class fixedf {
1313
public:
1414
static const int FRAC = FRAC_BITS;
1515
static const Uint64 MASK = (Uint64(1UL) << FRAC_BITS) - 1;
16+
static const fixedf PI;
1617

1718
fixedf() :
1819
v(0) {}

src/galaxy/CustomSystem.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,9 +1125,9 @@ void CustomSystemsDatabase::RunLuaSystemSanityChecks(CustomSystem *csys)
11251125
star_B->m_inclination = star_A->m_inclination;
11261126
star_B->m_argOfPeriapsis = star_A->m_argOfPeriapsis;
11271127

1128-
star_B->m_orbitalPhaseAtStart = star_A->m_orbitalPhaseAtStart + FIXED_PI;
1129-
if (star_B->m_orbitalPhaseAtStart > fixed(2, 1) * FIXED_PI)
1130-
star_B->m_orbitalPhaseAtStart -= fixed(2, 1) * FIXED_PI;
1128+
star_B->m_orbitalPhaseAtStart = star_A->m_orbitalPhaseAtStart + fixed::PI;
1129+
if (star_B->m_orbitalPhaseAtStart > fixed(2, 1) * fixed::PI)
1130+
star_B->m_orbitalPhaseAtStart -= fixed(2, 1) * fixed::PI;
11311131
}
11321132
}
11331133
}

src/galaxy/StarSystemGenerator.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,19 +1147,19 @@ SystemBody *StarSystemRandomGenerator::MakeBodyInOrbitSlice(Random &rand, StarSy
11471147
planet->m_rotationPeriod = fixed(rand.Int32(1, 200), 24);
11481148

11491149
// longitude of ascending node
1150-
planet->m_orbitalOffset = rand.Fixed() * 2 * FIXED_PI;
1150+
planet->m_orbitalOffset = rand.Fixed() * 2 * fixed::PI;
11511151
// inclination in the hemisphere above the equator, low probability of high-inclination orbits
11521152
fixed incl_scale = rand.Fixed() * fixed(666, 1000);
1153-
planet->m_inclination = rand.NormFixed().Abs() * incl_scale * FIXED_PI * fixed(1, 2);
1153+
planet->m_inclination = rand.NormFixed().Abs() * incl_scale * fixed::PI * fixed(1, 2);
11541154
// argument of periapsis, interval -PI .. PI
1155-
planet->m_argOfPeriapsis = rand.NormFixed() * FIXED_PI;
1155+
planet->m_argOfPeriapsis = rand.NormFixed() * fixed::PI;
11561156

11571157
// rare chance of reversed orbit
11581158
if (rand.Fixed() < fixed(1, 20))
1159-
planet->m_inclination = FIXED_PI - planet->m_inclination;
1159+
planet->m_inclination = fixed::PI - planet->m_inclination;
11601160

11611161
// true anomaly as rotation beyond periapsis
1162-
planet->m_orbitalPhaseAtStart = rand.Fixed() * 2 * FIXED_PI;
1162+
planet->m_orbitalPhaseAtStart = rand.Fixed() * 2 * fixed::PI;
11631163

11641164
planet->SetOrbitFromParameters();
11651165
planet->SetAtmFromParameters();
@@ -1271,10 +1271,10 @@ void StarSystemRandomGenerator::MakeBinaryPair(SystemBody *a, SystemBody *b, fix
12711271
b->m_orbit.SetPlane(matrix3x3d::RotateY(rotY - M_PI) * matrix3x3d::RotateX(rotX));
12721272

12731273
// store orbit parameters for later use to be accessible in other way than by rotMatrix
1274-
b->m_orbitalPhaseAtStart = b->m_orbitalPhaseAtStart + FIXED_PI;
1275-
b->m_orbitalPhaseAtStart = b->m_orbitalPhaseAtStart > 2 * FIXED_PI ? b->m_orbitalPhaseAtStart - 2 * FIXED_PI : b->m_orbitalPhaseAtStart;
1276-
a->m_orbitalPhaseAtStart = a->m_orbitalPhaseAtStart > 2 * FIXED_PI ? a->m_orbitalPhaseAtStart - 2 * FIXED_PI : a->m_orbitalPhaseAtStart;
1277-
a->m_orbitalPhaseAtStart = a->m_orbitalPhaseAtStart < 0 ? a->m_orbitalPhaseAtStart + 2 * FIXED_PI : a->m_orbitalPhaseAtStart;
1274+
b->m_orbitalPhaseAtStart = b->m_orbitalPhaseAtStart + fixed::PI;
1275+
b->m_orbitalPhaseAtStart = b->m_orbitalPhaseAtStart > 2 * fixed::PI ? b->m_orbitalPhaseAtStart - 2 * fixed::PI : b->m_orbitalPhaseAtStart;
1276+
a->m_orbitalPhaseAtStart = a->m_orbitalPhaseAtStart > 2 * fixed::PI ? a->m_orbitalPhaseAtStart - 2 * fixed::PI : a->m_orbitalPhaseAtStart;
1277+
a->m_orbitalPhaseAtStart = a->m_orbitalPhaseAtStart < 0 ? a->m_orbitalPhaseAtStart + 2 * fixed::PI : a->m_orbitalPhaseAtStart;
12781278
b->m_orbitalOffset = fixed(int(round(rotY * 10000)), 10000);
12791279
a->m_orbitalOffset = fixed(int(round(rotY * 10000)), 10000);
12801280

@@ -1450,8 +1450,8 @@ void PopulateStarSystemGenerator::PositionSettlementOnPlanet(SystemBody *sbody,
14501450

14511451
// store latitude and longitude to equivalent orbital parameters to
14521452
// be accessible easier
1453-
sbody->m_inclination = latitude * FIXED_PI * fixed(1, 2);
1454-
sbody->m_orbitalOffset = longitude * FIXED_PI * 2;
1453+
sbody->m_inclination = latitude * fixed::PI * fixed(1, 2);
1454+
sbody->m_orbitalOffset = longitude * fixed::PI * 2;
14551455

14561456
sbody->SetOrbitFromParameters();
14571457
}
@@ -1714,12 +1714,12 @@ void PopulateStarSystemGenerator::PopulateAddStations(SystemBody *sbody, StarSys
17141714
shells[1] = innerOrbit + ((orbMaxS - innerOrbit) * fixed(1, 2)); // med
17151715
shells[2] = orbMaxS; // high
17161716

1717-
shellIncl[0] = rand.NormFixed() * FIXED_PI;
1718-
shellIncl[1] = rand.NormFixed() * FIXED_PI;
1719-
shellIncl[2] = rand.NormFixed() * FIXED_PI;
1717+
shellIncl[0] = rand.NormFixed() * fixed::PI;
1718+
shellIncl[1] = rand.NormFixed() * fixed::PI;
1719+
shellIncl[2] = rand.NormFixed() * fixed::PI;
17201720
} else {
17211721
shells[0] = shells[1] = shells[2] = innerOrbit;
1722-
shellIncl[0] = shellIncl[1] = shellIncl[2] = rand.NormFixed() * FIXED_PI;
1722+
shellIncl[0] = shellIncl[1] = shellIncl[2] = rand.NormFixed() * fixed::PI;
17231723
}
17241724

17251725
Uint32 orbitIdx = 0;
@@ -1751,9 +1751,9 @@ void PopulateStarSystemGenerator::PopulateAddStations(SystemBody *sbody, StarSys
17511751
// slightly random min/max orbital distance
17521752
sp->m_eccentricity = rand.NormFixed().Abs() * fixed(1, 8);
17531753
// perturb the orbital plane to avoid all stations falling in line with each other
1754-
sp->m_inclination = currOrbitIncl + rand.NormFixed() * fixed(1, 4) * FIXED_PI;
1754+
sp->m_inclination = currOrbitIncl + rand.NormFixed() * fixed(1, 4) * fixed::PI;
17551755
// station spacing around the primary body
1756-
sp->m_argOfPeriapsis = rand.Fixed() * FIXED_PI * 2;
1756+
sp->m_argOfPeriapsis = rand.Fixed() * fixed::PI * 2;
17571757
// TODO: no axial tilt for stations / axial tilt in general is strangely modeled
17581758
sp->m_axialTilt = fixed();
17591759

0 commit comments

Comments
 (0)