Remove regs use from minigolf vehicle functions (#11937)

* Remove regs use from UpdateTrackMotionMiniGolf

* Remove regs from UpdateTrackMotionMiniGolfVehicle
This commit is contained in:
hdpoliveira 2020-06-13 03:56:35 -03:00 committed by GitHub
parent a8d21610fb
commit 2dc98e6370
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 71 additions and 130 deletions

View File

@ -8697,14 +8697,12 @@ loc_6DBE7F:
* *
* *
*/ */
void Vehicle::UpdateTrackMotionMiniGolfVehicle( void Vehicle::UpdateTrackMotionMiniGolfVehicle(Ride* curRide, rct_ride_entry* rideEntry, rct_ride_entry_vehicle* vehicleEntry)
Ride* curRide, rct_ride_entry* rideEntry, rct_ride_entry_vehicle* vehicleEntry, registers& regs)
{ {
uint16_t otherVehicleIndex = SPRITE_INDEX_NULL; uint16_t otherVehicleIndex = SPRITE_INDEX_NULL;
TileElement* tileElement = nullptr; TileElement* tileElement = nullptr;
CoordsXYZ trackPos; CoordsXYZ trackPos;
regs.ebx = vehicle_sprite_type;
_vehicleUnkF64E10 = 1; _vehicleUnkF64E10 = 1;
acceleration = dword_9A2970[vehicle_sprite_type]; acceleration = dword_9A2970[vehicle_sprite_type];
remaining_distance = _vehicleVelocityF64E0C + remaining_distance; remaining_distance = _vehicleVelocityF64E0C + remaining_distance;
@ -8804,11 +8802,10 @@ loc_6DC476:
// There are two bytes before the move info list // There are two bytes before the move info list
{ {
uint16_t unk16_v34 = track_progress + 1; uint16_t trackTotalProgress = vehicle_get_move_info_size(TrackSubposition, track_type);
uint16_t unk16 = vehicle_get_move_info_size(TrackSubposition, track_type); if (track_progress + 1 < trackTotalProgress)
if (unk16_v34 < unk16)
{ {
regs.ax = unk16_v34; track_progress += 1;
goto loc_6DC743; goto loc_6DC743;
} }
} }
@ -8855,21 +8852,19 @@ loc_6DC476:
if (!IsHead()) if (!IsHead())
{ {
Vehicle* prevVehicle = GET_VEHICLE(prev_vehicle_on_ride); Vehicle* prevVehicle = GET_VEHICLE(prev_vehicle_on_ride);
regs.al = prevVehicle->TrackSubposition; TrackSubposition = prevVehicle->TrackSubposition;
if (regs.al != VEHICLE_TRACK_SUBPOSITION_MINI_GOLF_START_9) if (TrackSubposition != VEHICLE_TRACK_SUBPOSITION_MINI_GOLF_START_9)
{ {
regs.al--; TrackSubposition--;
} }
TrackSubposition = regs.al;
} }
ClearUpdateFlag(VEHICLE_UPDATE_FLAG_ON_LIFT_HILL); ClearUpdateFlag(VEHICLE_UPDATE_FLAG_ON_LIFT_HILL);
track_type = (tileElement->AsTrack()->GetTrackType() << 2) | (direction & 3); track_type = (tileElement->AsTrack()->GetTrackType() << 2) | (direction & 3);
var_CF = tileElement->AsTrack()->GetBrakeBoosterSpeed(); var_CF = tileElement->AsTrack()->GetBrakeBoosterSpeed();
regs.ax = 0; track_progress = 0;
loc_6DC743: loc_6DC743:
track_progress = regs.ax;
if (!IsHead()) if (!IsHead())
{ {
animation_frame++; animation_frame++;
@ -8896,16 +8891,16 @@ loc_6DC743:
else else
{ {
uint16_t rand16 = scenario_rand() & 0xFFFF; uint16_t rand16 = scenario_rand() & 0xFFFF;
regs.bl = VEHICLE_TRACK_SUBPOSITION_MINI_GOLF_BALL_PATH_C_14; uint8_t nextTrackSubposition = VEHICLE_TRACK_SUBPOSITION_MINI_GOLF_BALL_PATH_C_14;
if (rand16 <= 0xA000) if (rand16 <= 0xA000)
{ {
regs.bl = VEHICLE_TRACK_SUBPOSITION_MINI_GOLF_BALL_PATH_B_12; nextTrackSubposition = VEHICLE_TRACK_SUBPOSITION_MINI_GOLF_BALL_PATH_B_12;
if (rand16 <= 0x900) if (rand16 <= 0x900)
{ {
regs.bl = VEHICLE_TRACK_SUBPOSITION_MINI_GOLF_BALL_PATH_A_10; nextTrackSubposition = VEHICLE_TRACK_SUBPOSITION_MINI_GOLF_BALL_PATH_A_10;
} }
} }
TrackSubposition = regs.bl; TrackSubposition = nextTrackSubposition;
} }
track_progress++; track_progress++;
break; break;
@ -8969,22 +8964,7 @@ loc_6DC743:
trackPos = { TrackLocation.x + moveInfo->x, TrackLocation.y + moveInfo->y, trackPos = { TrackLocation.x + moveInfo->x, TrackLocation.y + moveInfo->y,
TrackLocation.z + moveInfo->z + RideData5[curRide->type].z_offset }; TrackLocation.z + moveInfo->z + RideData5[curRide->type].z_offset };
// Investigate redundant code remaining_distance -= 0x368A;
regs.ebx = 0;
if (regs.ax != unk_F64E20.x)
{
regs.ebx |= 1;
}
if (regs.cx == unk_F64E20.y)
{
regs.ebx |= 2;
}
if (regs.dx == unk_F64E20.z)
{
regs.ebx |= 4;
}
regs.ebx = 0x368A;
remaining_distance -= regs.ebx;
if (remaining_distance < 0) if (remaining_distance < 0)
{ {
remaining_distance = 0; remaining_distance = 0;
@ -9016,7 +8996,6 @@ loc_6DC743:
goto loc_6DC99A; goto loc_6DC99A;
loc_6DC985: loc_6DC985:
regs.ebx = 0;
remaining_distance -= 0x368A; remaining_distance -= 0x368A;
if (remaining_distance < 0) if (remaining_distance < 0)
{ {
@ -9039,9 +9018,9 @@ loc_6DC9BC:
goto loc_6DCD2B; goto loc_6DCD2B;
loc_6DCA9A: loc_6DCA9A:
regs.ax = track_progress - 1; if (track_progress != 0)
if (static_cast<uint16_t>(regs.ax) != 0xFFFF)
{ {
track_progress -= 1;
goto loc_6DCC2C; goto loc_6DCC2C;
} }
@ -9098,31 +9077,14 @@ loc_6DCA9A:
var_CF = tileElement->AsTrack()->GetSeatRotation() << 1; var_CF = tileElement->AsTrack()->GetSeatRotation() << 1;
// There are two bytes before the move info list // There are two bytes before the move info list
regs.ax = vehicle_get_move_info_size(TrackSubposition, track_type); track_progress = vehicle_get_move_info_size(TrackSubposition, track_type);
loc_6DCC2C: loc_6DCC2C:
track_progress = regs.ax;
moveInfo = vehicle_get_move_info(TrackSubposition, track_type, track_progress); moveInfo = vehicle_get_move_info(TrackSubposition, track_type, track_progress);
trackPos = { TrackLocation.x + moveInfo->x, TrackLocation.y + moveInfo->y, trackPos = { TrackLocation.x + moveInfo->x, TrackLocation.y + moveInfo->y,
TrackLocation.z + moveInfo->z + RideData5[curRide->type].z_offset }; TrackLocation.z + moveInfo->z + RideData5[curRide->type].z_offset };
// Investigate redundant code remaining_distance -= 0x368A;
regs.ebx = 0;
if (regs.ax != unk_F64E20.x)
{
regs.ebx |= 1;
}
if (regs.cx == unk_F64E20.y)
{
regs.ebx |= 2;
}
if (regs.dx == unk_F64E20.z)
{
regs.ebx |= 4;
}
regs.ebx = 0x368A;
remaining_distance -= regs.ebx;
if (remaining_distance < 0) if (remaining_distance < 0)
{ {
remaining_distance = 0; remaining_distance = 0;
@ -9168,7 +9130,6 @@ loc_6DCD4A:
_vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5; _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_5;
_vehicleVelocityF64E0C -= remaining_distance - 0x368A; _vehicleVelocityF64E0C -= remaining_distance - 0x368A;
remaining_distance = 0x368A; remaining_distance = 0x368A;
regs.ebx = vehicle_sprite_type;
goto loc_6DC99A; goto loc_6DC99A;
loc_6DCD6B: loc_6DCD6B:
@ -9177,8 +9138,7 @@ loc_6DCD6B:
{ {
Vehicle* vEBP = GET_VEHICLE(otherVehicleIndex); Vehicle* vEBP = GET_VEHICLE(otherVehicleIndex);
Vehicle* vEDI = gCurrentVehicle; Vehicle* vEDI = gCurrentVehicle;
regs.eax = abs(vEDI->velocity - vEBP->velocity); if (abs(vEDI->velocity - vEBP->velocity) > 0xE0000)
if (regs.eax > 0xE0000)
{ {
if (!(vehicleEntry->flags & VEHICLE_ENTRY_FLAG_BOAT_HIRE_COLLISION_DETECTION)) if (!(vehicleEntry->flags & VEHICLE_ENTRY_FLAG_BOAT_HIRE_COLLISION_DETECTION))
{ {
@ -9217,7 +9177,6 @@ loc_6DCE02:
{ {
return; return;
} }
regs.ax = track_progress;
if (_vehicleVelocityF64E08 < 0) if (_vehicleVelocityF64E08 < 0)
{ {
if (track_progress > 11) if (track_progress > 11)
@ -9225,7 +9184,6 @@ loc_6DCE02:
return; return;
} }
} }
regs.cx = 8;
if (track_progress <= 8) if (track_progress <= 8)
{ {
return; return;
@ -9249,7 +9207,6 @@ loc_6DCE02:
int32_t Vehicle::UpdateTrackMotionMiniGolf(int32_t* outStation) int32_t Vehicle::UpdateTrackMotionMiniGolf(int32_t* outStation)
{ {
registers regs = {};
auto curRide = get_ride(ride); auto curRide = get_ride(ride);
if (curRide == nullptr) if (curRide == nullptr)
return 0; return 0;
@ -9266,7 +9223,7 @@ int32_t Vehicle::UpdateTrackMotionMiniGolf(int32_t* outStation)
for (Vehicle* vehicle = _vehicleFrontVehicle;;) for (Vehicle* vehicle = _vehicleFrontVehicle;;)
{ {
vehicle->UpdateTrackMotionMiniGolfVehicle(curRide, rideEntry, vehicleEntry, regs); vehicle->UpdateTrackMotionMiniGolfVehicle(curRide, rideEntry, vehicleEntry);
if (vehicle->UpdateFlag(VEHICLE_UPDATE_FLAG_ON_LIFT_HILL)) if (vehicle->UpdateFlag(VEHICLE_UPDATE_FLAG_ON_LIFT_HILL))
{ {
_vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_ON_LIFT_HILL; _vehicleMotionTrackFlags |= VEHICLE_UPDATE_MOTION_TRACK_FLAG_VEHICLE_ON_LIFT_HILL;
@ -9289,17 +9246,15 @@ int32_t Vehicle::UpdateTrackMotionMiniGolf(int32_t* outStation)
} }
} }
regs.eax = 0; int32_t sumAcceleration = 0;
regs.dx = 0; int32_t numVehicles = 0;
regs.ebx = 0;
uint16_t totalMass = 0; uint16_t totalMass = 0;
for (Vehicle* vehicle = this;;) for (Vehicle* vehicle = this;;)
{ {
regs.ebx++; numVehicles++;
regs.dx |= vehicle->update_flags;
totalMass += vehicle->mass; totalMass += vehicle->mass;
regs.eax += vehicle->acceleration; sumAcceleration += vehicle->acceleration;
auto nextVehicleIndex = vehicle->next_vehicle_on_train; auto nextVehicleIndex = vehicle->next_vehicle_on_train;
if (nextVehicleIndex == SPRITE_INDEX_NULL) if (nextVehicleIndex == SPRITE_INDEX_NULL)
{ {
@ -9308,20 +9263,16 @@ int32_t Vehicle::UpdateTrackMotionMiniGolf(int32_t* outStation)
vehicle = GET_VEHICLE(nextVehicleIndex); vehicle = GET_VEHICLE(nextVehicleIndex);
} }
regs.eax /= regs.ebx; int32_t newAcceleration = ((sumAcceleration / numVehicles) * 21) >> 9;
regs.ecx = (regs.eax * 21) >> 9; newAcceleration -= velocity >> 12;
regs.eax = velocity >> 12; int32_t accelerationDecrease2 = velocity >> 8;
regs.ecx -= regs.eax; accelerationDecrease2 *= accelerationDecrease2;
regs.ebx = velocity; if (velocity < 0)
regs.edx = velocity >> 8;
regs.edx *= regs.edx;
if (regs.ebx < 0)
{ {
regs.edx = -regs.edx; accelerationDecrease2 = -accelerationDecrease2;
} }
regs.edx >>= 4; accelerationDecrease2 >>= 4;
regs.eax = regs.edx / totalMass; newAcceleration -= accelerationDecrease2 / totalMass;
regs.ecx -= regs.eax;
if (!(vehicleEntry->flags & VEHICLE_ENTRY_FLAG_POWERED)) if (!(vehicleEntry->flags & VEHICLE_ENTRY_FLAG_POWERED))
{ {
@ -9329,73 +9280,64 @@ int32_t Vehicle::UpdateTrackMotionMiniGolf(int32_t* outStation)
} }
if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_POWERED_RIDE_UNRESTRICTED_GRAVITY) if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_POWERED_RIDE_UNRESTRICTED_GRAVITY)
{ {
regs.eax = speed * 0x4000; if (speed * 0x4000 < velocity)
if (regs.eax < velocity)
{ {
goto loc_6DD069; goto loc_6DD069;
} }
} }
regs.eax = speed;
regs.bx = GetTrackType();
regs.ebx = regs.eax;
regs.eax <<= 14;
regs.ebx *= totalMass;
regs.ebx >>= 2;
if (UpdateFlag(VEHICLE_UPDATE_FLAG_REVERSING_SHUTTLE))
{ {
regs.eax = -regs.eax; int32_t poweredAcceleration = speed << 14;
} int32_t quarterForce = (speed * totalMass) >> 2;
regs.eax -= velocity; if (UpdateFlag(VEHICLE_UPDATE_FLAG_REVERSING_SHUTTLE))
regs.edx = powered_acceleration; {
regs.edx <<= 1; poweredAcceleration = -poweredAcceleration;
regs.eax *= regs.edx; }
regs.eax = regs.eax / regs.ebx; poweredAcceleration -= velocity;
poweredAcceleration *= powered_acceleration << 1;
poweredAcceleration = poweredAcceleration / quarterForce;
if (!(vehicleEntry->flags & VEHICLE_ENTRY_FLAG_WATER_RIDE)) if (!(vehicleEntry->flags & VEHICLE_ENTRY_FLAG_WATER_RIDE))
{ {
goto loc_6DD054; goto loc_6DD054;
} }
if (regs.eax < 0) if (poweredAcceleration < 0)
{ {
regs.eax >>= 4; poweredAcceleration >>= 4;
} }
if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_SPINNING)
{
spin_speed = std::clamp(spin_speed, VEHICLE_MIN_SPIN_SPEED_WATER_RIDE, VEHICLE_MAX_SPIN_SPEED_WATER_RIDE);
}
if (vehicle_sprite_type != 0)
{
regs.eax = std::max(0, regs.eax);
if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_SPINNING) if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_SPINNING)
{ {
if (vehicle_sprite_type == 2) spin_speed = std::clamp(spin_speed, VEHICLE_MIN_SPIN_SPEED_WATER_RIDE, VEHICLE_MAX_SPIN_SPEED_WATER_RIDE);
}
if (vehicle_sprite_type != 0)
{
poweredAcceleration = std::max(0, poweredAcceleration);
if (vehicleEntry->flags & VEHICLE_ENTRY_FLAG_SPINNING)
{ {
spin_speed = 0; if (vehicle_sprite_type == 2)
{
spin_speed = 0;
}
} }
} }
} else
else
{
loc_6DD054:
regs.ebx = abs(velocity);
if (regs.ebx > 0x10000)
{ {
regs.ecx = 0; loc_6DD054:
if (abs(velocity) > 0x10000)
{
newAcceleration = 0;
}
} }
newAcceleration += poweredAcceleration;
} }
regs.ecx += regs.eax;
loc_6DD069: loc_6DD069:
acceleration = regs.ecx; acceleration = newAcceleration;
regs.eax = _vehicleMotionTrackFlags;
regs.ebx = _vehicleStationIndex;
if (outStation != nullptr) if (outStation != nullptr)
*outStation = regs.ebx; *outStation = _vehicleStationIndex;
return regs.eax; return _vehicleMotionTrackFlags;
} }
/** /**

View File

@ -420,8 +420,7 @@ private:
void KillPassengers(Ride* curRide); void KillPassengers(Ride* curRide);
void TrainReadyToDepart(uint8_t num_peeps_on_train, uint8_t num_used_seats); void TrainReadyToDepart(uint8_t num_peeps_on_train, uint8_t num_used_seats);
int32_t UpdateTrackMotionMiniGolf(int32_t* outStation); int32_t UpdateTrackMotionMiniGolf(int32_t* outStation);
void UpdateTrackMotionMiniGolfVehicle( void UpdateTrackMotionMiniGolfVehicle(Ride* curRide, rct_ride_entry* rideEntry, rct_ride_entry_vehicle* vehicleEntry);
Ride* curRide, rct_ride_entry* rideEntry, rct_ride_entry_vehicle* vehicleEntry, registers& regs);
bool UpdateTrackMotionForwardsGetNewTrack(uint16_t trackType, Ride* curRide, rct_ride_entry* rideEntry); bool UpdateTrackMotionForwardsGetNewTrack(uint16_t trackType, Ride* curRide, rct_ride_entry* rideEntry);
bool UpdateTrackMotionBackwardsGetNewTrack(uint16_t trackType, Ride* curRide, uint16_t* progress); bool UpdateTrackMotionBackwardsGetNewTrack(uint16_t trackType, Ride* curRide, uint16_t* progress);
}; };