From 887ec16b539bd31e56fab08be47ec7dafe0a9fd9 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Mon, 23 Oct 2017 10:52:10 +0200 Subject: [PATCH] Split off ride_get_rotated_coords() --- src/openrct2/ride/ride.c | 49 +++++++++++++---------- src/openrct2/ride/ride.h | 2 + src/openrct2/windows/RideConstruction.cpp | 23 ++--------- 3 files changed, 34 insertions(+), 40 deletions(-) diff --git a/src/openrct2/ride/ride.c b/src/openrct2/ride/ride.c index 6ab9913a1c..1e5536db4b 100644 --- a/src/openrct2/ride/ride.c +++ b/src/openrct2/ride/ride.c @@ -3494,27 +3494,7 @@ sint32 ride_music_params_update(sint16 x, sint16 y, sint16 z, uint8 rideIndex, u { if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gGameSoundsOff && g_music_tracking_viewport != NULL) { - LocationXY16 rotatedCoords = {0, 0}; - - switch (get_current_rotation()) - { - case 0: - rotatedCoords.x = y - x; - rotatedCoords.y = ((y + x) / 2) - z; - break; - case 1: - rotatedCoords.x = -x - y; - rotatedCoords.y = ((y - x) / 2) - z; - break; - case 2: - rotatedCoords.x = x - y; - rotatedCoords.y = ((-y - x) / 2) - z; - break; - case 3: - rotatedCoords.x = y + x; - rotatedCoords.y = ((x - y) / 2) - z; - break; - } + const LocationXY16 rotatedCoords = ride_get_rotated_coords(x, y, z); rct_viewport * viewport = g_music_tracking_viewport; sint16 view_width = viewport->view_width; sint16 view_width2 = view_width * 2; @@ -8219,3 +8199,30 @@ sint32 ride_get_entry_index(sint32 rideType, sint32 rideSubType) return subType; } + +LocationXY16 ride_get_rotated_coords(sint16 x, sint16 y, sint16 z) +{ + LocationXY16 rotatedCoords = { 0, 0 }; + + switch (get_current_rotation()) + { + case 0: + rotatedCoords.x = y - x; + rotatedCoords.y = ((y + x) / 2) - z; + break; + case 1: + rotatedCoords.x = -x - y; + rotatedCoords.y = ((y - x) / 2) - z; + break; + case 2: + rotatedCoords.x = x - y; + rotatedCoords.y = ((-y - x) / 2) - z; + break; + case 3: + rotatedCoords.x = y + x; + rotatedCoords.y = ((x - y) / 2) - z; + break; + } + + return rotatedCoords; +} diff --git a/src/openrct2/ride/ride.h b/src/openrct2/ride/ride.h index 5af2bf8d29..29a8037ddf 100644 --- a/src/openrct2/ride/ride.h +++ b/src/openrct2/ride/ride.h @@ -1212,6 +1212,8 @@ sint32 ride_get_entry_index(sint32 rideType, sint32 rideSubType); void ride_demolish(sint32 rideIndex, sint32 flags); void ride_stop_peeps_queuing(sint32 rideIndex); +LocationXY16 ride_get_rotated_coords(sint16 x, sint16 y, sint16 z); + #ifdef __cplusplus } #endif diff --git a/src/openrct2/windows/RideConstruction.cpp b/src/openrct2/windows/RideConstruction.cpp index d87c7bc961..6861ddbd81 100644 --- a/src/openrct2/windows/RideConstruction.cpp +++ b/src/openrct2/windows/RideConstruction.cpp @@ -2283,25 +2283,10 @@ static void window_ride_construction_draw_track_piece( TrackDefinitions[trackType].preview_z_offset; z -= previewZOffset; - sint32 start_x = x; - switch (get_current_rotation()) { - case 0: - x = y - x; - y = (y + start_x) / 2 - z; - break; - case 1: - x = -x - y; - y = (y - start_x) / 2 - z; - break; - case 2: - x -= y; - y = (-y - start_x) / 2 - z; - break; - case 3: - x += y; - y = (-y + start_x) / 2 - z; - break; - } + const LocationXY16 rotatedCoords = ride_get_rotated_coords(x, y, z); + x = rotatedCoords.x; + y = rotatedCoords.y; + dpi->x += x - width / 2; dpi->y += y - height / 2 - 16; uint32 d = unknown << 16;