From 1e07385ff6e26bcd59eeb69462d3376fcb8faf96 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Tue, 21 Oct 2025 21:22:37 +0200 Subject: [PATCH] Use getters for all VehicleGeometry tables --- src/openrct2/ride/Vehicle.cpp | 27 +++++++------- src/openrct2/ride/VehicleGeometry.cpp | 53 +++++++++++++++++++++++++-- src/openrct2/ride/VehicleGeometry.h | 40 +++++--------------- 3 files changed, 73 insertions(+), 47 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 773af388ff..27ad6bd91b 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -2916,8 +2916,9 @@ void Vehicle::UpdateCrashSetup() lastVehicle = trainVehicle; trainVehicle->sub_state = 0; - int32_t trainX = Geometry::kCrashDirectionComponents[trainVehicle->Orientation / 2].x; - int32_t trainY = Geometry::kCrashDirectionComponents[trainVehicle->Orientation / 2].y; + auto crashDirection = Geometry::getCrashDirectionComponents(trainVehicle->Orientation); + int32_t trainX = crashDirection.x; + int32_t trainY = crashDirection.y; auto carLaunchDirection = Geometry::getPitchVector32(trainVehicle->pitch); @@ -3743,7 +3744,7 @@ void Vehicle::UpdateMotionBoatHire() } int32_t edi = (Orientation | (var_35 & 1)) & 0x1F; - loc2 = { x + Geometry::kFreeroamVehicleMovementData[edi].x, y + Geometry::kFreeroamVehicleMovementData[edi].y }; + loc2 = { x + Geometry::getFreeroamVehicleMovementData(edi).x, y + Geometry::getFreeroamVehicleMovementData(edi).y }; if (UpdateMotionCollisionDetection({ loc2, z }, nullptr)) { remaining_distance = 0; @@ -3841,7 +3842,7 @@ void Vehicle::UpdateMotionBoatHire() TrackLocation = { flooredLocation, TrackLocation.z }; } - remaining_distance -= Geometry::kFreeroamVehicleMovementData[edi].distance; + remaining_distance -= Geometry::getFreeroamVehicleMovementData(edi).distance; _vehicleCurPosition.x = loc2.x; _vehicleCurPosition.y = loc2.y; if (remaining_distance < 0x368A) @@ -4916,7 +4917,7 @@ void Vehicle::UpdateSound() sound2_volume = soundIdVolume.volume; // Calculate Sound Vector (used for sound frequency calcs) - int32_t soundDirection = Geometry::kSpriteDirectionToSoundDirection[Orientation]; + int32_t soundDirection = Geometry::getSoundDirectionFromOrientation(Orientation); int32_t soundVector = ((velocity >> 14) * soundDirection) >> 14; soundVector = std::clamp(soundVector, -127, 127); @@ -5024,7 +5025,7 @@ OpenRCT2::Audio::SoundId Vehicle::ProduceScreamSound(const int32_t totalNumPeeps GForces Vehicle::GetGForces() const { int32_t gForceVert = ((static_cast(0x280000)) * Geometry::getPitchVector32(pitch).x) >> 32; - gForceVert = ((static_cast(gForceVert)) * Geometry::kRollHorizontalComponent[EnumValue(roll)]) >> 32; + gForceVert = ((static_cast(gForceVert)) * Geometry::getRollHorizontalComponent(roll)) >> 32; const auto& ted = GetTrackElementDescriptor(GetTrackType()); const int32_t vertFactor = ted.verticalFactor(track_progress); @@ -5180,10 +5181,10 @@ int32_t Vehicle::UpdateMotionDodgems() CoordsXYZ location = { x, y, z }; - location.x += Geometry::kFreeroamVehicleMovementData[oldCollisionDirection].x; - location.y += Geometry::kFreeroamVehicleMovementData[oldCollisionDirection].y; - location.x += Geometry::kFreeroamVehicleMovementData[oldCollisionDirection + 1].x; - location.y += Geometry::kFreeroamVehicleMovementData[oldCollisionDirection + 1].y; + location.x += Geometry::getFreeroamVehicleMovementData(oldCollisionDirection).x; + location.y += Geometry::getFreeroamVehicleMovementData(oldCollisionDirection).y; + location.x += Geometry::getFreeroamVehicleMovementData(oldCollisionDirection + 1).x; + location.y += Geometry::getFreeroamVehicleMovementData(oldCollisionDirection + 1).y; if (collideSprite = DodgemsCarWouldCollideAt(location); !collideSprite.has_value()) { @@ -5207,15 +5208,15 @@ int32_t Vehicle::UpdateMotionDodgems() direction |= var_35 & 1; CoordsXY location = _vehicleCurPosition; - location.x += Geometry::kFreeroamVehicleMovementData[direction].x; - location.y += Geometry::kFreeroamVehicleMovementData[direction].y; + location.x += Geometry::getFreeroamVehicleMovementData(direction).x; + location.y += Geometry::getFreeroamVehicleMovementData(direction).y; if (collideSprite = DodgemsCarWouldCollideAt(location); collideSprite.has_value()) { break; } - remaining_distance -= Geometry::kFreeroamVehicleMovementData[direction].distance; + remaining_distance -= Geometry::getFreeroamVehicleMovementData(direction).distance; _vehicleCurPosition.x = location.x; _vehicleCurPosition.y = location.y; if (remaining_distance < 13962) diff --git a/src/openrct2/ride/VehicleGeometry.cpp b/src/openrct2/ride/VehicleGeometry.cpp index c77eed6e08..d834bb1e84 100644 --- a/src/openrct2/ride/VehicleGeometry.cpp +++ b/src/openrct2/ride/VehicleGeometry.cpp @@ -41,7 +41,7 @@ namespace OpenRCT2::RideVehicle::Geometry static_assert(std::size(kSubpositionTranslationDistances) == 16); /** rct2: 0x009A36C4 */ - constexpr auto kFreeroamVehicleMovementData = std::to_array({ + const auto kFreeroamVehicleMovementData = std::to_array({ { -1, 0, 8716 }, { -1, 0, 8716 }, { -1, 0, 8716 }, { -1, 1, 12327 }, { -1, 1, 12327 }, { -1, 1, 12327 }, { 0, 1, 8716 }, { -1, 1, 12327 }, { 0, 1, 8716 }, { 0, 1, 8716 }, { 0, 1, 8716 }, { 1, 1, 12327 }, { 1, 1, 12327 }, { 1, 1, 12327 }, { 1, 0, 8716 }, { 1, 1, 12327 }, { 1, 0, 8716 }, { 1, 0, 8716 }, @@ -186,7 +186,7 @@ namespace OpenRCT2::RideVehicle::Geometry static_assert(std::size(kPitchToDirectionVectorInt32) == EnumValue(VehiclePitch::pitchCount)); /** rct2: 0x009A39C4 */ - constexpr auto kRollHorizontalComponent = std::to_array({ + const auto kRollHorizontalComponent = std::to_array({ 2147483647, 2096579710, 1946281152, 2096579710, 1946281152, 1380375879, 555809667, -372906620, -1231746017, -1859775391, 1380375879, 555809667, -372906620, -1231746017, -1859775391, 0, 2096579710, 1946281152, 2096579710, 1946281152, @@ -194,7 +194,7 @@ namespace OpenRCT2::RideVehicle::Geometry static_assert(std::size(kRollHorizontalComponent) == EnumValue(VehicleRoll::rollCount)); /** rct2: 0x009A3684 */ - constexpr auto kSpriteDirectionToSoundDirection = std::to_array({ + const auto kSpriteDirectionToSoundDirection = std::to_array({ -0x4000, // 0 -0x3000, // 1 -0x2000, // 2 @@ -230,7 +230,7 @@ namespace OpenRCT2::RideVehicle::Geometry }); /** rct2: 0x009A3AC4, 0x009A3AC6 */ - constexpr auto kCrashDirectionComponents = std::to_array({ + const auto kCrashDirectionComponents = std::to_array({ { -256, 0 }, { -236, 98 }, { -181, 181 }, @@ -250,4 +250,49 @@ namespace OpenRCT2::RideVehicle::Geometry }); static_assert(std::size(kCrashDirectionComponents) == 16); + Unk9A36C4Struct getFreeroamVehicleMovementData(uint8_t orientation) + { + return kFreeroamVehicleMovementData[orientation]; + } + + int32_t getRollHorizontalComponent(VehicleRoll roll) + { + return kRollHorizontalComponent[EnumValue(roll)]; + } + + int32_t getSoundDirectionFromOrientation(uint8_t orientation) + { + return kSpriteDirectionToSoundDirection[orientation]; + } + + CoordsXY getCrashDirectionComponents(uint8_t orientation) + { + return kCrashDirectionComponents[orientation / 2]; + } + + int32_t getTranslationDistance(CoordsXYZ distance, bool useReverserDistance) + { + uint8_t index = ((distance.x != 0) << 0) | ((distance.y != 0) << 1) | ((distance.z != 0) << 2) + | ((useReverserDistance) << 3); + return kSubpositionTranslationDistances[index]; + } + + int32_t getAccelerationFromPitch(VehiclePitch pitch) + { + if (pitch >= VehiclePitch::pitchCount) + { + return 0; + } + return kAccelerationFromPitch[EnumValue(pitch)]; + } + + CoordsXY getPitchVector32(VehiclePitch pitch) + { + if (pitch >= VehiclePitch::pitchCount) + { + pitch = VehiclePitch::flat; + } + return kPitchToDirectionVectorInt32[EnumValue(pitch)]; + } + } // namespace OpenRCT2::RideVehicle::Geometry diff --git a/src/openrct2/ride/VehicleGeometry.h b/src/openrct2/ride/VehicleGeometry.h index 8358aa05e4..4d2e64958c 100644 --- a/src/openrct2/ride/VehicleGeometry.h +++ b/src/openrct2/ride/VehicleGeometry.h @@ -17,7 +17,6 @@ namespace OpenRCT2::RideVehicle::Geometry { - struct Unk9A36C4Struct { int16_t x; @@ -25,40 +24,21 @@ namespace OpenRCT2::RideVehicle::Geometry uint32_t distance; }; - extern const std::array kSubpositionTranslationDistances; - extern const std::array kFreeroamVehicleMovementData; - extern const std::array kAccelerationFromPitch; - extern const std::array kPitchToDirectionVectorInt32; - extern const std::array kRollHorizontalComponent; - extern const std::array kSpriteDirectionToSoundDirection; - extern const std::array kCrashDirectionComponents; + Unk9A36C4Struct getFreeroamVehicleMovementData(uint8_t orientation); + + int32_t getRollHorizontalComponent(VehicleRoll roll); + + int32_t getSoundDirectionFromOrientation(uint8_t orientation); + + CoordsXY getCrashDirectionComponents(uint8_t orientation); /** The distance between subposition points in a movement vector. * Squashes vector components to 0 or !0, so vector length is ignored. */ - constexpr int32_t getTranslationDistance(CoordsXYZ distance, bool useReverserDistance) - { - uint8_t index = ((distance.x != 0) << 0) | ((distance.y != 0) << 1) | ((distance.z != 0) << 2) - | ((useReverserDistance) << 3); - return kSubpositionTranslationDistances[index]; - } + int32_t getTranslationDistance(CoordsXYZ distance, bool useReverserDistance); - constexpr int32_t getAccelerationFromPitch(VehiclePitch pitch) - { - if (pitch >= VehiclePitch::pitchCount) - { - return 0; - } - return kAccelerationFromPitch[EnumValue(pitch)]; - } + int32_t getAccelerationFromPitch(VehiclePitch pitch); - constexpr CoordsXY getPitchVector32(VehiclePitch pitch) - { - if (pitch >= VehiclePitch::pitchCount) - { - pitch = VehiclePitch::flat; - } - return kPitchToDirectionVectorInt32[EnumValue(pitch)]; - } + CoordsXY getPitchVector32(VehiclePitch pitch); } // namespace OpenRCT2::RideVehicle::Geometry