From 0c4fffb2ec13c86e25db0879f3bed00d31f2ad09 Mon Sep 17 00:00:00 2001 From: duncanspumpkin Date: Sun, 24 Nov 2019 15:53:18 +0000 Subject: [PATCH] Refactor viewport_adjust_for_map_height to use CoordsXYZ. --- src/openrct2/interface/Viewport.cpp | 10 +++------- src/openrct2/interface/Viewport.h | 2 +- src/openrct2/interface/Window.cpp | 10 ++++------ 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/openrct2/interface/Viewport.cpp b/src/openrct2/interface/Viewport.cpp index ba0971c174..95a12f4c6e 100644 --- a/src/openrct2/interface/Viewport.cpp +++ b/src/openrct2/interface/Viewport.cpp @@ -215,17 +215,15 @@ void viewport_create( * edx is assumed to be (and always is) the current rotation, so it is not * needed as parameter. */ -void viewport_adjust_for_map_height(int16_t* x, int16_t* y, int16_t* z) +CoordsXYZ viewport_adjust_for_map_height(const ScreenCoordsXY startCoords) { - int16_t start_x = *x; - int16_t start_y = *y; int16_t height = 0; uint32_t rotation = get_current_rotation(); CoordsXY pos{}; for (int32_t i = 0; i < 6; i++) { - pos = viewport_coord_to_map_coord(start_x, start_y, height); + pos = viewport_coord_to_map_coord(startCoords.x, startCoords.y, height); height = tile_element_height(pos); // HACK: This is to prevent the x and y values being set to values outside @@ -239,9 +237,7 @@ void viewport_adjust_for_map_height(int16_t* x, int16_t* y, int16_t* z) } } - *x = pos.x; - *y = pos.y; - *z = height; + return { pos, height }; } /* diff --git a/src/openrct2/interface/Viewport.h b/src/openrct2/interface/Viewport.h index 707790af2d..4c4432c123 100644 --- a/src/openrct2/interface/Viewport.h +++ b/src/openrct2/interface/Viewport.h @@ -138,7 +138,7 @@ void viewport_paint( const rct_viewport* viewport, rct_drawpixelinfo* dpi, int16_t left, int16_t top, int16_t right, int16_t bottom, std::vector* sessions = nullptr); -void viewport_adjust_for_map_height(int16_t* x, int16_t* y, int16_t* z); +CoordsXYZ viewport_adjust_for_map_height(const ScreenCoordsXY startCoords); LocationXY16 screen_coord_to_viewport_coord(rct_viewport* viewport, ScreenCoordsXY screenCoords); CoordsXY viewport_coord_to_map_coord(int32_t x, int32_t y, int32_t z); diff --git a/src/openrct2/interface/Window.cpp b/src/openrct2/interface/Window.cpp index 552ba4bedc..8fbad85760 100644 --- a/src/openrct2/interface/Window.cpp +++ b/src/openrct2/interface/Window.cpp @@ -912,11 +912,10 @@ void window_rotate_camera(rct_window* w, int32_t direction) int16_t x = (viewport->width >> 1) + viewport->x; int16_t y = (viewport->height >> 1) + viewport->y; - int16_t z; // has something to do with checking if middle of the viewport is obstructed rct_viewport* other; - CoordsXY coords = screen_get_map_xy({ x, y }, &other); + CoordsXYZ coords{ screen_get_map_xy({ x, y }, &other), 0 }; // other != viewport probably triggers on viewports in ride or guest window? // x is LOCATION_NULL if middle of viewport is obstructed by another window? @@ -925,17 +924,16 @@ void window_rotate_camera(rct_window* w, int32_t direction) int16_t view_x = (viewport->view_width >> 1) + viewport->view_x; int16_t view_y = (viewport->view_height >> 1) + viewport->view_y; - viewport_adjust_for_map_height(&view_x, &view_y, &z); - coords = { view_x, view_y }; + coords = viewport_adjust_for_map_height({ view_x, view_y }); } else { - z = tile_element_height(coords); + coords.z = tile_element_height(coords); } gCurrentRotation = (get_current_rotation() + direction) & 3; - auto centreLoc = centre_2d_coordinates({ coords, z }, viewport); + auto centreLoc = centre_2d_coordinates(coords, viewport); if (centreLoc) {