Skip to content

Commit

Permalink
Change FIXED_XDP from macros to constexprs
Browse files Browse the repository at this point in the history
  • Loading branch information
Gymnasiast committed Jan 22, 2025
1 parent b9486b9 commit b6fa5ec
Show file tree
Hide file tree
Showing 95 changed files with 272 additions and 254 deletions.
2 changes: 1 addition & 1 deletion src/openrct2-ui/interface/Objective.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace OpenRCT2::Ui
ft.Add<int16_t>(objective.NumGuests);
ft.Add<int16_t>(DateGetTotalMonths(MONTH_OCTOBER, objective.Year));
if (objective.Type == OBJECTIVE_FINISH_5_ROLLERCOASTERS)
ft.Add<uint16_t>(objective.MinimumExcitement);
ft.Add<ride_rating>(objective.MinimumExcitement);
else
ft.Add<money64>(objective.Currency);
}
Expand Down
16 changes: 8 additions & 8 deletions src/openrct2-ui/windows/EditorObjectiveOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ namespace OpenRCT2::Ui::Windows
static constexpr uint16_t ObjectiveLengthMin = 1000;
static constexpr uint16_t ObjectiveLengthAdjustment = 100;

static constexpr uint16_t ObjectiveExcitementMax = FIXED_2DP(9, 90);
static constexpr uint16_t ObjectiveExcitementMin = FIXED_2DP(4, 00);
static constexpr uint16_t ObjectiveExcitementAdjustment = FIXED_2DP(0, 10);
static constexpr ride_rating kObjectiveExcitementMax = MakeRideRating(9, 90);
static constexpr ride_rating kObjectiveExcitementMin = MakeRideRating(4, 00);
static constexpr ride_rating kObjectiveExcitementAdjustment = MakeRideRating(0, 10);

// The number has to leave a bit of room for other entities like vehicles, litter and balloons.
static constexpr uint16_t ObjectiveGuestsMax = 50000;
Expand Down Expand Up @@ -413,7 +413,7 @@ namespace OpenRCT2::Ui::Windows
gameState.ScenarioObjective.MinimumLength = 1200;
break;
case OBJECTIVE_FINISH_5_ROLLERCOASTERS:
gameState.ScenarioObjective.MinimumExcitement = FIXED_2DP(6, 70);
gameState.ScenarioObjective.MinimumExcitement = MakeRideRating(6, 70);
break;
case OBJECTIVE_REPAY_LOAN_AND_PARK_VALUE:
gameState.ScenarioObjective.Currency = 50000.00_GBP;
Expand Down Expand Up @@ -524,13 +524,13 @@ namespace OpenRCT2::Ui::Windows
}
break;
case OBJECTIVE_FINISH_5_ROLLERCOASTERS:
if (gameState.ScenarioObjective.MinimumExcitement >= ObjectiveExcitementMax)
if (gameState.ScenarioObjective.MinimumExcitement >= kObjectiveExcitementMax)
{
ContextShowError(STR_CANT_INCREASE_FURTHER, kStringIdNone, {});
}
else
{
gameState.ScenarioObjective.MinimumExcitement += ObjectiveExcitementAdjustment;
gameState.ScenarioObjective.MinimumExcitement += kObjectiveExcitementAdjustment;
Invalidate();
}
break;
Expand Down Expand Up @@ -589,13 +589,13 @@ namespace OpenRCT2::Ui::Windows
}
break;
case OBJECTIVE_FINISH_5_ROLLERCOASTERS:
if (gameState.ScenarioObjective.MinimumExcitement <= ObjectiveExcitementMin)
if (gameState.ScenarioObjective.MinimumExcitement <= kObjectiveExcitementMin)
{
ContextShowError(STR_CANT_REDUCE_FURTHER, kStringIdNone, {});
}
else
{
gameState.ScenarioObjective.MinimumExcitement -= ObjectiveExcitementAdjustment;
gameState.ScenarioObjective.MinimumExcitement -= kObjectiveExcitementAdjustment;
Invalidate();
}
break;
Expand Down
17 changes: 8 additions & 9 deletions src/openrct2-ui/windows/Ride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,8 @@ namespace OpenRCT2::Ui::Windows
};
static_assert(std::size(GraphsYAxisDetails) == 4);

static constexpr auto RIDE_G_FORCES_RED_NEG_VERTICAL = -FIXED_2DP(2, 50);
static constexpr auto RIDE_G_FORCES_RED_LATERAL = FIXED_2DP(2, 80);
static constexpr auto kRideGForcesRedNegVertical = -MakeFixed2dp<fixed16_2dp>(2, 50);
static constexpr auto kRideGForcesRedLateral = MakeFixed2dp<fixed16_2dp>(2, 80);

// Used for sorting the ride type cheat dropdown.
struct RideTypeLabel
Expand Down Expand Up @@ -5648,7 +5648,7 @@ namespace OpenRCT2::Ui::Windows
stringId = STR_INTENSITY_RATING;
if (!RideHasRatings(*ride))
stringId = STR_INTENSITY_RATING_NOT_YET_AVAILABLE;
else if (ride->ratings.intensity >= RIDE_RATING(10, 00))
else if (ride->ratings.intensity >= MakeRideRating(10, 00))
stringId = STR_INTENSITY_RATING_RED;

DrawTextBasic(dpi, screenCoords, stringId, ft);
Expand Down Expand Up @@ -5784,7 +5784,7 @@ namespace OpenRCT2::Ui::Windows
screenCoords.y += kListRowHeight;

// Max. negative vertical G's
stringId = ride->max_negative_vertical_g <= RIDE_G_FORCES_RED_NEG_VERTICAL
stringId = ride->max_negative_vertical_g <= kRideGForcesRedNegVertical
? STR_MAX_NEGATIVE_VERTICAL_G_RED
: STR_MAX_NEGATIVE_VERTICAL_G;
ft = Formatter();
Expand All @@ -5793,8 +5793,7 @@ namespace OpenRCT2::Ui::Windows
screenCoords.y += kListRowHeight;

// Max lateral G's
stringId = ride->max_lateral_g > RIDE_G_FORCES_RED_LATERAL ? STR_MAX_LATERAL_G_RED
: STR_MAX_LATERAL_G;
stringId = ride->max_lateral_g > kRideGForcesRedLateral ? STR_MAX_LATERAL_G_RED : STR_MAX_LATERAL_G;
ft = Formatter();
ft.Add<fixed16_2dp>(ride->max_lateral_g);
DrawTextBasic(dpi, screenCoords, stringId, ft);
Expand Down Expand Up @@ -6163,13 +6162,13 @@ namespace OpenRCT2::Ui::Windows
case GRAPH_VERTICAL:
firstPoint = measurement->vertical[x] + VerticalGraphHeightOffset;
secondPoint = measurement->vertical[x + 1] + VerticalGraphHeightOffset;
intensityThresholdNegative = (RIDE_G_FORCES_RED_NEG_VERTICAL / 8) + VerticalGraphHeightOffset;
intensityThresholdNegative = (kRideGForcesRedNegVertical / 8) + VerticalGraphHeightOffset;
break;
case GRAPH_LATERAL:
firstPoint = measurement->lateral[x] + LateralGraphHeightOffset;
secondPoint = measurement->lateral[x + 1] + LateralGraphHeightOffset;
intensityThresholdPositive = (RIDE_G_FORCES_RED_LATERAL / 8) + LateralGraphHeightOffset;
intensityThresholdNegative = -(RIDE_G_FORCES_RED_LATERAL / 8) + LateralGraphHeightOffset;
intensityThresholdPositive = (kRideGForcesRedLateral / 8) + LateralGraphHeightOffset;
intensityThresholdNegative = -(kRideGForcesRedLateral / 8) + LateralGraphHeightOffset;
break;
default:
LOG_ERROR("Wrong graph type %d", listType);
Expand Down
6 changes: 3 additions & 3 deletions src/openrct2-ui/windows/ViewClipping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ namespace OpenRCT2::Ui::Windows
{
// Height label is Units.
auto ft = Formatter();
ft.Add<fixed16_1dp>(static_cast<fixed16_1dp>(FIXED_1DP(gClipHeight, 0) / 2 - FIXED_1DP(7, 0)));
ft.Add<fixed16_1dp>((MakeFixed1dp<fixed16_1dp>(gClipHeight, 0) / 2 - MakeFixed1dp<fixed16_1dp>(7, 0)));
DrawTextBasic(
dpi, screenCoords, STR_UNIT1DP_NO_SUFFIX, ft,
{ this->colours[0] }); // Printing the value in Height Units.
Expand All @@ -320,15 +320,15 @@ namespace OpenRCT2::Ui::Windows
{
auto ft = Formatter();
ft.Add<fixed32_2dp>(
static_cast<fixed32_2dp>(FIXED_2DP(gClipHeight, 0) / 2 * 1.5f - FIXED_2DP(10, 50)));
MakeFixed2dp<fixed32_2dp>(gClipHeight, 0) / 2 * 1.5f - MakeFixed2dp<fixed32_2dp>(10, 50));
DrawTextBasic(dpi, screenCoords, STR_UNIT2DP_SUFFIX_METRES, ft, { this->colours[0] });
break;
}
case MeasurementFormat::Imperial:
{
auto ft = Formatter();
ft.Add<fixed16_1dp>(
static_cast<fixed16_1dp>(FIXED_1DP(gClipHeight, 0) / 2.0f * 5 - FIXED_1DP(35, 0)));
MakeFixed1dp<fixed16_1dp>(gClipHeight, 0) / 2.0f * 5 - MakeFixed1dp<fixed16_1dp>(35, 0));
DrawTextBasic(dpi, screenCoords, STR_UNIT1DP_SUFFIX_FEET, ft, { this->colours[0] });
break;
}
Expand Down
23 changes: 19 additions & 4 deletions src/openrct2/core/FixedPoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,22 @@ using fixed32_2dp = int32_t;
using fixed64_1dp = int64_t;

// Construct a fixed point number. For example, to create the value 3.65 you
// would write FIXED_2DP(3,65)
#define FIXED_XDP(x, whole, fraction) ((whole) * (10 * (x)) + (fraction))
#define FIXED_1DP(whole, fraction) FIXED_XDP(1, whole, fraction)
#define FIXED_2DP(whole, fraction) FIXED_XDP(10, whole, fraction)
// would write MakeFixed2dp(3, 65)
template<typename T, uint8_t numDecimals>
static constexpr T MakeFixedXdp(T whole, uint8_t fraction)
{
constexpr auto x = 2 ^ (numDecimals);
return ((whole) * (10 * (x)) + (fraction));
}

template<typename T>
constexpr T MakeFixed1dp(T whole, uint8_t fraction)
{
return MakeFixedXdp<T, 1>(whole, fraction);
}

template<typename T>
constexpr T MakeFixed2dp(T whole, uint8_t fraction)
{
return MakeFixedXdp<T, 2>(whole, fraction);
}
19 changes: 10 additions & 9 deletions src/openrct2/entity/Guest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1935,7 +1935,7 @@ OpenRCT2::BitSet<OpenRCT2::Limits::kMaxRidesInPark> Guest::FindRidesToGoOn()
// Always take the tall rides into consideration (realistic as you can usually see them from anywhere in the park)
for (auto& ride : GetRideManager())
{
if (ride.highest_drop_height > 66 || ride.ratings.excitement >= RIDE_RATING(8, 00))
if (ride.highest_drop_height > 66 || ride.ratings.excitement >= MakeRideRating(8, 00))
{
rideConsideration[ride.id.ToUnderlying()] = true;
}
Expand Down Expand Up @@ -2074,7 +2074,7 @@ bool Guest::ShouldGoOnRide(Ride& ride, StationIndex entranceNum, bool atQueue, b
// excitement check and will only do a basic intensity check when they arrive at the ride itself.
if (ride.id == GuestHeadingToRideId)
{
if (ride.ratings.intensity > RIDE_RATING(10, 00) && !GetGameState().Cheats.ignoreRideIntensity)
if (ride.ratings.intensity > MakeRideRating(10, 00) && !GetGameState().Cheats.ignoreRideIntensity)
{
PeepRideIsTooIntense(this, ride, peepAtRide);
return false;
Expand Down Expand Up @@ -2147,7 +2147,7 @@ bool Guest::ShouldGoOnRide(Ride& ride, StationIndex entranceNum, bool atQueue, b
}

// Very nauseous peeps will only go on very gentle rides.
if (ride.ratings.nausea >= FIXED_2DP(1, 40) && Nausea > 160)
if (ride.ratings.nausea >= MakeRideRating(1, 40) && Nausea > 160)
{
ChoseNotToGoOnRide(ride, peepAtRide, false);
return false;
Expand All @@ -2169,8 +2169,9 @@ bool Guest::ShouldGoOnRide(Ride& ride, StationIndex entranceNum, bool atQueue, b

if (!GetGameState().Cheats.ignoreRideIntensity)
{
if (ride.max_positive_vertical_g > FIXED_2DP(5, 00) || ride.max_negative_vertical_g < FIXED_2DP(-4, 00)
|| ride.max_lateral_g > FIXED_2DP(4, 00))
if (ride.max_positive_vertical_g > MakeFixed2dp<fixed16_2dp>(5, 00)
|| ride.max_negative_vertical_g < MakeFixed2dp<fixed16_2dp>(-4, 00)
|| ride.max_lateral_g > MakeFixed2dp<fixed16_2dp>(4, 00))
{
ChoseNotToGoOnRide(ride, peepAtRide, false);
return false;
Expand Down Expand Up @@ -2882,7 +2883,7 @@ static bool PeepShouldGoOnRideAgain(Guest* peep, const Ride& ride)
return false;
if (!RideHasRatings(ride))
return false;
if (ride.ratings.intensity > RIDE_RATING(10, 00) && !GetGameState().Cheats.ignoreRideIntensity)
if (ride.ratings.intensity > MakeRideRating(10, 00) && !GetGameState().Cheats.ignoreRideIntensity)
return false;
if (peep->Happiness < 180)
return false;
Expand Down Expand Up @@ -2927,7 +2928,7 @@ static bool PeepReallyLikedRide(Guest* peep, const Ride& ride)
return false;
if (!RideHasRatings(ride))
return false;
if (ride.ratings.intensity > RIDE_RATING(10, 00) && !GetGameState().Cheats.ignoreRideIntensity)
if (ride.ratings.intensity > MakeRideRating(10, 00) && !GetGameState().Cheats.ignoreRideIntensity)
return false;
return true;
}
Expand Down Expand Up @@ -6320,12 +6321,12 @@ static bool PeepShouldWatchRide(TileElement* tileElement)
return true;
}

if (ride->ratings.excitement >= RIDE_RATING(4, 70))
if (ride->ratings.excitement >= MakeRideRating(4, 70))
{
return true;
}

if (ride->ratings.intensity >= RIDE_RATING(4, 50))
if (ride->ratings.intensity >= MakeRideRating(4, 50))
{
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/management/Award.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ static bool AwardIsDeservedBestCustomDesignedRides(int32_t activeAwardTypes)
continue;
if (ride.lifecycle_flags & RIDE_LIFECYCLE_NOT_CUSTOM_DESIGN)
continue;
if (ride.ratings.excitement < RIDE_RATING(5, 50))
if (ride.ratings.excitement < MakeRideRating(5, 50))
continue;
if (ride.status != RideStatus::Open || (ride.lifecycle_flags & RIDE_LIFECYCLE_CRASHED))
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/ride/RideData.h
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ constexpr RideTypeDescriptor DummyRTD =
.RatingsData =
{
RatingsCalculationType::FlatRide,
{ RIDE_RATING(1, 00), RIDE_RATING(1, 00), RIDE_RATING(1, 00) },
{ MakeRideRating(1, 00), MakeRideRating(1, 00), MakeRideRating(1, 00) },
1,
-1,
false,
Expand Down
Loading

0 comments on commit b6fa5ec

Please sign in to comment.