From 6f0ebfea27594aac013b04f2c681274a4efbe404 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Wed, 4 Dec 2019 08:02:09 -0300 Subject: [PATCH 1/4] Use CoordsXY and ScreenCoordsXY for rotate in Ride*.* --- src/openrct2-ui/windows/RideConstruction.cpp | 26 +++++++++----------- src/openrct2/ride/Ride.cpp | 18 ++++++-------- src/openrct2/ride/Ride.h | 5 ++-- 3 files changed, 20 insertions(+), 29 deletions(-) diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 2fbb235fbbce..a98371090fba 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 = ride_get_rotated_coords(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..d4a678748c12 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -2899,9 +2899,8 @@ 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; + CoordsXYZ rideCoords{ ride->stations[0].Start.x * 32 + 16, ride->stations[0].Start.y * 32 + 16, + ride->stations[0].Height * 8 }; int32_t sampleRate = 22050; @@ -2914,7 +2913,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 +3562,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 = ride_get_rotated_coords(rideCoords); rct_viewport* viewport = g_music_tracking_viewport; int16_t view_width = viewport->view_width; int16_t view_width2 = view_width * 2; @@ -7658,12 +7656,10 @@ 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) +ScreenCoordsXY ride_get_rotated_coords(CoordsXYZ coords3d) { - 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; + return screenCoords; } // Normally, a station has at most one entrance and one exit, which are at the same height diff --git a/src/openrct2/ride/Ride.h b/src/openrct2/ride/Ride.h index 1c6df544cf56..45d74233e95a 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,7 +1278,7 @@ 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); +ScreenCoordsXY ride_get_rotated_coords(CoordsXYZ coords); void determine_ride_entrance_and_exit_locations(); void ride_clear_leftover_entrances(Ride* ride); From d9348cf562d9f941fc4c9cd523ec1b39ce83f2bc Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Wed, 4 Dec 2019 22:02:11 -0300 Subject: [PATCH 2/4] Use CoordsXY::ToTileCentre() on Ride.cpp --- src/openrct2/ride/Ride.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index d4a678748c12..5d4136433163 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -2899,8 +2899,8 @@ static void ride_music_update(Ride* ride) return; } - CoordsXYZ rideCoords{ ride->stations[0].Start.x * 32 + 16, ride->stations[0].Start.y * 32 + 16, - ride->stations[0].Height * 8 }; + CoordsXYZ rideCoords{ ride->stations[0].Start.x * 32, ride->stations[0].Start.y * 32, ride->stations[0].Height * 8 }; + rideCoords = { rideCoords.ToTileCentre(), rideCoords.z }; int32_t sampleRate = 22050; From aca4d391074c58c0b3915729b2ef7142bfb4d981 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Thu, 5 Dec 2019 21:43:20 -0300 Subject: [PATCH 3/4] Allow TileCoordsXYZ conversion to CoordsXYZ --- src/openrct2/ride/Ride.cpp | 3 ++- src/openrct2/world/Location.hpp | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 5d4136433163..66807d0d021e 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -2899,7 +2899,8 @@ static void ride_music_update(Ride* ride) return; } - CoordsXYZ rideCoords{ ride->stations[0].Start.x * 32, ride->stations[0].Start.y * 32, ride->stations[0].Height * 8 }; + TileCoordsXYZ rideTileCoords{ ride->stations[0].Start.x, ride->stations[0].Start.y, ride->stations[0].Height }; + CoordsXYZ rideCoords{rideTileCoords.ToCoordsXYZ()}; rideCoords = { rideCoords.ToTileCentre(), rideCoords.z }; int32_t sampleRate = 22050; 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; }; From 01c62437b2671eaad6b948bf679b8619df0e9473 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Mon, 9 Dec 2019 16:52:47 -0300 Subject: [PATCH 4/4] Remove Ride::ride_get_rotated_coords() --- src/openrct2-ui/windows/RideConstruction.cpp | 2 +- src/openrct2/ride/Ride.cpp | 12 +++--------- src/openrct2/ride/Ride.h | 2 -- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index a98371090fba..820e3d1a1f0a 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -2385,7 +2385,7 @@ static void window_ride_construction_draw_track_piece( : TrackDefinitions[trackType].preview_z_offset; mapCoords.z -= previewZOffset; - const ScreenCoordsXY rotatedScreenCoords = ride_get_rotated_coords(mapCoords); + const ScreenCoordsXY rotatedScreenCoords = translate_3d_to_2d_with_z(get_current_rotation(), mapCoords); dpi->x += rotatedScreenCoords.x - width / 2; dpi->y += rotatedScreenCoords.y - height / 2 - 16; diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 66807d0d021e..cac818ec8ef9 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -2899,8 +2899,8 @@ static void ride_music_update(Ride* ride) return; } - TileCoordsXYZ rideTileCoords{ ride->stations[0].Start.x, ride->stations[0].Start.y, ride->stations[0].Height }; - CoordsXYZ rideCoords{rideTileCoords.ToCoordsXYZ()}; + 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; @@ -3567,7 +3567,7 @@ int32_t ride_music_params_update(CoordsXYZ rideCoords, Ride* ride, uint16_t samp { if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gGameSoundsOff && g_music_tracking_viewport != nullptr) { - const ScreenCoordsXY rotatedCoords = ride_get_rotated_coords(rideCoords); + 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; @@ -7657,12 +7657,6 @@ StationObject* ride_get_station_object(const Ride* ride) return static_cast(objManager.GetLoadedObject(OBJECT_TYPE_STATION, ride->entrance_style)); } -ScreenCoordsXY ride_get_rotated_coords(CoordsXYZ coords3d) -{ - auto screenCoords = translate_3d_to_2d_with_z(get_current_rotation(), coords3d); - return screenCoords; -} - // 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 45d74233e95a..3cba7fc50287 100644 --- a/src/openrct2/ride/Ride.h +++ b/src/openrct2/ride/Ride.h @@ -1278,8 +1278,6 @@ StationObject* ride_get_station_object(const Ride* ride); void ride_action_modify(Ride* ride, int32_t modifyType, int32_t flags); -ScreenCoordsXY ride_get_rotated_coords(CoordsXYZ coords); - void determine_ride_entrance_and_exit_locations(); void ride_clear_leftover_entrances(Ride* ride);