mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-06 06:32:56 +01:00
add getter for SubpositionTranslationDistance
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user