diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 2fbb235fbbce..820e3d1a1f0a 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -2367,32 +2367,28 @@ static void window_ride_construction_draw_track_piece( while ((trackBlock + 1)->index != 0xFF) trackBlock++; - int16_t x = trackBlock->x; - int16_t z = trackBlock->z; - int16_t y = trackBlock->y; + CoordsXYZ mapCoords{ trackBlock->x, trackBlock->z, trackBlock->y }; if (trackBlock->var_09 & 2) { - x = 0; - y = 0; + mapCoords.x = 0; + mapCoords.y = 0; } - rotate_map_coordinates(&x, &y, trackDirection & 3); + auto rotatedMapCoords = mapCoords.Rotate(trackDirection); // this is actually case 0, but the other cases all jump to it - x = 4112 + (x / 2); - y = 4112 + (y / 2); - z = 1024 + z; + mapCoords.x = 4112 + (rotatedMapCoords.x / 2); + mapCoords.y = 4112 + (rotatedMapCoords.y / 2); + mapCoords.z = 1024 + mapCoords.z; int16_t previewZOffset = ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_FLAT_RIDE) ? FlatRideTrackDefinitions[trackType].preview_z_offset : TrackDefinitions[trackType].preview_z_offset; - z -= previewZOffset; + mapCoords.z -= previewZOffset; - const LocationXY16 rotatedCoords = ride_get_rotated_coords(x, y, z); - x = rotatedCoords.x; - y = rotatedCoords.y; + const ScreenCoordsXY rotatedScreenCoords = translate_3d_to_2d_with_z(get_current_rotation(), mapCoords); - dpi->x += x - width / 2; - dpi->y += y - height / 2 - 16; + dpi->x += rotatedScreenCoords.x - width / 2; + dpi->y += rotatedScreenCoords.y - height / 2 - 16; uint32_t d = unknown << 16; d |= rideIndex; d |= trackType << 8; diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 722a0cfb9a27..cac818ec8ef9 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -2899,9 +2899,9 @@ static void ride_music_update(Ride* ride) return; } - int32_t x = ride->stations[0].Start.x * 32 + 16; - int32_t y = ride->stations[0].Start.y * 32 + 16; - int32_t z = ride->stations[0].Height * 8; + TileCoordsXYZ stationTileCoords{ ride->stations[0].Start.x, ride->stations[0].Start.y, ride->stations[0].Height }; + CoordsXYZ rideCoords{ stationTileCoords.ToCoordsXYZ() }; + rideCoords = { rideCoords.ToTileCentre(), rideCoords.z }; int32_t sampleRate = 22050; @@ -2914,7 +2914,7 @@ static void ride_music_update(Ride* ride) sampleRate += 22050; } - ride->music_position = ride_music_params_update(x, y, z, ride, sampleRate, ride->music_position, &ride->music_tune_id); + ride->music_position = ride_music_params_update(rideCoords, ride, sampleRate, ride->music_position, &ride->music_tune_id); } #pragma endregion @@ -3563,12 +3563,11 @@ static int32_t ride_music_params_update_label_58(uint32_t position, uint8_t* tun * @param tuneId (bh) * @returns new position (ebp) */ -int32_t ride_music_params_update( - int16_t x, int16_t y, int16_t z, Ride* ride, uint16_t sampleRate, uint32_t position, uint8_t* tuneId) +int32_t ride_music_params_update(CoordsXYZ rideCoords, Ride* ride, uint16_t sampleRate, uint32_t position, uint8_t* tuneId) { if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gGameSoundsOff && g_music_tracking_viewport != nullptr) { - const LocationXY16 rotatedCoords = ride_get_rotated_coords(x, y, z); + const ScreenCoordsXY rotatedCoords = translate_3d_to_2d_with_z(get_current_rotation(), rideCoords); rct_viewport* viewport = g_music_tracking_viewport; int16_t view_width = viewport->view_width; int16_t view_width2 = view_width * 2; @@ -7658,14 +7657,6 @@ StationObject* ride_get_station_object(const Ride* ride) return static_cast(objManager.GetLoadedObject(OBJECT_TYPE_STATION, ride->entrance_style)); } -LocationXY16 ride_get_rotated_coords(int16_t x, int16_t y, int16_t z) -{ - CoordsXYZ coords3d = { x, y, z }; - auto screenCoords = translate_3d_to_2d_with_z(get_current_rotation(), coords3d); - LocationXY16 rotatedCoords = { (int16_t)screenCoords.x, (int16_t)screenCoords.y }; - return rotatedCoords; -} - // Normally, a station has at most one entrance and one exit, which are at the same height // as the station. But in hacked parks, neither can be taken for granted. This code ensures // that the ride->entrances and ride->exits arrays will point to one of them. There is diff --git a/src/openrct2/ride/Ride.h b/src/openrct2/ride/Ride.h index 1c6df544cf56..3cba7fc50287 100644 --- a/src/openrct2/ride/Ride.h +++ b/src/openrct2/ride/Ride.h @@ -1169,8 +1169,7 @@ int32_t sub_6C683D( int32_t* x, int32_t* y, int32_t* z, int32_t direction, int32_t type, uint16_t extra_params, TileElement** output_element, uint16_t flags); void ride_set_map_tooltip(TileElement* tileElement); -int32_t ride_music_params_update( - int16_t x, int16_t y, int16_t z, Ride* ride, uint16_t sampleRate, uint32_t position, uint8_t* tuneId); +int32_t ride_music_params_update(CoordsXYZ rideCoords, Ride* ride, uint16_t sampleRate, uint32_t position, uint8_t* tuneId); void ride_music_update_final(); void ride_prepare_breakdown(Ride* ride, int32_t breakdownReason); TileElement* ride_get_station_start_track_element(Ride* ride, int32_t stationIndex); @@ -1279,8 +1278,6 @@ StationObject* ride_get_station_object(const Ride* ride); void ride_action_modify(Ride* ride, int32_t modifyType, int32_t flags); -LocationXY16 ride_get_rotated_coords(int16_t x, int16_t y, int16_t z); - void determine_ride_entrance_and_exit_locations(); void ride_clear_leftover_entrances(Ride* ride); diff --git a/src/openrct2/world/Location.hpp b/src/openrct2/world/Location.hpp index 4d3aa1e6ba64..2f835c933e9c 100644 --- a/src/openrct2/world/Location.hpp +++ b/src/openrct2/world/Location.hpp @@ -273,6 +273,11 @@ struct TileCoordsXYZ return !(*this == other); } + CoordsXYZ ToCoordsXYZ() + { + return { x * 32, y * 32, z * 8 }; + } + int32_t x = 0, y = 0, z = 0; };