From 98992ea6166b6b8df923d6756d3376acd8bf5194 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sat, 7 Sep 2024 00:37:17 +0200 Subject: [PATCH 1/4] Extract UpdateTrackMotionMiniGolfFlagsStatus() --- src/openrct2/ride/Vehicle.cpp | 353 ++++++++++++++++++---------------- src/openrct2/ride/Vehicle.h | 8 + 2 files changed, 192 insertions(+), 169 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 7c30157c8d..1bfeb193f6 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -7604,6 +7604,183 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c } } +Vehicle::UpdateMiniGolfFlagsStatus Vehicle::UpdateTrackMotionMiniGolfFlagsStatus(const Ride& curRide) +{ + if (var_D3 != 0) + { + var_D3--; + remaining_distance -= 0x368A; + if (remaining_distance < 0) + { + remaining_distance = 0; + } + + if (remaining_distance < 0x368A) + { + Loc6DCDE4(curRide); + return Vehicle::UpdateMiniGolfFlagsStatus::stop; + } + acceleration = AccelerationFromPitch[Pitch]; + _vehicleUnkF64E10++; + return Vehicle::UpdateMiniGolfFlagsStatus::restart; + } + + if (mini_golf_flags & MiniGolfFlag::Flag2) + { + uint8_t nextFrame = animation_frame + 1; + if (nextFrame < MiniGolfPeepAnimationLengths[EnumValue(mini_golf_current_animation)]) + { + animation_frame = nextFrame; + remaining_distance -= 0x368A; + if (remaining_distance < 0) + { + remaining_distance = 0; + } + + if (remaining_distance < 0x368A) + { + Loc6DCDE4(curRide); + return Vehicle::UpdateMiniGolfFlagsStatus::stop; + } + acceleration = AccelerationFromPitch[Pitch]; + _vehicleUnkF64E10++; + return Vehicle::UpdateMiniGolfFlagsStatus::restart; + } + mini_golf_flags &= ~MiniGolfFlag::Flag2; + } + + if (mini_golf_flags & MiniGolfFlag::Flag0) + { + auto vehicleIdx = IsHead() ? next_vehicle_on_ride : prev_vehicle_on_ride; + Vehicle* vEDI = GetEntity(vehicleIdx); + if (vEDI == nullptr) + { + return Vehicle::UpdateMiniGolfFlagsStatus::stop; + } + if (!(vEDI->mini_golf_flags & MiniGolfFlag::Flag0) || (vEDI->mini_golf_flags & MiniGolfFlag::Flag2)) + { + remaining_distance -= 0x368A; + if (remaining_distance < 0) + { + remaining_distance = 0; + } + + if (remaining_distance < 0x368A) + { + Loc6DCDE4(curRide); + return Vehicle::UpdateMiniGolfFlagsStatus::stop; + } + acceleration = AccelerationFromPitch[Pitch]; + _vehicleUnkF64E10++; + return Vehicle::UpdateMiniGolfFlagsStatus::restart; + } + if (vEDI->var_D3 != 0) + { + remaining_distance -= 0x368A; + if (remaining_distance < 0) + { + remaining_distance = 0; + } + + if (remaining_distance < 0x368A) + { + Loc6DCDE4(curRide); + return Vehicle::UpdateMiniGolfFlagsStatus::stop; + } + acceleration = AccelerationFromPitch[Pitch]; + _vehicleUnkF64E10++; + return Vehicle::UpdateMiniGolfFlagsStatus::restart; + } + vEDI->mini_golf_flags &= ~MiniGolfFlag::Flag0; + mini_golf_flags &= ~MiniGolfFlag::Flag0; + } + + if (mini_golf_flags & MiniGolfFlag::Flag1) + { + auto vehicleIdx = IsHead() ? next_vehicle_on_ride : prev_vehicle_on_ride; + Vehicle* vEDI = GetEntity(vehicleIdx); + if (vEDI == nullptr) + { + return Vehicle::UpdateMiniGolfFlagsStatus::stop; + } + if (!(vEDI->mini_golf_flags & MiniGolfFlag::Flag1) || (vEDI->mini_golf_flags & MiniGolfFlag::Flag2)) + { + remaining_distance -= 0x368A; + if (remaining_distance < 0) + { + remaining_distance = 0; + } + + if (remaining_distance < 0x368A) + { + Loc6DCDE4(curRide); + return Vehicle::UpdateMiniGolfFlagsStatus::stop; + } + acceleration = AccelerationFromPitch[Pitch]; + _vehicleUnkF64E10++; + return Vehicle::UpdateMiniGolfFlagsStatus::restart; + } + if (vEDI->var_D3 != 0) + { + remaining_distance -= 0x368A; + if (remaining_distance < 0) + { + remaining_distance = 0; + } + + if (remaining_distance < 0x368A) + { + Loc6DCDE4(curRide); + return Vehicle::UpdateMiniGolfFlagsStatus::stop; + } + acceleration = AccelerationFromPitch[Pitch]; + _vehicleUnkF64E10++; + return Vehicle::UpdateMiniGolfFlagsStatus::restart; + } + vEDI->mini_golf_flags &= ~MiniGolfFlag::Flag1; + mini_golf_flags &= ~MiniGolfFlag::Flag1; + } + + if (mini_golf_flags & MiniGolfFlag::Flag3) + { + Vehicle* vEDI = this; + + for (;;) + { + vEDI = GetEntity(vEDI->prev_vehicle_on_ride); + if (vEDI == this || vEDI == nullptr) + { + break; + } + if (vEDI->IsHead()) + continue; + if (!(vEDI->mini_golf_flags & MiniGolfFlag::Flag4)) + continue; + if (vEDI->TrackLocation != TrackLocation) + continue; + remaining_distance -= 0x368A; + if (remaining_distance < 0) + { + remaining_distance = 0; + } + + if (remaining_distance < 0x368A) + { + Loc6DCDE4(curRide); + return Vehicle::UpdateMiniGolfFlagsStatus::stop; + } + acceleration = AccelerationFromPitch[Pitch]; + _vehicleUnkF64E10++; + return Vehicle::UpdateMiniGolfFlagsStatus::restart; + } + + mini_golf_flags |= MiniGolfFlag::Flag4; + mini_golf_flags &= ~MiniGolfFlag::Flag3; + } + + return Vehicle::UpdateMiniGolfFlagsStatus::carryOn; +} + /** * rct2: 0x006DC3A7 * @@ -7637,177 +7814,15 @@ void Vehicle::UpdateTrackMotionMiniGolfVehicle(const Ride& curRide, const RideOb goto Loc6DCA9A; Loc6DC462: - if (var_D3 != 0) +{ + Vehicle::UpdateMiniGolfFlagsStatus flagsStatus = Vehicle::UpdateMiniGolfFlagsStatus::restart; + while (flagsStatus == Vehicle::UpdateMiniGolfFlagsStatus::restart) { - var_D3--; - remaining_distance -= 0x368A; - if (remaining_distance < 0) - { - remaining_distance = 0; - } - - if (remaining_distance < 0x368A) - { - Loc6DCDE4(curRide); - return; - } - acceleration = AccelerationFromPitch[Pitch]; - _vehicleUnkF64E10++; - goto Loc6DC462; - } - - if (mini_golf_flags & MiniGolfFlag::Flag2) - { - uint8_t nextFrame = animation_frame + 1; - if (nextFrame < MiniGolfPeepAnimationLengths[EnumValue(mini_golf_current_animation)]) - { - animation_frame = nextFrame; - remaining_distance -= 0x368A; - if (remaining_distance < 0) - { - remaining_distance = 0; - } - - if (remaining_distance < 0x368A) - { - Loc6DCDE4(curRide); - return; - } - acceleration = AccelerationFromPitch[Pitch]; - _vehicleUnkF64E10++; - goto Loc6DC462; - } - mini_golf_flags &= ~MiniGolfFlag::Flag2; - } - - if (mini_golf_flags & MiniGolfFlag::Flag0) - { - auto vehicleIdx = IsHead() ? next_vehicle_on_ride : prev_vehicle_on_ride; - Vehicle* vEDI = GetEntity(vehicleIdx); - if (vEDI == nullptr) - { - return; - } - if (!(vEDI->mini_golf_flags & MiniGolfFlag::Flag0) || (vEDI->mini_golf_flags & MiniGolfFlag::Flag2)) - { - remaining_distance -= 0x368A; - if (remaining_distance < 0) - { - remaining_distance = 0; - } - - if (remaining_distance < 0x368A) - { - Loc6DCDE4(curRide); - return; - } - acceleration = AccelerationFromPitch[Pitch]; - _vehicleUnkF64E10++; - goto Loc6DC462; - } - if (vEDI->var_D3 != 0) - { - remaining_distance -= 0x368A; - if (remaining_distance < 0) - { - remaining_distance = 0; - } - - if (remaining_distance < 0x368A) - { - Loc6DCDE4(curRide); - return; - } - acceleration = AccelerationFromPitch[Pitch]; - _vehicleUnkF64E10++; - goto Loc6DC462; - } - vEDI->mini_golf_flags &= ~MiniGolfFlag::Flag0; - mini_golf_flags &= ~MiniGolfFlag::Flag0; - } - - if (mini_golf_flags & MiniGolfFlag::Flag1) - { - auto vehicleIdx = IsHead() ? next_vehicle_on_ride : prev_vehicle_on_ride; - Vehicle* vEDI = GetEntity(vehicleIdx); - if (vEDI == nullptr) - { - return; - } - if (!(vEDI->mini_golf_flags & MiniGolfFlag::Flag1) || (vEDI->mini_golf_flags & MiniGolfFlag::Flag2)) - { - remaining_distance -= 0x368A; - if (remaining_distance < 0) - { - remaining_distance = 0; - } - - if (remaining_distance < 0x368A) - { - Loc6DCDE4(curRide); - return; - } - acceleration = AccelerationFromPitch[Pitch]; - _vehicleUnkF64E10++; - goto Loc6DC462; - } - if (vEDI->var_D3 != 0) - { - remaining_distance -= 0x368A; - if (remaining_distance < 0) - { - remaining_distance = 0; - } - - if (remaining_distance < 0x368A) - { - Loc6DCDE4(curRide); - return; - } - acceleration = AccelerationFromPitch[Pitch]; - _vehicleUnkF64E10++; - goto Loc6DC462; - } - vEDI->mini_golf_flags &= ~MiniGolfFlag::Flag1; - mini_golf_flags &= ~MiniGolfFlag::Flag1; - } - - if (mini_golf_flags & MiniGolfFlag::Flag3) - { - Vehicle* vEDI = this; - - for (;;) - { - vEDI = GetEntity(vEDI->prev_vehicle_on_ride); - if (vEDI == this || vEDI == nullptr) - { - break; - } - if (vEDI->IsHead()) - continue; - if (!(vEDI->mini_golf_flags & MiniGolfFlag::Flag4)) - continue; - if (vEDI->TrackLocation != TrackLocation) - continue; - remaining_distance -= 0x368A; - if (remaining_distance < 0) - { - remaining_distance = 0; - } - - if (remaining_distance < 0x368A) - { - Loc6DCDE4(curRide); - return; - } - acceleration = AccelerationFromPitch[Pitch]; - _vehicleUnkF64E10++; - goto Loc6DC462; - } - - mini_golf_flags |= MiniGolfFlag::Flag4; - mini_golf_flags &= ~MiniGolfFlag::Flag3; + flagsStatus = UpdateTrackMotionMiniGolfFlagsStatus(curRide); } + if (flagsStatus == UpdateMiniGolfFlagsStatus::stop) + return; +}; { uint16_t trackTotalProgress = GetTrackProgress(); diff --git a/src/openrct2/ride/Vehicle.h b/src/openrct2/ride/Vehicle.h index b2299c063c..7f2ec05343 100644 --- a/src/openrct2/ride/Vehicle.h +++ b/src/openrct2/ride/Vehicle.h @@ -379,6 +379,14 @@ private: void Loc6DCE02(const Ride& curRide); void Loc6DCDE4(const Ride& curRide); + + enum class UpdateMiniGolfFlagsStatus + { + carryOn, + restart, + stop, + }; + UpdateMiniGolfFlagsStatus UpdateTrackMotionMiniGolfFlagsStatus(const Ride& curRide); }; static_assert(sizeof(Vehicle) <= 512); From 717622ed01cc262811618b8339c88b2ba9e7a77c Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Mon, 7 Oct 2024 22:32:54 +0200 Subject: [PATCH 2/4] Cut out Mini Golf inverted code --- src/openrct2/ride/Vehicle.cpp | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 1bfeb193f6..3baf4634d3 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -7852,7 +7852,7 @@ Loc6DC462: direction = outDirection; } - if (PitchAndRollStart(HasFlag(VehicleFlags::CarIsInverted), tileElement) != TrackPitchAndRollEnd(GetTrackType())) + if (PitchAndRollStart(false, tileElement) != TrackPitchAndRollEnd(GetTrackType())) { _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; _vehicleVelocityF64E0C -= remaining_distance + 1; @@ -7866,18 +7866,6 @@ Loc6DC462: goto Loc6DCA9A; } - { - int32_t rideType = ::GetRide(tileElement->AsTrack()->GetRideIndex())->type; - ClearFlag(VehicleFlags::CarIsInverted); - if (GetRideTypeDescriptor(rideType).HasFlag(RtdFlag::hasInvertedVariant)) - { - if (tileElement->AsTrack()->IsInverted()) - { - SetFlag(VehicleFlags::CarIsInverted); - } - } - } - TrackLocation = trackPos; if (!IsHead()) @@ -8070,7 +8058,7 @@ Loc6DCA9A: tileElement = trackBeginEnd.begin_element; } - if (PitchAndRollStart(HasFlag(VehicleFlags::CarIsInverted), tileElement) != TrackPitchAndRollEnd(GetTrackType())) + if (PitchAndRollStart(false, tileElement) != TrackPitchAndRollEnd(GetTrackType())) { _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; _vehicleVelocityF64E0C -= remaining_distance - 0x368A; @@ -8085,18 +8073,6 @@ Loc6DCA9A: goto Loc6DC462; } - { - int32_t rideType = ::GetRide(tileElement->AsTrack()->GetRideIndex())->type; - ClearFlag(VehicleFlags::CarIsInverted); - if (GetRideTypeDescriptor(rideType).HasFlag(RtdFlag::hasInvertedVariant)) - { - if (tileElement->AsTrack()->IsInverted()) - { - SetFlag(VehicleFlags::CarIsInverted); - } - } - } - TrackLocation = trackPos; if (HasFlag(VehicleFlags::OnLiftHill)) From 7694195db7bfd77cd740d620cbc86e5919494d29 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Mon, 7 Oct 2024 22:35:53 +0200 Subject: [PATCH 3/4] Mini golf vehicle code: remove ifs that are always true --- src/openrct2/ride/Vehicle.cpp | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 3baf4634d3..f53f634da2 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -7839,10 +7839,6 @@ Loc6DC462: _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; _vehicleVelocityF64E0C -= remaining_distance + 1; remaining_distance = -1; - if (remaining_distance >= 0) - { - Loc6DCDE4(curRide); - } acceleration += AccelerationFromPitch[Pitch]; _vehicleUnkF64E10++; goto Loc6DCA9A; @@ -8045,10 +8041,6 @@ Loc6DCA9A: _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; _vehicleVelocityF64E0C -= remaining_distance + 1; remaining_distance = -1; - if (remaining_distance >= 0) - { - Loc6DCDE4(curRide); - } acceleration += AccelerationFromPitch[Pitch]; _vehicleUnkF64E10++; goto Loc6DCA9A; @@ -8063,11 +8055,6 @@ Loc6DCA9A: _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; _vehicleVelocityF64E0C -= remaining_distance - 0x368A; remaining_distance = 0x368A; - if (remaining_distance < 0x368A) - { - Loc6DCDE4(curRide); - return; - } acceleration = AccelerationFromPitch[Pitch]; _vehicleUnkF64E10++; goto Loc6DC462; @@ -8151,11 +8138,6 @@ Loc6DCA9A: vEBP->velocity = vEDI->velocity >> 1; } _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_2; - if (remaining_distance < 0x368A) - { - Loc6DCDE4(curRide); - return; - } acceleration = AccelerationFromPitch[Pitch]; _vehicleUnkF64E10++; goto Loc6DC462; From 9bdbeaf563b3fce6e38821df38880865ea99d1dc Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Mon, 7 Oct 2024 22:44:37 +0200 Subject: [PATCH 4/4] Mini golf vehicle code: remove more flag checks that are never set --- src/openrct2/ride/Vehicle.cpp | 63 +---------------------------------- 1 file changed, 1 insertion(+), 62 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index f53f634da2..24ccefca8b 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -8003,16 +8003,6 @@ Loc6DC462: bank_rotation = moveInfo->bank_rotation; Pitch = moveInfo->Pitch; - if (rideEntry.Cars[0].flags & CAR_ENTRY_FLAG_WOODEN_WILD_MOUSE_SWING) - { - if (Pitch != 0) - { - SwingSprite = 0; - SwingPosition = 0; - SwingSpeed = 0; - } - } - if (this == _vehicleFrontVehicle) { if (_vehicleVelocityF64E08 >= 0) @@ -8101,16 +8091,6 @@ Loc6DCA9A: bank_rotation = moveInfo->bank_rotation; Pitch = moveInfo->Pitch; - if (rideEntry.Cars[0].flags & CAR_ENTRY_FLAG_WOODEN_WILD_MOUSE_SWING) - { - if (Pitch != 0) - { - SwingSprite = 0; - SwingPosition = 0; - SwingSpeed = 0; - } - } - if (this == _vehicleFrontVehicle) { if (_vehicleVelocityF64E08 >= 0) @@ -8129,10 +8109,7 @@ Loc6DCA9A: Vehicle* vEDI = gCurrentVehicle; if (abs(vEDI->velocity - vEBP->velocity) > 14.0_mph) { - if (!(carEntry->flags & CAR_ENTRY_FLAG_BOAT_HIRE_COLLISION_DETECTION)) - { - _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_COLLISION; - } + _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_COLLISION; } vEDI->velocity = vEBP->velocity >> 1; vEBP->velocity = vEDI->velocity >> 1; @@ -8248,17 +8225,6 @@ int32_t Vehicle::UpdateTrackMotionMiniGolfCalculateAcceleration(const CarEntry& newAcceleration -= velocity >> 12; newAcceleration -= GetAccelerationDecrease2(velocity, totalMass); - if (!(carEntry.flags & CAR_ENTRY_FLAG_POWERED)) - { - return newAcceleration; - } - if (carEntry.flags & CAR_ENTRY_FLAG_POWERED_RIDE_UNRESTRICTED_GRAVITY) - { - if (speed * 0x4000 < velocity) - { - return newAcceleration; - } - } { int32_t poweredAcceleration = speed << 14; int32_t quarterForce = (speed * totalMass) >> 2; @@ -8271,33 +8237,6 @@ int32_t Vehicle::UpdateTrackMotionMiniGolfCalculateAcceleration(const CarEntry& if (quarterForce != 0) poweredAcceleration /= quarterForce; - if (carEntry.flags & CAR_ENTRY_FLAG_WATER_RIDE) - { - if (poweredAcceleration < 0) - { - poweredAcceleration >>= 4; - } - - if (carEntry.flags & CAR_ENTRY_FLAG_SPINNING) - { - spin_speed = std::clamp(spin_speed, VEHICLE_MIN_SPIN_SPEED_WATER_RIDE, VEHICLE_MAX_SPIN_SPEED_WATER_RIDE); - } - - if (Pitch != 0) - { - poweredAcceleration = std::max(0, poweredAcceleration); - if (carEntry.flags & CAR_ENTRY_FLAG_SPINNING) - { - if (Pitch == 2) - { - spin_speed = 0; - } - } - newAcceleration += poweredAcceleration; - return newAcceleration; - } - } - if (abs(velocity) > 1.0_mph) { newAcceleration = 0;