From d1fa1e6acf5107bc6d520d486eb0f35359ab0676 Mon Sep 17 00:00:00 2001 From: Spacek531 Date: Mon, 4 Nov 2024 22:07:21 -0800 Subject: [PATCH] remove GetRelativeSpeed --- src/openrct2/ride/RideData.cpp | 5 ----- src/openrct2/ride/Track.h | 3 ++- src/openrct2/ride/TrackDesign.cpp | 7 ++++--- src/openrct2/ride/Vehicle.cpp | 11 ++++------- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/openrct2/ride/RideData.cpp b/src/openrct2/ride/RideData.cpp index 649c39590699..47ebc00e09ea 100644 --- a/src/openrct2/ride/RideData.cpp +++ b/src/openrct2/ride/RideData.cpp @@ -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 diff --git a/src/openrct2/ride/Track.h b/src/openrct2/ride/Track.h index fa07b790e186..a1a685e044bb 100644 --- a/src/openrct2/ride/Track.h +++ b/src/openrct2/ride/Track.h @@ -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 diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index 92d083626891..2a0afa90ff37 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -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) { @@ -253,7 +254,7 @@ ResultWithMessage TrackDesign::CreateTrackDesignTrack(TrackDesignState& tds, con { trackFlags += 1; } - trackFlags = std::min(trackFlags, kLegacyBrakeSpeedMask); + trackFlags = std::min(trackFlags, kLegacyBrakeSpeedMax); trackFlags /= kLegacyBrakeSpeedMultiplier; trackFlags &= 0xF; diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 05ef11cdbe8b..771158dd448a 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -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; }