1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-23 06:44:38 +01:00

Merge pull request #11956 from hdpoliveira/loc_6DB38B

Simplify code related to V-angle and bank
This commit is contained in:
Tulio Leao
2020-07-03 15:16:08 -03:00
committed by GitHub
5 changed files with 63 additions and 58 deletions

View File

@@ -232,8 +232,6 @@ bool Vehicle::CableLiftUpdateTrackMotionForwards()
uint16_t trackTotalProgress = GetTrackProgress();
if (trackProgress >= trackTotalProgress)
{
_vehicleVAngleEndF64E36 = TrackDefinitions[trackType].vangle_end;
_vehicleBankEndF64E37 = TrackDefinitions[trackType].bank_end;
TileElement* trackElement = map_get_track_element_at_of_type_seq(TrackLocation, trackType, 0);
CoordsXYE output;
@@ -245,8 +243,7 @@ bool Vehicle::CableLiftUpdateTrackMotionForwards()
if (!track_block_get_next(&input, &output, &outputZ, &outputDirection))
return false;
if (TrackDefinitions[output.element->AsTrack()->GetTrackType()].vangle_start != _vehicleVAngleEndF64E36
|| TrackDefinitions[output.element->AsTrack()->GetTrackType()].bank_start != _vehicleBankEndF64E37)
if (TrackPitchAndRollEnd(trackType) != TrackPitchAndRollStart(output.element->AsTrack()->GetTrackType()))
return false;
TrackLocation = { output, outputZ };
@@ -298,9 +295,6 @@ bool Vehicle::CableLiftUpdateTrackMotionBackwards()
if (static_cast<int16_t>(trackProgress) == -1)
{
uint8_t trackType = GetTrackType();
_vehicleVAngleEndF64E36 = TrackDefinitions[trackType].vangle_start;
_vehicleBankEndF64E37 = TrackDefinitions[trackType].bank_start;
TileElement* trackElement = map_get_track_element_at_of_type_seq(TrackLocation, trackType, 0);
auto input = CoordsXYE{ TrackLocation, trackElement };
@@ -309,8 +303,7 @@ bool Vehicle::CableLiftUpdateTrackMotionBackwards()
if (!track_block_get_previous(input, &output))
return false;
if (TrackDefinitions[output.begin_element->AsTrack()->GetTrackType()].vangle_end != _vehicleVAngleEndF64E36
|| TrackDefinitions[output.begin_element->AsTrack()->GetTrackType()].bank_end != _vehicleBankEndF64E37)
if (TrackPitchAndRollStart(trackType) != TrackPitchAndRollEnd(output.begin_element->AsTrack()->GetTrackType()))
return false;
TrackLocation = { output.begin_x, output.begin_y, output.begin_z };

View File

@@ -560,6 +560,16 @@ const rct_trackdefinition FlatRideTrackDefinitions[256] =
};
// clang-format on
PitchAndRoll TrackPitchAndRollStart(uint8_t trackType)
{
return { TrackDefinitions[trackType].vangle_start, TrackDefinitions[trackType].bank_start };
}
PitchAndRoll TrackPitchAndRollEnd(uint8_t trackType)
{
return { TrackDefinitions[trackType].vangle_end, TrackDefinitions[trackType].bank_end };
}
/**
* Helper method to determine if a connects to b by its bank and angle, not location.
*/
@@ -1120,7 +1130,7 @@ bool track_element_is_block_start(TileElement* trackElement)
return false;
}
int32_t track_get_actual_bank(TileElement* tileElement, int32_t bank)
roll_type_t track_get_actual_bank(TileElement* tileElement, roll_type_t bank)
{
auto ride = get_ride(tileElement->AsTrack()->GetRideIndex());
if (ride != nullptr)
@@ -1131,7 +1141,7 @@ int32_t track_get_actual_bank(TileElement* tileElement, int32_t bank)
return bank;
}
int32_t track_get_actual_bank_2(int32_t rideType, bool isInverted, int32_t bank)
roll_type_t track_get_actual_bank_2(int32_t rideType, bool isInverted, roll_type_t bank)
{
if (RideTypeDescriptors[rideType].Flags & RIDE_TYPE_FLAG_HAS_ALTERNATIVE_TRACK_TYPE)
{
@@ -1150,7 +1160,7 @@ int32_t track_get_actual_bank_2(int32_t rideType, bool isInverted, int32_t bank)
return bank;
}
int32_t track_get_actual_bank_3(Vehicle* vehicle, TileElement* tileElement)
roll_type_t track_get_actual_bank_3(bool useInvertedSprites, TileElement* tileElement)
{
auto trackType = tileElement->AsTrack()->GetTrackType();
auto bankStart = TrackDefinitions[trackType].bank_start;
@@ -1158,7 +1168,7 @@ int32_t track_get_actual_bank_3(Vehicle* vehicle, TileElement* tileElement)
if (ride == nullptr)
return bankStart;
bool isInverted = vehicle->HasUpdateFlag(VEHICLE_UPDATE_FLAG_USE_INVERTED_SPRITES) ^ tileElement->AsTrack()->IsInverted();
bool isInverted = useInvertedSprites ^ tileElement->AsTrack()->IsInverted();
return track_get_actual_bank_2(ride->type, isInverted, bankStart);
}

View File

@@ -18,21 +18,37 @@ constexpr const uint16_t RideConstructionSpecialPieceSelected = 0x100;
constexpr const int32_t BLOCK_BRAKE_BASE_SPEED = 0x20364;
using track_type_t = uint16_t;
using roll_type_t = uint8_t;
using pitch_type_t = uint8_t;
#pragma pack(push, 1)
struct rct_trackdefinition
{
uint8_t type;
uint8_t vangle_end;
uint8_t vangle_start;
uint8_t bank_end;
uint8_t bank_start;
pitch_type_t vangle_end;
pitch_type_t vangle_start;
roll_type_t bank_end;
roll_type_t bank_start;
int8_t preview_z_offset;
uint8_t pad[2] = {};
};
assert_struct_size(rct_trackdefinition, 8);
#pragma pack(pop)
struct PitchAndRoll
{
pitch_type_t Pitch;
roll_type_t Roll;
};
constexpr bool operator==(const PitchAndRoll& vb1, const PitchAndRoll& vb2)
{
return vb1.Pitch == vb2.Pitch && vb1.Roll == vb2.Roll;
}
constexpr bool operator!=(const PitchAndRoll& vb1, const PitchAndRoll& vb2)
{
return !(vb1 == vb2);
}
/* size 0x0A */
struct rct_preview_track
{
@@ -538,6 +554,9 @@ struct track_circuit_iterator
extern const rct_trackdefinition FlatRideTrackDefinitions[256];
extern const rct_trackdefinition TrackDefinitions[256];
PitchAndRoll TrackPitchAndRollStart(uint8_t trackType);
PitchAndRoll TrackPitchAndRollEnd(uint8_t trackType);
int32_t track_is_connected_by_shape(TileElement* a, TileElement* b);
const rct_preview_track* get_track_def_from_ride(Ride* ride, int32_t trackType);
@@ -556,9 +575,9 @@ bool track_element_is_block_start(TileElement* trackElement);
bool track_element_is_covered(int32_t trackElementType);
bool track_type_is_station(track_type_t trackType);
int32_t track_get_actual_bank(TileElement* tileElement, int32_t bank);
int32_t track_get_actual_bank_2(int32_t rideType, bool isInverted, int32_t bank);
int32_t track_get_actual_bank_3(Vehicle* vehicle, TileElement* tileElement);
roll_type_t track_get_actual_bank(TileElement* tileElement, roll_type_t bank);
roll_type_t track_get_actual_bank_2(int32_t rideType, bool isInverted, roll_type_t bank);
roll_type_t track_get_actual_bank_3(bool useInvertedSprites, TileElement* tileElement);
bool track_add_station_element(CoordsXYZD loc, ride_id_t rideIndex, int32_t flags, bool fromTrackDesign);
bool track_remove_station_element(int32_t x, int32_t y, int32_t z, Direction direction, ride_id_t rideIndex, int32_t flags);

View File

@@ -65,8 +65,6 @@ uint32_t _vehicleMotionTrackFlags;
int32_t _vehicleVelocityF64E08;
int32_t _vehicleVelocityF64E0C;
int32_t _vehicleUnkF64E10;
uint8_t _vehicleVAngleEndF64E36;
uint8_t _vehicleBankEndF64E37;
uint8_t _vehicleF64E2C;
Vehicle* _vehicleFrontVehicle;
CoordsXYZ unk_F64E20;
@@ -7448,16 +7446,10 @@ void Vehicle::UpdateSceneryDoor() const
*
* rct2: 0x006DB38B
*/
static bool loc_6DB38B(Vehicle* vehicle, TileElement* tileElement)
static PitchAndRoll PitchAndRollStart(bool useInvertedSprites, TileElement* tileElement)
{
// Get bank
int32_t bankStart = track_get_actual_bank_3(vehicle, tileElement);
// Get vangle
int32_t trackType = tileElement->AsTrack()->GetTrackType();
int32_t vangleStart = TrackDefinitions[trackType].vangle_start;
return vangleStart == _vehicleVAngleEndF64E36 && bankStart == _vehicleBankEndF64E37;
auto trackType = tileElement->AsTrack()->GetTrackType();
return PitchAndRoll{ TrackDefinitions[trackType].vangle_start, track_get_actual_bank_3(useInvertedSprites, tileElement) };
}
void Vehicle::UpdateGoKartAttemptSwitchLanes()
@@ -7894,8 +7886,7 @@ bool Vehicle::UpdateTrackMotionForwardsGetNewTrack(uint16_t trackType, Ride* cur
{
CoordsXYZD location = {};
_vehicleVAngleEndF64E36 = TrackDefinitions[trackType].vangle_end;
_vehicleBankEndF64E37 = TrackDefinitions[trackType].bank_end;
auto pitchAndRollEnd = TrackPitchAndRollEnd(trackType);
TileElement* tileElement = map_get_track_element_at_of_type_seq(TrackLocation, trackType, 0);
if (tileElement == nullptr)
@@ -7983,7 +7974,7 @@ bool Vehicle::UpdateTrackMotionForwardsGetNewTrack(uint16_t trackType, Ride* cur
}
}
if (!loc_6DB38B(this, tileElement))
if (PitchAndRollStart(HasUpdateFlag(VEHICLE_UPDATE_FLAG_USE_INVERTED_SPRITES), tileElement) != pitchAndRollEnd)
{
return false;
}
@@ -8308,14 +8299,20 @@ loc_6DB967:
return false;
}
static PitchAndRoll PitchAndRollEnd(Ride* curRide, bool useInvertedSprites, uint16_t trackType, TileElement* tileElement)
{
bool isInverted = useInvertedSprites ^ tileElement->AsTrack()->IsInverted();
return { TrackDefinitions[trackType].vangle_end,
track_get_actual_bank_2(curRide->type, isInverted, TrackDefinitions[trackType].bank_end) };
}
/**
*
* rct2: 0x006DBAA6
*/
bool Vehicle::UpdateTrackMotionBackwardsGetNewTrack(uint16_t trackType, Ride* curRide, uint16_t* progress)
{
_vehicleVAngleEndF64E36 = TrackDefinitions[trackType].vangle_start;
_vehicleBankEndF64E37 = TrackDefinitions[trackType].bank_start;
auto pitchAndRollStart = TrackPitchAndRollStart(trackType);
TileElement* tileElement = map_get_track_element_at_of_type_seq(TrackLocation, trackType, 0);
if (tileElement == nullptr)
@@ -8360,11 +8357,8 @@ bool Vehicle::UpdateTrackMotionBackwardsGetNewTrack(uint16_t trackType, Ride* cu
return false;
}
bool isInverted = HasUpdateFlag(VEHICLE_UPDATE_FLAG_USE_INVERTED_SPRITES) ^ tileElement->AsTrack()->IsInverted();
int32_t bank = TrackDefinitions[trackType].bank_end;
bank = track_get_actual_bank_2(curRide->type, isInverted, bank);
int32_t vAngle = TrackDefinitions[trackType].vangle_end;
if (_vehicleVAngleEndF64E36 != vAngle || _vehicleBankEndF64E37 != bank)
if (PitchAndRollEnd(curRide, HasUpdateFlag(VEHICLE_UPDATE_FLAG_USE_INVERTED_SPRITES), trackType, tileElement)
!= pitchAndRollStart)
{
return false;
}
@@ -8730,12 +8724,7 @@ loc_6DC476:
}
}
{
uint16_t trackType = GetTrackType();
_vehicleVAngleEndF64E36 = TrackDefinitions[trackType].vangle_end;
_vehicleBankEndF64E37 = TrackDefinitions[trackType].bank_end;
tileElement = map_get_track_element_at_of_type_seq(TrackLocation, trackType, 0);
}
tileElement = map_get_track_element_at_of_type_seq(TrackLocation, GetTrackType(), 0);
int32_t direction;
{
CoordsXYE output;
@@ -8750,7 +8739,8 @@ loc_6DC476:
direction = outDirection;
}
if (!loc_6DB38B(this, tileElement))
if (PitchAndRollStart(HasUpdateFlag(VEHICLE_UPDATE_FLAG_USE_INVERTED_SPRITES), tileElement)
!= TrackPitchAndRollEnd(GetTrackType()))
{
goto loc_6DC9BC;
}
@@ -8944,13 +8934,7 @@ loc_6DCA9A:
goto loc_6DCC2C;
}
{
uint16_t trackType = GetTrackType();
_vehicleVAngleEndF64E36 = TrackDefinitions[trackType].vangle_end;
_vehicleBankEndF64E37 = TrackDefinitions[trackType].bank_end;
tileElement = map_get_track_element_at_of_type_seq(TrackLocation, trackType, 0);
}
tileElement = map_get_track_element_at_of_type_seq(TrackLocation, GetTrackType(), 0);
{
track_begin_end trackBeginEnd;
if (!track_block_get_previous({ TrackLocation, tileElement }, &trackBeginEnd))
@@ -8962,7 +8946,8 @@ loc_6DCA9A:
tileElement = trackBeginEnd.begin_element;
}
if (!loc_6DB38B(this, tileElement))
if (PitchAndRollStart(HasUpdateFlag(VEHICLE_UPDATE_FLAG_USE_INVERTED_SPRITES), tileElement)
!= TrackPitchAndRollEnd(GetTrackType()))
{
goto loc_6DCD4A;
}

View File

@@ -629,8 +629,6 @@ extern uint32_t _vehicleMotionTrackFlags;
extern int32_t _vehicleVelocityF64E08;
extern int32_t _vehicleVelocityF64E0C;
extern int32_t _vehicleUnkF64E10;
extern uint8_t _vehicleVAngleEndF64E36;
extern uint8_t _vehicleBankEndF64E37;
extern uint8_t _vehicleF64E2C;
extern Vehicle* _vehicleFrontVehicle;
extern CoordsXYZ unk_F64E20;