From 126c7b7e7375ff453807d5d439d6ba12899f4e4f Mon Sep 17 00:00:00 2001 From: Spacek531 Date: Tue, 7 Oct 2025 10:46:53 -0700 Subject: [PATCH 01/14] add VehicleGeometry files --- src/openrct2/libopenrct2.vcxproj | 4 +++- src/openrct2/ride/Vehicle.cpp | 2 ++ src/openrct2/ride/VehicleGeometry.cpp | 17 +++++++++++++++++ src/openrct2/ride/VehicleGeometry.h | 20 ++++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/openrct2/ride/VehicleGeometry.cpp create mode 100644 src/openrct2/ride/VehicleGeometry.h diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index 868b309ddf..d6775939d9 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -543,6 +543,7 @@ + @@ -1092,6 +1093,7 @@ + @@ -1196,4 +1198,4 @@ - + \ No newline at end of file diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index ec2c627e92..9483a361f6 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -62,6 +62,7 @@ #include "TrackData.h" #include "TrainManager.h" #include "VehicleData.h" +#include "VehicleGeometry.h" #include "VehicleSubpositionData.h" #include @@ -71,6 +72,7 @@ using namespace OpenRCT2; using namespace OpenRCT2::Audio; using namespace OpenRCT2::TrackMetaData; using namespace OpenRCT2::Math::Trigonometry; +using namespace OpenRCT2::RideVehicle; static bool vehicle_boat_is_location_accessible(const CoordsXYZ& location); constexpr int16_t kVehicleMaxSpinSpeed = 1536; diff --git a/src/openrct2/ride/VehicleGeometry.cpp b/src/openrct2/ride/VehicleGeometry.cpp new file mode 100644 index 0000000000..962c45f3f5 --- /dev/null +++ b/src/openrct2/ride/VehicleGeometry.cpp @@ -0,0 +1,17 @@ +/***************************************************************************** + * Copyright (c) 2014-2025 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#include "VehicleGeometry.h" + +#include + +namespace OpenRCT2::RideVehicle::Geometry +{ + +} // namespace OpenRCT2::RideVehicle::Geometry diff --git a/src/openrct2/ride/VehicleGeometry.h b/src/openrct2/ride/VehicleGeometry.h new file mode 100644 index 0000000000..c8cfee35fb --- /dev/null +++ b/src/openrct2/ride/VehicleGeometry.h @@ -0,0 +1,20 @@ +/***************************************************************************** + * Copyright (c) 2014-2025 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#pragma once + +#include "../world/Location.hpp" +#include "Angles.h" + +#include + +namespace OpenRCT2::RideVehicle::Geometry +{ + +} // namespace OpenRCT2::RideVehicle::Geometry From 925ed8ded5f7abaf8f36eeedd46410f5df6d54aa Mon Sep 17 00:00:00 2001 From: Spacek531 Date: Mon, 20 Oct 2025 13:49:32 -0700 Subject: [PATCH 02/14] move SubpositionTranslationDistance to VehicleGeometry --- src/openrct2/ride/CableLift.cpp | 5 +++-- src/openrct2/ride/Vehicle.cpp | 4 ++-- src/openrct2/ride/VehicleData.cpp | 25 ------------------------- src/openrct2/ride/VehicleData.h | 1 - src/openrct2/ride/VehicleGeometry.cpp | 25 +++++++++++++++++++++++++ src/openrct2/ride/VehicleGeometry.h | 2 ++ 6 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/openrct2/ride/CableLift.cpp b/src/openrct2/ride/CableLift.cpp index c7466697fc..3f76efbb0a 100644 --- a/src/openrct2/ride/CableLift.cpp +++ b/src/openrct2/ride/CableLift.cpp @@ -21,6 +21,7 @@ #include "Track.h" #include "Vehicle.h" #include "VehicleData.h" +#include "VehicleGeometry.h" using namespace OpenRCT2; @@ -283,7 +284,7 @@ bool Vehicle::CableLiftUpdateTrackMotionForwards() if (nextVehiclePosition.z != _vehicleCurPosition.z) remainingDistanceFlags |= (1 << 2); - remaining_distance -= SubpositionTranslationDistances[remainingDistanceFlags]; + remaining_distance -= OpenRCT2::RideVehicle::Geometry::SubpositionTranslationDistances[remainingDistanceFlags]; _vehicleCurPosition.x = nextVehiclePosition.x; _vehicleCurPosition.y = nextVehiclePosition.y; _vehicleCurPosition.z = nextVehiclePosition.z; @@ -352,7 +353,7 @@ bool Vehicle::CableLiftUpdateTrackMotionBackwards() if (unk.z != _vehicleCurPosition.z) remainingDistanceFlags |= (1 << 2); - remaining_distance += SubpositionTranslationDistances[remainingDistanceFlags]; + remaining_distance += OpenRCT2::RideVehicle::Geometry::SubpositionTranslationDistances[remainingDistanceFlags]; _vehicleCurPosition.x = unk.x; _vehicleCurPosition.y = unk.y; _vehicleCurPosition.z = unk.z; diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 9483a361f6..3ec1b78046 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -7316,7 +7316,7 @@ bool Vehicle::UpdateTrackMotionForwards(const CarEntry* carEntry, const Ride& cu } // Loc6DB8A5 - remaining_distance -= SubpositionTranslationDistances[remainingDistanceFlags]; + remaining_distance -= Geometry::SubpositionTranslationDistances[remainingDistanceFlags]; _vehicleCurPosition = nextVehiclePosition; Orientation = moveInfo->direction; roll = moveInfo->roll; @@ -7629,7 +7629,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c { remainingDistanceFlags |= 4; } - remaining_distance += SubpositionTranslationDistances[remainingDistanceFlags]; + remaining_distance += Geometry::SubpositionTranslationDistances[remainingDistanceFlags]; _vehicleCurPosition = nextVehiclePosition; Orientation = moveInfo->direction; diff --git a/src/openrct2/ride/VehicleData.cpp b/src/openrct2/ride/VehicleData.cpp index 9bf2f47d27..b4e94fa698 100644 --- a/src/openrct2/ride/VehicleData.cpp +++ b/src/openrct2/ride/VehicleData.cpp @@ -795,31 +795,6 @@ const uint8_t MotionSimulatorTimeToSpriteMap[] = { const int32_t MotionSimulatorTimeToSpriteMapCount = static_cast(std::size(MotionSimulatorTimeToSpriteMap)); -/** rct2: 0x009A2930 -The distance between subposition points in a movement direction (but not distance). -*/ -const int32_t SubpositionTranslationDistances[] = { - // For a base length of 8716 (0x220C) on the horizontal and 6554 (0x199A) on the vertical, - // use the Pythagoras theorem and round up. - 0, // no movement - 8716, // X translation - 8716, // Y translation - 12327, // XY translation - 6554, // Z translation - 10905, // XZ translation - 10905, // YZ translation - 13961, // XYZ translation - // For the reverser car, multiply the horizontal distance by 2.5 and the vertical distance by 4.072. - 0, // no movement - 21790, // X translation - 21790, // Y translation - 30817, // Z translation - 16385, // XY translation - 27262, // XZ translation - 27262, // YZ translation - 34902, // XYZ translation -}; - /** rct2: 0x009A2970 */ const int32_t AccelerationFromPitch[] = { 0, // Flat diff --git a/src/openrct2/ride/VehicleData.h b/src/openrct2/ride/VehicleData.h index 5a7c47c80a..9ef99fc105 100644 --- a/src/openrct2/ride/VehicleData.h +++ b/src/openrct2/ride/VehicleData.h @@ -26,7 +26,6 @@ extern const TopSpinTimeToSpriteMap* TopSpinTimeToSpriteMaps[]; extern const uint8_t MotionSimulatorTimeToSpriteMap[]; extern const int32_t MotionSimulatorTimeToSpriteMapCount; -extern const int32_t SubpositionTranslationDistances[]; extern const int32_t AccelerationFromPitch[]; extern const int32_t SpriteDirectionToSoundDirection[]; diff --git a/src/openrct2/ride/VehicleGeometry.cpp b/src/openrct2/ride/VehicleGeometry.cpp index 962c45f3f5..4eb813fb09 100644 --- a/src/openrct2/ride/VehicleGeometry.cpp +++ b/src/openrct2/ride/VehicleGeometry.cpp @@ -14,4 +14,29 @@ namespace OpenRCT2::RideVehicle::Geometry { + /** rct2: 0x009A2930 + The distance between subposition points in a movement direction (but not distance). + */ + const int32_t SubpositionTranslationDistances[] = { + // For a base length of 8716 (0x220C) on the horizontal and 6554 (0x199A) on the vertical, + // use the Pythagoras theorem and round up. + 0, // no movement + 8716, // X translation + 8716, // Y translation + 12327, // XY translation + 6554, // Z translation + 10905, // XZ translation + 10905, // YZ translation + 13961, // XYZ translation + // For the reverser car, multiply the horizontal distance by 2.5 and the vertical distance by 4.072. + 0, // no movement + 21790, // X translation + 21790, // Y translation + 30817, // Z translation + 16385, // XY translation + 27262, // XZ translation + 27262, // YZ translation + 34902, // XYZ translation + }; + } // namespace OpenRCT2::RideVehicle::Geometry diff --git a/src/openrct2/ride/VehicleGeometry.h b/src/openrct2/ride/VehicleGeometry.h index c8cfee35fb..fa83549341 100644 --- a/src/openrct2/ride/VehicleGeometry.h +++ b/src/openrct2/ride/VehicleGeometry.h @@ -17,4 +17,6 @@ namespace OpenRCT2::RideVehicle::Geometry { + extern const int32_t SubpositionTranslationDistances[]; + } // namespace OpenRCT2::RideVehicle::Geometry From 6cee099abc6a3ba1c2577d788a34da7c026f3b8a Mon Sep 17 00:00:00 2001 From: Spacek531 Date: Mon, 20 Oct 2025 15:15:01 -0700 Subject: [PATCH 03/14] add getter for SubpositionTranslationDistance --- src/openrct2/ride/CableLift.cpp | 30 ++++---------------- src/openrct2/ride/Vehicle.cpp | 41 ++++----------------------- src/openrct2/ride/VehicleGeometry.cpp | 16 +++++++---- src/openrct2/ride/VehicleGeometry.h | 5 +++- 4 files changed, 27 insertions(+), 65 deletions(-) diff --git a/src/openrct2/ride/CableLift.cpp b/src/openrct2/ride/CableLift.cpp index 3f76efbb0a..2ca8d79717 100644 --- a/src/openrct2/ride/CableLift.cpp +++ b/src/openrct2/ride/CableLift.cpp @@ -275,19 +275,10 @@ bool Vehicle::CableLiftUpdateTrackMotionForwards() const auto moveInfo = GetMoveInfo(); auto nextVehiclePosition = CoordsXYZ{ moveInfo->x, moveInfo->y, moveInfo->z } + TrackLocation; - uint8_t remainingDistanceFlags = 0; nextVehiclePosition.z += GetRideTypeDescriptor(curRide->type).Heights.VehicleZOffset; - if (nextVehiclePosition.x != _vehicleCurPosition.x) - remainingDistanceFlags |= (1 << 0); - if (nextVehiclePosition.y != _vehicleCurPosition.y) - remainingDistanceFlags |= (1 << 1); - if (nextVehiclePosition.z != _vehicleCurPosition.z) - remainingDistanceFlags |= (1 << 2); - remaining_distance -= OpenRCT2::RideVehicle::Geometry::SubpositionTranslationDistances[remainingDistanceFlags]; - _vehicleCurPosition.x = nextVehiclePosition.x; - _vehicleCurPosition.y = nextVehiclePosition.y; - _vehicleCurPosition.z = nextVehiclePosition.z; + remaining_distance -= OpenRCT2::RideVehicle::Geometry::getTranslationDistance(nextVehiclePosition - _vehicleCurPosition, false); + _vehicleCurPosition = nextVehiclePosition; Orientation = moveInfo->direction; roll = moveInfo->roll; @@ -342,22 +333,13 @@ bool Vehicle::CableLiftUpdateTrackMotionBackwards() } track_progress = trackProgress; const auto moveInfo = GetMoveInfo(); - auto unk = CoordsXYZ{ moveInfo->x, moveInfo->y, moveInfo->z } + TrackLocation; + auto nextVehiclePosition = CoordsXYZ{ moveInfo->x, moveInfo->y, moveInfo->z } + TrackLocation; - uint8_t remainingDistanceFlags = 0; - unk.z += GetRideTypeDescriptor(curRide->type).Heights.VehicleZOffset; - if (unk.x != _vehicleCurPosition.x) - remainingDistanceFlags |= (1 << 0); - if (unk.y != _vehicleCurPosition.y) - remainingDistanceFlags |= (1 << 1); - if (unk.z != _vehicleCurPosition.z) - remainingDistanceFlags |= (1 << 2); + nextVehiclePosition.z += GetRideTypeDescriptor(curRide->type).Heights.VehicleZOffset; - remaining_distance += OpenRCT2::RideVehicle::Geometry::SubpositionTranslationDistances[remainingDistanceFlags]; - _vehicleCurPosition.x = unk.x; - _vehicleCurPosition.y = unk.y; - _vehicleCurPosition.z = unk.z; + remaining_distance += OpenRCT2::RideVehicle::Geometry::getTranslationDistance(nextVehiclePosition - _vehicleCurPosition, false); + _vehicleCurPosition = nextVehiclePosition; Orientation = moveInfo->direction; roll = moveInfo->roll; pitch = moveInfo->pitch; diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 3ec1b78046..bdf162a867 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -7283,26 +7283,12 @@ bool Vehicle::UpdateTrackMotionForwards(const CarEntry* carEntry, const Ride& cu + CoordsXYZ{ moveInfo->x, moveInfo->y, moveInfo->z + GetRideTypeDescriptor(curRide.type).Heights.VehicleZOffset }; - uint8_t remainingDistanceFlags = 0; - if (nextVehiclePosition.x != _vehicleCurPosition.x) - { - remainingDistanceFlags |= 1; - } - if (nextVehiclePosition.y != _vehicleCurPosition.y) - { - remainingDistanceFlags |= 2; - } - if (nextVehiclePosition.z != _vehicleCurPosition.z) - { - remainingDistanceFlags |= 4; - } - - if (TrackSubposition == VehicleTrackSubposition::ReverserRCFrontBogie + bool useReverserDistance = TrackSubposition == VehicleTrackSubposition::ReverserRCFrontBogie && (trackType == TrackElemType::LeftReverser || trackType == TrackElemType::RightReverser) - && track_progress >= 30 && track_progress <= 66) - { - remainingDistanceFlags |= 8; - } + && track_progress >= 30 && track_progress <= 66; + + // Loc6DB8A5 + remaining_distance -= Geometry::getTranslationDistance(nextVehiclePosition - _vehicleCurPosition, useReverserDistance); if (TrackSubposition == VehicleTrackSubposition::ReverserRCRearBogie && (trackType == TrackElemType::LeftReverser || trackType == TrackElemType::RightReverser) @@ -7315,8 +7301,6 @@ bool Vehicle::UpdateTrackMotionForwards(const CarEntry* carEntry, const Ride& cu nextVehiclePosition.y = y + moveInfo2->y; } - // Loc6DB8A5 - remaining_distance -= Geometry::SubpositionTranslationDistances[remainingDistanceFlags]; _vehicleCurPosition = nextVehiclePosition; Orientation = moveInfo->direction; roll = moveInfo->roll; @@ -7616,20 +7600,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c + CoordsXYZ{ moveInfo->x, moveInfo->y, moveInfo->z + GetRideTypeDescriptor(curRide.type).Heights.VehicleZOffset }; - uint8_t remainingDistanceFlags = 0; - if (nextVehiclePosition.x != _vehicleCurPosition.x) - { - remainingDistanceFlags |= 1; - } - if (nextVehiclePosition.y != _vehicleCurPosition.y) - { - remainingDistanceFlags |= 2; - } - if (nextVehiclePosition.z != _vehicleCurPosition.z) - { - remainingDistanceFlags |= 4; - } - remaining_distance += Geometry::SubpositionTranslationDistances[remainingDistanceFlags]; + remaining_distance += Geometry::getTranslationDistance(nextVehiclePosition - _vehicleCurPosition, false); _vehicleCurPosition = nextVehiclePosition; Orientation = moveInfo->direction; diff --git a/src/openrct2/ride/VehicleGeometry.cpp b/src/openrct2/ride/VehicleGeometry.cpp index 4eb813fb09..8975deefa7 100644 --- a/src/openrct2/ride/VehicleGeometry.cpp +++ b/src/openrct2/ride/VehicleGeometry.cpp @@ -14,10 +14,8 @@ namespace OpenRCT2::RideVehicle::Geometry { - /** rct2: 0x009A2930 - The distance between subposition points in a movement direction (but not distance). - */ - const int32_t SubpositionTranslationDistances[] = { + /** rct2: 0x009A2930 */ + static constexpr auto kSubpositionTranslationDistances = std::to_array({ // For a base length of 8716 (0x220C) on the horizontal and 6554 (0x199A) on the vertical, // use the Pythagoras theorem and round up. 0, // no movement @@ -37,6 +35,14 @@ namespace OpenRCT2::RideVehicle::Geometry 27262, // XZ translation 27262, // YZ translation 34902, // XYZ translation - }; + }); + static_assert(std::size(kSubpositionTranslationDistances) == 16); + + 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]; + } } // namespace OpenRCT2::RideVehicle::Geometry diff --git a/src/openrct2/ride/VehicleGeometry.h b/src/openrct2/ride/VehicleGeometry.h index fa83549341..fdec24347e 100644 --- a/src/openrct2/ride/VehicleGeometry.h +++ b/src/openrct2/ride/VehicleGeometry.h @@ -17,6 +17,9 @@ namespace OpenRCT2::RideVehicle::Geometry { - extern const int32_t SubpositionTranslationDistances[]; + /** 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); } // namespace OpenRCT2::RideVehicle::Geometry From 2e4646a3507e16249ff6a0dbd772333360150dfb Mon Sep 17 00:00:00 2001 From: Spacek531 Date: Mon, 20 Oct 2025 15:40:31 -0700 Subject: [PATCH 04/14] use getter for subposition translation distance --- src/openrct2/ride/VehicleGeometry.cpp | 9 +-------- src/openrct2/ride/VehicleGeometry.h | 9 ++++++++- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/openrct2/ride/VehicleGeometry.cpp b/src/openrct2/ride/VehicleGeometry.cpp index 8975deefa7..53c241aa9d 100644 --- a/src/openrct2/ride/VehicleGeometry.cpp +++ b/src/openrct2/ride/VehicleGeometry.cpp @@ -15,7 +15,7 @@ namespace OpenRCT2::RideVehicle::Geometry { /** rct2: 0x009A2930 */ - static constexpr auto kSubpositionTranslationDistances = std::to_array({ + constexpr auto kSubpositionTranslationDistances = std::to_array({ // For a base length of 8716 (0x220C) on the horizontal and 6554 (0x199A) on the vertical, // use the Pythagoras theorem and round up. 0, // no movement @@ -38,11 +38,4 @@ namespace OpenRCT2::RideVehicle::Geometry }); static_assert(std::size(kSubpositionTranslationDistances) == 16); - 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]; - } - } // namespace OpenRCT2::RideVehicle::Geometry diff --git a/src/openrct2/ride/VehicleGeometry.h b/src/openrct2/ride/VehicleGeometry.h index fdec24347e..918b886046 100644 --- a/src/openrct2/ride/VehicleGeometry.h +++ b/src/openrct2/ride/VehicleGeometry.h @@ -17,9 +17,16 @@ namespace OpenRCT2::RideVehicle::Geometry { + extern const std::array kSubpositionTranslationDistances; + /** 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); + 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]; + } } // namespace OpenRCT2::RideVehicle::Geometry From ea467ff723707c54995ca18fe03c6338067a23db Mon Sep 17 00:00:00 2001 From: Spacek531 Date: Mon, 20 Oct 2025 16:10:55 -0700 Subject: [PATCH 05/14] move array unk9A36C4 to kFreeroamVehicleMovementData --- src/openrct2/ride/Vehicle.cpp | 35 +++++++-------------------- src/openrct2/ride/VehicleGeometry.cpp | 11 +++++++++ src/openrct2/ride/VehicleGeometry.h | 9 +++++++ 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index bdf162a867..366883eec5 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -380,23 +380,6 @@ static constexpr const int8_t* SwingingTimeToSpriteMaps[] = { kSwingingTimeToSpriteMap8, kSwingingTimeToSpriteMap9, kSwingingTimeToSpriteMap10, kSwingingTimeToSpriteMap11, }; -struct Unk9A36C4Struct -{ - int16_t x; - int16_t y; - uint32_t distance; -}; - -/** rct2: 0x009A36C4 */ -static constexpr Unk9A36C4Struct kUnk9A36C4[] = { - { -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 }, - { 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 }, -}; - /** rct2: 0x009A37C4 */ static constexpr CoordsXY kSurroundingTiles[] = { { 0, 0 }, @@ -3792,7 +3775,7 @@ void Vehicle::UpdateMotionBoatHire() } int32_t edi = (Orientation | (var_35 & 1)) & 0x1F; - loc2 = { x + kUnk9A36C4[edi].x, y + kUnk9A36C4[edi].y }; + loc2 = { x + Geometry::kFreeroamVehicleMovementData[edi].x, y + Geometry::kFreeroamVehicleMovementData[edi].y }; if (UpdateMotionCollisionDetection({ loc2, z }, nullptr)) { remaining_distance = 0; @@ -3890,7 +3873,7 @@ void Vehicle::UpdateMotionBoatHire() TrackLocation = { flooredLocation, TrackLocation.z }; } - remaining_distance -= kUnk9A36C4[edi].distance; + remaining_distance -= Geometry::kFreeroamVehicleMovementData[edi].distance; _vehicleCurPosition.x = loc2.x; _vehicleCurPosition.y = loc2.y; if (remaining_distance < 0x368A) @@ -5229,10 +5212,10 @@ int32_t Vehicle::UpdateMotionDodgems() CoordsXYZ location = { x, y, z }; - location.x += kUnk9A36C4[oldCollisionDirection].x; - location.y += kUnk9A36C4[oldCollisionDirection].y; - location.x += kUnk9A36C4[oldCollisionDirection + 1].x; - location.y += kUnk9A36C4[oldCollisionDirection + 1].y; + 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; if (collideSprite = DodgemsCarWouldCollideAt(location); !collideSprite.has_value()) { @@ -5256,15 +5239,15 @@ int32_t Vehicle::UpdateMotionDodgems() direction |= var_35 & 1; CoordsXY location = _vehicleCurPosition; - location.x += kUnk9A36C4[direction].x; - location.y += kUnk9A36C4[direction].y; + location.x += Geometry::kFreeroamVehicleMovementData[direction].x; + location.y += Geometry::kFreeroamVehicleMovementData[direction].y; if (collideSprite = DodgemsCarWouldCollideAt(location); collideSprite.has_value()) { break; } - remaining_distance -= kUnk9A36C4[direction].distance; + remaining_distance -= Geometry::kFreeroamVehicleMovementData[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 53c241aa9d..70e2f56cbf 100644 --- a/src/openrct2/ride/VehicleGeometry.cpp +++ b/src/openrct2/ride/VehicleGeometry.cpp @@ -38,4 +38,15 @@ namespace OpenRCT2::RideVehicle::Geometry }); static_assert(std::size(kSubpositionTranslationDistances) == 16); + /** rct2: 0x009A36C4 */ + constexpr 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 }, + { 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 }, + }); + static_assert(std::size(kFreeroamVehicleMovementData) == 32); + } // namespace OpenRCT2::RideVehicle::Geometry diff --git a/src/openrct2/ride/VehicleGeometry.h b/src/openrct2/ride/VehicleGeometry.h index 918b886046..68aea8c92e 100644 --- a/src/openrct2/ride/VehicleGeometry.h +++ b/src/openrct2/ride/VehicleGeometry.h @@ -17,7 +17,16 @@ namespace OpenRCT2::RideVehicle::Geometry { + + struct Unk9A36C4Struct + { + int16_t x; + int16_t y; + uint32_t distance; + }; + extern const std::array kSubpositionTranslationDistances; + extern const std::array kFreeroamVehicleMovementData; /** The distance between subposition points in a movement vector. * Squashes vector components to 0 or !0, so vector length is ignored. From ebe6dac2da8b8a81911fd73b1845c93744eb9fdd Mon Sep 17 00:00:00 2001 From: Spacek531 Date: Mon, 20 Oct 2025 16:45:45 -0700 Subject: [PATCH 06/14] move AccelerationFromPitch --- src/openrct2/ride/CableLift.cpp | 13 ++--- src/openrct2/ride/Vehicle.cpp | 44 ++++++++--------- src/openrct2/ride/VehicleData.cpp | 67 -------------------------- src/openrct2/ride/VehicleData.h | 2 - src/openrct2/ride/VehicleGeometry.cpp | 68 ++++++++++++++++++++++++++- src/openrct2/ride/VehicleGeometry.h | 3 +- 6 files changed, 98 insertions(+), 99 deletions(-) diff --git a/src/openrct2/ride/CableLift.cpp b/src/openrct2/ride/CableLift.cpp index 2ca8d79717..54aefffeab 100644 --- a/src/openrct2/ride/CableLift.cpp +++ b/src/openrct2/ride/CableLift.cpp @@ -24,6 +24,7 @@ #include "VehicleGeometry.h" using namespace OpenRCT2; +using namespace OpenRCT2::RideVehicle; Vehicle* CableLiftSegmentCreate( Ride& ride, int32_t x, int32_t y, int32_t z, int32_t direction, uint16_t var_44, int32_t remaining_distance, bool head) @@ -277,7 +278,7 @@ bool Vehicle::CableLiftUpdateTrackMotionForwards() nextVehiclePosition.z += GetRideTypeDescriptor(curRide->type).Heights.VehicleZOffset; - remaining_distance -= OpenRCT2::RideVehicle::Geometry::getTranslationDistance(nextVehiclePosition - _vehicleCurPosition, false); + remaining_distance -= Geometry::getTranslationDistance(nextVehiclePosition - _vehicleCurPosition, false); _vehicleCurPosition = nextVehiclePosition; Orientation = moveInfo->direction; @@ -286,7 +287,7 @@ bool Vehicle::CableLiftUpdateTrackMotionForwards() if (remaining_distance >= 13962) { - acceleration += AccelerationFromPitch[EnumValue(pitch)]; + acceleration += Geometry::kAccelerationFromPitch[EnumValue(pitch)]; } } return true; @@ -346,7 +347,7 @@ bool Vehicle::CableLiftUpdateTrackMotionBackwards() if (remaining_distance < 0) { - acceleration += AccelerationFromPitch[EnumValue(pitch)]; + acceleration += Geometry::kAccelerationFromPitch[EnumValue(pitch)]; } } return true; @@ -377,7 +378,7 @@ int32_t Vehicle::CableLiftUpdateTrackMotion() for (Vehicle* vehicle = frontVehicle; vehicle != nullptr;) { - vehicle->acceleration = AccelerationFromPitch[EnumValue(vehicle->pitch)]; + vehicle->acceleration = Geometry::kAccelerationFromPitch[EnumValue(vehicle->pitch)]; _vehicleUnkF64E10 = 1; vehicle->remaining_distance += _vehicleVelocityF64E0C; @@ -398,7 +399,7 @@ int32_t Vehicle::CableLiftUpdateTrackMotion() _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; _vehicleVelocityF64E0C -= vehicle->remaining_distance - 13962; vehicle->remaining_distance = 13962; - vehicle->acceleration += AccelerationFromPitch[EnumValue(vehicle->pitch)]; + vehicle->acceleration += Geometry::kAccelerationFromPitch[EnumValue(vehicle->pitch)]; _vehicleUnkF64E10++; continue; } @@ -411,7 +412,7 @@ int32_t Vehicle::CableLiftUpdateTrackMotion() _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; _vehicleVelocityF64E0C -= vehicle->remaining_distance + 1; vehicle->remaining_distance = -1; - vehicle->acceleration += AccelerationFromPitch[EnumValue(vehicle->pitch)]; + vehicle->acceleration += Geometry::kAccelerationFromPitch[EnumValue(vehicle->pitch)]; _vehicleUnkF64E10++; } vehicle->MoveTo(_vehicleCurPosition); diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 366883eec5..5edcdb2e45 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -5405,7 +5405,7 @@ void Vehicle::UpdateTrackMotionUpStopCheck() const gForces.LateralG = std::abs(gForces.LateralG); if (gForces.LateralG <= 150) { - if (AccelerationFromPitch[EnumValue(pitch)] < 0) + if (Geometry::kAccelerationFromPitch[EnumValue(pitch)] < 0) { if (gForces.VerticalG > -40) { @@ -5431,7 +5431,7 @@ void Vehicle::UpdateTrackMotionUpStopCheck() const { auto gForces = GetGForces(); - if (AccelerationFromPitch[EnumValue(pitch)] < 0) + if (Geometry::kAccelerationFromPitch[EnumValue(pitch)] < 0) { if (gForces.VerticalG > -45) { @@ -7354,7 +7354,7 @@ bool Vehicle::UpdateTrackMotionForwards(const CarEntry* carEntry, const Ride& cu return true; } - acceleration += AccelerationFromPitch[moveInfovehicleAnimationGroup]; + acceleration += Geometry::kAccelerationFromPitch[moveInfovehicleAnimationGroup]; _vehicleUnkF64E10++; } } @@ -7650,7 +7650,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c { return true; } - acceleration += AccelerationFromPitch[EnumValue(moveInfoVehicleAnimationGroup)]; + acceleration += Geometry::kAccelerationFromPitch[EnumValue(moveInfoVehicleAnimationGroup)]; _vehicleUnkF64E10++; } } @@ -7671,7 +7671,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c Loc6DCDE4(curRide); return Vehicle::UpdateMiniGolfSubroutineStatus::stop; } - acceleration = AccelerationFromPitch[EnumValue(pitch)]; + acceleration = Geometry::kAccelerationFromPitch[EnumValue(pitch)]; _vehicleUnkF64E10++; return Vehicle::UpdateMiniGolfSubroutineStatus::restart; } @@ -7693,7 +7693,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c Loc6DCDE4(curRide); return Vehicle::UpdateMiniGolfSubroutineStatus::stop; } - acceleration = AccelerationFromPitch[EnumValue(pitch)]; + acceleration = Geometry::kAccelerationFromPitch[EnumValue(pitch)]; _vehicleUnkF64E10++; return Vehicle::UpdateMiniGolfSubroutineStatus::restart; } @@ -7721,7 +7721,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c Loc6DCDE4(curRide); return Vehicle::UpdateMiniGolfSubroutineStatus::stop; } - acceleration = AccelerationFromPitch[EnumValue(pitch)]; + acceleration = Geometry::kAccelerationFromPitch[EnumValue(pitch)]; _vehicleUnkF64E10++; return Vehicle::UpdateMiniGolfSubroutineStatus::restart; } @@ -7738,7 +7738,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c Loc6DCDE4(curRide); return Vehicle::UpdateMiniGolfSubroutineStatus::stop; } - acceleration = AccelerationFromPitch[EnumValue(pitch)]; + acceleration = Geometry::kAccelerationFromPitch[EnumValue(pitch)]; _vehicleUnkF64E10++; return Vehicle::UpdateMiniGolfSubroutineStatus::restart; } @@ -7767,7 +7767,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c Loc6DCDE4(curRide); return Vehicle::UpdateMiniGolfSubroutineStatus::stop; } - acceleration = AccelerationFromPitch[EnumValue(pitch)]; + acceleration = Geometry::kAccelerationFromPitch[EnumValue(pitch)]; _vehicleUnkF64E10++; return Vehicle::UpdateMiniGolfSubroutineStatus::restart; } @@ -7784,7 +7784,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c Loc6DCDE4(curRide); return Vehicle::UpdateMiniGolfSubroutineStatus::stop; } - acceleration = AccelerationFromPitch[EnumValue(pitch)]; + acceleration = Geometry::kAccelerationFromPitch[EnumValue(pitch)]; _vehicleUnkF64E10++; return Vehicle::UpdateMiniGolfSubroutineStatus::restart; } @@ -7820,7 +7820,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c Loc6DCDE4(curRide); return Vehicle::UpdateMiniGolfSubroutineStatus::stop; } - acceleration = AccelerationFromPitch[EnumValue(pitch)]; + acceleration = Geometry::kAccelerationFromPitch[EnumValue(pitch)]; _vehicleUnkF64E10++; return Vehicle::UpdateMiniGolfSubroutineStatus::restart; } @@ -7859,7 +7859,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; _vehicleVelocityF64E0C -= remaining_distance + 1; remaining_distance = -1; - acceleration += AccelerationFromPitch[EnumValue(pitch)]; + acceleration += Geometry::kAccelerationFromPitch[EnumValue(pitch)]; _vehicleUnkF64E10++; return UpdateMiniGolfSubroutineStatus::carryOn; } @@ -7876,7 +7876,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c { Loc6DCDE4(curRide); } - acceleration += AccelerationFromPitch[EnumValue(pitch)]; + acceleration += Geometry::kAccelerationFromPitch[EnumValue(pitch)]; _vehicleUnkF64E10++; return UpdateMiniGolfSubroutineStatus::carryOn; } @@ -8034,7 +8034,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c Loc6DCDE4(curRide); return UpdateMiniGolfSubroutineStatus::stop; } - acceleration = AccelerationFromPitch[EnumValue(pitch)]; + acceleration = Geometry::kAccelerationFromPitch[EnumValue(pitch)]; _vehicleUnkF64E10++; } } @@ -8052,7 +8052,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; _vehicleVelocityF64E0C -= remaining_distance + 1; remaining_distance = -1; - acceleration += AccelerationFromPitch[EnumValue(pitch)]; + acceleration += Geometry::kAccelerationFromPitch[EnumValue(pitch)]; _vehicleUnkF64E10++; continue; } @@ -8065,7 +8065,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; _vehicleVelocityF64E0C -= remaining_distance - 0x368A; remaining_distance = 0x368A; - acceleration = AccelerationFromPitch[EnumValue(pitch)]; + acceleration = Geometry::kAccelerationFromPitch[EnumValue(pitch)]; _vehicleUnkF64E10++; return Vehicle::UpdateMiniGolfSubroutineStatus::restart; } @@ -8135,7 +8135,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c vEBP->velocity = vEDI->velocity >> 1; } _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_2; - acceleration = AccelerationFromPitch[EnumValue(pitch)]; + acceleration = Geometry::kAccelerationFromPitch[EnumValue(pitch)]; _vehicleUnkF64E10++; return UpdateMiniGolfSubroutineStatus::restart; } @@ -8147,7 +8147,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c Loc6DCDE4(curRide); return UpdateMiniGolfSubroutineStatus::stop; } - acceleration += AccelerationFromPitch[EnumValue(pitch)]; + acceleration += Geometry::kAccelerationFromPitch[EnumValue(pitch)]; _vehicleUnkF64E10++; } } @@ -8161,7 +8161,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c void Vehicle::UpdateTrackMotionMiniGolfVehicle(const Ride& curRide, const RideObjectEntry& rideEntry, const CarEntry* carEntry) { _vehicleUnkF64E10 = 1; - acceleration = AccelerationFromPitch[EnumValue(pitch)]; + acceleration = Geometry::kAccelerationFromPitch[EnumValue(pitch)]; if (!HasFlag(VehicleFlags::MoveSingleCar)) { remaining_distance = _vehicleVelocityF64E0C + remaining_distance; @@ -8487,7 +8487,7 @@ void Vehicle::UpdateTrackMotionPreUpdate( { car.UpdateAdditionalAnimation(); } - car.acceleration = AccelerationFromPitch[EnumValue(car.pitch)]; + car.acceleration = Geometry::kAccelerationFromPitch[EnumValue(car.pitch)]; _vehicleUnkF64E10 = 1; if (!car.HasFlag(VehicleFlags::MoveSingleCar)) @@ -8515,7 +8515,7 @@ void Vehicle::UpdateTrackMotionPreUpdate( { break; } - car.acceleration += AccelerationFromPitch[EnumValue(car.pitch)]; + car.acceleration += Geometry::kAccelerationFromPitch[EnumValue(car.pitch)]; _vehicleUnkF64E10++; continue; } @@ -8533,7 +8533,7 @@ void Vehicle::UpdateTrackMotionPreUpdate( { break; } - car.acceleration = AccelerationFromPitch[EnumValue(car.pitch)]; + car.acceleration = Geometry::kAccelerationFromPitch[EnumValue(car.pitch)]; _vehicleUnkF64E10++; continue; } diff --git a/src/openrct2/ride/VehicleData.cpp b/src/openrct2/ride/VehicleData.cpp index b4e94fa698..c794105d62 100644 --- a/src/openrct2/ride/VehicleData.cpp +++ b/src/openrct2/ride/VehicleData.cpp @@ -795,73 +795,6 @@ const uint8_t MotionSimulatorTimeToSpriteMap[] = { const int32_t MotionSimulatorTimeToSpriteMapCount = static_cast(std::size(MotionSimulatorTimeToSpriteMap)); -/** rct2: 0x009A2970 */ -const int32_t AccelerationFromPitch[] = { - 0, // Flat - // The geometric angle of slopes 12.5 and 25 are actually 11.1 and 22.2 respectively. - -124548, // 1 Slope Up 12.5 - -243318, // 2 Slope Up 25 - -416016, // 3 Slope Up 42.5 - -546342, // 4 Slope Up 60 - 124548, // 5 Slope Down 12.5 - 243318, // 6 Slope Down 25 - 416016, // 7 Slope Down 42.5 - 546342, // 8 Slope Down 60 - -617604, // 9 Slope Up 75 - -642000, // 10 Slope Up 90 - -620172, // 11 Slope Up 105 - -555972, // 12 Slope Up 120 - -453894, // 13 Slope Up 135 - -321000, // 14 Slope Up 150 - -166278, // 15 Slope Up 165 - 0, // 16 Fully Inverted - 617604, // 17 Slope Down 75 - 642000, // 18 Slope Down 90 - 620172, // 19 Slope Down 105 - 555972, // 20 Slope Down 120 - 453894, // 21 Slope Down 135 - 321000, // 22 Slope Down 150 - 166278, // 23 Slope Down 165 - -321000, // 24 Corkscrew Right Up 0 - -555972, // 25 Corkscrew Right Up 1 - -642000, // 26 Corkscrew Right Up 2 - -555972, // 27 Corkscrew Right Up 3 - -321000, // 28 Corkscrew Right Up 4 - 321000, // 29 Corkscrew Right Down 4 - 555972, // 30 Corkscrew Right Down 3 - 642000, // 31 Corkscrew Right Down 2 - 555972, // 32 Corkscrew Right Down 1 - 321000, // 33 Corkscrew Right Down 0 - -321000, // 34 Corkscrew Left Up 0 - -555972, // 35 Corkscrew Left Up 1 - -642000, // 36 Corkscrew Left Up 2 - -555972, // 37 Corkscrew Left Up 3 - -321000, // 38 Corkscrew Left Up 4 - 321000, // 39 Corkscrew Left Down 4 - 555972, // 40 Corkscrew Left Down 2 - 642000, // 41 Corkscrew Left Down 1 - 555972, // 42 Corkscrew Left Down 1 - 321000, // 43 Corkscrew Left Down 0 - -33384, // 44 Half Helix Up Large - -55854, // 45 Half Helix Up Small - 33384, // 46 Half Helix Down Large - 55854, // 47 Half Helix Down Small - -66768, // 48 Quarter Helix Up - 66768, // 49 Quarter Helix Down - // currently only diagonal elements use slopes angles 8, 16, 50. Diagonal gentle-to-steep transition uses - // diagonal sprites of slopes 25 and 42. - -90522, // 50 Slope Up 8 - -179760, // 51 Slope Down 16 - -484068, // 52 Slope Up 50 - 90522, // 53 Slope Down 8 - 179760, // 54 Slope Down 16 - 484068, // 55 Slope Down 50 - 243318, // 56 Inverting Loop Down 25 - 416016, // 57 Inverting Loop Down 42.5 - 546342, // 58 Inverting Loop Down 60 - -110424, // 59 Slope Up Spiral Lift Hill -}; - /** rct2: 0x009A3684 */ const int32_t SpriteDirectionToSoundDirection[] = { -0x4000, // 0 diff --git a/src/openrct2/ride/VehicleData.h b/src/openrct2/ride/VehicleData.h index 9ef99fc105..0618f82acd 100644 --- a/src/openrct2/ride/VehicleData.h +++ b/src/openrct2/ride/VehicleData.h @@ -26,6 +26,4 @@ extern const TopSpinTimeToSpriteMap* TopSpinTimeToSpriteMaps[]; extern const uint8_t MotionSimulatorTimeToSpriteMap[]; extern const int32_t MotionSimulatorTimeToSpriteMapCount; -extern const int32_t AccelerationFromPitch[]; - extern const int32_t SpriteDirectionToSoundDirection[]; diff --git a/src/openrct2/ride/VehicleGeometry.cpp b/src/openrct2/ride/VehicleGeometry.cpp index 70e2f56cbf..c3073c811a 100644 --- a/src/openrct2/ride/VehicleGeometry.cpp +++ b/src/openrct2/ride/VehicleGeometry.cpp @@ -39,7 +39,7 @@ namespace OpenRCT2::RideVehicle::Geometry static_assert(std::size(kSubpositionTranslationDistances) == 16); /** rct2: 0x009A36C4 */ - constexpr auto kFreeroamVehicleMovementData = std::to_array( { + constexpr 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 }, @@ -49,4 +49,70 @@ namespace OpenRCT2::RideVehicle::Geometry }); static_assert(std::size(kFreeroamVehicleMovementData) == 32); + /** rct2: 0x009A2970 */ + constexpr auto kAccelerationFromPitch = std::to_array({ + 0, // Flat + -124548, // 1 Slope Up 12.5 + -243318, // 2 Slope Up 25 + -416016, // 3 Slope Up 42.5 + -546342, // 4 Slope Up 60 + 124548, // 5 Slope Down 12.5 + 243318, // 6 Slope Down 25 + 416016, // 7 Slope Down 42.5 + 546342, // 8 Slope Down 60 + -617604, // 9 Slope Up 75 + -642000, // 10 Slope Up 90 + -620172, // 11 Slope Up 105 + -555972, // 12 Slope Up 120 + -453894, // 13 Slope Up 135 + -321000, // 14 Slope Up 150 + -166278, // 15 Slope Up 165 + 0, // 16 Fully Inverted + 617604, // 17 Slope Down 75 + 642000, // 18 Slope Down 90 + 620172, // 19 Slope Down 105 + 555972, // 20 Slope Down 120 + 453894, // 21 Slope Down 135 + 321000, // 22 Slope Down 150 + 166278, // 23 Slope Down 165 + -321000, // 24 Corkscrew Right Up 0 + -555972, // 25 Corkscrew Right Up 1 + -642000, // 26 Corkscrew Right Up 2 + -555972, // 27 Corkscrew Right Up 3 + -321000, // 28 Corkscrew Right Up 4 + 321000, // 29 Corkscrew Right Down 4 + 555972, // 30 Corkscrew Right Down 3 + 642000, // 31 Corkscrew Right Down 2 + 555972, // 32 Corkscrew Right Down 1 + 321000, // 33 Corkscrew Right Down 0 + -321000, // 34 Corkscrew Left Up 0 + -555972, // 35 Corkscrew Left Up 1 + -642000, // 36 Corkscrew Left Up 2 + -555972, // 37 Corkscrew Left Up 3 + -321000, // 38 Corkscrew Left Up 4 + 321000, // 39 Corkscrew Left Down 4 + 555972, // 40 Corkscrew Left Down 2 + 642000, // 41 Corkscrew Left Down 1 + 555972, // 42 Corkscrew Left Down 1 + 321000, // 43 Corkscrew Left Down 0 + -33384, // 44 Half Helix Up Large + -55854, // 45 Half Helix Up Small + 33384, // 46 Half Helix Down Large + 55854, // 47 Half Helix Down Small + -66768, // 48 Quarter Helix Up + 66768, // 49 Quarter Helix Down + -90522, // 50 Slope Up 8 + -179760, // 51 Slope Down 16 + -484068, // 52 Slope Up 50 + 90522, // 53 Slope Down 8 + 179760, // 54 Slope Down 16 + 484068, // 55 Slope Down 50 + 243318, // 56 Inverting Loop Down 25 + 416016, // 57 Inverting Loop Down 42.5 + 546342, // 58 Inverting Loop Down 60 + -110424, // 59 Slope Up Spiral Lift Hill + 110424, // 60 Slope Down Spiral Lift Hill + }); + static_assert(std::size(kAccelerationFromPitch) == EnumValue(VehiclePitch::pitchCount)); + } // namespace OpenRCT2::RideVehicle::Geometry diff --git a/src/openrct2/ride/VehicleGeometry.h b/src/openrct2/ride/VehicleGeometry.h index 68aea8c92e..f7b48c1146 100644 --- a/src/openrct2/ride/VehicleGeometry.h +++ b/src/openrct2/ride/VehicleGeometry.h @@ -9,6 +9,7 @@ #pragma once +#include "../core/EnumUtils.hpp" #include "../world/Location.hpp" #include "Angles.h" @@ -17,7 +18,6 @@ namespace OpenRCT2::RideVehicle::Geometry { - struct Unk9A36C4Struct { int16_t x; @@ -27,6 +27,7 @@ namespace OpenRCT2::RideVehicle::Geometry extern const std::array kSubpositionTranslationDistances; extern const std::array kFreeroamVehicleMovementData; + extern const std::array kAccelerationFromPitch; /** The distance between subposition points in a movement vector. * Squashes vector components to 0 or !0, so vector length is ignored. From 6cec7d33ea3018a8576fa0d12216ce2d8c3f31d0 Mon Sep 17 00:00:00 2001 From: Spacek531 Date: Mon, 20 Oct 2025 18:20:53 -0700 Subject: [PATCH 07/14] replace AccelerationFromPitch with getter --- src/openrct2/ride/CableLift.cpp | 12 +++---- src/openrct2/ride/Vehicle.cpp | 49 +++++++++++++---------------- src/openrct2/ride/VehicleGeometry.h | 9 ++++++ 3 files changed, 37 insertions(+), 33 deletions(-) diff --git a/src/openrct2/ride/CableLift.cpp b/src/openrct2/ride/CableLift.cpp index 54aefffeab..44818b2259 100644 --- a/src/openrct2/ride/CableLift.cpp +++ b/src/openrct2/ride/CableLift.cpp @@ -287,7 +287,7 @@ bool Vehicle::CableLiftUpdateTrackMotionForwards() if (remaining_distance >= 13962) { - acceleration += Geometry::kAccelerationFromPitch[EnumValue(pitch)]; + acceleration += Geometry::getAccelerationFromPitch(pitch); } } return true; @@ -338,7 +338,7 @@ bool Vehicle::CableLiftUpdateTrackMotionBackwards() nextVehiclePosition.z += GetRideTypeDescriptor(curRide->type).Heights.VehicleZOffset; - remaining_distance += OpenRCT2::RideVehicle::Geometry::getTranslationDistance(nextVehiclePosition - _vehicleCurPosition, false); + remaining_distance += Geometry::getTranslationDistance(nextVehiclePosition - _vehicleCurPosition, false); _vehicleCurPosition = nextVehiclePosition; Orientation = moveInfo->direction; @@ -347,7 +347,7 @@ bool Vehicle::CableLiftUpdateTrackMotionBackwards() if (remaining_distance < 0) { - acceleration += Geometry::kAccelerationFromPitch[EnumValue(pitch)]; + acceleration += Geometry::getAccelerationFromPitch(pitch); } } return true; @@ -378,7 +378,7 @@ int32_t Vehicle::CableLiftUpdateTrackMotion() for (Vehicle* vehicle = frontVehicle; vehicle != nullptr;) { - vehicle->acceleration = Geometry::kAccelerationFromPitch[EnumValue(vehicle->pitch)]; + vehicle->acceleration = Geometry::getAccelerationFromPitch(vehicle->pitch); _vehicleUnkF64E10 = 1; vehicle->remaining_distance += _vehicleVelocityF64E0C; @@ -399,7 +399,7 @@ int32_t Vehicle::CableLiftUpdateTrackMotion() _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; _vehicleVelocityF64E0C -= vehicle->remaining_distance - 13962; vehicle->remaining_distance = 13962; - vehicle->acceleration += Geometry::kAccelerationFromPitch[EnumValue(vehicle->pitch)]; + vehicle->acceleration += Geometry::getAccelerationFromPitch(vehicle->pitch); _vehicleUnkF64E10++; continue; } @@ -412,7 +412,7 @@ int32_t Vehicle::CableLiftUpdateTrackMotion() _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; _vehicleVelocityF64E0C -= vehicle->remaining_distance + 1; vehicle->remaining_distance = -1; - vehicle->acceleration += Geometry::kAccelerationFromPitch[EnumValue(vehicle->pitch)]; + vehicle->acceleration += Geometry::getAccelerationFromPitch(vehicle->pitch); _vehicleUnkF64E10++; } vehicle->MoveTo(_vehicleCurPosition); diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 5edcdb2e45..ac0dc5b6b2 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -5405,7 +5405,7 @@ void Vehicle::UpdateTrackMotionUpStopCheck() const gForces.LateralG = std::abs(gForces.LateralG); if (gForces.LateralG <= 150) { - if (Geometry::kAccelerationFromPitch[EnumValue(pitch)] < 0) + if (Geometry::getAccelerationFromPitch(pitch) < 0) { if (gForces.VerticalG > -40) { @@ -5431,7 +5431,7 @@ void Vehicle::UpdateTrackMotionUpStopCheck() const { auto gForces = GetGForces(); - if (Geometry::kAccelerationFromPitch[EnumValue(pitch)] < 0) + if (Geometry::getAccelerationFromPitch(pitch) < 0) { if (gForces.VerticalG > -45) { @@ -7260,7 +7260,6 @@ bool Vehicle::UpdateTrackMotionForwards(const CarEntry* carEntry, const Ride& cu // Loc6DB706 const auto moveInfo = GetMoveInfo(); trackType = GetTrackType(); - uint8_t moveInfovehicleAnimationGroup; { auto nextVehiclePosition = TrackLocation + CoordsXYZ{ moveInfo->x, moveInfo->y, @@ -7289,8 +7288,6 @@ bool Vehicle::UpdateTrackMotionForwards(const CarEntry* carEntry, const Ride& cu roll = moveInfo->roll; pitch = moveInfo->pitch; - moveInfovehicleAnimationGroup = EnumValue(moveInfo->pitch); - if ((carEntry->flags & CAR_ENTRY_FLAG_WOODEN_WILD_MOUSE_SWING) && moveInfo->pitch != VehiclePitch::flat) { SwingSprite = 0; @@ -7354,7 +7351,7 @@ bool Vehicle::UpdateTrackMotionForwards(const CarEntry* carEntry, const Ride& cu return true; } - acceleration += Geometry::kAccelerationFromPitch[moveInfovehicleAnimationGroup]; + acceleration += Geometry::getAccelerationFromPitch(pitch); _vehicleUnkF64E10++; } } @@ -7576,7 +7573,6 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c // Loc6DBD42 track_progress = newTrackProgress; - VehiclePitch moveInfoVehicleAnimationGroup; { const VehicleInfo* moveInfo = GetMoveInfo(); auto nextVehiclePosition = TrackLocation @@ -7589,7 +7585,6 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c Orientation = moveInfo->direction; roll = moveInfo->roll; pitch = moveInfo->pitch; - moveInfoVehicleAnimationGroup = moveInfo->pitch; if ((carEntry->flags & CAR_ENTRY_FLAG_WOODEN_WILD_MOUSE_SWING) && pitch != VehiclePitch::flat) { @@ -7650,7 +7645,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c { return true; } - acceleration += Geometry::kAccelerationFromPitch[EnumValue(moveInfoVehicleAnimationGroup)]; + acceleration += Geometry::getAccelerationFromPitch(pitch); _vehicleUnkF64E10++; } } @@ -7671,7 +7666,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c Loc6DCDE4(curRide); return Vehicle::UpdateMiniGolfSubroutineStatus::stop; } - acceleration = Geometry::kAccelerationFromPitch[EnumValue(pitch)]; + acceleration = Geometry::getAccelerationFromPitch(pitch); _vehicleUnkF64E10++; return Vehicle::UpdateMiniGolfSubroutineStatus::restart; } @@ -7693,7 +7688,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c Loc6DCDE4(curRide); return Vehicle::UpdateMiniGolfSubroutineStatus::stop; } - acceleration = Geometry::kAccelerationFromPitch[EnumValue(pitch)]; + acceleration = Geometry::getAccelerationFromPitch(pitch); _vehicleUnkF64E10++; return Vehicle::UpdateMiniGolfSubroutineStatus::restart; } @@ -7721,7 +7716,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c Loc6DCDE4(curRide); return Vehicle::UpdateMiniGolfSubroutineStatus::stop; } - acceleration = Geometry::kAccelerationFromPitch[EnumValue(pitch)]; + acceleration = Geometry::getAccelerationFromPitch(pitch); _vehicleUnkF64E10++; return Vehicle::UpdateMiniGolfSubroutineStatus::restart; } @@ -7738,7 +7733,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c Loc6DCDE4(curRide); return Vehicle::UpdateMiniGolfSubroutineStatus::stop; } - acceleration = Geometry::kAccelerationFromPitch[EnumValue(pitch)]; + acceleration = Geometry::getAccelerationFromPitch(pitch); _vehicleUnkF64E10++; return Vehicle::UpdateMiniGolfSubroutineStatus::restart; } @@ -7767,7 +7762,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c Loc6DCDE4(curRide); return Vehicle::UpdateMiniGolfSubroutineStatus::stop; } - acceleration = Geometry::kAccelerationFromPitch[EnumValue(pitch)]; + acceleration = Geometry::getAccelerationFromPitch(pitch); _vehicleUnkF64E10++; return Vehicle::UpdateMiniGolfSubroutineStatus::restart; } @@ -7784,7 +7779,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c Loc6DCDE4(curRide); return Vehicle::UpdateMiniGolfSubroutineStatus::stop; } - acceleration = Geometry::kAccelerationFromPitch[EnumValue(pitch)]; + acceleration = Geometry::getAccelerationFromPitch(pitch); _vehicleUnkF64E10++; return Vehicle::UpdateMiniGolfSubroutineStatus::restart; } @@ -7820,7 +7815,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c Loc6DCDE4(curRide); return Vehicle::UpdateMiniGolfSubroutineStatus::stop; } - acceleration = Geometry::kAccelerationFromPitch[EnumValue(pitch)]; + acceleration = Geometry::getAccelerationFromPitch(pitch); _vehicleUnkF64E10++; return Vehicle::UpdateMiniGolfSubroutineStatus::restart; } @@ -7859,7 +7854,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; _vehicleVelocityF64E0C -= remaining_distance + 1; remaining_distance = -1; - acceleration += Geometry::kAccelerationFromPitch[EnumValue(pitch)]; + acceleration += Geometry::getAccelerationFromPitch(pitch); _vehicleUnkF64E10++; return UpdateMiniGolfSubroutineStatus::carryOn; } @@ -7876,7 +7871,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c { Loc6DCDE4(curRide); } - acceleration += Geometry::kAccelerationFromPitch[EnumValue(pitch)]; + acceleration += Geometry::getAccelerationFromPitch(pitch); _vehicleUnkF64E10++; return UpdateMiniGolfSubroutineStatus::carryOn; } @@ -8034,7 +8029,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c Loc6DCDE4(curRide); return UpdateMiniGolfSubroutineStatus::stop; } - acceleration = Geometry::kAccelerationFromPitch[EnumValue(pitch)]; + acceleration = Geometry::getAccelerationFromPitch(pitch); _vehicleUnkF64E10++; } } @@ -8052,7 +8047,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; _vehicleVelocityF64E0C -= remaining_distance + 1; remaining_distance = -1; - acceleration += Geometry::kAccelerationFromPitch[EnumValue(pitch)]; + acceleration += Geometry::getAccelerationFromPitch(pitch); _vehicleUnkF64E10++; continue; } @@ -8065,7 +8060,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; _vehicleVelocityF64E0C -= remaining_distance - 0x368A; remaining_distance = 0x368A; - acceleration = Geometry::kAccelerationFromPitch[EnumValue(pitch)]; + acceleration = Geometry::getAccelerationFromPitch(pitch); _vehicleUnkF64E10++; return Vehicle::UpdateMiniGolfSubroutineStatus::restart; } @@ -8135,7 +8130,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c vEBP->velocity = vEDI->velocity >> 1; } _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_2; - acceleration = Geometry::kAccelerationFromPitch[EnumValue(pitch)]; + acceleration = Geometry::getAccelerationFromPitch(pitch); _vehicleUnkF64E10++; return UpdateMiniGolfSubroutineStatus::restart; } @@ -8147,7 +8142,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c Loc6DCDE4(curRide); return UpdateMiniGolfSubroutineStatus::stop; } - acceleration += Geometry::kAccelerationFromPitch[EnumValue(pitch)]; + acceleration += Geometry::getAccelerationFromPitch(pitch); _vehicleUnkF64E10++; } } @@ -8161,7 +8156,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c void Vehicle::UpdateTrackMotionMiniGolfVehicle(const Ride& curRide, const RideObjectEntry& rideEntry, const CarEntry* carEntry) { _vehicleUnkF64E10 = 1; - acceleration = Geometry::kAccelerationFromPitch[EnumValue(pitch)]; + acceleration = Geometry::getAccelerationFromPitch(pitch); if (!HasFlag(VehicleFlags::MoveSingleCar)) { remaining_distance = _vehicleVelocityF64E0C + remaining_distance; @@ -8487,7 +8482,7 @@ void Vehicle::UpdateTrackMotionPreUpdate( { car.UpdateAdditionalAnimation(); } - car.acceleration = Geometry::kAccelerationFromPitch[EnumValue(car.pitch)]; + car.acceleration = Geometry::getAccelerationFromPitch(car.pitch); _vehicleUnkF64E10 = 1; if (!car.HasFlag(VehicleFlags::MoveSingleCar)) @@ -8515,7 +8510,7 @@ void Vehicle::UpdateTrackMotionPreUpdate( { break; } - car.acceleration += Geometry::kAccelerationFromPitch[EnumValue(car.pitch)]; + car.acceleration += Geometry::getAccelerationFromPitch(car.pitch); _vehicleUnkF64E10++; continue; } @@ -8533,7 +8528,7 @@ void Vehicle::UpdateTrackMotionPreUpdate( { break; } - car.acceleration = Geometry::kAccelerationFromPitch[EnumValue(car.pitch)]; + car.acceleration = Geometry::getAccelerationFromPitch(car.pitch); _vehicleUnkF64E10++; continue; } diff --git a/src/openrct2/ride/VehicleGeometry.h b/src/openrct2/ride/VehicleGeometry.h index f7b48c1146..a7c5b65c14 100644 --- a/src/openrct2/ride/VehicleGeometry.h +++ b/src/openrct2/ride/VehicleGeometry.h @@ -39,4 +39,13 @@ namespace OpenRCT2::RideVehicle::Geometry return kSubpositionTranslationDistances[index]; } + constexpr int32_t getAccelerationFromPitch(VehiclePitch pitch) + { + if (pitch >= VehiclePitch::pitchCount) + { + return 0; + } + return kAccelerationFromPitch[EnumValue(pitch)]; + } + } // namespace OpenRCT2::RideVehicle::Geometry From ea9a04d489b46caddee69fa52c019163f455f064 Mon Sep 17 00:00:00 2001 From: Spacek531 Date: Mon, 20 Oct 2025 21:31:04 -0700 Subject: [PATCH 08/14] move horizontal and vertical arrays --- src/openrct2/ride/Vehicle.cpp | 28 +++------------------------ src/openrct2/ride/VehicleGeometry.cpp | 24 +++++++++++++++++++++++ src/openrct2/ride/VehicleGeometry.h | 2 ++ 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index ac0dc5b6b2..f98f343991 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -393,28 +393,6 @@ static constexpr CoordsXY kSurroundingTiles[] = { { 0, +kCoordsXYStep }, }; -/** rct2: 0x009A37E4 */ -static constexpr int32_t kUnk9A37E4[] = { - 2147483647, 2106585154, 1985590284, 1636362342, 1127484953, 2106585154, 1985590284, 1636362342, 1127484953, - 58579923, 0, -555809667, -1073741824, -1518500249, -1859775391, -2074309916, -2147483647, 58579923, - 0, -555809667, -1073741824, -1518500249, -1859775391, -2074309916, 1859775393, 1073741824, 0, - -1073741824, -1859775393, 1859775393, 1073741824, 0, -1073741824, -1859775393, 1859775393, 1073741824, - 0, -1073741824, -1859775393, 1859775393, 1073741824, 0, -1073741824, -1859775393, 2144540595, - 2139311823, 2144540595, 2139311823, 2135719507, 2135719507, 2125953864, 2061796213, 1411702590, 2125953864, - 2061796213, 1411702590, 1985590284, 1636362342, 1127484953, 2115506168, 2115506168, -}; - -/** rct2: 0x009A38D4 */ -static constexpr int32_t kUnk9A38D4[] = { - 0, 417115092, 817995863, 1390684831, 1827693544, -417115092, -817995863, -1390684831, -1827693544, - 2066040965, 2147483647, 2074309916, 1859775393, 1518500249, 1073741824, 555809666, 0, -2066040965, - -2147483647, -2074309916, -1859775393, -1518500249, -1073741824, -555809666, 1073741824, 1859775393, 2147483647, - 1859775393, 1073741824, -1073741824, -1859775393, -2147483647, -1859775393, -1073741824, 1073741824, 1859775393, - 2147483647, 1859775393, 1073741824, -1073741824, -1859775393, -2147483647, -1859775393, -1073741824, 112390610, - 187165532, -112390610, -187165532, 224473165, -224473165, 303325208, 600568389, 1618265062, -303325208, - -600568389, -1618265062, -817995863, -1390684831, -1827693544, 369214930, -369214930, -}; - /** rct2: 0x009A39C4 */ static constexpr int32_t kUnk9A39C4[] = { 2147483647, 2096579710, 1946281152, 2096579710, 1946281152, 1380375879, 555809667, -372906620, -1231746017, -1859775391, @@ -2952,9 +2930,9 @@ void Vehicle::UpdateCrashSetup() trainVehicle->sub_state = 0; int32_t trainX = stru_9A3AC4[trainVehicle->Orientation / 2].x; int32_t trainY = stru_9A3AC4[trainVehicle->Orientation / 2].y; - auto trainZ = kUnk9A38D4[EnumValue(trainVehicle->pitch)] >> 23; + auto trainZ = Geometry::kPitchVerticalComponent[EnumValue(trainVehicle->pitch)] >> 23; - int32_t ecx = kUnk9A37E4[EnumValue(trainVehicle->pitch)] >> 15; + int32_t ecx = Geometry::kPitchHorizontalComponent[EnumValue(trainVehicle->pitch)] >> 15; trainX *= ecx; trainY *= ecx; trainX >>= 16; @@ -5055,7 +5033,7 @@ OpenRCT2::Audio::SoundId Vehicle::ProduceScreamSound(const int32_t totalNumPeeps */ GForces Vehicle::GetGForces() const { - int32_t gForceVert = ((static_cast(0x280000)) * kUnk9A37E4[EnumValue(pitch)]) >> 32; + int32_t gForceVert = ((static_cast(0x280000)) * Geometry::kPitchHorizontalComponent[EnumValue(pitch)]) >> 32; gForceVert = ((static_cast(gForceVert)) * kUnk9A39C4[EnumValue(roll)]) >> 32; const auto& ted = GetTrackElementDescriptor(GetTrackType()); diff --git a/src/openrct2/ride/VehicleGeometry.cpp b/src/openrct2/ride/VehicleGeometry.cpp index c3073c811a..52bb7c8de9 100644 --- a/src/openrct2/ride/VehicleGeometry.cpp +++ b/src/openrct2/ride/VehicleGeometry.cpp @@ -115,4 +115,28 @@ namespace OpenRCT2::RideVehicle::Geometry }); static_assert(std::size(kAccelerationFromPitch) == EnumValue(VehiclePitch::pitchCount)); + /** rct2: 0x009A37E4 */ + constexpr auto kPitchHorizontalComponent = std::to_array({ + 2147483647, 2106585154, 1985590284, 1636362342, 1127484953, 2106585154, 1985590284, 1636362342, 1127484953, + 58579923, 0, -555809667, -1073741824, -1518500249, -1859775391, -2074309916, -2147483647, 58579923, + 0, -555809667, -1073741824, -1518500249, -1859775391, -2074309916, 1859775393, 1073741824, 0, + -1073741824, -1859775393, 1859775393, 1073741824, 0, -1073741824, -1859775393, 1859775393, 1073741824, + 0, -1073741824, -1859775393, 1859775393, 1073741824, 0, -1073741824, -1859775393, 2144540595, + 2139311823, 2144540595, 2139311823, 2135719507, 2135719507, 2125953864, 2061796213, 1411702590, 2125953864, + 2061796213, 1411702590, 1985590284, 1636362342, 1127484953, 2115506168, 2115506168, + }); + static_assert(std::size(kPitchHorizontalComponent) == EnumValue(VehiclePitch::pitchCount)); + + /** rct2: 0x009A38D4 */ + constexpr auto kPitchVerticalComponent = std::to_array({ + 0, 417115092, 817995863, 1390684831, 1827693544, -417115092, -817995863, -1390684831, -1827693544, + 2066040965, 2147483647, 2074309916, 1859775393, 1518500249, 1073741824, 555809666, 0, -2066040965, + -2147483647, -2074309916, -1859775393, -1518500249, -1073741824, -555809666, 1073741824, 1859775393, 2147483647, + 1859775393, 1073741824, -1073741824, -1859775393, -2147483647, -1859775393, -1073741824, 1073741824, 1859775393, + 2147483647, 1859775393, 1073741824, -1073741824, -1859775393, -2147483647, -1859775393, -1073741824, 112390610, + 187165532, -112390610, -187165532, 224473165, -224473165, 303325208, 600568389, 1618265062, -303325208, + -600568389, -1618265062, -817995863, -1390684831, -1827693544, 369214930, -369214930, + }); + static_assert(std::size(kPitchVerticalComponent) == EnumValue(VehiclePitch::pitchCount)); + } // namespace OpenRCT2::RideVehicle::Geometry diff --git a/src/openrct2/ride/VehicleGeometry.h b/src/openrct2/ride/VehicleGeometry.h index a7c5b65c14..32528df016 100644 --- a/src/openrct2/ride/VehicleGeometry.h +++ b/src/openrct2/ride/VehicleGeometry.h @@ -28,6 +28,8 @@ namespace OpenRCT2::RideVehicle::Geometry extern const std::array kSubpositionTranslationDistances; extern const std::array kFreeroamVehicleMovementData; extern const std::array kAccelerationFromPitch; + extern const std::array kPitchHorizontalComponent; + extern const std::array kPitchVerticalComponent; /** The distance between subposition points in a movement vector. * Squashes vector components to 0 or !0, so vector length is ignored. From 0070eda86bad3b6a3ac62ad95b551c1cda20241e Mon Sep 17 00:00:00 2001 From: Spacek531 Date: Mon, 20 Oct 2025 21:55:55 -0700 Subject: [PATCH 09/14] combine horizontal and vertical arrays into one --- src/openrct2/ride/Vehicle.cpp | 6 +- src/openrct2/ride/VehicleGeometry.cpp | 88 ++++++++++++++++++++------- src/openrct2/ride/VehicleGeometry.h | 3 +- 3 files changed, 70 insertions(+), 27 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index f98f343991..7cb1310062 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -2930,9 +2930,9 @@ void Vehicle::UpdateCrashSetup() trainVehicle->sub_state = 0; int32_t trainX = stru_9A3AC4[trainVehicle->Orientation / 2].x; int32_t trainY = stru_9A3AC4[trainVehicle->Orientation / 2].y; - auto trainZ = Geometry::kPitchVerticalComponent[EnumValue(trainVehicle->pitch)] >> 23; + auto trainZ = Geometry::kPitchToDirectionVectorFromGeometryInt32[EnumValue(trainVehicle->pitch)].y >> 23; - int32_t ecx = Geometry::kPitchHorizontalComponent[EnumValue(trainVehicle->pitch)] >> 15; + int32_t ecx = Geometry::kPitchToDirectionVectorFromGeometryInt32[EnumValue(trainVehicle->pitch)].x >> 15; trainX *= ecx; trainY *= ecx; trainX >>= 16; @@ -5033,7 +5033,7 @@ OpenRCT2::Audio::SoundId Vehicle::ProduceScreamSound(const int32_t totalNumPeeps */ GForces Vehicle::GetGForces() const { - int32_t gForceVert = ((static_cast(0x280000)) * Geometry::kPitchHorizontalComponent[EnumValue(pitch)]) >> 32; + int32_t gForceVert = ((static_cast(0x280000)) * Geometry::kPitchToDirectionVectorFromGeometryInt32[EnumValue(pitch)].x) >> 32; gForceVert = ((static_cast(gForceVert)) * kUnk9A39C4[EnumValue(roll)]) >> 32; const auto& ted = GetTrackElementDescriptor(GetTrackType()); diff --git a/src/openrct2/ride/VehicleGeometry.cpp b/src/openrct2/ride/VehicleGeometry.cpp index 52bb7c8de9..592c421daf 100644 --- a/src/openrct2/ride/VehicleGeometry.cpp +++ b/src/openrct2/ride/VehicleGeometry.cpp @@ -115,28 +115,72 @@ namespace OpenRCT2::RideVehicle::Geometry }); static_assert(std::size(kAccelerationFromPitch) == EnumValue(VehiclePitch::pitchCount)); - /** rct2: 0x009A37E4 */ - constexpr auto kPitchHorizontalComponent = std::to_array({ - 2147483647, 2106585154, 1985590284, 1636362342, 1127484953, 2106585154, 1985590284, 1636362342, 1127484953, - 58579923, 0, -555809667, -1073741824, -1518500249, -1859775391, -2074309916, -2147483647, 58579923, - 0, -555809667, -1073741824, -1518500249, -1859775391, -2074309916, 1859775393, 1073741824, 0, - -1073741824, -1859775393, 1859775393, 1073741824, 0, -1073741824, -1859775393, 1859775393, 1073741824, - 0, -1073741824, -1859775393, 1859775393, 1073741824, 0, -1073741824, -1859775393, 2144540595, - 2139311823, 2144540595, 2139311823, 2135719507, 2135719507, 2125953864, 2061796213, 1411702590, 2125953864, - 2061796213, 1411702590, 1985590284, 1636362342, 1127484953, 2115506168, 2115506168, + /** rct2: 0x009A37E4 + * rct2: 0x009A38D4 + */ + constexpr auto kPitchToDirectionVectorFromGeometryInt32 = std::to_array({ + { 2147483647, 0 }, // flat + { 2106585154, 417115092 }, // up12 + { 1985590284, 817995863 }, // up25 + { 1636362342, 1390684831 }, // up42 + { 1127484953, 1827693544 }, // up60 + { 2106585154, -417115092 }, // down12 + { 1985590284, -817995863 }, // down25 + { 1636362342, -1390684831 }, // down42 + { 1127484953, -1827693544 }, // down60 + { 58579923, 2066040965 }, // up75 + { 0, 2147483647 }, // up90 + { -555809667, 2074309916 }, // up115 + { -1073741824, 1859775393 }, // up120 + { -1518500249, 1518500249 }, // up135 + { -1859775391, 1073741824 }, // up150 + { -2074309916, 555809666 }, // up165 + { -2147483647, 0 }, // inverted + { 58579923, -2066040965 }, // down75 + { 0, -2147483647 }, // down90 + { -555809667, -2074309916 }, // down115 + { -1073741824, -1859775393 }, // down120 + { -1518500249, -1518500249 }, // down135 + { -1859775391, -1073741824 }, // down150 + { -2074309916, -555809666 }, // down165 + { 1859775393, 1073741824 }, // corkscrewUpRight0 + { 1073741824, 1859775393 }, // corkscrewUpRight1 + { 0, 2147483647 }, // corkscrewUpRight2 + { -1073741824, 1859775393 }, // corkscrewUpRight3 + { -1859775393, 1073741824 }, // corkscrewUpRight4 + { 1859775393, -1073741824 }, // corkscrewDownLeft0 + { 1073741824, -1859775393 }, // corkscrewDownLeft1 + { 0, -2147483647 }, // corkscrewDownLeft2 + { -1073741824, -1859775393 }, // corkscrewDownLeft3 + { -1859775393, -1073741824 }, // corkscrewDownLeft4 + { 1859775393, 1073741824 }, // corkscrewUpLeft0 + { 1073741824, 1859775393 }, // corkscrewUpLeft1 + { 0, 2147483647 }, // corkscrewUpLeft2 + { -1073741824, 1859775393 }, // corkscrewUpLeft3 + { -1859775393, 1073741824 }, // corkscrewUpLeft4 + { 1859775393, -1073741824 }, // corkscrewDownRight0 + { 1073741824, -1859775393 }, // corkscrewDownRight1 + { 0, -2147483647 }, // corkscrewDownRight2 + { -1073741824, -1859775393 }, // corkscrewDownRight3 + { -1859775393, -1073741824 }, // corkscrewDownRight4 + { 2144540595, 112390610 }, // upHalfHelixLarge + { 2139311823, 187165532 }, // upHalfHelixSmall + { 2144540595, -112390610 }, // downHalfHelixLarge + { 2139311823, -187165532 }, // downHalfHelixSmall + { 2135719507, 224473165 }, // upQuarterHelix + { 2135719507, -224473165 }, // downQuarterHelix + { 2125953864, 303325208 }, // up8 + { 2061796213, 600568389 }, // up16 + { 1411702590, 1618265062 }, // up50 + { 2125953864, -303325208 }, // down8 + { 2061796213, -600568389 }, // down16 + { 1411702590, -1618265062 }, // down50 + { 1985590284, -817995863 }, // uninvertingDown25 + { 1636362342, -1390684831 }, // uninvertingDown42 + { 1127484953, -1827693544 }, // uninvertingDown60 + { 2115506168, 369214930 }, // curvedLifthillUp + { 2115506168, -369214930 }, // curvedLiftHillDown }); - static_assert(std::size(kPitchHorizontalComponent) == EnumValue(VehiclePitch::pitchCount)); - - /** rct2: 0x009A38D4 */ - constexpr auto kPitchVerticalComponent = std::to_array({ - 0, 417115092, 817995863, 1390684831, 1827693544, -417115092, -817995863, -1390684831, -1827693544, - 2066040965, 2147483647, 2074309916, 1859775393, 1518500249, 1073741824, 555809666, 0, -2066040965, - -2147483647, -2074309916, -1859775393, -1518500249, -1073741824, -555809666, 1073741824, 1859775393, 2147483647, - 1859775393, 1073741824, -1073741824, -1859775393, -2147483647, -1859775393, -1073741824, 1073741824, 1859775393, - 2147483647, 1859775393, 1073741824, -1073741824, -1859775393, -2147483647, -1859775393, -1073741824, 112390610, - 187165532, -112390610, -187165532, 224473165, -224473165, 303325208, 600568389, 1618265062, -303325208, - -600568389, -1618265062, -817995863, -1390684831, -1827693544, 369214930, -369214930, - }); - static_assert(std::size(kPitchVerticalComponent) == EnumValue(VehiclePitch::pitchCount)); + static_assert(std::size(kPitchToDirectionVectorFromGeometryInt32) == EnumValue(VehiclePitch::pitchCount)); } // namespace OpenRCT2::RideVehicle::Geometry diff --git a/src/openrct2/ride/VehicleGeometry.h b/src/openrct2/ride/VehicleGeometry.h index 32528df016..8a0203f048 100644 --- a/src/openrct2/ride/VehicleGeometry.h +++ b/src/openrct2/ride/VehicleGeometry.h @@ -28,8 +28,7 @@ namespace OpenRCT2::RideVehicle::Geometry extern const std::array kSubpositionTranslationDistances; extern const std::array kFreeroamVehicleMovementData; extern const std::array kAccelerationFromPitch; - extern const std::array kPitchHorizontalComponent; - extern const std::array kPitchVerticalComponent; + extern const std::array kPitchToDirectionVectorFromGeometryInt32; /** The distance between subposition points in a movement vector. * Squashes vector components to 0 or !0, so vector length is ignored. From 8bf18c4543ed5080be4a6943394441a02d5a81d9 Mon Sep 17 00:00:00 2001 From: Spacek531 Date: Mon, 20 Oct 2025 22:01:01 -0700 Subject: [PATCH 10/14] use getter for pitch components --- src/openrct2/ride/Vehicle.cpp | 8 +++++--- src/openrct2/ride/VehicleGeometry.cpp | 4 ++-- src/openrct2/ride/VehicleGeometry.h | 11 ++++++++++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 7cb1310062..1890553909 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -2930,9 +2930,11 @@ void Vehicle::UpdateCrashSetup() trainVehicle->sub_state = 0; int32_t trainX = stru_9A3AC4[trainVehicle->Orientation / 2].x; int32_t trainY = stru_9A3AC4[trainVehicle->Orientation / 2].y; - auto trainZ = Geometry::kPitchToDirectionVectorFromGeometryInt32[EnumValue(trainVehicle->pitch)].y >> 23; - int32_t ecx = Geometry::kPitchToDirectionVectorFromGeometryInt32[EnumValue(trainVehicle->pitch)].x >> 15; + auto carLaunchDirection = Geometry::getPitchVector32(trainVehicle->pitch); + + auto trainZ = carLaunchDirection.y >> 23; + int32_t ecx = carLaunchDirection.x >> 15; trainX *= ecx; trainY *= ecx; trainX >>= 16; @@ -5033,7 +5035,7 @@ OpenRCT2::Audio::SoundId Vehicle::ProduceScreamSound(const int32_t totalNumPeeps */ GForces Vehicle::GetGForces() const { - int32_t gForceVert = ((static_cast(0x280000)) * Geometry::kPitchToDirectionVectorFromGeometryInt32[EnumValue(pitch)].x) >> 32; + int32_t gForceVert = ((static_cast(0x280000)) * Geometry::getPitchVector32(pitch).x) >> 32; gForceVert = ((static_cast(gForceVert)) * kUnk9A39C4[EnumValue(roll)]) >> 32; const auto& ted = GetTrackElementDescriptor(GetTrackType()); diff --git a/src/openrct2/ride/VehicleGeometry.cpp b/src/openrct2/ride/VehicleGeometry.cpp index 592c421daf..6882f12149 100644 --- a/src/openrct2/ride/VehicleGeometry.cpp +++ b/src/openrct2/ride/VehicleGeometry.cpp @@ -118,7 +118,7 @@ namespace OpenRCT2::RideVehicle::Geometry /** rct2: 0x009A37E4 * rct2: 0x009A38D4 */ - constexpr auto kPitchToDirectionVectorFromGeometryInt32 = std::to_array({ + constexpr auto kPitchToDirectionVectorInt32 = std::to_array({ { 2147483647, 0 }, // flat { 2106585154, 417115092 }, // up12 { 1985590284, 817995863 }, // up25 @@ -181,6 +181,6 @@ namespace OpenRCT2::RideVehicle::Geometry { 2115506168, 369214930 }, // curvedLifthillUp { 2115506168, -369214930 }, // curvedLiftHillDown }); - static_assert(std::size(kPitchToDirectionVectorFromGeometryInt32) == EnumValue(VehiclePitch::pitchCount)); + static_assert(std::size(kPitchToDirectionVectorInt32) == EnumValue(VehiclePitch::pitchCount)); } // namespace OpenRCT2::RideVehicle::Geometry diff --git a/src/openrct2/ride/VehicleGeometry.h b/src/openrct2/ride/VehicleGeometry.h index 8a0203f048..d877882d3a 100644 --- a/src/openrct2/ride/VehicleGeometry.h +++ b/src/openrct2/ride/VehicleGeometry.h @@ -28,7 +28,7 @@ namespace OpenRCT2::RideVehicle::Geometry extern const std::array kSubpositionTranslationDistances; extern const std::array kFreeroamVehicleMovementData; extern const std::array kAccelerationFromPitch; - extern const std::array kPitchToDirectionVectorFromGeometryInt32; + extern const std::array kPitchToDirectionVectorInt32; /** The distance between subposition points in a movement vector. * Squashes vector components to 0 or !0, so vector length is ignored. @@ -49,4 +49,13 @@ namespace OpenRCT2::RideVehicle::Geometry return kAccelerationFromPitch[EnumValue(pitch)]; } + constexpr CoordsXY getPitchVector32(VehiclePitch pitch) + { + if (pitch >= VehiclePitch::pitchCount) + { + pitch = VehiclePitch::flat; + } + return kPitchToDirectionVectorInt32[EnumValue(pitch)]; + } + } // namespace OpenRCT2::RideVehicle::Geometry From 965ce8bf69a937233aa05b95156540f6be78b87b Mon Sep 17 00:00:00 2001 From: Spacek531 Date: Mon, 20 Oct 2025 22:11:20 -0700 Subject: [PATCH 11/14] rename pitch direction vector and move roll component array --- src/openrct2/ride/Vehicle.cpp | 8 +------- src/openrct2/ride/VehicleGeometry.cpp | 7 +++++++ src/openrct2/ride/VehicleGeometry.h | 1 + 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 1890553909..c4501edeef 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -393,12 +393,6 @@ static constexpr CoordsXY kSurroundingTiles[] = { { 0, +kCoordsXYStep }, }; -/** rct2: 0x009A39C4 */ -static constexpr int32_t kUnk9A39C4[] = { - 2147483647, 2096579710, 1946281152, 2096579710, 1946281152, 1380375879, 555809667, -372906620, -1231746017, -1859775391, - 1380375879, 555809667, -372906620, -1231746017, -1859775391, 0, 2096579710, 1946281152, 2096579710, 1946281152, -}; - static constexpr OpenRCT2::Audio::SoundId kDoorOpenSoundIds[] = { OpenRCT2::Audio::SoundId::null, // DoorSoundType::none OpenRCT2::Audio::SoundId::doorOpen, // DoorSoundType::door @@ -5036,7 +5030,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)) * kUnk9A39C4[EnumValue(roll)]) >> 32; + gForceVert = ((static_cast(gForceVert)) * Geometry::kRollHorizontalComponent[EnumValue(roll)]) >> 32; const auto& ted = GetTrackElementDescriptor(GetTrackType()); const int32_t vertFactor = ted.verticalFactor(track_progress); diff --git a/src/openrct2/ride/VehicleGeometry.cpp b/src/openrct2/ride/VehicleGeometry.cpp index 6882f12149..25a27e3a33 100644 --- a/src/openrct2/ride/VehicleGeometry.cpp +++ b/src/openrct2/ride/VehicleGeometry.cpp @@ -183,4 +183,11 @@ namespace OpenRCT2::RideVehicle::Geometry }); static_assert(std::size(kPitchToDirectionVectorInt32) == EnumValue(VehiclePitch::pitchCount)); + /** rct2: 0x009A39C4 */ + constexpr 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, + }); + static_assert(std::size(kRollHorizontalComponent) == EnumValue(VehicleRoll::rollCount)); } // namespace OpenRCT2::RideVehicle::Geometry diff --git a/src/openrct2/ride/VehicleGeometry.h b/src/openrct2/ride/VehicleGeometry.h index d877882d3a..7768dbbddf 100644 --- a/src/openrct2/ride/VehicleGeometry.h +++ b/src/openrct2/ride/VehicleGeometry.h @@ -29,6 +29,7 @@ namespace OpenRCT2::RideVehicle::Geometry extern const std::array kFreeroamVehicleMovementData; extern const std::array kAccelerationFromPitch; extern const std::array kPitchToDirectionVectorInt32; + extern const std::array kRollHorizontalComponent; /** The distance between subposition points in a movement vector. * Squashes vector components to 0 or !0, so vector length is ignored. From af3286acef562eb50ae562187eda13bf97f63df0 Mon Sep 17 00:00:00 2001 From: Spacek531 Date: Mon, 20 Oct 2025 23:18:53 -0700 Subject: [PATCH 12/14] move doppler and crash direction arrays --- src/openrct2/ride/Vehicle.cpp | 12 ++---- src/openrct2/ride/VehicleData.cpp | 36 ----------------- src/openrct2/ride/VehicleData.h | 2 - src/openrct2/ride/VehicleGeometry.cpp | 58 +++++++++++++++++++++++++++ src/openrct2/ride/VehicleGeometry.h | 2 + 5 files changed, 63 insertions(+), 47 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index c4501edeef..e81dd5970f 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -2883,12 +2883,6 @@ void Vehicle::UpdateCollisionSetup() velocity = 0; } -/** rct2: 0x009A3AC4, 0x009A3AC6 */ -static constexpr CoordsXY stru_9A3AC4[] = { - { -256, 0 }, { -236, 98 }, { -181, 181 }, { -98, 236 }, { 0, 256 }, { 98, 236 }, { 181, 181 }, { 236, 98 }, - { 256, 0 }, { 236, -98 }, { 181, -181 }, { 98, -236 }, { 0, -256 }, { -98, -236 }, { -181, -181 }, { -236, -98 }, -}; - /** * * rct2: 0x006D9EFE @@ -2922,8 +2916,8 @@ void Vehicle::UpdateCrashSetup() lastVehicle = trainVehicle; trainVehicle->sub_state = 0; - int32_t trainX = stru_9A3AC4[trainVehicle->Orientation / 2].x; - int32_t trainY = stru_9A3AC4[trainVehicle->Orientation / 2].y; + int32_t trainX = Geometry::kCrashDirectionComponents[trainVehicle->Orientation / 2].x; + int32_t trainY = Geometry::kCrashDirectionComponents[trainVehicle->Orientation / 2].y; auto carLaunchDirection = Geometry::getPitchVector32(trainVehicle->pitch); @@ -4922,7 +4916,7 @@ void Vehicle::UpdateSound() sound2_volume = soundIdVolume.volume; // Calculate Sound Vector (used for sound frequency calcs) - int32_t soundDirection = SpriteDirectionToSoundDirection[Orientation]; + int32_t soundDirection = Geometry::kSpriteDirectionToSoundDirection[Orientation]; int32_t soundVector = ((velocity >> 14) * soundDirection) >> 14; soundVector = std::clamp(soundVector, -127, 127); diff --git a/src/openrct2/ride/VehicleData.cpp b/src/openrct2/ride/VehicleData.cpp index c794105d62..ad3f4fd10d 100644 --- a/src/openrct2/ride/VehicleData.cpp +++ b/src/openrct2/ride/VehicleData.cpp @@ -794,40 +794,4 @@ const uint8_t MotionSimulatorTimeToSpriteMap[] = { }; const int32_t MotionSimulatorTimeToSpriteMapCount = static_cast(std::size(MotionSimulatorTimeToSpriteMap)); - -/** rct2: 0x009A3684 */ -const int32_t SpriteDirectionToSoundDirection[] = { - -0x4000, // 0 - -0x3000, // 1 - -0x2000, // 2 - -0x1000, // 3 - 0, // 4 - 0x1000, // 5 - 0x2000, // 6 - 0x3000, // 7 - 0x4000, // 8 - 0x4800, // 9 - 0x4800, // 10 - 0x4800, // 11 - 0x4800, // 12 - 0x4800, // 13 - 0x4800, // 14 - 0x4800, // 15 - 0x4000, // 16 - 0x3000, // 17 - 0x2000, // 18 - 0x1000, // 19 - 0, // 20 - -0x1000, // 21 - -0x2000, // 22 - -0x3000, // 23 - -0x4000, // 24 - -0x4800, // 25 - -0x4800, // 26 - -0x4800, // 27 - -0x4800, // 28 - -0x4800, // 29 - -0x4800, // 30 - -0x4800, // 31 -}; // clang-format on diff --git a/src/openrct2/ride/VehicleData.h b/src/openrct2/ride/VehicleData.h index 0618f82acd..8665a430d5 100644 --- a/src/openrct2/ride/VehicleData.h +++ b/src/openrct2/ride/VehicleData.h @@ -25,5 +25,3 @@ extern const TopSpinTimeToSpriteMap* TopSpinTimeToSpriteMaps[]; extern const uint8_t MotionSimulatorTimeToSpriteMap[]; extern const int32_t MotionSimulatorTimeToSpriteMapCount; - -extern const int32_t SpriteDirectionToSoundDirection[]; diff --git a/src/openrct2/ride/VehicleGeometry.cpp b/src/openrct2/ride/VehicleGeometry.cpp index 25a27e3a33..8148ee9ac6 100644 --- a/src/openrct2/ride/VehicleGeometry.cpp +++ b/src/openrct2/ride/VehicleGeometry.cpp @@ -190,4 +190,62 @@ namespace OpenRCT2::RideVehicle::Geometry -1859775391, 0, 2096579710, 1946281152, 2096579710, 1946281152, }); static_assert(std::size(kRollHorizontalComponent) == EnumValue(VehicleRoll::rollCount)); + + /** rct2: 0x009A3684 */ + constexpr auto kSpriteDirectionToSoundDirection = std::to_array({ + -0x4000, // 0 + -0x3000, // 1 + -0x2000, // 2 + -0x1000, // 3 + 0, // 4 + 0x1000, // 5 + 0x2000, // 6 + 0x3000, // 7 + 0x4000, // 8 + 0x4800, // 9 + 0x4800, // 10 + 0x4800, // 11 + 0x4800, // 12 + 0x4800, // 13 + 0x4800, // 14 + 0x4800, // 15 + 0x4000, // 16 + 0x3000, // 17 + 0x2000, // 18 + 0x1000, // 19 + 0, // 20 + -0x1000, // 21 + -0x2000, // 22 + -0x3000, // 23 + -0x4000, // 24 + -0x4800, // 25 + -0x4800, // 26 + -0x4800, // 27 + -0x4800, // 28 + -0x4800, // 29 + -0x4800, // 30 + -0x4800, // 31 + }); + + /** rct2: 0x009A3AC4, 0x009A3AC6 */ + constexpr auto kCrashDirectionComponents = std::to_array({ + { -256, 0 }, + { -236, 98 }, + { -181, 181 }, + { -98, 236 }, + { 0, 256 }, + { 98, 236 }, + { 181, 181 }, + { 236, 98 }, + { 256, 0 }, + { 236, -98 }, + { 181, -181 }, + { 98, -236 }, + { 0, -256 }, + { -98, -236 }, + { -181, -181 }, + { -236, -98 }, + }); + static_assert(std::size(kCrashDirectionComponents) == 16); + } // namespace OpenRCT2::RideVehicle::Geometry diff --git a/src/openrct2/ride/VehicleGeometry.h b/src/openrct2/ride/VehicleGeometry.h index 7768dbbddf..8358aa05e4 100644 --- a/src/openrct2/ride/VehicleGeometry.h +++ b/src/openrct2/ride/VehicleGeometry.h @@ -30,6 +30,8 @@ namespace OpenRCT2::RideVehicle::Geometry 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; /** The distance between subposition points in a movement vector. * Squashes vector components to 0 or !0, so vector length is ignored. From a7aea1ad8b4af8fe28d42acb922f2de699e41803 Mon Sep 17 00:00:00 2001 From: Spacek531 Date: Mon, 20 Oct 2025 23:22:51 -0700 Subject: [PATCH 13/14] fix formatting --- src/openrct2/ride/Vehicle.cpp | 3 ++- src/openrct2/ride/VehicleGeometry.cpp | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index e81dd5970f..773af388ff 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -7238,7 +7238,8 @@ bool Vehicle::UpdateTrackMotionForwards(const CarEntry* carEntry, const Ride& cu && track_progress >= 30 && track_progress <= 66; // Loc6DB8A5 - remaining_distance -= Geometry::getTranslationDistance(nextVehiclePosition - _vehicleCurPosition, useReverserDistance); + remaining_distance -= Geometry::getTranslationDistance( + nextVehiclePosition - _vehicleCurPosition, useReverserDistance); if (TrackSubposition == VehicleTrackSubposition::ReverserRCRearBogie && (trackType == TrackElemType::LeftReverser || trackType == TrackElemType::RightReverser) diff --git a/src/openrct2/ride/VehicleGeometry.cpp b/src/openrct2/ride/VehicleGeometry.cpp index 8148ee9ac6..c77eed6e08 100644 --- a/src/openrct2/ride/VehicleGeometry.cpp +++ b/src/openrct2/ride/VehicleGeometry.cpp @@ -14,6 +14,7 @@ namespace OpenRCT2::RideVehicle::Geometry { + // clang-format off /** rct2: 0x009A2930 */ constexpr auto kSubpositionTranslationDistances = std::to_array({ // For a base length of 8716 (0x220C) on the horizontal and 6554 (0x199A) on the vertical, @@ -26,7 +27,7 @@ namespace OpenRCT2::RideVehicle::Geometry 10905, // XZ translation 10905, // YZ translation 13961, // XYZ translation - // For the reverser car, multiply the horizontal distance by 2.5 and the vertical distance by 4.072. + // For the reverser car, multiply the horizontal distance by 2.5 and the vertical distance by 4.072. 0, // no movement 21790, // X translation 21790, // Y translation @@ -36,6 +37,7 @@ namespace OpenRCT2::RideVehicle::Geometry 27262, // YZ translation 34902, // XYZ translation }); + // clang-format on static_assert(std::size(kSubpositionTranslationDistances) == 16); /** rct2: 0x009A36C4 */ From 1e07385ff6e26bcd59eeb69462d3376fcb8faf96 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Tue, 21 Oct 2025 21:22:37 +0200 Subject: [PATCH 14/14] 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