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 24, 2025
1 parent e3929c1 commit 125a425
Show file tree
Hide file tree
Showing 95 changed files with 272 additions and 250 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
8 changes: 4 additions & 4 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 kObjectiveLengthMin = 1000;
static constexpr uint16_t kObjectiveLengthAdjustment = 100;

static constexpr uint16_t kObjectiveExcitementMax = FIXED_2DP(9, 90);
static constexpr uint16_t kObjectiveExcitementMin = FIXED_2DP(4, 00);
static constexpr uint16_t kObjectiveExcitementAdjustment = 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 kObjectiveGuestsMax = 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
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 = -MakeFixed16_2dp(2, 50);
static constexpr auto kRideGForcesRedLateral = MakeFixed16_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
27 changes: 23 additions & 4 deletions src/openrct2/core/FixedPoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,26 @@ 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 factor>
static constexpr T MakeFixedXdp(T whole, uint8_t fraction)
{
return (whole * factor) + fraction;
}

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

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

constexpr fixed16_2dp MakeFixed16_2dp(int16_t whole, uint8_t fraction)
{
return MakeFixed2dp<fixed16_2dp>(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 > MakeFixed16_2dp(5, 00)
|| ride.max_negative_vertical_g < MakeFixed16_2dp(-4, 00)
|| ride.max_lateral_g > MakeFixed16_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 kDummyRTD =
.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
52 changes: 26 additions & 26 deletions src/openrct2/ride/RideRatings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1701,27 +1701,27 @@ static RatingTuple ride_ratings_get_gforce_ratings(const Ride& ride)

// Apply maximum negative G force factor
fixed16_2dp gforce = ride.max_negative_vertical_g;
result.excitement += (std::clamp<fixed16_2dp>(gforce, -FIXED_2DP(2, 50), FIXED_2DP(0, 00)) * -15728) >> 16;
result.intensity += ((gforce - FIXED_2DP(1, 00)) * -52428) >> 16;
result.nausea += ((gforce - FIXED_2DP(1, 00)) * -14563) >> 16;
result.excitement += (std::clamp<fixed16_2dp>(gforce, -MakeRideRating(2, 50), MakeRideRating(0, 00)) * -15728) >> 16;
result.intensity += ((gforce - MakeRideRating(1, 00)) * -52428) >> 16;
result.nausea += ((gforce - MakeRideRating(1, 00)) * -14563) >> 16;

// Apply lateral G force factor
result.excitement += (std::min<fixed16_2dp>(FIXED_2DP(1, 50), ride.max_lateral_g) * 26214) >> 16;
result.excitement += (std::min<fixed16_2dp>(MakeRideRating(1, 50), ride.max_lateral_g) * 26214) >> 16;
result.intensity += ride.max_lateral_g;
result.nausea += (ride.max_lateral_g * 21845) >> 16;

// Very high lateral G force penalty
#ifdef ORIGINAL_RATINGS
if (ride.max_lateral_g > FIXED_2DP(2, 80))
if (ride.max_lateral_g > MakeFixed16_2dp(2, 80))
{
result.intensity += FIXED_2DP(3, 75);
result.nausea += FIXED_2DP(2, 00);
result.intensity += MakeRideRating(3, 75);
result.nausea += MakeRideRating(2, 00);
}
if (ride.max_lateral_g > FIXED_2DP(3, 10))
if (ride.max_lateral_g > MakeFixed16_2dp(3, 10))
{
result.excitement /= 2;
result.intensity += FIXED_2DP(8, 50);
result.nausea += FIXED_2DP(4, 00);
result.intensity += MakeRideRating(8, 50);
result.nausea += MakeRideRating(4, 00);
}
#endif

Expand Down Expand Up @@ -1983,11 +1983,11 @@ static void RideRatingsApplyBonusMotionSimulatorMode(RatingTuple& ratings, const
// Hardcoded until ride mode refactor
if (ride.mode == RideMode::FilmThrillRiders)
{
RideRatingsSet(ratings, RIDE_RATING(3, 25), RIDE_RATING(4, 10), RIDE_RATING(3, 30));
RideRatingsSet(ratings, MakeRideRating(3, 25), MakeRideRating(4, 10), MakeRideRating(3, 30));
}
else
{
RideRatingsSet(ratings, RIDE_RATING(2, 90), RIDE_RATING(3, 50), RIDE_RATING(3, 00));
RideRatingsSet(ratings, MakeRideRating(2, 90), MakeRideRating(3, 50), MakeRideRating(3, 00));
}
}

Expand All @@ -1998,13 +1998,13 @@ static void RideRatingsApplyBonus3DCinemaMode(RatingTuple& ratings, const Ride&
{
default:
case RideMode::MouseTails3DFilm:
RideRatingsSet(ratings, RIDE_RATING(3, 50), RIDE_RATING(2, 40), RIDE_RATING(1, 40));
RideRatingsSet(ratings, MakeRideRating(3, 50), MakeRideRating(2, 40), MakeRideRating(1, 40));
break;
case RideMode::StormChasers3DFilm:
RideRatingsSet(ratings, RIDE_RATING(4, 00), RIDE_RATING(2, 65), RIDE_RATING(1, 55));
RideRatingsSet(ratings, MakeRideRating(4, 00), MakeRideRating(2, 65), MakeRideRating(1, 55));
break;
case RideMode::SpaceRaiders3DFilm:
RideRatingsSet(ratings, RIDE_RATING(4, 20), RIDE_RATING(2, 60), RIDE_RATING(1, 48));
RideRatingsSet(ratings, MakeRideRating(4, 20), MakeRideRating(2, 60), MakeRideRating(1, 48));
break;
}
}
Expand All @@ -2016,13 +2016,13 @@ static void RideRatingsApplyBonusTopSpinMode(RatingTuple& ratings, const Ride& r
{
default:
case RideMode::Beginners:
RideRatingsSet(ratings, RIDE_RATING(2, 00), RIDE_RATING(4, 80), RIDE_RATING(5, 74));
RideRatingsSet(ratings, MakeRideRating(2, 00), MakeRideRating(4, 80), MakeRideRating(5, 74));
break;
case RideMode::Intense:
RideRatingsSet(ratings, RIDE_RATING(3, 00), RIDE_RATING(5, 75), RIDE_RATING(6, 64));
RideRatingsSet(ratings, MakeRideRating(3, 00), MakeRideRating(5, 75), MakeRideRating(6, 64));
break;
case RideMode::Berserk:
RideRatingsSet(ratings, RIDE_RATING(3, 20), RIDE_RATING(6, 80), RIDE_RATING(7, 94));
RideRatingsSet(ratings, MakeRideRating(3, 20), MakeRideRating(6, 80), MakeRideRating(7, 94));
break;
}
}
Expand Down Expand Up @@ -2229,29 +2229,29 @@ static void RideRatingsApplyRequirementSplashdown(RatingTuple& ratings, const Ri
static RatingTuple ride_ratings_get_excessive_lateral_g_penalty(const Ride& ride)
{
RatingTuple result{};
if (ride.max_lateral_g > FIXED_2DP(2, 80))
if (ride.max_lateral_g > MakeFixed16_2dp(2, 80))
{
result.intensity = FIXED_2DP(3, 75);
result.nausea = FIXED_2DP(2, 00);
result.intensity = MakeRideRating(3, 75);
result.nausea = MakeRideRating(2, 00);
}

if (ride.max_lateral_g > FIXED_2DP(3, 10))
if (ride.max_lateral_g > MakeFixed16_2dp(3, 10))
{
// Remove half of the ride_ratings_get_gforce_ratings
result.excitement = (ride.max_positive_vertical_g * 5242) >> 16;

// Apply maximum negative G force factor
fixed16_2dp gforce = ride.max_negative_vertical_g;
result.excitement += (std::clamp<fixed16_2dp>(gforce, -FIXED_2DP(2, 50), FIXED_2DP(0, 00)) * -15728) >> 16;
result.excitement += (std::clamp<fixed16_2dp>(gforce, -MakeRideRating(2, 50), MakeRideRating(0, 00)) * -15728) >> 16;

// Apply lateral G force factor
result.excitement += (std::min<fixed16_2dp>(FIXED_2DP(1, 50), ride.max_lateral_g) * 26214) >> 16;
result.excitement += (std::min<fixed16_2dp>(MakeRideRating(1, 50), ride.max_lateral_g) * 26214) >> 16;

// Remove half of the ride_ratings_get_gforce_ratings
result.excitement /= 2;
result.excitement *= -1;
result.intensity = FIXED_2DP(12, 25);
result.nausea = FIXED_2DP(6, 00);
result.intensity = MakeRideRating(12, 25);
result.nausea = MakeRideRating(6, 00);
}
return result;
}
Expand Down
7 changes: 5 additions & 2 deletions src/openrct2/ride/RideRatings.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ namespace OpenRCT2
}

// Convenience function for writing ride ratings. The result is a 16 bit signed
// integer. To create the ride rating 3.65 type RIDE_RATING(3,65)
#define RIDE_RATING(whole, fraction) FIXED_2DP(whole, fraction)
// integer. To create the ride rating 3.65 type MakeRideRating(3, 65).
constexpr ride_rating MakeRideRating(int16_t whole, uint8_t fraction)
{
return MakeFixed2dp<ride_rating>(whole, fraction);
}
constexpr ride_rating kRideRatingUndefined = 0xFFFFu;

#pragma pack(push, 1)
Expand Down
4 changes: 2 additions & 2 deletions src/openrct2/ride/Vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2358,8 +2358,8 @@ static void test_reset(Ride& ride, StationIndex curStation)
ride.average_speed = 0;
ride.current_test_segment = 0;
ride.average_speed_test_timeout = 0;
ride.max_positive_vertical_g = FIXED_2DP(1, 0);
ride.max_negative_vertical_g = FIXED_2DP(1, 0);
ride.max_positive_vertical_g = MakeFixed16_2dp(1, 0);
ride.max_negative_vertical_g = MakeFixed16_2dp(1, 0);
ride.max_lateral_g = 0;
ride.previous_vertical_g = 0;
ride.previous_lateral_g = 0;
Expand Down
Loading

0 comments on commit 125a425

Please sign in to comment.