Create struct VAngleAndBank and simplify code

This commit is contained in:
hdpoliveira 2020-06-14 20:45:42 -03:00
parent d3d853b7d6
commit affa0dd30b
3 changed files with 58 additions and 36 deletions

View File

@ -233,8 +233,7 @@ bool Vehicle::CableLiftUpdateTrackMotionForwards()
uint16_t trackTotalProgress = vehicle_get_move_info_size(TrackSubposition, track_type); uint16_t trackTotalProgress = vehicle_get_move_info_size(TrackSubposition, track_type);
if (trackProgress >= trackTotalProgress) if (trackProgress >= trackTotalProgress)
{ {
_vehicleVAngleEndF64E36 = TrackDefinitions[trackType].vangle_end; _vehicleVAngleAndBank = VAngleAndBankEnd(trackType);
_vehicleBankEndF64E37 = TrackDefinitions[trackType].bank_end;
TileElement* trackElement = map_get_track_element_at_of_type_seq(TrackLocation, trackType, 0); TileElement* trackElement = map_get_track_element_at_of_type_seq(TrackLocation, trackType, 0);
CoordsXYE output; CoordsXYE output;
@ -246,8 +245,7 @@ bool Vehicle::CableLiftUpdateTrackMotionForwards()
if (!track_block_get_next(&input, &output, &outputZ, &outputDirection)) if (!track_block_get_next(&input, &output, &outputZ, &outputDirection))
return false; return false;
if (TrackDefinitions[output.element->AsTrack()->GetTrackType()].vangle_start != _vehicleVAngleEndF64E36 if (_vehicleVAngleAndBank != VAngleAndBankStart(output.element->AsTrack()->GetTrackType()))
|| TrackDefinitions[output.element->AsTrack()->GetTrackType()].bank_start != _vehicleBankEndF64E37)
return false; return false;
TrackLocation = { output, outputZ }; TrackLocation = { output, outputZ };
@ -300,8 +298,7 @@ bool Vehicle::CableLiftUpdateTrackMotionBackwards()
if (static_cast<int16_t>(trackProgress) == -1) if (static_cast<int16_t>(trackProgress) == -1)
{ {
uint8_t trackType = GetTrackType(); uint8_t trackType = GetTrackType();
_vehicleVAngleEndF64E36 = TrackDefinitions[trackType].vangle_start; _vehicleVAngleAndBank = VAngleAndBankStart(trackType);
_vehicleBankEndF64E37 = TrackDefinitions[trackType].bank_start;
TileElement* trackElement = map_get_track_element_at_of_type_seq(TrackLocation, trackType, 0); TileElement* trackElement = map_get_track_element_at_of_type_seq(TrackLocation, trackType, 0);
@ -311,8 +308,7 @@ bool Vehicle::CableLiftUpdateTrackMotionBackwards()
if (!track_block_get_previous(input, &output)) if (!track_block_get_previous(input, &output))
return false; return false;
if (TrackDefinitions[output.begin_element->AsTrack()->GetTrackType()].vangle_end != _vehicleVAngleEndF64E36 if (_vehicleVAngleAndBank != VAngleAndBankEnd(output.begin_element->AsTrack()->GetTrackType()))
|| TrackDefinitions[output.begin_element->AsTrack()->GetTrackType()].bank_end != _vehicleBankEndF64E37)
return false; return false;
TrackLocation = { output.begin_x, output.begin_y, output.begin_z }; TrackLocation = { output.begin_x, output.begin_y, output.begin_z };

View File

@ -65,8 +65,7 @@ uint32_t _vehicleMotionTrackFlags;
int32_t _vehicleVelocityF64E08; int32_t _vehicleVelocityF64E08;
int32_t _vehicleVelocityF64E0C; int32_t _vehicleVelocityF64E0C;
int32_t _vehicleUnkF64E10; int32_t _vehicleUnkF64E10;
uint8_t _vehicleVAngleEndF64E36; VAngleAndBank _vehicleVAngleAndBank;
uint8_t _vehicleBankEndF64E37;
uint8_t _vehicleF64E2C; uint8_t _vehicleF64E2C;
Vehicle* _vehicleFrontVehicle; Vehicle* _vehicleFrontVehicle;
CoordsXYZ unk_F64E20; CoordsXYZ unk_F64E20;
@ -7481,16 +7480,10 @@ static void vehicle_update_scenery_door(Vehicle* vehicle)
* *
* rct2: 0x006DB38B * rct2: 0x006DB38B
*/ */
static bool loc_6DB38B(bool useInvertedSprites, TileElement* tileElement) static VAngleAndBank VehicleVAngleAndBankStart(bool useInvertedSprites, TileElement* tileElement)
{ {
// Get bank
int32_t bankStart = track_get_actual_bank_3(useInvertedSprites, tileElement);
// Get vangle
int32_t trackType = tileElement->AsTrack()->GetTrackType(); int32_t trackType = tileElement->AsTrack()->GetTrackType();
int32_t vangleStart = TrackDefinitions[trackType].vangle_start; return VAngleAndBank{ TrackDefinitions[trackType].vangle_start, track_get_actual_bank_3(useInvertedSprites, tileElement) };
return vangleStart == _vehicleVAngleEndF64E36 && bankStart == _vehicleBankEndF64E37;
} }
static void VehicleUpdateGoKartAttemptSwitchLanes(Vehicle* vehicle) static void VehicleUpdateGoKartAttemptSwitchLanes(Vehicle* vehicle)
@ -7937,6 +7930,17 @@ static void sub_6DBF3E(Vehicle* vehicle)
} }
} }
// TODO move these to Track.cpp
VAngleAndBank VAngleAndBankStart(uint8_t trackType)
{
return { TrackDefinitions[trackType].vangle_start, TrackDefinitions[trackType].bank_start };
}
VAngleAndBank VAngleAndBankEnd(uint8_t trackType)
{
return { TrackDefinitions[trackType].vangle_end, TrackDefinitions[trackType].bank_end };
}
/** /**
* *
* rct2: 0x006DB08C * rct2: 0x006DB08C
@ -7945,8 +7949,7 @@ bool Vehicle::UpdateTrackMotionForwardsGetNewTrack(uint16_t trackType, Ride* cur
{ {
CoordsXYZD location = {}; CoordsXYZD location = {};
_vehicleVAngleEndF64E36 = TrackDefinitions[trackType].vangle_end; _vehicleVAngleAndBank = VAngleAndBankEnd(trackType);
_vehicleBankEndF64E37 = TrackDefinitions[trackType].bank_end;
TileElement* tileElement = map_get_track_element_at_of_type_seq(TrackLocation, trackType, 0); TileElement* tileElement = map_get_track_element_at_of_type_seq(TrackLocation, trackType, 0);
if (tileElement == nullptr) if (tileElement == nullptr)
@ -8034,7 +8037,8 @@ bool Vehicle::UpdateTrackMotionForwardsGetNewTrack(uint16_t trackType, Ride* cur
} }
} }
if (!loc_6DB38B(HasUpdateFlag(VEHICLE_UPDATE_FLAG_USE_INVERTED_SPRITES), tileElement)) if (VehicleVAngleAndBankStart(HasUpdateFlag(VEHICLE_UPDATE_FLAG_USE_INVERTED_SPRITES), tileElement)
!= _vehicleVAngleAndBank)
{ {
return false; return false;
} }
@ -8367,14 +8371,21 @@ loc_6DB967:
return false; return false;
} }
static VAngleAndBank VehicleVAngleAndBankEnd(
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 * rct2: 0x006DBAA6
*/ */
bool Vehicle::UpdateTrackMotionBackwardsGetNewTrack(uint16_t trackType, Ride* curRide, uint16_t* progress) bool Vehicle::UpdateTrackMotionBackwardsGetNewTrack(uint16_t trackType, Ride* curRide, uint16_t* progress)
{ {
_vehicleVAngleEndF64E36 = TrackDefinitions[trackType].vangle_start; _vehicleVAngleAndBank = VAngleAndBankStart(trackType);
_vehicleBankEndF64E37 = TrackDefinitions[trackType].bank_start;
TileElement* tileElement = map_get_track_element_at_of_type_seq(TrackLocation, trackType, 0); TileElement* tileElement = map_get_track_element_at_of_type_seq(TrackLocation, trackType, 0);
if (tileElement == nullptr) if (tileElement == nullptr)
@ -8419,11 +8430,8 @@ bool Vehicle::UpdateTrackMotionBackwardsGetNewTrack(uint16_t trackType, Ride* cu
return false; return false;
} }
bool isInverted = HasUpdateFlag(VEHICLE_UPDATE_FLAG_USE_INVERTED_SPRITES) ^ tileElement->AsTrack()->IsInverted(); if (VehicleVAngleAndBankEnd(curRide, HasUpdateFlag(VEHICLE_UPDATE_FLAG_USE_INVERTED_SPRITES), trackType, tileElement)
int32_t bank = TrackDefinitions[trackType].bank_end; != _vehicleVAngleAndBank)
bank = track_get_actual_bank_2(curRide->type, isInverted, bank);
int32_t vAngle = TrackDefinitions[trackType].vangle_end;
if (_vehicleVAngleEndF64E36 != vAngle || _vehicleBankEndF64E37 != bank)
{ {
return false; return false;
} }
@ -8797,8 +8805,7 @@ loc_6DC476:
{ {
uint16_t trackType = GetTrackType(); uint16_t trackType = GetTrackType();
_vehicleVAngleEndF64E36 = TrackDefinitions[trackType].vangle_end; _vehicleVAngleAndBank = VAngleAndBankEnd(trackType);
_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, trackType, 0);
} }
int32_t direction; int32_t direction;
@ -8815,7 +8822,8 @@ loc_6DC476:
direction = outDirection; direction = outDirection;
} }
if (!loc_6DB38B(HasUpdateFlag(VEHICLE_UPDATE_FLAG_USE_INVERTED_SPRITES), tileElement)) if (VehicleVAngleAndBankStart(HasUpdateFlag(VEHICLE_UPDATE_FLAG_USE_INVERTED_SPRITES), tileElement)
!= _vehicleVAngleAndBank)
{ {
goto loc_6DC9BC; goto loc_6DC9BC;
} }
@ -9011,8 +9019,7 @@ loc_6DCA9A:
{ {
uint16_t trackType = GetTrackType(); uint16_t trackType = GetTrackType();
_vehicleVAngleEndF64E36 = TrackDefinitions[trackType].vangle_end; _vehicleVAngleAndBank = VAngleAndBankEnd(trackType);
_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, trackType, 0);
} }
@ -9027,7 +9034,8 @@ loc_6DCA9A:
tileElement = trackBeginEnd.begin_element; tileElement = trackBeginEnd.begin_element;
} }
if (!loc_6DB38B(HasUpdateFlag(VEHICLE_UPDATE_FLAG_USE_INVERTED_SPRITES), tileElement)) if (VehicleVAngleAndBankStart(HasUpdateFlag(VEHICLE_UPDATE_FLAG_USE_INVERTED_SPRITES), tileElement)
!= _vehicleVAngleAndBank)
{ {
goto loc_6DCD4A; goto loc_6DCD4A;
} }

View File

@ -608,6 +608,21 @@ enum
SOUND_RANGE_NONE = 255 SOUND_RANGE_NONE = 255
}; };
// TODO move these to Track.h
struct VAngleAndBank
{
uint8_t VAngle;
uint8_t Bank;
};
bool operator==(const VAngleAndBank& vb1, const VAngleAndBank& vb2)
{
return vb1.VAngle == vb2.VAngle && vb1.Bank == vb2.Bank;
}
bool operator!=(const VAngleAndBank& vb1, const VAngleAndBank& vb2)
{
return !(vb1 == vb2);
}
#define VEHICLE_SEAT_PAIR_FLAG 0x80 #define VEHICLE_SEAT_PAIR_FLAG 0x80
#define VEHICLE_SEAT_NUM_MASK 0x7F #define VEHICLE_SEAT_NUM_MASK 0x7F
@ -623,12 +638,15 @@ extern uint32_t _vehicleMotionTrackFlags;
extern int32_t _vehicleVelocityF64E08; extern int32_t _vehicleVelocityF64E08;
extern int32_t _vehicleVelocityF64E0C; extern int32_t _vehicleVelocityF64E0C;
extern int32_t _vehicleUnkF64E10; extern int32_t _vehicleUnkF64E10;
extern uint8_t _vehicleVAngleEndF64E36; extern VAngleAndBank _vehicleVAngleAndBank;
extern uint8_t _vehicleBankEndF64E37;
extern uint8_t _vehicleF64E2C; extern uint8_t _vehicleF64E2C;
extern Vehicle* _vehicleFrontVehicle; extern Vehicle* _vehicleFrontVehicle;
extern CoordsXYZ unk_F64E20; extern CoordsXYZ unk_F64E20;
// TODO move these to Track.h
VAngleAndBank VAngleAndBankStart(uint8_t trackType);
VAngleAndBank VAngleAndBankEnd(uint8_t trackType);
/** Helper macro until rides are stored in this module. */ /** Helper macro until rides are stored in this module. */
#define GET_VEHICLE(sprite_index) &(get_sprite(sprite_index)->vehicle) #define GET_VEHICLE(sprite_index) &(get_sprite(sprite_index)->vehicle)