From 774240d08126d1a2b809b80ffaef99865dcd4a41 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sat, 25 Jan 2025 13:59:37 +0100 Subject: [PATCH 1/4] Make Loc6DC462 a loop --- src/openrct2/ride/Vehicle.cpp | 260 +++++++++++++++++----------------- 1 file changed, 129 insertions(+), 131 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 3ef5fdcc99..9b506462f3 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -7839,17 +7839,16 @@ void Vehicle::UpdateTrackMotionMiniGolfVehicle(const Ride& curRide, const RideOb goto Loc6DCA9A; Loc6DC462: -{ - Vehicle::UpdateMiniGolfFlagsStatus flagsStatus = Vehicle::UpdateMiniGolfFlagsStatus::restart; - while (flagsStatus == Vehicle::UpdateMiniGolfFlagsStatus::restart) + while (true) { - flagsStatus = UpdateTrackMotionMiniGolfFlagsStatus(curRide); - } - if (flagsStatus == UpdateMiniGolfFlagsStatus::stop) - return; -}; + Vehicle::UpdateMiniGolfFlagsStatus flagsStatus = Vehicle::UpdateMiniGolfFlagsStatus::restart; + while (flagsStatus == Vehicle::UpdateMiniGolfFlagsStatus::restart) + { + flagsStatus = UpdateTrackMotionMiniGolfFlagsStatus(curRide); + } + if (flagsStatus == UpdateMiniGolfFlagsStatus::stop) + return; - { uint16_t trackTotalProgress = GetTrackProgress(); if (track_progress + 1 >= trackTotalProgress) { @@ -7866,7 +7865,7 @@ Loc6DC462: remaining_distance = -1; acceleration += AccelerationFromPitch[Pitch]; _vehicleUnkF64E10++; - goto Loc6DCA9A; + break; } tileElement = output.element; trackPos = { output.x, output.y, outZ }; @@ -7884,7 +7883,7 @@ Loc6DC462: } acceleration += AccelerationFromPitch[Pitch]; _vehicleUnkF64E10++; - goto Loc6DCA9A; + break; } TrackLocation = trackPos; @@ -7913,137 +7912,136 @@ Loc6DC462: { track_progress += 1; } - } - if (!IsHead()) - { - animation_frame++; - if (animation_frame >= 6) + if (!IsHead()) { - animation_frame = 0; - } - } - const VehicleInfo* moveInfo; - for (;;) - { - moveInfo = GetMoveInfo(); - if (moveInfo->x != kLocationNull) - { - break; - } - switch (MiniGolfState(moveInfo->y)) - { - case MiniGolfState::Unk0: // Loc6DC7B4 - if (!IsHead()) - { - mini_golf_flags |= MiniGolfFlag::Flag3; - } - else - { - uint16_t rand16 = ScenarioRand() & 0xFFFF; - VehicleTrackSubposition nextTrackSubposition = VehicleTrackSubposition::MiniGolfBallPathC14; - if (rand16 <= 0xA000) - { - nextTrackSubposition = VehicleTrackSubposition::MiniGolfBallPathB12; - if (rand16 <= 0x900) - { - nextTrackSubposition = VehicleTrackSubposition::MiniGolfBallPathA10; - } - } - TrackSubposition = nextTrackSubposition; - } - track_progress++; - break; - case MiniGolfState::Unk1: // Loc6DC7ED - LOG_ERROR("Unused move info..."); - assert(false); - var_D3 = static_cast(moveInfo->z); - track_progress++; - break; - case MiniGolfState::Unk2: // Loc6DC800 - mini_golf_flags |= MiniGolfFlag::Flag0; - track_progress++; - break; - case MiniGolfState::Unk3: // Loc6DC810 - mini_golf_flags |= MiniGolfFlag::Flag1; - track_progress++; - break; - case MiniGolfState::Unk4: // Loc6DC820 + animation_frame++; + if (animation_frame >= 6) { - auto animation = MiniGolfAnimation(moveInfo->z); - // When the ride is closed occasionally the peep is removed - // but the vehicle is still on the track. This will prevent - // it from crashing in that situation. - auto* curPeep = TryGetEntity(peep[0]); - if (curPeep != nullptr) - { - if (animation == MiniGolfAnimation::SwingLeft) - { - if (curPeep->PeepId & 7) - { - animation = MiniGolfAnimation::Swing; - } - } - if (animation == MiniGolfAnimation::PuttLeft) - { - if (curPeep->PeepId & 7) - { - animation = MiniGolfAnimation::Putt; - } - } - } - mini_golf_current_animation = animation; animation_frame = 0; - track_progress++; + } + } + const VehicleInfo* moveInfo; + for (;;) + { + moveInfo = GetMoveInfo(); + if (moveInfo->x != kLocationNull) + { break; } - case MiniGolfState::Unk5: // Loc6DC87A - mini_golf_flags |= MiniGolfFlag::Flag2; - track_progress++; - break; - case MiniGolfState::Unk6: // Loc6DC88A - mini_golf_flags &= ~MiniGolfFlag::Flag4; - mini_golf_flags |= MiniGolfFlag::Flag5; - track_progress++; - break; - default: - LOG_ERROR("Invalid move info..."); - assert(false); - break; + switch (MiniGolfState(moveInfo->y)) + { + case MiniGolfState::Unk0: // Loc6DC7B4 + if (!IsHead()) + { + mini_golf_flags |= MiniGolfFlag::Flag3; + } + else + { + uint16_t rand16 = ScenarioRand() & 0xFFFF; + VehicleTrackSubposition nextTrackSubposition = VehicleTrackSubposition::MiniGolfBallPathC14; + if (rand16 <= 0xA000) + { + nextTrackSubposition = VehicleTrackSubposition::MiniGolfBallPathB12; + if (rand16 <= 0x900) + { + nextTrackSubposition = VehicleTrackSubposition::MiniGolfBallPathA10; + } + } + TrackSubposition = nextTrackSubposition; + } + track_progress++; + break; + case MiniGolfState::Unk1: // Loc6DC7ED + LOG_ERROR("Unused move info..."); + assert(false); + var_D3 = static_cast(moveInfo->z); + track_progress++; + break; + case MiniGolfState::Unk2: // Loc6DC800 + mini_golf_flags |= MiniGolfFlag::Flag0; + track_progress++; + break; + case MiniGolfState::Unk3: // Loc6DC810 + mini_golf_flags |= MiniGolfFlag::Flag1; + track_progress++; + break; + case MiniGolfState::Unk4: // Loc6DC820 + { + auto animation = MiniGolfAnimation(moveInfo->z); + // When the ride is closed occasionally the peep is removed + // but the vehicle is still on the track. This will prevent + // it from crashing in that situation. + auto* curPeep = TryGetEntity(peep[0]); + if (curPeep != nullptr) + { + if (animation == MiniGolfAnimation::SwingLeft) + { + if (curPeep->PeepId & 7) + { + animation = MiniGolfAnimation::Swing; + } + } + if (animation == MiniGolfAnimation::PuttLeft) + { + if (curPeep->PeepId & 7) + { + animation = MiniGolfAnimation::Putt; + } + } + } + mini_golf_current_animation = animation; + animation_frame = 0; + track_progress++; + break; + } + case MiniGolfState::Unk5: // Loc6DC87A + mini_golf_flags |= MiniGolfFlag::Flag2; + track_progress++; + break; + case MiniGolfState::Unk6: // Loc6DC88A + mini_golf_flags &= ~MiniGolfFlag::Flag4; + mini_golf_flags |= MiniGolfFlag::Flag5; + track_progress++; + break; + default: + LOG_ERROR("Invalid move info..."); + assert(false); + break; + } } - } - // Loc6DC8A1 - trackPos = { TrackLocation.x + moveInfo->x, TrackLocation.y + moveInfo->y, - TrackLocation.z + moveInfo->z + GetRideTypeDescriptor(curRide.type).Heights.VehicleZOffset }; + // Loc6DC8A1 + trackPos = { TrackLocation.x + moveInfo->x, TrackLocation.y + moveInfo->y, + TrackLocation.z + moveInfo->z + GetRideTypeDescriptor(curRide.type).Heights.VehicleZOffset }; - remaining_distance -= 0x368A; - if (remaining_distance < 0) - { - remaining_distance = 0; - } - - _vehicleCurPosition = trackPos; - Orientation = moveInfo->direction; - bank_rotation = moveInfo->bank_rotation; - Pitch = moveInfo->Pitch; - - if (this == _vehicleFrontVehicle) - { - if (_vehicleVelocityF64E08 >= 0) + remaining_distance -= 0x368A; + if (remaining_distance < 0) { - otherVehicleIndex = prev_vehicle_on_ride; - UpdateMotionCollisionDetection(trackPos, &otherVehicleIndex); + remaining_distance = 0; } + + _vehicleCurPosition = trackPos; + Orientation = moveInfo->direction; + bank_rotation = moveInfo->bank_rotation; + Pitch = moveInfo->Pitch; + + if (this == _vehicleFrontVehicle) + { + if (_vehicleVelocityF64E08 >= 0) + { + otherVehicleIndex = prev_vehicle_on_ride; + UpdateMotionCollisionDetection(trackPos, &otherVehicleIndex); + } + } + if (remaining_distance < 0x368A) + { + Loc6DCDE4(curRide); + return; + } + acceleration = AccelerationFromPitch[Pitch]; + _vehicleUnkF64E10++; } - if (remaining_distance < 0x368A) - { - Loc6DCDE4(curRide); - return; - } - acceleration = AccelerationFromPitch[Pitch]; - _vehicleUnkF64E10++; - goto Loc6DC462; Loc6DCA9A: if (track_progress == 0) @@ -8101,7 +8099,7 @@ Loc6DCA9A: track_progress -= 1; } - moveInfo = GetMoveInfo(); + auto moveInfo = GetMoveInfo(); trackPos = { TrackLocation.x + moveInfo->x, TrackLocation.y + moveInfo->y, TrackLocation.z + moveInfo->z + GetRideTypeDescriptor(curRide.type).Heights.VehicleZOffset }; From 3ad19f71ee1e1f479e98483ec62e35c634c388cb Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sat, 25 Jan 2025 14:21:24 +0100 Subject: [PATCH 2/4] Make Loc6DCA9A a loop --- src/openrct2/ride/Vehicle.cpp | 196 +++++++++++++++++----------------- 1 file changed, 99 insertions(+), 97 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 9b506462f3..8d375ce238 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -8044,115 +8044,117 @@ Loc6DC462: } Loc6DCA9A: - if (track_progress == 0) + while (true) { - tileElement = MapGetTrackElementAtOfTypeSeq(TrackLocation, GetTrackType(), 0); + if (track_progress == 0) { - TrackBeginEnd trackBeginEnd; - if (!TrackBlockGetPrevious({ TrackLocation, tileElement }, &trackBeginEnd)) + tileElement = MapGetTrackElementAtOfTypeSeq(TrackLocation, GetTrackType(), 0); + { + TrackBeginEnd trackBeginEnd; + if (!TrackBlockGetPrevious({ TrackLocation, tileElement }, &trackBeginEnd)) + { + _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; + _vehicleVelocityF64E0C -= remaining_distance + 1; + remaining_distance = -1; + acceleration += AccelerationFromPitch[Pitch]; + _vehicleUnkF64E10++; + continue; + } + trackPos = { trackBeginEnd.begin_x, trackBeginEnd.begin_y, trackBeginEnd.begin_z }; + direction = trackBeginEnd.begin_direction; + tileElement = trackBeginEnd.begin_element; + } + + if (PitchAndRollStart(false, tileElement) != TrackPitchAndRollEnd(GetTrackType())) { _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; - _vehicleVelocityF64E0C -= remaining_distance + 1; - remaining_distance = -1; - acceleration += AccelerationFromPitch[Pitch]; - _vehicleUnkF64E10++; - goto Loc6DCA9A; - } - trackPos = { trackBeginEnd.begin_x, trackBeginEnd.begin_y, trackBeginEnd.begin_z }; - direction = trackBeginEnd.begin_direction; - tileElement = trackBeginEnd.begin_element; - } - - if (PitchAndRollStart(false, tileElement) != TrackPitchAndRollEnd(GetTrackType())) - { - _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; - _vehicleVelocityF64E0C -= remaining_distance - 0x368A; - remaining_distance = 0x368A; - acceleration = AccelerationFromPitch[Pitch]; - _vehicleUnkF64E10++; - goto Loc6DC462; - } - - TrackLocation = trackPos; - - if (HasFlag(VehicleFlags::OnLiftHill)) - { - ClearFlag(VehicleFlags::OnLiftHill); - if (next_vehicle_on_train.IsNull()) - { - if (_vehicleVelocityF64E08 < 0) - { - _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_8; - } - } - } - - SetTrackType(tileElement->AsTrack()->GetTrackType()); - SetTrackDirection(direction); - brake_speed = tileElement->AsTrack()->GetBrakeBoosterSpeed(); - - // There are two bytes before the move info list - track_progress = GetTrackProgress(); - } - else - { - track_progress -= 1; - } - - auto moveInfo = GetMoveInfo(); - trackPos = { TrackLocation.x + moveInfo->x, TrackLocation.y + moveInfo->y, - TrackLocation.z + moveInfo->z + GetRideTypeDescriptor(curRide.type).Heights.VehicleZOffset }; - - remaining_distance -= 0x368A; - if (remaining_distance < 0) - { - remaining_distance = 0; - } - - _vehicleCurPosition = trackPos; - Orientation = moveInfo->direction; - bank_rotation = moveInfo->bank_rotation; - Pitch = moveInfo->Pitch; - - if (this == _vehicleFrontVehicle) - { - if (_vehicleVelocityF64E08 >= 0) - { - otherVehicleIndex = EntityId::FromUnderlying(var_44); // Possibly wrong?. - if (UpdateMotionCollisionDetection(trackPos, &otherVehicleIndex)) - { _vehicleVelocityF64E0C -= remaining_distance - 0x368A; remaining_distance = 0x368A; - { - Vehicle* vEBP = GetEntity(otherVehicleIndex); - if (vEBP == nullptr) - { - return; - } - Vehicle* vEDI = gCurrentVehicle; - if (abs(vEDI->velocity - vEBP->velocity) > 14.0_mph) - { - _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_COLLISION; - } - vEDI->velocity = vEBP->velocity >> 1; - vEBP->velocity = vEDI->velocity >> 1; - } - _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_2; acceleration = AccelerationFromPitch[Pitch]; _vehicleUnkF64E10++; goto Loc6DC462; } - } - } - if (remaining_distance >= 0) - { - Loc6DCDE4(curRide); - return; + TrackLocation = trackPos; + + if (HasFlag(VehicleFlags::OnLiftHill)) + { + ClearFlag(VehicleFlags::OnLiftHill); + if (next_vehicle_on_train.IsNull()) + { + if (_vehicleVelocityF64E08 < 0) + { + _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_8; + } + } + } + + SetTrackType(tileElement->AsTrack()->GetTrackType()); + SetTrackDirection(direction); + brake_speed = tileElement->AsTrack()->GetBrakeBoosterSpeed(); + + // There are two bytes before the move info list + track_progress = GetTrackProgress(); + } + else + { + track_progress -= 1; + } + + auto moveInfo = GetMoveInfo(); + trackPos = { TrackLocation.x + moveInfo->x, TrackLocation.y + moveInfo->y, + TrackLocation.z + moveInfo->z + GetRideTypeDescriptor(curRide.type).Heights.VehicleZOffset }; + + remaining_distance -= 0x368A; + if (remaining_distance < 0) + { + remaining_distance = 0; + } + + _vehicleCurPosition = trackPos; + Orientation = moveInfo->direction; + bank_rotation = moveInfo->bank_rotation; + Pitch = moveInfo->Pitch; + + if (this == _vehicleFrontVehicle) + { + if (_vehicleVelocityF64E08 >= 0) + { + otherVehicleIndex = EntityId::FromUnderlying(var_44); // Possibly wrong?. + if (UpdateMotionCollisionDetection(trackPos, &otherVehicleIndex)) + { + _vehicleVelocityF64E0C -= remaining_distance - 0x368A; + remaining_distance = 0x368A; + { + Vehicle* vEBP = GetEntity(otherVehicleIndex); + if (vEBP == nullptr) + { + return; + } + Vehicle* vEDI = gCurrentVehicle; + if (abs(vEDI->velocity - vEBP->velocity) > 14.0_mph) + { + _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_COLLISION; + } + vEDI->velocity = vEBP->velocity >> 1; + vEBP->velocity = vEDI->velocity >> 1; + } + _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_2; + acceleration = AccelerationFromPitch[Pitch]; + _vehicleUnkF64E10++; + goto Loc6DC462; + } + } + } + + if (remaining_distance >= 0) + { + Loc6DCDE4(curRide); + return; + } + acceleration += AccelerationFromPitch[Pitch]; + _vehicleUnkF64E10++; } - acceleration += AccelerationFromPitch[Pitch]; - _vehicleUnkF64E10++; - goto Loc6DCA9A; } void Vehicle::Loc6DCDE4(const Ride& curRide) From 4b13f45eec4c67745c36f88ee145f09b993dab90 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sat, 25 Jan 2025 14:40:23 +0100 Subject: [PATCH 3/4] Move Loc6DC462 to own function --- src/openrct2/ride/Vehicle.cpp | 161 ++++++++++++++++++---------------- src/openrct2/ride/Vehicle.h | 5 +- 2 files changed, 88 insertions(+), 78 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 8d375ce238..d9e1fb3bc7 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -7629,7 +7629,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c } } -Vehicle::UpdateMiniGolfFlagsStatus Vehicle::UpdateTrackMotionMiniGolfFlagsStatus(const Ride& curRide) +[[nodiscard]] Vehicle::UpdateMiniGolfSubroutineStatus Vehicle::UpdateTrackMotionMiniGolfFlagsStatus(const Ride& curRide) { if (var_D3 != 0) { @@ -7643,11 +7643,11 @@ Vehicle::UpdateMiniGolfFlagsStatus Vehicle::UpdateTrackMotionMiniGolfFlagsStatus if (remaining_distance < 0x368A) { Loc6DCDE4(curRide); - return Vehicle::UpdateMiniGolfFlagsStatus::stop; + return Vehicle::UpdateMiniGolfSubroutineStatus::stop; } acceleration = AccelerationFromPitch[Pitch]; _vehicleUnkF64E10++; - return Vehicle::UpdateMiniGolfFlagsStatus::restart; + return Vehicle::UpdateMiniGolfSubroutineStatus::restart; } if (mini_golf_flags & MiniGolfFlag::Flag2) @@ -7665,11 +7665,11 @@ Vehicle::UpdateMiniGolfFlagsStatus Vehicle::UpdateTrackMotionMiniGolfFlagsStatus if (remaining_distance < 0x368A) { Loc6DCDE4(curRide); - return Vehicle::UpdateMiniGolfFlagsStatus::stop; + return Vehicle::UpdateMiniGolfSubroutineStatus::stop; } acceleration = AccelerationFromPitch[Pitch]; _vehicleUnkF64E10++; - return Vehicle::UpdateMiniGolfFlagsStatus::restart; + return Vehicle::UpdateMiniGolfSubroutineStatus::restart; } mini_golf_flags &= ~MiniGolfFlag::Flag2; } @@ -7680,7 +7680,7 @@ Vehicle::UpdateMiniGolfFlagsStatus Vehicle::UpdateTrackMotionMiniGolfFlagsStatus Vehicle* vEDI = GetEntity(vehicleIdx); if (vEDI == nullptr) { - return Vehicle::UpdateMiniGolfFlagsStatus::stop; + return Vehicle::UpdateMiniGolfSubroutineStatus::stop; } if (!(vEDI->mini_golf_flags & MiniGolfFlag::Flag0) || (vEDI->mini_golf_flags & MiniGolfFlag::Flag2)) { @@ -7693,11 +7693,11 @@ Vehicle::UpdateMiniGolfFlagsStatus Vehicle::UpdateTrackMotionMiniGolfFlagsStatus if (remaining_distance < 0x368A) { Loc6DCDE4(curRide); - return Vehicle::UpdateMiniGolfFlagsStatus::stop; + return Vehicle::UpdateMiniGolfSubroutineStatus::stop; } acceleration = AccelerationFromPitch[Pitch]; _vehicleUnkF64E10++; - return Vehicle::UpdateMiniGolfFlagsStatus::restart; + return Vehicle::UpdateMiniGolfSubroutineStatus::restart; } if (vEDI->var_D3 != 0) { @@ -7710,11 +7710,11 @@ Vehicle::UpdateMiniGolfFlagsStatus Vehicle::UpdateTrackMotionMiniGolfFlagsStatus if (remaining_distance < 0x368A) { Loc6DCDE4(curRide); - return Vehicle::UpdateMiniGolfFlagsStatus::stop; + return Vehicle::UpdateMiniGolfSubroutineStatus::stop; } acceleration = AccelerationFromPitch[Pitch]; _vehicleUnkF64E10++; - return Vehicle::UpdateMiniGolfFlagsStatus::restart; + return Vehicle::UpdateMiniGolfSubroutineStatus::restart; } vEDI->mini_golf_flags &= ~MiniGolfFlag::Flag0; mini_golf_flags &= ~MiniGolfFlag::Flag0; @@ -7726,7 +7726,7 @@ Vehicle::UpdateMiniGolfFlagsStatus Vehicle::UpdateTrackMotionMiniGolfFlagsStatus Vehicle* vEDI = GetEntity(vehicleIdx); if (vEDI == nullptr) { - return Vehicle::UpdateMiniGolfFlagsStatus::stop; + return Vehicle::UpdateMiniGolfSubroutineStatus::stop; } if (!(vEDI->mini_golf_flags & MiniGolfFlag::Flag1) || (vEDI->mini_golf_flags & MiniGolfFlag::Flag2)) { @@ -7739,11 +7739,11 @@ Vehicle::UpdateMiniGolfFlagsStatus Vehicle::UpdateTrackMotionMiniGolfFlagsStatus if (remaining_distance < 0x368A) { Loc6DCDE4(curRide); - return Vehicle::UpdateMiniGolfFlagsStatus::stop; + return Vehicle::UpdateMiniGolfSubroutineStatus::stop; } acceleration = AccelerationFromPitch[Pitch]; _vehicleUnkF64E10++; - return Vehicle::UpdateMiniGolfFlagsStatus::restart; + return Vehicle::UpdateMiniGolfSubroutineStatus::restart; } if (vEDI->var_D3 != 0) { @@ -7756,11 +7756,11 @@ Vehicle::UpdateMiniGolfFlagsStatus Vehicle::UpdateTrackMotionMiniGolfFlagsStatus if (remaining_distance < 0x368A) { Loc6DCDE4(curRide); - return Vehicle::UpdateMiniGolfFlagsStatus::stop; + return Vehicle::UpdateMiniGolfSubroutineStatus::stop; } acceleration = AccelerationFromPitch[Pitch]; _vehicleUnkF64E10++; - return Vehicle::UpdateMiniGolfFlagsStatus::restart; + return Vehicle::UpdateMiniGolfSubroutineStatus::restart; } vEDI->mini_golf_flags &= ~MiniGolfFlag::Flag1; mini_golf_flags &= ~MiniGolfFlag::Flag1; @@ -7792,85 +7792,54 @@ Vehicle::UpdateMiniGolfFlagsStatus Vehicle::UpdateTrackMotionMiniGolfFlagsStatus if (remaining_distance < 0x368A) { Loc6DCDE4(curRide); - return Vehicle::UpdateMiniGolfFlagsStatus::stop; + return Vehicle::UpdateMiniGolfSubroutineStatus::stop; } acceleration = AccelerationFromPitch[Pitch]; _vehicleUnkF64E10++; - return Vehicle::UpdateMiniGolfFlagsStatus::restart; + return Vehicle::UpdateMiniGolfSubroutineStatus::restart; } mini_golf_flags |= MiniGolfFlag::Flag4; mini_golf_flags &= ~MiniGolfFlag::Flag3; } - return Vehicle::UpdateMiniGolfFlagsStatus::carryOn; + return Vehicle::UpdateMiniGolfSubroutineStatus::carryOn; } -/** - * rct2: 0x006DC3A7 - * - * - */ - -void Vehicle::UpdateTrackMotionMiniGolfVehicle(const Ride& curRide, const RideObjectEntry& rideEntry, const CarEntry* carEntry) +[[nodiscard]] Vehicle::UpdateMiniGolfSubroutineStatus Vehicle::Loc6DC462(const Ride& curRide) { - EntityId otherVehicleIndex = EntityId::GetNull(); - TileElement* tileElement = nullptr; - CoordsXYZ trackPos; - int32_t direction{}; - - _vehicleUnkF64E10 = 1; - acceleration = AccelerationFromPitch[Pitch]; - if (!HasFlag(VehicleFlags::MoveSingleCar)) - { - remaining_distance = _vehicleVelocityF64E0C + remaining_distance; - } - if (remaining_distance >= 0 && remaining_distance < 0x368A) - { - Loc6DCE02(curRide); - return; - } - sound2_flags &= ~VEHICLE_SOUND2_FLAGS_LIFT_HILL; - _vehicleCurPosition.x = x; - _vehicleCurPosition.y = y; - _vehicleCurPosition.z = z; - Invalidate(); - if (remaining_distance < 0) - goto Loc6DCA9A; - -Loc6DC462: while (true) { - Vehicle::UpdateMiniGolfFlagsStatus flagsStatus = Vehicle::UpdateMiniGolfFlagsStatus::restart; - while (flagsStatus == Vehicle::UpdateMiniGolfFlagsStatus::restart) + Vehicle::UpdateMiniGolfSubroutineStatus flagsStatus = Vehicle::UpdateMiniGolfSubroutineStatus::restart; + while (flagsStatus == Vehicle::UpdateMiniGolfSubroutineStatus::restart) { flagsStatus = UpdateTrackMotionMiniGolfFlagsStatus(curRide); } - if (flagsStatus == UpdateMiniGolfFlagsStatus::stop) - return; + if (flagsStatus == UpdateMiniGolfSubroutineStatus::stop) + return UpdateMiniGolfSubroutineStatus::stop; uint16_t trackTotalProgress = GetTrackProgress(); if (track_progress + 1 >= trackTotalProgress) { - tileElement = MapGetTrackElementAtOfTypeSeq(TrackLocation, GetTrackType(), 0); + CoordsXYZ trackPos; + Direction direction; + auto* tileElement = MapGetTrackElementAtOfTypeSeq(TrackLocation, GetTrackType(), 0); + CoordsXYE output; + int32_t outZ{}; + int32_t outDirection{}; + CoordsXYE input = { TrackLocation, tileElement }; + if (!TrackBlockGetNext(&input, &output, &outZ, &outDirection)) { - CoordsXYE output; - int32_t outZ{}; - int32_t outDirection{}; - CoordsXYE input = { TrackLocation, tileElement }; - if (!TrackBlockGetNext(&input, &output, &outZ, &outDirection)) - { - _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; - _vehicleVelocityF64E0C -= remaining_distance + 1; - remaining_distance = -1; - acceleration += AccelerationFromPitch[Pitch]; - _vehicleUnkF64E10++; - break; - } - tileElement = output.element; - trackPos = { output.x, output.y, outZ }; - direction = outDirection; + _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; + _vehicleVelocityF64E0C -= remaining_distance + 1; + remaining_distance = -1; + acceleration += AccelerationFromPitch[Pitch]; + _vehicleUnkF64E10++; + return UpdateMiniGolfSubroutineStatus::carryOn; } + tileElement = output.element; + trackPos = { output.x, output.y, outZ }; + direction = outDirection; if (PitchAndRollStart(false, tileElement) != TrackPitchAndRollEnd(GetTrackType())) { @@ -7883,7 +7852,7 @@ Loc6DC462: } acceleration += AccelerationFromPitch[Pitch]; _vehicleUnkF64E10++; - break; + return UpdateMiniGolfSubroutineStatus::carryOn; } TrackLocation = trackPos; @@ -7898,7 +7867,7 @@ Loc6DC462: if (TrackSubposition != VehicleTrackSubposition::MiniGolfStart9) { TrackSubposition = VehicleTrackSubposition{ static_cast( - static_cast(TrackSubposition) - 1u) }; + static_cast(TrackSubposition) - 1u) }; } } @@ -8012,7 +7981,7 @@ Loc6DC462: } // Loc6DC8A1 - trackPos = { TrackLocation.x + moveInfo->x, TrackLocation.y + moveInfo->y, + CoordsXYZ trackPos = { TrackLocation.x + moveInfo->x, TrackLocation.y + moveInfo->y, TrackLocation.z + moveInfo->z + GetRideTypeDescriptor(curRide.type).Heights.VehicleZOffset }; remaining_distance -= 0x368A; @@ -8030,18 +7999,58 @@ Loc6DC462: { if (_vehicleVelocityF64E08 >= 0) { - otherVehicleIndex = prev_vehicle_on_ride; + auto otherVehicleIndex = prev_vehicle_on_ride; UpdateMotionCollisionDetection(trackPos, &otherVehicleIndex); } } if (remaining_distance < 0x368A) { Loc6DCDE4(curRide); - return; + return UpdateMiniGolfSubroutineStatus::stop; } acceleration = AccelerationFromPitch[Pitch]; _vehicleUnkF64E10++; } +} + +/** + * rct2: 0x006DC3A7 + * + * + */ + +void Vehicle::UpdateTrackMotionMiniGolfVehicle(const Ride& curRide, const RideObjectEntry& rideEntry, const CarEntry* carEntry) +{ + EntityId otherVehicleIndex = EntityId::GetNull(); + TileElement* tileElement = nullptr; + CoordsXYZ trackPos; + int32_t direction{}; + + _vehicleUnkF64E10 = 1; + acceleration = AccelerationFromPitch[Pitch]; + if (!HasFlag(VehicleFlags::MoveSingleCar)) + { + remaining_distance = _vehicleVelocityF64E0C + remaining_distance; + } + if (remaining_distance >= 0 && remaining_distance < 0x368A) + { + Loc6DCE02(curRide); + return; + } + sound2_flags &= ~VEHICLE_SOUND2_FLAGS_LIFT_HILL; + _vehicleCurPosition.x = x; + _vehicleCurPosition.y = y; + _vehicleCurPosition.z = z; + Invalidate(); + if (remaining_distance < 0) + goto Loc6DCA9A; + +Loc6DC462: + { + auto result = Loc6DC462(curRide); + if (result == UpdateMiniGolfSubroutineStatus::stop) + return; + }; Loc6DCA9A: while (true) diff --git a/src/openrct2/ride/Vehicle.h b/src/openrct2/ride/Vehicle.h index c5c03a82ef..a930403956 100644 --- a/src/openrct2/ride/Vehicle.h +++ b/src/openrct2/ride/Vehicle.h @@ -380,13 +380,14 @@ private: void Loc6DCE02(const Ride& curRide); void Loc6DCDE4(const Ride& curRide); - enum class UpdateMiniGolfFlagsStatus + enum class UpdateMiniGolfSubroutineStatus { carryOn, restart, stop, }; - UpdateMiniGolfFlagsStatus UpdateTrackMotionMiniGolfFlagsStatus(const Ride& curRide); + [[nodiscard]] UpdateMiniGolfSubroutineStatus UpdateTrackMotionMiniGolfFlagsStatus(const Ride& curRide); + [[nodiscard]] UpdateMiniGolfSubroutineStatus Loc6DC462(const Ride& curRide); void UpdateTrackMotionPreUpdate( Vehicle& car, const Ride& curRide, const RideObjectEntry& rideEntry, const CarEntry* carEntry); }; From 5769e9237f4039efdf1d5550505de45841c1e11e Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sat, 25 Jan 2025 15:01:32 +0100 Subject: [PATCH 4/4] Move Loc6DCA9A to own function --- src/openrct2/ride/Vehicle.cpp | 125 +++++++++++++++++----------------- src/openrct2/ride/Vehicle.h | 7 ++ 2 files changed, 70 insertions(+), 62 deletions(-) diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index d9e1fb3bc7..723683d27a 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -7867,7 +7867,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c if (TrackSubposition != VehicleTrackSubposition::MiniGolfStart9) { TrackSubposition = VehicleTrackSubposition{ static_cast( - static_cast(TrackSubposition) - 1u) }; + static_cast(TrackSubposition) - 1u) }; } } @@ -7982,7 +7982,7 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c // Loc6DC8A1 CoordsXYZ trackPos = { TrackLocation.x + moveInfo->x, TrackLocation.y + moveInfo->y, - TrackLocation.z + moveInfo->z + GetRideTypeDescriptor(curRide.type).Heights.VehicleZOffset }; + TrackLocation.z + moveInfo->z + GetRideTypeDescriptor(curRide.type).Heights.VehicleZOffset }; remaining_distance -= 0x368A; if (remaining_distance < 0) @@ -8013,66 +8013,26 @@ bool Vehicle::UpdateTrackMotionBackwards(const CarEntry* carEntry, const Ride& c } } -/** - * rct2: 0x006DC3A7 - * - * - */ - -void Vehicle::UpdateTrackMotionMiniGolfVehicle(const Ride& curRide, const RideObjectEntry& rideEntry, const CarEntry* carEntry) +[[nodiscard]] Vehicle::UpdateMiniGolfSubroutineStatus Vehicle::Loc6DCA9A(const Ride& curRide) { - EntityId otherVehicleIndex = EntityId::GetNull(); - TileElement* tileElement = nullptr; - CoordsXYZ trackPos; - int32_t direction{}; - - _vehicleUnkF64E10 = 1; - acceleration = AccelerationFromPitch[Pitch]; - if (!HasFlag(VehicleFlags::MoveSingleCar)) - { - remaining_distance = _vehicleVelocityF64E0C + remaining_distance; - } - if (remaining_distance >= 0 && remaining_distance < 0x368A) - { - Loc6DCE02(curRide); - return; - } - sound2_flags &= ~VEHICLE_SOUND2_FLAGS_LIFT_HILL; - _vehicleCurPosition.x = x; - _vehicleCurPosition.y = y; - _vehicleCurPosition.z = z; - Invalidate(); - if (remaining_distance < 0) - goto Loc6DCA9A; - -Loc6DC462: - { - auto result = Loc6DC462(curRide); - if (result == UpdateMiniGolfSubroutineStatus::stop) - return; - }; - -Loc6DCA9A: while (true) { if (track_progress == 0) { - tileElement = MapGetTrackElementAtOfTypeSeq(TrackLocation, GetTrackType(), 0); + auto tileElement = MapGetTrackElementAtOfTypeSeq(TrackLocation, GetTrackType(), 0); + TrackBeginEnd trackBeginEnd; + if (!TrackBlockGetPrevious({ TrackLocation, tileElement }, &trackBeginEnd)) { - TrackBeginEnd trackBeginEnd; - if (!TrackBlockGetPrevious({ TrackLocation, tileElement }, &trackBeginEnd)) - { - _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; - _vehicleVelocityF64E0C -= remaining_distance + 1; - remaining_distance = -1; - acceleration += AccelerationFromPitch[Pitch]; - _vehicleUnkF64E10++; - continue; - } - trackPos = { trackBeginEnd.begin_x, trackBeginEnd.begin_y, trackBeginEnd.begin_z }; - direction = trackBeginEnd.begin_direction; - tileElement = trackBeginEnd.begin_element; + _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; + _vehicleVelocityF64E0C -= remaining_distance + 1; + remaining_distance = -1; + acceleration += AccelerationFromPitch[Pitch]; + _vehicleUnkF64E10++; + continue; } + CoordsXYZ trackPos = { trackBeginEnd.begin_x, trackBeginEnd.begin_y, trackBeginEnd.begin_z }; + auto direction = trackBeginEnd.begin_direction; + tileElement = trackBeginEnd.begin_element; if (PitchAndRollStart(false, tileElement) != TrackPitchAndRollEnd(GetTrackType())) { @@ -8081,7 +8041,7 @@ Loc6DCA9A: remaining_distance = 0x368A; acceleration = AccelerationFromPitch[Pitch]; _vehicleUnkF64E10++; - goto Loc6DC462; + return Vehicle::UpdateMiniGolfSubroutineStatus::restart; } TrackLocation = trackPos; @@ -8111,8 +8071,8 @@ Loc6DCA9A: } auto moveInfo = GetMoveInfo(); - trackPos = { TrackLocation.x + moveInfo->x, TrackLocation.y + moveInfo->y, - TrackLocation.z + moveInfo->z + GetRideTypeDescriptor(curRide.type).Heights.VehicleZOffset }; + CoordsXYZ trackPos = { TrackLocation.x + moveInfo->x, TrackLocation.y + moveInfo->y, + TrackLocation.z + moveInfo->z + GetRideTypeDescriptor(curRide.type).Heights.VehicleZOffset }; remaining_distance -= 0x368A; if (remaining_distance < 0) @@ -8129,7 +8089,7 @@ Loc6DCA9A: { if (_vehicleVelocityF64E08 >= 0) { - otherVehicleIndex = EntityId::FromUnderlying(var_44); // Possibly wrong?. + auto otherVehicleIndex = EntityId::FromUnderlying(var_44); // Possibly wrong?. if (UpdateMotionCollisionDetection(trackPos, &otherVehicleIndex)) { _vehicleVelocityF64E0C -= remaining_distance - 0x368A; @@ -8138,7 +8098,7 @@ Loc6DCA9A: Vehicle* vEBP = GetEntity(otherVehicleIndex); if (vEBP == nullptr) { - return; + return UpdateMiniGolfSubroutineStatus::stop; } Vehicle* vEDI = gCurrentVehicle; if (abs(vEDI->velocity - vEBP->velocity) > 14.0_mph) @@ -8151,7 +8111,7 @@ Loc6DCA9A: _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_2; acceleration = AccelerationFromPitch[Pitch]; _vehicleUnkF64E10++; - goto Loc6DC462; + return UpdateMiniGolfSubroutineStatus::restart; } } } @@ -8159,13 +8119,54 @@ Loc6DCA9A: if (remaining_distance >= 0) { Loc6DCDE4(curRide); - return; + return UpdateMiniGolfSubroutineStatus::stop; } acceleration += AccelerationFromPitch[Pitch]; _vehicleUnkF64E10++; } } +/** + * rct2: 0x006DC3A7 + * + * + */ + +void Vehicle::UpdateTrackMotionMiniGolfVehicle(const Ride& curRide, const RideObjectEntry& rideEntry, const CarEntry* carEntry) +{ + _vehicleUnkF64E10 = 1; + acceleration = AccelerationFromPitch[Pitch]; + if (!HasFlag(VehicleFlags::MoveSingleCar)) + { + remaining_distance = _vehicleVelocityF64E0C + remaining_distance; + } + if (remaining_distance >= 0 && remaining_distance < 0x368A) + { + Loc6DCE02(curRide); + return; + } + sound2_flags &= ~VEHICLE_SOUND2_FLAGS_LIFT_HILL; + _vehicleCurPosition.x = x; + _vehicleCurPosition.y = y; + _vehicleCurPosition.z = z; + Invalidate(); + bool skipLoc6DC462 = (remaining_distance < 0); + + while (true) + { + if (!skipLoc6DC462) + { + auto result1 = Loc6DC462(curRide); + if (result1 == UpdateMiniGolfSubroutineStatus::stop) + return; + } + skipLoc6DC462 = false; + auto result2 = Loc6DCA9A(curRide); + if (result2 == UpdateMiniGolfSubroutineStatus::stop) + return; + } +} + void Vehicle::Loc6DCDE4(const Ride& curRide) { MoveTo(_vehicleCurPosition); diff --git a/src/openrct2/ride/Vehicle.h b/src/openrct2/ride/Vehicle.h index a930403956..2b3ad2aaf5 100644 --- a/src/openrct2/ride/Vehicle.h +++ b/src/openrct2/ride/Vehicle.h @@ -387,7 +387,14 @@ private: stop, }; [[nodiscard]] UpdateMiniGolfSubroutineStatus UpdateTrackMotionMiniGolfFlagsStatus(const Ride& curRide); + /** + * @return UpdateMiniGolfSubroutineStatus::stop or UpdateMiniGolfSubroutineStatus::carryOn + */ [[nodiscard]] UpdateMiniGolfSubroutineStatus Loc6DC462(const Ride& curRide); + /** + * @return UpdateMiniGolfSubroutineStatus::stop or UpdateMiniGolfSubroutineStatus::restart + */ + [[nodiscard]] UpdateMiniGolfSubroutineStatus Loc6DCA9A(const Ride& curRide); void UpdateTrackMotionPreUpdate( Vehicle& car, const Ride& curRide, const RideObjectEntry& rideEntry, const CarEntry* carEntry); };