Skip to content

Commit

Permalink
remove GetRelativeSpeed
Browse files Browse the repository at this point in the history
  • Loading branch information
spacek531 committed Nov 5, 2024
1 parent 9a66901 commit d1fa1e6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
5 changes: 0 additions & 5 deletions src/openrct2/ride/RideData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,11 +452,6 @@ TrackDrawerEntry getTrackDrawerEntry(const RideTypeDescriptor& rtd, bool isInver
return descriptor.Regular;
}

int32_t RideTypeDescriptor::GetRelativeBoosterSpeed(const int32_t& absoluteSpeed) const
{
return absoluteSpeed * 2 / LegacyBoosterSettings.BoosterSpeedFactor;
}

int32_t RideTypeDescriptor::GetAbsoluteBoosterSpeed(const int32_t& relativeSpeed) const
{
// BoosterSpeedFactor has valid values of 1, 2, 4 representing a 1/2, 1, and 2 multiplier of relative speed to absolute
Expand Down
3 changes: 2 additions & 1 deletion src/openrct2/ride/Track.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ constexpr uint8_t kRCT2DefaultBlockBrakeSpeed = 2;
constexpr int32_t kBlockBrakeBaseSpeed = 0x20364;
constexpr int32_t kBlockBrakeSpeedOffset = kBlockBrakeBaseSpeed - (kRCT2DefaultBlockBrakeSpeed << 16);
constexpr uint8_t kLegacyBrakeSpeedMultiplier = 2;
constexpr uint8_t kLegacyBrakeSpeedMask = 0b00011110;
constexpr uint8_t kLegacyBrakeSpeedMask = 0b00001111;
constexpr uint8_t kLegacyBrakeSpeedMax = 0b00011110;
constexpr uint8_t kMaximumTrackSpeed = 0b00111111; // 2 high bits reserved for potential future behavior

namespace OpenRCT2
Expand Down
7 changes: 4 additions & 3 deletions src/openrct2/ride/TrackDesign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,12 @@ ResultWithMessage TrackDesign::CreateTrackDesignTrack(TrackDesignState& tds, con
trackFlags = trackElement.element->AsTrack()->GetBrakeBoosterSpeed();
if (track.type == TrackElemType::Booster)
{
trackFlags = ride.GetRideTypeDescriptor().GetRelativeBoosterSpeed(trackFlags);
// convert absolute speed into legacy speed units
trackFlags *= 2 / ride.GetRideTypeDescriptor().LegacyBoosterSettings.BoosterSpeedFactor;
}

// check to ensure the value is serialisable. This warning will not apply to new track design format.
bool tooHigh = trackFlags > kLegacyBrakeSpeedMask;
bool tooHigh = trackFlags > kLegacyBrakeSpeedMax;
bool tooPrecise = trackFlags & 1;
if (tooPrecise || tooHigh)
{
Expand All @@ -253,7 +254,7 @@ ResultWithMessage TrackDesign::CreateTrackDesignTrack(TrackDesignState& tds, con
{
trackFlags += 1;
}
trackFlags = std::min<uint8_t>(trackFlags, kLegacyBrakeSpeedMask);
trackFlags = std::min<uint8_t>(trackFlags, kLegacyBrakeSpeedMax);

trackFlags /= kLegacyBrakeSpeedMultiplier;
trackFlags &= 0xF;
Expand Down
11 changes: 4 additions & 7 deletions src/openrct2/ride/Vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6836,13 +6836,10 @@ void Vehicle::Sub6DBF3E()

static uint8_t GetLegacyBoosterSpeed(uint8_t rawSpeed, RideTypeDescriptor& vehicleRTD, RideTypeDescriptor& trackRTD)
{
auto relativeSpeed = trackRTD.GetRelativeBoosterSpeed(rawSpeed);
relativeSpeed &= kLegacyBrakeSpeedMask;
auto finalSpeed = vehicleRTD.GetAbsoluteBoosterSpeed(relativeSpeed);
auto finalSpeed2 = (rawSpeed * vehicleRTD.LegacyBoosterSettings.BoosterSpeedFactor
/ trackRTD.LegacyBoosterSettings.BoosterSpeedFactor)
& (15 * vehicleRTD.LegacyBoosterSettings.BoosterSpeedFactor);
assert(finalSpeed == finalSpeed2);
// convert between speed regimes and mask to the highest 4 bits
auto finalSpeed = (rawSpeed * vehicleRTD.LegacyBoosterSettings.BoosterSpeedFactor
/ trackRTD.LegacyBoosterSettings.BoosterSpeedFactor)
& (kLegacyBrakeSpeedMask * vehicleRTD.LegacyBoosterSettings.BoosterSpeedFactor);
return finalSpeed;
}

Expand Down

0 comments on commit d1fa1e6

Please sign in to comment.